From 31aad21f23ad62188e6a82b75219ef6bc19fc6b9 Mon Sep 17 00:00:00 2001 From: Jon Coppeard Date: Fri, 2 Aug 2013 13:15:39 +0100 Subject: [PATCH] Bug 899973 - GC: Convert the rest of the JS property API to use MutableHandleValue for out params - js changes r=sfink --- js/src/jsapi-tests/testLookup.cpp | 2 +- js/src/jsapi.cpp | 55 ++++++++++++++++--------------- js/src/jsapi.h | 18 +++++----- js/src/jscntxt.cpp | 2 +- js/src/jsproxy.cpp | 2 +- js/src/shell/js.cpp | 6 ++-- 6 files changed, 44 insertions(+), 41 deletions(-) diff --git a/js/src/jsapi-tests/testLookup.cpp b/js/src/jsapi-tests/testLookup.cpp index 6298df5e67b..3965f96ff28 100644 --- a/js/src/jsapi-tests/testLookup.cpp +++ b/js/src/jsapi-tests/testLookup.cpp @@ -27,7 +27,7 @@ BEGIN_TEST(testLookup_bug522590) // This lookup must not return an internal function object. JS::RootedValue r(cx); - CHECK(JS_LookupProperty(cx, xobj, "f", r.address())); + CHECK(JS_LookupProperty(cx, xobj, "f", &r)); CHECK(r.isObject()); JSObject *funobj = &r.toObject(); CHECK(funobj->is()); diff --git a/js/src/jsapi.cpp b/js/src/jsapi.cpp index ae6a73a5af7..5939832fad8 100644 --- a/js/src/jsapi.cpp +++ b/js/src/jsapi.cpp @@ -3106,11 +3106,11 @@ LookupPropertyById(JSContext *cx, HandleObject obj, HandleId id, unsigned flags, static JSBool LookupResult(JSContext *cx, HandleObject obj, HandleObject obj2, HandleId id, - HandleShape shape, Value *vp) + HandleShape shape, MutableHandleValue vp) { if (!shape) { /* XXX bad API: no way to tell "not defined" from "void value" */ - vp->setUndefined(); + vp.setUndefined(); return JS_TRUE; } @@ -3120,28 +3120,28 @@ LookupResult(JSContext *cx, HandleObject obj, HandleObject obj2, HandleId id, if (!Proxy::getPropertyDescriptor(cx, obj2, id, &desc, 0)) return false; if (!(desc.attrs & JSPROP_SHARED)) { - *vp = desc.value; + vp.set(desc.value); return true; } } } else if (IsImplicitDenseElement(shape)) { - *vp = obj2->getDenseElement(JSID_TO_INT(id)); + vp.set(obj2->getDenseElement(JSID_TO_INT(id))); return true; } else { /* Peek at the native property's slot value, without doing a Get. */ if (shape->hasSlot()) { - *vp = obj2->nativeGetSlot(shape->slot()); + vp.set(obj2->nativeGetSlot(shape->slot())); return true; } } /* XXX bad API: no way to return "defined but value unknown" */ - vp->setBoolean(true); + vp.setBoolean(true); return true; } JS_PUBLIC_API(JSBool) -JS_LookupPropertyById(JSContext *cx, JSObject *objArg, jsid idArg, jsval *vp) +JS_LookupPropertyById(JSContext *cx, JSObject *objArg, jsid idArg, MutableHandleValue vp) { RootedId id(cx, idArg); RootedObject obj(cx, objArg); @@ -3160,11 +3160,15 @@ JS_LookupElement(JSContext *cx, JSObject *objArg, uint32_t index, jsval *vp) RootedId id(cx); if (!IndexToId(cx, index, &id)) return false; - return JS_LookupPropertyById(cx, obj, id, vp); + RootedValue value(cx); + if (!JS_LookupPropertyById(cx, obj, id, &value)) + return false; + *vp = value; + return true; } JS_PUBLIC_API(JSBool) -JS_LookupProperty(JSContext *cx, JSObject *objArg, const char *name, jsval *vp) +JS_LookupProperty(JSContext *cx, JSObject *objArg, const char *name, MutableHandleValue vp) { RootedObject obj(cx, objArg); JSAtom *atom = Atomize(cx, name, strlen(name)); @@ -3172,7 +3176,8 @@ JS_LookupProperty(JSContext *cx, JSObject *objArg, const char *name, jsval *vp) } JS_PUBLIC_API(JSBool) -JS_LookupUCProperty(JSContext *cx, JSObject *objArg, const jschar *name, size_t namelen, jsval *vp) +JS_LookupUCProperty(JSContext *cx, JSObject *objArg, const jschar *name, size_t namelen, + MutableHandleValue vp) { RootedObject obj(cx, objArg); JSAtom *atom = AtomizeChars(cx, name, AUTO_NAMELEN(name, namelen)); @@ -3181,7 +3186,7 @@ JS_LookupUCProperty(JSContext *cx, JSObject *objArg, const jschar *name, size_t JS_PUBLIC_API(JSBool) JS_LookupPropertyWithFlagsById(JSContext *cx, JSObject *objArg, jsid id_, unsigned flags, - JSObject **objpArg, jsval *vp) + JSObject **objpArg, MutableHandleValue vp) { RootedObject obj(cx, objArg); RootedObject objp(cx, *objpArg); @@ -3204,7 +3209,8 @@ JS_LookupPropertyWithFlagsById(JSContext *cx, JSObject *objArg, jsid id_, unsign } JS_PUBLIC_API(JSBool) -JS_LookupPropertyWithFlags(JSContext *cx, JSObject *objArg, const char *name, unsigned flags, jsval *vp) +JS_LookupPropertyWithFlags(JSContext *cx, JSObject *objArg, const char *name, unsigned flags, + MutableHandleValue vp) { RootedObject obj(cx, objArg); JSObject *obj2; @@ -3718,18 +3724,14 @@ JS_GetUCPropertyAttrsGetterAndSetter(JSContext *cx, JSObject *objArg, } JS_PUBLIC_API(JSBool) -JS_GetOwnPropertyDescriptor(JSContext *cx, JSObject *objArg, jsid idArg, jsval *vp) +JS_GetOwnPropertyDescriptor(JSContext *cx, JSObject *objArg, jsid idArg, MutableHandleValue vp) { RootedObject obj(cx, objArg); RootedId id(cx, idArg); AssertHeapIsIdle(cx); CHECK_REQUEST(cx); - RootedValue value(cx); - if (!GetOwnPropertyDescriptor(cx, obj, id, &value)) - return false; - *vp = value; - return true; + return GetOwnPropertyDescriptor(cx, obj, id, vp); } static JSBool @@ -3926,7 +3928,7 @@ JS_SetUCProperty(JSContext *cx, JSObject *objArg, const jschar *name, size_t nam } JS_PUBLIC_API(JSBool) -JS_DeletePropertyById2(JSContext *cx, JSObject *objArg, jsid id, jsval *rval) +JS_DeletePropertyById2(JSContext *cx, JSObject *objArg, jsid id, MutableHandleValue rval) { RootedObject obj(cx, objArg); AssertHeapIsIdle(cx); @@ -3946,7 +3948,7 @@ JS_DeletePropertyById2(JSContext *cx, JSObject *objArg, jsid id, jsval *rval) return false; } - *rval = BooleanValue(succeeded); + rval.setBoolean(succeeded); return true; } @@ -3968,7 +3970,7 @@ JS_DeleteElement2(JSContext *cx, JSObject *objArg, uint32_t index, jsval *rval) } JS_PUBLIC_API(JSBool) -JS_DeleteProperty2(JSContext *cx, JSObject *objArg, const char *name, jsval *rval) +JS_DeleteProperty2(JSContext *cx, JSObject *objArg, const char *name, MutableHandleValue rval) { RootedObject obj(cx, objArg); CHECK_REQUEST(cx); @@ -3983,12 +3985,13 @@ JS_DeleteProperty2(JSContext *cx, JSObject *objArg, const char *name, jsval *rva if (!JSObject::deleteByValue(cx, obj, StringValue(atom), &succeeded)) return false; - *rval = BooleanValue(succeeded); + rval.setBoolean(succeeded); return true; } JS_PUBLIC_API(JSBool) -JS_DeleteUCProperty2(JSContext *cx, JSObject *objArg, const jschar *name, size_t namelen, jsval *rval) +JS_DeleteUCProperty2(JSContext *cx, JSObject *objArg, const jschar *name, size_t namelen, + MutableHandleValue rval) { RootedObject obj(cx, objArg); CHECK_REQUEST(cx); @@ -4003,14 +4006,14 @@ JS_DeleteUCProperty2(JSContext *cx, JSObject *objArg, const jschar *name, size_t if (!JSObject::deleteByValue(cx, obj, StringValue(atom), &succeeded)) return false; - *rval = BooleanValue(succeeded); + rval.setBoolean(succeeded); return true; } JS_PUBLIC_API(JSBool) JS_DeletePropertyById(JSContext *cx, JSObject *objArg, jsid idArg) { - jsval junk; + RootedValue junk(cx); return JS_DeletePropertyById2(cx, objArg, idArg, &junk); } @@ -4024,7 +4027,7 @@ JS_DeleteElement(JSContext *cx, JSObject *objArg, uint32_t index) JS_PUBLIC_API(JSBool) JS_DeleteProperty(JSContext *cx, JSObject *objArg, const char *name) { - jsval junk; + RootedValue junk(cx); return JS_DeleteProperty2(cx, objArg, name, &junk); } diff --git a/js/src/jsapi.h b/js/src/jsapi.h index 1b0a0aa0230..a48308fb3c4 100644 --- a/js/src/jsapi.h +++ b/js/src/jsapi.h @@ -3389,18 +3389,18 @@ extern JS_PUBLIC_API(JSBool) JS_HasPropertyById(JSContext *cx, JSObject *obj, jsid id, JSBool *foundp); extern JS_PUBLIC_API(JSBool) -JS_LookupProperty(JSContext *cx, JSObject *obj, const char *name, jsval *vp); +JS_LookupProperty(JSContext *cx, JSObject *obj, const char *name, JS::MutableHandle vp); extern JS_PUBLIC_API(JSBool) -JS_LookupPropertyById(JSContext *cx, JSObject *obj, jsid id, jsval *vp); +JS_LookupPropertyById(JSContext *cx, JSObject *obj, jsid id, JS::MutableHandle vp); extern JS_PUBLIC_API(JSBool) JS_LookupPropertyWithFlags(JSContext *cx, JSObject *obj, const char *name, - unsigned flags, jsval *vp); + unsigned flags, JS::MutableHandle vp); extern JS_PUBLIC_API(JSBool) JS_LookupPropertyWithFlagsById(JSContext *cx, JSObject *obj, jsid id, - unsigned flags, JSObject **objp, jsval *vp); + unsigned flags, JSObject **objp, JS::MutableHandle vp); struct JSPropertyDescriptor { JSObject *obj; @@ -3530,7 +3530,7 @@ JS_GetPropertyDescriptorById(JSContext *cx, JSObject *obj, jsid id, unsigned fla JSPropertyDescriptor *desc); extern JS_PUBLIC_API(JSBool) -JS_GetOwnPropertyDescriptor(JSContext *cx, JSObject *obj, jsid id, jsval *vp); +JS_GetOwnPropertyDescriptor(JSContext *cx, JSObject *obj, jsid id, JS::MutableHandle vp); extern JS_PUBLIC_API(JSBool) JS_GetProperty(JSContext *cx, JSObject *obj, const char *name, JS::MutableHandle vp); @@ -3561,13 +3561,13 @@ JS_DeleteProperty(JSContext *cx, JSObject *obj, const char *name); extern JS_PUBLIC_API(JSBool) JS_DeleteProperty2(JSContext *cx, JSObject *obj, const char *name, - jsval *rval); + JS::MutableHandle rval); extern JS_PUBLIC_API(JSBool) JS_DeletePropertyById(JSContext *cx, JSObject *obj, jsid id); extern JS_PUBLIC_API(JSBool) -JS_DeletePropertyById2(JSContext *cx, JSObject *obj, jsid id, jsval *rval); +JS_DeletePropertyById2(JSContext *cx, JSObject *obj, jsid id, JS::MutableHandle rval); extern JS_PUBLIC_API(JSBool) JS_DefineUCProperty(JSContext *cx, JSObject *obj, @@ -3629,7 +3629,7 @@ JS_HasUCProperty(JSContext *cx, JSObject *obj, extern JS_PUBLIC_API(JSBool) JS_LookupUCProperty(JSContext *cx, JSObject *obj, const jschar *name, size_t namelen, - jsval *vp); + JS::MutableHandle vp); extern JS_PUBLIC_API(JSBool) JS_GetUCProperty(JSContext *cx, JSObject *obj, @@ -3644,7 +3644,7 @@ JS_SetUCProperty(JSContext *cx, JSObject *obj, extern JS_PUBLIC_API(JSBool) JS_DeleteUCProperty2(JSContext *cx, JSObject *obj, const jschar *name, size_t namelen, - jsval *rval); + JS::MutableHandle rval); extern JS_PUBLIC_API(JSObject *) JS_NewArrayObject(JSContext *cx, int length, jsval *vector); diff --git a/js/src/jscntxt.cpp b/js/src/jscntxt.cpp index 00f1725cad8..9c2db0759f2 100644 --- a/js/src/jscntxt.cpp +++ b/js/src/jscntxt.cpp @@ -531,7 +531,7 @@ js::ReportUsageError(JSContext *cx, HandleObject callee, const char *msg) JS_ASSERT(shape->hasDefaultGetter()); RootedValue usage(cx); - if (!JS_LookupProperty(cx, callee, "usage", usage.address())) + if (!JS_LookupProperty(cx, callee, "usage", &usage)) return; if (JSVAL_IS_VOID(usage)) { diff --git a/js/src/jsproxy.cpp b/js/src/jsproxy.cpp index 26236cd2e0c..dca4c960d03 100644 --- a/js/src/jsproxy.cpp +++ b/js/src/jsproxy.cpp @@ -424,7 +424,7 @@ DirectProxyHandler::delete_(JSContext *cx, HandleObject proxy, HandleId id, bool assertEnteredPolicy(cx, proxy, id); RootedObject target(cx, proxy->as().target()); RootedValue v(cx); - if (!JS_DeletePropertyById2(cx, target, id, v.address())) + if (!JS_DeletePropertyById2(cx, target, id, &v)) return false; JSBool b; if (!JS_ValueToBoolean(cx, v, &b)) diff --git a/js/src/shell/js.cpp b/js/src/shell/js.cpp index 6dce3910c2c..268b8989a0c 100644 --- a/js/src/shell/js.cpp +++ b/js/src/shell/js.cpp @@ -4024,10 +4024,10 @@ static bool PrintHelp(JSContext *cx, HandleObject obj) { RootedValue usage(cx); - if (!JS_LookupProperty(cx, obj, "usage", usage.address())) + if (!JS_LookupProperty(cx, obj, "usage", &usage)) return false; RootedValue help(cx); - if (!JS_LookupProperty(cx, obj, "help", help.address())) + if (!JS_LookupProperty(cx, obj, "help", &help)) return false; if (JSVAL_IS_VOID(usage) || JSVAL_IS_VOID(help)) @@ -4050,7 +4050,7 @@ Help(JSContext *cx, unsigned argc, jsval *vp) for (size_t i = 0; i < ida.length(); i++) { RootedValue v(cx); - if (!JS_LookupPropertyById(cx, global, ida[i], v.address())) + if (!JS_LookupPropertyById(cx, global, ida[i], &v)) return false; if (JSVAL_IS_PRIMITIVE(v)) { JS_ReportError(cx, "primitive arg");