diff --git a/js/src/jsapi.cpp b/js/src/jsapi.cpp index da894769892a..3b2eb7447351 100644 --- a/js/src/jsapi.cpp +++ b/js/src/jsapi.cpp @@ -2855,17 +2855,16 @@ JS_FinalizeStub(JSContext *cx, JSObject *obj) {} JS_PUBLIC_API(JSObject *) -JS_InitClassWithType(JSContext *cx, JSObject *obj, JSObject *parent_proto, - JSClass *clasp, JSNative constructor, uintN nargs, - JSTypeHandler ctorHandler, - JSPropertySpec *ps, JSFunctionSpec *fs, - JSPropertySpec *static_ps, JSFunctionSpec *static_fs) +JS_InitClass(JSContext *cx, JSObject *obj, JSObject *parent_proto, + JSClass *clasp, JSNative constructor, uintN nargs, + JSPropertySpec *ps, JSFunctionSpec *fs, + JSPropertySpec *static_ps, JSFunctionSpec *static_fs) { CHECK_REQUEST(cx); assertSameCompartment(cx, obj, parent_proto); return js_InitClass(cx, obj, parent_proto, Valueify(clasp), Valueify(constructor), nargs, - ctorHandler, ps, fs, static_ps, static_fs); + NULL, ps, fs, static_ps, static_fs); } #ifdef JS_THREADSAFE @@ -2949,18 +2948,6 @@ JS_SetPrototype(JSContext *cx, JSObject *obj, JSObject *proto) return SetProto(cx, obj, proto, JS_FALSE); } -JS_PUBLIC_API(void) -JS_SplicePrototype(JSContext *cx, JSObject *obj, JSObject *proto) -{ - /* - * Change the prototype of an object which hasn't been used anywhere - * and does not share its type with another object. Unlike JS_SetPrototype, - * does not nuke type information for the object. - */ - CHECK_REQUEST(cx); - obj->getType()->splicePrototype(cx, proto); -} - JS_PUBLIC_API(JSObject *) JS_GetParent(JSContext *cx, JSObject *obj) { @@ -3081,26 +3068,6 @@ JS_NewObject(JSContext *cx, JSClass *jsclasp, JSObject *proto, JSObject *parent) return obj; } -JS_PUBLIC_API(JSObject *) -JS_NewObjectWithUniqueType(JSContext *cx, JSClass *clasp, JSObject *proto, JSObject *parent) -{ - JSObject *obj = JS_NewObject(cx, clasp, proto, parent); - if (!obj) - return NULL; - - TypeObject *type = cx->compartment->types.newTypeObject(cx, NULL, "Unique", "", - false, false, proto); - if (!type) - return NULL; - if (obj->hasSpecialEquality()) - cx->markTypeObjectFlags(type, OBJECT_FLAG_SPECIAL_EQUALITY); - if (!obj->setTypeAndUniqueShape(cx, type)) - return NULL; - type->singleton = obj; - - return obj; -} - JS_PUBLIC_API(JSObject *) JS_NewObjectWithGivenProto(JSContext *cx, JSClass *jsclasp, JSObject *proto, JSObject *parent) { @@ -4221,9 +4188,8 @@ JS_GetSecurityCallbacks(JSContext *cx) } JS_PUBLIC_API(JSFunction *) -JS_NewFunctionWithType(JSContext *cx, JSNative native, uintN nargs, uintN flags, - JSObject *parent, const char *name, - JSTypeHandler handler) +JS_NewFunction(JSContext *cx, JSNative native, uintN nargs, uintN flags, + JSObject *parent, const char *name) { JS_THREADSAFE_ASSERT(cx->compartment != cx->runtime->atomsCompartment); JSAtom *atom; @@ -4238,7 +4204,7 @@ JS_NewFunctionWithType(JSContext *cx, JSNative native, uintN nargs, uintN flags, if (!atom) return NULL; } - return js_NewFunction(cx, NULL, Valueify(native), nargs, flags, parent, atom, handler, name); + return js_NewFunction(cx, NULL, Valueify(native), nargs, flags, parent, atom, NULL, name); } JS_PUBLIC_API(JSFunction *) @@ -4498,6 +4464,10 @@ JS_DefineFunctions(JSContext *cx, JSObject *obj, JSFunctionSpec *fs) for (; fs->name; fs++) { flags = fs->flags; + JSAtom *atom = js_Atomize(cx, fs->name, strlen(fs->name)); + if (!atom) + return JS_FALSE; + /* * Define a generic arity N+1 static method for the arity N prototype * method if flags contains JSFUN_GENERIC_NATIVE. @@ -4510,11 +4480,11 @@ JS_DefineFunctions(JSContext *cx, JSObject *obj, JSFunctionSpec *fs) } flags &= ~JSFUN_GENERIC_NATIVE; - fun = JS_DefineFunctionWithType(cx, ctor, fs->name, - Jsvalify(js_generic_native_method_dispatcher), - fs->nargs + 1, - flags & ~JSFUN_TRCINFO, - fs->handler); + fun = js_DefineFunction(cx, ctor, ATOM_TO_JSID(atom), + js_generic_native_method_dispatcher, + fs->nargs + 1, + flags & ~JSFUN_TRCINFO, + fs->handler, fs->name); if (!fun) return JS_FALSE; @@ -4530,8 +4500,8 @@ JS_DefineFunctions(JSContext *cx, JSObject *obj, JSFunctionSpec *fs) return JS_FALSE; } - fun = JS_DefineFunctionWithType(cx, obj, fs->name, fs->call, fs->nargs, flags, - fs->handler); + fun = js_DefineFunction(cx, obj, ATOM_TO_JSID(atom), Valueify(fs->call), fs->nargs, flags, + fs->handler, fs->name); if (!fun) return JS_FALSE; } @@ -4539,9 +4509,8 @@ JS_DefineFunctions(JSContext *cx, JSObject *obj, JSFunctionSpec *fs) } JS_PUBLIC_API(JSFunction *) -JS_DefineFunctionWithType(JSContext *cx, JSObject *obj, const char *name, JSNative call, - uintN nargs, uintN attrs, - JSTypeHandler handler) +JS_DefineFunction(JSContext *cx, JSObject *obj, const char *name, JSNative call, + uintN nargs, uintN attrs) { JS_THREADSAFE_ASSERT(cx->compartment != cx->runtime->atomsCompartment); CHECK_REQUEST(cx); @@ -4549,14 +4518,13 @@ JS_DefineFunctionWithType(JSContext *cx, JSObject *obj, const char *name, JSNati JSAtom *atom = js_Atomize(cx, name, strlen(name)); if (!atom) return NULL; - return js_DefineFunction(cx, obj, ATOM_TO_JSID(atom), Valueify(call), nargs, attrs, handler, name); + return js_DefineFunction(cx, obj, ATOM_TO_JSID(atom), Valueify(call), nargs, attrs, NULL, name); } JS_PUBLIC_API(JSFunction *) -JS_DefineUCFunctionWithType(JSContext *cx, JSObject *obj, - const jschar *name, size_t namelen, JSNative call, - uintN nargs, uintN attrs, - JSTypeHandler handler) +JS_DefineUCFunction(JSContext *cx, JSObject *obj, + const jschar *name, size_t namelen, JSNative call, + uintN nargs, uintN attrs) { JS_THREADSAFE_ASSERT(cx->compartment != cx->runtime->atomsCompartment); CHECK_REQUEST(cx); @@ -4564,7 +4532,7 @@ JS_DefineUCFunctionWithType(JSContext *cx, JSObject *obj, JSAtom *atom = js_AtomizeChars(cx, name, AUTO_NAMELEN(name, namelen)); if (!atom) return NULL; - return js_DefineFunction(cx, obj, ATOM_TO_JSID(atom), Valueify(call), nargs, attrs, handler, "UCFunction"); + return js_DefineFunction(cx, obj, ATOM_TO_JSID(atom), Valueify(call), nargs, attrs, NULL, "UCFunction"); } extern JS_PUBLIC_API(JSFunction *) diff --git a/js/src/jsapi.h b/js/src/jsapi.h index c75ce843da91..e4ab9d314a96 100644 --- a/js/src/jsapi.h +++ b/js/src/jsapi.h @@ -2133,22 +2133,10 @@ struct JSFunctionSpec { {name, (JSNative) call, nargs, (flags) | JSFUN_STUB_GSOPS, handler} extern JS_PUBLIC_API(JSObject *) -JS_InitClassWithType(JSContext *cx, JSObject *obj, JSObject *parent_proto, - JSClass *clasp, JSNative constructor, uintN nargs, - JSTypeHandler ctorHandler, - JSPropertySpec *ps, JSFunctionSpec *fs, - JSPropertySpec *static_ps, JSFunctionSpec *static_fs); - -static JS_ALWAYS_INLINE JSObject* JS_InitClass(JSContext *cx, JSObject *obj, JSObject *parent_proto, JSClass *clasp, JSNative constructor, uintN nargs, JSPropertySpec *ps, JSFunctionSpec *fs, - JSPropertySpec *static_ps, JSFunctionSpec *static_fs) -{ - return JS_InitClassWithType(cx, obj, parent_proto, clasp, constructor, - nargs, NULL, - ps, fs, static_ps, static_fs); -} + JSPropertySpec *static_ps, JSFunctionSpec *static_fs); #ifdef JS_THREADSAFE extern JS_PUBLIC_API(JSClass *) @@ -2184,9 +2172,6 @@ JS_GetPrototype(JSContext *cx, JSObject *obj); extern JS_PUBLIC_API(JSBool) JS_SetPrototype(JSContext *cx, JSObject *obj, JSObject *proto); -extern JS_PUBLIC_API(void) -JS_SplicePrototype(JSContext *cx, JSObject *obj, JSObject *proto); - extern JS_PUBLIC_API(JSObject *) JS_GetParent(JSContext *cx, JSObject *obj); @@ -2213,9 +2198,6 @@ JS_NewCompartmentAndGlobalObject(JSContext *cx, JSClass *clasp, JSPrincipals *pr extern JS_PUBLIC_API(JSObject *) JS_NewObject(JSContext *cx, JSClass *clasp, JSObject *proto, JSObject *parent); -extern JS_PUBLIC_API(JSObject *) -JS_NewObjectWithUniqueType(JSContext *cx, JSClass *clasp, JSObject *proto, JSObject *parent); - /* Queries the [[Extensible]] property of the object. */ extern JS_PUBLIC_API(JSBool) JS_IsExtensible(JSObject *obj); @@ -2630,16 +2612,8 @@ JS_GetSecurityCallbacks(JSContext *cx); * Functions and scripts. */ extern JS_PUBLIC_API(JSFunction *) -JS_NewFunctionWithType(JSContext *cx, JSNative call, uintN nargs, uintN flags, - JSObject *parent, const char *name, - JSTypeHandler handler); - -static JS_ALWAYS_INLINE JSFunction* JS_NewFunction(JSContext *cx, JSNative call, uintN nargs, uintN flags, - JSObject *parent, const char *name) -{ - return JS_NewFunctionWithType(cx, call, nargs, flags, parent, name, NULL); -} + JSObject *parent, const char *name); /* * Create the function with the name given by the id. JSID_IS_STRING(id) must @@ -2689,33 +2663,13 @@ extern JS_PUBLIC_API(JSBool) JS_DefineFunctions(JSContext *cx, JSObject *obj, JSFunctionSpec *fs); extern JS_PUBLIC_API(JSFunction *) -JS_DefineFunctionWithType(JSContext *cx, JSObject *obj, - const char *name, JSNative call, - uintN nargs, uintN attrs, - JSTypeHandler handler); - -static JS_ALWAYS_INLINE JSFunction* -JS_DefineFunction(JSContext *cx, JSObject *obj, - const char *name, JSNative call, - uintN nargs, uintN attrs) -{ - return JS_DefineFunctionWithType(cx, obj, name, call, nargs, attrs, NULL); -} +JS_DefineFunction(JSContext *cx, JSObject *obj, const char *name, JSNative call, + uintN nargs, uintN attrs); extern JS_PUBLIC_API(JSFunction *) -JS_DefineUCFunctionWithType(JSContext *cx, JSObject *obj, - const jschar *name, size_t namelen, JSNative call, - uintN nargs, uintN attrs, - JSTypeHandler handler); - -static JS_ALWAYS_INLINE JSFunction* JS_DefineUCFunction(JSContext *cx, JSObject *obj, const jschar *name, size_t namelen, JSNative call, - uintN nargs, uintN attrs) -{ - return JS_DefineUCFunctionWithType(cx, obj, name, namelen, call, - nargs, attrs, NULL); -} + uintN nargs, uintN attrs); extern JS_PUBLIC_API(JSFunction *) JS_DefineFunctionById(JSContext *cx, JSObject *obj, jsid id, JSNative call, diff --git a/js/src/jsfriendapi.cpp b/js/src/jsfriendapi.cpp index 902d43626722..afab60675b52 100644 --- a/js/src/jsfriendapi.cpp +++ b/js/src/jsfriendapi.cpp @@ -41,6 +41,8 @@ #include "jscompartment.h" #include "jsfriendapi.h" +#include "jsobjinlines.h" + using namespace js; JS_FRIEND_API(JSString *) @@ -80,3 +82,35 @@ JS_GetFrameScopeChainRaw(JSStackFrame *fp) { return &Valueify(fp)->scopeChain(); } + +JS_FRIEND_API(void) +JS_SplicePrototype(JSContext *cx, JSObject *obj, JSObject *proto) +{ + /* + * Change the prototype of an object which hasn't been used anywhere + * and does not share its type with another object. Unlike JS_SetPrototype, + * does not nuke type information for the object. + */ + CHECK_REQUEST(cx); + obj->getType()->splicePrototype(cx, proto); +} + +JS_FRIEND_API(JSObject *) +JS_NewObjectWithUniqueType(JSContext *cx, JSClass *clasp, JSObject *proto, JSObject *parent) +{ + JSObject *obj = JS_NewObject(cx, clasp, proto, parent); + if (!obj) + return NULL; + + types::TypeObject *type = cx->compartment->types.newTypeObject(cx, NULL, "Unique", "", + false, false, proto); + if (!type) + return NULL; + if (obj->hasSpecialEquality()) + cx->markTypeObjectFlags(type, types::OBJECT_FLAG_SPECIAL_EQUALITY); + if (!obj->setTypeAndUniqueShape(cx, type)) + return NULL; + type->singleton = obj; + + return obj; +} diff --git a/js/src/jsfriendapi.h b/js/src/jsfriendapi.h index a2179e5983f4..feb40b39a3c4 100644 --- a/js/src/jsfriendapi.h +++ b/js/src/jsfriendapi.h @@ -57,6 +57,12 @@ JS_UnwrapObject(JSObject *obj); extern JS_FRIEND_API(JSObject *) JS_GetFrameScopeChainRaw(JSStackFrame *fp); +extern JS_FRIEND_API(void) +JS_SplicePrototype(JSContext *cx, JSObject *obj, JSObject *proto); + +extern JS_FRIEND_API(JSObject *) +JS_NewObjectWithUniqueType(JSContext *cx, JSClass *clasp, JSObject *proto, JSObject *parent); + JS_END_EXTERN_C #endif /* jsfriendapi_h___ */ diff --git a/js/src/jsxml.cpp b/js/src/jsxml.cpp index 67dca95809ca..36f20d012a2e 100644 --- a/js/src/jsxml.cpp +++ b/js/src/jsxml.cpp @@ -7159,8 +7159,7 @@ js_InitXMLClass(JSContext *cx, JSObject *obj) return NULL; /* Define the isXMLName function. */ - if (!JS_DefineFunctionWithType(cx, obj, js_isXMLName_str, xml_isXMLName, 1, 0, - JS_TypeHandlerBool)) + if (!JS_DefineFunction(cx, obj, js_isXMLName_str, xml_isXMLName, 1, 0)) return NULL; /* Properties of XML objects are not modeled by type inference. */ @@ -7201,8 +7200,7 @@ js_InitXMLClass(JSContext *cx, JSObject *obj) return NULL; /* Define the XMLList function and give it the same prototype as XML. */ - fun = JS_DefineFunctionWithType(cx, obj, js_XMLList_str, XMLList, 1, JSFUN_CONSTRUCTOR, - JS_TypeHandlerDynamic); + fun = JS_DefineFunction(cx, obj, js_XMLList_str, XMLList, 1, JSFUN_CONSTRUCTOR); if (!fun) return NULL; if (!js_SetClassPrototype(cx, FUN_OBJECT(fun), proto, diff --git a/js/src/perf/jsperf.cpp b/js/src/perf/jsperf.cpp index 533f0b4b2b4c..2d573bde3407 100644 --- a/js/src/perf/jsperf.cpp +++ b/js/src/perf/jsperf.cpp @@ -117,7 +117,6 @@ pm_start(JSContext* cx, uintN /*unused*/, jsval* vp) return JS_FALSE; p->start(); - *vp = Jsvalify(js::UndefinedValue()); return JS_TRUE; } @@ -129,7 +128,6 @@ pm_stop(JSContext* cx, uintN /*unused*/, jsval* vp) return JS_FALSE; p->stop(); - *vp = Jsvalify(js::UndefinedValue()); return JS_TRUE; } @@ -141,7 +139,6 @@ pm_reset(JSContext* cx, uintN /*unused*/, jsval* vp) return JS_FALSE; p->reset(); - *vp = Jsvalify(js::UndefinedValue()); return JS_TRUE; } @@ -158,10 +155,10 @@ pm_canMeasureSomething(JSContext* cx, uintN /*unused*/, jsval* vp) const uint8 PM_FATTRS = JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_SHARED; static JSFunctionSpec pm_fns[] = { - JS_FN_TYPE("start", pm_start, 0, PM_FATTRS, JS_TypeHandlerVoid), - JS_FN_TYPE("stop", pm_stop, 0, PM_FATTRS, JS_TypeHandlerVoid), - JS_FN_TYPE("reset", pm_reset, 0, PM_FATTRS, JS_TypeHandlerVoid), - JS_FN_TYPE("canMeasureSomething", pm_canMeasureSomething, 0, PM_FATTRS, JS_TypeHandlerBool), + JS_FN("start", pm_start, 0, PM_FATTRS), + JS_FN("stop", pm_stop, 0, PM_FATTRS), + JS_FN("reset", pm_reset, 0, PM_FATTRS), + JS_FN("canMeasureSomething", pm_canMeasureSomething, 0, PM_FATTRS), JS_FS_END }; @@ -256,9 +253,9 @@ namespace JS { JSObject* RegisterPerfMeasurement(JSContext *cx, JSObject *global) { - JSObject *prototype = JS_InitClassWithType(cx, global, 0 /* parent */, - &pm_class, pm_construct, 1, JS_TypeHandlerNew, - pm_props, pm_fns, 0, 0); + JSObject *prototype = JS_InitClass(cx, global, 0 /* parent */, + &pm_class, pm_construct, 1, + pm_props, pm_fns, 0, 0); if (!prototype) return 0; @@ -267,7 +264,7 @@ RegisterPerfMeasurement(JSContext *cx, JSObject *global) return 0; for (const pm_const *c = pm_consts; c->name; c++) { - if (!JS_DefineProperty(cx, ctor, c->name, DOUBLE_TO_JSVAL(c->value), + if (!JS_DefineProperty(cx, ctor, c->name, INT_TO_JSVAL(c->value), JS_PropertyStub, JS_StrictPropertyStub, PM_CATTRS)) return 0; } diff --git a/js/src/xpconnect/shell/xpcshell.cpp b/js/src/xpconnect/shell/xpcshell.cpp index fdb2dbda91b5..77dc3d9b5222 100644 --- a/js/src/xpconnect/shell/xpcshell.cpp +++ b/js/src/xpconnect/shell/xpcshell.cpp @@ -49,6 +49,7 @@ #include "jsapi.h" #include "jscntxt.h" #include "jsdbgapi.h" +#include "jsfriendapi.h" #include "jsprf.h" #include "nsXULAppAPI.h" #include "nsServiceManagerUtils.h" diff --git a/js/src/xpconnect/src/xpcinlines.h b/js/src/xpconnect/src/xpcinlines.h index 5bf63b08b6ac..5298c4763dca 100644 --- a/js/src/xpconnect/src/xpcinlines.h +++ b/js/src/xpconnect/src/xpcinlines.h @@ -44,6 +44,8 @@ #ifndef xpcinlines_h___ #define xpcinlines_h___ +#include "jsfriendapi.h" + /***************************************************************************/ PRBool xpc::PtrAndPrincipalHashKey::KeyEquals(const PtrAndPrincipalHashKey* aKey) const