<?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>126121</bug_id>
          
          <creation_ts>2013-12-21 12:30:48 -0800</creation_ts>
          <short_desc>The JavaScriptCore API ignores dynamically created protocols</short_desc>
          <delta_ts>2013-12-30 16:44:22 -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>NEW</bug_status>
          <resolution></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="Mark Villacampa">markvjal</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>barraclough</cc>
    
    <cc>brandon</cc>
    
    <cc>mhahnenberg</cc>
    
    <cc>sam</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>962264</commentid>
    <comment_count>0</comment_count>
      <attachid>219854</attachid>
    <who name="Mark Villacampa">markvjal</who>
    <bug_when>2013-12-21 12:30:48 -0800</bug_when>
    <thetext>Created attachment 219854
Example of dynamically generated protocol ignored by JavaScriptCore

I would like to use a dynamically generated protocol as my JSExport sub-protocol for interacting with JavaScriptCore.

However JavaScriptCore ignores dynamically generated protocols. Attached is a snippet which shows the behaviour when the protocol is statically defined, and when it is dynamically defined.

The &quot;hello&quot; method is only called when the protocol is statically defined.

I have tracked down the issue to the private Objective-C runtime method  _protocol_getMethodTypeEncoding() which returns null if the protocol method has been dynamically defined.

Said method is extensively used in the ObjCCallbackFunction.mm file. A solution, if possible, would be to use the method_getTypeEncoding() method which correctly outputs the type encoding for both dynamically and statically generated protocol methods.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>963411</commentid>
    <comment_count>1</comment_count>
    <who name="Brandon Evans">brandon</who>
    <bug_when>2013-12-30 16:44:22 -0800</bug_when>
    <thetext>I&apos;ve been investigating this bug as well, and it seems that the private _protocol_getMethodTypeEncoding method also emits type strings (e.g. &apos;v24@0:8@16&apos; vs. &apos;v24@0:8@&quot;JSValue&quot;16&apos;) when the compiler&apos;s type information is available. This extended type information is used when invoking Objective-C code, specifically when parseObjCType calls typeOfClass in ObjcRuntimeExtras.h at L197.

I made the appropriate changes to use method_getTypeEncoding instead like you suggested and most cases seem to work with the exception of methods that accept a JSValue as a parameter (such as a JS function). These end up getting passed an empty NSDictionary, so there&apos;s clearly some problems that occur when the argument type information isn&apos;t available to JSC.

It may be possible to work around this by also providing protocols for these specific methods and then ignoring them when doing a dynamic export to avoid losing the type information. This is clearly less elegant though.</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="0"
              isprivate="0"
          >
            <attachid>219854</attachid>
            <date>2013-12-21 12:30:48 -0800</date>
            <delta_ts>2013-12-21 12:30:48 -0800</delta_ts>
            <desc>Example of dynamically generated protocol ignored by JavaScriptCore</desc>
            <filename>JavaScriptCore-example.m</filename>
            <type>application/octet-stream</type>
            <size>1116</size>
            <attacher name="Mark Villacampa">markvjal</attacher>
            
              <data encoding="base64">I2ltcG9ydCA8Rm91bmRhdGlvbi9Gb3VuZGF0aW9uLmg+CiNpbXBvcnQgPEphdmFTY3JpcHRDb3Jl
L0phdmFTY3JpcHRDb3JlLmg+CiNpbXBvcnQgPG9iamMvcnVudGltZS5oPgoKLy9AcHJvdG9jb2wg
TXlQcm90b2NvbCA8SlNFeHBvcnQ+Ci8vLSh2b2lkKWhlbGxvO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KU0NvbnRleHQgYWxs
b2NdIGluaXRdOwogICAgTXlDbGFzcyAqbXljbGFzcyA9IFtbTXlDbGFzcyBhbGxvY10gaW5pdF07
CiAgICBjb250ZXh0W0AiTXljbGFzcyJdID0gbXljbGFzczsKICAgIFtjb250ZXh0IGV2YWx1YXRl
U2NyaXB0OkAiTXljbGFzcy5oZWxsbygpIl07CiAgfQp9
</data>

          </attachment>
      

    </bug>

</bugzilla>