<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>128840</bug_id>
          
          <creation_ts>2014-02-14 13:46:55 -0800</creation_ts>
          <short_desc>ASSERT(isValidAllocation(bytes)) when ObjC API creates custom errors</short_desc>
          <delta_ts>2014-02-14 14:39:49 -0800</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>JavaScriptCore</component>
          <version>528+ (Nightly build)</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Joseph Pecoraro">joepeck</reporter>
          <assigned_to name="Mark Hahnenberg">mhahnenberg</assigned_to>
          <cc>ggaren</cc>
    
    <cc>joepeck</cc>
    
    <cc>mhahnenberg</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>980952</commentid>
    <comment_count>0</comment_count>
    <who name="Joseph Pecoraro">joepeck</who>
    <bug_when>2014-02-14 13:46:55 -0800</bug_when>
    <thetext>* TEST:
JSContext *context = [[[JSContext alloc] init] autorelease];
[[JSValue valueWithInt32:42 inContext:context] toDictionary];

* ASSERT
ASSERTION FAILED: isValidAllocation(bytes)
/Volumes/Data/Code/safari/OpenSource/Source/JavaScriptCore/heap/Heap.h(467) : void *JSC::Heap::allocateWithoutDestructor(size_t)
1   0x10a94ce50 WTFCrash
2   0x10a1ce54b JSC::Heap::allocateWithoutDestructor(unsigned long)
3   0x10a4ea107 void* JSC::allocateCell&lt;JSC::ErrorInstance&gt;(JSC::Heap&amp;, unsigned long)
4   0x10a4e986f void* JSC::allocateCell&lt;JSC::ErrorInstance&gt;(JSC::Heap&amp;)
5   0x10a4e8ffb JSC::ErrorInstance::create(JSC::VM&amp;, JSC::Structure*, WTF::String const&amp;, WTF::Vector&lt;JSC::StackFrame, 0ul, WTF::CrashOnOverflow&gt;)
6   0x10a4e88f7 JSC::createTypeError(JSC::JSGlobalObject*, WTF::String const&amp;)
7   0x10a4e8b35 JSC::createTypeError(JSC::ExecState*, WTF::String const&amp;)
8   0x10a6d5af5 valueToDictionary(OpaqueJSContext*, OpaqueJSValue const*, OpaqueJSValue const**)
9   0x10a6d5921 -[JSValue toDictionary]
10  0x10a1b5f04 main
11  0x7fff8cbbf5f1 start

Specifically, vm-&gt;identifierTable != wtfThreadData().currentIdentifierTable.

My guess is that the ObjC API has to grab the APIEntryShim before it calls into JSC (via JSC::createTypeError). Most of the ObjC API uses the C API which already does this implicitly.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>980953</commentid>
    <comment_count>1</comment_count>
    <who name="Joseph Pecoraro">joepeck</who>
    <bug_when>2014-02-14 13:48:01 -0800</bug_when>
    <thetext>There are a number of create calls throughout the ObjC API. They will all need to be audited:

    shell&gt; ack &apos;create.*?Error&apos; API/*.mm
    API/JSValue.mm
    784:        *exception = toRef(JSC::createTypeError(toJS(context), &quot;Cannot convert primitive to NSArray&quot;));
    800:        *exception = toRef(JSC::createTypeError(toJS(context), &quot;Cannot convert primitive to NSDictionary&quot;));

    API/ObjCCallbackFunction.mm
    132:        *exception = toRef(JSC::createTypeError(toJS(contextRef), &quot;Argument does not match Objective-C Class&quot;));
    456:    // (2) We&apos;re calling some JSC internals that require us to be on the &apos;inside&apos; - e.g. createTypeError.
    499:        *exception = toRef(JSC::createTypeError(toJS(contextRef), &quot;Objective-C blocks called as constructors must return an object.&quot;));
    565:            *exception = toRef(JSC::createTypeError(toJS(contextRef), &quot;self type check failed for Objective-C instance method&quot;));
    575:            *exception = toRef(JSC::createTypeError(toJS(contextRef), &quot;self type check failed for Objective-C instance method&quot;));</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>980968</commentid>
    <comment_count>2</comment_count>
    <who name="Geoffrey Garen">ggaren</who>
    <bug_when>2014-02-14 14:06:19 -0800</bug_when>
    <thetext>&gt; My guess is that the ObjC API has to grab the APIEntryShim before it calls into JSC (via JSC::createTypeError).

Right.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>980970</commentid>
    <comment_count>3</comment_count>
      <attachid>224250</attachid>
    <who name="Mark Hahnenberg">mhahnenberg</who>
    <bug_when>2014-02-14 14:09:12 -0800</bug_when>
    <thetext>Created attachment 224250
Patch</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>980971</commentid>
    <comment_count>4</comment_count>
    <who name="Mark Hahnenberg">mhahnenberg</who>
    <bug_when>2014-02-14 14:09:52 -0800</bug_when>
    <thetext>(In reply to comment #1)
&gt; There are a number of create calls throughout the ObjC API. They will all need to be audited:
&gt; 
&gt;     shell&gt; ack &apos;create.*?Error&apos; API/*.mm
&gt;     API/JSValue.mm
&gt;     784:        *exception = toRef(JSC::createTypeError(toJS(context), &quot;Cannot convert primitive to NSArray&quot;));
&gt;     800:        *exception = toRef(JSC::createTypeError(toJS(context), &quot;Cannot convert primitive to NSDictionary&quot;));
&gt; 
&gt;     API/ObjCCallbackFunction.mm
&gt;     132:        *exception = toRef(JSC::createTypeError(toJS(contextRef), &quot;Argument does not match Objective-C Class&quot;));
&gt;     456:    // (2) We&apos;re calling some JSC internals that require us to be on the &apos;inside&apos; - e.g. createTypeError.
&gt;     499:        *exception = toRef(JSC::createTypeError(toJS(contextRef), &quot;Objective-C blocks called as constructors must return an object.&quot;));
&gt;     565:            *exception = toRef(JSC::createTypeError(toJS(contextRef), &quot;self type check failed for Objective-C instance method&quot;));
&gt;     575:            *exception = toRef(JSC::createTypeError(toJS(contextRef), &quot;self type check failed for Objective-C instance method&quot;));

I audited the other call sites and other than these two they are all in places where we already hold the API lock.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>980990</commentid>
    <comment_count>5</comment_count>
      <attachid>224250</attachid>
    <who name="Joseph Pecoraro">joepeck</who>
    <bug_when>2014-02-14 14:23:44 -0800</bug_when>
    <thetext>Comment on attachment 224250
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=224250&amp;action=review

r=me

&gt; Source/JavaScriptCore/API/JSValue.mm:785
&gt;          *exception = toRef(JSC::createTypeError(toJS(context), &quot;Cannot convert primitive to NSArray&quot;));

Nit: You could ASCIILiteral(...) the string being passed to createTypeError, since it is a string literal turning into a WTF::String.

Is the lock needed by the &quot;tryUnwrapObjcObject&quot; call at the top of these functions?

Otherwise this is identical to the local fix I had.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>980994</commentid>
    <comment_count>6</comment_count>
    <who name="Mark Hahnenberg">mhahnenberg</who>
    <bug_when>2014-02-14 14:28:18 -0800</bug_when>
    <thetext>(In reply to comment #5)
&gt; (From update of attachment 224250 [details])
&gt; View in context: https://bugs.webkit.org/attachment.cgi?id=224250&amp;action=review
&gt; 
&gt; r=me
&gt; 
&gt; &gt; Source/JavaScriptCore/API/JSValue.mm:785
&gt; &gt;          *exception = toRef(JSC::createTypeError(toJS(context), &quot;Cannot convert primitive to NSArray&quot;));
&gt; 
&gt; Nit: You could ASCIILiteral(...) the string being passed to createTypeError, since it is a string literal turning into a WTF::String.
&gt; 
Will do.

&gt; Is the lock needed by the &quot;tryUnwrapObjcObject&quot; call at the top of these functions?
&gt; 
I don&apos;t think so. We don&apos;t create any objects in it, and the object is always reachable from the stack. If I missed something and we do need to take the shim for things that happen inside tryUnwrapObjcObject then the shim should probably go in there instead of out here.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>981001</commentid>
    <comment_count>7</comment_count>
    <who name="Mark Hahnenberg">mhahnenberg</who>
    <bug_when>2014-02-14 14:39:49 -0800</bug_when>
    <thetext>Committed r164136: &lt;http://trac.webkit.org/changeset/164136&gt;</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>224250</attachid>
            <date>2014-02-14 14:09:12 -0800</date>
            <delta_ts>2014-02-14 14:23:43 -0800</delta_ts>
            <desc>Patch</desc>
            <filename>bug-128840-20140214140905.patch</filename>
            <type>text/plain</type>
            <size>2732</size>
            <attacher name="Mark Hahnenberg">mhahnenberg</attacher>
            
              <data encoding="base64">SW5kZXg6IFNvdXJjZS9KYXZhU2NyaXB0Q29yZS9DaGFuZ2VMb2cKPT09PT09PT09PT09PT09PT09
PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PQotLS0gU291
cmNlL0phdmFTY3JpcHRDb3JlL0NoYW5nZUxvZwkocmV2aXNpb24gMTY0MTMyKQorKysgU291cmNl
L0phdmFTY3JpcHRDb3JlL0NoYW5nZUxvZwkod29ya2luZyBjb3B5KQpAQCAtMSwzICsxLDE3IEBA
CisyMDE0LTAyLTE0ICBNYXJrIEhhaG5lbmJlcmcgIDxtaGFobmVuYmVyZ0BhcHBsZS5jb20+CisK
KyAgICAgICAgQVNTRVJUKGlzVmFsaWRBbGxvY2F0aW9uKGJ5dGVzKSkgd2hlbiBPYmpDIEFQSSBj
cmVhdGVzIGN1c3RvbSBlcnJvcnMKKyAgICAgICAgaHR0cHM6Ly9idWdzLndlYmtpdC5vcmcvc2hv
d19idWcuY2dpP2lkPTEyODg0MAorCisgICAgICAgIFJldmlld2VkIGJ5IE5PQk9EWSAoT09QUyEp
LgorCisgICAgICAgIFdlIG5lZWQgdG8gYWRkIEFQSUVudHJ5U2hpbXMgYXJvdW5kIHBsYWNlcyB3
aGVyZSB3ZSBhbGxvY2F0ZSBlcnJvcnMgaW4gSlNDLgorCisgICAgICAgICogQVBJL0pTVmFsdWUu
bW06CisgICAg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cmUvQVBJ
L3Rlc3RzL3Rlc3RhcGkubW0JKHdvcmtpbmcgY29weSkKQEAgLTEyNzIsNiArMTI3MiwxMiBAQCB2
b2lkIHRlc3RPYmplY3RpdmVDQVBJKCkKICAgICAgICAgY2hlY2tSZXN1bHQoQCJtYWtlT2JqZWN0
KCkgaW5zdGFuY2VvZiBVbmV4cG9ydGVkT2JqZWN0IiwgW3Jlc3VsdCBpc0Jvb2xlYW5dICYmIFty
ZXN1bHQgdG9Cb29sXSk7CiAgICAgfQogCisgICAgQGF1dG9yZWxlYXNlcG9vbCB7CisgICAgICAg
IEpTQ29udGV4dCAqY29udGV4dCA9IFtbSlNDb250ZXh0IGFsbG9jXSBpbml0XTsKKyAgICAgICAg
W1tKU1ZhbHVlIHZhbHVlV2l0aEludDMyOjQyIGluQ29udGV4dDpjb250ZXh0XSB0b0RpY3Rpb25h
cnldOworICAgICAgICBbW0pTVmFsdWUgdmFsdWVXaXRoSW50MzI6NDIgaW5Db250ZXh0OmNvbnRl
eHRdIHRvQXJyYXldOworICAgIH0KKwogICAgIGN1cnJlbnRUaGlzSW5zaWRlQmxvY2tHZXR0ZXJU
ZXN0KCk7CiAgICAgcnVuRGF0ZVRlc3RzKCk7CiAgICAgcnVuSlNFeHBvcnRUZXN0cygpOwo=
</data>
<flag name="review"
          id="248330"
          type_id="1"
          status="+"
          setter="joepeck"
    />
          </attachment>
      

    </bug>

</bugzilla>