Changeset 17017 in webkit for trunk/JavaScriptCore
- Timestamp:
- Oct 12, 2006, 1:42:56 PM (19 years ago)
- Location:
- trunk/JavaScriptCore
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/API/JSClassRef.cpp
r16371 r17017 93 93 } 94 94 95 JSClassRef OpaqueJSClass::createNo Prototype(const JSClassDefinition* definition)95 JSClassRef OpaqueJSClass::createNoAutomaticPrototype(const JSClassDefinition* definition) 96 96 { 97 97 return new OpaqueJSClass(definition, 0); … … 114 114 OpaqueJSClass* protoClass = new OpaqueJSClass(&protoDefinition, 0); 115 115 116 // remove functions from the original definition116 // remove functions from the original class 117 117 JSClassDefinition objectDefinition = *definition; 118 118 objectDefinition.staticFunctions = 0; -
trunk/JavaScriptCore/API/JSClassRef.h
r15497 r17017 58 58 struct OpaqueJSClass { 59 59 static OpaqueJSClass* create(const JSClassDefinition*); 60 static OpaqueJSClass* createNo Prototype(const JSClassDefinition*);60 static OpaqueJSClass* createNoAutomaticPrototype(const JSClassDefinition*); 61 61 ~OpaqueJSClass(); 62 62 -
trunk/JavaScriptCore/API/JSObjectRef.cpp
r16371 r17017 45 45 JSClassRef JSClassCreate(JSClassDefinition* definition) 46 46 { 47 JSClassRef jsClass = (definition->attributes & kJSClassAttributeNo Prototype)48 ? OpaqueJSClass::createNo Prototype(definition)47 JSClassRef jsClass = (definition->attributes & kJSClassAttributeNoAutomaticPrototype) 48 ? OpaqueJSClass::createNoAutomaticPrototype(definition) 49 49 : OpaqueJSClass::create(definition); 50 50 … … 69 69 ExecState* exec = toJS(ctx); 70 70 71 JSValue* jsPrototype = jsClass 72 ? jsClass->prototype(ctx) 73 : exec->lexicalInterpreter()->builtinObjectPrototype(); 74 75 return JSObjectMakeWithPrototype(ctx, jsClass, data, toRef(jsPrototype)); 76 } 77 78 JSObjectRef JSObjectMakeWithPrototype(JSContextRef ctx, JSClassRef jsClass, void* data, JSValueRef prototype) 79 { 80 JSLock lock; 81 82 ExecState* exec = toJS(ctx); 83 JSValue* jsPrototype = toJS(prototype); 84 85 if (!prototype) 71 if (!jsClass) 72 return toRef(new JSObject(exec->lexicalInterpreter()->builtinObjectPrototype())); // slightly more efficient 73 74 JSValue* jsPrototype = jsClass->prototype(ctx); 75 if (!jsPrototype) 86 76 jsPrototype = exec->lexicalInterpreter()->builtinObjectPrototype(); 87 77 88 if (!jsClass)89 return toRef(new JSObject(jsPrototype)); // slightly more efficient90 91 78 return toRef(new JSCallbackObject(exec, jsClass, jsPrototype, data)); 92 79 } -
trunk/JavaScriptCore/API/JSObjectRef.h
r15497 r17017 61 61 @enum JSClassAttribute 62 62 @constant kJSClassAttributeNone Specifies that a class has no special attributes. 63 @constant kJSClassAttributeNo Prototype Specifies that a class should not generate a prototype object. Use kJSClassAttributeNoPrototype in combination with JSObjectMakeWithPrototype to manage prototypes manually.63 @constant kJSClassAttributeNoAutomaticPrototype Specifies that a class should not automatically generate a shared prototype for its instance objects. Use kJSClassAttributeNoAutomaticPrototype in combination with JSObjectSetPrototype to manage prototypes manually. 64 64 */ 65 65 enum { 66 66 kJSClassAttributeNone = 0, 67 kJSClassAttributeNo Prototype = 1 << 167 kJSClassAttributeNoAutomaticPrototype = 1 << 1 68 68 }; 69 69 … … 330 330 }; 331 331 332 Standard JavaScript practice calls for storing function s in prototype objects, so derived objects can share them. Therefore, it is common for prototypes to have function properties but no value properties, and for objects to have value properties but no function properties. The default behavior of JSClassCreate is to follow this idiom, automatically generating a prototype in which to store the class's function properties. The kJSClassAttributeNoPrototype attribute overrides the idiom, specifying that all supplied function and value properties should be stored directly in the object.332 Standard JavaScript practice calls for storing function objects in prototypes, so they can be shared. The default JSClass created by JSClassCreate follows this idiom, instantiating objects with a shared, automatically generating prototype containing the class's function objects. The kJSClassAttributeNoAutomaticPrototype attribute specifies that a JSClass should not automatically generate such a prototype. The resulting JSClass instantiates objects with the default object prototype, and gives each instance object its own copy of the class's function objects. 333 333 334 334 A NULL callback specifies that the default object callback should substitute, except in the case of hasProperty, where it specifies that getProperty should substitute. … … 363 363 364 364 JSClassDefinition definition = kJSClassDefinitionEmpty; 365 366 365 definition.finalize = Finalize; 367 366 */ … … 398 397 @param data A void* to set as the object's private data. Pass NULL to specify no private data. 399 398 @result A JSObject with the given class and private data. 400 @discussion JSObjectMake assigns jsClass's automatically generated prototype to the object it creates. If jsClass has no automatically generated prototype, JSObjectMake uses the default object prototype.399 @discussion The default object class does not allocate storage for private data, so you must provide a non-NULL jsClass to JSObjectMake if you want your object to be able to store private data. 401 400 402 401 data is 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. 403 404 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.405 402 */ 406 403 JSObjectRef JSObjectMake(JSContextRef ctx, JSClassRef jsClass, void* data); 407 408 /*!409 @function410 @abstract Creates a JavaScript object with a given prototype.411 @param ctx The execution context to use.412 @param jsClass The JSClass to assign to the object. Pass NULL to use the default object class.413 @param prototype The prototype to assign to the object. Pass NULL to use the default object prototype.414 @param data A void* to set as the object's private data. Pass NULL to specify no private data.415 @result A JSObject with the given class, private data, and prototype.416 @discussion Use JSObjectMakeWithPrototype in combination with kJSClassAttributeNoPrototype to manage prototypes manually.417 418 data is 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.419 420 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.421 */422 JSObjectRef JSObjectMakeWithPrototype(JSContextRef ctx, JSClassRef jsClass, void* data, JSValueRef prototype);423 404 424 405 /*! -
trunk/JavaScriptCore/API/testapi.c
r16156 r17017 498 498 JSValueRef jsOne = JSValueMakeNumber(context, 1); 499 499 JSValueRef jsOneThird = JSValueMakeNumber(context, 1.0 / 3.0); 500 JSObjectRef jsObjectNoProto = JSObjectMakeWithPrototype(context, NULL, NULL, JSValueMakeNull(context)); 500 JSObjectRef jsObjectNoProto = JSObjectMake(context, NULL, NULL); 501 JSObjectSetPrototype(context, jsObjectNoProto, JSValueMakeNull(context)); 501 502 502 503 // FIXME: test funny utf8 characters … … 793 794 794 795 JSClassDefinition nullDefinition = kJSClassDefinitionEmpty; 795 nullDefinition.attributes = kJSClassAttributeNo Prototype;796 nullDefinition.attributes = kJSClassAttributeNoAutomaticPrototype; 796 797 JSClassRef nullClass = JSClassCreate(&nullDefinition); 797 798 JSClassRelease(nullClass); -
trunk/JavaScriptCore/ChangeLog
r17015 r17017 1 2006-10-12 Geoffrey Garen <[email protected]> 2 3 Reviewed by Maciej. 4 5 Removed JSObjectMakeWithPrototype, clarified some comments. We really 6 don't want people to manage their own prototypes, so we don't want an 7 extra function in the API devoted to just that. People can still manage 8 their own prototypes if they really want by using JSObjectSetPrototype. 9 10 * API/JSClassRef.cpp: 11 (OpaqueJSClass::createNoAutomaticPrototype): 12 (OpaqueJSClass::create): 13 * API/JSClassRef.h: 14 * API/JSObjectRef.cpp: 15 (JSClassCreate): 16 (JSObjectMake): 17 * API/JSObjectRef.h: 18 * API/testapi.c: 19 (main): 20 * JavaScriptCore.exp: 21 1 22 2006-10-12 Kevin McCullough <[email protected]> 2 23 -
trunk/JavaScriptCore/JavaScriptCore.exp
r16200 r17017 25 25 _JSObjectMakeFunction 26 26 _JSObjectMakeFunctionWithCallback 27 _JSObjectMakeWithPrototype28 27 _JSObjectSetPrivate 29 28 _JSObjectSetProperty
Note:
See TracChangeset
for help on using the changeset viewer.