Changeset 53657 in webkit for trunk/JavaScriptCore/API
- Timestamp:
- Jan 21, 2010, 4:06:00 PM (15 years ago)
- Location:
- trunk/JavaScriptCore/API
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/API/JSClassRef.cpp
r53642 r53657 35 35 #include <runtime/Identifier.h> 36 36 37 using namespace std; 37 38 using namespace JSC; 38 39 … … 121 122 } 122 123 123 PassRefPtr<OpaqueJSClass> OpaqueJSClass::create(const JSClassDefinition* definition) 124 { 125 const JSStaticFunction* staticFunctions = definition->staticFunctions; 126 if (staticFunctions || definition->parentClass) { 127 // copy functions into a prototype class 128 JSClassDefinition protoDefinition = kJSClassDefinitionEmpty; 129 protoDefinition.staticFunctions = staticFunctions; 130 protoDefinition.finalize = clearReferenceToPrototype; 131 132 // We are supposed to use JSClassRetain/Release but since we know that we currently have 133 // the only reference to this class object we cheat and use a RefPtr instead. 134 RefPtr<OpaqueJSClass> protoClass = adoptRef(new OpaqueJSClass(&protoDefinition, 0)); 135 136 // remove functions from the original class 137 JSClassDefinition objectDefinition = *definition; 138 objectDefinition.staticFunctions = 0; 139 140 return adoptRef(new OpaqueJSClass(&objectDefinition, protoClass.get())); 141 } 142 143 return adoptRef(new OpaqueJSClass(definition, 0)); 124 PassRefPtr<OpaqueJSClass> OpaqueJSClass::create(const JSClassDefinition* clientDefinition) 125 { 126 JSClassDefinition definition = *clientDefinition; // Avoid modifying client copy. 127 128 JSClassDefinition protoDefinition = kJSClassDefinitionEmpty; 129 protoDefinition.finalize = clearReferenceToPrototype; 130 swap(definition.staticFunctions, protoDefinition.staticFunctions); // Move static functions to the prototype. 131 132 // We are supposed to use JSClassRetain/Release but since we know that we currently have 133 // the only reference to this class object we cheat and use a RefPtr instead. 134 RefPtr<OpaqueJSClass> protoClass = adoptRef(new OpaqueJSClass(&protoDefinition, 0)); 135 return adoptRef(new OpaqueJSClass(&definition, protoClass.get())); 144 136 } 145 137 -
trunk/JavaScriptCore/API/tests/testapi.c
r51068 r53657 624 624 } 625 625 626 static JSClassRef Derived2_class(JSContextRef context) 627 { 628 static JSClassRef jsClass; 629 if (!jsClass) { 630 JSClassDefinition definition = kJSClassDefinitionEmpty; 631 definition.parentClass = Derived_class(context); 632 jsClass = JSClassCreate(&definition); 633 } 634 return jsClass; 635 } 636 626 637 static JSValueRef print_callAsFunction(JSContextRef ctx, JSObjectRef functionObject, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) 627 638 { … … 1071 1082 ASSERT(!JSObjectGetPrivate(myConstructor)); 1072 1083 1084 string = JSStringCreateWithUTF8CString("Base"); 1085 JSObjectRef baseConstructor = JSObjectMakeConstructor(context, Base_class(context), NULL); 1086 JSObjectSetProperty(context, globalObject, string, baseConstructor, kJSPropertyAttributeNone, NULL); 1087 JSStringRelease(string); 1088 1073 1089 string = JSStringCreateWithUTF8CString("Derived"); 1074 1090 JSObjectRef derivedConstructor = JSObjectMakeConstructor(context, Derived_class(context), NULL); … … 1076 1092 JSStringRelease(string); 1077 1093 1094 string = JSStringCreateWithUTF8CString("Derived2"); 1095 JSObjectRef derived2Constructor = JSObjectMakeConstructor(context, Derived2_class(context), NULL); 1096 JSObjectSetProperty(context, globalObject, string, derived2Constructor, kJSPropertyAttributeNone, NULL); 1097 JSStringRelease(string); 1098 1078 1099 o = JSObjectMake(context, NULL, NULL); 1079 1100 JSObjectSetProperty(context, o, jsOneIString, JSValueMakeNumber(context, 1), kJSPropertyAttributeNone, NULL); … … 1174 1195 script = JSStringCreateWithUTF8CString(scriptUTF8); 1175 1196 result = JSEvaluateScript(context, script, NULL, NULL, 1, &exception); 1176 if ( JSValueIsUndefined(context, result))1197 if (result && JSValueIsUndefined(context, result)) 1177 1198 printf("PASS: Test script executed successfully.\n"); 1178 1199 else { -
trunk/JavaScriptCore/API/tests/testapi.js
r53638 r53657 170 170 derived = new Derived(); 171 171 172 shouldBe("derived instanceof Derived", true); 173 shouldBe("derived instanceof Base", true); 174 172 175 // base properties and functions return 1 when called/gotten; derived, 2 173 176 shouldBe("derived.baseProtoDup()", 2); … … 184 187 shouldBe("derived.derivedOnly = 0", 2) 185 188 shouldBe("derived.protoDup = 0", 2); 189 190 derived2 = new Derived2(); 191 192 shouldBe("derived2 instanceof Derived2", true); 193 shouldBe("derived2 instanceof Derived", true); 194 shouldBe("derived2 instanceof Base", true); 195 196 // base properties and functions return 1 when called/gotten; derived, 2 197 shouldBe("derived2.baseProtoDup()", 2); 198 shouldBe("derived2.baseProto()", 1); 199 shouldBe("derived2.baseDup", 2); 200 shouldBe("derived2.baseOnly", 1); 201 shouldBe("derived2.protoOnly()", 2); 202 shouldBe("derived2.protoDup", 2); 203 shouldBe("derived2.derivedOnly", 2) 204 205 // base properties throw 1 when set; derived, 2 206 shouldBe("derived2.baseDup = 0", 2); 207 shouldBe("derived2.baseOnly = 0", 1); 208 shouldBe("derived2.derivedOnly = 0", 2) 209 shouldBe("derived2.protoDup = 0", 2); 186 210 187 211 shouldBe('Object.getOwnPropertyDescriptor(derived, "baseProto")', undefined);
Note:
See TracChangeset
for help on using the changeset viewer.