[Cocoa] An exported Objective C class’s prototype and constructor don't persist acros...
authorkeith_miller@apple.com <keith_miller@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 22 May 2017 19:48:38 +0000 (19:48 +0000)
committerkeith_miller@apple.com <keith_miller@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 22 May 2017 19:48:38 +0000 (19:48 +0000)
commitc52cfed39bde19b766bb6106ea61b617020595dc
treefe6e0b5067805b80e8fa58e2cc69f6e14b4a657d
parent526da42a8036e39db4028c37b8903ba592d7c8a1
[Cocoa] An exported Objective C class’s prototype and constructor don't persist across JSContext deallocation
https://bugs.webkit.org/show_bug.cgi?id=167708

Reviewed by Geoffrey Garen.

This patch moves the Objective C wrapper map to the global object. In order to make this work the JSWrapperMap
class no longer holds a reference to the JSContext. Instead, the context must be provided when getting a wrapper.

Also, this patch fixes a "bug" where we would observe changes to the Object property on the global object when
creating a wrapper for NSObject.

* API/APICast.h:
(toJSGlobalObject):
* API/JSContext.mm:
(-[JSContext ensureWrapperMap]):
(-[JSContext initWithVirtualMachine:]):
(-[JSContext dealloc]):
(-[JSContext wrapperMap]):
(-[JSContext initWithGlobalContextRef:]):
(-[JSContext wrapperForObjCObject:]):
(-[JSContext wrapperForJSObject:]):
* API/JSWrapperMap.h:
* API/JSWrapperMap.mm:
(-[JSObjCClassInfo initForClass:]):
(-[JSObjCClassInfo allocateConstructorAndPrototypeInContext:]):
(-[JSObjCClassInfo wrapperForObject:inContext:]):
(-[JSObjCClassInfo constructorInContext:]):
(-[JSObjCClassInfo prototypeInContext:]):
(-[JSWrapperMap initWithGlobalContextRef:]):
(-[JSWrapperMap classInfoForClass:]):
(-[JSWrapperMap jsWrapperForObject:inContext:]):
(-[JSWrapperMap objcWrapperForJSValueRef:inContext:]):
(-[JSObjCClassInfo initWithContext:forClass:]): Deleted.
(-[JSObjCClassInfo allocateConstructorAndPrototype]): Deleted.
(-[JSObjCClassInfo wrapperForObject:]): Deleted.
(-[JSObjCClassInfo constructor]): Deleted.
(-[JSObjCClassInfo prototype]): Deleted.
(-[JSWrapperMap initWithContext:]): Deleted.
(-[JSWrapperMap jsWrapperForObject:]): Deleted.
(-[JSWrapperMap objcWrapperForJSValueRef:]): Deleted.
* API/tests/JSExportTests.mm:
(wrapperLifetimeIsTiedToGlobalObject):
(runJSExportTests):
* API/tests/testapi.mm:
* runtime/JSGlobalObject.h:
(JSC::JSGlobalObject::wrapperMap):
(JSC::JSGlobalObject::setWrapperMap):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@217240 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Source/JavaScriptCore/API/APICast.h
Source/JavaScriptCore/API/JSContext.mm
Source/JavaScriptCore/API/JSWrapperMap.h
Source/JavaScriptCore/API/JSWrapperMap.mm
Source/JavaScriptCore/API/tests/JSExportTests.mm
Source/JavaScriptCore/API/tests/testapi.mm
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/runtime/JSGlobalObject.h