JSClassRelease(prototypeClass);
}
-JSClassRef OpaqueJSClass::createNoPrototype(const JSClassDefinition* definition)
+JSClassRef OpaqueJSClass::createNoAutomaticPrototype(const JSClassDefinition* definition)
{
return new OpaqueJSClass(definition, 0);
}
protoDefinition.finalize = clearReferenceToPrototype;
OpaqueJSClass* protoClass = new OpaqueJSClass(&protoDefinition, 0);
- // remove functions from the original definition
+ // remove functions from the original class
JSClassDefinition objectDefinition = *definition;
objectDefinition.staticFunctions = 0;
return new OpaqueJSClass(&objectDefinition, protoClass);
struct OpaqueJSClass {
static OpaqueJSClass* create(const JSClassDefinition*);
- static OpaqueJSClass* createNoPrototype(const JSClassDefinition*);
+ static OpaqueJSClass* createNoAutomaticPrototype(const JSClassDefinition*);
~OpaqueJSClass();
KJS::JSObject* prototype(JSContextRef ctx);
JSClassRef JSClassCreate(JSClassDefinition* definition)
{
- JSClassRef jsClass = (definition->attributes & kJSClassAttributeNoPrototype)
- ? OpaqueJSClass::createNoPrototype(definition)
+ JSClassRef jsClass = (definition->attributes & kJSClassAttributeNoAutomaticPrototype)
+ ? OpaqueJSClass::createNoAutomaticPrototype(definition)
: OpaqueJSClass::create(definition);
return JSClassRetain(jsClass);
JSLock lock;
ExecState* exec = toJS(ctx);
- JSValue* jsPrototype = jsClass
- ? jsClass->prototype(ctx)
- : exec->lexicalInterpreter()->builtinObjectPrototype();
-
- return JSObjectMakeWithPrototype(ctx, jsClass, data, toRef(jsPrototype));
-}
-
-JSObjectRef JSObjectMakeWithPrototype(JSContextRef ctx, JSClassRef jsClass, void* data, JSValueRef prototype)
-{
- JSLock lock;
-
- ExecState* exec = toJS(ctx);
- JSValue* jsPrototype = toJS(prototype);
+ if (!jsClass)
+ return toRef(new JSObject(exec->lexicalInterpreter()->builtinObjectPrototype())); // slightly more efficient
- if (!prototype)
+ JSValue* jsPrototype = jsClass->prototype(ctx);
+ if (!jsPrototype)
jsPrototype = exec->lexicalInterpreter()->builtinObjectPrototype();
- if (!jsClass)
- return toRef(new JSObject(jsPrototype)); // slightly more efficient
-
return toRef(new JSCallbackObject(exec, jsClass, jsPrototype, data));
}
/*!
@enum JSClassAttribute
@constant kJSClassAttributeNone Specifies that a class has no special attributes.
-@constant kJSClassAttributeNoPrototype Specifies that a class should not generate a prototype object. Use kJSClassAttributeNoPrototype in combination with JSObjectMakeWithPrototype to manage prototypes manually.
+@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.
*/
enum {
kJSClassAttributeNone = 0,
- kJSClassAttributeNoPrototype = 1 << 1
+ kJSClassAttributeNoAutomaticPrototype = 1 << 1
};
/*!
{ 0, 0, 0, 0 }
};
-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.
+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.
A NULL callback specifies that the default object callback should substitute, except in the case of hasProperty, where it specifies that getProperty should substitute.
*/
@discussion Use this constant as a convenience when creating class definitions. For example, to create a class definition with only a finalize method:
JSClassDefinition definition = kJSClassDefinitionEmpty;
-
definition.finalize = Finalize;
*/
extern const JSClassDefinition kJSClassDefinitionEmpty;
@param jsClass The JSClass to assign to the object. Pass NULL to use the default object class.
@param data A void* to set as the object's private data. Pass NULL to specify no private data.
@result A JSObject with the given class and private data.
-@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.
+@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.
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.
-
-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.
*/
JSObjectRef JSObjectMake(JSContextRef ctx, JSClassRef jsClass, void* data);
-/*!
-@function
-@abstract Creates a JavaScript object with a given prototype.
-@param ctx The execution context to use.
-@param jsClass The JSClass to assign to the object. Pass NULL to use the default object class.
-@param prototype The prototype to assign to the object. Pass NULL to use the default object prototype.
-@param data A void* to set as the object's private data. Pass NULL to specify no private data.
-@result A JSObject with the given class, private data, and prototype.
-@discussion Use JSObjectMakeWithPrototype in combination with kJSClassAttributeNoPrototype to manage prototypes manually.
-
-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.
-
-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.
-*/
-JSObjectRef JSObjectMakeWithPrototype(JSContextRef ctx, JSClassRef jsClass, void* data, JSValueRef prototype);
-
/*!
@function
@abstract Convenience method for creating a JavaScript function with a given callback as its implementation.
JSValueRef jsZero = JSValueMakeNumber(context, 0);
JSValueRef jsOne = JSValueMakeNumber(context, 1);
JSValueRef jsOneThird = JSValueMakeNumber(context, 1.0 / 3.0);
- JSObjectRef jsObjectNoProto = JSObjectMakeWithPrototype(context, NULL, NULL, JSValueMakeNull(context));
+ JSObjectRef jsObjectNoProto = JSObjectMake(context, NULL, NULL);
+ JSObjectSetPrototype(context, jsObjectNoProto, JSValueMakeNull(context));
// FIXME: test funny utf8 characters
JSStringRef jsEmptyIString = JSStringCreateWithUTF8CString("");
assert(count == 1); // jsCFString should not be enumerated
JSClassDefinition nullDefinition = kJSClassDefinitionEmpty;
- nullDefinition.attributes = kJSClassAttributeNoPrototype;
+ nullDefinition.attributes = kJSClassAttributeNoAutomaticPrototype;
JSClassRef nullClass = JSClassCreate(&nullDefinition);
JSClassRelease(nullClass);
+2006-10-12 Geoffrey Garen <ggaren@apple.com>
+
+ 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:
+
2006-10-12 Kevin McCullough <KMcCullough@apple.com>
Reviewed by Adam.
_JSObjectMakeFunction
_JSObjectMakeFunction
_JSObjectMakeFunctionWithCallback
-_JSObjectMakeWithPrototype
_JSObjectSetPrivate
_JSObjectSetProperty
_JSObjectSetPropertyAtIndex