From 19022b5f4a82c3c3d32f450dce812bb1edd714af Mon Sep 17 00:00:00 2001 From: Terrence Cole Date: Wed, 5 Aug 2015 11:02:00 -0700 Subject: [PATCH] Bug 1191529 - Remove JSIdArray and AutoIdArray and replace with Rooted; r=mccr8, r=jonco * * * imported patch 2_remove_AutoIdArray_gk --- dom/bindings/Codegen.py | 4 +- dom/geolocation/nsGeolocationSettings.cpp | 4 +- dom/plugins/base/nsJSNPRuntime.cpp | 4 +- js/ipc/JavaScriptShared.cpp | 4 +- js/public/TracingAPI.h | 58 ++++++++++++--------- js/src/NamespaceImports.h | 12 ++--- js/src/ctypes/CTypes.cpp | 8 +-- js/src/gc/RootMarking.cpp | 13 ----- js/src/jsapi.cpp | 34 +++---------- js/src/jsapi.h | 62 +---------------------- js/src/jsatom.h | 10 ---- js/src/jsiter.cpp | 19 ------- js/src/jsiter.h | 3 -- js/src/jspubtd.h | 2 - js/src/shell/js.cpp | 4 +- js/xpconnect/src/XPCComponents.cpp | 4 +- js/xpconnect/src/XPCWrappedJSClass.cpp | 4 +- widget/android/NativeJSContainer.cpp | 5 +- 18 files changed, 69 insertions(+), 185 deletions(-) diff --git a/dom/bindings/Codegen.py b/dom/bindings/Codegen.py index 5747bff374a8..c43079f568da 100644 --- a/dom/bindings/Codegen.py +++ b/dom/bindings/Codegen.py @@ -4516,8 +4516,8 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None, ${mozMapType} &mozMap = ${mozMapRef}; JS::Rooted mozMapObj(cx, &$${val}.toObject()); - JS::AutoIdArray ids(cx, JS_Enumerate(cx, mozMapObj)); - if (!ids) { + JS::Rooted ids(cx, JS::IdVector(cx)); + if (!JS_Enumerate(cx, mozMapObj, &ids)) { $*{exceptionCode} } JS::Rooted propNameValue(cx); diff --git a/dom/geolocation/nsGeolocationSettings.cpp b/dom/geolocation/nsGeolocationSettings.cpp index f8a0ac19a27a..cbc335294bb7 100644 --- a/dom/geolocation/nsGeolocationSettings.cpp +++ b/dom/geolocation/nsGeolocationSettings.cpp @@ -245,10 +245,10 @@ nsGeolocationSettings::HandleGeolocationPerOriginSettingsChange(const JS::Value& AutoEntryScript aes(global, "geolocation.app_settings enumeration"); aes.TakeOwnershipOfErrorReporting(); JSContext *cx = aes.cx(); - JS::AutoIdArray ids(cx, JS_Enumerate(cx, obj)); + JS::Rooted ids(cx, JS::IdVector(cx)); // if we get no ids then the exception list is empty and we can return here. - if (!ids) { + if (!JS_Enumerate(cx, obj, &ids)) { return; } diff --git a/dom/plugins/base/nsJSNPRuntime.cpp b/dom/plugins/base/nsJSNPRuntime.cpp index 50b3069610b8..7357ca63035c 100644 --- a/dom/plugins/base/nsJSNPRuntime.cpp +++ b/dom/plugins/base/nsJSNPRuntime.cpp @@ -1032,8 +1032,8 @@ nsJSObjWrapper::NP_Enumerate(NPObject *npobj, NPIdentifier **idarray, JS::Rooted jsobj(cx, npjsobj->mJSObj); JSAutoCompartment ac(cx, jsobj); - JS::AutoIdArray ida(cx, JS_Enumerate(cx, jsobj)); - if (!ida) { + JS::Rooted ida(cx, JS::IdVector(cx)); + if (!JS_Enumerate(cx, jsobj, &ida)) { return false; } diff --git a/js/ipc/JavaScriptShared.cpp b/js/ipc/JavaScriptShared.cpp index 0cf825ce71ef..729f48f155be 100644 --- a/js/ipc/JavaScriptShared.cpp +++ b/js/ipc/JavaScriptShared.cpp @@ -729,8 +729,8 @@ JavaScriptShared::Wrap(JSContext* cx, HandleObject aObj, InfallibleTArray ids(cx, IdVector(cx)); + if (!JS_Enumerate(cx, aObj, &ids)) return false; RootedId id(cx); diff --git a/js/public/TracingAPI.h b/js/public/TracingAPI.h index e9ee438eedd1..280cf18fec76 100644 --- a/js/public/TracingAPI.h +++ b/js/public/TracingAPI.h @@ -259,31 +259,6 @@ JSTracer::asCallbackTracer() return static_cast(this); } -namespace js { - -// Automates static dispatch for tracing for TraceableContainers. -template struct DefaultTracer; - -// The default for POD, non-pointer types is to do nothing. -template -struct DefaultTracer::value && - mozilla::IsPod::value>::Type> { - static void trace(JSTracer* trc, T* t, const char* name) { - MOZ_ASSERT(mozilla::IsPod::value); - MOZ_ASSERT(!mozilla::IsPointer::value); - } -}; - -// The default for non-pod (e.g. struct) types is to call the trace method. -template -struct DefaultTracer::value>::Type> { - static void trace(JSTracer* trc, T* t, const char* name) { - t->trace(trc); - } -}; - -} // namespace js - // The JS_Call*Tracer family of functions traces the given GC thing reference. // This performs the tracing action configured on the given JSTracer: // typically calling the JSTracer::callback or marking the thing as live. @@ -366,4 +341,37 @@ extern JS_PUBLIC_API(void) JS_GetTraceThingInfo(char* buf, size_t bufsize, JSTracer* trc, void* thing, JS::TraceKind kind, bool includeDetails); +namespace js { + +// Automates static dispatch for tracing for TraceableContainers. +template struct DefaultTracer; + +// The default for POD, non-pointer types is to do nothing. +template +struct DefaultTracer::value && + mozilla::IsPod::value>::Type> { + static void trace(JSTracer* trc, T* t, const char* name) { + MOZ_ASSERT(mozilla::IsPod::value); + MOZ_ASSERT(!mozilla::IsPointer::value); + } +}; + +// The default for non-pod (e.g. struct) types is to call the trace method. +template +struct DefaultTracer::value>::Type> { + static void trace(JSTracer* trc, T* t, const char* name) { + t->trace(trc); + } +}; + +template <> +struct DefaultTracer +{ + static void trace(JSTracer* trc, jsid* id, const char* name) { + JS_CallUnbarrieredIdTracer(trc, id, name); + } +}; + +} // namespace js + #endif /* js_TracingAPI_h */ diff --git a/js/src/NamespaceImports.h b/js/src/NamespaceImports.h index 3319e137818f..c6a962340927 100644 --- a/js/src/NamespaceImports.h +++ b/js/src/NamespaceImports.h @@ -36,7 +36,9 @@ typedef AutoVectorRooter AutoIdVector; typedef AutoVectorRooter AutoObjectVector; typedef AutoVectorRooter AutoVector; -class AutoIdArray; +using ValueVector = js::TraceableVector; +using IdVector = js::TraceableVector; +using ScriptVector = js::TraceableVector; template class AutoVectorRooter; template class AutoHashMapRooter; @@ -82,11 +84,9 @@ typedef AutoVectorRooter AutoIdVector; typedef AutoVectorRooter AutoObjectVector; typedef AutoVectorRooter AutoScriptVector; -using ValueVector = TraceableVector; -using IdVector = TraceableVector; -using ScriptVector = TraceableVector; - -using JS::AutoIdArray; +using JS::ValueVector; +using JS::IdVector; +using JS::ScriptVector; using JS::AutoHashMapRooter; using JS::AutoHashSetRooter; diff --git a/js/src/ctypes/CTypes.cpp b/js/src/ctypes/CTypes.cpp index e4c0874857e9..924eb15a302d 100644 --- a/js/src/ctypes/CTypes.cpp +++ b/js/src/ctypes/CTypes.cpp @@ -3261,8 +3261,8 @@ ImplicitConvert(JSContext* cx, if (val.isObject() && !sourceData) { // Enumerate the properties of the object; if they match the struct // specification, convert the fields. - AutoIdArray props(cx, JS_Enumerate(cx, valObj)); - if (!props) + Rooted props(cx, IdVector(cx)); + if (!JS_Enumerate(cx, valObj, &props)) return false; // Convert into an intermediate, in case of failure. @@ -5343,8 +5343,8 @@ ExtractStructField(JSContext* cx, Value val, MutableHandleObject typeObj) } RootedObject obj(cx, &val.toObject()); - AutoIdArray props(cx, JS_Enumerate(cx, obj)); - if (!props) + Rooted props(cx, IdVector(cx)); + if (!JS_Enumerate(cx, obj, &props)) return nullptr; // make sure we have one, and only one, property diff --git a/js/src/gc/RootMarking.cpp b/js/src/gc/RootMarking.cpp index aa9466746a3d..299812cb341a 100644 --- a/js/src/gc/RootMarking.cpp +++ b/js/src/gc/RootMarking.cpp @@ -82,13 +82,6 @@ MarkExactStackRoots(JSRuntime* rt, JSTracer* trc) MarkExactStackRootsAcrossTypes(&rt->mainThread, trc); } -void -JS::AutoIdArray::trace(JSTracer* trc) -{ - MOZ_ASSERT(tag_ == IDARRAY); - TraceRange(trc, idArray->length, idArray->begin(), "JSAutoIdArray.idArray"); -} - inline void AutoGCRooter::trace(JSTracer* trc) { @@ -97,12 +90,6 @@ AutoGCRooter::trace(JSTracer* trc) frontend::MarkParser(trc, this); return; - case IDARRAY: { - JSIdArray* ida = static_cast(this)->idArray; - TraceRange(trc, ida->length, ida->begin(), "JS::AutoIdArray.idArray"); - return; - } - case VALVECTOR: { AutoValueVector::VectorImpl& vector = static_cast(this)->vector; TraceRootRange(trc, vector.length(), vector.begin(), "JS::AutoValueVector.vector"); diff --git a/js/src/jsapi.cpp b/js/src/jsapi.cpp index 0c304e848fcc..4e2a7046a905 100644 --- a/js/src/jsapi.cpp +++ b/js/src/jsapi.cpp @@ -1765,25 +1765,6 @@ JS_SetNativeStackQuota(JSRuntime* rt, size_t systemCodeStackSize, size_t trusted /************************************************************************/ -JS_PUBLIC_API(int) -JS_IdArrayLength(JSContext* cx, JSIdArray* ida) -{ - return ida->length; -} - -JS_PUBLIC_API(jsid) -JS_IdArrayGet(JSContext* cx, JSIdArray* ida, unsigned index) -{ - MOZ_ASSERT(index < unsigned(ida->length)); - return ida->vector[index]; -} - -JS_PUBLIC_API(void) -JS_DestroyIdArray(JSContext* cx, JSIdArray* ida) -{ - cx->runtime()->defaultFreeOp()->free_(ida); -} - JS_PUBLIC_API(bool) JS_ValueToId(JSContext* cx, HandleValue value, MutableHandleId idp) { @@ -3166,18 +3147,19 @@ JS_SetAllNonReservedSlotsToUndefined(JSContext* cx, JSObject* objArg) obj->as().setSlot(i, UndefinedValue()); } -JS_PUBLIC_API(JSIdArray*) -JS_Enumerate(JSContext* cx, HandleObject obj) +JS_PUBLIC_API(bool) +JS_Enumerate(JSContext* cx, HandleObject obj, JS::MutableHandle props) { AssertHeapIsIdle(cx); CHECK_REQUEST(cx); assertSameCompartment(cx, obj); + MOZ_ASSERT(props.empty()); - AutoIdVector props(cx); - JSIdArray* ida; - if (!GetPropertyKeys(cx, obj, JSITER_OWNONLY, &props) || !VectorToIdArray(cx, props, &ida)) - return nullptr; - return ida; + AutoIdVector ids(cx); + if (!GetPropertyKeys(cx, obj, JSITER_OWNONLY, &ids)) + return false; + + return props.append(ids.begin(), ids.end()); } JS_PUBLIC_API(Value) diff --git a/js/src/jsapi.h b/js/src/jsapi.h index feb7773a98e4..7efdbce59bc7 100644 --- a/js/src/jsapi.h +++ b/js/src/jsapi.h @@ -1867,64 +1867,6 @@ JS_SetNativeStackQuota(JSRuntime* cx, size_t systemCodeStackSize, /************************************************************************/ -extern JS_PUBLIC_API(int) -JS_IdArrayLength(JSContext* cx, JSIdArray* ida); - -extern JS_PUBLIC_API(jsid) -JS_IdArrayGet(JSContext* cx, JSIdArray* ida, unsigned index); - -extern JS_PUBLIC_API(void) -JS_DestroyIdArray(JSContext* cx, JSIdArray* ida); - -namespace JS { - -class AutoIdArray : private AutoGCRooter -{ - public: - AutoIdArray(JSContext* cx, JSIdArray* ida - MOZ_GUARD_OBJECT_NOTIFIER_PARAM) - : AutoGCRooter(cx, IDARRAY), context(cx), idArray(ida) - { - MOZ_GUARD_OBJECT_NOTIFIER_INIT; - } - ~AutoIdArray() { - if (idArray) - JS_DestroyIdArray(context, idArray); - } - bool operator!() const { - return !idArray; - } - jsid operator[](size_t i) const { - MOZ_ASSERT(idArray); - return JS_IdArrayGet(context, idArray, unsigned(i)); - } - size_t length() const { - return JS_IdArrayLength(context, idArray); - } - - friend void AutoGCRooter::trace(JSTracer* trc); - - JSIdArray* steal() { - JSIdArray* copy = idArray; - idArray = nullptr; - return copy; - } - - protected: - inline void trace(JSTracer* trc); - - private: - JSContext* context; - JSIdArray* idArray; - MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER - - /* No copy or assignment semantics. */ - AutoIdArray(AutoIdArray& ida) = delete; - void operator=(AutoIdArray& ida) = delete; -}; - -} /* namespace JS */ - extern JS_PUBLIC_API(bool) JS_ValueToId(JSContext* cx, JS::HandleValue v, JS::MutableHandleId idp); @@ -3151,8 +3093,8 @@ JS_CreateMappedArrayBufferContents(int fd, size_t offset, size_t length); extern JS_PUBLIC_API(void) JS_ReleaseMappedArrayBufferContents(void* contents, size_t length); -extern JS_PUBLIC_API(JSIdArray*) -JS_Enumerate(JSContext* cx, JS::HandleObject obj); +extern JS_PUBLIC_API(bool) +JS_Enumerate(JSContext* cx, JS::HandleObject obj, JS::MutableHandle props); extern JS_PUBLIC_API(JS::Value) JS_GetReservedSlot(JSObject* obj, uint32_t index); diff --git a/js/src/jsatom.h b/js/src/jsatom.h index 460574fe00bc..6fce99f5ccf5 100644 --- a/js/src/jsatom.h +++ b/js/src/jsatom.h @@ -19,16 +19,6 @@ class JSAtom; class JSAutoByteString; -struct JSIdArray { - int length; - js::HeapId vector[1]; /* actually, length jsid words */ - - js::HeapId* begin() { return vector; } - const js::HeapId* begin() const { return vector; } - js::HeapId* end() { return vector + length; } - const js::HeapId* end() const { return vector + length; } -}; - namespace js { JS_STATIC_ASSERT(sizeof(HashNumber) == 4); diff --git a/js/src/jsiter.cpp b/js/src/jsiter.cpp index 46b129ead6ad..9c55fe06383c 100644 --- a/js/src/jsiter.cpp +++ b/js/src/jsiter.cpp @@ -395,25 +395,6 @@ Snapshot(JSContext* cx, HandleObject pobj_, unsigned flags, AutoIdVector* props) return true; } -bool -js::VectorToIdArray(JSContext* cx, AutoIdVector& props, JSIdArray** idap) -{ - JS_STATIC_ASSERT(sizeof(JSIdArray) > sizeof(jsid)); - size_t len = props.length(); - size_t idsz = len * sizeof(jsid); - size_t sz = (sizeof(JSIdArray) - sizeof(jsid)) + idsz; - JSIdArray* ida = reinterpret_cast(cx->zone()->pod_malloc(sz)); - if (!ida) - return false; - - ida->length = static_cast(len); - jsid* v = props.begin(); - for (int i = 0; i < ida->length; i++) - ida->vector[i].init(v[i]); - *idap = ida; - return true; -} - JS_FRIEND_API(bool) js::GetPropertyKeys(JSContext* cx, HandleObject obj, unsigned flags, AutoIdVector* props) { diff --git a/js/src/jsiter.h b/js/src/jsiter.h index 244eeea5c13c..1ed88bbc1efc 100644 --- a/js/src/jsiter.h +++ b/js/src/jsiter.h @@ -146,9 +146,6 @@ class StringIteratorObject : public JSObject static const Class class_; }; -bool -VectorToIdArray(JSContext* cx, AutoIdVector& props, JSIdArray** idap); - bool GetIterator(JSContext* cx, HandleObject obj, unsigned flags, MutableHandleObject objp); diff --git a/js/src/jspubtd.h b/js/src/jspubtd.h index 7a22a92cdf03..c27f01bb4f5c 100644 --- a/js/src/jspubtd.h +++ b/js/src/jspubtd.h @@ -93,7 +93,6 @@ struct JSCrossCompartmentCall; class JSErrorReport; struct JSExceptionState; struct JSFunctionSpec; -struct JSIdArray; struct JSLocaleCallbacks; struct JSObjectMap; struct JSPrincipals; @@ -218,7 +217,6 @@ class JS_PUBLIC_API(AutoGCRooter) enum { VALARRAY = -2, /* js::AutoValueArray */ PARSER = -3, /* js::frontend::Parser */ - IDARRAY = -6, /* js::AutoIdArray */ VALVECTOR = -10, /* js::AutoValueVector */ IDVECTOR = -11, /* js::AutoIdVector */ OBJVECTOR = -14, /* js::AutoObjectVector */ diff --git a/js/src/shell/js.cpp b/js/src/shell/js.cpp index 88b6b6d6e6a2..7b3037f8dbd3 100644 --- a/js/src/shell/js.cpp +++ b/js/src/shell/js.cpp @@ -4954,8 +4954,8 @@ Help(JSContext* cx, unsigned argc, Value* vp) RootedObject obj(cx); if (args.length() == 0) { RootedObject global(cx, JS::CurrentGlobalOrNull(cx)); - AutoIdArray ida(cx, JS_Enumerate(cx, global)); - if (!ida) + Rooted ida(cx, IdVector(cx)); + if (!JS_Enumerate(cx, global, &ida)) return false; for (size_t i = 0; i < ida.length(); i++) { diff --git a/js/xpconnect/src/XPCComponents.cpp b/js/xpconnect/src/XPCComponents.cpp index 511a6eebcca4..3093304e2799 100644 --- a/js/xpconnect/src/XPCComponents.cpp +++ b/js/xpconnect/src/XPCComponents.cpp @@ -2836,8 +2836,8 @@ nsXPCComponents_Utils::MakeObjectPropsNormal(HandleValue vobj, JSContext* cx) RootedObject obj(cx, js::UncheckedUnwrap(&vobj.toObject())); JSAutoCompartment ac(cx, obj); - AutoIdArray ida(cx, JS_Enumerate(cx, obj)); - if (!ida) + Rooted ida(cx, IdVector(cx)); + if (!JS_Enumerate(cx, obj, &ida)) return NS_ERROR_FAILURE; RootedId id(cx); diff --git a/js/xpconnect/src/XPCWrappedJSClass.cpp b/js/xpconnect/src/XPCWrappedJSClass.cpp index 20ff5d16ee3b..96fb02854168 100644 --- a/js/xpconnect/src/XPCWrappedJSClass.cpp +++ b/js/xpconnect/src/XPCWrappedJSClass.cpp @@ -357,8 +357,8 @@ nsXPCWrappedJSClass::BuildPropertyEnumerator(XPCCallContext& ccx, if (!scriptEval.StartEvaluating(aJSObj)) return NS_ERROR_FAILURE; - AutoIdArray idArray(cx, JS_Enumerate(cx, aJSObj)); - if (!idArray) + Rooted idArray(cx, IdVector(cx)); + if (!JS_Enumerate(cx, aJSObj, &idArray)) return NS_ERROR_FAILURE; nsCOMArray propertyArray(idArray.length()); diff --git a/widget/android/NativeJSContainer.cpp b/widget/android/NativeJSContainer.cpp index b6e2d2091b5c..ea773a34a5fa 100644 --- a/widget/android/NativeJSContainer.cpp +++ b/widget/android/NativeJSContainer.cpp @@ -262,9 +262,8 @@ class NativeJSContainerImpl final sdk::Bundle::LocalRef BundleFromValue(const JS::HandleObject obj) { - const JS::AutoIdArray ids(mJSContext, - JS_Enumerate(mJSContext, obj)); - if (!CheckJSCall(!!ids)) { + JS::Rooted ids(mJSContext, JS::IdVector(mJSContext)); + if (!CheckJSCall(JS_Enumerate(mJSContext, obj, &ids))) { return nullptr; }