diff --git a/js/public/RootingAPI.h b/js/public/RootingAPI.h index d19c63fec854..d570817d36c7 100644 --- a/js/public/RootingAPI.h +++ b/js/public/RootingAPI.h @@ -1089,12 +1089,6 @@ using RootedPtrTraits = js::RootedTraceableTraits, js::RootedGCThingTraits>; -// Dummy types to make it easier to understand template overload preference -// ordering. -struct FallbackOverload {}; -struct PreferredOverload : FallbackOverload {}; -using OverloadSelector = PreferredOverload; - } /* namespace detail */ /** @@ -1123,38 +1117,17 @@ class MOZ_RAII Rooted : public js::RootedBase> { return rootLists(RootingContext::get(cx)); } - // Define either one or two Rooted(cx) constructors: the fallback one, which - // constructs a Rooted holding a SafelyInitialized, and a convenience one - // for types that can be constructed with a cx, which will give a Rooted - // holding a T(cx). - - // Dummy type to distinguish these constructors from Rooted(cx, initial) - struct CtorDispatcher {}; - - // Normal case: construct an empty Rooted holding a safely initialized but - // empty T. - template - Rooted(const RootingContext& cx, CtorDispatcher, detail::FallbackOverload) - : Rooted(cx, SafelyInitialized()) {} - - // If T can be constructed with a cx, then define another constructor for it - // that will be preferred. - template < - typename RootingContext, - typename = std::enable_if_t>> - Rooted(const RootingContext& cx, CtorDispatcher, detail::PreferredOverload) - : Rooted(cx, T(cx)) {} - public: using ElementType = T; - // Construct an empty Rooted. Delegates to an internal constructor that - // chooses a specific meaning of "empty" depending on whether T can be - // constructed with a cx. + // Construct an empty Rooted holding a safely initialized but empty T. template explicit Rooted(const RootingContext& cx) - : Rooted(cx, CtorDispatcher(), detail::OverloadSelector()) {} + : ptr(SafelyInitialized()) { + registerWithRootLists(rootLists(cx)); + } + // Provide an initial value. template Rooted(const RootingContext& cx, S&& initial) : ptr(std::forward(initial)) { diff --git a/js/src/builtin/ModuleObject.cpp b/js/src/builtin/ModuleObject.cpp index 1272ecd3103a..647d955a5dee 100644 --- a/js/src/builtin/ModuleObject.cpp +++ b/js/src/builtin/ModuleObject.cpp @@ -2495,7 +2495,7 @@ template XDRResult js::XDRExportEntries(XDRState* xdr, MutableHandleArrayObject vec) { JSContext* cx = xdr->cx(); - Rooted> expVec(cx); + Rooted> expVec(cx, cx); RootedExportEntryObject expObj(cx); RootedAtom exportName(cx); RootedModuleRequestObject moduleRequest(cx); diff --git a/js/src/builtin/RegExp.cpp b/js/src/builtin/RegExp.cpp index 504cf4d5030c..a56e15eba4f9 100644 --- a/js/src/builtin/RegExp.cpp +++ b/js/src/builtin/RegExp.cpp @@ -1631,7 +1631,7 @@ static bool CollectNames(JSContext* cx, HandleLinearString replacement, static bool InitNamedCaptures(JSContext* cx, HandleLinearString replacement, HandleObject groups, size_t firstDollarIndex, MutableHandle namedCaptures) { - Rooted> names(cx); + Rooted> names(cx, cx); if (replacement->hasLatin1Chars()) { if (!CollectNames(cx, replacement, firstDollarIndex, &names)) { return false; @@ -1766,7 +1766,7 @@ bool js::RegExpGetSubstitution(JSContext* cx, HandleArrayObject matchResult, captures.infallibleAppend(StringValue(captureLinear)); } - Rooted namedCaptures(cx); + Rooted namedCaptures(cx, cx); if (groups.isObject()) { RootedObject groupsObj(cx, &groups.toObject()); if (!InitNamedCaptures(cx, replacement, groupsObj, firstDollarIndex, diff --git a/js/src/debugger/Debugger.cpp b/js/src/debugger/Debugger.cpp index 52e846842ecb..3a80db20a5ae 100644 --- a/js/src/debugger/Debugger.cpp +++ b/js/src/debugger/Debugger.cpp @@ -5235,7 +5235,7 @@ class MOZ_STACK_CLASS Debugger::ScriptQuery : public Debugger::QueryBase { using RealmToScriptMap = GCHashMap>; - Rooted innermostForRealm(cx); + Rooted innermostForRealm(cx, cx); // Visit each candidate script and find innermost in each realm. for (BaseScript* script : scriptVector) { diff --git a/js/src/jsapi-tests/testGCExactRooting.cpp b/js/src/jsapi-tests/testGCExactRooting.cpp index f7a10e00e6bd..6481e84026c2 100644 --- a/js/src/jsapi-tests/testGCExactRooting.cpp +++ b/js/src/jsapi-tests/testGCExactRooting.cpp @@ -255,7 +255,7 @@ END_TEST(testGCHandleHashMap) using ShapeVec = GCVector; BEGIN_TEST(testGCRootedVector) { - JS::Rooted shapes(cx); + JS::Rooted shapes(cx, cx); for (size_t i = 0; i < 10; ++i) { RootedObject obj(cx, JS_NewObject(cx, nullptr)); diff --git a/js/src/shell/ModuleLoader.cpp b/js/src/shell/ModuleLoader.cpp index c7da361fa500..8aa6fd0b2c6c 100644 --- a/js/src/shell/ModuleLoader.cpp +++ b/js/src/shell/ModuleLoader.cpp @@ -500,7 +500,7 @@ JSLinearString* ModuleLoader::normalizePath(JSContext* cx, #endif // XP_WIN // Normalize the path by removing redundant path components. - Rooted> components(cx); + Rooted> components(cx, cx); size_t lastSep = 0; while (lastSep < path->length()) { int32_t i = IndexOf(path, PathSeparator, lastSep);