Changeset 17017 in webkit for trunk/JavaScriptCore


Ignore:
Timestamp:
Oct 12, 2006, 1:42:56 PM (19 years ago)
Author:
ggaren
Message:

Reviewed by Maciej.


Removed JSObjectMakeWithPrototype, clarified some comments. We really
don't want people to manage their own prototypes, so we don't want an
extra function in the API devoted to just that. People can still manage
their own prototypes if they really want by using JSObjectSetPrototype.

  • API/JSClassRef.cpp: (OpaqueJSClass::createNoAutomaticPrototype): (OpaqueJSClass::create):
  • API/JSClassRef.h:
  • API/JSObjectRef.cpp: (JSClassCreate): (JSObjectMake):
  • API/JSObjectRef.h:
  • API/testapi.c: (main):
  • JavaScriptCore.exp:
Location:
trunk/JavaScriptCore
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/API/JSClassRef.cpp

    r16371 r17017  
    9393}
    9494
    95 JSClassRef OpaqueJSClass::createNoPrototype(const JSClassDefinition* definition)
     95JSClassRef OpaqueJSClass::createNoAutomaticPrototype(const JSClassDefinition* definition)
    9696{
    9797    return new OpaqueJSClass(definition, 0);
     
    114114        OpaqueJSClass* protoClass = new OpaqueJSClass(&protoDefinition, 0);
    115115
    116         // remove functions from the original definition
     116        // remove functions from the original class
    117117        JSClassDefinition objectDefinition = *definition;
    118118        objectDefinition.staticFunctions = 0;
  • trunk/JavaScriptCore/API/JSClassRef.h

    r15497 r17017  
    5858struct OpaqueJSClass {
    5959    static OpaqueJSClass* create(const JSClassDefinition*);
    60     static OpaqueJSClass* createNoPrototype(const JSClassDefinition*);
     60    static OpaqueJSClass* createNoAutomaticPrototype(const JSClassDefinition*);
    6161    ~OpaqueJSClass();
    6262   
  • trunk/JavaScriptCore/API/JSObjectRef.cpp

    r16371 r17017  
    4545JSClassRef JSClassCreate(JSClassDefinition* definition)
    4646{
    47     JSClassRef jsClass = (definition->attributes & kJSClassAttributeNoPrototype)
    48         ? OpaqueJSClass::createNoPrototype(definition)
     47    JSClassRef jsClass = (definition->attributes & kJSClassAttributeNoAutomaticPrototype)
     48        ? OpaqueJSClass::createNoAutomaticPrototype(definition)
    4949        : OpaqueJSClass::create(definition);
    5050   
     
    6969    ExecState* exec = toJS(ctx);
    7070
    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)
    8676        jsPrototype = exec->lexicalInterpreter()->builtinObjectPrototype();
    8777
    88     if (!jsClass)
    89         return toRef(new JSObject(jsPrototype)); // slightly more efficient
    90    
    9178    return toRef(new JSCallbackObject(exec, jsClass, jsPrototype, data));
    9279}
  • trunk/JavaScriptCore/API/JSObjectRef.h

    r15497 r17017  
    6161@enum JSClassAttribute
    6262@constant kJSClassAttributeNone Specifies that a class has no special attributes.
    63 @constant kJSClassAttributeNoPrototype 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.
    6464*/
    6565enum {
    6666    kJSClassAttributeNone = 0,
    67     kJSClassAttributeNoPrototype = 1 << 1
     67    kJSClassAttributeNoAutomaticPrototype = 1 << 1
    6868};
    6969
     
    330330};
    331331
    332 Standard JavaScript practice calls for storing functions 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.
     332Standard 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.
    333333
    334334A NULL callback specifies that the default object callback should substitute, except in the case of hasProperty, where it specifies that getProperty should substitute.
     
    363363
    364364JSClassDefinition definition = kJSClassDefinitionEmpty;
    365 
    366365definition.finalize = Finalize;
    367366*/
     
    398397@param data A void* to set as the object's private data. Pass NULL to specify no private data.
    399398@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.
    401400
    402401data 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.
    405402*/
    406403JSObjectRef JSObjectMake(JSContextRef ctx, JSClassRef jsClass, void* data);
    407 
    408 /*!
    409 @function
    410 @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);
    423404
    424405/*!
  • trunk/JavaScriptCore/API/testapi.c

    r16156 r17017  
    498498    JSValueRef jsOne = JSValueMakeNumber(context, 1);
    499499    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));
    501502
    502503    // FIXME: test funny utf8 characters
     
    793794
    794795    JSClassDefinition nullDefinition = kJSClassDefinitionEmpty;
    795     nullDefinition.attributes = kJSClassAttributeNoPrototype;
     796    nullDefinition.attributes = kJSClassAttributeNoAutomaticPrototype;
    796797    JSClassRef nullClass = JSClassCreate(&nullDefinition);
    797798    JSClassRelease(nullClass);
  • trunk/JavaScriptCore/ChangeLog

    r17015 r17017  
     12006-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
    1222006-10-12  Kevin McCullough  <[email protected]>
    223
  • trunk/JavaScriptCore/JavaScriptCore.exp

    r16200 r17017  
    2525_JSObjectMakeFunction
    2626_JSObjectMakeFunctionWithCallback
    27 _JSObjectMakeWithPrototype
    2827_JSObjectSetPrivate
    2928_JSObjectSetProperty
Note: See TracChangeset for help on using the changeset viewer.