From 56d2495c20baf096861b6036d8c42a8a5a5c2b4e Mon Sep 17 00:00:00 2001 From: Tom Schuster Date: Wed, 18 Dec 2013 13:30:49 +0100 Subject: [PATCH] Bug 942453 - Handlify IndexToId. r=terrence --- js/src/builtin/TypedObject.cpp | 2 +- js/src/jsapi.cpp | 10 +++++----- js/src/jsarray.cpp | 7 +++---- js/src/jsatom.cpp | 4 ++-- js/src/jsatominlines.h | 17 +++-------------- js/src/jsiter.cpp | 2 +- js/src/jsobj.cpp | 22 ++++++++++------------ js/src/jsobjinlines.h | 9 ++++----- js/src/json.cpp | 2 +- js/src/jsproxy.cpp | 20 ++++++++++---------- js/src/vm/ScopeObject.cpp | 10 +++++----- 11 files changed, 45 insertions(+), 60 deletions(-) diff --git a/js/src/builtin/TypedObject.cpp b/js/src/builtin/TypedObject.cpp index da319e2a9691..213ffed57f76 100644 --- a/js/src/builtin/TypedObject.cpp +++ b/js/src/builtin/TypedObject.cpp @@ -2336,7 +2336,7 @@ TypedDatum::obj_deleteElement(JSContext *cx, HandleObject obj, uint32_t index, bool *succeeded) { RootedId id(cx); - if (!IndexToId(cx, index, id.address())) + if (!IndexToId(cx, index, &id)) return false; if (IsOwnId(cx, obj, id)) diff --git a/js/src/jsapi.cpp b/js/src/jsapi.cpp index e3de514e220f..b8f3e3fffde4 100644 --- a/js/src/jsapi.cpp +++ b/js/src/jsapi.cpp @@ -2805,7 +2805,7 @@ JS_LookupElement(JSContext *cx, JSObject *objArg, uint32_t index, MutableHandleV RootedObject obj(cx, objArg); CHECK_REQUEST(cx); RootedId id(cx); - if (!IndexToId(cx, index, id.address())) + if (!IndexToId(cx, index, &id)) return false; return JS_LookupPropertyById(cx, obj, id, vp); } @@ -2880,7 +2880,7 @@ JS_HasElement(JSContext *cx, JSObject *objArg, uint32_t index, bool *foundp) AssertHeapIsIdle(cx); CHECK_REQUEST(cx); RootedId id(cx); - if (!IndexToId(cx, index, id.address())) + if (!IndexToId(cx, index, &id)) return false; return JS_HasPropertyById(cx, obj, id, foundp); } @@ -2936,7 +2936,7 @@ JS_AlreadyHasOwnElement(JSContext *cx, JSObject *objArg, uint32_t index, bool *f AssertHeapIsIdle(cx); CHECK_REQUEST(cx); RootedId id(cx); - if (!IndexToId(cx, index, id.address())) + if (!IndexToId(cx, index, &id)) return false; return JS_AlreadyHasOwnPropertyById(cx, obj, id, foundp); } @@ -3078,7 +3078,7 @@ JS_DefineElement(JSContext *cx, JSObject *objArg, uint32_t index, jsval valueArg AssertHeapIsIdle(cx); CHECK_REQUEST(cx); RootedId id(cx); - if (!IndexToId(cx, index, id.address())) + if (!IndexToId(cx, index, &id)) return false; return DefinePropertyById(cx, obj, id, value, GetterWrapper(getter), SetterWrapper(setter), attrs, 0, 0); @@ -6049,7 +6049,7 @@ BOOL WINAPI DllMain (HINSTANCE hDLL, DWORD dwReason, LPVOID lpReserved) JS_PUBLIC_API(bool) JS_IndexToId(JSContext *cx, uint32_t index, MutableHandleId id) { - return IndexToId(cx, index, id.address()); + return IndexToId(cx, index, id); } JS_PUBLIC_API(bool) diff --git a/js/src/jsarray.cpp b/js/src/jsarray.cpp index 85b3f2b0b194..b51749da0453 100644 --- a/js/src/jsarray.cpp +++ b/js/src/jsarray.cpp @@ -137,7 +137,7 @@ static bool ToId(JSContext *cx, double index, MutableHandleId id) { if (index == uint32_t(index)) - return IndexToId(cx, uint32_t(index), id.address()); + return IndexToId(cx, uint32_t(index), id); Value tmp = DoubleValue(index); return ValueToId(cx, HandleValue::fromMarkedLocation(&tmp), id); @@ -146,7 +146,7 @@ ToId(JSContext *cx, double index, MutableHandleId id) static bool ToId(JSContext *cx, uint32_t index, MutableHandleId id) { - return IndexToId(cx, index, id.address()); + return IndexToId(cx, index, id); } /* @@ -161,7 +161,6 @@ DoGetElement(JSContext *cx, HandleObject obj, HandleObject receiver, IndexType index, bool *hole, MutableHandleValue vp) { RootedId id(cx); - if (!ToId(cx, index, &id)) return false; @@ -718,7 +717,7 @@ js::ArraySetLength(typename ExecutionModeTraits::ContextType cxArg, // returned from the function before step 15 above. JSContext *cx = cxArg->asJSContext(); RootedId elementId(cx); - if (!IndexToId(cx, newLen - 1, elementId.address())) + if (!IndexToId(cx, newLen - 1, &elementId)) return false; return arr->reportNotConfigurable(cx, elementId); } diff --git a/js/src/jsatom.cpp b/js/src/jsatom.cpp index 2f6ae88f1f0d..410501faa479 100644 --- a/js/src/jsatom.cpp +++ b/js/src/jsatom.cpp @@ -391,7 +391,7 @@ js::AtomizeChars(ExclusiveContext *cx, const jschar *chars, size_t length, Inter } bool -js::IndexToIdSlow(ExclusiveContext *cx, uint32_t index, jsid *idp) +js::IndexToIdSlow(ExclusiveContext *cx, uint32_t index, MutableHandleId idp) { JS_ASSERT(index > JSID_INT_MAX); @@ -403,7 +403,7 @@ js::IndexToIdSlow(ExclusiveContext *cx, uint32_t index, jsid *idp) if (!atom) return false; - *idp = JSID_FROM_BITS((size_t)atom); + idp.set(JSID_FROM_BITS((size_t)atom)); return true; } diff --git a/js/src/jsatominlines.h b/js/src/jsatominlines.h index f6ed26e39bda..7d78232bf4d1 100644 --- a/js/src/jsatominlines.h +++ b/js/src/jsatominlines.h @@ -105,30 +105,19 @@ BackfillIndexInCharBuffer(uint32_t index, mozilla::RangedPtr end) } bool -IndexToIdSlow(ExclusiveContext *cx, uint32_t index, jsid *idp); +IndexToIdSlow(ExclusiveContext *cx, uint32_t index, MutableHandleId idp); inline bool -IndexToId(ExclusiveContext *cx, uint32_t index, jsid *idp) +IndexToId(ExclusiveContext *cx, uint32_t index, MutableHandleId idp) { if (index <= JSID_INT_MAX) { - *idp = INT_TO_JSID(index); + idp.set(INT_TO_JSID(index)); return true; } return IndexToIdSlow(cx, index, idp); } -inline bool -IndexToIdPure(uint32_t index, jsid *idp) -{ - if (index <= JSID_INT_MAX) { - *idp = INT_TO_JSID(index); - return true; - } - - return false; -} - static JS_ALWAYS_INLINE JSFlatString * IdToString(JSContext *cx, jsid id) { diff --git a/js/src/jsiter.cpp b/js/src/jsiter.cpp index d7c182eaa815..459d5f912bc0 100644 --- a/js/src/jsiter.cpp +++ b/js/src/jsiter.cpp @@ -1124,7 +1124,7 @@ bool js_SuppressDeletedElement(JSContext *cx, HandleObject obj, uint32_t index) { RootedId id(cx); - if (!IndexToId(cx, index, id.address())) + if (!IndexToId(cx, index, &id)) return false; return js_SuppressDeletedProperty(cx, obj, id); } diff --git a/js/src/jsobj.cpp b/js/src/jsobj.cpp index 61ff5de58012..9d7dae3bc707 100644 --- a/js/src/jsobj.cpp +++ b/js/src/jsobj.cpp @@ -1685,7 +1685,7 @@ JSObject::nonNativeSetElement(JSContext *cx, HandleObject obj, { if (JS_UNLIKELY(obj->watched())) { RootedId id(cx); - if (!IndexToId(cx, index, id.address())) + if (!IndexToId(cx, index, &id)) return false; WatchpointMap *wpmap = cx->compartment()->watchpointMap; @@ -3269,7 +3269,7 @@ bool baseops::DefineElement(ExclusiveContext *cx, HandleObject obj, uint32_t index, HandleValue value, PropertyOp getter, StrictPropertyOp setter, unsigned attrs) { - Rooted id(cx); + RootedId id(cx); if (index <= JSID_INT_MAX) { id = INT_TO_JSID(index); return DefineNativeProperty(cx, obj, id, value, getter, setter, attrs, 0, 0); @@ -3277,7 +3277,7 @@ baseops::DefineElement(ExclusiveContext *cx, HandleObject obj, uint32_t index, H AutoRooterGetterSetter gsRoot(cx, attrs, &getter, &setter); - if (!IndexToId(cx, index, id.address())) + if (!IndexToId(cx, index, &id)) return false; return DefineNativeProperty(cx, obj, id, value, getter, setter, attrs, 0, 0); @@ -3867,7 +3867,7 @@ baseops::LookupElement(JSContext *cx, HandleObject obj, uint32_t index, MutableHandleObject objp, MutableHandleShape propp) { RootedId id(cx); - if (!IndexToId(cx, index, id.address())) + if (!IndexToId(cx, index, &id)) return false; return LookupPropertyWithFlagsInline(cx, obj, id, cx->resolveFlags, objp, propp); @@ -4406,11 +4406,9 @@ static bool JS_ALWAYS_INLINE GetElementPure(ThreadSafeContext *cx, JSObject *obj, uint32_t index, Value *vp) { - jsid id; - if (!IndexToIdPure(index, &id)) - return false; - - return GetPropertyPure(cx, obj, id, vp); + if (index <= JSID_INT_MAX) + return GetPropertyPure(cx, obj, INT_TO_JSID(index), vp); + return false; } /* @@ -4442,7 +4440,7 @@ baseops::GetElement(JSContext *cx, HandleObject obj, HandleObject receiver, uint MutableHandleValue vp) { RootedId id(cx); - if (!IndexToId(cx, index, id.address())) + if (!IndexToId(cx, index, &id)) return false; /* This call site is hot -- use the always-inlined variant of js_GetPropertyHelper(). */ @@ -4823,7 +4821,7 @@ baseops::SetElementHelper(JSContext *cx, HandleObject obj, HandleObject receiver unsigned defineHow, MutableHandleValue vp, bool strict) { RootedId id(cx); - if (!IndexToId(cx, index, id.address())) + if (!IndexToId(cx, index, &id)) return false; return baseops::SetPropertyHelper(cx, obj, receiver, id, defineHow, vp, strict); @@ -4928,7 +4926,7 @@ bool baseops::DeleteElement(JSContext *cx, HandleObject obj, uint32_t index, bool *succeeded) { RootedId id(cx); - if (!IndexToId(cx, index, id.address())) + if (!IndexToId(cx, index, &id)) return false; return baseops::DeleteGeneric(cx, obj, id, succeeded); } diff --git a/js/src/jsobjinlines.h b/js/src/jsobjinlines.h index 674d4ea03c17..d544fce69a71 100644 --- a/js/src/jsobjinlines.h +++ b/js/src/jsobjinlines.h @@ -53,7 +53,7 @@ JSObject::deleteProperty(JSContext *cx, js::HandleObject obj, js::HandleProperty /* static */ inline bool JSObject::deleteElement(JSContext *cx, js::HandleObject obj, uint32_t index, bool *succeeded) { - jsid id; + JS::RootedId id(cx); if (!js::IndexToId(cx, index, &id)) return false; js::types::MarkTypePropertyConfigured(cx, obj, id); @@ -621,7 +621,7 @@ JSObject::getElement(JSContext *cx, js::HandleObject obj, js::HandleObject recei return op(cx, obj, receiver, index, vp); JS::RootedId id(cx); - if (!js::IndexToId(cx, index, id.address())) + if (!js::IndexToId(cx, index, &id)) return false; return getGeneric(cx, obj, receiver, id, vp); } @@ -634,10 +634,9 @@ JSObject::getElementNoGC(JSContext *cx, JSObject *obj, JSObject *receiver, if (op) return false; - jsid id; - if (!js::IndexToId(cx, index, &id)) + if (index > JSID_INT_MAX) return false; - return getGenericNoGC(cx, obj, receiver, id, vp); + return getGenericNoGC(cx, obj, receiver, INT_TO_JSID(index), vp); } inline js::GlobalObject & diff --git a/js/src/json.cpp b/js/src/json.cpp index 2c995b2b28c6..9358b5ac68e6 100644 --- a/js/src/json.cpp +++ b/js/src/json.cpp @@ -688,7 +688,7 @@ Walk(JSContext *cx, HandleObject holder, HandleId name, HandleValue reviver, Mut RootedId id(cx); RootedValue newElement(cx); for (uint32_t i = 0; i < length; i++) { - if (!IndexToId(cx, i, id.address())) + if (!IndexToId(cx, i, &id)) return false; /* Step 2a(iii)(1). */ diff --git a/js/src/jsproxy.cpp b/js/src/jsproxy.cpp index bc3febde96ce..81a50dd93705 100644 --- a/js/src/jsproxy.cpp +++ b/js/src/jsproxy.cpp @@ -381,7 +381,7 @@ BaseProxyHandler::slice(JSContext *cx, HandleObject proxy, uint32_t begin, uint3 RootedId id(cx); RootedValue value(cx); for (uint32_t index = begin; index < end; index++) { - if (!IndexToId(cx, index, id.address())) + if (!IndexToId(cx, index, &id)) return false; bool present; @@ -2820,7 +2820,7 @@ static bool proxy_LookupProperty(JSContext *cx, HandleObject obj, HandlePropertyName name, MutableHandleObject objp, MutableHandleShape propp) { - Rooted id(cx, NameToId(name)); + RootedId id(cx, NameToId(name)); return proxy_LookupGeneric(cx, obj, id, objp, propp); } @@ -2829,7 +2829,7 @@ proxy_LookupElement(JSContext *cx, HandleObject obj, uint32_t index, MutableHandleObject objp, MutableHandleShape propp) { RootedId id(cx); - if (!IndexToId(cx, index, id.address())) + if (!IndexToId(cx, index, &id)) return false; return proxy_LookupGeneric(cx, obj, id, objp, propp); } @@ -2838,7 +2838,7 @@ static bool proxy_LookupSpecial(JSContext *cx, HandleObject obj, HandleSpecialId sid, MutableHandleObject objp, MutableHandleShape propp) { - Rooted id(cx, SPECIALID_TO_JSID(sid)); + RootedId id(cx, SPECIALID_TO_JSID(sid)); return proxy_LookupGeneric(cx, obj, id, objp, propp); } @@ -2869,7 +2869,7 @@ proxy_DefineElement(JSContext *cx, HandleObject obj, uint32_t index, HandleValue PropertyOp getter, StrictPropertyOp setter, unsigned attrs) { RootedId id(cx); - if (!IndexToId(cx, index, id.address())) + if (!IndexToId(cx, index, &id)) return false; return proxy_DefineGeneric(cx, obj, id, value, getter, setter, attrs); } @@ -2902,7 +2902,7 @@ proxy_GetElement(JSContext *cx, HandleObject obj, HandleObject receiver, uint32_ MutableHandleValue vp) { RootedId id(cx); - if (!IndexToId(cx, index, id.address())) + if (!IndexToId(cx, index, &id)) return false; return proxy_GetGeneric(cx, obj, receiver, id, vp); } @@ -2935,7 +2935,7 @@ proxy_SetElement(JSContext *cx, HandleObject obj, uint32_t index, MutableHandleValue vp, bool strict) { RootedId id(cx); - if (!IndexToId(cx, index, id.address())) + if (!IndexToId(cx, index, &id)) return false; return proxy_SetGeneric(cx, obj, id, vp, strict); } @@ -2982,7 +2982,7 @@ proxy_DeleteGeneric(JSContext *cx, HandleObject obj, HandleId id, bool *succeede static bool proxy_DeleteProperty(JSContext *cx, HandleObject obj, HandlePropertyName name, bool *succeeded) { - Rooted id(cx, NameToId(name)); + RootedId id(cx, NameToId(name)); return proxy_DeleteGeneric(cx, obj, id, succeeded); } @@ -2990,7 +2990,7 @@ static bool proxy_DeleteElement(JSContext *cx, HandleObject obj, uint32_t index, bool *succeeded) { RootedId id(cx); - if (!IndexToId(cx, index, id.address())) + if (!IndexToId(cx, index, &id)) return false; return proxy_DeleteGeneric(cx, obj, id, succeeded); } @@ -2998,7 +2998,7 @@ proxy_DeleteElement(JSContext *cx, HandleObject obj, uint32_t index, bool *succe static bool proxy_DeleteSpecial(JSContext *cx, HandleObject obj, HandleSpecialId sid, bool *succeeded) { - Rooted id(cx, SPECIALID_TO_JSID(sid)); + RootedId id(cx, SPECIALID_TO_JSID(sid)); return proxy_DeleteGeneric(cx, obj, id, succeeded); } diff --git a/js/src/vm/ScopeObject.cpp b/js/src/vm/ScopeObject.cpp index 868bd032767b..18dfcf6e6a7a 100644 --- a/js/src/vm/ScopeObject.cpp +++ b/js/src/vm/ScopeObject.cpp @@ -396,7 +396,7 @@ with_LookupElement(JSContext *cx, HandleObject obj, uint32_t index, MutableHandleObject objp, MutableHandleShape propp) { RootedId id(cx); - if (!IndexToId(cx, index, id.address())) + if (!IndexToId(cx, index, &id)) return false; return with_LookupGeneric(cx, obj, id, objp, propp); } @@ -405,7 +405,7 @@ static bool with_LookupSpecial(JSContext *cx, HandleObject obj, HandleSpecialId sid, MutableHandleObject objp, MutableHandleShape propp) { - Rooted id(cx, SPECIALID_TO_JSID(sid)); + RootedId id(cx, SPECIALID_TO_JSID(sid)); return with_LookupGeneric(cx, obj, id, objp, propp); } @@ -421,7 +421,7 @@ static bool with_GetProperty(JSContext *cx, HandleObject obj, HandleObject receiver, HandlePropertyName name, MutableHandleValue vp) { - Rooted id(cx, NameToId(name)); + RootedId id(cx, NameToId(name)); return with_GetGeneric(cx, obj, receiver, id, vp); } @@ -430,7 +430,7 @@ with_GetElement(JSContext *cx, HandleObject obj, HandleObject receiver, uint32_t MutableHandleValue vp) { RootedId id(cx); - if (!IndexToId(cx, index, id.address())) + if (!IndexToId(cx, index, &id)) return false; return with_GetGeneric(cx, obj, receiver, id, vp); } @@ -439,7 +439,7 @@ static bool with_GetSpecial(JSContext *cx, HandleObject obj, HandleObject receiver, HandleSpecialId sid, MutableHandleValue vp) { - Rooted id(cx, SPECIALID_TO_JSID(sid)); + RootedId id(cx, SPECIALID_TO_JSID(sid)); return with_GetGeneric(cx, obj, receiver, id, vp); }