<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@lists.webkit.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>mitz@webkit.org
</td>
</tr>
<tr>
<th>CC</th>
<td>ggaren@apple.com, joepeck@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:
@import JavaScriptCore;
@import Foundation;
@protocol AJSExport <JSExport>
- (instancetype)init;
@end
@interface A : NSObject <AJSExport>
@end
@implementation A
@end
int main(int argc, const char * argv[]) {
JSGlobalContextRef contextRef;
@autoreleasepool {
JSContext *context = [[JSContext alloc] init];
contextRef = JSGlobalContextRetain(context.JSGlobalContextRef);
context[@"A"] = A.class;
NSLog(@"%@", [context evaluateScript:@"new A().constructor === A"]);
}
@autoreleasepool {
JSContext *context = [JSContext contextWithJSGlobalContextRef:contextRef];
NSLog(@"%@", [context evaluateScript:@"new A().constructor === A"]);
}
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>