<html>
    <head>
      <base href="https://bugs.webkit.org/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - [Cocoa] An exported Objective C class’s constructor doesn’t persist across JSContext deallocation"
   href="https://bugs.webkit.org/show_bug.cgi?id=167708">167708</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>[Cocoa] An exported Objective C class’s constructor doesn’t persist across JSContext deallocation
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>WebKit
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>Other
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>Unspecified
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Unspecified
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>Normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P2
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>JavaScriptCore
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>webkit-unassigned&#64;lists.webkit.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>mitz&#64;webkit.org
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>ggaren&#64;apple.com, joepeck&#64;webkit.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>If a class A with an initializer is exported to JavaScriptCore, and its constructor is referenced by a global object in some context, but the JSContext wrapping that context get deallocated, then a new, different constructor is created the next time it’s needed.

To see the problem, build and run this program:

&#64;import JavaScriptCore;
&#64;import Foundation;

&#64;protocol AJSExport &lt;JSExport&gt;
- (instancetype)init;
&#64;end

&#64;interface A : NSObject &lt;AJSExport&gt;
&#64;end

&#64;implementation A
&#64;end

int main(int argc, const char * argv[]) {
    JSGlobalContextRef contextRef;
    &#64;autoreleasepool {
        JSContext *context = [[JSContext alloc] init];
        contextRef = JSGlobalContextRetain(context.JSGlobalContextRef);
        context[&#64;&quot;A&quot;] = A.class;
        NSLog(&#64;&quot;%&#64;&quot;, [context evaluateScript:&#64;&quot;new A().constructor === A&quot;]);
    }

    &#64;autoreleasepool {
        JSContext *context = [JSContext contextWithJSGlobalContextRef:contextRef];
        NSLog(&#64;&quot;%&#64;&quot;, [context evaluateScript:&#64;&quot;new A().constructor === A&quot;]);
    }

    JSGlobalContextRelease(contextRef);

    return 0;
}

The first NSLog statement logs true, and the second one logs false. It’s expected to log true as well.</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are the assignee for the bug.</li>
      </ul>
    </body>
</html>