Changeset 15497 in webkit for trunk/JavaScriptCore/API/JSClassRef.cpp
- Timestamp:
- Jul 17, 2006, 9:33:46 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/API/JSClassRef.cpp
r15480 r15497 25 25 */ 26 26 27 #include "APICast.h" 28 #include "JSCallbackObject.h" 27 29 #include "JSClassRef.h" 28 30 #include "JSObjectRef.h" … … 31 33 using namespace KJS; 32 34 33 const JSClassDefinition kJSClassDefinition Null = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };35 const JSClassDefinition kJSClassDefinitionEmpty = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 34 36 35 OpaqueJSClass::OpaqueJSClass( JSClassDefinition* definition)37 OpaqueJSClass::OpaqueJSClass(const JSClassDefinition* definition, OpaqueJSClass* protoClass) 36 38 : refCount(0) 37 39 , className(definition->className) 38 40 , parentClass(definition->parentClass) 41 , prototypeClass(0) 39 42 , staticValues(0) 40 43 , staticFunctions(0) … … 68 71 } 69 72 } 73 74 if (protoClass) 75 prototypeClass = JSClassRetain(protoClass); 70 76 } 71 77 … … 81 87 delete staticFunctions; 82 88 } 89 90 if (prototypeClass) 91 JSClassRelease(prototypeClass); 83 92 } 93 94 JSClassRef OpaqueJSClass::createNoPrototype(const JSClassDefinition* definition) 95 { 96 return new OpaqueJSClass(definition, 0); 97 } 98 99 void clearReferenceToPrototype(JSObjectRef prototype) 100 { 101 OpaqueJSClass* jsClass = static_cast<OpaqueJSClass*>(JSObjectGetPrivate(prototype)); 102 ASSERT(jsClass); 103 jsClass->cachedPrototype = 0; 104 } 105 106 JSClassRef OpaqueJSClass::create(const JSClassDefinition* definition) 107 { 108 if (JSStaticFunction* staticFunctions = definition->staticFunctions) { 109 // copy functions into a prototype class 110 JSClassDefinition protoDefinition = kJSClassDefinitionEmpty; 111 protoDefinition.staticFunctions = staticFunctions; 112 protoDefinition.finalize = clearReferenceToPrototype; 113 OpaqueJSClass* protoClass = new OpaqueJSClass(&protoDefinition, 0); 114 115 // remove functions from the original definition 116 JSClassDefinition objectDefinition = *definition; 117 objectDefinition.staticFunctions = 0; 118 return new OpaqueJSClass(&objectDefinition, protoClass); 119 } 120 121 return new OpaqueJSClass(definition, 0); 122 } 123 124 /*! 125 // Doc here in case we make this public. (Hopefully we won't.) 126 @function 127 @abstract Returns the prototype that will be used when constructing an object with a given class. 128 @param ctx The execution context to use. 129 @param jsClass A JSClass whose prototype you want to get. 130 @result The JSObject prototype that was automatically generated for jsClass, or NULL if no prototype was automatically generated. This is the prototype that will be used when constructing an object using jsClass. 131 */ 132 JSObject* OpaqueJSClass::prototype(JSContextRef ctx) 133 { 134 /* Class (C++) and prototype (JS) inheritance are parallel, so: 135 * (C++) | (JS) 136 * ParentClass | ParentClassPrototype 137 * ^ | ^ 138 * | | | 139 * DerivedClass | DerivedClassPrototype 140 */ 141 142 if (!prototypeClass) 143 return 0; 144 145 ExecState* exec = toJS(ctx); 146 147 if (!cachedPrototype) { 148 // Recursive, but should be good enough for our purposes 149 JSObject* parentPrototype = 0; 150 if (parentClass) 151 parentPrototype = parentClass->prototype(ctx); // can be null 152 if (!parentPrototype) 153 parentPrototype = exec->dynamicInterpreter()->builtinObjectPrototype(); 154 cachedPrototype = new JSCallbackObject(exec, prototypeClass, parentPrototype, this); // set ourself as the object's private data, so it can clear our reference on destruction 155 } 156 return cachedPrototype; 157 }
Note:
See TracChangeset
for help on using the changeset viewer.