mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-26 12:20:56 +00:00
Bug 1729602 - Remove the magic cx constructor handling in Rooted<TypeConstructibleWithCx> foo(cx);
r=tcampbell,jonco
Differential Revision: https://phabricator.services.mozilla.com/D124994
This commit is contained in:
parent
a546dccdaf
commit
c6e64ca198
@ -1089,12 +1089,6 @@ using RootedPtrTraits =
|
||||
js::RootedTraceableTraits<T>,
|
||||
js::RootedGCThingTraits<T>>;
|
||||
|
||||
// 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<T, Rooted<T>> {
|
||||
return rootLists(RootingContext::get(cx));
|
||||
}
|
||||
|
||||
// Define either one or two Rooted(cx) constructors: the fallback one, which
|
||||
// constructs a Rooted holding a SafelyInitialized<T>, 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 <typename RootingContext>
|
||||
Rooted(const RootingContext& cx, CtorDispatcher, detail::FallbackOverload)
|
||||
: Rooted(cx, SafelyInitialized<T>()) {}
|
||||
|
||||
// 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<std::is_constructible_v<T, RootingContext>>>
|
||||
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 <typename RootingContext>
|
||||
explicit Rooted(const RootingContext& cx)
|
||||
: Rooted(cx, CtorDispatcher(), detail::OverloadSelector()) {}
|
||||
: ptr(SafelyInitialized<T>()) {
|
||||
registerWithRootLists(rootLists(cx));
|
||||
}
|
||||
|
||||
// Provide an initial value.
|
||||
template <typename RootingContext, typename S>
|
||||
Rooted(const RootingContext& cx, S&& initial)
|
||||
: ptr(std::forward<S>(initial)) {
|
||||
|
@ -2495,7 +2495,7 @@ template <XDRMode mode>
|
||||
XDRResult js::XDRExportEntries(XDRState<mode>* xdr,
|
||||
MutableHandleArrayObject vec) {
|
||||
JSContext* cx = xdr->cx();
|
||||
Rooted<GCVector<ExportEntryObject*>> expVec(cx);
|
||||
Rooted<GCVector<ExportEntryObject*>> expVec(cx, cx);
|
||||
RootedExportEntryObject expObj(cx);
|
||||
RootedAtom exportName(cx);
|
||||
RootedModuleRequestObject moduleRequest(cx);
|
||||
|
@ -1631,7 +1631,7 @@ static bool CollectNames(JSContext* cx, HandleLinearString replacement,
|
||||
static bool InitNamedCaptures(JSContext* cx, HandleLinearString replacement,
|
||||
HandleObject groups, size_t firstDollarIndex,
|
||||
MutableHandle<CapturesVector> namedCaptures) {
|
||||
Rooted<GCVector<jsid>> names(cx);
|
||||
Rooted<GCVector<jsid>> names(cx, cx);
|
||||
if (replacement->hasLatin1Chars()) {
|
||||
if (!CollectNames<Latin1Char>(cx, replacement, firstDollarIndex, &names)) {
|
||||
return false;
|
||||
@ -1766,7 +1766,7 @@ bool js::RegExpGetSubstitution(JSContext* cx, HandleArrayObject matchResult,
|
||||
captures.infallibleAppend(StringValue(captureLinear));
|
||||
}
|
||||
|
||||
Rooted<CapturesVector> namedCaptures(cx);
|
||||
Rooted<CapturesVector> namedCaptures(cx, cx);
|
||||
if (groups.isObject()) {
|
||||
RootedObject groupsObj(cx, &groups.toObject());
|
||||
if (!InitNamedCaptures(cx, replacement, groupsObj, firstDollarIndex,
|
||||
|
@ -5235,7 +5235,7 @@ class MOZ_STACK_CLASS Debugger::ScriptQuery : public Debugger::QueryBase {
|
||||
using RealmToScriptMap =
|
||||
GCHashMap<Realm*, BaseScript*, DefaultHasher<Realm*>>;
|
||||
|
||||
Rooted<RealmToScriptMap> innermostForRealm(cx);
|
||||
Rooted<RealmToScriptMap> innermostForRealm(cx, cx);
|
||||
|
||||
// Visit each candidate script and find innermost in each realm.
|
||||
for (BaseScript* script : scriptVector) {
|
||||
|
@ -255,7 +255,7 @@ END_TEST(testGCHandleHashMap)
|
||||
using ShapeVec = GCVector<Shape*>;
|
||||
|
||||
BEGIN_TEST(testGCRootedVector) {
|
||||
JS::Rooted<ShapeVec> shapes(cx);
|
||||
JS::Rooted<ShapeVec> shapes(cx, cx);
|
||||
|
||||
for (size_t i = 0; i < 10; ++i) {
|
||||
RootedObject obj(cx, JS_NewObject(cx, nullptr));
|
||||
|
@ -500,7 +500,7 @@ JSLinearString* ModuleLoader::normalizePath(JSContext* cx,
|
||||
#endif // XP_WIN
|
||||
|
||||
// Normalize the path by removing redundant path components.
|
||||
Rooted<GCVector<JSLinearString*>> components(cx);
|
||||
Rooted<GCVector<JSLinearString*>> components(cx, cx);
|
||||
size_t lastSep = 0;
|
||||
while (lastSep < path->length()) {
|
||||
int32_t i = IndexOf(path, PathSeparator, lastSep);
|
||||
|
Loading…
x
Reference in New Issue
Block a user