diff --git a/dom/base/nsDOMWindowUtils.cpp b/dom/base/nsDOMWindowUtils.cpp index 346deb715b30..6d69e267dacb 100644 --- a/dom/base/nsDOMWindowUtils.cpp +++ b/dom/base/nsDOMWindowUtils.cpp @@ -1825,13 +1825,13 @@ nsDOMWindowUtils::GetParent(const JS::Value& aObject, return NS_ERROR_XPC_BAD_CONVERT_JS; } - JSObject* parent = JS_GetParent(JSVAL_TO_OBJECT(aObject)); + JS::Rooted parent(aCx, JS_GetParent(JSVAL_TO_OBJECT(aObject))); *aParent = OBJECT_TO_JSVAL(parent); // Outerize if necessary. if (parent) { if (JSObjectOp outerize = js::GetObjectClass(parent)->ext.outerObject) { - *aParent = OBJECT_TO_JSVAL(outerize(aCx, JS::RootedObject(aCx, parent))); + *aParent = OBJECT_TO_JSVAL(outerize(aCx, parent)); } } diff --git a/js/src/builtin/MapObject.cpp b/js/src/builtin/MapObject.cpp index 9fca8d2a5ec3..a7893d5d6e8c 100644 --- a/js/src/builtin/MapObject.cpp +++ b/js/src/builtin/MapObject.cpp @@ -155,8 +155,8 @@ JSFunctionSpec MapObject::methods[] = { JSObject * MapObject::initClass(JSContext *cx, JSObject *obj) { - return InitClass(cx, Rooted(cx, &obj->asGlobal()), - &class_, JSProto_Map, construct, methods); + Rooted global(cx, &obj->asGlobal()); + return InitClass(cx, global, &class_, JSProto_Map, construct, methods); } void @@ -348,8 +348,8 @@ JSFunctionSpec SetObject::methods[] = { JSObject * SetObject::initClass(JSContext *cx, JSObject *obj) { - return InitClass(cx, Rooted(cx, &obj->asGlobal()), - &class_, JSProto_Set, construct, methods); + Rooted global(cx, &obj->asGlobal()); + return InitClass(cx, global, &class_, JSProto_Set, construct, methods); } void diff --git a/js/src/builtin/RegExp.cpp b/js/src/builtin/RegExp.cpp index 6d1a611b04ae..91c86c463972 100644 --- a/js/src/builtin/RegExp.cpp +++ b/js/src/builtin/RegExp.cpp @@ -23,8 +23,8 @@ class RegExpMatchBuilder JSContext * const cx; RootedObject array; - bool setProperty(JSAtom *name, Value v) { - return !!baseops::DefineProperty(cx, array, RootedId(cx, AtomToId(name)), &v, + bool setProperty(Handle name, Value v) { + return !!baseops::DefineProperty(cx, array, name, &v, JS_PropertyStub, JS_StrictPropertyStub, JSPROP_ENUMERATE); } @@ -38,12 +38,14 @@ class RegExpMatchBuilder } bool setIndex(int index) { - return setProperty(cx->runtime->atomState.indexAtom, Int32Value(index)); + Rooted name(cx, cx->runtime->atomState.indexAtom); + return setProperty(name, Int32Value(index)); } bool setInput(JSString *str) { JS_ASSERT(str); - return setProperty(cx->runtime->atomState.inputAtom, StringValue(str)); + Rooted name(cx, cx->runtime->atomState.inputAtom); + return setProperty(name, StringValue(str)); } }; @@ -194,8 +196,8 @@ CompileRegExpObject(JSContext *cx, RegExpObjectBuilder &builder, CallArgs args) { if (args.length() == 0) { RegExpStatics *res = cx->regExpStatics(); - RegExpObject *reobj = builder.build(RootedAtom(cx, cx->runtime->emptyString), - res->getFlags()); + Rooted empty(cx, cx->runtime->emptyString); + RegExpObject *reobj = builder.build(empty, res->getFlags()); if (!reobj) return false; args.rval() = ObjectValue(*reobj); @@ -242,7 +244,8 @@ CompileRegExpObject(JSContext *cx, RegExpObjectBuilder &builder, CallArgs args) if (!sourceObj.getProperty(cx, cx->runtime->atomState.sourceAtom, &v)) return false; - RegExpObject *reobj = builder.build(RootedAtom(cx, &v.toString()->asAtom()), flags); + Rooted sourceAtom(cx, &v.toString()->asAtom()); + RegExpObject *reobj = builder.build(sourceAtom, flags); if (!reobj) return false; @@ -462,7 +465,8 @@ js_InitRegExpClass(JSContext *cx, JSObject *obj) proto->setPrivate(NULL); RegExpObjectBuilder builder(cx, &proto->asRegExp()); - if (!builder.build(RootedAtom(cx, cx->runtime->emptyString), RegExpFlag(0))) + Rooted empty(cx, cx->runtime->emptyString); + if (!builder.build(empty, RegExpFlag(0))) return NULL; if (!DefinePropertiesAndBrand(cx, proto, NULL, regexp_methods)) diff --git a/js/src/frontend/BytecodeEmitter.cpp b/js/src/frontend/BytecodeEmitter.cpp index 208967f7077b..8710dfe41e39 100644 --- a/js/src/frontend/BytecodeEmitter.cpp +++ b/js/src/frontend/BytecodeEmitter.cpp @@ -5614,8 +5614,8 @@ EmitObject(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn) if (obj) { JS_ASSERT(!obj->inDictionaryMode()); - if (!DefineNativeProperty(cx, obj, RootedId(cx, AtomToId(pn3->pn_atom)), - UndefinedValue(), NULL, NULL, + Rooted id(cx, AtomToId(pn3->pn_atom)); + if (!DefineNativeProperty(cx, obj, id, UndefinedValue(), NULL, NULL, JSPROP_ENUMERATE, 0, 0)) { return false; diff --git a/js/src/frontend/Parser.cpp b/js/src/frontend/Parser.cpp index 1448986fc340..fcc4e6733f33 100644 --- a/js/src/frontend/Parser.cpp +++ b/js/src/frontend/Parser.cpp @@ -540,7 +540,8 @@ BindLocalVariable(JSContext *cx, TreeContext *tc, ParseNode *pn, BindingKind kin JS_ASSERT(kind == VARIABLE || kind == CONSTANT); unsigned index = tc->sc->bindings.numVars(); - if (!tc->sc->bindings.add(cx, RootedAtom(cx, pn->pn_atom), kind)) + Rooted atom(cx, pn->pn_atom); + if (!tc->sc->bindings.add(cx, atom, kind)) return false; if (!pn->pn_cookie.set(cx, tc->staticLevel, index)) @@ -604,7 +605,7 @@ Parser::functionBody(FunctionBodyType type) if (!CheckStrictParameters(context, this)) return NULL; - Rooted const arguments(context, context->runtime->atomState.argumentsAtom); + Rooted arguments(context, context->runtime->atomState.argumentsAtom); /* * Non-top-level functions use JSOP_DEFFUN which is a dynamic scope @@ -6851,8 +6852,8 @@ Parser::primaryExpr(TokenKind tt, bool afterDoubleDot) pn->pn_xflags |= PNX_NONCONST; /* NB: Getter function in { get x(){} } is unnamed. */ - pn2 = functionDef(RootedPropertyName(context, NULL), - op == JSOP_GETTER ? Getter : Setter, Expression); + Rooted funName(context, NULL); + pn2 = functionDef(funName, op == JSOP_GETTER ? Getter : Setter, Expression); if (!pn2) return NULL; TokenPos pos = {begin, pn2->pn_pos.end}; diff --git a/js/src/gc/Root.h b/js/src/gc/Root.h index 6b87ca8e60f9..4505ab1d3acb 100644 --- a/js/src/gc/Root.h +++ b/js/src/gc/Root.h @@ -96,7 +96,7 @@ class Handle * Construct a handle from an explicitly rooted location. This is the * normal way to create a handle, and normally happens implicitly. */ - template inline Handle(const Rooted &root); + template inline Handle(Rooted &root); const T *address() const { return ptr; } T value() const { return *ptr; } @@ -163,15 +163,6 @@ class Rooted Rooted(JSContext *cx) { init(cx, RootMethods::initial()); } Rooted(JSContext *cx, T initial) { init(cx, initial); } - /* - * This method is only necessary due to an obscure C++98 requirement (that - * there be an accessible, usable copy constructor when passing a temporary - * to an implicitly-called constructor for use with a const-ref parameter). - * (Head spinning yet?) We can remove this when we build the JS engine - * with -std=c++11. - */ - operator Handle () const { return Handle(*this); } - ~Rooted() { #if defined(JSGC_ROOT_ANALYSIS) || defined(JSGC_USE_EXACT_ROOTING) @@ -217,7 +208,7 @@ class Rooted template template inline -Handle::Handle(const Rooted &root) +Handle::Handle(Rooted &root) { testAssign(); ptr = reinterpret_cast(root.address()); diff --git a/js/src/jsapi.cpp b/js/src/jsapi.cpp index 18015169e533..a56918e823b6 100644 --- a/js/src/jsapi.cpp +++ b/js/src/jsapi.cpp @@ -1779,7 +1779,8 @@ JS_InitStandardClasses(JSContext *cx, JSObject *obj) assertSameCompartment(cx, obj); - return GlobalObject::initStandardClasses(cx, Rooted(cx, &obj->global())); + Rooted global(cx, &obj->global()); + return GlobalObject::initStandardClasses(cx, global); } #define CLASP(name) (&name##Class) @@ -3143,7 +3144,7 @@ JS_ConvertStub(JSContext *cx, JSHandleObject obj, JSType type, jsval *vp) { JS_ASSERT(type != JSTYPE_OBJECT && type != JSTYPE_FUNCTION); JS_ASSERT(obj); - return DefaultValue(cx, RootedObject(cx, obj), type, vp); + return DefaultValue(cx, obj, type, vp); } JS_PUBLIC_API(JSObject *) @@ -3231,12 +3232,15 @@ JS_GetPrototype(JSObject *obj) } JS_PUBLIC_API(JSBool) -JS_SetPrototype(JSContext *cx, JSObject *obj, JSObject *proto) +JS_SetPrototype(JSContext *cx, JSObject *obj_, JSObject *proto_) { AssertNoGC(cx); CHECK_REQUEST(cx); - assertSameCompartment(cx, obj, proto); - return SetProto(cx, RootedObject(cx, obj), RootedObject(cx, proto), JS_FALSE); + assertSameCompartment(cx, obj_, proto_); + + Rooted obj(cx, obj_); + Rooted proto(cx, proto_); + return SetProto(cx, obj, proto, JS_FALSE); } JS_PUBLIC_API(JSObject *) @@ -3247,14 +3251,17 @@ JS_GetParent(JSObject *obj) } JS_PUBLIC_API(JSBool) -JS_SetParent(JSContext *cx, JSObject *obj, JSObject *parent) +JS_SetParent(JSContext *cx, JSObject *obj_, JSObject *parent_) { AssertNoGC(cx); CHECK_REQUEST(cx); - JS_ASSERT(!obj->isScope()); - JS_ASSERT(parent || !obj->getParent()); - assertSameCompartment(cx, obj, parent); - return JSObject::setParent(cx, RootedObject(cx, obj), RootedObject(cx, parent)); + JS_ASSERT(!obj_->isScope()); + JS_ASSERT(parent_ || !obj_->getParent()); + assertSameCompartment(cx, obj_, parent_); + + Rooted obj(cx, obj_); + Rooted parent(cx, parent_); + return JSObject::setParent(cx, obj, parent); } JS_PUBLIC_API(JSObject *) @@ -3804,12 +3811,15 @@ JS_DefineUCPropertyWithTinyId(JSContext *cx, JSObject *obj, const jschar *name, } JS_PUBLIC_API(JSBool) -JS_DefineOwnProperty(JSContext *cx, JSObject *obj, jsid id, jsval descriptor, JSBool *bp) +JS_DefineOwnProperty(JSContext *cx, JSObject *obj_, jsid id_, jsval descriptor, JSBool *bp) { AssertNoGC(cx); CHECK_REQUEST(cx); - assertSameCompartment(cx, obj, id, descriptor); - return js_DefineOwnProperty(cx, RootedObject(cx, obj), RootedId(cx, id), descriptor, bp); + assertSameCompartment(cx, obj_, id_, descriptor); + + Rooted obj(cx, obj_); + Rooted id(cx, id_); + return js_DefineOwnProperty(cx, obj, id, descriptor, bp); } JS_PUBLIC_API(JSObject *) @@ -3985,11 +3995,14 @@ JS_GetUCPropertyAttrsGetterAndSetter(JSContext *cx, JSObject *obj, } JS_PUBLIC_API(JSBool) -JS_GetOwnPropertyDescriptor(JSContext *cx, JSObject *obj, jsid id, jsval *vp) +JS_GetOwnPropertyDescriptor(JSContext *cx, JSObject *obj_, jsid id_, jsval *vp) { AssertNoGC(cx); CHECK_REQUEST(cx); - return GetOwnPropertyDescriptor(cx, RootedObject(cx, obj), RootedId(cx, id), vp); + + Rooted obj(cx, obj_); + Rooted id(cx, id_); + return GetOwnPropertyDescriptor(cx, obj, id, vp); } static JSBool @@ -4018,7 +4031,8 @@ JS_SetPropertyAttributes(JSContext *cx, JSObject *obj, const char *name, unsigned attrs, JSBool *foundp) { JSAtom *atom = js_Atomize(cx, name, strlen(name)); - return atom && SetPropertyAttributesById(cx, obj, RootedId(cx, AtomToId(atom)), attrs, foundp); + Rooted id(cx, AtomToId(atom)); + return atom && SetPropertyAttributesById(cx, obj, id, attrs, foundp); } JS_PUBLIC_API(JSBool) @@ -4026,7 +4040,8 @@ JS_SetUCPropertyAttributes(JSContext *cx, JSObject *obj, const jschar *name, siz unsigned attrs, JSBool *foundp) { JSAtom *atom = js_AtomizeChars(cx, name, AUTO_NAMELEN(name, namelen)); - return atom && SetPropertyAttributesById(cx, obj, RootedId(cx, AtomToId(atom)), attrs, foundp); + Rooted id(cx, AtomToId(atom)); + return atom && SetPropertyAttributesById(cx, obj, id, attrs, foundp); } JS_PUBLIC_API(JSBool) @@ -4050,9 +4065,11 @@ JS_ForwardGetPropertyTo(JSContext *cx, JSObject *obj, jsid id_, JSObject *onBeha } JS_PUBLIC_API(JSBool) -JS_GetPropertyByIdDefault(JSContext *cx, JSObject *obj, jsid id, jsval def, jsval *vp) +JS_GetPropertyByIdDefault(JSContext *cx, JSObject *obj_, jsid id_, jsval def, jsval *vp) { - return baseops::GetPropertyDefault(cx, RootedObject(cx, obj), RootedId(cx, id), def, vp); + Rooted obj(cx, obj_); + Rooted id(cx, id_); + return baseops::GetPropertyDefault(cx, obj, id, def, vp); } JS_PUBLIC_API(JSBool) @@ -4184,8 +4201,10 @@ JS_DeletePropertyById2(JSContext *cx, JSObject *obj, jsid id, jsval *rval) assertSameCompartment(cx, obj, id); JSAutoResolveFlags rf(cx, JSRESOLVE_QUALIFIED); - if (JSID_IS_SPECIAL(id)) - return obj->deleteSpecial(cx, Rooted(cx, JSID_TO_SPECIALID(id)), rval, false); + if (JSID_IS_SPECIAL(id)) { + Rooted sid(cx, JSID_TO_SPECIALID(id)); + return obj->deleteSpecial(cx, sid, rval, false); + } return obj->deleteByValue(cx, IdToValue(id), rval, false); } @@ -4431,12 +4450,14 @@ JS_NextProperty(JSContext *cx, JSObject *iterobj, jsid *idp) } JS_PUBLIC_API(JSObject *) -JS_NewElementIterator(JSContext *cx, JSObject *obj) +JS_NewElementIterator(JSContext *cx, JSObject *obj_) { AssertNoGC(cx); CHECK_REQUEST(cx); - assertSameCompartment(cx, obj); - return ElementIteratorObject::create(cx, RootedObject(cx, obj)); + assertSameCompartment(cx, obj_); + + Rooted obj(cx, obj_); + return ElementIteratorObject::create(cx, obj); } JS_PUBLIC_API(JSObject *) @@ -4728,6 +4749,8 @@ JS_DefineFunctions(JSContext *cx, JSObject *obj_, JSFunctionSpec *fs) if (!atom) return JS_FALSE; + Rooted id(cx, AtomToId(atom)); + /* * Define a generic arity N+1 static method for the arity N prototype * method if flags contains JSFUN_GENERIC_NATIVE. @@ -4740,11 +4763,8 @@ JS_DefineFunctions(JSContext *cx, JSObject *obj_, JSFunctionSpec *fs) } flags &= ~JSFUN_GENERIC_NATIVE; - fun = js_DefineFunction(cx, ctor, RootedId(cx, AtomToId(atom)), - js_generic_native_method_dispatcher, - fs->nargs + 1, - flags, - JSFunction::ExtendedFinalizeKind); + fun = js_DefineFunction(cx, ctor, id, js_generic_native_method_dispatcher, + fs->nargs + 1, flags, JSFunction::ExtendedFinalizeKind); if (!fun) return JS_FALSE; @@ -4755,8 +4775,7 @@ JS_DefineFunctions(JSContext *cx, JSObject *obj_, JSFunctionSpec *fs) fun->setExtendedSlot(0, PrivateValue(fs)); } - fun = js_DefineFunction(cx, obj, - RootedId(cx, AtomToId(atom)), fs->call, fs->nargs, flags); + fun = js_DefineFunction(cx, obj, id, fs->call, fs->nargs, flags); if (!fun) return JS_FALSE; } @@ -4776,7 +4795,8 @@ JS_DefineFunction(JSContext *cx, JSObject *obj_, const char *name, JSNative call JSAtom *atom = js_Atomize(cx, name, strlen(name)); if (!atom) return NULL; - return js_DefineFunction(cx, obj, RootedId(cx, AtomToId(atom)), call, nargs, attrs); + Rooted id(cx, AtomToId(atom)); + return js_DefineFunction(cx, obj, id, call, nargs, attrs); } JS_PUBLIC_API(JSFunction *) @@ -4793,7 +4813,8 @@ JS_DefineUCFunction(JSContext *cx, JSObject *obj_, JSAtom *atom = js_AtomizeChars(cx, name, AUTO_NAMELEN(name, namelen)); if (!atom) return NULL; - return js_DefineFunction(cx, obj, RootedId(cx, AtomToId(atom)), call, nargs, attrs); + Rooted id(cx, AtomToId(atom)); + return js_DefineFunction(cx, obj, id, call, nargs, attrs); } extern JS_PUBLIC_API(JSFunction *) @@ -5168,11 +5189,10 @@ CompileUCFunctionForPrincipalsCommon(JSContext *cx, JSObject *obj_, return NULL; } - if (obj && funAtom && - !obj->defineGeneric(cx, RootedId(cx, AtomToId(funAtom)), ObjectValue(*fun), NULL, NULL, - JSPROP_ENUMERATE)) - { - return NULL; + if (obj && funAtom) { + Rooted id(cx, AtomToId(funAtom)); + if (!obj->defineGeneric(cx, id, ObjectValue(*fun), NULL, NULL, JSPROP_ENUMERATE)) + return NULL; } return fun; @@ -5471,8 +5491,11 @@ JS_CallFunctionName(JSContext *cx, JSObject *obj_, const char *name, unsigned ar Value v; JSAtom *atom = js_Atomize(cx, name, strlen(name)); - return atom && - GetMethod(cx, obj, RootedId(cx, AtomToId(atom)), 0, &v) && + if (!atom) + return false; + + Rooted id(cx, AtomToId(atom)); + return GetMethod(cx, obj, id, 0, &v) && Invoke(cx, ObjectOrNullValue(obj), v, argc, argv, rval); } @@ -5851,7 +5874,9 @@ JS_ConcatStrings(JSContext *cx, JSString *left, JSString *right) { AssertNoGC(cx); CHECK_REQUEST(cx); - return js_ConcatStrings(cx, RootedString(cx, left), RootedString(cx, right)); + Rooted lstr(cx, left); + Rooted rstr(cx, right); + return js_ConcatStrings(cx, lstr, rstr); } JS_PUBLIC_API(const jschar *) diff --git a/js/src/jsarray.cpp b/js/src/jsarray.cpp index 6e444f31aa86..b371aae0c07a 100644 --- a/js/src/jsarray.cpp +++ b/js/src/jsarray.cpp @@ -716,7 +716,8 @@ static JSBool array_lookupProperty(JSContext *cx, HandleObject obj, HandlePropertyName name, JSObject **objp, JSProperty **propp) { - return array_lookupGeneric(cx, obj, RootedId(cx, NameToId(name)), objp, propp); + Rooted id(cx, NameToId(name)); + return array_lookupGeneric(cx, obj, id, objp, propp); } static JSBool @@ -744,7 +745,8 @@ static JSBool array_lookupSpecial(JSContext *cx, HandleObject obj, HandleSpecialId sid, JSObject **objp, JSProperty **propp) { - return array_lookupGeneric(cx, obj, RootedId(cx, SPECIALID_TO_JSID(sid)), objp, propp); + Rooted id(cx, SPECIALID_TO_JSID(sid)); + return array_lookupGeneric(cx, obj, id, objp, propp); } JSBool @@ -775,8 +777,10 @@ array_getProperty(JSContext *cx, HandleObject obj, HandleObject receiver, Handle return true; } - if (!obj->isDenseArray()) - return baseops::GetProperty(cx, obj, receiver, RootedId(cx, NameToId(name)), vp); + if (!obj->isDenseArray()) { + Rooted id(cx, NameToId(name)); + return baseops::GetProperty(cx, obj, receiver, id, vp); + } JSObject *proto = obj->getProto(); if (!proto) { @@ -821,7 +825,8 @@ array_getSpecial(JSContext *cx, HandleObject obj, HandleObject receiver, HandleS return true; } - return baseops::GetProperty(cx, obj, receiver, RootedId(cx, SPECIALID_TO_JSID(sid)), vp); + Rooted id(cx, SPECIALID_TO_JSID(sid)); + return baseops::GetProperty(cx, obj, receiver, id, vp); } static JSBool @@ -833,9 +838,9 @@ array_getGeneric(JSContext *cx, HandleObject obj, HandleObject receiver, HandleI if (IsDefinitelyIndex(idval, &index)) return array_getElement(cx, obj, receiver, index, vp); - SpecialId sid; - if (ValueIsSpecial(obj, &idval, &sid, cx)) - return array_getSpecial(cx, obj, receiver, Rooted(cx, sid), vp); + Rooted sid(cx); + if (ValueIsSpecial(obj, &idval, sid.address(), cx)) + return array_getSpecial(cx, obj, receiver, sid, vp); JSAtom *atom = ToAtom(cx, idval); if (!atom) @@ -844,7 +849,8 @@ array_getGeneric(JSContext *cx, HandleObject obj, HandleObject receiver, HandleI if (atom->isIndex(&index)) return array_getElement(cx, obj, receiver, index, vp); - return array_getProperty(cx, obj, receiver, RootedPropertyName(cx, atom->asPropertyName()), vp); + Rooted name(cx, atom->asPropertyName()); + return array_getProperty(cx, obj, receiver, name, vp); } static JSBool @@ -904,7 +910,8 @@ array_setGeneric(JSContext *cx, HandleObject obj, HandleId id, Value *vp, JSBool static JSBool array_setProperty(JSContext *cx, HandleObject obj, HandlePropertyName name, Value *vp, JSBool strict) { - return array_setGeneric(cx, obj, RootedId(cx, NameToId(name)), vp, strict); + Rooted id(cx, NameToId(name)); + return array_setGeneric(cx, obj, id, vp, strict); } static JSBool @@ -949,7 +956,8 @@ array_setElement(JSContext *cx, HandleObject obj, uint32_t index, Value *vp, JSB static JSBool array_setSpecial(JSContext *cx, HandleObject obj, HandleSpecialId sid, Value *vp, JSBool strict) { - return array_setGeneric(cx, obj, RootedId(cx, SPECIALID_TO_JSID(sid)), vp, strict); + Rooted id(cx, SPECIALID_TO_JSID(sid)); + return array_setGeneric(cx, obj, id, vp, strict); } JSBool @@ -982,7 +990,7 @@ array_defineGeneric(JSContext *cx, HandleObject obj, HandleId id, const Value *v return JS_TRUE; if (!obj->isDenseArray()) - return baseops::DefineProperty(cx, obj, id, value, getter, setter, attrs); + return baseops::DefineGeneric(cx, obj, id, value, getter, setter, attrs); do { uint32_t i = 0; // init to shut GCC up @@ -1008,14 +1016,15 @@ array_defineGeneric(JSContext *cx, HandleObject obj, HandleId id, const Value *v if (!JSObject::makeDenseArraySlow(cx, obj)) return false; - return baseops::DefineProperty(cx, obj, id, value, getter, setter, attrs); + return baseops::DefineGeneric(cx, obj, id, value, getter, setter, attrs); } static JSBool array_defineProperty(JSContext *cx, HandleObject obj, HandlePropertyName name, const Value *value, JSPropertyOp getter, StrictPropertyOp setter, unsigned attrs) { - return array_defineGeneric(cx, obj, RootedId(cx, NameToId(name)), value, getter, setter, attrs); + Rooted id(cx, NameToId(name)); + return array_defineGeneric(cx, obj, id, value, getter, setter, attrs); } namespace js { @@ -1063,8 +1072,8 @@ static JSBool array_defineSpecial(JSContext *cx, HandleObject obj, HandleSpecialId sid, const Value *value, PropertyOp getter, StrictPropertyOp setter, unsigned attrs) { - return array_defineGeneric(cx, obj, RootedId(cx, SPECIALID_TO_JSID(sid)), - value, getter, setter, attrs); + Rooted id(cx, SPECIALID_TO_JSID(sid)); + return array_defineGeneric(cx, obj, id, value, getter, setter, attrs); } static JSBool @@ -1155,7 +1164,7 @@ array_deleteElement(JSContext *cx, HandleObject obj, uint32_t index, Value *rval obj->setDenseArrayElement(index, MagicValue(JS_ARRAY_HOLE)); } - if (!js_SuppressDeletedElement(cx, RootedObject(cx, obj), index)) + if (!js_SuppressDeletedElement(cx, obj, index)) return false; rval->setBoolean(true); @@ -1704,7 +1713,8 @@ array_toLocaleString(JSContext *cx, unsigned argc, Value *vp) * Passing comma here as the separator. Need a way to get a * locale-specific version. */ - return array_toString_sub(cx, obj, JS_TRUE, RootedString(cx), args); + Rooted none(cx, NULL); + return array_toString_sub(cx, obj, JS_TRUE, none, args); } static inline bool @@ -2385,7 +2395,7 @@ NewbornArrayPushImpl(JSContext *cx, HandleObject obj, const Value &v) /* This can happen in one evil case. See bug 630377. */ RootedId id(cx); return IndexToId(cx, length, id.address()) && - baseops::DefineProperty(cx, obj, id, &v, NULL, NULL, JSPROP_ENUMERATE); + baseops::DefineGeneric(cx, obj, id, &v, NULL, NULL, JSPROP_ENUMERATE); } JS_ASSERT(obj->isDenseArray()); diff --git a/js/src/jscompartment.cpp b/js/src/jscompartment.cpp index ba7f4070ae5f..3ee927f4edbd 100644 --- a/js/src/jscompartment.cpp +++ b/js/src/jscompartment.cpp @@ -167,7 +167,7 @@ JSCompartment::wrap(JSContext *cx, Value *vp) /* Unwrap incoming objects. */ if (vp->isObject()) { - JSObject *obj = &vp->toObject(); + Rooted obj(cx, &vp->toObject()); if (obj->compartment() == this) return WrapForSameCompartment(cx, obj, vp); @@ -194,7 +194,7 @@ JSCompartment::wrap(JSContext *cx, Value *vp) #ifdef DEBUG { - JSObject *outer = GetOuterObject(cx, RootedObject(cx, obj)); + JSObject *outer = GetOuterObject(cx, obj); JS_ASSERT(outer && outer == obj); } #endif diff --git a/js/src/jsdate.cpp b/js/src/jsdate.cpp index 51b1335d7fb9..2b28df175c5f 100644 --- a/js/src/jsdate.cpp +++ b/js/src/jsdate.cpp @@ -2699,8 +2699,8 @@ js_InitDateClass(JSContext *cx, JSObject *obj) RootedId toUTCStringId(cx, NameToId(cx->runtime->atomState.toUTCStringAtom)); RootedId toGMTStringId(cx, NameToId(cx->runtime->atomState.toGMTStringAtom)); if (!baseops::GetProperty(cx, dateProto, toUTCStringId, &toUTCStringFun) || - !baseops::DefineProperty(cx, dateProto, toGMTStringId, &toUTCStringFun, - JS_PropertyStub, JS_StrictPropertyStub, 0)) + !baseops::DefineGeneric(cx, dateProto, toGMTStringId, &toUTCStringFun, + JS_PropertyStub, JS_StrictPropertyStub, 0)) { return NULL; } diff --git a/js/src/jsdbgapi.cpp b/js/src/jsdbgapi.cpp index db19626d7840..2c150aba4c15 100644 --- a/js/src/jsdbgapi.cpp +++ b/js/src/jsdbgapi.cpp @@ -783,7 +783,8 @@ GetPropertyDesc(JSContext *cx, JSObject *obj_, Shape *shape, JSPropertyDesc *pd) lastException = cx->getPendingException(); cx->clearPendingException(); - if (!baseops::GetProperty(cx, obj, RootedId(cx, shape->propid()), &pd->value)) { + Rooted id(cx, shape->propid()); + if (!baseops::GetProperty(cx, obj, id, &pd->value)) { if (!cx->isExceptionPending()) { pd->flags = JSPD_ERROR; pd->value = JSVAL_VOID; diff --git a/js/src/jsexn.cpp b/js/src/jsexn.cpp index 9cb5c3a0b72d..5a4f3fa006c0 100644 --- a/js/src/jsexn.cpp +++ b/js/src/jsexn.cpp @@ -269,17 +269,20 @@ InitExnPrivate(JSContext *cx, HandleObject exnObject, HandleString message, if (checkAccess && i.isNonEvalFunctionFrame()) { Value v = NullValue(); RootedId callerid(cx, NameToId(cx->runtime->atomState.callerAtom)); - if (!checkAccess(cx, RootedObject(cx, i.callee()), callerid, JSACC_READ, &v)) + Rooted obj(cx, i.callee()); + if (!checkAccess(cx, obj, callerid, JSACC_READ, &v)) break; } if (!frames.growBy(1)) return false; JSStackTraceStackElem &frame = frames.back(); - if (i.isNonEvalFunctionFrame()) - frame.funName = fp->fun()->atom ? fp->fun()->atom : cx->runtime->emptyString; - else + if (i.isNonEvalFunctionFrame()) { + JSAtom *atom = fp->fun()->atom ? fp->fun()->atom : cx->runtime->emptyString; + frame.funName = atom; + } else { frame.funName = NULL; + } const char *cfilename = i.script()->filename; if (!cfilename) cfilename = ""; diff --git a/js/src/jsfriendapi.cpp b/js/src/jsfriendapi.cpp index 4c59d85dcf23..52c57ea51b1e 100644 --- a/js/src/jsfriendapi.cpp +++ b/js/src/jsfriendapi.cpp @@ -231,8 +231,8 @@ JS_DefineFunctionsWithHelp(JSContext *cx, JSObject *obj_, const JSFunctionSpecWi return false; RootedFunction fun(cx); - fun = js_DefineFunction(cx, obj, RootedId(cx, AtomToId(atom)), - fs->call, fs->nargs, fs->flags); + Rooted id(cx, AtomToId(atom)); + fun = js_DefineFunction(cx, obj, id, fs->call, fs->nargs, fs->flags); if (!fun) return false; @@ -338,9 +338,8 @@ js::DefineFunctionWithReserved(JSContext *cx, JSObject *obj_, const char *name, JSAtom *atom = js_Atomize(cx, name, strlen(name)); if (!atom) return NULL; - return js_DefineFunction(cx, obj, RootedId(cx, AtomToId(atom)), - call, nargs, attrs, - JSFunction::ExtendedFinalizeKind); + Rooted id(cx, AtomToId(atom)); + return js_DefineFunction(cx, obj, id, call, nargs, attrs, JSFunction::ExtendedFinalizeKind); } JS_FRIEND_API(JSFunction *) diff --git a/js/src/jsfun.cpp b/js/src/jsfun.cpp index 339b538598f8..ea99641e0125 100644 --- a/js/src/jsfun.cpp +++ b/js/src/jsfun.cpp @@ -426,7 +426,8 @@ js::CloneInterpretedFunction(JSContext *cx, JSFunction *srcFun) if (!clone->clearType(cx)) return NULL; - JSScript *clonedScript = CloneScript(cx, RootedScript(cx, srcFun->script())); + Rooted srcScript(cx, srcFun->script()); + JSScript *clonedScript = CloneScript(cx, srcScript); if (!clonedScript) return NULL; diff --git a/js/src/jsfuninlines.h b/js/src/jsfuninlines.h index ae875cb54566..1ac2e8102703 100644 --- a/js/src/jsfuninlines.h +++ b/js/src/jsfuninlines.h @@ -206,7 +206,8 @@ CloneFunctionObjectIfNotSingleton(JSContext *cx, HandleFunction fun, HandleObjec * with its type in existence. */ if (fun->hasSingletonType()) { - if (!JSObject::setParent(cx, fun, RootedObject(cx, SkipScopeParent(parent)))) + Rooted obj(cx, SkipScopeParent(parent)); + if (!JSObject::setParent(cx, fun, obj)) return NULL; fun->setEnvironment(parent); return fun; @@ -230,10 +231,9 @@ CloneFunctionObject(JSContext *cx, HandleFunction fun) if (fun->hasSingletonType()) return fun; - return js_CloneFunctionObject(cx, fun, - RootedObject(cx, fun->environment()), - RootedObject(cx, fun->getProto()), - JSFunction::ExtendedFinalizeKind); + Rooted env(cx, fun->environment()); + Rooted proto(cx, fun->getProto()); + return js_CloneFunctionObject(cx, fun, env, proto, JSFunction::ExtendedFinalizeKind); } } /* namespace js */ diff --git a/js/src/jsinfer.cpp b/js/src/jsinfer.cpp index dc1cd4f0fe8a..fc441fc4bf45 100644 --- a/js/src/jsinfer.cpp +++ b/js/src/jsinfer.cpp @@ -1682,8 +1682,8 @@ TypeSet::isOwnProperty(JSContext *cx, TypeObject *object, bool configurable) */ if (object->flags & OBJECT_FLAG_NEW_SCRIPT_REGENERATE) { if (object->newScript) { - CheckNewScriptProperties(cx, RootedTypeObject(cx, object), - object->newScript->fun); + Rooted typeObj(cx, object); + CheckNewScriptProperties(cx, typeObj, object->newScript->fun); } else { JS_ASSERT(object->flags & OBJECT_FLAG_NEW_SCRIPT_CLEARED); object->flags &= ~OBJECT_FLAG_NEW_SCRIPT_REGENERATE; diff --git a/js/src/jsinterp.cpp b/js/src/jsinterp.cpp index 0c9a484b504d..e8c632feced3 100644 --- a/js/src/jsinterp.cpp +++ b/js/src/jsinterp.cpp @@ -537,7 +537,8 @@ js::LooselyEqual(JSContext *cx, const Value &lval, const Value &rval, bool *resu if (JSEqualityOp eq = l->getClass()->ext.equality) { JSBool res; - if (!eq(cx, RootedObject(cx, l), &rval, &res)) + Rooted lobj(cx, l); + if (!eq(cx, lobj, &rval, &res)) return false; *result = !!res; return true; @@ -983,7 +984,8 @@ IteratorMore(JSContext *cx, JSObject *iterobj, bool *cond, Value *rval) return true; } } - if (!js_IteratorMore(cx, RootedObject(cx, iterobj), rval)) + Rooted iobj(cx, iterobj); + if (!js_IteratorMore(cx, iobj, rval)) return false; *cond = rval->isTrue(); return true; diff --git a/js/src/jsinterpinlines.h b/js/src/jsinterpinlines.h index d0734adb1aaf..dfff7ae9762e 100644 --- a/js/src/jsinterpinlines.h +++ b/js/src/jsinterpinlines.h @@ -125,7 +125,8 @@ ValuePropertyBearer(JSContext *cx, StackFrame *fp, const Value &v, int spindex) } inline bool -NativeGet(JSContext *cx, JSObject *obj, JSObject *pobj, const Shape *shape, unsigned getHow, Value *vp) +NativeGet(JSContext *cx, Handle obj, Handle pobj, const Shape *shape, + unsigned getHow, Value *vp) { if (shape->isDataDescriptor() && shape->hasDefaultGetter()) { /* Fast path for Object instance properties. */ @@ -211,9 +212,9 @@ GetPropertyOperation(JSContext *cx, jsbytecode *pc, const Value &lval, Value *vp return false; PropertyCacheEntry *entry; - JSObject *obj2; + Rooted obj2(cx); PropertyName *name; - JS_PROPERTY_CACHE(cx).test(cx, pc, obj.reference(), obj2, entry, name); + JS_PROPERTY_CACHE(cx).test(cx, pc, obj.reference(), obj2.reference(), entry, name); if (!name) { AssertValidPropertyCacheHit(cx, obj, obj2, entry); if (!NativeGet(cx, obj, obj2, entry->prop, JSGET_CACHE_RESULT, vp)) @@ -336,9 +337,9 @@ NameOperation(JSContext *cx, jsbytecode *pc, Value *vp) obj = &obj->global(); PropertyCacheEntry *entry; - JSObject *obj2; + Rooted obj2(cx); RootedPropertyName name(cx); - JS_PROPERTY_CACHE(cx).test(cx, pc, obj.reference(), obj2, entry, name.reference()); + JS_PROPERTY_CACHE(cx).test(cx, pc, obj.reference(), obj2.reference(), entry, name.reference()); if (!name) { AssertValidPropertyCacheHit(cx, obj, obj2, entry); if (!NativeGet(cx, obj, obj2, entry->prop, 0, vp)) @@ -347,7 +348,7 @@ NameOperation(JSContext *cx, jsbytecode *pc, Value *vp) } JSProperty *prop; - if (!FindPropertyHelper(cx, name, true, obj, obj.address(), &obj2, &prop)) + if (!FindPropertyHelper(cx, name, true, obj, obj.address(), obj2.address(), &prop)) return false; if (!prop) { /* Kludge to allow (typeof foo == "undefined") tests. */ @@ -364,11 +365,12 @@ NameOperation(JSContext *cx, jsbytecode *pc, Value *vp) /* Take the slow path if prop was not found in a native object. */ if (!obj->isNative() || !obj2->isNative()) { - if (!obj->getGeneric(cx, RootedId(cx, NameToId(name)), vp)) + Rooted id(cx, NameToId(name)); + if (!obj->getGeneric(cx, id, vp)) return false; } else { Shape *shape = (Shape *)prop; - JSObject *normalized = obj; + Rooted normalized(cx, obj); if (normalized->getClass() == &WithClass && !shape->hasDefaultGetter()) normalized = &normalized->asWith().object(); if (!NativeGet(cx, normalized, obj2, shape, 0, vp)) diff --git a/js/src/jsobj.cpp b/js/src/jsobj.cpp index 9eb91bd761a9..386c5f2884eb 100644 --- a/js/src/jsobj.cpp +++ b/js/src/jsobj.cpp @@ -84,19 +84,21 @@ Class js::ObjectClass = { }; JS_FRIEND_API(JSObject *) -JS_ObjectToInnerObject(JSContext *cx, JSObject *obj) +JS_ObjectToInnerObject(JSContext *cx, JSObject *obj_) { - if (!obj) { + if (!obj_) { JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_INACTIVE); return NULL; } - return GetInnerObject(cx, RootedObject(cx, obj)); + Rooted obj(cx, obj_); + return GetInnerObject(cx, obj); } JS_FRIEND_API(JSObject *) -JS_ObjectToOuterObject(JSContext *cx, JSObject *obj) +JS_ObjectToOuterObject(JSContext *cx, JSObject *obj_) { - return GetOuterObject(cx, RootedObject(cx, obj)); + Rooted obj(cx, obj_); + return GetOuterObject(cx, obj); } #if JS_HAS_OBJ_PROTO_PROP @@ -201,7 +203,8 @@ MarkSharpObjects(JSContext *cx, HandleObject obj, JSIdArray **idap, JSSharpInfo if (hasSetter) { /* Mark the getter, then set val to setter. */ if (hasGetter && value.isObject()) { - ok = MarkSharpObjects(cx, RootedObject(cx, &value.toObject()), NULL, NULL); + Rooted vobj(cx, &value.toObject()); + ok = MarkSharpObjects(cx, vobj, NULL, NULL); if (!ok) break; } @@ -211,11 +214,12 @@ MarkSharpObjects(JSContext *cx, HandleObject obj, JSIdArray **idap, JSSharpInfo if (!ok) break; } - if (value.isObject() && - !MarkSharpObjects(cx, RootedObject(cx, &value.toObject()), NULL, NULL)) - { - ok = false; - break; + if (value.isObject()) { + Rooted vobj(cx, &value.toObject()); + if (!MarkSharpObjects(cx, vobj, NULL, NULL)) { + ok = false; + break; + } } } if (!ok || !idap) @@ -702,8 +706,10 @@ AssertInnerizedScopeChain(JSContext *cx, JSObject &scopeobj) { #ifdef DEBUG for (JSObject *o = &scopeobj; o; o = o->enclosingScope()) { - if (JSObjectOp op = o->getClass()->ext.innerObject) - JS_ASSERT(op(cx, RootedObject(cx, o)) == o); + if (JSObjectOp op = o->getClass()->ext.innerObject) { + Rooted obj(cx, o); + JS_ASSERT(op(cx, obj) == o); + } } #endif } @@ -1084,9 +1090,11 @@ JSBool eval(JSContext *cx, unsigned argc, Value *vp) { CallArgs args = CallArgsFromVp(argc, vp); - return WarnOnTooManyArgs(cx, args) && - EvalKernel(cx, args, INDIRECT_EVAL, NULL, - RootedObject(cx, &args.callee().global())); + if (!WarnOnTooManyArgs(cx, args)) + return false; + + Rooted global(cx, &args.callee().global()); + return EvalKernel(cx, args, INDIRECT_EVAL, NULL, global); } bool @@ -1286,7 +1294,8 @@ js_HasOwnProperty(JSContext *cx, LookupGenericOp lookup, HandleObject obj, Handl JSObject *outer = NULL; if (JSObjectOp op = (*objp)->getClass()->ext.outerObject) { - outer = op(cx, RootedObject(cx, *objp)); + Rooted inner(cx, *objp); + outer = op(cx, inner); if (!outer) return false; } @@ -1970,9 +1979,9 @@ DefinePropertyOnObject(JSContext *cx, HandleObject obj, HandleId id, const PropD if (desc.isGenericDescriptor() || desc.isDataDescriptor()) { JS_ASSERT(!obj->getOps()->defineProperty); Value v = desc.hasValue() ? desc.value() : UndefinedValue(); - return baseops::DefineProperty(cx, obj, id, &v, - JS_PropertyStub, JS_StrictPropertyStub, - desc.attributes()); + return baseops::DefineGeneric(cx, obj, id, &v, + JS_PropertyStub, JS_StrictPropertyStub, + desc.attributes()); } JS_ASSERT(desc.isAccessorDescriptor()); @@ -1987,8 +1996,8 @@ DefinePropertyOnObject(JSContext *cx, HandleObject obj, HandleId id, const PropD return JS_FALSE; Value tmp = UndefinedValue(); - return baseops::DefineProperty(cx, obj, id, &tmp, - desc.getter(), desc.setter(), desc.attributes()); + return baseops::DefineGeneric(cx, obj, id, &tmp, + desc.getter(), desc.setter(), desc.attributes()); } /* 8.12.9 steps 5-6 (note 5 is merely a special case of 6). */ @@ -2238,7 +2247,7 @@ DefinePropertyOnObject(JSContext *cx, HandleObject obj, HandleId id, const PropD return false; } - return baseops::DefineProperty(cx, obj, id, &v, getter, setter, attrs); + return baseops::DefineGeneric(cx, obj, id, &v, getter, setter, attrs); } static JSBool @@ -2382,7 +2391,7 @@ DefineProperties(JSContext *cx, HandleObject obj, JSObject *props) bool dummy; for (size_t i = 0, len = ids.length(); i < len; i++) { - if (!DefineProperty(cx, obj, RootedId(cx, ids[i]), descs[i], true, &dummy)) + if (!DefineProperty(cx, obj, Handle::fromMarkedLocation(&ids[i]), descs[i], true, &dummy)) return false; } @@ -3173,9 +3182,9 @@ JSObject::deleteByValue(JSContext *cx, const Value &property, Value *rval, bool return deleteElement(cx, index, rval, strict); Value propval = property; - SpecialId sid; - if (ValueIsSpecial(this, &propval, &sid, cx)) - return deleteSpecial(cx, Rooted(cx, sid), rval, strict); + Rooted sid(cx); + if (ValueIsSpecial(this, &propval, sid.address(), cx)) + return deleteSpecial(cx, sid, rval, strict); RootedObject self(cx, this); @@ -3186,7 +3195,8 @@ JSObject::deleteByValue(JSContext *cx, const Value &property, Value *rval, bool if (name->isIndex(&index)) return self->deleteElement(cx, index, rval, false); - return self->deleteProperty(cx, RootedPropertyName(cx, name->asPropertyName()), rval, false); + Rooted propname(cx, name->asPropertyName()); + return self->deleteProperty(cx, propname, rval, false); } JS_FRIEND_API(bool) @@ -3217,7 +3227,8 @@ JS_CopyPropertiesFrom(JSContext *cx, JSObject *target, JSObject *obj) Value v = shape->hasSlot() ? obj->getSlot(shape->slot()) : UndefinedValue(); if (!cx->compartment->wrap(cx, &v)) return false; - if (!target->defineGeneric(cx, RootedId(cx, shape->propid()), v, getter, setter, attrs)) + Rooted id(cx, shape->propid()); + if (!target->defineGeneric(cx, id, v, getter, setter, attrs)) return false; } return true; @@ -3956,15 +3967,16 @@ JSObject::growSlots(JSContext *cx, uint32_t oldCount, uint32_t newCount) gc::AllocKind kind = type()->newScript->allocKind; unsigned newScriptSlots = gc::GetGCKindSlots(kind); if (newScriptSlots == numFixedSlots() && gc::TryIncrementAllocKind(&kind)) { - JSObject *obj = NewReshapedObject(cx, RootedTypeObject(cx, type()), + Rooted typeObj(cx, type()); + JSObject *obj = NewReshapedObject(cx, typeObj, getParent(), kind, - type()->newScript->shape); + typeObj->newScript->shape); if (!obj) return false; - type()->newScript->allocKind = kind; - type()->newScript->shape = obj->lastProperty(); - type()->markStateChange(cx); + typeObj->newScript->allocKind = kind; + typeObj->newScript->shape = obj->lastProperty(); + typeObj->markStateChange(cx); } } @@ -4476,7 +4488,7 @@ js_AddNativeProperty(JSContext *cx, HandleObject obj, jsid id_, } JSBool -baseops::DefineProperty(JSContext *cx, HandleObject obj, HandleId id, const Value *value, +baseops::DefineGeneric(JSContext *cx, HandleObject obj, HandleId id, const Value *value, PropertyOp getter, StrictPropertyOp setter, unsigned attrs) { return !!DefineNativeProperty(cx, obj, id, *value, getter, setter, attrs, 0, 0); @@ -4486,14 +4498,14 @@ JSBool baseops::DefineElement(JSContext *cx, HandleObject obj, uint32_t index, const Value *value, PropertyOp getter, StrictPropertyOp setter, unsigned attrs) { + Rooted id(cx); if (index <= JSID_INT_MAX) { - return !!DefineNativeProperty(cx, obj, RootedId(cx, INT_TO_JSID(index)), *value, - getter, setter, attrs, 0, 0); + id = INT_TO_JSID(index); + return !!DefineNativeProperty(cx, obj, id, *value, getter, setter, attrs, 0, 0); } AutoRooterGetterSetter gsRoot(cx, attrs, &getter, &setter); - RootedId id(cx); if (!IndexToId(cx, index, id.address())) return false; @@ -4512,7 +4524,8 @@ CallAddPropertyHook(JSContext *cx, Class *clasp, HandleObject obj, HandleShape s if (clasp->addProperty != JS_PropertyStub) { Value nominal = *vp; - if (!CallJSPropertyOp(cx, clasp->addProperty, obj, RootedId(cx, shape->propid()), vp)) + Rooted id(cx, shape->propid()); + if (!CallJSPropertyOp(cx, clasp->addProperty, obj, id, vp)) return false; if (*vp != nominal) { if (shape->hasSlot()) @@ -4965,7 +4978,7 @@ js::FindIdentifierBase(JSContext *cx, HandleObject scopeChain, HandlePropertyNam } static JS_ALWAYS_INLINE JSBool -js_NativeGetInline(JSContext *cx, JSObject *receiver, JSObject *obj, JSObject *pobj, +js_NativeGetInline(JSContext *cx, Handle receiver, JSObject *obj, JSObject *pobj, const Shape *shape, unsigned getHow, Value *vp) { JS_ASSERT(pobj->isNative()); @@ -4992,7 +5005,7 @@ js_NativeGetInline(JSContext *cx, JSObject *receiver, JSObject *obj, JSObject *p Rooted shapeRoot(cx, shape); RootedObject pobjRoot(cx, pobj); - if (!shape->get(cx, RootedObject(cx, receiver), obj, pobj, vp)) + if (!shape->get(cx, receiver, obj, pobj, vp)) return false; /* Update slotful shapes according to the value produced by the getter. */ @@ -5003,14 +5016,15 @@ js_NativeGetInline(JSContext *cx, JSObject *receiver, JSObject *obj, JSObject *p } JSBool -js_NativeGet(JSContext *cx, JSObject *obj, JSObject *pobj, const Shape *shape, unsigned getHow, - Value *vp) +js_NativeGet(JSContext *cx, Handle obj, Handle pobj, const Shape *shape, + unsigned getHow, Value *vp) { return js_NativeGetInline(cx, obj, obj, pobj, shape, getHow, vp); } JSBool -js_NativeSet(JSContext *cx, JSObject *obj, const Shape *shape, bool added, bool strict, Value *vp) +js_NativeSet(JSContext *cx, Handle obj, const Shape *shape, bool added, bool strict, + Value *vp) { AddTypePropertyId(cx, obj, shape->propid(), *vp); @@ -5038,7 +5052,7 @@ js_NativeSet(JSContext *cx, JSObject *obj, const Shape *shape, bool added, bool Rooted shapeRoot(cx, shape); int32_t sample = cx->runtime->propertyRemovals; - if (!shapeRoot->set(cx, RootedObject(cx, obj), strict, vp)) + if (!shapeRoot->set(cx, obj, strict, vp)) return false; /* @@ -5256,8 +5270,9 @@ bool JSObject::callMethod(JSContext *cx, HandleId id, unsigned argc, Value *argv, Value *vp) { Value fval; - return GetMethod(cx, RootedObject(cx, this), id, 0, &fval) && - Invoke(cx, ObjectValue(*this), fval, argc, argv, vp); + Rooted obj(cx, this); + return GetMethod(cx, obj, id, 0, &fval) && + Invoke(cx, ObjectValue(*obj), fval, argc, argv, vp); } JSBool @@ -5568,7 +5583,8 @@ baseops::DeleteGeneric(JSContext *cx, HandleObject obj, HandleId id, Value *rval JSBool baseops::DeleteProperty(JSContext *cx, HandleObject obj, HandlePropertyName name, Value *rval, JSBool strict) { - return baseops::DeleteGeneric(cx, obj, RootedId(cx, NameToId(name)), rval, strict); + Rooted id(cx, NameToId(name)); + return baseops::DeleteGeneric(cx, obj, id, rval, strict); } JSBool @@ -5583,7 +5599,8 @@ baseops::DeleteElement(JSContext *cx, HandleObject obj, uint32_t index, Value *r JSBool baseops::DeleteSpecial(JSContext *cx, HandleObject obj, HandleSpecialId sid, Value *rval, JSBool strict) { - return baseops::DeleteGeneric(cx, obj, RootedId(cx, SPECIALID_TO_JSID(sid)), rval, strict); + Rooted id(cx, SPECIALID_TO_JSID(sid)); + return baseops::DeleteGeneric(cx, obj, id, rval, strict); } namespace js { @@ -5610,9 +5627,9 @@ HasDataProperty(JSContext *cx, HandleObject obj, jsid id, Value *vp) * or steps 3-4. */ static bool -MaybeCallMethod(JSContext *cx, HandleObject obj, jsid id, Value *vp) +MaybeCallMethod(JSContext *cx, HandleObject obj, Handle id, Value *vp) { - if (!GetMethod(cx, obj, RootedId(cx, id), 0, vp)) + if (!GetMethod(cx, obj, id, 0, vp)) return false; if (!js_IsCallable(*vp)) { *vp = ObjectValue(*obj); @@ -5629,49 +5646,58 @@ DefaultValue(JSContext *cx, HandleObject obj, JSType hint, Value *vp) JS_ASSERT(!obj->isXML()); #endif + Rooted id(cx); + Class *clasp = obj->getClass(); if (hint == JSTYPE_STRING) { + id = NameToId(cx->runtime->atomState.toStringAtom); + /* Optimize (new String(...)).toString(). */ - if (clasp == &StringClass && - ClassMethodIsNative(cx, obj, - &StringClass, - RootedId(cx, NameToId(cx->runtime->atomState.toStringAtom)), - js_str_toString)) { - *vp = StringValue(obj->asString().unbox()); - return true; + if (clasp == &StringClass) { + if (ClassMethodIsNative(cx, obj, &StringClass, id, js_str_toString)) { + *vp = StringValue(obj->asString().unbox()); + return true; + } } - if (!MaybeCallMethod(cx, obj, NameToId(cx->runtime->atomState.toStringAtom), vp)) + if (!MaybeCallMethod(cx, obj, id, vp)) return false; if (vp->isPrimitive()) return true; - if (!MaybeCallMethod(cx, obj, NameToId(cx->runtime->atomState.valueOfAtom), vp)) + id = NameToId(cx->runtime->atomState.valueOfAtom); + if (!MaybeCallMethod(cx, obj, id, vp)) return false; if (vp->isPrimitive()) return true; } else { - /* Optimize (new String(...)).valueOf(). */ - if ((clasp == &StringClass && - ClassMethodIsNative(cx, obj, &StringClass, - RootedId(cx, NameToId(cx->runtime->atomState.valueOfAtom)), - js_str_toString)) || - (clasp == &NumberClass && - ClassMethodIsNative(cx, obj, &NumberClass, - RootedId(cx, NameToId(cx->runtime->atomState.valueOfAtom)), - js_num_valueOf))) { - *vp = obj->isString() - ? StringValue(obj->asString().unbox()) - : NumberValue(obj->asNumber().unbox()); - return true; + + /* Optimize new String(...).valueOf(). */ + if (clasp == &StringClass) { + id = NameToId(cx->runtime->atomState.valueOfAtom); + if (ClassMethodIsNative(cx, obj, &StringClass, id, js_str_toString)) { + *vp = StringValue(obj->asString().unbox()); + return true; + } } - if (!MaybeCallMethod(cx, obj, NameToId(cx->runtime->atomState.valueOfAtom), vp)) + /* Optimize new Number(...).valueOf(). */ + if (clasp == &NumberClass) { + id = NameToId(cx->runtime->atomState.valueOfAtom); + if (ClassMethodIsNative(cx, obj, &NumberClass, id, js_num_valueOf)) { + *vp = NumberValue(obj->asNumber().unbox()); + return true; + } + } + + id = NameToId(cx->runtime->atomState.valueOfAtom); + if (!MaybeCallMethod(cx, obj, id, vp)) return false; if (vp->isPrimitive()) return true; - if (!MaybeCallMethod(cx, obj, NameToId(cx->runtime->atomState.toStringAtom), vp)) + id = NameToId(cx->runtime->atomState.toStringAtom); + if (!MaybeCallMethod(cx, obj, id, vp)) return false; if (vp->isPrimitive()) return true; @@ -5868,8 +5894,10 @@ js_GetClassPrototype(JSContext *cx, JSObject *scopeobj, JSProtoKey protoKey, JSObject * PrimitiveToObject(JSContext *cx, const Value &v) { - if (v.isString()) - return StringObject::create(cx, RootedString(cx, v.toString())); + if (v.isString()) { + Rooted str(cx, v.toString()); + return StringObject::create(cx, str); + } if (v.isNumber()) return NumberObject::create(cx, v.toNumber()); diff --git a/js/src/jsobj.h b/js/src/jsobj.h index 734ce0373213..529cdb1ece40 100644 --- a/js/src/jsobj.h +++ b/js/src/jsobj.h @@ -105,7 +105,8 @@ inline bool LookupProperty(JSContext *cx, HandleObject obj, PropertyName *name, JSObject **objp, JSProperty **propp) { - return LookupProperty(cx, obj, RootedId(cx, NameToId(name)), objp, propp); + Rooted id(cx, NameToId(name)); + return LookupProperty(cx, obj, id, objp, propp); } extern JS_FRIEND_API(JSBool) @@ -113,9 +114,17 @@ LookupElement(JSContext *cx, HandleObject obj, uint32_t index, JSObject **objp, JSProperty **propp); extern JSBool -DefineProperty(JSContext *cx, HandleObject obj, HandleId id, const js::Value *value, +DefineGeneric(JSContext *cx, HandleObject obj, HandleId id, const js::Value *value, JSPropertyOp getter, JSStrictPropertyOp setter, unsigned attrs); +inline JSBool +DefineProperty(JSContext *cx, HandleObject obj, PropertyName *name, const js::Value *value, + JSPropertyOp getter, JSStrictPropertyOp setter, unsigned attrs) +{ + Rooted id(cx, NameToId(name)); + return DefineGeneric(cx, obj, id, value, getter, setter, attrs); +} + extern JSBool DefineElement(JSContext *cx, HandleObject obj, uint32_t index, const js::Value *value, JSPropertyOp getter, JSStrictPropertyOp setter, unsigned attrs); @@ -149,7 +158,8 @@ inline bool SetPropertyHelper(JSContext *cx, HandleObject obj, PropertyName *name, unsigned defineHow, Value *vp, JSBool strict) { - return SetPropertyHelper(cx, obj, RootedId(cx, NameToId(name)), defineHow, vp, strict); + Rooted id(cx, NameToId(name)); + return SetPropertyHelper(cx, obj, id, defineHow, vp, strict); } extern JSBool @@ -1141,8 +1151,8 @@ DefineNativeProperty(JSContext *cx, HandleObject obj, PropertyName *name, const PropertyOp getter, StrictPropertyOp setter, unsigned attrs, unsigned flags, int shortid, unsigned defineHow = 0) { - return DefineNativeProperty(cx, obj, RootedId(cx, NameToId(name)), - value, getter, setter, attrs, flags, + Rooted id(cx, NameToId(name)); + return DefineNativeProperty(cx, obj, id, value, getter, setter, attrs, flags, shortid, defineHow); } @@ -1157,7 +1167,8 @@ inline bool LookupPropertyWithFlags(JSContext *cx, HandleObject obj, PropertyName *name, unsigned flags, JSObject **objp, JSProperty **propp) { - return LookupPropertyWithFlags(cx, obj, RootedId(cx, NameToId(name)), flags, objp, propp); + Rooted id(cx, NameToId(name)); + return LookupPropertyWithFlags(cx, obj, id, flags, objp, propp); } /* @@ -1221,11 +1232,11 @@ const unsigned JSGET_CACHE_RESULT = 1; // from a caching interpreter opcode * scope containing shape unlocked. */ extern JSBool -js_NativeGet(JSContext *cx, JSObject *obj, JSObject *pobj, const js::Shape *shape, unsigned getHow, - js::Value *vp); +js_NativeGet(JSContext *cx, js::Handle obj, js::Handle pobj, + const js::Shape *shape, unsigned getHow, js::Value *vp); extern JSBool -js_NativeSet(JSContext *cx, JSObject *obj, const js::Shape *shape, bool added, +js_NativeSet(JSContext *cx, js::Handle obj, const js::Shape *shape, bool added, bool strict, js::Value *vp); namespace js { @@ -1254,7 +1265,8 @@ GetMethod(JSContext *cx, HandleObject obj, HandleId id, unsigned getHow, Value * inline bool GetMethod(JSContext *cx, HandleObject obj, PropertyName *name, unsigned getHow, Value *vp) { - return GetMethod(cx, obj, RootedId(cx, NameToId(name)), getHow, vp); + Rooted id(cx, NameToId(name)); + return GetMethod(cx, obj, id, getHow, vp); } /* diff --git a/js/src/jsobjinlines.h b/js/src/jsobjinlines.h index 80cdf6b3faf8..566b4f164e45 100644 --- a/js/src/jsobjinlines.h +++ b/js/src/jsobjinlines.h @@ -54,7 +54,8 @@ inline bool JSObject::enumerate(JSContext *cx, JSIterateOp iterop, js::Value *statep, jsid *idp) { JSNewEnumerateOp op = getOps()->enumerate; - return (op ? op : JS_EnumerateState)(cx, js::RootedObject(cx, this), iterop, statep, idp); + js::Rooted obj(cx, this); + return (op ? op : JS_EnumerateState)(cx, obj, iterop, statep, idp); } inline bool @@ -76,14 +77,16 @@ inline JSType JSObject::typeOf(JSContext *cx) { js::TypeOfOp op = getOps()->typeOf; - return (op ? op : js::baseops::TypeOf)(cx, js::RootedObject(cx, this)); + js::Rooted obj(cx, this); + return (op ? op : js::baseops::TypeOf)(cx, obj); } inline JSObject * JSObject::thisObject(JSContext *cx) { JSObjectOp op = getOps()->thisObject; - return op ? op(cx, js::RootedObject(cx, this)) : this; + js::Rooted obj(cx, this); + return op ? op(cx, obj) : this; } inline JSBool @@ -91,15 +94,15 @@ JSObject::setGeneric(JSContext *cx, js::HandleId id, js::Value *vp, JSBool stric { if (getOps()->setGeneric) return nonNativeSetProperty(cx, id, vp, strict); - return js::baseops::SetPropertyHelper(cx, - js::RootedObject(cx, this), - id, 0, vp, strict); + js::Rooted obj(cx, this); + return js::baseops::SetPropertyHelper(cx, obj, id, 0, vp, strict); } inline JSBool JSObject::setProperty(JSContext *cx, js::PropertyName *name, js::Value *vp, JSBool strict) { - return setGeneric(cx, js::RootedId(cx, js::NameToId(name)), vp, strict); + js::Rooted id(cx, js::NameToId(name)); + return setGeneric(cx, id, vp, strict); } inline JSBool @@ -107,13 +110,15 @@ JSObject::setElement(JSContext *cx, uint32_t index, js::Value *vp, JSBool strict { if (getOps()->setElement) return nonNativeSetElement(cx, index, vp, strict); - return js::baseops::SetElementHelper(cx, js::RootedObject(cx, this), index, 0, vp, strict); + js::Rooted obj(cx, this); + return js::baseops::SetElementHelper(cx, obj, index, 0, vp, strict); } inline JSBool JSObject::setSpecial(JSContext *cx, js::SpecialId sid, js::Value *vp, JSBool strict) { - return setGeneric(cx, js::RootedId(cx, SPECIALID_TO_JSID(sid)), vp, strict); + js::Rooted id(cx, SPECIALID_TO_JSID(sid)); + return setGeneric(cx, id, vp, strict); } inline JSBool @@ -121,26 +126,30 @@ JSObject::setGenericAttributes(JSContext *cx, js::HandleId id, unsigned *attrsp) { js::types::MarkTypePropertyConfigured(cx, this, id); js::GenericAttributesOp op = getOps()->setGenericAttributes; - return (op ? op : js::baseops::SetAttributes)(cx, js::RootedObject(cx, this), id, attrsp); + js::Rooted obj(cx, this); + return (op ? op : js::baseops::SetAttributes)(cx, obj, id, attrsp); } inline JSBool JSObject::setPropertyAttributes(JSContext *cx, js::PropertyName *name, unsigned *attrsp) { - return setGenericAttributes(cx, js::RootedId(cx, js::NameToId(name)), attrsp); + js::Rooted id(cx, js::NameToId(name)); + return setGenericAttributes(cx, id, attrsp); } inline JSBool JSObject::setElementAttributes(JSContext *cx, uint32_t index, unsigned *attrsp) { js::ElementAttributesOp op = getOps()->setElementAttributes; - return (op ? op : js::baseops::SetElementAttributes)(cx, js::RootedObject(cx, this), index, attrsp); + js::Rooted obj(cx, this); + return (op ? op : js::baseops::SetElementAttributes)(cx, obj, index, attrsp); } inline JSBool JSObject::setSpecialAttributes(JSContext *cx, js::SpecialId sid, unsigned *attrsp) { - return setGenericAttributes(cx, js::RootedId(cx, SPECIALID_TO_JSID(sid)), attrsp); + js::Rooted id(cx, SPECIALID_TO_JSID(sid)); + return setGenericAttributes(cx, id, attrsp); } inline bool @@ -168,19 +177,22 @@ JSObject::getGeneric(JSContext *cx, js::HandleObject receiver, js::HandleId id, inline JSBool JSObject::getProperty(JSContext *cx, js::HandleObject receiver, js::PropertyName *name, js::Value *vp) { - return getGeneric(cx, receiver, js::RootedId(cx, js::NameToId(name)), vp); + js::Rooted id(cx, js::NameToId(name)); + return getGeneric(cx, receiver, id, vp); } inline JSBool JSObject::getGeneric(JSContext *cx, js::HandleId id, js::Value *vp) { - return getGeneric(cx, js::RootedObject(cx, this), id, vp); + js::Rooted obj(cx, this); + return getGeneric(cx, obj, id, vp); } inline JSBool JSObject::getProperty(JSContext *cx, js::PropertyName *name, js::Value *vp) { - return getGeneric(cx, js::RootedId(cx, js::NameToId(name)), vp); + js::Rooted id(cx, js::NameToId(name)); + return getGeneric(cx, id, vp); } inline bool @@ -190,7 +202,8 @@ JSObject::deleteProperty(JSContext *cx, js::HandlePropertyName name, js::Value * js::types::AddTypePropertyId(cx, this, id, js::types::Type::UndefinedType()); js::types::MarkTypePropertyConfigured(cx, this, id); js::DeletePropertyOp op = getOps()->deleteProperty; - return (op ? op : js::baseops::DeleteProperty)(cx, js::RootedObject(cx, this), name, rval, strict); + js::Rooted obj(cx, this); + return (op ? op : js::baseops::DeleteProperty)(cx, obj, name, rval, strict); } inline bool @@ -214,7 +227,8 @@ JSObject::deleteSpecial(JSContext *cx, js::HandleSpecialId sid, js::Value *rval, js::types::AddTypePropertyId(cx, this, id, js::types::Type::UndefinedType()); js::types::MarkTypePropertyConfigured(cx, this, id); js::DeleteSpecialOp op = getOps()->deleteSpecial; - return (op ? op : js::baseops::DeleteSpecial)(cx, js::RootedObject(cx, this), sid, rval, strict); + js::Rooted obj(cx, this); + return (op ? op : js::baseops::DeleteSpecial)(cx, obj, sid, rval, strict); } inline void @@ -1026,7 +1040,8 @@ JSObject::lookupGeneric(JSContext *cx, js::HandleId id, JSObject **objp, JSPrope inline JSBool JSObject::lookupProperty(JSContext *cx, js::PropertyName *name, JSObject **objp, JSProperty **propp) { - return lookupGeneric(cx, js::RootedId(cx, js::NameToId(name)), objp, propp); + js::Rooted id(cx, js::NameToId(name)); + return lookupGeneric(cx, id, objp, propp); } inline JSBool @@ -1039,7 +1054,7 @@ JSObject::defineGeneric(JSContext *cx, js::HandleId id, const js::Value &value, JS_ASSERT(!(attrs & JSPROP_NATIVE_ACCESSORS)); js::DefineGenericOp op = getOps()->defineGeneric; - return (op ? op : js::baseops::DefineProperty)(cx, self, id, &value, getter, setter, attrs); + return (op ? op : js::baseops::DefineGeneric)(cx, self, id, &value, getter, setter, attrs); } inline JSBool @@ -1048,7 +1063,8 @@ JSObject::defineProperty(JSContext *cx, js::PropertyName *name, const js::Value JSStrictPropertyOp setter /* = JS_StrictPropertyStub */, unsigned attrs /* = JSPROP_ENUMERATE */) { - return defineGeneric(cx, js::RootedId(cx, js::NameToId(name)), value, getter, setter, attrs); + js::Rooted id(cx, js::NameToId(name)); + return defineGeneric(cx, id, value, getter, setter, attrs); } inline JSBool @@ -1069,7 +1085,8 @@ JSObject::defineSpecial(JSContext *cx, js::SpecialId sid, const js::Value &value JSStrictPropertyOp setter /* = JS_StrictPropertyStub */, unsigned attrs /* = JSPROP_ENUMERATE */) { - return defineGeneric(cx, js::RootedId(cx, SPECIALID_TO_JSID(sid)), value, getter, setter, attrs); + js::Rooted id(cx, SPECIALID_TO_JSID(sid)); + return defineGeneric(cx, id, value, getter, setter, attrs); } inline JSBool @@ -1084,7 +1101,8 @@ JSObject::lookupElement(JSContext *cx, uint32_t index, JSObject **objp, JSProper inline JSBool JSObject::lookupSpecial(JSContext *cx, js::SpecialId sid, JSObject **objp, JSProperty **propp) { - return lookupGeneric(cx, js::RootedId(cx, SPECIALID_TO_JSID(sid)), objp, propp); + js::Rooted id(cx, SPECIALID_TO_JSID(sid)); + return lookupGeneric(cx, id, objp, propp); } inline JSBool @@ -1105,7 +1123,8 @@ JSObject::getElement(JSContext *cx, js::HandleObject receiver, uint32_t index, j inline JSBool JSObject::getElement(JSContext *cx, uint32_t index, js::Value *vp) { - return getElement(cx, js::RootedObject(cx, this), index, vp); + js::Rooted obj(cx, this); + return getElement(cx, obj, index, vp); } inline JSBool @@ -1145,20 +1164,23 @@ JSObject::getElementIfPresent(JSContext *cx, js::HandleObject receiver, uint32_t inline JSBool JSObject::getSpecial(JSContext *cx, js::HandleObject receiver, js::SpecialId sid, js::Value *vp) { - return getGeneric(cx, receiver, js::RootedId(cx, SPECIALID_TO_JSID(sid)), vp); + js::Rooted id(cx, SPECIALID_TO_JSID(sid)); + return getGeneric(cx, receiver, id, vp); } inline JSBool JSObject::getGenericAttributes(JSContext *cx, js::HandleId id, unsigned *attrsp) { js::GenericAttributesOp op = getOps()->getGenericAttributes; - return (op ? op : js::baseops::GetAttributes)(cx, js::RootedObject(cx, this), id, attrsp); + js::Rooted obj(cx, this); + return (op ? op : js::baseops::GetAttributes)(cx, obj, id, attrsp); } inline JSBool JSObject::getPropertyAttributes(JSContext *cx, js::PropertyName *name, unsigned *attrsp) { - return getGenericAttributes(cx, js::RootedId(cx, js::NameToId(name)), attrsp); + js::Rooted id(cx, js::NameToId(name)); + return getGenericAttributes(cx, id, attrsp); } inline JSBool @@ -1173,7 +1195,8 @@ JSObject::getElementAttributes(JSContext *cx, uint32_t index, unsigned *attrsp) inline JSBool JSObject::getSpecialAttributes(JSContext *cx, js::SpecialId sid, unsigned *attrsp) { - return getGenericAttributes(cx, js::RootedId(cx, SPECIALID_TO_JSID(sid)), attrsp); + js::Rooted id(cx, SPECIALID_TO_JSID(sid)); + return getGenericAttributes(cx, id, attrsp); } inline bool diff --git a/js/src/json.cpp b/js/src/json.cpp index 6cc21bae2245..eefc51921a28 100644 --- a/js/src/json.cpp +++ b/js/src/json.cpp @@ -280,7 +280,8 @@ PreprocessValue(JSContext *cx, JSObject *holder, KeyType key, Value *vp, Stringi if (vp->isObject()) { Value toJSON; RootedId id(cx, NameToId(cx->runtime->atomState.toJSONAtom)); - if (!GetMethod(cx, RootedObject(cx, &vp->toObject()), id, 0, &toJSON)) + Rooted obj(cx, &vp->toObject()); + if (!GetMethod(cx, obj, id, 0, &toJSON)) return false; if (js_IsCallable(toJSON)) { @@ -855,7 +856,8 @@ Revive(JSContext *cx, const Value &reviver, Value *vp) if (!obj->defineProperty(cx, cx->runtime->atomState.emptyAtom, *vp)) return false; - return Walk(cx, obj, RootedId(cx, NameToId(cx->runtime->atomState.emptyAtom)), reviver, vp); + Rooted id(cx, NameToId(cx->runtime->atomState.emptyAtom)); + return Walk(cx, obj, id, reviver, vp); } namespace js { diff --git a/js/src/jsonparser.cpp b/js/src/jsonparser.cpp index 317ca2c4e16a..63f0ab959c14 100644 --- a/js/src/jsonparser.cpp +++ b/js/src/jsonparser.cpp @@ -549,7 +549,8 @@ JSONParser::parse(Value *vp) case FinishArrayElement: { Value v = valueStack.popCopy(); - if (!js_NewbornArrayPush(cx, RootedObject(cx, &valueStack.back().toObject()), v)) + Rooted obj(cx, &valueStack.back().toObject()); + if (!js_NewbornArrayPush(cx, obj, v)) return false; token = advanceAfterArrayElement(); if (token == Comma) { diff --git a/js/src/jsproxy.cpp b/js/src/jsproxy.cpp index 6f13d7d9388c..183d68e908cf 100644 --- a/js/src/jsproxy.cpp +++ b/js/src/jsproxy.cpp @@ -310,7 +310,8 @@ bool BaseProxyHandler::defaultValue(JSContext *cx, JSObject *proxy, JSType hint, Value *vp) { - return DefaultValue(cx, RootedObject(cx, proxy), hint, vp); + Rooted obj(cx, proxy); + return DefaultValue(cx, obj, hint, vp); } bool @@ -397,14 +398,14 @@ IndirectProxyHandler::getOwnPropertyDescriptor(JSContext *cx, JSObject *proxy, } bool -IndirectProxyHandler::defineProperty(JSContext *cx, JSObject *proxy, jsid id, +IndirectProxyHandler::defineProperty(JSContext *cx, JSObject *proxy, jsid id_, PropertyDescriptor *desc) { RootedObject obj(cx, GetProxyTargetObject(proxy)); - return CheckDefineProperty(cx, obj, RootedId(cx, id), RootedValue(cx, desc->value), - desc->getter, desc->setter, desc->attrs) && - JS_DefinePropertyById(cx, obj, id, desc->value, desc->getter, desc->setter, - desc->attrs); + Rooted id(cx, id_); + Rooted v(cx, desc->value); + return CheckDefineProperty(cx, obj, id, v, desc->getter, desc->setter, desc->attrs) && + JS_DefinePropertyById(cx, obj, id, v, desc->getter, desc->setter, desc->attrs); } bool @@ -523,25 +524,25 @@ IndirectProxyHandler::defaultValue(JSContext *cx, JSObject *proxy, JSType hint, bool IndirectProxyHandler::iteratorNext(JSContext *cx, JSObject *proxy, Value *vp) { - if (!js_IteratorMore(cx, RootedObject(cx, GetProxyTargetObject(proxy)), - vp)) + Rooted target(cx, GetProxyTargetObject(proxy)); + if (!js_IteratorMore(cx, target, vp)) return false; if (vp->toBoolean()) { *vp = cx->iterValue; - cx->iterValue.setUndefined(); - } else - vp->setMagic(JS_NO_ITER_VALUE); + cx->iterValue = UndefinedValue(); + } else { + *vp = MagicValue(JS_NO_ITER_VALUE); + } return true; } -DirectProxyHandler::DirectProxyHandler(void *family) : - IndirectProxyHandler(family) +DirectProxyHandler::DirectProxyHandler(void *family) + : IndirectProxyHandler(family) { } bool -DirectProxyHandler::has(JSContext *cx, JSObject *proxy, jsid id, - bool *bp) +DirectProxyHandler::has(JSContext *cx, JSObject *proxy, jsid id, bool *bp) { JSBool found; if (!JS_HasPropertyById(cx, GetProxyTargetObject(proxy), id, &found)) @@ -590,8 +591,8 @@ bool DirectProxyHandler::iterate(JSContext *cx, JSObject *proxy, unsigned flags, Value *vp) { - return GetIterator(cx, RootedObject(cx, GetProxyTargetObject(proxy)), - flags, vp); + Rooted target(cx, GetProxyTargetObject(proxy)); + return GetIterator(cx, target, flags, vp); } static bool @@ -599,7 +600,8 @@ GetTrap(JSContext *cx, JSObject *handler, PropertyName *name, Value *fvalp) { JS_CHECK_RECURSION(cx, return false); - return handler->getGeneric(cx, RootedId(cx, NameToId(name)), fvalp); + Rooted propname(cx, name); + return handler->getProperty(cx, propname, fvalp); } static bool @@ -1243,7 +1245,8 @@ static JSBool proxy_LookupProperty(JSContext *cx, HandleObject obj, HandlePropertyName name, JSObject **objp, JSProperty **propp) { - return proxy_LookupGeneric(cx, obj, RootedId(cx, NameToId(name)), objp, propp); + Rooted id(cx, NameToId(name)); + return proxy_LookupGeneric(cx, obj, id, objp, propp); } static JSBool @@ -1259,7 +1262,8 @@ proxy_LookupElement(JSContext *cx, HandleObject obj, uint32_t index, JSObject ** static JSBool proxy_LookupSpecial(JSContext *cx, HandleObject obj, HandleSpecialId sid, JSObject **objp, JSProperty **propp) { - return proxy_LookupGeneric(cx, obj, RootedId(cx, SPECIALID_TO_JSID(sid)), objp, propp); + Rooted id(cx, SPECIALID_TO_JSID(sid)); + return proxy_LookupGeneric(cx, obj, id, objp, propp); } static JSBool @@ -1280,7 +1284,8 @@ static JSBool proxy_DefineProperty(JSContext *cx, HandleObject obj, HandlePropertyName name, const Value *value, PropertyOp getter, StrictPropertyOp setter, unsigned attrs) { - return proxy_DefineGeneric(cx, obj, RootedId(cx, NameToId(name)), value, getter, setter, attrs); + Rooted id(cx, NameToId(name)); + return proxy_DefineGeneric(cx, obj, id, value, getter, setter, attrs); } static JSBool @@ -1297,8 +1302,8 @@ static JSBool proxy_DefineSpecial(JSContext *cx, HandleObject obj, HandleSpecialId sid, const Value *value, PropertyOp getter, StrictPropertyOp setter, unsigned attrs) { - return proxy_DefineGeneric(cx, obj, RootedId(cx, SPECIALID_TO_JSID(sid)), - value, getter, setter, attrs); + Rooted id(cx, SPECIALID_TO_JSID(sid)); + return proxy_DefineGeneric(cx, obj, id, value, getter, setter, attrs); } static JSBool @@ -1310,7 +1315,8 @@ proxy_GetGeneric(JSContext *cx, HandleObject obj, HandleObject receiver, HandleI static JSBool proxy_GetProperty(JSContext *cx, HandleObject obj, HandleObject receiver, HandlePropertyName name, Value *vp) { - return proxy_GetGeneric(cx, obj, receiver, RootedId(cx, NameToId(name)), vp); + Rooted id(cx, NameToId(name)); + return proxy_GetGeneric(cx, obj, receiver, id, vp); } static JSBool @@ -1332,7 +1338,8 @@ proxy_GetElementIfPresent(JSContext *cx, HandleObject obj, HandleObject receiver static JSBool proxy_GetSpecial(JSContext *cx, HandleObject obj, HandleObject receiver, HandleSpecialId sid, Value *vp) { - return proxy_GetGeneric(cx, obj, receiver, RootedId(cx, SPECIALID_TO_JSID(sid)), vp); + Rooted id(cx, SPECIALID_TO_JSID(sid)); + return proxy_GetGeneric(cx, obj, receiver, id, vp); } static JSBool @@ -1344,7 +1351,8 @@ proxy_SetGeneric(JSContext *cx, HandleObject obj, HandleId id, Value *vp, JSBool static JSBool proxy_SetProperty(JSContext *cx, HandleObject obj, HandlePropertyName name, Value *vp, JSBool strict) { - return proxy_SetGeneric(cx, obj, RootedId(cx, NameToId(name)), vp, strict); + Rooted id(cx, NameToId(name)); + return proxy_SetGeneric(cx, obj, id, vp, strict); } static JSBool @@ -1359,7 +1367,8 @@ proxy_SetElement(JSContext *cx, HandleObject obj, uint32_t index, Value *vp, JSB static JSBool proxy_SetSpecial(JSContext *cx, HandleObject obj, HandleSpecialId sid, Value *vp, JSBool strict) { - return proxy_SetGeneric(cx, obj, RootedId(cx, SPECIALID_TO_JSID(sid)), vp, strict); + Rooted id(cx, SPECIALID_TO_JSID(sid)); + return proxy_SetGeneric(cx, obj, id, vp, strict); } static JSBool @@ -1375,7 +1384,8 @@ proxy_GetGenericAttributes(JSContext *cx, HandleObject obj, HandleId id, unsigne static JSBool proxy_GetPropertyAttributes(JSContext *cx, HandleObject obj, HandlePropertyName name, unsigned *attrsp) { - return proxy_GetGenericAttributes(cx, obj, RootedId(cx, NameToId(name)), attrsp); + Rooted id(cx, NameToId(name)); + return proxy_GetGenericAttributes(cx, obj, id, attrsp); } static JSBool @@ -1390,7 +1400,8 @@ proxy_GetElementAttributes(JSContext *cx, HandleObject obj, uint32_t index, unsi static JSBool proxy_GetSpecialAttributes(JSContext *cx, HandleObject obj, HandleSpecialId sid, unsigned *attrsp) { - return proxy_GetGenericAttributes(cx, obj, RootedId(cx, SPECIALID_TO_JSID(sid)), attrsp); + Rooted id(cx, SPECIALID_TO_JSID(sid)); + return proxy_GetGenericAttributes(cx, obj, id, attrsp); } static JSBool @@ -1407,7 +1418,8 @@ proxy_SetGenericAttributes(JSContext *cx, HandleObject obj, HandleId id, unsigne static JSBool proxy_SetPropertyAttributes(JSContext *cx, HandleObject obj, HandlePropertyName name, unsigned *attrsp) { - return proxy_SetGenericAttributes(cx, obj, RootedId(cx, NameToId(name)), attrsp); + Rooted id(cx, NameToId(name)); + return proxy_SetGenericAttributes(cx, obj, id, attrsp); } static JSBool @@ -1422,7 +1434,8 @@ proxy_SetElementAttributes(JSContext *cx, HandleObject obj, uint32_t index, unsi static JSBool proxy_SetSpecialAttributes(JSContext *cx, HandleObject obj, HandleSpecialId sid, unsigned *attrsp) { - return proxy_SetGenericAttributes(cx, obj, RootedId(cx, SPECIALID_TO_JSID(sid)), attrsp); + Rooted id(cx, SPECIALID_TO_JSID(sid)); + return proxy_SetGenericAttributes(cx, obj, id, attrsp); } static JSBool @@ -1439,7 +1452,8 @@ proxy_DeleteGeneric(JSContext *cx, HandleObject obj, HandleId id, Value *rval, J static JSBool proxy_DeleteProperty(JSContext *cx, HandleObject obj, HandlePropertyName name, Value *rval, JSBool strict) { - return proxy_DeleteGeneric(cx, obj, RootedId(cx, NameToId(name)), rval, strict); + Rooted id(cx, NameToId(name)); + return proxy_DeleteGeneric(cx, obj, id, rval, strict); } static JSBool @@ -1454,7 +1468,8 @@ proxy_DeleteElement(JSContext *cx, HandleObject obj, uint32_t index, Value *rval static JSBool proxy_DeleteSpecial(JSContext *cx, HandleObject obj, HandleSpecialId sid, Value *rval, JSBool strict) { - return proxy_DeleteGeneric(cx, obj, RootedId(cx, SPECIALID_TO_JSID(sid)), rval, strict); + Rooted id(cx, SPECIALID_TO_JSID(sid)); + return proxy_DeleteGeneric(cx, obj, id, rval, strict); } static void diff --git a/js/src/jsscope.cpp b/js/src/jsscope.cpp index 10f32cda359e..cb45328f25b8 100644 --- a/js/src/jsscope.cpp +++ b/js/src/jsscope.cpp @@ -1013,7 +1013,9 @@ JSObject::shadowingShapeChange(JSContext *cx, const Shape &shape) bool JSObject::clearParent(JSContext *cx) { - return setParent(cx, RootedObject(cx, this), RootedObject(cx)); + Rooted obj(cx, this); + Rooted newParent(cx, NULL); + return setParent(cx, obj, newParent); } /* static */ bool diff --git a/js/src/jsscript.cpp b/js/src/jsscript.cpp index 97d189c0ed04..53ed9e96c7f6 100644 --- a/js/src/jsscript.cpp +++ b/js/src/jsscript.cpp @@ -1745,7 +1745,8 @@ js::CloneScript(JSContext *cx, HandleScript src) for (unsigned i = 0; i < names.length(); ++i) { if (JSAtom *atom = names[i].maybeAtom) { - if (!bindings.add(cx, RootedAtom(cx, atom), names[i].kind)) + Rooted root(cx, atom); + if (!bindings.add(cx, root, names[i].kind)) return NULL; } else { uint16_t _; diff --git a/js/src/jsscript.h b/js/src/jsscript.h index ae9899e1d6d5..bcc452bc9da7 100644 --- a/js/src/jsscript.h +++ b/js/src/jsscript.h @@ -175,7 +175,8 @@ class Bindings } bool addDestructuring(JSContext *cx, uint16_t *slotp) { *slotp = nargs; - return add(cx, RootedAtom(cx), ARGUMENT); + Rooted atom(cx, NULL); + return add(cx, atom, ARGUMENT); } void noteDup() { hasDup_ = true; } diff --git a/js/src/jsstr.cpp b/js/src/jsstr.cpp index fcc8007c9a11..9baa7f60edf6 100644 --- a/js/src/jsstr.cpp +++ b/js/src/jsstr.cpp @@ -428,15 +428,13 @@ ThisToStringForStringProto(JSContext *cx, CallReceiver call) if (call.thisv().isObject()) { RootedObject obj(cx, &call.thisv().toObject()); - if (obj->isString() && - ClassMethodIsNative(cx, obj, - &StringClass, - RootedId(cx, NameToId(cx->runtime->atomState.toStringAtom)), - js_str_toString)) - { - JSString *str = obj->asString().unbox(); - call.thisv().setString(str); - return str; + if (obj->isString()) { + Rooted id(cx, NameToId(cx->runtime->atomState.toStringAtom)); + if (ClassMethodIsNative(cx, obj, &StringClass, id, js_str_toString)) { + JSString *str = obj->asString().unbox(); + call.thisv().setString(str); + return str; + } } } else if (call.thisv().isNullOrUndefined()) { JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_CANT_CONVERT_TO, @@ -1984,7 +1982,7 @@ BuildFlatReplacement(JSContext *cx, HandleString textstr, HandleString repstr, return false; } } else { - if (!builder.append(RootedString(cx, str))) + if (!builder.append(str)) return false; } pos += str->length(); @@ -3065,8 +3063,9 @@ js_InitStringClass(JSContext *cx, JSObject *obj) Rooted global(cx, &obj->asGlobal()); + Rooted empty(cx, cx->runtime->emptyString); RootedObject proto(cx, global->createBlankPrototype(cx, &StringClass)); - if (!proto || !proto->asString().init(cx, RootedString(cx, cx->runtime->emptyString))) + if (!proto || !proto->asString().init(cx, empty)) return NULL; /* Now create the String function. */ @@ -3286,7 +3285,8 @@ js_ValueToSource(JSContext *cx, const Value &v) Value rval = NullValue(); Value fval; RootedId id(cx, NameToId(cx->runtime->atomState.toSourceAtom)); - if (!GetMethod(cx, RootedObject(cx, &v.toObject()), id, 0, &fval)) + Rooted obj(cx, &v.toObject()); + if (!GetMethod(cx, obj, id, 0, &fval)) return NULL; if (js_IsCallable(fval)) { if (!Invoke(cx, v, fval, 0, NULL, &rval)) diff --git a/js/src/jstypedarray.cpp b/js/src/jstypedarray.cpp index 6c44eb6cecee..f7c195f75124 100644 --- a/js/src/jstypedarray.cpp +++ b/js/src/jstypedarray.cpp @@ -349,7 +349,8 @@ JSBool ArrayBufferObject::obj_lookupProperty(JSContext *cx, HandleObject obj, HandlePropertyName name, JSObject **objp, JSProperty **propp) { - return obj_lookupGeneric(cx, obj, RootedId(cx, NameToId(name)), objp, propp); + Rooted id(cx, NameToId(name)); + return obj_lookupGeneric(cx, obj, id, objp, propp); } JSBool @@ -387,7 +388,8 @@ JSBool ArrayBufferObject::obj_lookupSpecial(JSContext *cx, HandleObject obj, HandleSpecialId sid, JSObject **objp, JSProperty **propp) { - return obj_lookupGeneric(cx, obj, RootedId(cx, SPECIALID_TO_JSID(sid)), objp, propp); + Rooted id(cx, SPECIALID_TO_JSID(sid)); + return obj_lookupGeneric(cx, obj, id, objp, propp); } JSBool @@ -402,7 +404,7 @@ ArrayBufferObject::obj_defineGeneric(JSContext *cx, HandleObject obj, HandleId i RootedObject delegate(cx, DelegateObject(cx, obj)); if (!delegate) return false; - return baseops::DefineProperty(cx, delegate, id, v, getter, setter, attrs); + return baseops::DefineGeneric(cx, delegate, id, v, getter, setter, attrs); } JSBool @@ -410,7 +412,8 @@ ArrayBufferObject::obj_defineProperty(JSContext *cx, HandleObject obj, HandlePropertyName name, const Value *v, PropertyOp getter, StrictPropertyOp setter, unsigned attrs) { - return obj_defineGeneric(cx, obj, RootedId(cx, NameToId(name)), v, getter, setter, attrs); + Rooted id(cx, NameToId(name)); + return obj_defineGeneric(cx, obj, id, v, getter, setter, attrs); } JSBool @@ -429,8 +432,8 @@ JSBool ArrayBufferObject::obj_defineSpecial(JSContext *cx, HandleObject obj, HandleSpecialId sid, const Value *v, PropertyOp getter, StrictPropertyOp setter, unsigned attrs) { - return obj_defineGeneric(cx, obj, RootedId(cx, SPECIALID_TO_JSID(sid)), - v, getter, setter, attrs); + Rooted id(cx, SPECIALID_TO_JSID(sid)); + return obj_defineGeneric(cx, obj, id, v, getter, setter, attrs); } JSBool @@ -474,7 +477,8 @@ ArrayBufferObject::obj_getProperty(JSContext *cx, HandleObject obj, nobj = DelegateObject(cx, nobj); if (!nobj) return false; - return baseops::GetProperty(cx, nobj, receiver, RootedId(cx, NameToId(name)), vp); + Rooted id(cx, NameToId(name)); + return baseops::GetProperty(cx, nobj, receiver, id, vp); } JSBool @@ -503,7 +507,8 @@ JSBool ArrayBufferObject::obj_getSpecial(JSContext *cx, HandleObject obj, HandleObject receiver, HandleSpecialId sid, Value *vp) { - return obj_getGeneric(cx, obj, receiver, RootedId(cx, SPECIALID_TO_JSID(sid)), vp); + Rooted id(cx, SPECIALID_TO_JSID(sid)); + return obj_getGeneric(cx, obj, receiver, id, vp); } JSBool @@ -548,7 +553,8 @@ ArrayBufferObject::obj_setGeneric(JSContext *cx, HandleObject obj, HandleId id, obj->reportNotExtensible(cx); return false; } - if (!SetProto(cx, obj, RootedObject(cx, vp->toObjectOrNull()), true)) { + Rooted newProto(cx, vp->toObjectOrNull()); + if (!SetProto(cx, obj, newProto, true)) { // this can be caused for example by setting x.__proto__ = x // restore delegate prototype chain SetProto(cx, delegate, oldDelegateProto, true); @@ -565,7 +571,8 @@ JSBool ArrayBufferObject::obj_setProperty(JSContext *cx, HandleObject obj, HandlePropertyName name, Value *vp, JSBool strict) { - return obj_setGeneric(cx, obj, RootedId(cx, NameToId(name)), vp, strict); + Rooted id(cx, NameToId(name)); + return obj_setGeneric(cx, obj, id, vp, strict); } JSBool @@ -583,7 +590,8 @@ JSBool ArrayBufferObject::obj_setSpecial(JSContext *cx, HandleObject obj, HandleSpecialId sid, Value *vp, JSBool strict) { - return obj_setGeneric(cx, obj, RootedId(cx, SPECIALID_TO_JSID(sid)), vp, strict); + Rooted id(cx, SPECIALID_TO_JSID(sid)); + return obj_setGeneric(cx, obj, id, vp, strict); } JSBool @@ -605,7 +613,8 @@ JSBool ArrayBufferObject::obj_getPropertyAttributes(JSContext *cx, HandleObject obj, HandlePropertyName name, unsigned *attrsp) { - return obj_getGenericAttributes(cx, obj, RootedId(cx, NameToId(name)), attrsp); + Rooted id(cx, NameToId(name)); + return obj_getGenericAttributes(cx, obj, id, attrsp); } JSBool @@ -622,7 +631,8 @@ JSBool ArrayBufferObject::obj_getSpecialAttributes(JSContext *cx, HandleObject obj, HandleSpecialId sid, unsigned *attrsp) { - return obj_getGenericAttributes(cx, obj, RootedId(cx, SPECIALID_TO_JSID(sid)), attrsp); + Rooted id(cx, SPECIALID_TO_JSID(sid)); + return obj_getGenericAttributes(cx, obj, id, attrsp); } JSBool @@ -645,7 +655,8 @@ JSBool ArrayBufferObject::obj_setPropertyAttributes(JSContext *cx, HandleObject obj, HandlePropertyName name, unsigned *attrsp) { - return obj_setGenericAttributes(cx, obj, RootedId(cx, NameToId(name)), attrsp); + Rooted id(cx, NameToId(name)); + return obj_setGenericAttributes(cx, obj, id, attrsp); } JSBool @@ -662,7 +673,8 @@ JSBool ArrayBufferObject::obj_setSpecialAttributes(JSContext *cx, HandleObject obj, HandleSpecialId sid, unsigned *attrsp) { - return obj_setGenericAttributes(cx, obj, RootedId(cx, SPECIALID_TO_JSID(sid)), attrsp); + Rooted id(cx, SPECIALID_TO_JSID(sid)); + return obj_setGenericAttributes(cx, obj, id, attrsp); } JSBool @@ -859,7 +871,8 @@ JSBool TypedArray::obj_lookupProperty(JSContext *cx, HandleObject obj, HandlePropertyName name, JSObject **objp, JSProperty **propp) { - return obj_lookupGeneric(cx, obj, RootedId(cx, NameToId(name)), objp, propp); + Rooted id(cx, NameToId(name)); + return obj_lookupGeneric(cx, obj, id, objp, propp); } JSBool @@ -887,7 +900,8 @@ JSBool TypedArray::obj_lookupSpecial(JSContext *cx, HandleObject obj, HandleSpecialId sid, JSObject **objp, JSProperty **propp) { - return obj_lookupGeneric(cx, obj, RootedId(cx, SPECIALID_TO_JSID(sid)), objp, propp); + Rooted id(cx, SPECIALID_TO_JSID(sid)); + return obj_lookupGeneric(cx, obj, id, objp, propp); } JSBool @@ -916,7 +930,8 @@ TypedArray::obj_getElementAttributes(JSContext *cx, HandleObject obj, uint32_t i JSBool TypedArray::obj_getSpecialAttributes(JSContext *cx, HandleObject obj, HandleSpecialId sid, unsigned *attrsp) { - return obj_getGenericAttributes(cx, obj, RootedId(cx, SPECIALID_TO_JSID(sid)), attrsp); + Rooted id(cx, SPECIALID_TO_JSID(sid)); + return obj_getGenericAttributes(cx, obj, id, attrsp); } JSBool @@ -1106,9 +1121,9 @@ class TypedArrayTemplate if (IsDefinitelyIndex(idval, &index)) return obj_getElement(cx, obj, receiver, index, vp); - SpecialId sid; - if (ValueIsSpecial(obj, &idval, &sid, cx)) - return obj_getSpecial(cx, obj, receiver, Rooted(cx, sid), vp); + Rooted sid(cx); + if (ValueIsSpecial(obj, &idval, sid.address(), cx)) + return obj_getSpecial(cx, obj, receiver, sid, vp); JSAtom *atom = ToAtom(cx, idval); if (!atom) @@ -1117,7 +1132,8 @@ class TypedArrayTemplate if (atom->isIndex(&index)) return obj_getElement(cx, obj, receiver, index, vp); - return obj_getProperty(cx, obj, receiver, RootedPropertyName(cx, atom->asPropertyName()), vp); + Rooted name(cx, atom->asPropertyName()); + return obj_getProperty(cx, obj, receiver, name, vp); } static JSBool @@ -1235,7 +1251,8 @@ class TypedArrayTemplate static JSBool obj_setProperty(JSContext *cx, HandleObject obj, HandlePropertyName name, Value *vp, JSBool strict) { - return obj_setGeneric(cx, obj, RootedId(cx, NameToId(name)), vp, strict); + Rooted id(cx, NameToId(name)); + return obj_setGeneric(cx, obj, id, vp, strict); } static JSBool @@ -1260,7 +1277,8 @@ class TypedArrayTemplate static JSBool obj_setSpecial(JSContext *cx, HandleObject obj, HandleSpecialId sid, Value *vp, JSBool strict) { - return obj_setGeneric(cx, obj, RootedId(cx, SPECIALID_TO_JSID(sid)), vp, strict); + Rooted id(cx, SPECIALID_TO_JSID(sid)); + return obj_setGeneric(cx, obj, id, vp, strict); } static JSBool @@ -1278,7 +1296,8 @@ class TypedArrayTemplate obj_defineProperty(JSContext *cx, HandleObject obj, HandlePropertyName name, const Value *v, PropertyOp getter, StrictPropertyOp setter, unsigned attrs) { - return obj_defineGeneric(cx, obj, RootedId(cx, NameToId(name)), v, getter, setter, attrs); + Rooted id(cx, NameToId(name)); + return obj_defineGeneric(cx, obj, id, v, getter, setter, attrs); } static JSBool @@ -1293,7 +1312,8 @@ class TypedArrayTemplate obj_defineSpecial(JSContext *cx, HandleObject obj, HandleSpecialId sid, const Value *v, PropertyOp getter, StrictPropertyOp setter, unsigned attrs) { - return obj_defineGeneric(cx, obj, RootedId(cx, SPECIALID_TO_JSID(sid)), v, getter, setter, attrs); + Rooted id(cx, SPECIALID_TO_JSID(sid)); + return obj_defineGeneric(cx, obj, id, v, getter, setter, attrs); } static JSBool @@ -1537,7 +1557,8 @@ class TypedArrayTemplate } } - return fromBuffer(cx, dataObj, byteOffset, length, RootedObject(cx)); + Rooted proto(cx, NULL); + return fromBuffer(cx, dataObj, byteOffset, length, proto); } /* subarray(start[, end]) */ @@ -2893,15 +2914,19 @@ JSFunctionSpec _typedArray::jsfuncs[] = { \ MOZ_ASSERT(nelements <= INT32_MAX); \ return TypedArrayTemplate::fromLength(cx, nelements); \ } \ - JS_FRIEND_API(JSObject *) JS_New ## Name ## ArrayFromArray(JSContext *cx, JSObject *other) \ + JS_FRIEND_API(JSObject *) JS_New ## Name ## ArrayFromArray(JSContext *cx, JSObject *other_)\ { \ - return TypedArrayTemplate::fromArray(cx, RootedObject(cx, other)); \ + Rooted other(cx, other_); \ + return TypedArrayTemplate::fromArray(cx, other); \ } \ JS_FRIEND_API(JSObject *) JS_New ## Name ## ArrayWithBuffer(JSContext *cx, \ - JSObject *arrayBuffer, uint32_t byteoffset, int32_t length) \ + JSObject *arrayBuffer_, uint32_t byteoffset, int32_t length) \ { \ MOZ_ASSERT(byteoffset <= INT32_MAX); \ - return TypedArrayTemplate::fromBuffer(cx, RootedObject(cx, arrayBuffer), byteoffset, length, RootedObject(cx)); \ + Rooted arrayBuffer(cx, arrayBuffer_); \ + Rooted proto(cx, NULL); \ + return TypedArrayTemplate::fromBuffer(cx, arrayBuffer, byteoffset, length, \ + proto); \ } \ JS_FRIEND_API(JSBool) JS_Is ## Name ## Array(JSObject *obj, JSContext *cx) \ { \ diff --git a/js/src/jswrapper.cpp b/js/src/jswrapper.cpp index a238610a1ec9..ea4274e65bfe 100644 --- a/js/src/jswrapper.cpp +++ b/js/src/jswrapper.cpp @@ -177,17 +177,20 @@ DirectWrapper::hasOwn(JSContext *cx, JSObject *wrapper, jsid id, bool *bp) } bool -DirectWrapper::get(JSContext *cx, JSObject *wrapper, JSObject *receiver, jsid id, Value *vp) +DirectWrapper::get(JSContext *cx, JSObject *wrapper, JSObject *receiver_, jsid id_, Value *vp) { vp->setUndefined(); // default result if we refuse to perform this action - GET(wrappedObject(wrapper)->getGeneric(cx, RootedObject(cx, receiver), RootedId(cx, id), vp)); + Rooted receiver(cx, receiver_); + Rooted id(cx, id_); + GET(wrappedObject(wrapper)->getGeneric(cx, receiver, id, vp)); } bool -DirectWrapper::set(JSContext *cx, JSObject *wrapper, JSObject *receiver, jsid id, bool strict, +DirectWrapper::set(JSContext *cx, JSObject *wrapper, JSObject *receiver, jsid id_, bool strict, Value *vp) { - SET(wrappedObject(wrapper)->setGeneric(cx, RootedId(cx, id), vp, strict)); + Rooted id(cx, id_); + SET(wrappedObject(wrapper)->setGeneric(cx, id, vp, strict)); } bool @@ -203,7 +206,8 @@ DirectWrapper::iterate(JSContext *cx, JSObject *wrapper, unsigned flags, Value * { vp->setUndefined(); // default result if we refuse to perform this action const jsid id = JSID_VOID; - GET(GetIterator(cx, RootedObject(cx, wrappedObject(wrapper)), flags, vp)); + Rooted wrapped(cx, wrappedObject(wrapper)); + GET(GetIterator(cx, wrapped, flags, vp)); } bool @@ -415,7 +419,8 @@ ErrorCopier::~ErrorCopier() if (exc.isObject() && exc.toObject().isError() && exc.toObject().getPrivate()) { cx->clearPendingException(); ac.leave(); - JSObject *copyobj = js_CopyErrorObject(cx, RootedObject(cx, &exc.toObject()), scope); + Rooted errObj(cx, &exc.toObject()); + JSObject *copyobj = js_CopyErrorObject(cx, errObj, scope); if (copyobj) cx->setPendingException(ObjectValue(*copyobj)); } diff --git a/js/src/jsxml.cpp b/js/src/jsxml.cpp index 7e002e7fa007..0a6ec8dd0ba3 100644 --- a/js/src/jsxml.cpp +++ b/js/src/jsxml.cpp @@ -386,7 +386,8 @@ ConvertQNameToString(JSContext *cx, JSObject *obj) if (!str) return NULL; } - str = js_ConcatStrings(cx, str, RootedString(cx, obj->getQNameLocalName())); + Rooted localName(cx, obj->getQNameLocalName()); + str = js_ConcatStrings(cx, str, localName); if (!str) return NULL; @@ -3999,7 +4000,8 @@ PutProperty(JSContext *cx, HandleObject obj_, HandleId id_, JSBool strict, jsval * Note that rxml can't be null here, because target * and targetprop are non-null. */ - ok = GetProperty(cx, RootedObject(cx, rxml->object), id, &attrval); + Rooted robj(cx, rxml->object); + ok = GetProperty(cx, robj, id, &attrval); if (!ok) goto out; if (JSVAL_IS_PRIMITIVE(attrval)) /* no such attribute */ @@ -4563,7 +4565,8 @@ ResolveValue(JSContext *cx, JSXML *list, JSXML **result) return JS_FALSE; RootedId id(cx, OBJECT_TO_JSID(targetprop)); - if (!GetProperty(cx, RootedObject(cx, base->object), id, &tv)) + Rooted baseObj(cx, base->object); + if (!GetProperty(cx, baseObj, id, &tv)) return JS_FALSE; target = (JSXML *) JSVAL_TO_OBJECT(tv)->getPrivate(); @@ -4573,9 +4576,9 @@ ResolveValue(JSContext *cx, JSXML *list, JSXML **result) return JS_TRUE; } tv = STRING_TO_JSVAL(cx->runtime->emptyString); - if (!PutProperty(cx, RootedObject(cx, base->object), id, false, &tv)) + if (!PutProperty(cx, baseObj, id, false, &tv)) return JS_FALSE; - if (!GetProperty(cx, RootedObject(cx, base->object), id, &tv)) + if (!GetProperty(cx, baseObj, id, &tv)) return JS_FALSE; target = (JSXML *) JSVAL_TO_OBJECT(tv)->getPrivate(); } @@ -4637,17 +4640,18 @@ static JSBool HasSimpleContent(JSXML *xml); static JSBool -HasFunctionProperty(JSContext *cx, JSObject *obj, jsid funid_, JSBool *found) +HasFunctionProperty(JSContext *cx, JSObject *obj_, jsid funid_, JSBool *found) { JSObject *pobj; JSProperty *prop; JSXML *xml; - JS_ASSERT(obj->getClass() == &XMLClass); + JS_ASSERT(obj_->getClass() == &XMLClass); RootedId funid(cx, funid_); - if (!baseops::LookupProperty(cx, RootedObject(cx, obj), funid, &pobj, &prop)) + Rooted obj(cx, obj_); + if (!baseops::LookupProperty(cx, obj, funid, &pobj, &prop)) return false; if (!prop) { xml = (JSXML *) obj->getPrivate(); @@ -4790,7 +4794,8 @@ static JSBool xml_lookupProperty(JSContext *cx, HandleObject obj, HandlePropertyName name, JSObject **objp, JSProperty **propp) { - return xml_lookupGeneric(cx, obj, RootedId(cx, NameToId(name)), objp, propp); + Rooted id(cx, NameToId(name)); + return xml_lookupGeneric(cx, obj, id, objp, propp); } static JSBool @@ -4809,9 +4814,8 @@ xml_lookupElement(JSContext *cx, HandleObject obj, uint32_t index, JSObject **ob return false; const Shape *shape = - js_AddNativeProperty(cx, RootedObject(cx, obj), id, GetProperty, PutProperty, - SHAPE_INVALID_SLOT, JSPROP_ENUMERATE, - 0, 0); + js_AddNativeProperty(cx, obj, id, GetProperty, PutProperty, SHAPE_INVALID_SLOT, + JSPROP_ENUMERATE, 0, 0); if (!shape) return false; @@ -4823,7 +4827,8 @@ xml_lookupElement(JSContext *cx, HandleObject obj, uint32_t index, JSObject **ob static JSBool xml_lookupSpecial(JSContext *cx, HandleObject obj, HandleSpecialId sid, JSObject **objp, JSProperty **propp) { - return xml_lookupGeneric(cx, obj, RootedId(cx, SPECIALID_TO_JSID(sid)), objp, propp); + Rooted id(cx, SPECIALID_TO_JSID(sid)); + return xml_lookupGeneric(cx, obj, id, objp, propp); } static JSBool @@ -4833,7 +4838,7 @@ xml_defineGeneric(JSContext *cx, HandleObject obj, HandleId id, const Value *v, if (IsFunctionObject(*v) || getter || setter || (attrs & JSPROP_ENUMERATE) == 0 || (attrs & (JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_SHARED))) { - return baseops::DefineProperty(cx, obj, id, v, getter, setter, attrs); + return baseops::DefineGeneric(cx, obj, id, v, getter, setter, attrs); } jsval tmp = *v; @@ -4844,7 +4849,8 @@ static JSBool xml_defineProperty(JSContext *cx, HandleObject obj, HandlePropertyName name, const Value *v, PropertyOp getter, StrictPropertyOp setter, unsigned attrs) { - return xml_defineGeneric(cx, obj, RootedId(cx, NameToId(name)), v, getter, setter, attrs); + Rooted id(cx, NameToId(name)); + return xml_defineGeneric(cx, obj, id, v, getter, setter, attrs); } static JSBool @@ -4861,7 +4867,8 @@ static JSBool xml_defineSpecial(JSContext *cx, HandleObject obj, HandleSpecialId sid, const Value *v, PropertyOp getter, StrictPropertyOp setter, unsigned attrs) { - return xml_defineGeneric(cx, obj, RootedId(cx, SPECIALID_TO_JSID(sid)), v, getter, setter, attrs); + Rooted id(cx, SPECIALID_TO_JSID(sid)); + return xml_defineGeneric(cx, obj, id, v, getter, setter, attrs); } static JSBool @@ -4878,7 +4885,8 @@ xml_getGeneric(JSContext *cx, HandleObject obj, HandleObject receiver, HandleId static JSBool xml_getProperty(JSContext *cx, HandleObject obj, HandleObject receiver, HandlePropertyName name, Value *vp) { - return xml_getGeneric(cx, obj, receiver, RootedId(cx, NameToId(name)), vp); + Rooted id(cx, NameToId(name)); + return xml_getGeneric(cx, obj, receiver, id, vp); } static JSBool @@ -4893,7 +4901,8 @@ xml_getElement(JSContext *cx, HandleObject obj, HandleObject receiver, uint32_t static JSBool xml_getSpecial(JSContext *cx, HandleObject obj, HandleObject receiver, HandleSpecialId sid, Value *vp) { - return xml_getGeneric(cx, obj, receiver, RootedId(cx, SPECIALID_TO_JSID(sid)), vp); + Rooted id(cx, SPECIALID_TO_JSID(sid)); + return xml_getGeneric(cx, obj, receiver, id, vp); } static JSBool @@ -4905,7 +4914,8 @@ xml_setGeneric(JSContext *cx, HandleObject obj, HandleId id, Value *vp, JSBool s static JSBool xml_setProperty(JSContext *cx, HandleObject obj, HandlePropertyName name, Value *vp, JSBool strict) { - return xml_setGeneric(cx, obj, RootedId(cx, NameToId(name)), vp, strict); + Rooted id(cx, NameToId(name)); + return xml_setGeneric(cx, obj, id, vp, strict); } static JSBool @@ -4920,7 +4930,8 @@ xml_setElement(JSContext *cx, HandleObject obj, uint32_t index, Value *vp, JSBoo static JSBool xml_setSpecial(JSContext *cx, HandleObject obj, HandleSpecialId sid, Value *vp, JSBool strict) { - return xml_setGeneric(cx, obj, RootedId(cx, SPECIALID_TO_JSID(sid)), vp, strict); + Rooted id(cx, SPECIALID_TO_JSID(sid)); + return xml_setGeneric(cx, obj, id, vp, strict); } static JSBool @@ -4937,7 +4948,8 @@ xml_getGenericAttributes(JSContext *cx, HandleObject obj, HandleId id, unsigned static JSBool xml_getPropertyAttributes(JSContext *cx, HandleObject obj, HandlePropertyName name, unsigned *attrsp) { - return xml_getGenericAttributes(cx, obj, RootedId(cx, NameToId(name)), attrsp); + Rooted id(cx, NameToId(name)); + return xml_getGenericAttributes(cx, obj, id, attrsp); } static JSBool @@ -4952,7 +4964,8 @@ xml_getElementAttributes(JSContext *cx, HandleObject obj, uint32_t index, unsign static JSBool xml_getSpecialAttributes(JSContext *cx, HandleObject obj, HandleSpecialId sid, unsigned *attrsp) { - return xml_getGenericAttributes(cx, obj, RootedId(cx, SPECIALID_TO_JSID(sid)), attrsp); + Rooted id(cx, SPECIALID_TO_JSID(sid)); + return xml_getGenericAttributes(cx, obj, id, attrsp); } static JSBool @@ -4973,7 +4986,8 @@ xml_setGenericAttributes(JSContext *cx, HandleObject obj, HandleId id, unsigned static JSBool xml_setPropertyAttributes(JSContext *cx, HandleObject obj, HandlePropertyName name, unsigned *attrsp) { - return xml_setGenericAttributes(cx, obj, RootedId(cx, NameToId(name)), attrsp); + Rooted id(cx, NameToId(name)); + return xml_setGenericAttributes(cx, obj, id, attrsp); } static JSBool @@ -4988,7 +5002,8 @@ xml_setElementAttributes(JSContext *cx, HandleObject obj, uint32_t index, unsign static JSBool xml_setSpecialAttributes(JSContext *cx, HandleObject obj, HandleSpecialId sid, unsigned *attrsp) { - return xml_setGenericAttributes(cx, obj, RootedId(cx, SPECIALID_TO_JSID(sid)), attrsp); + Rooted id(cx, SPECIALID_TO_JSID(sid)); + return xml_setGenericAttributes(cx, obj, id, attrsp); } static JSBool @@ -5037,7 +5052,8 @@ xml_deleteGeneric(JSContext *cx, HandleObject obj, HandleId id, Value *rval, JSB static JSBool xml_deleteProperty(JSContext *cx, HandleObject obj, HandlePropertyName name, Value *rval, JSBool strict) { - return xml_deleteGeneric(cx, obj, RootedId(cx, NameToId(name)), rval, strict); + Rooted id(cx, NameToId(name)); + return xml_deleteGeneric(cx, obj, id, rval, strict); } static JSBool @@ -5070,7 +5086,8 @@ xml_deleteElement(JSContext *cx, HandleObject obj, uint32_t index, Value *rval, static JSBool xml_deleteSpecial(JSContext *cx, HandleObject obj, HandleSpecialId sid, Value *rval, JSBool strict) { - return xml_deleteGeneric(cx, obj, RootedId(cx, SPECIALID_TO_JSID(sid)), rval, strict); + Rooted id(cx, SPECIALID_TO_JSID(sid)); + return xml_deleteGeneric(cx, obj, id, rval, strict); } static JSString * @@ -5211,19 +5228,20 @@ again: * 11.2.2.1 Step 3(d) onward. */ JSBool -js_GetXMLMethod(JSContext *cx, HandleObject obj, jsid id, Value *vp) +js_GetXMLMethod(JSContext *cx, HandleObject obj, jsid id_, Value *vp) { JS_ASSERT(obj->isXML()); + Rooted id(cx, id_); if (JSID_IS_OBJECT(id)) - js_GetLocalNameFromFunctionQName(JSID_TO_OBJECT(id), &id, cx); + js_GetLocalNameFromFunctionQName(JSID_TO_OBJECT(id), id.address(), cx); /* * As our callers have a bad habit of passing a pointer to an unrooted * local value as vp, we use a proper root here. */ AutoValueRooter tvr(cx); - JSBool ok = GetXMLFunction(cx, obj, RootedId(cx, id), tvr.addr()); + JSBool ok = GetXMLFunction(cx, obj, id, tvr.addr()); *vp = tvr.value(); return ok; } @@ -5502,10 +5520,6 @@ xml_addNamespace(JSContext *cx, unsigned argc, jsval *vp) static JSBool xml_appendChild(JSContext *cx, unsigned argc, jsval *vp) { - jsval v; - JSObject *vobj; - JSXML *vxml; - NON_LIST_XML_METHOD_PROLOG; xml = CHECK_COPY_ON_WRITE(cx, xml, obj); if (!xml) @@ -5515,20 +5529,21 @@ xml_appendChild(JSContext *cx, unsigned argc, jsval *vp) if (!js_GetAnyName(cx, name.address())) return JS_FALSE; + Value v; if (!GetProperty(cx, obj, name, &v)) return JS_FALSE; JS_ASSERT(!JSVAL_IS_PRIMITIVE(v)); - vobj = JSVAL_TO_OBJECT(v); + Rooted vobj(cx, &v.toObject()); JS_ASSERT(vobj->isXML()); - vxml = (JSXML *) vobj->getPrivate(); + JSXML *vxml = (JSXML *) vobj->getPrivate(); JS_ASSERT(vxml->xml_class == JSXML_CLASS_LIST); if (!IndexToId(cx, vxml->xml_kids.length, name.address())) return JS_FALSE; *vp = (argc != 0) ? vp[2] : JSVAL_VOID; - if (!PutProperty(cx, RootedObject(cx, JSVAL_TO_OBJECT(v)), name, false, vp)) + if (!PutProperty(cx, vobj, name, false, vp)) return JS_FALSE; *vp = OBJECT_TO_JSVAL(obj); @@ -5614,7 +5629,7 @@ ValueToIdForXML(JSContext *cx, jsval v, jsid *idp) } static JSBool -xml_child_helper(JSContext *cx, JSObject *obj, JSXML *xml, jsval name, +xml_child_helper(JSContext *cx, JSObject *obj_, JSXML *xml, jsval name, jsval *rval) { bool isIndex; @@ -5625,6 +5640,8 @@ xml_child_helper(JSContext *cx, JSObject *obj, JSXML *xml, jsval name, /* ECMA-357 13.4.4.6 */ JS_ASSERT(xml->xml_class != JSXML_CLASS_LIST); + Rooted obj(cx, obj_); + if (!IdValIsIndex(cx, name, &index, &isIndex)) return JS_FALSE; @@ -5649,7 +5666,7 @@ xml_child_helper(JSContext *cx, JSObject *obj, JSXML *xml, jsval name, if (!ValueToIdForXML(cx, name, id.address())) return JS_FALSE; - return GetProperty(cx, RootedObject(cx, obj), id, rval); + return GetProperty(cx, obj, id, rval); } /* XML and XMLList */ @@ -6334,9 +6351,11 @@ xml_normalize_helper(JSContext *cx, JSObject *obj, JSXML *xml) } else if (kid->xml_class == JSXML_CLASS_TEXT) { while (i + 1 < n && (kid2 = XMLARRAY_MEMBER(&xml->xml_kids, i + 1, JSXML)) && - kid2->xml_class == JSXML_CLASS_TEXT) { - str = js_ConcatStrings(cx, RootedString(cx, kid->xml_value), - RootedString(cx, kid2->xml_value)); + kid2->xml_class == JSXML_CLASS_TEXT) + { + Rooted lstr(cx, kid->xml_value); + Rooted rstr(cx, kid2->xml_value); + str = js_ConcatStrings(cx, lstr, rstr); if (!str) return JS_FALSE; NormalizingDelete(cx, xml, i + 1); @@ -6683,8 +6702,9 @@ xml_setChildren(JSContext *cx, unsigned argc, jsval *vp) if (!StartNonListXMLMethod(cx, vp, obj.address())) return JS_FALSE; + Rooted id(cx, NameToId(cx->runtime->atomState.starAtom)); *vp = argc != 0 ? vp[2] : JSVAL_VOID; /* local root */ - if (!PutProperty(cx, obj, RootedId(cx, NameToId(cx->runtime->atomState.starAtom)), false, vp)) + if (!PutProperty(cx, obj, id, false, vp)) return JS_FALSE; *vp = OBJECT_TO_JSVAL(obj); diff --git a/js/src/methodjit/Compiler.cpp b/js/src/methodjit/Compiler.cpp index 395f28065ae8..0f80241796e2 100644 --- a/js/src/methodjit/Compiler.cpp +++ b/js/src/methodjit/Compiler.cpp @@ -4822,27 +4822,29 @@ mjit::Compiler::jsop_getprop(PropertyName *name, JSValueType knownType, bool testObject; JSObject *singleton = (*PC == JSOP_GETPROP || *PC == JSOP_CALLPROP) ? pushedSingleton(0) : NULL; - if (singleton && singleton->isFunction() && !hasTypeBarriers(PC) && - testSingletonPropertyTypes(top, RootedId(cx, NameToId(name)), &testObject)) { - if (testObject) { - Jump notObject = frame.testObject(Assembler::NotEqual, top); - stubcc.linkExit(notObject, Uses(1)); - stubcc.leave(); - stubcc.masm.move(ImmPtr(name), Registers::ArgReg1); - OOL_STUBCALL(stubs::GetProp, REJOIN_FALLTHROUGH); - testPushedType(REJOIN_FALLTHROUGH, -1); + if (singleton && singleton->isFunction() && !hasTypeBarriers(PC)) { + Rooted id(cx, NameToId(name)); + if (testSingletonPropertyTypes(top, id, &testObject)) { + if (testObject) { + Jump notObject = frame.testObject(Assembler::NotEqual, top); + stubcc.linkExit(notObject, Uses(1)); + stubcc.leave(); + stubcc.masm.move(ImmPtr(name), Registers::ArgReg1); + OOL_STUBCALL(stubs::GetProp, REJOIN_FALLTHROUGH); + testPushedType(REJOIN_FALLTHROUGH, -1); + } + + frame.pop(); + frame.push(ObjectValue(*singleton)); + + if (script->hasScriptCounts && cx->typeInferenceEnabled()) + bumpPropCount(PC, PCCounts::PROP_STATIC); + + if (testObject) + stubcc.rejoin(Changes(1)); + + return true; } - - frame.pop(); - frame.push(ObjectValue(*singleton)); - - if (script->hasScriptCounts && cx->typeInferenceEnabled()) - bumpPropCount(PC, PCCounts::PROP_STATIC); - - if (testObject) - stubcc.rejoin(Changes(1)); - - return true; } /* Check if this is a property access we can make a loop invariant entry for. */ @@ -5119,7 +5121,8 @@ mjit::Compiler::testSingletonPropertyTypes(FrameEntry *top, HandleId id, bool *t JS_ASSERT_IF(top->isTypeKnown(), top->isType(JSVAL_TYPE_OBJECT)); types::TypeObject *object = types->getTypeObject(0); if (object && object->proto) { - if (!testSingletonProperty(RootedObject(cx, object->proto), id)) + Rooted proto(cx, object->proto); + if (!testSingletonProperty(proto, id)) return false; types->addFreeze(cx); @@ -5196,12 +5199,13 @@ mjit::Compiler::jsop_getprop_dispatch(PropertyName *name) if (ownTypes->isOwnProperty(cx, object, false)) return false; - if (!testSingletonProperty(RootedObject(cx, object->proto), id)) + Rooted proto(cx, object->proto); + if (!testSingletonProperty(proto, id)) return false; - if (object->proto->getType(cx)->unknownProperties()) + if (proto->getType(cx)->unknownProperties()) return false; - types::TypeSet *protoTypes = object->proto->type()->getProperty(cx, id, false); + types::TypeSet *protoTypes = proto->type()->getProperty(cx, id, false); if (!protoTypes) return false; JSObject *singleton = protoTypes->getSingleton(cx); @@ -6255,9 +6259,12 @@ mjit::Compiler::jsop_getgname(uint32_t index) /* Optimize singletons like Math for JSOP_CALLPROP. */ JSObject *obj = pushedSingleton(0); - if (obj && !hasTypeBarriers(PC) && testSingletonProperty(globalObj, RootedId(cx, NameToId(name)))) { - frame.push(ObjectValue(*obj)); - return true; + if (obj && !hasTypeBarriers(PC)) { + Rooted id(cx, NameToId(name)); + if (testSingletonProperty(globalObj, id)) { + frame.push(ObjectValue(*obj)); + return true; + } } jsid id = NameToId(name); diff --git a/js/src/methodjit/FastOps.cpp b/js/src/methodjit/FastOps.cpp index 5a033a09acba..a5533588664c 100644 --- a/js/src/methodjit/FastOps.cpp +++ b/js/src/methodjit/FastOps.cpp @@ -2655,11 +2655,11 @@ mjit::Compiler::jsop_initprop() JSObject *holder; JSProperty *prop = NULL; + Rooted id(cx, NameToId(name)); #ifdef DEBUG bool res = #endif - LookupPropertyWithFlags(cx, baseobj, RootedId(cx, NameToId(name)), - JSRESOLVE_QUALIFIED, &holder, &prop); + LookupPropertyWithFlags(cx, baseobj, id, JSRESOLVE_QUALIFIED, &holder, &prop); JS_ASSERT(res && prop && holder == baseobj); RegisterID objReg = frame.copyDataIntoReg(obj); diff --git a/js/src/methodjit/PolyIC.cpp b/js/src/methodjit/PolyIC.cpp index 4fa9abdbcae5..ff72f3b31a14 100644 --- a/js/src/methodjit/PolyIC.cpp +++ b/js/src/methodjit/PolyIC.cpp @@ -1665,7 +1665,7 @@ class ScopeNameCompiler : public PICStubCompiler bool retrieve(Value *vp, PICInfo::Kind kind) { JSObject *obj = getprop.obj; - JSObject *holder = getprop.holder; + Rooted holder(cx, getprop.holder); const JSProperty *prop = getprop.prop; if (!prop) { @@ -1690,7 +1690,7 @@ class ScopeNameCompiler : public PICStubCompiler } const Shape *shape = getprop.shape; - JSObject *normalized = obj; + Rooted normalized(cx, obj); if (obj->isWith() && !shape->hasDefaultGetter()) normalized = &obj->asWith().object(); NATIVE_GET(cx, normalized, holder, shape, 0, vp, return false); @@ -2437,7 +2437,8 @@ GetElementIC::attachTypedArray(VMFrame &f, JSObject *obj, const Value &v, jsid i disable(f, "generated typed array stub"); // Fetch the value as expected of Lookup_Cacheable for GetElement. - if (!obj->getGeneric(cx, RootedId(cx, id), vp)) + Rooted idRoot(cx, id); + if (!obj->getGeneric(cx, idRoot, vp)) return Lookup_Error; return Lookup_Cacheable; @@ -2504,11 +2505,11 @@ ic::GetElement(VMFrame &f, ic::GetElementIC *ic) } #endif - jsid id; + Rooted id(cx); if (idval.isInt32() && INT_FITS_IN_JSID(idval.toInt32())) { id = INT_TO_JSID(idval.toInt32()); } else { - if (!InternNonIntElementId(cx, obj, idval, &id)) + if (!InternNonIntElementId(cx, obj, idval, id.address())) THROW(); } @@ -2527,7 +2528,7 @@ ic::GetElement(VMFrame &f, ic::GetElementIC *ic) } } - if (!obj->getGeneric(cx, RootedId(cx, id), &f.regs.sp[-2])) + if (!obj->getGeneric(cx, id, &f.regs.sp[-2])) THROW(); #if JS_HAS_NO_SUCH_METHOD diff --git a/js/src/methodjit/StubCalls.cpp b/js/src/methodjit/StubCalls.cpp index 57c054f5b208..c5445340fa44 100644 --- a/js/src/methodjit/StubCalls.cpp +++ b/js/src/methodjit/StubCalls.cpp @@ -52,10 +52,10 @@ using namespace js::types; using namespace JSC; void JS_FASTCALL -stubs::BindName(VMFrame &f, PropertyName *name) +stubs::BindName(VMFrame &f, PropertyName *name_) { - JSObject *obj = FindIdentifierBase(f.cx, f.fp()->scopeChain(), - RootedPropertyName(f.cx, name)); + Rooted name(f.cx, name_); + JSObject *obj = FindIdentifierBase(f.cx, f.fp()->scopeChain(), name); if (!obj) THROW(); f.regs.sp[0].setObject(*obj); @@ -505,7 +505,8 @@ StubEqualityOp(VMFrame &f) JSObject *l = &lval.toObject(), *r = &rval.toObject(); if (JSEqualityOp eq = l->getClass()->ext.equality) { JSBool equal; - if (!eq(cx, RootedObject(cx, l), &rval, &equal)) + Rooted lobj(cx, l); + if (!eq(cx, lobj, &rval, &equal)) return false; cond = !!equal == EQ; } else { @@ -886,7 +887,8 @@ stubs::NewInitObject(VMFrame &f, JSObject *baseobj) JSObject *obj; if (baseobj) { - obj = CopyInitializerObject(cx, RootedObject(cx, baseobj)); + Rooted base(cx, baseobj); + obj = CopyInitializerObject(cx, base); } else { gc::AllocKind kind = GuessObjectGCKind(0); obj = NewBuiltinClassInstance(cx, &ObjectClass, kind); @@ -1065,8 +1067,8 @@ stubs::IterMore(VMFrame &f) JS_ASSERT(f.regs.sp[-1].isObject()); Value v; - JSObject *iterobj = &f.regs.sp[-1].toObject(); - if (!js_IteratorMore(f.cx, RootedObject(f.cx, iterobj), &v)) + Rooted iterobj(f.cx, &f.regs.sp[-1].toObject()); + if (!js_IteratorMore(f.cx, iterobj, &v)) THROWV(JS_FALSE); return v.toBoolean(); @@ -1400,9 +1402,8 @@ stubs::DefVarOrConst(VMFrame &f, PropertyName *dn) if (JSOp(*f.regs.pc) == JSOP_DEFCONST) attrs |= JSPROP_READONLY; - JSObject &obj = f.fp()->varObj(); - - if (!DefVarOrConstOperation(f.cx, RootedObject(f.cx, &obj), dn, attrs)) + Rooted varobj(f.cx, &f.fp()->varObj()); + if (!DefVarOrConstOperation(f.cx, varobj, dn, attrs)) THROW(); } diff --git a/js/src/shell/js.cpp b/js/src/shell/js.cpp index ef5aa3ce4b81..a5693dba6fb8 100644 --- a/js/src/shell/js.cpp +++ b/js/src/shell/js.cpp @@ -2782,7 +2782,8 @@ static JSBool resolver_resolve(JSContext *cx, HandleObject obj, HandleId id, unsigned flags, JSObject **objp) { jsval v = JS_GetReservedSlot(obj, 0); - return CopyProperty(cx, obj, RootedObject(cx, JSVAL_TO_OBJECT(v)), id, flags, objp); + Rooted vobj(cx, &v.toObject()); + return CopyProperty(cx, obj, vobj, id, flags, objp); } static JSBool @@ -2794,8 +2795,10 @@ resolver_enumerate(JSContext *cx, HandleObject obj) AutoIdArray ida(cx, JS_Enumerate(cx, referent)); bool ok = !!ida; JSObject *ignore; - for (size_t i = 0; ok && i < ida.length(); i++) - ok = CopyProperty(cx, obj, referent, RootedId(cx, ida[i]), JSRESOLVE_QUALIFIED, &ignore); + for (size_t i = 0; ok && i < ida.length(); i++) { + Rooted id(cx, ida[i]); + ok = CopyProperty(cx, obj, referent, id, JSRESOLVE_QUALIFIED, &ignore); + } return ok; } @@ -3147,13 +3150,13 @@ Parent(JSContext *cx, unsigned argc, jsval *vp) return false; } - JSObject *parent = JS_GetParent(JSVAL_TO_OBJECT(v)); + Rooted parent(cx, JS_GetParent(&v.toObject())); *vp = OBJECT_TO_JSVAL(parent); /* Outerize if necessary. Embrace the ugliness! */ if (parent) { if (JSObjectOp op = parent->getClass()->ext.outerObject) - *vp = OBJECT_TO_JSVAL(op(cx, RootedObject(cx, parent))); + *vp = OBJECT_TO_JSVAL(op(cx, parent)); } return true; diff --git a/js/src/shell/jsheaptools.cpp b/js/src/shell/jsheaptools.cpp index b0ab98b93ed7..2c7b4c1af511 100644 --- a/js/src/shell/jsheaptools.cpp +++ b/js/src/shell/jsheaptools.cpp @@ -552,7 +552,8 @@ FindReferences(JSContext *cx, unsigned argc, jsval *vp) /* Given the reversed map, find the referents of target. */ ReferenceFinder finder(cx, reverser); - JSObject *references = finder.findReferences(RootedObject(cx, &target.toObject())); + Rooted targetObj(cx, &target.toObject()); + JSObject *references = finder.findReferences(targetObj); if (!references) return false; diff --git a/js/src/vm/ArgumentsObject.cpp b/js/src/vm/ArgumentsObject.cpp index 6867fb7f953d..fed1741486ff 100644 --- a/js/src/vm/ArgumentsObject.cpp +++ b/js/src/vm/ArgumentsObject.cpp @@ -203,7 +203,7 @@ ArgSetter(JSContext *cx, HandleObject obj, HandleId id, JSBool strict, Value *vp */ RootedValue value(cx); return baseops::DeleteGeneric(cx, obj, id, value.address(), false) && - baseops::DefineProperty(cx, obj, id, vp, NULL, NULL, JSPROP_ENUMERATE); + baseops::DefineGeneric(cx, obj, id, vp, NULL, NULL, JSPROP_ENUMERATE); } static JSBool @@ -233,7 +233,7 @@ args_resolve(JSContext *cx, HandleObject obj, HandleId id, unsigned flags, } Value undef = UndefinedValue(); - if (!baseops::DefineProperty(cx, argsobj, id, &undef, ArgGetter, ArgSetter, attrs)) + if (!baseops::DefineGeneric(cx, argsobj, id, &undef, ArgGetter, ArgSetter, attrs)) return JS_FALSE; *objp = argsobj; @@ -282,7 +282,8 @@ NormalArgumentsObject::optimizedGetElem(JSContext *cx, StackFrame *fp, const Val if (!proto) return false; - return proto->getGeneric(cx, RootedId(cx, id), vp); + Rooted root(cx, id); + return proto->getGeneric(cx, root, vp); } static JSBool @@ -396,7 +397,7 @@ strictargs_resolve(JSContext *cx, HandleObject obj, HandleId id, unsigned flags, } Value undef = UndefinedValue(); - if (!baseops::DefineProperty(cx, argsobj, id, &undef, getter, setter, attrs)) + if (!baseops::DefineGeneric(cx, argsobj, id, &undef, getter, setter, attrs)) return false; *objp = argsobj; diff --git a/js/src/vm/Debugger.cpp b/js/src/vm/Debugger.cpp index b3b7d07ed878..e140f016c866 100644 --- a/js/src/vm/Debugger.cpp +++ b/js/src/vm/Debugger.cpp @@ -840,7 +840,7 @@ Debugger::parseResumptionValue(AutoCompartment &ac, bool ok, const Value &rv, Va /* Check that rv is {return: val} or {throw: val}. */ JSContext *cx = ac.context; - JSObject *obj; + Rooted obj(cx); const Shape *shape; jsid returnId = NameToId(cx->runtime->atomState.returnAtom); jsid throwId = NameToId(cx->runtime->atomState.throwAtom); @@ -878,11 +878,13 @@ CallMethodIfPresent(JSContext *cx, HandleObject obj, const char *name, int argc, { rval->setUndefined(); JSAtom *atom = js_Atomize(cx, name, strlen(name)); + if (!atom) + return false; + + Rooted id(cx, AtomToId(atom)); Value fval; - return atom && - GetMethod(cx, obj, RootedId(cx, AtomToId(atom)), 0, &fval) && - (!js_IsCallable(fval) || - Invoke(cx, ObjectValue(*obj), fval, argc, argv, rval)); + return GetMethod(cx, obj, id, 0, &fval) && + (!js_IsCallable(fval) || Invoke(cx, ObjectValue(*obj), fval, argc, argv, rval)); } JSTrapStatus @@ -1128,7 +1130,8 @@ Debugger::onTrap(JSContext *cx, Value *vp) if (!dbg->getScriptFrame(cx, fp, &argv[0])) return dbg->handleUncaughtException(ac, vp, false); Value rv; - bool ok = CallMethodIfPresent(cx, RootedObject(cx, bp->handler), "hit", 1, argv, &rv); + Rooted handler(cx, bp->handler); + bool ok = CallMethodIfPresent(cx, handler, "hit", 1, argv, &rv); JSTrapStatus st = dbg->parseResumptionValue(ac, ok, rv, vp, true); if (st != JSTRAP_CONTINUE) return st; @@ -2319,7 +2322,8 @@ Debugger::findScripts(JSContext *cx, unsigned argc, Value *vp) result->ensureDenseArrayInitializedLength(cx, 0, scripts.length()); for (size_t i = 0; i < scripts.length(); i++) { - JSObject *scriptObject = dbg->wrapScript(cx, Rooted(cx, scripts[i])); + JSObject *scriptObject = + dbg->wrapScript(cx, Handle::fromMarkedLocation(&scripts[i])); if (!scriptObject) return false; result->setDenseArrayElement(i, ObjectValue(*scriptObject)); @@ -2537,11 +2541,13 @@ DebuggerScript_getChildScripts(JSContext *cx, unsigned argc, Value *vp) * It is not really a child script of this script, so skip it. */ ObjectArray *objects = script->objects(); + Rooted funScript(cx); for (uint32_t i = script->savedCallerFun ? 1 : 0; i < objects->length; i++) { JSObject *obj = objects->vector[i]; if (obj->isFunction()) { JSFunction *fun = static_cast(obj); - JSObject *s = dbg->wrapScript(cx, Rooted(cx, fun->script())); + funScript = fun->script(); + JSObject *s = dbg->wrapScript(cx, funScript); if (!s || !js_NewbornArrayPush(cx, result, ObjectValue(*s))) return false; } @@ -3208,7 +3214,7 @@ DebuggerFrame_getArguments(JSContext *cx, unsigned argc, Value *vp) SetReservedSlot(argsobj, JSSLOT_DEBUGARGUMENTS_FRAME, ObjectValue(*thisobj)); JS_ASSERT(fp->numActualArgs() <= 0x7fffffff); - int32_t fargc = int32_t(fp->numActualArgs()); + unsigned fargc = fp->numActualArgs(); if (!DefineNativeProperty(cx, argsobj, cx->runtime->atomState.lengthAtom, Int32Value(fargc), NULL, NULL, JSPROP_PERMANENT | JSPROP_READONLY, 0, 0)) @@ -3216,12 +3222,16 @@ DebuggerFrame_getArguments(JSContext *cx, unsigned argc, Value *vp) return false; } - for (int32_t i = 0; i < fargc; i++) { + Rooted id(cx); + for (unsigned i = 0; i < fargc; i++) { RootedFunction getobj(cx); getobj = js_NewFunction(cx, NULL, DebuggerArguments_getArg, 0, 0, global, NULL, JSFunction::ExtendedFinalizeKind); + if (!getobj) + return false; + id = INT_TO_JSID(i); if (!getobj || - !DefineNativeProperty(cx, argsobj, RootedId(cx, INT_TO_JSID(i)), UndefinedValue(), + !DefineNativeProperty(cx, argsobj, id, UndefinedValue(), JS_DATA_TO_FUNC_PTR(PropertyOp, getobj.reference()), NULL, JSPROP_ENUMERATE | JSPROP_SHARED | JSPROP_GETTER, 0, 0)) { @@ -3247,7 +3257,8 @@ DebuggerFrame_getScript(JSContext *cx, unsigned argc, Value *vp) if (fp->isFunctionFrame() && !fp->isEvalFrame()) { JSFunction &callee = fp->callee(); if (callee.isInterpreted()) { - scriptObject = debug->wrapScript(cx, Rooted(cx, callee.script())); + Rooted script(cx, callee.script()); + scriptObject = debug->wrapScript(cx, script); if (!scriptObject) return false; } @@ -3256,8 +3267,8 @@ DebuggerFrame_getScript(JSContext *cx, unsigned argc, Value *vp) * We got eval, JS_Evaluate*, or JS_ExecuteScript non-function script * frames. */ - JSScript *script = fp->script(); - scriptObject = debug->wrapScript(cx, Rooted(cx, script)); + Rooted script(cx, fp->script()); + scriptObject = debug->wrapScript(cx, script); if (!scriptObject) return false; } @@ -3447,7 +3458,8 @@ DebuggerFrameEval(JSContext *cx, unsigned argc, Value *vp, EvalBindingsMode mode } for (size_t i = 0; i < keys.length(); i++) { Value *valp = &values[i]; - if (!bindingsobj->getGeneric(cx, bindingsobj, RootedId(cx, keys[i]), valp) || + if (!bindingsobj->getGeneric(cx, bindingsobj, + Handle::fromMarkedLocation(&keys[i]), valp) || !dbg->unwrapDebuggeeValue(cx, valp)) { return false; @@ -3716,7 +3728,8 @@ DebuggerObject_getScript(JSContext *cx, unsigned argc, Value *vp) return true; } - JSObject *scriptObject = dbg->wrapScript(cx, Rooted(cx, fun->script())); + Rooted script(cx, fun->script()); + JSObject *scriptObject = dbg->wrapScript(cx, script); if (!scriptObject) return false; @@ -3919,8 +3932,11 @@ DebuggerObject_defineProperties(JSContext *cx, unsigned argc, Value *vp) ErrorCopier ec(ac, dbg->toJSObject()); for (size_t i = 0; i < n; i++) { bool dummy; - if (!DefineProperty(cx, obj, RootedId(cx, rewrappedIds[i]), rewrappedDescs[i], true, &dummy)) + if (!DefineProperty(cx, obj, Handle::fromMarkedLocation(&rewrappedIds[i]), + rewrappedDescs[i], true, &dummy)) + { return false; + } } } diff --git a/js/src/vm/RegExpObject.cpp b/js/src/vm/RegExpObject.cpp index 0f1f471b2f80..3ab9e592af3d 100644 --- a/js/src/vm/RegExpObject.cpp +++ b/js/src/vm/RegExpObject.cpp @@ -97,14 +97,16 @@ RegExpObjectBuilder::clone(Handle other, Handle RegExpFlag staticsFlags = res->getFlags(); if ((origFlags & staticsFlags) != staticsFlags) { RegExpFlag newFlags = RegExpFlag(origFlags | staticsFlags); - return build(Rooted(cx, other->getSource()), newFlags); + Rooted source(cx, other->getSource()); + return build(source, newFlags); } RegExpGuard g; if (!other->getShared(cx, &g)) return NULL; - return build(RootedAtom(cx, other->getSource()), *g); + Rooted source(cx, other->getSource()); + return build(source, *g); } /* MatchPairs */ @@ -618,14 +620,12 @@ RegExpCompartment::get(JSContext *cx, JSAtom *atom, JSString *opt, RegExpGuard * /* Functions */ JSObject * -js::CloneRegExpObject(JSContext *cx, JSObject *obj, JSObject *proto) +js::CloneRegExpObject(JSContext *cx, JSObject *obj_, JSObject *proto_) { - JS_ASSERT(obj->isRegExp()); - JS_ASSERT(proto->isRegExp()); - RegExpObjectBuilder builder(cx); - return builder.clone(Rooted(cx, &obj->asRegExp()), - Rooted(cx, &proto->asRegExp())); + Rooted regex(cx, &obj_->asRegExp()); + Rooted proto(cx, &proto_->asRegExp()); + return builder.clone(regex, proto); } bool diff --git a/js/src/vm/ScopeObject.cpp b/js/src/vm/ScopeObject.cpp index 06369efd6780..245e6f6dbbbc 100644 --- a/js/src/vm/ScopeObject.cpp +++ b/js/src/vm/ScopeObject.cpp @@ -119,7 +119,8 @@ CallObject::create(JSContext *cx, JSScript *script, HandleObject enclosing, Hand */ if (&enclosing->global() != obj->getParent()) { JS_ASSERT(obj->getParent() == NULL); - if (!JSObject::setParent(cx, obj, RootedObject(cx, &enclosing->global()))) + Rooted global(cx, &enclosing->global()); + if (!JSObject::setParent(cx, obj, global)) return NULL; } @@ -158,7 +159,8 @@ CallObject::createForFunction(JSContext *cx, StackFrame *fp) } RootedScript script(cx, fp->script()); - CallObject *callobj = create(cx, script, scopeChain, RootedFunction(cx, &fp->callee())); + Rooted callee(cx, &fp->callee()); + CallObject *callobj = create(cx, script, scopeChain, callee); if (!callobj) return NULL; @@ -212,7 +214,8 @@ CallObject::createForStrictEval(JSContext *cx, StackFrame *fp) JS_ASSERT(cx->fp() == fp); JS_ASSERT(cx->regs().pc == fp->script()->code); - return create(cx, fp->script(), fp->scopeChain(), RootedFunction(cx)); + Rooted callee(cx, NULL); + return create(cx, fp->script(), fp->scopeChain(), callee); } JSBool @@ -303,8 +306,8 @@ DeclEnvObject::create(JSContext *cx, StackFrame *fp) return NULL; - if (!DefineNativeProperty(cx, obj, RootedId(cx, AtomToId(fp->fun()->atom)), - ObjectValue(fp->callee()), NULL, NULL, + Rooted id(cx, AtomToId(fp->fun()->atom)); + if (!DefineNativeProperty(cx, obj, id, ObjectValue(fp->callee()), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_READONLY, 0, 0)) { return NULL; @@ -354,7 +357,8 @@ with_LookupGeneric(JSContext *cx, HandleObject obj, HandleId id, JSObject **objp static JSBool with_LookupProperty(JSContext *cx, HandleObject obj, HandlePropertyName name, JSObject **objp, JSProperty **propp) { - return with_LookupGeneric(cx, obj, RootedId(cx, NameToId(name)), objp, propp); + Rooted id(cx, NameToId(name)); + return with_LookupGeneric(cx, obj, id, objp, propp); } static JSBool @@ -370,7 +374,8 @@ with_LookupElement(JSContext *cx, HandleObject obj, uint32_t index, JSObject **o static JSBool with_LookupSpecial(JSContext *cx, HandleObject obj, HandleSpecialId sid, JSObject **objp, JSProperty **propp) { - return with_LookupGeneric(cx, obj, RootedId(cx, SPECIALID_TO_JSID(sid)), objp, propp); + Rooted id(cx, SPECIALID_TO_JSID(sid)); + return with_LookupGeneric(cx, obj, id, objp, propp); } static JSBool @@ -382,7 +387,8 @@ with_GetGeneric(JSContext *cx, HandleObject obj, HandleObject receiver, HandleId static JSBool with_GetProperty(JSContext *cx, HandleObject obj, HandleObject receiver, HandlePropertyName name, Value *vp) { - return with_GetGeneric(cx, obj, receiver, RootedId(cx, NameToId(name)), vp); + Rooted id(cx, NameToId(name)); + return with_GetGeneric(cx, obj, receiver, id, vp); } static JSBool @@ -397,7 +403,8 @@ with_GetElement(JSContext *cx, HandleObject obj, HandleObject receiver, uint32_t static JSBool with_GetSpecial(JSContext *cx, HandleObject obj, HandleObject receiver, HandleSpecialId sid, Value *vp) { - return with_GetGeneric(cx, obj, receiver, RootedId(cx, SPECIALID_TO_JSID(sid)), vp); + Rooted id(cx, SPECIALID_TO_JSID(sid)); + return with_GetGeneric(cx, obj, receiver, id, vp); } static JSBool @@ -587,7 +594,8 @@ ClonedBlockObject::create(JSContext *cx, Handle block, Stac /* Set the parent if necessary, as for call objects. */ if (&fp->global() != obj->getParent()) { JS_ASSERT(obj->getParent() == NULL); - if (!JSObject::setParent(cx, obj, RootedObject(cx, &fp->global()))) + Rooted global(cx, &fp->global()); + if (!JSObject::setParent(cx, obj, global)) return NULL; } @@ -1325,18 +1333,21 @@ class DebugScopeProxy : public BaseProxyHandler if (handleUnaliasedAccess(cx, scope, id, GET, vp)) return true; - return scope.getGeneric(cx, RootedObject(cx, &scope), RootedId(cx, id), vp); + Rooted scopeObj(cx, &scope); + Rooted idRoot(cx, id); + return scope.getGeneric(cx, scopeObj, idRoot, vp); } - bool set(JSContext *cx, JSObject *proxy, JSObject *receiver, jsid id, bool strict, + bool set(JSContext *cx, JSObject *proxy, JSObject *receiver, jsid id_, bool strict, Value *vp) MOZ_OVERRIDE { ScopeObject &scope = proxy->asDebugScope().scope(); - if (handleUnaliasedAccess(cx, scope, id, SET, vp)) + if (handleUnaliasedAccess(cx, scope, id_, SET, vp)) return true; - return scope.setGeneric(cx, RootedId(cx, id), vp, strict); + Rooted id(cx, id_); + return scope.setGeneric(cx, id, vp, strict); } bool defineProperty(JSContext *cx, JSObject *proxy, jsid id, PropertyDescriptor *desc) MOZ_OVERRIDE diff --git a/js/xpconnect/src/XPCComponents.cpp b/js/xpconnect/src/XPCComponents.cpp index 10f7af469ab4..3972f857a98d 100644 --- a/js/xpconnect/src/XPCComponents.cpp +++ b/js/xpconnect/src/XPCComponents.cpp @@ -4079,7 +4079,7 @@ nsXPCComponents_Utils::GetGlobalForObject(const JS::Value& object, // a wrapper for the foreign global. So we need to unwrap before getting the // parent, enter the compartment for the duration of the call, and wrap the // result. - JSObject *obj = JSVAL_TO_OBJECT(object); + JS::Rooted obj(cx, JSVAL_TO_OBJECT(object)); obj = js::UnwrapObject(obj); { JSAutoEnterCompartment ac; @@ -4087,12 +4087,12 @@ nsXPCComponents_Utils::GetGlobalForObject(const JS::Value& object, return NS_ERROR_FAILURE; obj = JS_GetGlobalForObject(cx, obj); } - JS_WrapObject(cx, &obj); + JS_WrapObject(cx, obj.address()); *retval = OBJECT_TO_JSVAL(obj); // Outerize if necessary. if (JSObjectOp outerize = js::GetObjectClass(obj)->ext.outerObject) - *retval = OBJECT_TO_JSVAL(outerize(cx, JS::RootedObject(cx, obj))); + *retval = OBJECT_TO_JSVAL(outerize(cx, obj)); return NS_OK; }