Diff
Modified: trunk/Source/_javascript_Core/API/JSWrapperMap.mm (232935 => 232936)
--- trunk/Source/_javascript_Core/API/JSWrapperMap.mm 2018-06-18 18:31:06 UTC (rev 232935)
+++ trunk/Source/_javascript_Core/API/JSWrapperMap.mm 2018-06-18 18:49:01 UTC (rev 232936)
@@ -367,6 +367,7 @@
JSClassRef m_classRef;
JSC::Weak<JSC::JSObject> m_prototype;
JSC::Weak<JSC::JSObject> m_constructor;
+ JSC::Weak<JSC::Structure> m_structure;
}
- (instancetype)initForClass:(Class)cls;
@@ -517,10 +518,14 @@
}
}
- JSC::JSObject* prototype = [self prototypeInContext:context];
+ JSC::Structure* structure = [self structureInContext:context];
- JSC::JSObject* wrapper = makeWrapper([context JSGlobalContextRef], m_classRef, object);
- JSObjectSetPrototype([context JSGlobalContextRef], toRef(wrapper), toRef(prototype));
+ JSC::ExecState* exec = toJS([context JSGlobalContextRef]);
+ JSC::VM& vm = exec->vm();
+ JSC::JSLockHolder locker(vm);
+
+ JSC::JSCallbackObject<JSC::JSAPIWrapperObject>* wrapper = JSC::JSCallbackObject<JSC::JSAPIWrapperObject>::create(exec, exec->lexicalGlobalObject(), structure, m_classRef, 0);
+ wrapper->setWrappedObject(object);
return wrapper;
}
@@ -542,6 +547,20 @@
return prototype;
}
+- (JSC::Structure*)structureInContext:(JSContext *)context
+{
+ JSC::Structure* structure = m_structure.get();
+ if (structure)
+ return structure;
+
+ JSC::ExecState* exec = toJS([context JSGlobalContextRef]);
+ JSC::JSGlobalObject* globalObject = toJSGlobalObject([context JSGlobalContextRef]);
+ JSC::JSObject* prototype = [self prototypeInContext:context];
+ m_structure = JSC::JSCallbackObject<JSC::JSAPIWrapperObject>::createStructure(exec->vm(), globalObject, prototype);
+
+ return m_structure.get();
+}
+
@end
@implementation JSWrapperMap {
Added: trunk/Source/_javascript_Core/API/tests/JSWrapperMapTests.h (0 => 232936)
--- trunk/Source/_javascript_Core/API/tests/JSWrapperMapTests.h (rev 0)
+++ trunk/Source/_javascript_Core/API/tests/JSWrapperMapTests.h 2018-06-18 18:49:01 UTC (rev 232936)
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2018 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import <Foundation/Foundation.h>
+#import <_javascript_Core/_javascript_Core.h>
+
+#if JSC_OBJC_API_ENABLED
+
+void runJSWrapperMapTests();
+
+#endif // JSC_OBJC_API_ENABLED
+
Added: trunk/Source/_javascript_Core/API/tests/JSWrapperMapTests.mm (0 => 232936)
--- trunk/Source/_javascript_Core/API/tests/JSWrapperMapTests.mm (rev 0)
+++ trunk/Source/_javascript_Core/API/tests/JSWrapperMapTests.mm 2018-06-18 18:49:01 UTC (rev 232936)
@@ -0,0 +1,79 @@
+/*
+ * Copyright (C) 2018 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "config.h"
+#import "JSWrapperMapTests.h"
+
+#import "APICast.h"
+#import "HeapCellInlines.h"
+#import "JSValue.h"
+
+#if JSC_OBJC_API_ENABLED
+
+extern "C" void checkResult(NSString *description, bool passed);
+
+@protocol TestClassJSExport <JSExport>
+- (instancetype)init;
+@end
+
+@interface TestClass : NSObject <TestClassJSExport>
+@end
+
+@implementation TestClass
+@end
+
+
+@interface JSWrapperMapTests : NSObject
++ (void)testStructureIdentity;
+@end
+
+
+@implementation JSWrapperMapTests
++ (void)testStructureIdentity
+{
+ JSContext* context = [[JSContext alloc] init];
+ JSGlobalContextRef contextRef = JSGlobalContextRetain(context.JSGlobalContextRef);
+ JSC::ExecState* exec = toJS(contextRef);
+
+ context[@"TestClass"] = [TestClass class];
+ JSValue* aWrapper = [context evaluateScript:@"new TestClass()"];
+ JSValue* bWrapper = [context evaluateScript:@"new TestClass()"];
+ JSC::JSValue aValue = toJS(exec, aWrapper.JSValueRef);
+ JSC::JSValue bValue = toJS(exec, bWrapper.JSValueRef);
+ JSC::Structure* aStructure = aValue.structureOrNull();
+ JSC::Structure* bStructure = bValue.structureOrNull();
+ checkResult(@"structure should not be null", !!aStructure);
+ checkResult(@"both wrappers should share the same structure", aStructure == bStructure);
+}
+@end
+
+void runJSWrapperMapTests()
+{
+ @autoreleasepool {
+ [JSWrapperMapTests testStructureIdentity];
+ }
+}
+
+#endif // JSC_OBJC_API_ENABLED
Modified: trunk/Source/_javascript_Core/API/tests/testapi.mm (232935 => 232936)
--- trunk/Source/_javascript_Core/API/tests/testapi.mm 2018-06-18 18:31:06 UTC (rev 232935)
+++ trunk/Source/_javascript_Core/API/tests/testapi.mm 2018-06-18 18:49:01 UTC (rev 232936)
@@ -29,6 +29,7 @@
#import "DateTests.h"
#import "JSExportTests.h"
#import "JSVirtualMachinePrivate.h"
+#import "JSWrapperMapTests.h"
#import "Regress141275.h"
#import "Regress141809.h"
@@ -1475,6 +1476,7 @@
currentThisInsideBlockGetterTest();
runDateTests();
runJSExportTests();
+ runJSWrapperMapTests();
runRegress141275();
runRegress141809();
}
Modified: trunk/Source/_javascript_Core/ChangeLog (232935 => 232936)
--- trunk/Source/_javascript_Core/ChangeLog 2018-06-18 18:31:06 UTC (rev 232935)
+++ trunk/Source/_javascript_Core/ChangeLog 2018-06-18 18:49:01 UTC (rev 232936)
@@ -1,3 +1,27 @@
+2018-06-18 Tadeu Zagallo <tzaga...@apple.com>
+
+ Share structure across instances of classes exported through the ObjC API
+ https://bugs.webkit.org/show_bug.cgi?id=186579
+ <rdar://problem/40969212>
+
+ Reviewed by Saam Barati.
+
+ A new structure was being created for each instance of exported ObjC
+ classes due to setting the prototype in the structure for every object,
+ since prototype transitions are not cached by the structure. Cache the
+ Structure in the JSObjcClassInfo to avoid the transition.
+
+ * API/JSWrapperMap.mm:
+ (-[JSObjCClassInfo wrapperForObject:inContext:]):
+ (-[JSObjCClassInfo structureInContext:]):
+ * API/tests/JSWrapperMapTests.h: Added.
+ * API/tests/JSWrapperMapTests.mm: Added.
+ (+[JSWrapperMapTests testStructureIdentity]):
+ (runJSWrapperMapTests):
+ * API/tests/testapi.mm:
+ (testObjectiveCAPIMain):
+ * _javascript_Core.xcodeproj/project.pbxproj:
+
2018-06-18 Michael Saboff <msab...@apple.com>
Support Unicode 11 in RegExp
Modified: trunk/Source/_javascript_Core/_javascript_Core.xcodeproj/project.pbxproj (232935 => 232936)
--- trunk/Source/_javascript_Core/_javascript_Core.xcodeproj/project.pbxproj 2018-06-18 18:31:06 UTC (rev 232935)
+++ trunk/Source/_javascript_Core/_javascript_Core.xcodeproj/project.pbxproj 2018-06-18 18:49:01 UTC (rev 232936)
@@ -762,6 +762,7 @@
1442566215EDE98D0066A49B /* JSWithScope.h in Headers */ = {isa = PBXBuildFile; fileRef = 1442566015EDE98D0066A49B /* JSWithScope.h */; settings = {ATTRIBUTES = (Private, ); }; };
144836E7132DA7BE005BE785 /* ConservativeRoots.h in Headers */ = {isa = PBXBuildFile; fileRef = 149DAAF212EB559D0083B12B /* ConservativeRoots.h */; settings = {ATTRIBUTES = (Private, ); }; };
145722861437E140005FDE26 /* StrongInlines.h in Headers */ = {isa = PBXBuildFile; fileRef = 145722851437E140005FDE26 /* StrongInlines.h */; settings = {ATTRIBUTES = (Private, ); }; };
+ 1471483020D323D30090E630 /* JSWrapperMapTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1471482F20D323650090E630 /* JSWrapperMapTests.mm */; };
147341CC1DC02D7200AA29BA /* ExecutableBase.h in Headers */ = {isa = PBXBuildFile; fileRef = 147341CB1DC02D7200AA29BA /* ExecutableBase.h */; settings = {ATTRIBUTES = (Private, ); }; };
147341CE1DC02D7900AA29BA /* ScriptExecutable.h in Headers */ = {isa = PBXBuildFile; fileRef = 147341CD1DC02D7900AA29BA /* ScriptExecutable.h */; settings = {ATTRIBUTES = (Private, ); }; };
147341D01DC02DB400AA29BA /* NativeExecutable.h in Headers */ = {isa = PBXBuildFile; fileRef = 147341CF1DC02DB400AA29BA /* NativeExecutable.h */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -3083,6 +3084,8 @@
146B14DB12EB5B12001BEC1B /* ConservativeRoots.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ConservativeRoots.cpp; sourceTree = "<group>"; };
146FA5A81378F6B0003627A3 /* HandleTypes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HandleTypes.h; sourceTree = "<group>"; };
146FE51111A710430087AE66 /* JITCall32_64.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JITCall32_64.cpp; sourceTree = "<group>"; };
+ 1471482E20D323640090E630 /* JSWrapperMapTests.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = JSWrapperMapTests.h; path = API/tests/JSWrapperMapTests.h; sourceTree = "<group>"; };
+ 1471482F20D323650090E630 /* JSWrapperMapTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = JSWrapperMapTests.mm; path = API/tests/JSWrapperMapTests.mm; sourceTree = "<group>"; };
147341CB1DC02D7200AA29BA /* ExecutableBase.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ExecutableBase.h; sourceTree = "<group>"; };
147341CD1DC02D7900AA29BA /* ScriptExecutable.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScriptExecutable.h; sourceTree = "<group>"; };
147341CF1DC02DB400AA29BA /* NativeExecutable.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NativeExecutable.h; sourceTree = "<group>"; };
@@ -5432,6 +5435,8 @@
0FF47C591EBFE83500F280B7 /* JSObjectGetProxyTargetTest.h */,
5C4E8E941DBEBDA20036F1FC /* JSONParseTest.cpp */,
5C4E8E951DBEBDA20036F1FC /* JSONParseTest.h */,
+ 1471482E20D323640090E630 /* JSWrapperMapTests.h */,
+ 1471482F20D323650090E630 /* JSWrapperMapTests.mm */,
144005170A531CB50005F061 /* minidom */,
FEF49AA91EB947FE00653BDB /* MultithreadedMultiVMExecutionTest.cpp */,
FEF49AAA1EB947FE00653BDB /* MultithreadedMultiVMExecutionTest.h */,
@@ -10154,6 +10159,7 @@
C2181FC218A948FB0025A235 /* JSExportTests.mm in Sources */,
0FF47C5A1EBFE84600F280B7 /* JSObjectGetProxyTargetTest.cpp in Sources */,
5C4E8E961DBEBE620036F1FC /* JSONParseTest.cpp in Sources */,
+ 1471483020D323D30090E630 /* JSWrapperMapTests.mm in Sources */,
FEF49AAB1EB9484B00653BDB /* MultithreadedMultiVMExecutionTest.cpp in Sources */,
FE7C41961B97FC4B00F4D598 /* PingPongStackOverflowTest.cpp in Sources */,
65570F5A1AA4C3EA009B3C23 /* Regress141275.mm in Sources */,