From 141bb389bfa5e1620934a1798fd7e1318e0af8e2 Mon Sep 17 00:00:00 2001 From: Ed Morley Date: Thu, 21 Jun 2012 10:00:36 +0100 Subject: [PATCH] Backout 1c5a8d617bff (bug 765990), 617cb36ead59, b3067d05a76a (bug 760995), 79f9a61a1e43 (bug 426163) for bustage --- dom/base/nsDOMWindowUtils.cpp | 4 +- js/src/builtin/MapObject.cpp | 8 +- js/src/builtin/RegExp.cpp | 20 ++- js/src/frontend/BytecodeEmitter.cpp | 4 +- js/src/frontend/Parser.cpp | 9 +- js/src/gc/Root.h | 13 +- js/src/jsapi.cpp | 107 +++++++--------- js/src/jsarray.cpp | 48 +++----- js/src/jscntxt.h | 2 +- js/src/jscompartment.cpp | 4 +- js/src/jsdate.cpp | 4 +- js/src/jsdbgapi.cpp | 3 +- js/src/jsexn.cpp | 3 +- js/src/jsfriendapi.cpp | 9 +- js/src/jsfun.cpp | 3 +- js/src/jsfuninlines.h | 10 +- js/src/jsinfer.cpp | 4 +- js/src/jsinterp.cpp | 6 +- js/src/jsinterpinlines.h | 18 ++- js/src/jsobj.cpp | 182 ++++++++++++---------------- js/src/jsobj.h | 32 ++--- js/src/jsobjinlines.h | 79 +++++------- js/src/json.cpp | 6 +- js/src/jsonparser.cpp | 3 +- js/src/jsproxy.cpp | 81 +++++-------- js/src/jsscope.cpp | 4 +- js/src/jsscript.cpp | 3 +- js/src/jsscript.h | 3 +- js/src/jsstr.cpp | 24 ++-- js/src/jstypedarray.cpp | 87 +++++-------- js/src/jswrapper.cpp | 17 +-- js/src/jsxml.cpp | 104 +++++++--------- js/src/methodjit/Compiler.cpp | 55 ++++----- js/src/methodjit/FastOps.cpp | 4 +- js/src/methodjit/PolyIC.cpp | 13 +- js/src/methodjit/StubCalls.cpp | 21 ++-- js/src/shell/js.cpp | 13 +- js/src/shell/jsheaptools.cpp | 3 +- js/src/vm/ArgumentsObject.cpp | 9 +- js/src/vm/Debugger.cpp | 50 +++----- js/src/vm/RegExpObject.cpp | 16 +-- js/src/vm/ScopeObject.cpp | 39 +++--- js/xpconnect/src/XPCComponents.cpp | 6 +- mfbt/Assertions.h | 36 +----- mfbt/HashFunctions.cpp | 1 - mfbt/HashFunctions.h | 1 - mfbt/Scoped.h | 10 +- 47 files changed, 469 insertions(+), 712 deletions(-) diff --git a/dom/base/nsDOMWindowUtils.cpp b/dom/base/nsDOMWindowUtils.cpp index 6d69e267dacb1..346deb715b30f 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; } - JS::Rooted parent(aCx, JS_GetParent(JSVAL_TO_OBJECT(aObject))); + JSObject* parent = 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, parent)); + *aParent = OBJECT_TO_JSVAL(outerize(aCx, JS::RootedObject(aCx, parent))); } } diff --git a/js/src/builtin/MapObject.cpp b/js/src/builtin/MapObject.cpp index a7893d5d6e8c7..9fca8d2a5ec32 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) { - Rooted global(cx, &obj->asGlobal()); - return InitClass(cx, global, &class_, JSProto_Map, construct, methods); + return InitClass(cx, Rooted(cx, &obj->asGlobal()), + &class_, JSProto_Map, construct, methods); } void @@ -348,8 +348,8 @@ JSFunctionSpec SetObject::methods[] = { JSObject * SetObject::initClass(JSContext *cx, JSObject *obj) { - Rooted global(cx, &obj->asGlobal()); - return InitClass(cx, global, &class_, JSProto_Set, construct, methods); + return InitClass(cx, Rooted(cx, &obj->asGlobal()), + &class_, JSProto_Set, construct, methods); } void diff --git a/js/src/builtin/RegExp.cpp b/js/src/builtin/RegExp.cpp index 20e278283bc2e..6d1a611b04aee 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(Handle name, Value v) { - return !!baseops::DefineProperty(cx, array, name, &v, + bool setProperty(JSAtom *name, Value v) { + return !!baseops::DefineProperty(cx, array, RootedId(cx, AtomToId(name)), &v, JS_PropertyStub, JS_StrictPropertyStub, JSPROP_ENUMERATE); } @@ -38,14 +38,12 @@ class RegExpMatchBuilder } bool setIndex(int index) { - Rooted name(cx, cx->runtime->atomState.indexAtom); - return setProperty(name, Int32Value(index)); + return setProperty(cx->runtime->atomState.indexAtom, Int32Value(index)); } bool setInput(JSString *str) { JS_ASSERT(str); - Rooted name(cx, cx->runtime->atomState.inputAtom); - return setProperty(name, StringValue(str)); + return setProperty(cx->runtime->atomState.inputAtom, StringValue(str)); } }; @@ -196,8 +194,8 @@ CompileRegExpObject(JSContext *cx, RegExpObjectBuilder &builder, CallArgs args) { if (args.length() == 0) { RegExpStatics *res = cx->regExpStatics(); - Rooted empty(cx, cx->runtime->emptyString); - RegExpObject *reobj = builder.build(empty, res->getFlags()); + RegExpObject *reobj = builder.build(RootedAtom(cx, cx->runtime->emptyString), + res->getFlags()); if (!reobj) return false; args.rval() = ObjectValue(*reobj); @@ -244,8 +242,7 @@ CompileRegExpObject(JSContext *cx, RegExpObjectBuilder &builder, CallArgs args) if (!sourceObj.getProperty(cx, cx->runtime->atomState.sourceAtom, &v)) return false; - Rooted sourceAtom(cx, &v.toString()->asAtom()); - RegExpObject *reobj = builder.build(sourceAtom, flags); + RegExpObject *reobj = builder.build(RootedAtom(cx, &v.toString()->asAtom()), flags); if (!reobj) return false; @@ -465,8 +462,7 @@ js_InitRegExpClass(JSContext *cx, JSObject *obj) proto->setPrivate(NULL); RegExpObjectBuilder builder(cx, &proto->asRegExp()); - Rooted empty(cx, cx->runtime->emptyString); - if (!builder.build(empty, RegExpFlag(0))) + if (!builder.build(RootedAtom(cx, cx->runtime->emptyString), 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 8710dfe41e39a..208967f7077b0 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()); - Rooted id(cx, AtomToId(pn3->pn_atom)); - if (!DefineNativeProperty(cx, obj, id, UndefinedValue(), NULL, NULL, + if (!DefineNativeProperty(cx, obj, RootedId(cx, AtomToId(pn3->pn_atom)), + UndefinedValue(), NULL, NULL, JSPROP_ENUMERATE, 0, 0)) { return false; diff --git a/js/src/frontend/Parser.cpp b/js/src/frontend/Parser.cpp index fcc4e6733f33c..1448986fc340a 100644 --- a/js/src/frontend/Parser.cpp +++ b/js/src/frontend/Parser.cpp @@ -540,8 +540,7 @@ BindLocalVariable(JSContext *cx, TreeContext *tc, ParseNode *pn, BindingKind kin JS_ASSERT(kind == VARIABLE || kind == CONSTANT); unsigned index = tc->sc->bindings.numVars(); - Rooted atom(cx, pn->pn_atom); - if (!tc->sc->bindings.add(cx, atom, kind)) + if (!tc->sc->bindings.add(cx, RootedAtom(cx, pn->pn_atom), kind)) return false; if (!pn->pn_cookie.set(cx, tc->staticLevel, index)) @@ -605,7 +604,7 @@ Parser::functionBody(FunctionBodyType type) if (!CheckStrictParameters(context, this)) return NULL; - Rooted arguments(context, context->runtime->atomState.argumentsAtom); + Rooted const arguments(context, context->runtime->atomState.argumentsAtom); /* * Non-top-level functions use JSOP_DEFFUN which is a dynamic scope @@ -6852,8 +6851,8 @@ Parser::primaryExpr(TokenKind tt, bool afterDoubleDot) pn->pn_xflags |= PNX_NONCONST; /* NB: Getter function in { get x(){} } is unnamed. */ - Rooted funName(context, NULL); - pn2 = functionDef(funName, op == JSOP_GETTER ? Getter : Setter, Expression); + pn2 = functionDef(RootedPropertyName(context, NULL), + 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 4505ab1d3acbf..6b87ca8e60f98 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(Rooted &root); + template inline Handle(const Rooted &root); const T *address() const { return ptr; } T value() const { return *ptr; } @@ -163,6 +163,15 @@ 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) @@ -208,7 +217,7 @@ class Rooted template template inline -Handle::Handle(Rooted &root) +Handle::Handle(const Rooted &root) { testAssign(); ptr = reinterpret_cast(root.address()); diff --git a/js/src/jsapi.cpp b/js/src/jsapi.cpp index a56918e823b65..18015169e5331 100644 --- a/js/src/jsapi.cpp +++ b/js/src/jsapi.cpp @@ -1779,8 +1779,7 @@ JS_InitStandardClasses(JSContext *cx, JSObject *obj) assertSameCompartment(cx, obj); - Rooted global(cx, &obj->global()); - return GlobalObject::initStandardClasses(cx, global); + return GlobalObject::initStandardClasses(cx, Rooted(cx, &obj->global())); } #define CLASP(name) (&name##Class) @@ -3144,7 +3143,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, obj, type, vp); + return DefaultValue(cx, RootedObject(cx, obj), type, vp); } JS_PUBLIC_API(JSObject *) @@ -3232,15 +3231,12 @@ 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_); - - Rooted obj(cx, obj_); - Rooted proto(cx, proto_); - return SetProto(cx, obj, proto, JS_FALSE); + assertSameCompartment(cx, obj, proto); + return SetProto(cx, RootedObject(cx, obj), RootedObject(cx, proto), JS_FALSE); } JS_PUBLIC_API(JSObject *) @@ -3251,17 +3247,14 @@ 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_); - - Rooted obj(cx, obj_); - Rooted parent(cx, parent_); - return JSObject::setParent(cx, obj, parent); + JS_ASSERT(!obj->isScope()); + JS_ASSERT(parent || !obj->getParent()); + assertSameCompartment(cx, obj, parent); + return JSObject::setParent(cx, RootedObject(cx, obj), RootedObject(cx, parent)); } JS_PUBLIC_API(JSObject *) @@ -3811,15 +3804,12 @@ 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); - - Rooted obj(cx, obj_); - Rooted id(cx, id_); - return js_DefineOwnProperty(cx, obj, id, descriptor, bp); + assertSameCompartment(cx, obj, id, descriptor); + return js_DefineOwnProperty(cx, RootedObject(cx, obj), RootedId(cx, id), descriptor, bp); } JS_PUBLIC_API(JSObject *) @@ -3995,14 +3985,11 @@ 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); - - Rooted obj(cx, obj_); - Rooted id(cx, id_); - return GetOwnPropertyDescriptor(cx, obj, id, vp); + return GetOwnPropertyDescriptor(cx, RootedObject(cx, obj), RootedId(cx, id), vp); } static JSBool @@ -4031,8 +4018,7 @@ JS_SetPropertyAttributes(JSContext *cx, JSObject *obj, const char *name, unsigned attrs, JSBool *foundp) { JSAtom *atom = js_Atomize(cx, name, strlen(name)); - Rooted id(cx, AtomToId(atom)); - return atom && SetPropertyAttributesById(cx, obj, id, attrs, foundp); + return atom && SetPropertyAttributesById(cx, obj, RootedId(cx, AtomToId(atom)), attrs, foundp); } JS_PUBLIC_API(JSBool) @@ -4040,8 +4026,7 @@ JS_SetUCPropertyAttributes(JSContext *cx, JSObject *obj, const jschar *name, siz unsigned attrs, JSBool *foundp) { JSAtom *atom = js_AtomizeChars(cx, name, AUTO_NAMELEN(name, namelen)); - Rooted id(cx, AtomToId(atom)); - return atom && SetPropertyAttributesById(cx, obj, id, attrs, foundp); + return atom && SetPropertyAttributesById(cx, obj, RootedId(cx, AtomToId(atom)), attrs, foundp); } JS_PUBLIC_API(JSBool) @@ -4065,11 +4050,9 @@ 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) { - Rooted obj(cx, obj_); - Rooted id(cx, id_); - return baseops::GetPropertyDefault(cx, obj, id, def, vp); + return baseops::GetPropertyDefault(cx, RootedObject(cx, obj), RootedId(cx, id), def, vp); } JS_PUBLIC_API(JSBool) @@ -4201,10 +4184,8 @@ JS_DeletePropertyById2(JSContext *cx, JSObject *obj, jsid id, jsval *rval) assertSameCompartment(cx, obj, id); JSAutoResolveFlags rf(cx, JSRESOLVE_QUALIFIED); - if (JSID_IS_SPECIAL(id)) { - Rooted sid(cx, JSID_TO_SPECIALID(id)); - return obj->deleteSpecial(cx, sid, rval, false); - } + if (JSID_IS_SPECIAL(id)) + return obj->deleteSpecial(cx, Rooted(cx, JSID_TO_SPECIALID(id)), rval, false); return obj->deleteByValue(cx, IdToValue(id), rval, false); } @@ -4450,14 +4431,12 @@ 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_); - - Rooted obj(cx, obj_); - return ElementIteratorObject::create(cx, obj); + assertSameCompartment(cx, obj); + return ElementIteratorObject::create(cx, RootedObject(cx, obj)); } JS_PUBLIC_API(JSObject *) @@ -4749,8 +4728,6 @@ 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. @@ -4763,8 +4740,11 @@ JS_DefineFunctions(JSContext *cx, JSObject *obj_, JSFunctionSpec *fs) } flags &= ~JSFUN_GENERIC_NATIVE; - fun = js_DefineFunction(cx, ctor, id, js_generic_native_method_dispatcher, - fs->nargs + 1, flags, JSFunction::ExtendedFinalizeKind); + fun = js_DefineFunction(cx, ctor, RootedId(cx, AtomToId(atom)), + js_generic_native_method_dispatcher, + fs->nargs + 1, + flags, + JSFunction::ExtendedFinalizeKind); if (!fun) return JS_FALSE; @@ -4775,7 +4755,8 @@ JS_DefineFunctions(JSContext *cx, JSObject *obj_, JSFunctionSpec *fs) fun->setExtendedSlot(0, PrivateValue(fs)); } - fun = js_DefineFunction(cx, obj, id, fs->call, fs->nargs, flags); + fun = js_DefineFunction(cx, obj, + RootedId(cx, AtomToId(atom)), fs->call, fs->nargs, flags); if (!fun) return JS_FALSE; } @@ -4795,8 +4776,7 @@ JS_DefineFunction(JSContext *cx, JSObject *obj_, const char *name, JSNative call JSAtom *atom = js_Atomize(cx, name, strlen(name)); if (!atom) return NULL; - Rooted id(cx, AtomToId(atom)); - return js_DefineFunction(cx, obj, id, call, nargs, attrs); + return js_DefineFunction(cx, obj, RootedId(cx, AtomToId(atom)), call, nargs, attrs); } JS_PUBLIC_API(JSFunction *) @@ -4813,8 +4793,7 @@ JS_DefineUCFunction(JSContext *cx, JSObject *obj_, JSAtom *atom = js_AtomizeChars(cx, name, AUTO_NAMELEN(name, namelen)); if (!atom) return NULL; - Rooted id(cx, AtomToId(atom)); - return js_DefineFunction(cx, obj, id, call, nargs, attrs); + return js_DefineFunction(cx, obj, RootedId(cx, AtomToId(atom)), call, nargs, attrs); } extern JS_PUBLIC_API(JSFunction *) @@ -5189,10 +5168,11 @@ CompileUCFunctionForPrincipalsCommon(JSContext *cx, JSObject *obj_, return NULL; } - if (obj && funAtom) { - Rooted id(cx, AtomToId(funAtom)); - if (!obj->defineGeneric(cx, id, ObjectValue(*fun), NULL, NULL, JSPROP_ENUMERATE)) - return NULL; + if (obj && funAtom && + !obj->defineGeneric(cx, RootedId(cx, AtomToId(funAtom)), ObjectValue(*fun), NULL, NULL, + JSPROP_ENUMERATE)) + { + return NULL; } return fun; @@ -5491,11 +5471,8 @@ JS_CallFunctionName(JSContext *cx, JSObject *obj_, const char *name, unsigned ar Value v; JSAtom *atom = js_Atomize(cx, name, strlen(name)); - if (!atom) - return false; - - Rooted id(cx, AtomToId(atom)); - return GetMethod(cx, obj, id, 0, &v) && + return atom && + GetMethod(cx, obj, RootedId(cx, AtomToId(atom)), 0, &v) && Invoke(cx, ObjectOrNullValue(obj), v, argc, argv, rval); } @@ -5874,9 +5851,7 @@ JS_ConcatStrings(JSContext *cx, JSString *left, JSString *right) { AssertNoGC(cx); CHECK_REQUEST(cx); - Rooted lstr(cx, left); - Rooted rstr(cx, right); - return js_ConcatStrings(cx, lstr, rstr); + return js_ConcatStrings(cx, RootedString(cx, left), RootedString(cx, right)); } JS_PUBLIC_API(const jschar *) diff --git a/js/src/jsarray.cpp b/js/src/jsarray.cpp index b371aae0c07a5..6e444f31aa86b 100644 --- a/js/src/jsarray.cpp +++ b/js/src/jsarray.cpp @@ -716,8 +716,7 @@ static JSBool array_lookupProperty(JSContext *cx, HandleObject obj, HandlePropertyName name, JSObject **objp, JSProperty **propp) { - Rooted id(cx, NameToId(name)); - return array_lookupGeneric(cx, obj, id, objp, propp); + return array_lookupGeneric(cx, obj, RootedId(cx, NameToId(name)), objp, propp); } static JSBool @@ -745,8 +744,7 @@ static JSBool array_lookupSpecial(JSContext *cx, HandleObject obj, HandleSpecialId sid, JSObject **objp, JSProperty **propp) { - Rooted id(cx, SPECIALID_TO_JSID(sid)); - return array_lookupGeneric(cx, obj, id, objp, propp); + return array_lookupGeneric(cx, obj, RootedId(cx, SPECIALID_TO_JSID(sid)), objp, propp); } JSBool @@ -777,10 +775,8 @@ array_getProperty(JSContext *cx, HandleObject obj, HandleObject receiver, Handle return true; } - if (!obj->isDenseArray()) { - Rooted id(cx, NameToId(name)); - return baseops::GetProperty(cx, obj, receiver, id, vp); - } + if (!obj->isDenseArray()) + return baseops::GetProperty(cx, obj, receiver, RootedId(cx, NameToId(name)), vp); JSObject *proto = obj->getProto(); if (!proto) { @@ -825,8 +821,7 @@ array_getSpecial(JSContext *cx, HandleObject obj, HandleObject receiver, HandleS return true; } - Rooted id(cx, SPECIALID_TO_JSID(sid)); - return baseops::GetProperty(cx, obj, receiver, id, vp); + return baseops::GetProperty(cx, obj, receiver, RootedId(cx, SPECIALID_TO_JSID(sid)), vp); } static JSBool @@ -838,9 +833,9 @@ array_getGeneric(JSContext *cx, HandleObject obj, HandleObject receiver, HandleI if (IsDefinitelyIndex(idval, &index)) return array_getElement(cx, obj, receiver, index, vp); - Rooted sid(cx); - if (ValueIsSpecial(obj, &idval, sid.address(), cx)) - return array_getSpecial(cx, obj, receiver, sid, vp); + SpecialId sid; + if (ValueIsSpecial(obj, &idval, &sid, cx)) + return array_getSpecial(cx, obj, receiver, Rooted(cx, sid), vp); JSAtom *atom = ToAtom(cx, idval); if (!atom) @@ -849,8 +844,7 @@ array_getGeneric(JSContext *cx, HandleObject obj, HandleObject receiver, HandleI if (atom->isIndex(&index)) return array_getElement(cx, obj, receiver, index, vp); - Rooted name(cx, atom->asPropertyName()); - return array_getProperty(cx, obj, receiver, name, vp); + return array_getProperty(cx, obj, receiver, RootedPropertyName(cx, atom->asPropertyName()), vp); } static JSBool @@ -910,8 +904,7 @@ 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) { - Rooted id(cx, NameToId(name)); - return array_setGeneric(cx, obj, id, vp, strict); + return array_setGeneric(cx, obj, RootedId(cx, NameToId(name)), vp, strict); } static JSBool @@ -956,8 +949,7 @@ 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) { - Rooted id(cx, SPECIALID_TO_JSID(sid)); - return array_setGeneric(cx, obj, id, vp, strict); + return array_setGeneric(cx, obj, RootedId(cx, SPECIALID_TO_JSID(sid)), vp, strict); } JSBool @@ -990,7 +982,7 @@ array_defineGeneric(JSContext *cx, HandleObject obj, HandleId id, const Value *v return JS_TRUE; if (!obj->isDenseArray()) - return baseops::DefineGeneric(cx, obj, id, value, getter, setter, attrs); + return baseops::DefineProperty(cx, obj, id, value, getter, setter, attrs); do { uint32_t i = 0; // init to shut GCC up @@ -1016,15 +1008,14 @@ array_defineGeneric(JSContext *cx, HandleObject obj, HandleId id, const Value *v if (!JSObject::makeDenseArraySlow(cx, obj)) return false; - return baseops::DefineGeneric(cx, obj, id, value, getter, setter, attrs); + return baseops::DefineProperty(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) { - Rooted id(cx, NameToId(name)); - return array_defineGeneric(cx, obj, id, value, getter, setter, attrs); + return array_defineGeneric(cx, obj, RootedId(cx, NameToId(name)), value, getter, setter, attrs); } namespace js { @@ -1072,8 +1063,8 @@ static JSBool array_defineSpecial(JSContext *cx, HandleObject obj, HandleSpecialId sid, const Value *value, PropertyOp getter, StrictPropertyOp setter, unsigned attrs) { - Rooted id(cx, SPECIALID_TO_JSID(sid)); - return array_defineGeneric(cx, obj, id, value, getter, setter, attrs); + return array_defineGeneric(cx, obj, RootedId(cx, SPECIALID_TO_JSID(sid)), + value, getter, setter, attrs); } static JSBool @@ -1164,7 +1155,7 @@ array_deleteElement(JSContext *cx, HandleObject obj, uint32_t index, Value *rval obj->setDenseArrayElement(index, MagicValue(JS_ARRAY_HOLE)); } - if (!js_SuppressDeletedElement(cx, obj, index)) + if (!js_SuppressDeletedElement(cx, RootedObject(cx, obj), index)) return false; rval->setBoolean(true); @@ -1713,8 +1704,7 @@ array_toLocaleString(JSContext *cx, unsigned argc, Value *vp) * Passing comma here as the separator. Need a way to get a * locale-specific version. */ - Rooted none(cx, NULL); - return array_toString_sub(cx, obj, JS_TRUE, none, args); + return array_toString_sub(cx, obj, JS_TRUE, RootedString(cx), args); } static inline bool @@ -2395,7 +2385,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::DefineGeneric(cx, obj, id, &v, NULL, NULL, JSPROP_ENUMERATE); + baseops::DefineProperty(cx, obj, id, &v, NULL, NULL, JSPROP_ENUMERATE); } JS_ASSERT(obj->isDenseArray()); diff --git a/js/src/jscntxt.h b/js/src/jscntxt.h index 644c73aa34c12..34a406aa55c69 100644 --- a/js/src/jscntxt.h +++ b/js/src/jscntxt.h @@ -657,7 +657,7 @@ struct JSRuntime : js::RuntimeFriendFields js::Value negativeInfinityValue; js::Value positiveInfinityValue; - js::PropertyName *emptyString; + JSAtom *emptyString; /* List of active contexts sharing this runtime. */ JSCList contextList; diff --git a/js/src/jscompartment.cpp b/js/src/jscompartment.cpp index 3ee927f4edbdb..ba7f4070ae5ff 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()) { - Rooted obj(cx, &vp->toObject()); + JSObject *obj = &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, obj); + JSObject *outer = GetOuterObject(cx, RootedObject(cx, obj)); JS_ASSERT(outer && outer == obj); } #endif diff --git a/js/src/jsdate.cpp b/js/src/jsdate.cpp index 2b28df175c5fa..51b1335d7fb9e 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::DefineGeneric(cx, dateProto, toGMTStringId, &toUTCStringFun, - JS_PropertyStub, JS_StrictPropertyStub, 0)) + !baseops::DefineProperty(cx, dateProto, toGMTStringId, &toUTCStringFun, + JS_PropertyStub, JS_StrictPropertyStub, 0)) { return NULL; } diff --git a/js/src/jsdbgapi.cpp b/js/src/jsdbgapi.cpp index 2c150aba4c15d..db19626d7840d 100644 --- a/js/src/jsdbgapi.cpp +++ b/js/src/jsdbgapi.cpp @@ -783,8 +783,7 @@ GetPropertyDesc(JSContext *cx, JSObject *obj_, Shape *shape, JSPropertyDesc *pd) lastException = cx->getPendingException(); cx->clearPendingException(); - Rooted id(cx, shape->propid()); - if (!baseops::GetProperty(cx, obj, id, &pd->value)) { + if (!baseops::GetProperty(cx, obj, RootedId(cx, shape->propid()), &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 e413a7bbf1914..9cb5c3a0b72d9 100644 --- a/js/src/jsexn.cpp +++ b/js/src/jsexn.cpp @@ -269,8 +269,7 @@ InitExnPrivate(JSContext *cx, HandleObject exnObject, HandleString message, if (checkAccess && i.isNonEvalFunctionFrame()) { Value v = NullValue(); RootedId callerid(cx, NameToId(cx->runtime->atomState.callerAtom)); - Rooted obj(cx, i.callee()); - if (!checkAccess(cx, obj, callerid, JSACC_READ, &v)) + if (!checkAccess(cx, RootedObject(cx, i.callee()), callerid, JSACC_READ, &v)) break; } diff --git a/js/src/jsfriendapi.cpp b/js/src/jsfriendapi.cpp index 52c57ea51b1e8..4c59d85dcf23e 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); - Rooted id(cx, AtomToId(atom)); - fun = js_DefineFunction(cx, obj, id, fs->call, fs->nargs, fs->flags); + fun = js_DefineFunction(cx, obj, RootedId(cx, AtomToId(atom)), + fs->call, fs->nargs, fs->flags); if (!fun) return false; @@ -338,8 +338,9 @@ js::DefineFunctionWithReserved(JSContext *cx, JSObject *obj_, const char *name, JSAtom *atom = js_Atomize(cx, name, strlen(name)); if (!atom) return NULL; - Rooted id(cx, AtomToId(atom)); - return js_DefineFunction(cx, obj, id, call, nargs, attrs, JSFunction::ExtendedFinalizeKind); + return js_DefineFunction(cx, obj, RootedId(cx, AtomToId(atom)), + call, nargs, attrs, + JSFunction::ExtendedFinalizeKind); } JS_FRIEND_API(JSFunction *) diff --git a/js/src/jsfun.cpp b/js/src/jsfun.cpp index ea99641e0125e..339b538598f84 100644 --- a/js/src/jsfun.cpp +++ b/js/src/jsfun.cpp @@ -426,8 +426,7 @@ js::CloneInterpretedFunction(JSContext *cx, JSFunction *srcFun) if (!clone->clearType(cx)) return NULL; - Rooted srcScript(cx, srcFun->script()); - JSScript *clonedScript = CloneScript(cx, srcScript); + JSScript *clonedScript = CloneScript(cx, RootedScript(cx, srcFun->script())); if (!clonedScript) return NULL; diff --git a/js/src/jsfuninlines.h b/js/src/jsfuninlines.h index 1ac2e8102703a..ae875cb545668 100644 --- a/js/src/jsfuninlines.h +++ b/js/src/jsfuninlines.h @@ -206,8 +206,7 @@ CloneFunctionObjectIfNotSingleton(JSContext *cx, HandleFunction fun, HandleObjec * with its type in existence. */ if (fun->hasSingletonType()) { - Rooted obj(cx, SkipScopeParent(parent)); - if (!JSObject::setParent(cx, fun, obj)) + if (!JSObject::setParent(cx, fun, RootedObject(cx, SkipScopeParent(parent)))) return NULL; fun->setEnvironment(parent); return fun; @@ -231,9 +230,10 @@ CloneFunctionObject(JSContext *cx, HandleFunction fun) if (fun->hasSingletonType()) return fun; - Rooted env(cx, fun->environment()); - Rooted proto(cx, fun->getProto()); - return js_CloneFunctionObject(cx, fun, env, proto, JSFunction::ExtendedFinalizeKind); + return js_CloneFunctionObject(cx, fun, + RootedObject(cx, fun->environment()), + RootedObject(cx, fun->getProto()), + JSFunction::ExtendedFinalizeKind); } } /* namespace js */ diff --git a/js/src/jsinfer.cpp b/js/src/jsinfer.cpp index fc441fc4bf457..dc1cd4f0fe8af 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) { - Rooted typeObj(cx, object); - CheckNewScriptProperties(cx, typeObj, object->newScript->fun); + CheckNewScriptProperties(cx, RootedTypeObject(cx, object), + 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 e8c632feced3a..0c9a484b504d0 100644 --- a/js/src/jsinterp.cpp +++ b/js/src/jsinterp.cpp @@ -537,8 +537,7 @@ js::LooselyEqual(JSContext *cx, const Value &lval, const Value &rval, bool *resu if (JSEqualityOp eq = l->getClass()->ext.equality) { JSBool res; - Rooted lobj(cx, l); - if (!eq(cx, lobj, &rval, &res)) + if (!eq(cx, RootedObject(cx, l), &rval, &res)) return false; *result = !!res; return true; @@ -984,8 +983,7 @@ IteratorMore(JSContext *cx, JSObject *iterobj, bool *cond, Value *rval) return true; } } - Rooted iobj(cx, iterobj); - if (!js_IteratorMore(cx, iobj, rval)) + if (!js_IteratorMore(cx, RootedObject(cx, iterobj), rval)) return false; *cond = rval->isTrue(); return true; diff --git a/js/src/jsinterpinlines.h b/js/src/jsinterpinlines.h index dfff7ae9762e4..d0734adb1aafc 100644 --- a/js/src/jsinterpinlines.h +++ b/js/src/jsinterpinlines.h @@ -125,8 +125,7 @@ ValuePropertyBearer(JSContext *cx, StackFrame *fp, const Value &v, int spindex) } inline bool -NativeGet(JSContext *cx, Handle obj, Handle pobj, const Shape *shape, - unsigned getHow, Value *vp) +NativeGet(JSContext *cx, JSObject *obj, JSObject *pobj, const Shape *shape, unsigned getHow, Value *vp) { if (shape->isDataDescriptor() && shape->hasDefaultGetter()) { /* Fast path for Object instance properties. */ @@ -212,9 +211,9 @@ GetPropertyOperation(JSContext *cx, jsbytecode *pc, const Value &lval, Value *vp return false; PropertyCacheEntry *entry; - Rooted obj2(cx); + JSObject *obj2; PropertyName *name; - JS_PROPERTY_CACHE(cx).test(cx, pc, obj.reference(), obj2.reference(), entry, name); + JS_PROPERTY_CACHE(cx).test(cx, pc, obj.reference(), obj2, entry, name); if (!name) { AssertValidPropertyCacheHit(cx, obj, obj2, entry); if (!NativeGet(cx, obj, obj2, entry->prop, JSGET_CACHE_RESULT, vp)) @@ -337,9 +336,9 @@ NameOperation(JSContext *cx, jsbytecode *pc, Value *vp) obj = &obj->global(); PropertyCacheEntry *entry; - Rooted obj2(cx); + JSObject *obj2; RootedPropertyName name(cx); - JS_PROPERTY_CACHE(cx).test(cx, pc, obj.reference(), obj2.reference(), entry, name.reference()); + JS_PROPERTY_CACHE(cx).test(cx, pc, obj.reference(), obj2, entry, name.reference()); if (!name) { AssertValidPropertyCacheHit(cx, obj, obj2, entry); if (!NativeGet(cx, obj, obj2, entry->prop, 0, vp)) @@ -348,7 +347,7 @@ NameOperation(JSContext *cx, jsbytecode *pc, Value *vp) } JSProperty *prop; - if (!FindPropertyHelper(cx, name, true, obj, obj.address(), obj2.address(), &prop)) + if (!FindPropertyHelper(cx, name, true, obj, obj.address(), &obj2, &prop)) return false; if (!prop) { /* Kludge to allow (typeof foo == "undefined") tests. */ @@ -365,12 +364,11 @@ 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()) { - Rooted id(cx, NameToId(name)); - if (!obj->getGeneric(cx, id, vp)) + if (!obj->getGeneric(cx, RootedId(cx, NameToId(name)), vp)) return false; } else { Shape *shape = (Shape *)prop; - Rooted normalized(cx, obj); + JSObject *normalized = 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 386c5f2884ebe..9eb91bd761a9c 100644 --- a/js/src/jsobj.cpp +++ b/js/src/jsobj.cpp @@ -84,21 +84,19 @@ 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; } - Rooted obj(cx, obj_); - return GetInnerObject(cx, obj); + return GetInnerObject(cx, RootedObject(cx, obj)); } JS_FRIEND_API(JSObject *) -JS_ObjectToOuterObject(JSContext *cx, JSObject *obj_) +JS_ObjectToOuterObject(JSContext *cx, JSObject *obj) { - Rooted obj(cx, obj_); - return GetOuterObject(cx, obj); + return GetOuterObject(cx, RootedObject(cx, obj)); } #if JS_HAS_OBJ_PROTO_PROP @@ -203,8 +201,7 @@ MarkSharpObjects(JSContext *cx, HandleObject obj, JSIdArray **idap, JSSharpInfo if (hasSetter) { /* Mark the getter, then set val to setter. */ if (hasGetter && value.isObject()) { - Rooted vobj(cx, &value.toObject()); - ok = MarkSharpObjects(cx, vobj, NULL, NULL); + ok = MarkSharpObjects(cx, RootedObject(cx, &value.toObject()), NULL, NULL); if (!ok) break; } @@ -214,12 +211,11 @@ MarkSharpObjects(JSContext *cx, HandleObject obj, JSIdArray **idap, JSSharpInfo if (!ok) break; } - if (value.isObject()) { - Rooted vobj(cx, &value.toObject()); - if (!MarkSharpObjects(cx, vobj, NULL, NULL)) { - ok = false; - break; - } + if (value.isObject() && + !MarkSharpObjects(cx, RootedObject(cx, &value.toObject()), NULL, NULL)) + { + ok = false; + break; } } if (!ok || !idap) @@ -706,10 +702,8 @@ AssertInnerizedScopeChain(JSContext *cx, JSObject &scopeobj) { #ifdef DEBUG for (JSObject *o = &scopeobj; o; o = o->enclosingScope()) { - if (JSObjectOp op = o->getClass()->ext.innerObject) { - Rooted obj(cx, o); - JS_ASSERT(op(cx, obj) == o); - } + if (JSObjectOp op = o->getClass()->ext.innerObject) + JS_ASSERT(op(cx, RootedObject(cx, o)) == o); } #endif } @@ -1090,11 +1084,9 @@ JSBool eval(JSContext *cx, unsigned argc, Value *vp) { CallArgs args = CallArgsFromVp(argc, vp); - if (!WarnOnTooManyArgs(cx, args)) - return false; - - Rooted global(cx, &args.callee().global()); - return EvalKernel(cx, args, INDIRECT_EVAL, NULL, global); + return WarnOnTooManyArgs(cx, args) && + EvalKernel(cx, args, INDIRECT_EVAL, NULL, + RootedObject(cx, &args.callee().global())); } bool @@ -1294,8 +1286,7 @@ js_HasOwnProperty(JSContext *cx, LookupGenericOp lookup, HandleObject obj, Handl JSObject *outer = NULL; if (JSObjectOp op = (*objp)->getClass()->ext.outerObject) { - Rooted inner(cx, *objp); - outer = op(cx, inner); + outer = op(cx, RootedObject(cx, *objp)); if (!outer) return false; } @@ -1979,9 +1970,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::DefineGeneric(cx, obj, id, &v, - JS_PropertyStub, JS_StrictPropertyStub, - desc.attributes()); + return baseops::DefineProperty(cx, obj, id, &v, + JS_PropertyStub, JS_StrictPropertyStub, + desc.attributes()); } JS_ASSERT(desc.isAccessorDescriptor()); @@ -1996,8 +1987,8 @@ DefinePropertyOnObject(JSContext *cx, HandleObject obj, HandleId id, const PropD return JS_FALSE; Value tmp = UndefinedValue(); - return baseops::DefineGeneric(cx, obj, id, &tmp, - desc.getter(), desc.setter(), desc.attributes()); + return baseops::DefineProperty(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). */ @@ -2247,7 +2238,7 @@ DefinePropertyOnObject(JSContext *cx, HandleObject obj, HandleId id, const PropD return false; } - return baseops::DefineGeneric(cx, obj, id, &v, getter, setter, attrs); + return baseops::DefineProperty(cx, obj, id, &v, getter, setter, attrs); } static JSBool @@ -2391,7 +2382,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, Handle::fromMarkedLocation(&ids[i]), descs[i], true, &dummy)) + if (!DefineProperty(cx, obj, RootedId(cx, ids[i]), descs[i], true, &dummy)) return false; } @@ -3182,9 +3173,9 @@ JSObject::deleteByValue(JSContext *cx, const Value &property, Value *rval, bool return deleteElement(cx, index, rval, strict); Value propval = property; - Rooted sid(cx); - if (ValueIsSpecial(this, &propval, sid.address(), cx)) - return deleteSpecial(cx, sid, rval, strict); + SpecialId sid; + if (ValueIsSpecial(this, &propval, &sid, cx)) + return deleteSpecial(cx, Rooted(cx, sid), rval, strict); RootedObject self(cx, this); @@ -3195,8 +3186,7 @@ JSObject::deleteByValue(JSContext *cx, const Value &property, Value *rval, bool if (name->isIndex(&index)) return self->deleteElement(cx, index, rval, false); - Rooted propname(cx, name->asPropertyName()); - return self->deleteProperty(cx, propname, rval, false); + return self->deleteProperty(cx, RootedPropertyName(cx, name->asPropertyName()), rval, false); } JS_FRIEND_API(bool) @@ -3227,8 +3217,7 @@ 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; - Rooted id(cx, shape->propid()); - if (!target->defineGeneric(cx, id, v, getter, setter, attrs)) + if (!target->defineGeneric(cx, RootedId(cx, shape->propid()), v, getter, setter, attrs)) return false; } return true; @@ -3967,16 +3956,15 @@ 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)) { - Rooted typeObj(cx, type()); - JSObject *obj = NewReshapedObject(cx, typeObj, + JSObject *obj = NewReshapedObject(cx, RootedTypeObject(cx, type()), getParent(), kind, - typeObj->newScript->shape); + type()->newScript->shape); if (!obj) return false; - typeObj->newScript->allocKind = kind; - typeObj->newScript->shape = obj->lastProperty(); - typeObj->markStateChange(cx); + type()->newScript->allocKind = kind; + type()->newScript->shape = obj->lastProperty(); + type()->markStateChange(cx); } } @@ -4488,7 +4476,7 @@ js_AddNativeProperty(JSContext *cx, HandleObject obj, jsid id_, } JSBool -baseops::DefineGeneric(JSContext *cx, HandleObject obj, HandleId id, const Value *value, +baseops::DefineProperty(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); @@ -4498,14 +4486,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) { - id = INT_TO_JSID(index); - return !!DefineNativeProperty(cx, obj, id, *value, getter, setter, attrs, 0, 0); + return !!DefineNativeProperty(cx, obj, RootedId(cx, INT_TO_JSID(index)), *value, + getter, setter, attrs, 0, 0); } AutoRooterGetterSetter gsRoot(cx, attrs, &getter, &setter); + RootedId id(cx); if (!IndexToId(cx, index, id.address())) return false; @@ -4524,8 +4512,7 @@ CallAddPropertyHook(JSContext *cx, Class *clasp, HandleObject obj, HandleShape s if (clasp->addProperty != JS_PropertyStub) { Value nominal = *vp; - Rooted id(cx, shape->propid()); - if (!CallJSPropertyOp(cx, clasp->addProperty, obj, id, vp)) + if (!CallJSPropertyOp(cx, clasp->addProperty, obj, RootedId(cx, shape->propid()), vp)) return false; if (*vp != nominal) { if (shape->hasSlot()) @@ -4978,7 +4965,7 @@ js::FindIdentifierBase(JSContext *cx, HandleObject scopeChain, HandlePropertyNam } static JS_ALWAYS_INLINE JSBool -js_NativeGetInline(JSContext *cx, Handle receiver, JSObject *obj, JSObject *pobj, +js_NativeGetInline(JSContext *cx, JSObject *receiver, JSObject *obj, JSObject *pobj, const Shape *shape, unsigned getHow, Value *vp) { JS_ASSERT(pobj->isNative()); @@ -5005,7 +4992,7 @@ js_NativeGetInline(JSContext *cx, Handle receiver, JSObject *obj, JSO Rooted shapeRoot(cx, shape); RootedObject pobjRoot(cx, pobj); - if (!shape->get(cx, receiver, obj, pobj, vp)) + if (!shape->get(cx, RootedObject(cx, receiver), obj, pobj, vp)) return false; /* Update slotful shapes according to the value produced by the getter. */ @@ -5016,15 +5003,14 @@ js_NativeGetInline(JSContext *cx, Handle receiver, JSObject *obj, JSO } JSBool -js_NativeGet(JSContext *cx, Handle obj, Handle pobj, const Shape *shape, - unsigned getHow, Value *vp) +js_NativeGet(JSContext *cx, JSObject *obj, JSObject *pobj, const Shape *shape, unsigned getHow, + Value *vp) { return js_NativeGetInline(cx, obj, obj, pobj, shape, getHow, vp); } JSBool -js_NativeSet(JSContext *cx, Handle obj, const Shape *shape, bool added, bool strict, - Value *vp) +js_NativeSet(JSContext *cx, JSObject *obj, const Shape *shape, bool added, bool strict, Value *vp) { AddTypePropertyId(cx, obj, shape->propid(), *vp); @@ -5052,7 +5038,7 @@ js_NativeSet(JSContext *cx, Handle obj, const Shape *shape, bool adde Rooted shapeRoot(cx, shape); int32_t sample = cx->runtime->propertyRemovals; - if (!shapeRoot->set(cx, obj, strict, vp)) + if (!shapeRoot->set(cx, RootedObject(cx, obj), strict, vp)) return false; /* @@ -5270,9 +5256,8 @@ bool JSObject::callMethod(JSContext *cx, HandleId id, unsigned argc, Value *argv, Value *vp) { Value fval; - Rooted obj(cx, this); - return GetMethod(cx, obj, id, 0, &fval) && - Invoke(cx, ObjectValue(*obj), fval, argc, argv, vp); + return GetMethod(cx, RootedObject(cx, this), id, 0, &fval) && + Invoke(cx, ObjectValue(*this), fval, argc, argv, vp); } JSBool @@ -5583,8 +5568,7 @@ baseops::DeleteGeneric(JSContext *cx, HandleObject obj, HandleId id, Value *rval JSBool baseops::DeleteProperty(JSContext *cx, HandleObject obj, HandlePropertyName name, Value *rval, JSBool strict) { - Rooted id(cx, NameToId(name)); - return baseops::DeleteGeneric(cx, obj, id, rval, strict); + return baseops::DeleteGeneric(cx, obj, RootedId(cx, NameToId(name)), rval, strict); } JSBool @@ -5599,8 +5583,7 @@ baseops::DeleteElement(JSContext *cx, HandleObject obj, uint32_t index, Value *r JSBool baseops::DeleteSpecial(JSContext *cx, HandleObject obj, HandleSpecialId sid, Value *rval, JSBool strict) { - Rooted id(cx, SPECIALID_TO_JSID(sid)); - return baseops::DeleteGeneric(cx, obj, id, rval, strict); + return baseops::DeleteGeneric(cx, obj, RootedId(cx, SPECIALID_TO_JSID(sid)), rval, strict); } namespace js { @@ -5627,9 +5610,9 @@ HasDataProperty(JSContext *cx, HandleObject obj, jsid id, Value *vp) * or steps 3-4. */ static bool -MaybeCallMethod(JSContext *cx, HandleObject obj, Handle id, Value *vp) +MaybeCallMethod(JSContext *cx, HandleObject obj, jsid id, Value *vp) { - if (!GetMethod(cx, obj, id, 0, vp)) + if (!GetMethod(cx, obj, RootedId(cx, id), 0, vp)) return false; if (!js_IsCallable(*vp)) { *vp = ObjectValue(*obj); @@ -5646,58 +5629,49 @@ 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) { - if (ClassMethodIsNative(cx, obj, &StringClass, id, js_str_toString)) { - *vp = StringValue(obj->asString().unbox()); - return true; - } + 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 (!MaybeCallMethod(cx, obj, id, vp)) + if (!MaybeCallMethod(cx, obj, NameToId(cx->runtime->atomState.toStringAtom), vp)) return false; if (vp->isPrimitive()) return true; - id = NameToId(cx->runtime->atomState.valueOfAtom); - if (!MaybeCallMethod(cx, obj, id, vp)) + if (!MaybeCallMethod(cx, obj, NameToId(cx->runtime->atomState.valueOfAtom), vp)) return false; if (vp->isPrimitive()) return true; } else { - - /* 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; - } - } - - /* 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; - } + /* 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; } - id = NameToId(cx->runtime->atomState.valueOfAtom); - if (!MaybeCallMethod(cx, obj, id, vp)) + if (!MaybeCallMethod(cx, obj, NameToId(cx->runtime->atomState.valueOfAtom), vp)) return false; if (vp->isPrimitive()) return true; - id = NameToId(cx->runtime->atomState.toStringAtom); - if (!MaybeCallMethod(cx, obj, id, vp)) + if (!MaybeCallMethod(cx, obj, NameToId(cx->runtime->atomState.toStringAtom), vp)) return false; if (vp->isPrimitive()) return true; @@ -5894,10 +5868,8 @@ js_GetClassPrototype(JSContext *cx, JSObject *scopeobj, JSProtoKey protoKey, JSObject * PrimitiveToObject(JSContext *cx, const Value &v) { - if (v.isString()) { - Rooted str(cx, v.toString()); - return StringObject::create(cx, str); - } + if (v.isString()) + return StringObject::create(cx, RootedString(cx, v.toString())); if (v.isNumber()) return NumberObject::create(cx, v.toNumber()); diff --git a/js/src/jsobj.h b/js/src/jsobj.h index 529cdb1ece403..734ce03732137 100644 --- a/js/src/jsobj.h +++ b/js/src/jsobj.h @@ -105,8 +105,7 @@ inline bool LookupProperty(JSContext *cx, HandleObject obj, PropertyName *name, JSObject **objp, JSProperty **propp) { - Rooted id(cx, NameToId(name)); - return LookupProperty(cx, obj, id, objp, propp); + return LookupProperty(cx, obj, RootedId(cx, NameToId(name)), objp, propp); } extern JS_FRIEND_API(JSBool) @@ -114,17 +113,9 @@ LookupElement(JSContext *cx, HandleObject obj, uint32_t index, JSObject **objp, JSProperty **propp); extern JSBool -DefineGeneric(JSContext *cx, HandleObject obj, HandleId id, const js::Value *value, +DefineProperty(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); @@ -158,8 +149,7 @@ inline bool SetPropertyHelper(JSContext *cx, HandleObject obj, PropertyName *name, unsigned defineHow, Value *vp, JSBool strict) { - Rooted id(cx, NameToId(name)); - return SetPropertyHelper(cx, obj, id, defineHow, vp, strict); + return SetPropertyHelper(cx, obj, RootedId(cx, NameToId(name)), defineHow, vp, strict); } extern JSBool @@ -1151,8 +1141,8 @@ DefineNativeProperty(JSContext *cx, HandleObject obj, PropertyName *name, const PropertyOp getter, StrictPropertyOp setter, unsigned attrs, unsigned flags, int shortid, unsigned defineHow = 0) { - Rooted id(cx, NameToId(name)); - return DefineNativeProperty(cx, obj, id, value, getter, setter, attrs, flags, + return DefineNativeProperty(cx, obj, RootedId(cx, NameToId(name)), + value, getter, setter, attrs, flags, shortid, defineHow); } @@ -1167,8 +1157,7 @@ inline bool LookupPropertyWithFlags(JSContext *cx, HandleObject obj, PropertyName *name, unsigned flags, JSObject **objp, JSProperty **propp) { - Rooted id(cx, NameToId(name)); - return LookupPropertyWithFlags(cx, obj, id, flags, objp, propp); + return LookupPropertyWithFlags(cx, obj, RootedId(cx, NameToId(name)), flags, objp, propp); } /* @@ -1232,11 +1221,11 @@ const unsigned JSGET_CACHE_RESULT = 1; // from a caching interpreter opcode * scope containing shape unlocked. */ extern JSBool -js_NativeGet(JSContext *cx, js::Handle obj, js::Handle pobj, - const js::Shape *shape, unsigned getHow, js::Value *vp); +js_NativeGet(JSContext *cx, JSObject *obj, JSObject *pobj, const js::Shape *shape, unsigned getHow, + js::Value *vp); extern JSBool -js_NativeSet(JSContext *cx, js::Handle obj, const js::Shape *shape, bool added, +js_NativeSet(JSContext *cx, JSObject *obj, const js::Shape *shape, bool added, bool strict, js::Value *vp); namespace js { @@ -1265,8 +1254,7 @@ GetMethod(JSContext *cx, HandleObject obj, HandleId id, unsigned getHow, Value * inline bool GetMethod(JSContext *cx, HandleObject obj, PropertyName *name, unsigned getHow, Value *vp) { - Rooted id(cx, NameToId(name)); - return GetMethod(cx, obj, id, getHow, vp); + return GetMethod(cx, obj, RootedId(cx, NameToId(name)), getHow, vp); } /* diff --git a/js/src/jsobjinlines.h b/js/src/jsobjinlines.h index 566b4f164e459..80cdf6b3faf88 100644 --- a/js/src/jsobjinlines.h +++ b/js/src/jsobjinlines.h @@ -54,8 +54,7 @@ inline bool JSObject::enumerate(JSContext *cx, JSIterateOp iterop, js::Value *statep, jsid *idp) { JSNewEnumerateOp op = getOps()->enumerate; - js::Rooted obj(cx, this); - return (op ? op : JS_EnumerateState)(cx, obj, iterop, statep, idp); + return (op ? op : JS_EnumerateState)(cx, js::RootedObject(cx, this), iterop, statep, idp); } inline bool @@ -77,16 +76,14 @@ inline JSType JSObject::typeOf(JSContext *cx) { js::TypeOfOp op = getOps()->typeOf; - js::Rooted obj(cx, this); - return (op ? op : js::baseops::TypeOf)(cx, obj); + return (op ? op : js::baseops::TypeOf)(cx, js::RootedObject(cx, this)); } inline JSObject * JSObject::thisObject(JSContext *cx) { JSObjectOp op = getOps()->thisObject; - js::Rooted obj(cx, this); - return op ? op(cx, obj) : this; + return op ? op(cx, js::RootedObject(cx, this)) : this; } inline JSBool @@ -94,15 +91,15 @@ JSObject::setGeneric(JSContext *cx, js::HandleId id, js::Value *vp, JSBool stric { if (getOps()->setGeneric) return nonNativeSetProperty(cx, id, vp, strict); - js::Rooted obj(cx, this); - return js::baseops::SetPropertyHelper(cx, obj, id, 0, vp, strict); + return js::baseops::SetPropertyHelper(cx, + js::RootedObject(cx, this), + id, 0, vp, strict); } inline JSBool JSObject::setProperty(JSContext *cx, js::PropertyName *name, js::Value *vp, JSBool strict) { - js::Rooted id(cx, js::NameToId(name)); - return setGeneric(cx, id, vp, strict); + return setGeneric(cx, js::RootedId(cx, js::NameToId(name)), vp, strict); } inline JSBool @@ -110,15 +107,13 @@ JSObject::setElement(JSContext *cx, uint32_t index, js::Value *vp, JSBool strict { if (getOps()->setElement) return nonNativeSetElement(cx, index, vp, strict); - js::Rooted obj(cx, this); - return js::baseops::SetElementHelper(cx, obj, index, 0, vp, strict); + return js::baseops::SetElementHelper(cx, js::RootedObject(cx, this), index, 0, vp, strict); } inline JSBool JSObject::setSpecial(JSContext *cx, js::SpecialId sid, js::Value *vp, JSBool strict) { - js::Rooted id(cx, SPECIALID_TO_JSID(sid)); - return setGeneric(cx, id, vp, strict); + return setGeneric(cx, js::RootedId(cx, SPECIALID_TO_JSID(sid)), vp, strict); } inline JSBool @@ -126,30 +121,26 @@ JSObject::setGenericAttributes(JSContext *cx, js::HandleId id, unsigned *attrsp) { js::types::MarkTypePropertyConfigured(cx, this, id); js::GenericAttributesOp op = getOps()->setGenericAttributes; - js::Rooted obj(cx, this); - return (op ? op : js::baseops::SetAttributes)(cx, obj, id, attrsp); + return (op ? op : js::baseops::SetAttributes)(cx, js::RootedObject(cx, this), id, attrsp); } inline JSBool JSObject::setPropertyAttributes(JSContext *cx, js::PropertyName *name, unsigned *attrsp) { - js::Rooted id(cx, js::NameToId(name)); - return setGenericAttributes(cx, id, attrsp); + return setGenericAttributes(cx, js::RootedId(cx, js::NameToId(name)), attrsp); } inline JSBool JSObject::setElementAttributes(JSContext *cx, uint32_t index, unsigned *attrsp) { js::ElementAttributesOp op = getOps()->setElementAttributes; - js::Rooted obj(cx, this); - return (op ? op : js::baseops::SetElementAttributes)(cx, obj, index, attrsp); + return (op ? op : js::baseops::SetElementAttributes)(cx, js::RootedObject(cx, this), index, attrsp); } inline JSBool JSObject::setSpecialAttributes(JSContext *cx, js::SpecialId sid, unsigned *attrsp) { - js::Rooted id(cx, SPECIALID_TO_JSID(sid)); - return setGenericAttributes(cx, id, attrsp); + return setGenericAttributes(cx, js::RootedId(cx, SPECIALID_TO_JSID(sid)), attrsp); } inline bool @@ -177,22 +168,19 @@ 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) { - js::Rooted id(cx, js::NameToId(name)); - return getGeneric(cx, receiver, id, vp); + return getGeneric(cx, receiver, js::RootedId(cx, js::NameToId(name)), vp); } inline JSBool JSObject::getGeneric(JSContext *cx, js::HandleId id, js::Value *vp) { - js::Rooted obj(cx, this); - return getGeneric(cx, obj, id, vp); + return getGeneric(cx, js::RootedObject(cx, this), id, vp); } inline JSBool JSObject::getProperty(JSContext *cx, js::PropertyName *name, js::Value *vp) { - js::Rooted id(cx, js::NameToId(name)); - return getGeneric(cx, id, vp); + return getGeneric(cx, js::RootedId(cx, js::NameToId(name)), vp); } inline bool @@ -202,8 +190,7 @@ 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; - js::Rooted obj(cx, this); - return (op ? op : js::baseops::DeleteProperty)(cx, obj, name, rval, strict); + return (op ? op : js::baseops::DeleteProperty)(cx, js::RootedObject(cx, this), name, rval, strict); } inline bool @@ -227,8 +214,7 @@ 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; - js::Rooted obj(cx, this); - return (op ? op : js::baseops::DeleteSpecial)(cx, obj, sid, rval, strict); + return (op ? op : js::baseops::DeleteSpecial)(cx, js::RootedObject(cx, this), sid, rval, strict); } inline void @@ -1040,8 +1026,7 @@ JSObject::lookupGeneric(JSContext *cx, js::HandleId id, JSObject **objp, JSPrope inline JSBool JSObject::lookupProperty(JSContext *cx, js::PropertyName *name, JSObject **objp, JSProperty **propp) { - js::Rooted id(cx, js::NameToId(name)); - return lookupGeneric(cx, id, objp, propp); + return lookupGeneric(cx, js::RootedId(cx, js::NameToId(name)), objp, propp); } inline JSBool @@ -1054,7 +1039,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::DefineGeneric)(cx, self, id, &value, getter, setter, attrs); + return (op ? op : js::baseops::DefineProperty)(cx, self, id, &value, getter, setter, attrs); } inline JSBool @@ -1063,8 +1048,7 @@ JSObject::defineProperty(JSContext *cx, js::PropertyName *name, const js::Value JSStrictPropertyOp setter /* = JS_StrictPropertyStub */, unsigned attrs /* = JSPROP_ENUMERATE */) { - js::Rooted id(cx, js::NameToId(name)); - return defineGeneric(cx, id, value, getter, setter, attrs); + return defineGeneric(cx, js::RootedId(cx, js::NameToId(name)), value, getter, setter, attrs); } inline JSBool @@ -1085,8 +1069,7 @@ JSObject::defineSpecial(JSContext *cx, js::SpecialId sid, const js::Value &value JSStrictPropertyOp setter /* = JS_StrictPropertyStub */, unsigned attrs /* = JSPROP_ENUMERATE */) { - js::Rooted id(cx, SPECIALID_TO_JSID(sid)); - return defineGeneric(cx, id, value, getter, setter, attrs); + return defineGeneric(cx, js::RootedId(cx, SPECIALID_TO_JSID(sid)), value, getter, setter, attrs); } inline JSBool @@ -1101,8 +1084,7 @@ JSObject::lookupElement(JSContext *cx, uint32_t index, JSObject **objp, JSProper inline JSBool JSObject::lookupSpecial(JSContext *cx, js::SpecialId sid, JSObject **objp, JSProperty **propp) { - js::Rooted id(cx, SPECIALID_TO_JSID(sid)); - return lookupGeneric(cx, id, objp, propp); + return lookupGeneric(cx, js::RootedId(cx, SPECIALID_TO_JSID(sid)), objp, propp); } inline JSBool @@ -1123,8 +1105,7 @@ JSObject::getElement(JSContext *cx, js::HandleObject receiver, uint32_t index, j inline JSBool JSObject::getElement(JSContext *cx, uint32_t index, js::Value *vp) { - js::Rooted obj(cx, this); - return getElement(cx, obj, index, vp); + return getElement(cx, js::RootedObject(cx, this), index, vp); } inline JSBool @@ -1164,23 +1145,20 @@ JSObject::getElementIfPresent(JSContext *cx, js::HandleObject receiver, uint32_t inline JSBool JSObject::getSpecial(JSContext *cx, js::HandleObject receiver, js::SpecialId sid, js::Value *vp) { - js::Rooted id(cx, SPECIALID_TO_JSID(sid)); - return getGeneric(cx, receiver, id, vp); + return getGeneric(cx, receiver, js::RootedId(cx, SPECIALID_TO_JSID(sid)), vp); } inline JSBool JSObject::getGenericAttributes(JSContext *cx, js::HandleId id, unsigned *attrsp) { js::GenericAttributesOp op = getOps()->getGenericAttributes; - js::Rooted obj(cx, this); - return (op ? op : js::baseops::GetAttributes)(cx, obj, id, attrsp); + return (op ? op : js::baseops::GetAttributes)(cx, js::RootedObject(cx, this), id, attrsp); } inline JSBool JSObject::getPropertyAttributes(JSContext *cx, js::PropertyName *name, unsigned *attrsp) { - js::Rooted id(cx, js::NameToId(name)); - return getGenericAttributes(cx, id, attrsp); + return getGenericAttributes(cx, js::RootedId(cx, js::NameToId(name)), attrsp); } inline JSBool @@ -1195,8 +1173,7 @@ JSObject::getElementAttributes(JSContext *cx, uint32_t index, unsigned *attrsp) inline JSBool JSObject::getSpecialAttributes(JSContext *cx, js::SpecialId sid, unsigned *attrsp) { - js::Rooted id(cx, SPECIALID_TO_JSID(sid)); - return getGenericAttributes(cx, id, attrsp); + return getGenericAttributes(cx, js::RootedId(cx, SPECIALID_TO_JSID(sid)), attrsp); } inline bool diff --git a/js/src/json.cpp b/js/src/json.cpp index eefc51921a286..6cc21bae2245f 100644 --- a/js/src/json.cpp +++ b/js/src/json.cpp @@ -280,8 +280,7 @@ PreprocessValue(JSContext *cx, JSObject *holder, KeyType key, Value *vp, Stringi if (vp->isObject()) { Value toJSON; RootedId id(cx, NameToId(cx->runtime->atomState.toJSONAtom)); - Rooted obj(cx, &vp->toObject()); - if (!GetMethod(cx, obj, id, 0, &toJSON)) + if (!GetMethod(cx, RootedObject(cx, &vp->toObject()), id, 0, &toJSON)) return false; if (js_IsCallable(toJSON)) { @@ -856,8 +855,7 @@ Revive(JSContext *cx, const Value &reviver, Value *vp) if (!obj->defineProperty(cx, cx->runtime->atomState.emptyAtom, *vp)) return false; - Rooted id(cx, NameToId(cx->runtime->atomState.emptyAtom)); - return Walk(cx, obj, id, reviver, vp); + return Walk(cx, obj, RootedId(cx, NameToId(cx->runtime->atomState.emptyAtom)), reviver, vp); } namespace js { diff --git a/js/src/jsonparser.cpp b/js/src/jsonparser.cpp index 63f0ab959c146..317ca2c4e16ab 100644 --- a/js/src/jsonparser.cpp +++ b/js/src/jsonparser.cpp @@ -549,8 +549,7 @@ JSONParser::parse(Value *vp) case FinishArrayElement: { Value v = valueStack.popCopy(); - Rooted obj(cx, &valueStack.back().toObject()); - if (!js_NewbornArrayPush(cx, obj, v)) + if (!js_NewbornArrayPush(cx, RootedObject(cx, &valueStack.back().toObject()), v)) return false; token = advanceAfterArrayElement(); if (token == Comma) { diff --git a/js/src/jsproxy.cpp b/js/src/jsproxy.cpp index 183d68e908cf5..6f13d7d9388c5 100644 --- a/js/src/jsproxy.cpp +++ b/js/src/jsproxy.cpp @@ -310,8 +310,7 @@ bool BaseProxyHandler::defaultValue(JSContext *cx, JSObject *proxy, JSType hint, Value *vp) { - Rooted obj(cx, proxy); - return DefaultValue(cx, obj, hint, vp); + return DefaultValue(cx, RootedObject(cx, proxy), hint, vp); } bool @@ -398,14 +397,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)); - 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); + 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); } bool @@ -524,25 +523,25 @@ IndirectProxyHandler::defaultValue(JSContext *cx, JSObject *proxy, JSType hint, bool IndirectProxyHandler::iteratorNext(JSContext *cx, JSObject *proxy, Value *vp) { - Rooted target(cx, GetProxyTargetObject(proxy)); - if (!js_IteratorMore(cx, target, vp)) + if (!js_IteratorMore(cx, RootedObject(cx, GetProxyTargetObject(proxy)), + vp)) return false; if (vp->toBoolean()) { *vp = cx->iterValue; - cx->iterValue = UndefinedValue(); - } else { - *vp = MagicValue(JS_NO_ITER_VALUE); - } + cx->iterValue.setUndefined(); + } else + vp->setMagic(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)) @@ -591,8 +590,8 @@ bool DirectProxyHandler::iterate(JSContext *cx, JSObject *proxy, unsigned flags, Value *vp) { - Rooted target(cx, GetProxyTargetObject(proxy)); - return GetIterator(cx, target, flags, vp); + return GetIterator(cx, RootedObject(cx, GetProxyTargetObject(proxy)), + flags, vp); } static bool @@ -600,8 +599,7 @@ GetTrap(JSContext *cx, JSObject *handler, PropertyName *name, Value *fvalp) { JS_CHECK_RECURSION(cx, return false); - Rooted propname(cx, name); - return handler->getProperty(cx, propname, fvalp); + return handler->getGeneric(cx, RootedId(cx, NameToId(name)), fvalp); } static bool @@ -1245,8 +1243,7 @@ static JSBool proxy_LookupProperty(JSContext *cx, HandleObject obj, HandlePropertyName name, JSObject **objp, JSProperty **propp) { - Rooted id(cx, NameToId(name)); - return proxy_LookupGeneric(cx, obj, id, objp, propp); + return proxy_LookupGeneric(cx, obj, RootedId(cx, NameToId(name)), objp, propp); } static JSBool @@ -1262,8 +1259,7 @@ proxy_LookupElement(JSContext *cx, HandleObject obj, uint32_t index, JSObject ** static JSBool proxy_LookupSpecial(JSContext *cx, HandleObject obj, HandleSpecialId sid, JSObject **objp, JSProperty **propp) { - Rooted id(cx, SPECIALID_TO_JSID(sid)); - return proxy_LookupGeneric(cx, obj, id, objp, propp); + return proxy_LookupGeneric(cx, obj, RootedId(cx, SPECIALID_TO_JSID(sid)), objp, propp); } static JSBool @@ -1284,8 +1280,7 @@ static JSBool proxy_DefineProperty(JSContext *cx, HandleObject obj, HandlePropertyName name, const Value *value, PropertyOp getter, StrictPropertyOp setter, unsigned attrs) { - Rooted id(cx, NameToId(name)); - return proxy_DefineGeneric(cx, obj, id, value, getter, setter, attrs); + return proxy_DefineGeneric(cx, obj, RootedId(cx, NameToId(name)), value, getter, setter, attrs); } static JSBool @@ -1302,8 +1297,8 @@ static JSBool proxy_DefineSpecial(JSContext *cx, HandleObject obj, HandleSpecialId sid, const Value *value, PropertyOp getter, StrictPropertyOp setter, unsigned attrs) { - Rooted id(cx, SPECIALID_TO_JSID(sid)); - return proxy_DefineGeneric(cx, obj, id, value, getter, setter, attrs); + return proxy_DefineGeneric(cx, obj, RootedId(cx, SPECIALID_TO_JSID(sid)), + value, getter, setter, attrs); } static JSBool @@ -1315,8 +1310,7 @@ proxy_GetGeneric(JSContext *cx, HandleObject obj, HandleObject receiver, HandleI static JSBool proxy_GetProperty(JSContext *cx, HandleObject obj, HandleObject receiver, HandlePropertyName name, Value *vp) { - Rooted id(cx, NameToId(name)); - return proxy_GetGeneric(cx, obj, receiver, id, vp); + return proxy_GetGeneric(cx, obj, receiver, RootedId(cx, NameToId(name)), vp); } static JSBool @@ -1338,8 +1332,7 @@ proxy_GetElementIfPresent(JSContext *cx, HandleObject obj, HandleObject receiver static JSBool proxy_GetSpecial(JSContext *cx, HandleObject obj, HandleObject receiver, HandleSpecialId sid, Value *vp) { - Rooted id(cx, SPECIALID_TO_JSID(sid)); - return proxy_GetGeneric(cx, obj, receiver, id, vp); + return proxy_GetGeneric(cx, obj, receiver, RootedId(cx, SPECIALID_TO_JSID(sid)), vp); } static JSBool @@ -1351,8 +1344,7 @@ 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) { - Rooted id(cx, NameToId(name)); - return proxy_SetGeneric(cx, obj, id, vp, strict); + return proxy_SetGeneric(cx, obj, RootedId(cx, NameToId(name)), vp, strict); } static JSBool @@ -1367,8 +1359,7 @@ 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) { - Rooted id(cx, SPECIALID_TO_JSID(sid)); - return proxy_SetGeneric(cx, obj, id, vp, strict); + return proxy_SetGeneric(cx, obj, RootedId(cx, SPECIALID_TO_JSID(sid)), vp, strict); } static JSBool @@ -1384,8 +1375,7 @@ proxy_GetGenericAttributes(JSContext *cx, HandleObject obj, HandleId id, unsigne static JSBool proxy_GetPropertyAttributes(JSContext *cx, HandleObject obj, HandlePropertyName name, unsigned *attrsp) { - Rooted id(cx, NameToId(name)); - return proxy_GetGenericAttributes(cx, obj, id, attrsp); + return proxy_GetGenericAttributes(cx, obj, RootedId(cx, NameToId(name)), attrsp); } static JSBool @@ -1400,8 +1390,7 @@ proxy_GetElementAttributes(JSContext *cx, HandleObject obj, uint32_t index, unsi static JSBool proxy_GetSpecialAttributes(JSContext *cx, HandleObject obj, HandleSpecialId sid, unsigned *attrsp) { - Rooted id(cx, SPECIALID_TO_JSID(sid)); - return proxy_GetGenericAttributes(cx, obj, id, attrsp); + return proxy_GetGenericAttributes(cx, obj, RootedId(cx, SPECIALID_TO_JSID(sid)), attrsp); } static JSBool @@ -1418,8 +1407,7 @@ proxy_SetGenericAttributes(JSContext *cx, HandleObject obj, HandleId id, unsigne static JSBool proxy_SetPropertyAttributes(JSContext *cx, HandleObject obj, HandlePropertyName name, unsigned *attrsp) { - Rooted id(cx, NameToId(name)); - return proxy_SetGenericAttributes(cx, obj, id, attrsp); + return proxy_SetGenericAttributes(cx, obj, RootedId(cx, NameToId(name)), attrsp); } static JSBool @@ -1434,8 +1422,7 @@ proxy_SetElementAttributes(JSContext *cx, HandleObject obj, uint32_t index, unsi static JSBool proxy_SetSpecialAttributes(JSContext *cx, HandleObject obj, HandleSpecialId sid, unsigned *attrsp) { - Rooted id(cx, SPECIALID_TO_JSID(sid)); - return proxy_SetGenericAttributes(cx, obj, id, attrsp); + return proxy_SetGenericAttributes(cx, obj, RootedId(cx, SPECIALID_TO_JSID(sid)), attrsp); } static JSBool @@ -1452,8 +1439,7 @@ 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) { - Rooted id(cx, NameToId(name)); - return proxy_DeleteGeneric(cx, obj, id, rval, strict); + return proxy_DeleteGeneric(cx, obj, RootedId(cx, NameToId(name)), rval, strict); } static JSBool @@ -1468,8 +1454,7 @@ 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) { - Rooted id(cx, SPECIALID_TO_JSID(sid)); - return proxy_DeleteGeneric(cx, obj, id, rval, strict); + return proxy_DeleteGeneric(cx, obj, RootedId(cx, SPECIALID_TO_JSID(sid)), rval, strict); } static void diff --git a/js/src/jsscope.cpp b/js/src/jsscope.cpp index cb45328f25b86..10f32cda359e0 100644 --- a/js/src/jsscope.cpp +++ b/js/src/jsscope.cpp @@ -1013,9 +1013,7 @@ JSObject::shadowingShapeChange(JSContext *cx, const Shape &shape) bool JSObject::clearParent(JSContext *cx) { - Rooted obj(cx, this); - Rooted newParent(cx, NULL); - return setParent(cx, obj, newParent); + return setParent(cx, RootedObject(cx, this), RootedObject(cx)); } /* static */ bool diff --git a/js/src/jsscript.cpp b/js/src/jsscript.cpp index 53ed9e96c7f62..97d189c0ed048 100644 --- a/js/src/jsscript.cpp +++ b/js/src/jsscript.cpp @@ -1745,8 +1745,7 @@ js::CloneScript(JSContext *cx, HandleScript src) for (unsigned i = 0; i < names.length(); ++i) { if (JSAtom *atom = names[i].maybeAtom) { - Rooted root(cx, atom); - if (!bindings.add(cx, root, names[i].kind)) + if (!bindings.add(cx, RootedAtom(cx, atom), names[i].kind)) return NULL; } else { uint16_t _; diff --git a/js/src/jsscript.h b/js/src/jsscript.h index bcc452bc9da7f..ae9899e1d6d5a 100644 --- a/js/src/jsscript.h +++ b/js/src/jsscript.h @@ -175,8 +175,7 @@ class Bindings } bool addDestructuring(JSContext *cx, uint16_t *slotp) { *slotp = nargs; - Rooted atom(cx, NULL); - return add(cx, atom, ARGUMENT); + return add(cx, RootedAtom(cx), ARGUMENT); } void noteDup() { hasDup_ = true; } diff --git a/js/src/jsstr.cpp b/js/src/jsstr.cpp index 9baa7f60edf68..fcc8007c9a116 100644 --- a/js/src/jsstr.cpp +++ b/js/src/jsstr.cpp @@ -428,13 +428,15 @@ ThisToStringForStringProto(JSContext *cx, CallReceiver call) if (call.thisv().isObject()) { RootedObject obj(cx, &call.thisv().toObject()); - 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; - } + 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; } } else if (call.thisv().isNullOrUndefined()) { JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_CANT_CONVERT_TO, @@ -1982,7 +1984,7 @@ BuildFlatReplacement(JSContext *cx, HandleString textstr, HandleString repstr, return false; } } else { - if (!builder.append(str)) + if (!builder.append(RootedString(cx, str))) return false; } pos += str->length(); @@ -3063,9 +3065,8 @@ 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, empty)) + if (!proto || !proto->asString().init(cx, RootedString(cx, cx->runtime->emptyString))) return NULL; /* Now create the String function. */ @@ -3285,8 +3286,7 @@ js_ValueToSource(JSContext *cx, const Value &v) Value rval = NullValue(); Value fval; RootedId id(cx, NameToId(cx->runtime->atomState.toSourceAtom)); - Rooted obj(cx, &v.toObject()); - if (!GetMethod(cx, obj, id, 0, &fval)) + if (!GetMethod(cx, RootedObject(cx, &v.toObject()), 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 f7c195f75124c..6c44eb6cecee3 100644 --- a/js/src/jstypedarray.cpp +++ b/js/src/jstypedarray.cpp @@ -349,8 +349,7 @@ JSBool ArrayBufferObject::obj_lookupProperty(JSContext *cx, HandleObject obj, HandlePropertyName name, JSObject **objp, JSProperty **propp) { - Rooted id(cx, NameToId(name)); - return obj_lookupGeneric(cx, obj, id, objp, propp); + return obj_lookupGeneric(cx, obj, RootedId(cx, NameToId(name)), objp, propp); } JSBool @@ -388,8 +387,7 @@ JSBool ArrayBufferObject::obj_lookupSpecial(JSContext *cx, HandleObject obj, HandleSpecialId sid, JSObject **objp, JSProperty **propp) { - Rooted id(cx, SPECIALID_TO_JSID(sid)); - return obj_lookupGeneric(cx, obj, id, objp, propp); + return obj_lookupGeneric(cx, obj, RootedId(cx, SPECIALID_TO_JSID(sid)), objp, propp); } JSBool @@ -404,7 +402,7 @@ ArrayBufferObject::obj_defineGeneric(JSContext *cx, HandleObject obj, HandleId i RootedObject delegate(cx, DelegateObject(cx, obj)); if (!delegate) return false; - return baseops::DefineGeneric(cx, delegate, id, v, getter, setter, attrs); + return baseops::DefineProperty(cx, delegate, id, v, getter, setter, attrs); } JSBool @@ -412,8 +410,7 @@ ArrayBufferObject::obj_defineProperty(JSContext *cx, HandleObject obj, HandlePropertyName name, const Value *v, PropertyOp getter, StrictPropertyOp setter, unsigned attrs) { - Rooted id(cx, NameToId(name)); - return obj_defineGeneric(cx, obj, id, v, getter, setter, attrs); + return obj_defineGeneric(cx, obj, RootedId(cx, NameToId(name)), v, getter, setter, attrs); } JSBool @@ -432,8 +429,8 @@ JSBool ArrayBufferObject::obj_defineSpecial(JSContext *cx, HandleObject obj, HandleSpecialId sid, const Value *v, PropertyOp getter, StrictPropertyOp setter, unsigned attrs) { - Rooted id(cx, SPECIALID_TO_JSID(sid)); - return obj_defineGeneric(cx, obj, id, v, getter, setter, attrs); + return obj_defineGeneric(cx, obj, RootedId(cx, SPECIALID_TO_JSID(sid)), + v, getter, setter, attrs); } JSBool @@ -477,8 +474,7 @@ ArrayBufferObject::obj_getProperty(JSContext *cx, HandleObject obj, nobj = DelegateObject(cx, nobj); if (!nobj) return false; - Rooted id(cx, NameToId(name)); - return baseops::GetProperty(cx, nobj, receiver, id, vp); + return baseops::GetProperty(cx, nobj, receiver, RootedId(cx, NameToId(name)), vp); } JSBool @@ -507,8 +503,7 @@ JSBool ArrayBufferObject::obj_getSpecial(JSContext *cx, HandleObject obj, HandleObject receiver, HandleSpecialId sid, Value *vp) { - Rooted id(cx, SPECIALID_TO_JSID(sid)); - return obj_getGeneric(cx, obj, receiver, id, vp); + return obj_getGeneric(cx, obj, receiver, RootedId(cx, SPECIALID_TO_JSID(sid)), vp); } JSBool @@ -553,8 +548,7 @@ ArrayBufferObject::obj_setGeneric(JSContext *cx, HandleObject obj, HandleId id, obj->reportNotExtensible(cx); return false; } - Rooted newProto(cx, vp->toObjectOrNull()); - if (!SetProto(cx, obj, newProto, true)) { + if (!SetProto(cx, obj, RootedObject(cx, vp->toObjectOrNull()), true)) { // this can be caused for example by setting x.__proto__ = x // restore delegate prototype chain SetProto(cx, delegate, oldDelegateProto, true); @@ -571,8 +565,7 @@ JSBool ArrayBufferObject::obj_setProperty(JSContext *cx, HandleObject obj, HandlePropertyName name, Value *vp, JSBool strict) { - Rooted id(cx, NameToId(name)); - return obj_setGeneric(cx, obj, id, vp, strict); + return obj_setGeneric(cx, obj, RootedId(cx, NameToId(name)), vp, strict); } JSBool @@ -590,8 +583,7 @@ JSBool ArrayBufferObject::obj_setSpecial(JSContext *cx, HandleObject obj, HandleSpecialId sid, Value *vp, JSBool strict) { - Rooted id(cx, SPECIALID_TO_JSID(sid)); - return obj_setGeneric(cx, obj, id, vp, strict); + return obj_setGeneric(cx, obj, RootedId(cx, SPECIALID_TO_JSID(sid)), vp, strict); } JSBool @@ -613,8 +605,7 @@ JSBool ArrayBufferObject::obj_getPropertyAttributes(JSContext *cx, HandleObject obj, HandlePropertyName name, unsigned *attrsp) { - Rooted id(cx, NameToId(name)); - return obj_getGenericAttributes(cx, obj, id, attrsp); + return obj_getGenericAttributes(cx, obj, RootedId(cx, NameToId(name)), attrsp); } JSBool @@ -631,8 +622,7 @@ JSBool ArrayBufferObject::obj_getSpecialAttributes(JSContext *cx, HandleObject obj, HandleSpecialId sid, unsigned *attrsp) { - Rooted id(cx, SPECIALID_TO_JSID(sid)); - return obj_getGenericAttributes(cx, obj, id, attrsp); + return obj_getGenericAttributes(cx, obj, RootedId(cx, SPECIALID_TO_JSID(sid)), attrsp); } JSBool @@ -655,8 +645,7 @@ JSBool ArrayBufferObject::obj_setPropertyAttributes(JSContext *cx, HandleObject obj, HandlePropertyName name, unsigned *attrsp) { - Rooted id(cx, NameToId(name)); - return obj_setGenericAttributes(cx, obj, id, attrsp); + return obj_setGenericAttributes(cx, obj, RootedId(cx, NameToId(name)), attrsp); } JSBool @@ -673,8 +662,7 @@ JSBool ArrayBufferObject::obj_setSpecialAttributes(JSContext *cx, HandleObject obj, HandleSpecialId sid, unsigned *attrsp) { - Rooted id(cx, SPECIALID_TO_JSID(sid)); - return obj_setGenericAttributes(cx, obj, id, attrsp); + return obj_setGenericAttributes(cx, obj, RootedId(cx, SPECIALID_TO_JSID(sid)), attrsp); } JSBool @@ -871,8 +859,7 @@ JSBool TypedArray::obj_lookupProperty(JSContext *cx, HandleObject obj, HandlePropertyName name, JSObject **objp, JSProperty **propp) { - Rooted id(cx, NameToId(name)); - return obj_lookupGeneric(cx, obj, id, objp, propp); + return obj_lookupGeneric(cx, obj, RootedId(cx, NameToId(name)), objp, propp); } JSBool @@ -900,8 +887,7 @@ JSBool TypedArray::obj_lookupSpecial(JSContext *cx, HandleObject obj, HandleSpecialId sid, JSObject **objp, JSProperty **propp) { - Rooted id(cx, SPECIALID_TO_JSID(sid)); - return obj_lookupGeneric(cx, obj, id, objp, propp); + return obj_lookupGeneric(cx, obj, RootedId(cx, SPECIALID_TO_JSID(sid)), objp, propp); } JSBool @@ -930,8 +916,7 @@ TypedArray::obj_getElementAttributes(JSContext *cx, HandleObject obj, uint32_t i JSBool TypedArray::obj_getSpecialAttributes(JSContext *cx, HandleObject obj, HandleSpecialId sid, unsigned *attrsp) { - Rooted id(cx, SPECIALID_TO_JSID(sid)); - return obj_getGenericAttributes(cx, obj, id, attrsp); + return obj_getGenericAttributes(cx, obj, RootedId(cx, SPECIALID_TO_JSID(sid)), attrsp); } JSBool @@ -1121,9 +1106,9 @@ class TypedArrayTemplate if (IsDefinitelyIndex(idval, &index)) return obj_getElement(cx, obj, receiver, index, vp); - Rooted sid(cx); - if (ValueIsSpecial(obj, &idval, sid.address(), cx)) - return obj_getSpecial(cx, obj, receiver, sid, vp); + SpecialId sid; + if (ValueIsSpecial(obj, &idval, &sid, cx)) + return obj_getSpecial(cx, obj, receiver, Rooted(cx, sid), vp); JSAtom *atom = ToAtom(cx, idval); if (!atom) @@ -1132,8 +1117,7 @@ class TypedArrayTemplate if (atom->isIndex(&index)) return obj_getElement(cx, obj, receiver, index, vp); - Rooted name(cx, atom->asPropertyName()); - return obj_getProperty(cx, obj, receiver, name, vp); + return obj_getProperty(cx, obj, receiver, RootedPropertyName(cx, atom->asPropertyName()), vp); } static JSBool @@ -1251,8 +1235,7 @@ class TypedArrayTemplate static JSBool obj_setProperty(JSContext *cx, HandleObject obj, HandlePropertyName name, Value *vp, JSBool strict) { - Rooted id(cx, NameToId(name)); - return obj_setGeneric(cx, obj, id, vp, strict); + return obj_setGeneric(cx, obj, RootedId(cx, NameToId(name)), vp, strict); } static JSBool @@ -1277,8 +1260,7 @@ class TypedArrayTemplate static JSBool obj_setSpecial(JSContext *cx, HandleObject obj, HandleSpecialId sid, Value *vp, JSBool strict) { - Rooted id(cx, SPECIALID_TO_JSID(sid)); - return obj_setGeneric(cx, obj, id, vp, strict); + return obj_setGeneric(cx, obj, RootedId(cx, SPECIALID_TO_JSID(sid)), vp, strict); } static JSBool @@ -1296,8 +1278,7 @@ class TypedArrayTemplate obj_defineProperty(JSContext *cx, HandleObject obj, HandlePropertyName name, const Value *v, PropertyOp getter, StrictPropertyOp setter, unsigned attrs) { - Rooted id(cx, NameToId(name)); - return obj_defineGeneric(cx, obj, id, v, getter, setter, attrs); + return obj_defineGeneric(cx, obj, RootedId(cx, NameToId(name)), v, getter, setter, attrs); } static JSBool @@ -1312,8 +1293,7 @@ class TypedArrayTemplate obj_defineSpecial(JSContext *cx, HandleObject obj, HandleSpecialId sid, const Value *v, PropertyOp getter, StrictPropertyOp setter, unsigned attrs) { - Rooted id(cx, SPECIALID_TO_JSID(sid)); - return obj_defineGeneric(cx, obj, id, v, getter, setter, attrs); + return obj_defineGeneric(cx, obj, RootedId(cx, SPECIALID_TO_JSID(sid)), v, getter, setter, attrs); } static JSBool @@ -1557,8 +1537,7 @@ class TypedArrayTemplate } } - Rooted proto(cx, NULL); - return fromBuffer(cx, dataObj, byteOffset, length, proto); + return fromBuffer(cx, dataObj, byteOffset, length, RootedObject(cx)); } /* subarray(start[, end]) */ @@ -2914,19 +2893,15 @@ 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) \ { \ - Rooted other(cx, other_); \ - return TypedArrayTemplate::fromArray(cx, other); \ + return TypedArrayTemplate::fromArray(cx, RootedObject(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); \ - Rooted arrayBuffer(cx, arrayBuffer_); \ - Rooted proto(cx, NULL); \ - return TypedArrayTemplate::fromBuffer(cx, arrayBuffer, byteoffset, length, \ - proto); \ + return TypedArrayTemplate::fromBuffer(cx, RootedObject(cx, arrayBuffer), byteoffset, length, RootedObject(cx)); \ } \ 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 ea4274e65bfe9..a238610a1ec93 100644 --- a/js/src/jswrapper.cpp +++ b/js/src/jswrapper.cpp @@ -177,20 +177,17 @@ 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 - Rooted receiver(cx, receiver_); - Rooted id(cx, id_); - GET(wrappedObject(wrapper)->getGeneric(cx, receiver, id, vp)); + GET(wrappedObject(wrapper)->getGeneric(cx, RootedObject(cx, receiver), RootedId(cx, 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) { - Rooted id(cx, id_); - SET(wrappedObject(wrapper)->setGeneric(cx, id, vp, strict)); + SET(wrappedObject(wrapper)->setGeneric(cx, RootedId(cx, id), vp, strict)); } bool @@ -206,8 +203,7 @@ 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; - Rooted wrapped(cx, wrappedObject(wrapper)); - GET(GetIterator(cx, wrapped, flags, vp)); + GET(GetIterator(cx, RootedObject(cx, wrappedObject(wrapper)), flags, vp)); } bool @@ -419,8 +415,7 @@ ErrorCopier::~ErrorCopier() if (exc.isObject() && exc.toObject().isError() && exc.toObject().getPrivate()) { cx->clearPendingException(); ac.leave(); - Rooted errObj(cx, &exc.toObject()); - JSObject *copyobj = js_CopyErrorObject(cx, errObj, scope); + JSObject *copyobj = js_CopyErrorObject(cx, RootedObject(cx, &exc.toObject()), scope); if (copyobj) cx->setPendingException(ObjectValue(*copyobj)); } diff --git a/js/src/jsxml.cpp b/js/src/jsxml.cpp index 0a6ec8dd0ba3e..7e002e7fa0076 100644 --- a/js/src/jsxml.cpp +++ b/js/src/jsxml.cpp @@ -386,8 +386,7 @@ ConvertQNameToString(JSContext *cx, JSObject *obj) if (!str) return NULL; } - Rooted localName(cx, obj->getQNameLocalName()); - str = js_ConcatStrings(cx, str, localName); + str = js_ConcatStrings(cx, str, RootedString(cx, obj->getQNameLocalName())); if (!str) return NULL; @@ -4000,8 +3999,7 @@ 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. */ - Rooted robj(cx, rxml->object); - ok = GetProperty(cx, robj, id, &attrval); + ok = GetProperty(cx, RootedObject(cx, rxml->object), id, &attrval); if (!ok) goto out; if (JSVAL_IS_PRIMITIVE(attrval)) /* no such attribute */ @@ -4565,8 +4563,7 @@ ResolveValue(JSContext *cx, JSXML *list, JSXML **result) return JS_FALSE; RootedId id(cx, OBJECT_TO_JSID(targetprop)); - Rooted baseObj(cx, base->object); - if (!GetProperty(cx, baseObj, id, &tv)) + if (!GetProperty(cx, RootedObject(cx, base->object), id, &tv)) return JS_FALSE; target = (JSXML *) JSVAL_TO_OBJECT(tv)->getPrivate(); @@ -4576,9 +4573,9 @@ ResolveValue(JSContext *cx, JSXML *list, JSXML **result) return JS_TRUE; } tv = STRING_TO_JSVAL(cx->runtime->emptyString); - if (!PutProperty(cx, baseObj, id, false, &tv)) + if (!PutProperty(cx, RootedObject(cx, base->object), id, false, &tv)) return JS_FALSE; - if (!GetProperty(cx, baseObj, id, &tv)) + if (!GetProperty(cx, RootedObject(cx, base->object), id, &tv)) return JS_FALSE; target = (JSXML *) JSVAL_TO_OBJECT(tv)->getPrivate(); } @@ -4640,18 +4637,17 @@ 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_); - Rooted obj(cx, obj_); - if (!baseops::LookupProperty(cx, obj, funid, &pobj, &prop)) + if (!baseops::LookupProperty(cx, RootedObject(cx, obj), funid, &pobj, &prop)) return false; if (!prop) { xml = (JSXML *) obj->getPrivate(); @@ -4794,8 +4790,7 @@ static JSBool xml_lookupProperty(JSContext *cx, HandleObject obj, HandlePropertyName name, JSObject **objp, JSProperty **propp) { - Rooted id(cx, NameToId(name)); - return xml_lookupGeneric(cx, obj, id, objp, propp); + return xml_lookupGeneric(cx, obj, RootedId(cx, NameToId(name)), objp, propp); } static JSBool @@ -4814,8 +4809,9 @@ xml_lookupElement(JSContext *cx, HandleObject obj, uint32_t index, JSObject **ob return false; const Shape *shape = - js_AddNativeProperty(cx, obj, id, GetProperty, PutProperty, SHAPE_INVALID_SLOT, - JSPROP_ENUMERATE, 0, 0); + js_AddNativeProperty(cx, RootedObject(cx, obj), id, GetProperty, PutProperty, + SHAPE_INVALID_SLOT, JSPROP_ENUMERATE, + 0, 0); if (!shape) return false; @@ -4827,8 +4823,7 @@ 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) { - Rooted id(cx, SPECIALID_TO_JSID(sid)); - return xml_lookupGeneric(cx, obj, id, objp, propp); + return xml_lookupGeneric(cx, obj, RootedId(cx, SPECIALID_TO_JSID(sid)), objp, propp); } static JSBool @@ -4838,7 +4833,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::DefineGeneric(cx, obj, id, v, getter, setter, attrs); + return baseops::DefineProperty(cx, obj, id, v, getter, setter, attrs); } jsval tmp = *v; @@ -4849,8 +4844,7 @@ static JSBool xml_defineProperty(JSContext *cx, HandleObject obj, HandlePropertyName name, const Value *v, PropertyOp getter, StrictPropertyOp setter, unsigned attrs) { - Rooted id(cx, NameToId(name)); - return xml_defineGeneric(cx, obj, id, v, getter, setter, attrs); + return xml_defineGeneric(cx, obj, RootedId(cx, NameToId(name)), v, getter, setter, attrs); } static JSBool @@ -4867,8 +4861,7 @@ static JSBool xml_defineSpecial(JSContext *cx, HandleObject obj, HandleSpecialId sid, const Value *v, PropertyOp getter, StrictPropertyOp setter, unsigned attrs) { - Rooted id(cx, SPECIALID_TO_JSID(sid)); - return xml_defineGeneric(cx, obj, id, v, getter, setter, attrs); + return xml_defineGeneric(cx, obj, RootedId(cx, SPECIALID_TO_JSID(sid)), v, getter, setter, attrs); } static JSBool @@ -4885,8 +4878,7 @@ xml_getGeneric(JSContext *cx, HandleObject obj, HandleObject receiver, HandleId static JSBool xml_getProperty(JSContext *cx, HandleObject obj, HandleObject receiver, HandlePropertyName name, Value *vp) { - Rooted id(cx, NameToId(name)); - return xml_getGeneric(cx, obj, receiver, id, vp); + return xml_getGeneric(cx, obj, receiver, RootedId(cx, NameToId(name)), vp); } static JSBool @@ -4901,8 +4893,7 @@ xml_getElement(JSContext *cx, HandleObject obj, HandleObject receiver, uint32_t static JSBool xml_getSpecial(JSContext *cx, HandleObject obj, HandleObject receiver, HandleSpecialId sid, Value *vp) { - Rooted id(cx, SPECIALID_TO_JSID(sid)); - return xml_getGeneric(cx, obj, receiver, id, vp); + return xml_getGeneric(cx, obj, receiver, RootedId(cx, SPECIALID_TO_JSID(sid)), vp); } static JSBool @@ -4914,8 +4905,7 @@ 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) { - Rooted id(cx, NameToId(name)); - return xml_setGeneric(cx, obj, id, vp, strict); + return xml_setGeneric(cx, obj, RootedId(cx, NameToId(name)), vp, strict); } static JSBool @@ -4930,8 +4920,7 @@ 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) { - Rooted id(cx, SPECIALID_TO_JSID(sid)); - return xml_setGeneric(cx, obj, id, vp, strict); + return xml_setGeneric(cx, obj, RootedId(cx, SPECIALID_TO_JSID(sid)), vp, strict); } static JSBool @@ -4948,8 +4937,7 @@ xml_getGenericAttributes(JSContext *cx, HandleObject obj, HandleId id, unsigned static JSBool xml_getPropertyAttributes(JSContext *cx, HandleObject obj, HandlePropertyName name, unsigned *attrsp) { - Rooted id(cx, NameToId(name)); - return xml_getGenericAttributes(cx, obj, id, attrsp); + return xml_getGenericAttributes(cx, obj, RootedId(cx, NameToId(name)), attrsp); } static JSBool @@ -4964,8 +4952,7 @@ xml_getElementAttributes(JSContext *cx, HandleObject obj, uint32_t index, unsign static JSBool xml_getSpecialAttributes(JSContext *cx, HandleObject obj, HandleSpecialId sid, unsigned *attrsp) { - Rooted id(cx, SPECIALID_TO_JSID(sid)); - return xml_getGenericAttributes(cx, obj, id, attrsp); + return xml_getGenericAttributes(cx, obj, RootedId(cx, SPECIALID_TO_JSID(sid)), attrsp); } static JSBool @@ -4986,8 +4973,7 @@ xml_setGenericAttributes(JSContext *cx, HandleObject obj, HandleId id, unsigned static JSBool xml_setPropertyAttributes(JSContext *cx, HandleObject obj, HandlePropertyName name, unsigned *attrsp) { - Rooted id(cx, NameToId(name)); - return xml_setGenericAttributes(cx, obj, id, attrsp); + return xml_setGenericAttributes(cx, obj, RootedId(cx, NameToId(name)), attrsp); } static JSBool @@ -5002,8 +4988,7 @@ xml_setElementAttributes(JSContext *cx, HandleObject obj, uint32_t index, unsign static JSBool xml_setSpecialAttributes(JSContext *cx, HandleObject obj, HandleSpecialId sid, unsigned *attrsp) { - Rooted id(cx, SPECIALID_TO_JSID(sid)); - return xml_setGenericAttributes(cx, obj, id, attrsp); + return xml_setGenericAttributes(cx, obj, RootedId(cx, SPECIALID_TO_JSID(sid)), attrsp); } static JSBool @@ -5052,8 +5037,7 @@ 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) { - Rooted id(cx, NameToId(name)); - return xml_deleteGeneric(cx, obj, id, rval, strict); + return xml_deleteGeneric(cx, obj, RootedId(cx, NameToId(name)), rval, strict); } static JSBool @@ -5086,8 +5070,7 @@ 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) { - Rooted id(cx, SPECIALID_TO_JSID(sid)); - return xml_deleteGeneric(cx, obj, id, rval, strict); + return xml_deleteGeneric(cx, obj, RootedId(cx, SPECIALID_TO_JSID(sid)), rval, strict); } static JSString * @@ -5228,20 +5211,19 @@ HasSimpleContent(JSXML *xml) * 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.address(), cx); + js_GetLocalNameFromFunctionQName(JSID_TO_OBJECT(id), &id, 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, id, tvr.addr()); + JSBool ok = GetXMLFunction(cx, obj, RootedId(cx, id), tvr.addr()); *vp = tvr.value(); return ok; } @@ -5520,6 +5502,10 @@ 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) @@ -5529,21 +5515,20 @@ 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)); - Rooted vobj(cx, &v.toObject()); + vobj = JSVAL_TO_OBJECT(v); JS_ASSERT(vobj->isXML()); - JSXML *vxml = (JSXML *) vobj->getPrivate(); + 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, vobj, name, false, vp)) + if (!PutProperty(cx, RootedObject(cx, JSVAL_TO_OBJECT(v)), name, false, vp)) return JS_FALSE; *vp = OBJECT_TO_JSVAL(obj); @@ -5629,7 +5614,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; @@ -5640,8 +5625,6 @@ 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; @@ -5666,7 +5649,7 @@ xml_child_helper(JSContext *cx, JSObject *obj_, JSXML *xml, jsval name, if (!ValueToIdForXML(cx, name, id.address())) return JS_FALSE; - return GetProperty(cx, obj, id, rval); + return GetProperty(cx, RootedObject(cx, obj), id, rval); } /* XML and XMLList */ @@ -6351,11 +6334,9 @@ 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) - { - Rooted lstr(cx, kid->xml_value); - Rooted rstr(cx, kid2->xml_value); - str = js_ConcatStrings(cx, lstr, rstr); + kid2->xml_class == JSXML_CLASS_TEXT) { + str = js_ConcatStrings(cx, RootedString(cx, kid->xml_value), + RootedString(cx, kid2->xml_value)); if (!str) return JS_FALSE; NormalizingDelete(cx, xml, i + 1); @@ -6702,9 +6683,8 @@ 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, id, false, vp)) + if (!PutProperty(cx, obj, RootedId(cx, NameToId(cx->runtime->atomState.starAtom)), 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 0f80241796e24..395f28065ae85 100644 --- a/js/src/methodjit/Compiler.cpp +++ b/js/src/methodjit/Compiler.cpp @@ -4822,29 +4822,27 @@ 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)) { - 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); - } + 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); + } - frame.pop(); - frame.push(ObjectValue(*singleton)); + frame.pop(); + frame.push(ObjectValue(*singleton)); - if (script->hasScriptCounts && cx->typeInferenceEnabled()) - bumpPropCount(PC, PCCounts::PROP_STATIC); + if (script->hasScriptCounts && cx->typeInferenceEnabled()) + bumpPropCount(PC, PCCounts::PROP_STATIC); - if (testObject) - stubcc.rejoin(Changes(1)); + if (testObject) + stubcc.rejoin(Changes(1)); - return true; - } + return true; } /* Check if this is a property access we can make a loop invariant entry for. */ @@ -5121,8 +5119,7 @@ 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) { - Rooted proto(cx, object->proto); - if (!testSingletonProperty(proto, id)) + if (!testSingletonProperty(RootedObject(cx, object->proto), id)) return false; types->addFreeze(cx); @@ -5199,13 +5196,12 @@ mjit::Compiler::jsop_getprop_dispatch(PropertyName *name) if (ownTypes->isOwnProperty(cx, object, false)) return false; - Rooted proto(cx, object->proto); - if (!testSingletonProperty(proto, id)) + if (!testSingletonProperty(RootedObject(cx, object->proto), id)) return false; - if (proto->getType(cx)->unknownProperties()) + if (object->proto->getType(cx)->unknownProperties()) return false; - types::TypeSet *protoTypes = proto->type()->getProperty(cx, id, false); + types::TypeSet *protoTypes = object->proto->type()->getProperty(cx, id, false); if (!protoTypes) return false; JSObject *singleton = protoTypes->getSingleton(cx); @@ -6259,12 +6255,9 @@ mjit::Compiler::jsop_getgname(uint32_t index) /* Optimize singletons like Math for JSOP_CALLPROP. */ JSObject *obj = pushedSingleton(0); - if (obj && !hasTypeBarriers(PC)) { - Rooted id(cx, NameToId(name)); - if (testSingletonProperty(globalObj, id)) { - frame.push(ObjectValue(*obj)); - return true; - } + if (obj && !hasTypeBarriers(PC) && testSingletonProperty(globalObj, RootedId(cx, NameToId(name)))) { + 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 a5533588664ce..5a033a09acba0 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, id, JSRESOLVE_QUALIFIED, &holder, &prop); + LookupPropertyWithFlags(cx, baseobj, RootedId(cx, NameToId(name)), + 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 ff72f3b31a144..4fa9abdbcae5e 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; - Rooted holder(cx, getprop.holder); + JSObject *holder = getprop.holder; const JSProperty *prop = getprop.prop; if (!prop) { @@ -1690,7 +1690,7 @@ class ScopeNameCompiler : public PICStubCompiler } const Shape *shape = getprop.shape; - Rooted normalized(cx, obj); + JSObject *normalized = obj; if (obj->isWith() && !shape->hasDefaultGetter()) normalized = &obj->asWith().object(); NATIVE_GET(cx, normalized, holder, shape, 0, vp, return false); @@ -2437,8 +2437,7 @@ 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. - Rooted idRoot(cx, id); - if (!obj->getGeneric(cx, idRoot, vp)) + if (!obj->getGeneric(cx, RootedId(cx, id), vp)) return Lookup_Error; return Lookup_Cacheable; @@ -2505,11 +2504,11 @@ ic::GetElement(VMFrame &f, ic::GetElementIC *ic) } #endif - Rooted id(cx); + jsid id; if (idval.isInt32() && INT_FITS_IN_JSID(idval.toInt32())) { id = INT_TO_JSID(idval.toInt32()); } else { - if (!InternNonIntElementId(cx, obj, idval, id.address())) + if (!InternNonIntElementId(cx, obj, idval, &id)) THROW(); } @@ -2528,7 +2527,7 @@ ic::GetElement(VMFrame &f, ic::GetElementIC *ic) } } - if (!obj->getGeneric(cx, id, &f.regs.sp[-2])) + if (!obj->getGeneric(cx, RootedId(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 c5445340fa444..57c054f5b2087 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) { - Rooted name(f.cx, name_); - JSObject *obj = FindIdentifierBase(f.cx, f.fp()->scopeChain(), name); + JSObject *obj = FindIdentifierBase(f.cx, f.fp()->scopeChain(), + RootedPropertyName(f.cx, name)); if (!obj) THROW(); f.regs.sp[0].setObject(*obj); @@ -505,8 +505,7 @@ StubEqualityOp(VMFrame &f) JSObject *l = &lval.toObject(), *r = &rval.toObject(); if (JSEqualityOp eq = l->getClass()->ext.equality) { JSBool equal; - Rooted lobj(cx, l); - if (!eq(cx, lobj, &rval, &equal)) + if (!eq(cx, RootedObject(cx, l), &rval, &equal)) return false; cond = !!equal == EQ; } else { @@ -887,8 +886,7 @@ stubs::NewInitObject(VMFrame &f, JSObject *baseobj) JSObject *obj; if (baseobj) { - Rooted base(cx, baseobj); - obj = CopyInitializerObject(cx, base); + obj = CopyInitializerObject(cx, RootedObject(cx, baseobj)); } else { gc::AllocKind kind = GuessObjectGCKind(0); obj = NewBuiltinClassInstance(cx, &ObjectClass, kind); @@ -1067,8 +1065,8 @@ stubs::IterMore(VMFrame &f) JS_ASSERT(f.regs.sp[-1].isObject()); Value v; - Rooted iterobj(f.cx, &f.regs.sp[-1].toObject()); - if (!js_IteratorMore(f.cx, iterobj, &v)) + JSObject *iterobj = &f.regs.sp[-1].toObject(); + if (!js_IteratorMore(f.cx, RootedObject(f.cx, iterobj), &v)) THROWV(JS_FALSE); return v.toBoolean(); @@ -1402,8 +1400,9 @@ stubs::DefVarOrConst(VMFrame &f, PropertyName *dn) if (JSOp(*f.regs.pc) == JSOP_DEFCONST) attrs |= JSPROP_READONLY; - Rooted varobj(f.cx, &f.fp()->varObj()); - if (!DefVarOrConstOperation(f.cx, varobj, dn, attrs)) + JSObject &obj = f.fp()->varObj(); + + if (!DefVarOrConstOperation(f.cx, RootedObject(f.cx, &obj), dn, attrs)) THROW(); } diff --git a/js/src/shell/js.cpp b/js/src/shell/js.cpp index a5693dba6fb83..ef5aa3ce4b812 100644 --- a/js/src/shell/js.cpp +++ b/js/src/shell/js.cpp @@ -2782,8 +2782,7 @@ static JSBool resolver_resolve(JSContext *cx, HandleObject obj, HandleId id, unsigned flags, JSObject **objp) { jsval v = JS_GetReservedSlot(obj, 0); - Rooted vobj(cx, &v.toObject()); - return CopyProperty(cx, obj, vobj, id, flags, objp); + return CopyProperty(cx, obj, RootedObject(cx, JSVAL_TO_OBJECT(v)), id, flags, objp); } static JSBool @@ -2795,10 +2794,8 @@ 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++) { - Rooted id(cx, ida[i]); - ok = CopyProperty(cx, obj, referent, id, JSRESOLVE_QUALIFIED, &ignore); - } + for (size_t i = 0; ok && i < ida.length(); i++) + ok = CopyProperty(cx, obj, referent, RootedId(cx, ida[i]), JSRESOLVE_QUALIFIED, &ignore); return ok; } @@ -3150,13 +3147,13 @@ Parent(JSContext *cx, unsigned argc, jsval *vp) return false; } - Rooted parent(cx, JS_GetParent(&v.toObject())); + JSObject *parent = JS_GetParent(JSVAL_TO_OBJECT(v)); *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, parent)); + *vp = OBJECT_TO_JSVAL(op(cx, RootedObject(cx, parent))); } return true; diff --git a/js/src/shell/jsheaptools.cpp b/js/src/shell/jsheaptools.cpp index 2c7b4c1af5118..b0ab98b93ed7f 100644 --- a/js/src/shell/jsheaptools.cpp +++ b/js/src/shell/jsheaptools.cpp @@ -552,8 +552,7 @@ FindReferences(JSContext *cx, unsigned argc, jsval *vp) /* Given the reversed map, find the referents of target. */ ReferenceFinder finder(cx, reverser); - Rooted targetObj(cx, &target.toObject()); - JSObject *references = finder.findReferences(targetObj); + JSObject *references = finder.findReferences(RootedObject(cx, &target.toObject())); if (!references) return false; diff --git a/js/src/vm/ArgumentsObject.cpp b/js/src/vm/ArgumentsObject.cpp index fed1741486ffd..6867fb7f953d1 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::DefineGeneric(cx, obj, id, vp, NULL, NULL, JSPROP_ENUMERATE); + baseops::DefineProperty(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::DefineGeneric(cx, argsobj, id, &undef, ArgGetter, ArgSetter, attrs)) + if (!baseops::DefineProperty(cx, argsobj, id, &undef, ArgGetter, ArgSetter, attrs)) return JS_FALSE; *objp = argsobj; @@ -282,8 +282,7 @@ NormalArgumentsObject::optimizedGetElem(JSContext *cx, StackFrame *fp, const Val if (!proto) return false; - Rooted root(cx, id); - return proto->getGeneric(cx, root, vp); + return proto->getGeneric(cx, RootedId(cx, id), vp); } static JSBool @@ -397,7 +396,7 @@ strictargs_resolve(JSContext *cx, HandleObject obj, HandleId id, unsigned flags, } Value undef = UndefinedValue(); - if (!baseops::DefineGeneric(cx, argsobj, id, &undef, getter, setter, attrs)) + if (!baseops::DefineProperty(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 d9d868b1b98f5..b3b7d07ed8780 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; - Rooted obj(cx); + JSObject *obj; const Shape *shape; jsid returnId = NameToId(cx->runtime->atomState.returnAtom); jsid throwId = NameToId(cx->runtime->atomState.throwAtom); @@ -878,13 +878,11 @@ 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 GetMethod(cx, obj, id, 0, &fval) && - (!js_IsCallable(fval) || Invoke(cx, ObjectValue(*obj), fval, argc, argv, rval)); + return atom && + GetMethod(cx, obj, RootedId(cx, AtomToId(atom)), 0, &fval) && + (!js_IsCallable(fval) || + Invoke(cx, ObjectValue(*obj), fval, argc, argv, rval)); } JSTrapStatus @@ -1130,8 +1128,7 @@ Debugger::onTrap(JSContext *cx, Value *vp) if (!dbg->getScriptFrame(cx, fp, &argv[0])) return dbg->handleUncaughtException(ac, vp, false); Value rv; - Rooted handler(cx, bp->handler); - bool ok = CallMethodIfPresent(cx, handler, "hit", 1, argv, &rv); + bool ok = CallMethodIfPresent(cx, RootedObject(cx, bp->handler), "hit", 1, argv, &rv); JSTrapStatus st = dbg->parseResumptionValue(ac, ok, rv, vp, true); if (st != JSTRAP_CONTINUE) return st; @@ -2322,8 +2319,7 @@ 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, Handle::fromMarkedLocation(&scripts[i])); + JSObject *scriptObject = dbg->wrapScript(cx, Rooted(cx, scripts[i])); if (!scriptObject) return false; result->setDenseArrayElement(i, ObjectValue(*scriptObject)); @@ -2541,13 +2537,11 @@ 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 script(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); - script = fun->script(); - JSObject *s = dbg->wrapScript(cx, script); + JSObject *s = dbg->wrapScript(cx, Rooted(cx, fun->script())); if (!s || !js_NewbornArrayPush(cx, result, ObjectValue(*s))) return false; } @@ -3214,7 +3208,7 @@ DebuggerFrame_getArguments(JSContext *cx, unsigned argc, Value *vp) SetReservedSlot(argsobj, JSSLOT_DEBUGARGUMENTS_FRAME, ObjectValue(*thisobj)); JS_ASSERT(fp->numActualArgs() <= 0x7fffffff); - unsigned fargc = fp->numActualArgs(); + int32_t fargc = int32_t(fp->numActualArgs()); if (!DefineNativeProperty(cx, argsobj, cx->runtime->atomState.lengthAtom, Int32Value(fargc), NULL, NULL, JSPROP_PERMANENT | JSPROP_READONLY, 0, 0)) @@ -3222,16 +3216,12 @@ DebuggerFrame_getArguments(JSContext *cx, unsigned argc, Value *vp) return false; } - Rooted id(cx); - for (unsigned i = 0; i < fargc; i++) { + for (int32_t 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, id, UndefinedValue(), + !DefineNativeProperty(cx, argsobj, RootedId(cx, INT_TO_JSID(i)), UndefinedValue(), JS_DATA_TO_FUNC_PTR(PropertyOp, getobj.reference()), NULL, JSPROP_ENUMERATE | JSPROP_SHARED | JSPROP_GETTER, 0, 0)) { @@ -3257,8 +3247,7 @@ DebuggerFrame_getScript(JSContext *cx, unsigned argc, Value *vp) if (fp->isFunctionFrame() && !fp->isEvalFrame()) { JSFunction &callee = fp->callee(); if (callee.isInterpreted()) { - Rooted script(cx, callee.script()); - scriptObject = debug->wrapScript(cx, script); + scriptObject = debug->wrapScript(cx, Rooted(cx, callee.script())); if (!scriptObject) return false; } @@ -3267,8 +3256,8 @@ DebuggerFrame_getScript(JSContext *cx, unsigned argc, Value *vp) * We got eval, JS_Evaluate*, or JS_ExecuteScript non-function script * frames. */ - Rooted script(cx, fp->script()); - scriptObject = debug->wrapScript(cx, script); + JSScript *script = fp->script(); + scriptObject = debug->wrapScript(cx, Rooted(cx, script)); if (!scriptObject) return false; } @@ -3458,8 +3447,7 @@ 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, - Handle::fromMarkedLocation(&keys[i]), valp) || + if (!bindingsobj->getGeneric(cx, bindingsobj, RootedId(cx, keys[i]), valp) || !dbg->unwrapDebuggeeValue(cx, valp)) { return false; @@ -3728,8 +3716,7 @@ DebuggerObject_getScript(JSContext *cx, unsigned argc, Value *vp) return true; } - Rooted script(cx, fun->script()); - JSObject *scriptObject = dbg->wrapScript(cx, script); + JSObject *scriptObject = dbg->wrapScript(cx, Rooted(cx, fun->script())); if (!scriptObject) return false; @@ -3932,11 +3919,8 @@ 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, Handle::fromMarkedLocation(&rewrappedIds[i]), - rewrappedDescs[i], true, &dummy)) - { + if (!DefineProperty(cx, obj, RootedId(cx, rewrappedIds[i]), rewrappedDescs[i], true, &dummy)) return false; - } } } diff --git a/js/src/vm/RegExpObject.cpp b/js/src/vm/RegExpObject.cpp index 3ab9e592af3d9..0f1f471b2f801 100644 --- a/js/src/vm/RegExpObject.cpp +++ b/js/src/vm/RegExpObject.cpp @@ -97,16 +97,14 @@ RegExpObjectBuilder::clone(Handle other, Handle RegExpFlag staticsFlags = res->getFlags(); if ((origFlags & staticsFlags) != staticsFlags) { RegExpFlag newFlags = RegExpFlag(origFlags | staticsFlags); - Rooted source(cx, other->getSource()); - return build(source, newFlags); + return build(Rooted(cx, other->getSource()), newFlags); } RegExpGuard g; if (!other->getShared(cx, &g)) return NULL; - Rooted source(cx, other->getSource()); - return build(source, *g); + return build(RootedAtom(cx, other->getSource()), *g); } /* MatchPairs */ @@ -620,12 +618,14 @@ 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); - Rooted regex(cx, &obj_->asRegExp()); - Rooted proto(cx, &proto_->asRegExp()); - return builder.clone(regex, proto); + return builder.clone(Rooted(cx, &obj->asRegExp()), + Rooted(cx, &proto->asRegExp())); } bool diff --git a/js/src/vm/ScopeObject.cpp b/js/src/vm/ScopeObject.cpp index 245e6f6dbbbc8..06369efd6780a 100644 --- a/js/src/vm/ScopeObject.cpp +++ b/js/src/vm/ScopeObject.cpp @@ -119,8 +119,7 @@ CallObject::create(JSContext *cx, JSScript *script, HandleObject enclosing, Hand */ if (&enclosing->global() != obj->getParent()) { JS_ASSERT(obj->getParent() == NULL); - Rooted global(cx, &enclosing->global()); - if (!JSObject::setParent(cx, obj, global)) + if (!JSObject::setParent(cx, obj, RootedObject(cx, &enclosing->global()))) return NULL; } @@ -159,8 +158,7 @@ CallObject::createForFunction(JSContext *cx, StackFrame *fp) } RootedScript script(cx, fp->script()); - Rooted callee(cx, &fp->callee()); - CallObject *callobj = create(cx, script, scopeChain, callee); + CallObject *callobj = create(cx, script, scopeChain, RootedFunction(cx, &fp->callee())); if (!callobj) return NULL; @@ -214,8 +212,7 @@ CallObject::createForStrictEval(JSContext *cx, StackFrame *fp) JS_ASSERT(cx->fp() == fp); JS_ASSERT(cx->regs().pc == fp->script()->code); - Rooted callee(cx, NULL); - return create(cx, fp->script(), fp->scopeChain(), callee); + return create(cx, fp->script(), fp->scopeChain(), RootedFunction(cx)); } JSBool @@ -306,8 +303,8 @@ DeclEnvObject::create(JSContext *cx, StackFrame *fp) return NULL; - Rooted id(cx, AtomToId(fp->fun()->atom)); - if (!DefineNativeProperty(cx, obj, id, ObjectValue(fp->callee()), NULL, NULL, + if (!DefineNativeProperty(cx, obj, RootedId(cx, AtomToId(fp->fun()->atom)), + ObjectValue(fp->callee()), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_READONLY, 0, 0)) { return NULL; @@ -357,8 +354,7 @@ with_LookupGeneric(JSContext *cx, HandleObject obj, HandleId id, JSObject **objp static JSBool with_LookupProperty(JSContext *cx, HandleObject obj, HandlePropertyName name, JSObject **objp, JSProperty **propp) { - Rooted id(cx, NameToId(name)); - return with_LookupGeneric(cx, obj, id, objp, propp); + return with_LookupGeneric(cx, obj, RootedId(cx, NameToId(name)), objp, propp); } static JSBool @@ -374,8 +370,7 @@ 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) { - Rooted id(cx, SPECIALID_TO_JSID(sid)); - return with_LookupGeneric(cx, obj, id, objp, propp); + return with_LookupGeneric(cx, obj, RootedId(cx, SPECIALID_TO_JSID(sid)), objp, propp); } static JSBool @@ -387,8 +382,7 @@ with_GetGeneric(JSContext *cx, HandleObject obj, HandleObject receiver, HandleId static JSBool with_GetProperty(JSContext *cx, HandleObject obj, HandleObject receiver, HandlePropertyName name, Value *vp) { - Rooted id(cx, NameToId(name)); - return with_GetGeneric(cx, obj, receiver, id, vp); + return with_GetGeneric(cx, obj, receiver, RootedId(cx, NameToId(name)), vp); } static JSBool @@ -403,8 +397,7 @@ with_GetElement(JSContext *cx, HandleObject obj, HandleObject receiver, uint32_t static JSBool with_GetSpecial(JSContext *cx, HandleObject obj, HandleObject receiver, HandleSpecialId sid, Value *vp) { - Rooted id(cx, SPECIALID_TO_JSID(sid)); - return with_GetGeneric(cx, obj, receiver, id, vp); + return with_GetGeneric(cx, obj, receiver, RootedId(cx, SPECIALID_TO_JSID(sid)), vp); } static JSBool @@ -594,8 +587,7 @@ 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); - Rooted global(cx, &fp->global()); - if (!JSObject::setParent(cx, obj, global)) + if (!JSObject::setParent(cx, obj, RootedObject(cx, &fp->global()))) return NULL; } @@ -1333,21 +1325,18 @@ class DebugScopeProxy : public BaseProxyHandler if (handleUnaliasedAccess(cx, scope, id, GET, vp)) return true; - Rooted scopeObj(cx, &scope); - Rooted idRoot(cx, id); - return scope.getGeneric(cx, scopeObj, idRoot, vp); + return scope.getGeneric(cx, RootedObject(cx, &scope), RootedId(cx, id), 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; - Rooted id(cx, id_); - return scope.setGeneric(cx, id, vp, strict); + return scope.setGeneric(cx, RootedId(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 d9a4474b07daf..1093607fdb7b8 100644 --- a/js/xpconnect/src/XPCComponents.cpp +++ b/js/xpconnect/src/XPCComponents.cpp @@ -4082,7 +4082,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. - JS::Rooted obj(cx, JSVAL_TO_OBJECT(object)); + JSObject *obj = JSVAL_TO_OBJECT(object); obj = js::UnwrapObject(obj); { JSAutoEnterCompartment ac; @@ -4090,12 +4090,12 @@ nsXPCComponents_Utils::GetGlobalForObject(const JS::Value& object, return NS_ERROR_FAILURE; obj = JS_GetGlobalForObject(cx, obj); } - JS_WrapObject(cx, obj.address()); + JS_WrapObject(cx, &obj); *retval = OBJECT_TO_JSVAL(obj); // Outerize if necessary. if (JSObjectOp outerize = js::GetObjectClass(obj)->ext.outerObject) - *retval = OBJECT_TO_JSVAL(outerize(cx, obj)); + *retval = OBJECT_TO_JSVAL(outerize(cx, JS::RootedObject(cx, obj))); return NS_OK; } diff --git a/mfbt/Assertions.h b/mfbt/Assertions.h index 407fb24e98d19..a6615c2f0fb84 100644 --- a/mfbt/Assertions.h +++ b/mfbt/Assertions.h @@ -9,27 +9,11 @@ #define mozilla_Assertions_h_ #include "mozilla/Attributes.h" +#include "mozilla/Types.h" -#include #include #include -#ifdef WIN32 - /* - * TerminateProcess and GetCurrentProcess are defined in , which - * further depends on . We hardcode these few definitions manually - * because those headers clutter the global namespace with a significant - * number of undesired macros and symbols. - */ -# ifdef __cplusplus - extern "C" { -# endif - __declspec(dllimport) int __stdcall - TerminateProcess(void* hProcess, unsigned int uExitCode); - __declspec(dllimport) void* __stdcall GetCurrentProcess(void); -# ifdef __cplusplus - } -# endif -#else +#ifndef WIN32 # include #endif #ifdef ANDROID @@ -136,30 +120,22 @@ extern "C" { * On MSVC use the __debugbreak compiler intrinsic, which produces an inline * (not nested in a system function) breakpoint. This distinctively invokes * Breakpad without requiring system library symbols on all stack-processing - * machines, as a nested breakpoint would require. We use TerminateProcess - * with the exit code aborting would generate because we don't want to invoke - * atexit handlers, destructors, library unload handlers, and so on when our - * process might be in a compromised state. We don't use abort() because - * it'd cause Windows to annoyingly pop up the process error dialog multiple - * times. See bug 345118 and bug 426163. - * - * (Technically these are Windows requirements, not MSVC requirements. But - * practically you need MSVC for debugging, and we only ship builds created - * by MSVC, so doing it this way reduces complexity.) + * machines, as a nested breakpoint would require. (Technically all Windows + * compilers would require this, but practically only MSVC matters.) */ # ifdef __cplusplus # define MOZ_CRASH() \ do { \ __debugbreak(); \ *((volatile int*) NULL) = 123; \ - ::TerminateProcess(::GetCurrentProcess(), 3); \ + ::exit(3); \ } while (0) # else # define MOZ_CRASH() \ do { \ __debugbreak(); \ *((volatile int*) NULL) = 123; \ - TerminateProcess(GetCurrentProcess(), 3); \ + exit(3); \ } while (0) # endif #else diff --git a/mfbt/HashFunctions.cpp b/mfbt/HashFunctions.cpp index 28d4c9f4022b0..199e265de52e5 100644 --- a/mfbt/HashFunctions.cpp +++ b/mfbt/HashFunctions.cpp @@ -6,7 +6,6 @@ /* Implementations of hash functions. */ #include "mozilla/HashFunctions.h" -#include "mozilla/Types.h" #include diff --git a/mfbt/HashFunctions.h b/mfbt/HashFunctions.h index 7a19749e556d6..64ac6f91ce5c4 100644 --- a/mfbt/HashFunctions.h +++ b/mfbt/HashFunctions.h @@ -48,7 +48,6 @@ #include "mozilla/Assertions.h" #include "mozilla/Attributes.h" #include "mozilla/StandardInteger.h" -#include "mozilla/Types.h" #ifdef __cplusplus namespace mozilla { diff --git a/mfbt/Scoped.h b/mfbt/Scoped.h index b811a47d5e443..27016b3c32eee 100644 --- a/mfbt/Scoped.h +++ b/mfbt/Scoped.h @@ -35,12 +35,12 @@ * Note that the RAII classes defined in this header do _not_ perform any form * of reference-counting or garbage-collection. These classes have exactly two * behaviors: - * * - if |forget()| has not been called, the resource is always deallocated at * the end of the scope; * - if |forget()| has been called, any control on the resource is unbound * and the resource is not deallocated by the class. * + * * Extension: * * In addition, this header provides class |Scoped| and macro |SCOPED_TEMPLATE| @@ -52,8 +52,6 @@ #include "mozilla/Attributes.h" #include "mozilla/GuardObjects.h" -namespace mozilla { - /* * Scoped is a helper to create RAII wrappers * Type argument |Traits| is expected to have the following structure: @@ -161,9 +159,9 @@ class Scoped */ #define SCOPED_TEMPLATE(name, Traits) \ template \ -struct name : public mozilla::Scoped > \ +struct name : public Scoped > \ { \ - typedef mozilla::Scoped > Super; \ + typedef Scoped > Super; \ typedef typename Super::Resource Resource; \ name& operator=(Resource ptr) { \ Super::operator=(ptr); \ @@ -223,6 +221,4 @@ struct ScopedDeleteArrayTraits : public ScopedFreePtrTraits }; SCOPED_TEMPLATE(ScopedDeleteArray, ScopedDeleteArrayTraits) -} /* namespace mozilla */ - #endif // mozilla_Scoped_h_