Changeset 15484 in webkit for trunk/JavaScriptCore/API
- Timestamp:
- Jul 17, 2006, 3:49:28 AM (19 years ago)
- Location:
- trunk/JavaScriptCore/API
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/API/JSCallbackObject.cpp
r15483 r15484 38 38 const ClassInfo JSCallbackObject::info = { "CallbackObject", 0, 0, 0 }; 39 39 40 JSCallbackObject::JSCallbackObject(ExecState* exec, JSClassRef jsClass) 41 : JSObject() 42 { 43 init(exec, jsClass); 44 } 45 46 JSCallbackObject::JSCallbackObject(ExecState* exec, JSClassRef jsClass, JSValue* prototype) 40 JSCallbackObject::JSCallbackObject(ExecState* exec, JSClassRef jsClass, JSValue* prototype, void* data) 47 41 : JSObject(prototype) 48 42 { 49 init(exec, jsClass );50 } 51 52 void JSCallbackObject::init(ExecState* exec, JSClassRef jsClass )53 { 54 m_privateData = 0;43 init(exec, jsClass, data); 44 } 45 46 void JSCallbackObject::init(ExecState* exec, JSClassRef jsClass, void* data) 47 { 48 m_privateData = data; 55 49 m_class = JSClassRetain(jsClass); 56 50 … … 64 58 for (int i = initRoutines.size() - 1; i >= 0; i--) { 65 59 JSObjectInitializeCallback initialize = initRoutines[i]; 66 initialize(toRef(exec), toRef(this) , toRef(exec->exceptionSlot()));60 initialize(toRef(exec), toRef(this)); 67 61 } 68 62 } -
trunk/JavaScriptCore/API/JSCallbackObject.h
r15483 r15484 37 37 { 38 38 public: 39 JSCallbackObject(ExecState*, JSClassRef); 40 JSCallbackObject(ExecState*, JSClassRef, JSValue* prototype); 39 JSCallbackObject(ExecState*, JSClassRef, JSValue* prototype, void* data); 41 40 virtual ~JSCallbackObject(); 42 41 … … 78 77 JSCallbackObject(const JSCallbackObject&); 79 78 80 void init(ExecState*, JSClassRef );79 void init(ExecState*, JSClassRef jsClass, void*); 81 80 82 81 static JSValue* cachedValueGetter(ExecState*, JSObject*, const Identifier&, const PropertySlot&); -
trunk/JavaScriptCore/API/JSContextRef.cpp
r15481 r15484 42 42 if (globalObjectClass) 43 43 // FIXME: We need to pass a real ExecState here to support an initialize callback in globalObjectClass 44 globalObject = new JSCallbackObject(0, globalObjectClass );44 globalObject = new JSCallbackObject(0, globalObjectClass, 0, 0); 45 45 else 46 46 globalObject = new JSObject(); -
trunk/JavaScriptCore/API/JSNode.c
r15483 r15484 157 157 }; 158 158 159 static void JSNode_initialize(JSContextRef context, JSObjectRef object) 160 { 161 Node* node = JSObjectGetPrivate(object); 162 assert(node); 163 164 Node_ref(node); 165 } 166 159 167 static void JSNode_finalize(JSObjectRef object) 160 168 { … … 171 179 JSClassDefinition definition = kJSClassDefinitionNull; 172 180 definition.staticValues = JSNode_staticValues; 181 definition.initialize = JSNode_initialize; 173 182 definition.finalize = JSNode_finalize; 174 183 … … 182 191 static JSObjectRef prototype; 183 192 if (!prototype) { 184 prototype = JSObjectMake(context, JSNodePrototype_class(context), NULL , NULL);193 prototype = JSObjectMake(context, JSNodePrototype_class(context), NULL); 185 194 JSValueProtect(context, prototype); 186 195 } … … 190 199 JSObjectRef JSNode_new(JSContextRef context, Node* node) 191 200 { 192 Node_ref(node); 193 194 JSObjectRef jsNode = JSObjectMake(context, JSNode_class(context), JSNode_prototype(context), NULL); 195 JSObjectSetPrivate(jsNode, node); 196 return jsNode; 201 return JSObjectMakeWithData(context, JSNode_class(context), JSNode_prototype(context), node); 197 202 } 198 203 -
trunk/JavaScriptCore/API/JSNodeList.c
r15483 r15484 89 89 } 90 90 91 static void JSNodeList_initialize(JSContextRef context, JSObjectRef thisObject) 92 { 93 NodeList* nodeList = JSObjectGetPrivate(thisObject); 94 assert(nodeList); 95 96 NodeList_ref(nodeList); 97 } 98 91 99 static void JSNodeList_finalize(JSObjectRef thisObject) 92 100 { 93 101 NodeList* nodeList = JSObjectGetPrivate(thisObject); 94 102 assert(nodeList); 103 95 104 NodeList_deref(nodeList); 96 105 } … … 103 112 definition.staticValues = JSNodeList_staticValues; 104 113 definition.getProperty = JSNodeList_getProperty; 114 definition.initialize = JSNodeList_initialize; 105 115 definition.finalize = JSNodeList_finalize; 106 116 … … 115 125 static JSObjectRef prototype; 116 126 if (!prototype) { 117 prototype = JSObjectMake(context, JSNodeListPrototype_class(context), NULL , NULL);127 prototype = JSObjectMake(context, JSNodeListPrototype_class(context), NULL); 118 128 JSValueProtect(context, prototype); 119 129 } … … 123 133 JSObjectRef JSNodeList_new(JSContextRef context, NodeList* nodeList) 124 134 { 125 NodeList_ref(nodeList); 126 127 JSObjectRef jsNodeList = JSObjectMake(context, JSNodeList_class(context), JSNodeList_prototype(context), NULL); 128 JSObjectSetPrivate(jsNodeList, nodeList); 129 return jsNodeList; 135 return JSObjectMakeWithData(context, JSNodeList_class(context), JSNodeList_prototype(context), nodeList); 130 136 } -
trunk/JavaScriptCore/API/JSObjectRef.cpp
r15483 r15484 60 60 } 61 61 62 JSObjectRef JSObjectMake(JSContextRef ctx, JSClassRef jsClass, JSValueRef prototype, JSValueRef* exception) 62 JSObjectRef JSObjectMake(JSContextRef ctx, JSClassRef jsClass, JSValueRef prototype) 63 { 64 return JSObjectMakeWithData(ctx, jsClass, prototype, 0); 65 } 66 67 JSObjectRef JSObjectMakeWithData(JSContextRef ctx, JSClassRef jsClass, JSValueRef prototype, void* data) 63 68 { 64 69 JSLock lock; … … 70 75 jsPrototype = exec->lexicalInterpreter()->builtinObjectPrototype(); 71 76 72 JSObjectRef result; 73 if (jsClass) { 74 result = toRef(new JSCallbackObject(exec, jsClass, jsPrototype)); 75 if (exec->hadException()) { 76 if (exception) 77 *exception = toRef(exec->exception()); 78 exec->clearException(); 79 } 80 } else 81 result = toRef(new JSObject(jsPrototype)); // slightly more efficient -- and can't throw 82 83 return result; 77 if (!jsClass) 78 return toRef(new JSObject(jsPrototype)); // slightly more efficient 79 80 return toRef(new JSCallbackObject(exec, jsClass, jsPrototype, data)); // initialize can't throw 84 81 } 85 82 -
trunk/JavaScriptCore/API/JSObjectRef.h
r15483 r15484 63 63 @param ctx The execution context to use. 64 64 @param object The JSObject being created. 65 @param exception A pointer to a JSValueRef in which to return an exception, if any.66 65 @discussion If you named your function Initialize, you would declare it like this: 67 66 68 void Initialize(JSContextRef ctx, JSObjectRef object , JSValueRef* exception);67 void Initialize(JSContextRef ctx, JSObjectRef object); 69 68 70 69 Unlike the other object callbacks, the initialize callback is called on the least … … 72 71 */ 73 72 typedef void 74 (*JSObjectInitializeCallback) (JSContextRef ctx, JSObjectRef object , JSValueRef* exception);73 (*JSObjectInitializeCallback) (JSContextRef ctx, JSObjectRef object); 75 74 76 75 /*! … … 380 379 /*! 381 380 @function 382 @abstract Creates a JavaScript object with a given class and prototype.381 @abstract Creates a JavaScript object. 383 382 @param ctx The execution context to use. 384 383 @param jsClass The JSClass to assign to the object. Pass NULL to use the default object class. 385 384 @param prototype The prototype to assign to the object. Pass NULL to use the default object prototype. 386 @param exception A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception. 387 @result A JSObject with the given class and prototype. 388 */ 389 JSObjectRef JSObjectMake(JSContextRef ctx, JSClassRef jsClass, JSValueRef prototype, JSValueRef* exception); 385 @result A JSObject with the given class, prototype, and private data. 386 @discussion The default object class does not allocate storage for private data, so you must provide a non-NULL JSClass if you want your object to be able to store private data. 387 */ 388 JSObjectRef JSObjectMake(JSContextRef ctx, JSClassRef jsClass, JSValueRef prototype); 389 390 /*! 391 @function 392 @abstract Creates a JavaScript object. 393 @param ctx The execution context to use. 394 @param jsClass The JSClass to assign to the object. Pass NULL to use the default object class. 395 @param prototype The prototype to assign to the object. Pass NULL to use the default object prototype. 396 @param data A void* to set as the object's private data. Pass NULL to specify no private data. 397 @param exception A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception. 398 @result A JSObject with the given class, prototype, and private data. 399 @discussion The default object class does not allocate storage for private data, so you must provide a non-NULL JSClass if you want your object to be able to store private data. 400 401 data will be set on the created object before the intialize methods in its class chain are called. This enables the initialize methods to retrieve and manipulate data through JSObjectGetPrivate. 402 */ 403 JSObjectRef JSObjectMakeWithData(JSContextRef ctx, JSClassRef jsClass, JSValueRef prototype, void* data); 390 404 391 405 /*! … … 512 526 /*! 513 527 @function 514 @abstract Gets a pointer to private data from an object.528 @abstract Gets an object's private data. 515 529 @param object A JSObject whose private data you want to get. 516 @result A void* that points tothe object's private data, if the object has private data, otherwise NULL.530 @result A void* that is the object's private data, if the object has private data, otherwise NULL. 517 531 */ 518 532 void* JSObjectGetPrivate(JSObjectRef object); … … 522 536 @abstract Sets a pointer to private data on an object. 523 537 @param object A JSObject whose private data you want to set. 524 @param data A void* t hat points tothe object's private data.538 @param data A void* to set as the object's private data. 525 539 @result true if the object can store private data, otherwise false. 526 @discussion Only custom objects created with aJSClass can store private data.540 @discussion The default object class does not allocate storage for private data. Only objects created with a non-NULL JSClass can store private data. 527 541 */ 528 542 bool JSObjectSetPrivate(JSObjectRef object, void* data); -
trunk/JavaScriptCore/API/minidom.c
r15482 r15484 65 65 free(scriptUTF8); 66 66 67 #if 0 // used for leak/finalize debugging 68 int i; 69 for (i = 0; i < 1000; i++) { 70 JSObjectRef o = JSObjectMake(context, NULL, NULL); 71 (void)o; 72 } 73 JSGarbageCollect(); 74 #endif 75 67 globalObject = 0; 76 68 JSGlobalContextRelease(context); 69 JSGarbageCollect(context); 77 70 printf("PASS: Program exited normally.\n"); 78 71 return 0; -
trunk/JavaScriptCore/API/minidom.js
r15482 r15484 199 199 node.appendChild(child2); 200 200 201 for (var i = 0; i < node.childNodes.length + 1; i++) { 202 print("item " + i + ": " + node.childNodes.item(i)); 203 } 204 205 for (var i = 0; i < node.childNodes.length + 1; i++) { 206 print(i + ": " + node.childNodes[i]); 201 var childNodes = node.childNodes; 202 203 for (var i = 0; i < childNodes.length + 1; i++) { 204 print("item " + i + ": " + childNodes.item(i)); 205 } 206 207 for (var i = 0; i < childNodes.length + 1; i++) { 208 print(i + ": " + childNodes[i]); 207 209 } 208 210 … … 210 212 node.replaceChild(child3, child2); 211 213 212 for (var i = 0; i < node.childNodes.length + 1; i++) {213 print("item " + i + ": " + node.childNodes.item(i));214 } 215 216 for (var i = 0; i < node.childNodes.length + 1; i++) {217 print(i + ": " + node.childNodes[i]);214 for (var i = 0; i < childNodes.length + 1; i++) { 215 print("item " + i + ": " + childNodes.item(i)); 216 } 217 218 for (var i = 0; i < childNodes.length + 1; i++) { 219 print(i + ": " + childNodes[i]); 218 220 } 219 221 -
trunk/JavaScriptCore/API/testapi.c
r15483 r15484 101 101 102 102 static bool didInitialize = false; 103 static void MyObject_initialize(JSContextRef context, JSObjectRef object , JSValueRef* exception)103 static void MyObject_initialize(JSContextRef context, JSObjectRef object) 104 104 { 105 105 UNUSED_PARAM(context); … … 291 291 } 292 292 293 static void Base_initialize(JSContextRef context, JSObjectRef object , JSValueRef* exception)293 static void Base_initialize(JSContextRef context, JSObjectRef object) 294 294 { 295 295 assert(!JSObjectGetPrivate(object)); … … 316 316 } 317 317 318 static void Derived_initialize(JSContextRef context, JSObjectRef object , JSValueRef* exception)318 static void Derived_initialize(JSContextRef context, JSObjectRef object) 319 319 { 320 320 assert((void*)1 == JSObjectGetPrivate(object)); … … 362 362 UNUSED_PARAM(constructorObject); 363 363 364 JSObjectRef result = JSObjectMake(context, NULL, 0,NULL);364 JSObjectRef result = JSObjectMake(context, NULL, NULL); 365 365 if (argumentCount > 0) { 366 366 JSStringRef value = JSStringCreateWithUTF8CString("value"); … … 391 391 JSValueRef jsOne = JSValueMakeNumber(context, 1); 392 392 JSValueRef jsOneThird = JSValueMakeNumber(context, 1.0 / 3.0); 393 JSObjectRef jsObjectNoProto = JSObjectMake(context, NULL, JSValueMakeNull(context) , NULL);393 JSObjectRef jsObjectNoProto = JSObjectMake(context, NULL, JSValueMakeNull(context)); 394 394 395 395 // FIXME: test funny utf8 characters … … 445 445 #endif // __APPLE__ 446 446 447 JSObjectRef myObject = JSObjectMake(context, MyObject_class(context), NULL , NULL);447 JSObjectRef myObject = JSObjectMake(context, MyObject_class(context), NULL); 448 448 assert(didInitialize); 449 449 JSStringRef myObjectIString = JSStringCreateWithUTF8CString("MyObject"); … … 559 559 #endif // __APPLE__ 560 560 561 jsGlobalValue = JSObjectMake(context, NULL, NULL , NULL);561 jsGlobalValue = JSObjectMake(context, NULL, NULL); 562 562 JSValueProtect(context, jsGlobalValue); 563 563 JSGarbageCollect(context); … … 667 667 assert(!JSObjectGetPrivate(myConstructor)); 668 668 669 o = JSObjectMake(context, NULL, NULL , NULL);669 o = JSObjectMake(context, NULL, NULL); 670 670 JSObjectSetProperty(context, o, jsOneIString, JSValueMakeNumber(context, 1), kJSPropertyAttributeNone, NULL); 671 671 JSObjectSetProperty(context, o, jsCFIString, JSValueMakeNumber(context, 1), kJSPropertyAttributeDontEnum, NULL); … … 690 690 assert(JSValueIsEqual(context, v, o, NULL)); 691 691 692 exception = NULL; 693 o = JSObjectMake(context, Derived_class(context), NULL, &exception); 694 assert(!exception); 692 o = JSObjectMake(context, Derived_class(context), NULL); 695 693 assert(JSObjectGetPrivate(o) == (void*)2); 696 694 o = NULL; … … 713 711 714 712 // Allocate a few dummies so that at least one will be collected 715 JSObjectMake(context, MyObject_class(context), NULL , NULL);716 JSObjectMake(context, MyObject_class(context), NULL , NULL);713 JSObjectMake(context, MyObject_class(context), NULL); 714 JSObjectMake(context, MyObject_class(context), NULL); 717 715 JSGarbageCollect(context); 718 716 assert(MyObject_didFinalize);
Note:
See TracChangeset
for help on using the changeset viewer.