Backed out 4 changesets (bug 1729602) for causing build bustages on RootingAPI.h. CLOSED TREE

Backed out changeset ba1ba9d974a4 (bug 1729602)
Backed out changeset 0f06d31a9008 (bug 1729602)
Backed out changeset cf7f13072e9f (bug 1729602)
Backed out changeset b277bca3bfe1 (bug 1729602)
This commit is contained in:
Marian-Vasile Laza 2021-09-14 01:24:35 +03:00
Родитель 1aeed2512d
Коммит 53d94ff3fb
6 изменённых файлов: 68 добавлений и 173 удалений

Просмотреть файл

@ -884,11 +884,7 @@ struct RootedTraceable final : public VirtualTraceable {
T ptr;
template <typename... CtorArgs>
explicit RootedTraceable(std::in_place_t, CtorArgs... args)
: ptr(std::forward<CtorArgs>(args)...) {}
template <typename U, typename = typename std::is_constructible<T, U>::type>
template <typename U>
MOZ_IMPLICIT RootedTraceable(U&& initial) : ptr(std::forward<U>(initial)) {}
operator T&() { return ptr; }
@ -1082,19 +1078,23 @@ class MOZ_RAII JS_PUBLIC_API CustomAutoRooter : private AutoGCRooter {
namespace detail {
template <typename T>
constexpr bool IsTraceable_v =
MapTypeToRootKind<T>::kind == JS::RootKind::Traceable;
template <typename T>
using RootedPtr =
std::conditional_t<IsTraceable_v<T>, js::RootedTraceable<T>, T>;
std::conditional_t<MapTypeToRootKind<T>::kind == JS::RootKind::Traceable,
js::RootedTraceable<T>, T>;
template <typename T>
using RootedPtrTraits =
std::conditional_t<IsTraceable_v<T>, js::RootedTraceableTraits<T>,
std::conditional_t<MapTypeToRootKind<T>::kind == JS::RootKind::Traceable,
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,49 +1123,45 @@ 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 holding a safely initialized but empty T.
// Requires T to have a copy constructor in order to copy the safely
// initialized value.
//
// Note that for SFINAE to reject this method, the 2nd template parameter must
// depend on RootingContext somehow even though we really only care about T.
template <typename RootingContext,
typename =
std::enable_if_t<std::is_copy_constructible_v<T>, RootingContext>>
explicit Rooted(const RootingContext& cx) : ptr(SafelyInitialized<T>()) {
registerWithRootLists(rootLists(cx));
}
// 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.
template <typename RootingContext>
explicit Rooted(const RootingContext& cx)
: Rooted(cx, CtorDispatcher(), detail::OverloadSelector()) {}
// Provide an initial value. Requires T to be constructible from the given
// argument.
template <typename RootingContext, typename S,
typename = typename std::is_constructible<T, S>::type>
template <typename RootingContext, typename S>
Rooted(const RootingContext& cx, S&& initial)
: ptr(std::forward<S>(initial)) {
MOZ_ASSERT(GCPolicy<T>::isValid(ptr));
registerWithRootLists(rootLists(cx));
}
// (Traceables only) Construct the contained value from the given arguments.
// Constructs in-place, so T does not need to be copyable or movable.
//
// Note that a copyable Traceable passed only a RootingContext will
// choose the above SafelyInitialized<T> constructor, because otherwise
// identical functions with parameter packs are considered less specialized.
//
// The SFINAE type must again depend on an inferred template parameter.
template <
typename RootingContext, typename... CtorArgs,
typename = std::enable_if_t<detail::IsTraceable_v<T>, RootingContext>>
explicit Rooted(const RootingContext& cx, CtorArgs... args)
: ptr(std::in_place, std::forward<CtorArgs>(args)...) {
MOZ_ASSERT(GCPolicy<T>::isValid(ptr));
registerWithRootLists(rootLists(cx));
}
~Rooted() {
MOZ_ASSERT(*stack ==
reinterpret_cast<Rooted<detail::RootListEntry*>*>(this));
@ -1402,37 +1398,37 @@ class PersistentRooted
reinterpret_cast<JS::PersistentRooted<detail::RootListEntry*>*>(this));
}
// Used when JSContext type is incomplete and so it is not known to inherit
// from RootingContext.
void registerWithRootLists(JSContext* cx) {
registerWithRootLists(RootingContext::get(cx));
}
public:
using ElementType = T;
PersistentRooted() : ptr(SafelyInitialized<T>()) {}
template <typename RootHolder, typename = std::enable_if_t<
std::is_copy_constructible_v<T>, RootHolder>>
explicit PersistentRooted(const RootHolder& cx)
: ptr(SafelyInitialized<T>()) {
explicit PersistentRooted(RootingContext* cx) : ptr(SafelyInitialized<T>()) {
registerWithRootLists(cx);
}
template <
typename RootHolder, typename U,
typename = std::enable_if_t<std::is_constructible_v<T, U>, RootHolder>>
PersistentRooted(const RootHolder& cx, U&& initial)
explicit PersistentRooted(JSContext* cx) : ptr(SafelyInitialized<T>()) {
registerWithRootLists(RootingContext::get(cx));
}
template <typename U>
PersistentRooted(RootingContext* cx, U&& initial)
: ptr(std::forward<U>(initial)) {
registerWithRootLists(cx);
}
template <typename RootHolder, typename... CtorArgs,
typename = std::enable_if_t<detail::IsTraceable_v<T>, RootHolder>>
PersistentRooted(const RootHolder& cx, CtorArgs... args)
: ptr(std::in_place, std::forward<CtorArgs>(args)...) {
registerWithRootLists(cx);
template <typename U>
PersistentRooted(JSContext* cx, U&& initial) : ptr(std::forward<U>(initial)) {
registerWithRootLists(RootingContext::get(cx));
}
explicit PersistentRooted(JSRuntime* rt) : ptr(SafelyInitialized<T>()) {
registerWithRootLists(rt);
}
template <typename U>
PersistentRooted(JSRuntime* rt, U&& initial) : ptr(std::forward<U>(initial)) {
registerWithRootLists(rt);
}
PersistentRooted(const PersistentRooted& rhs)

Просмотреть файл

@ -2495,7 +2495,7 @@ template <XDRMode mode>
XDRResult js::XDRExportEntries(XDRState<mode>* xdr,
MutableHandleArrayObject vec) {
JSContext* cx = xdr->cx();
Rooted<GCVector<ExportEntryObject*>> expVec(cx, cx);
Rooted<GCVector<ExportEntryObject*>> expVec(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, cx);
Rooted<GCVector<jsid>> names(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, cx);
Rooted<CapturesVector> namedCaptures(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, cx);
Rooted<RealmToScriptMap> innermostForRealm(cx);
// Visit each candidate script and find innermost in each realm.
for (BaseScript* script : scriptVector) {

Просмотреть файл

@ -47,49 +47,13 @@ BEGIN_TEST(testGCSuppressions) {
END_TEST(testGCSuppressions)
struct MyContainer {
int whichConstructor;
HeapPtr<JSObject*> obj;
HeapPtr<JSString*> str;
MyContainer() : whichConstructor(1), obj(nullptr), str(nullptr) {}
explicit MyContainer(double) : MyContainer() { whichConstructor = 2; }
explicit MyContainer(JSContext* cx) : MyContainer() { whichConstructor = 3; }
MyContainer(JSContext* cx, JSContext* cx2, JSContext* cx3) : MyContainer() {
whichConstructor = 4;
}
MyContainer(const MyContainer& rhs)
: whichConstructor(100 + rhs.whichConstructor),
obj(rhs.obj),
str(rhs.str) {}
MyContainer() : obj(nullptr), str(nullptr) {}
void trace(JSTracer* trc) {
js::TraceNullableEdge(trc, &obj, "test container obj");
js::TraceNullableEdge(trc, &str, "test container str");
}
};
struct MyNonCopyableContainer {
int whichConstructor;
HeapPtr<JSObject*> obj;
HeapPtr<JSString*> str;
MyNonCopyableContainer() : whichConstructor(1), obj(nullptr), str(nullptr) {}
explicit MyNonCopyableContainer(double) : MyNonCopyableContainer() {
whichConstructor = 2;
}
explicit MyNonCopyableContainer(JSContext* cx) : MyNonCopyableContainer() {
whichConstructor = 3;
}
explicit MyNonCopyableContainer(JSContext* cx, JSContext* cx2, JSContext* cx3)
: MyNonCopyableContainer() {
whichConstructor = 4;
}
MyNonCopyableContainer(const MyNonCopyableContainer&) = delete;
MyNonCopyableContainer& operator=(const MyNonCopyableContainer&) = delete;
void trace(JSTracer* trc) {
js::TraceNullableEdge(trc, &obj, "test container obj");
js::TraceNullableEdge(trc, &str, "test container str");
js::TraceNullableEdge(trc, &obj, "test container");
js::TraceNullableEdge(trc, &str, "test container");
}
};
@ -98,51 +62,10 @@ template <typename Wrapper>
struct MutableWrappedPtrOperations<MyContainer, Wrapper> {
HeapPtr<JSObject*>& obj() { return static_cast<Wrapper*>(this)->get().obj; }
HeapPtr<JSString*>& str() { return static_cast<Wrapper*>(this)->get().str; }
int constructor() {
return static_cast<Wrapper*>(this)->get().whichConstructor;
}
};
template <typename Wrapper>
struct MutableWrappedPtrOperations<MyNonCopyableContainer, Wrapper> {
HeapPtr<JSObject*>& obj() { return static_cast<Wrapper*>(this)->get().obj; }
HeapPtr<JSString*>& str() { return static_cast<Wrapper*>(this)->get().str; }
int constructor() {
return static_cast<Wrapper*>(this)->get().whichConstructor;
}
};
} // namespace js
BEGIN_TEST(testGCRootedStaticStructInternalStackStorageAugmented) {
// Test Rooted constructors for a copyable type.
JS::Rooted<MyContainer> r1(cx);
JS::Rooted<MyContainer> r2(cx, 3.4);
JS::Rooted<MyContainer> r3(cx, MyContainer(cx));
JS::Rooted<MyContainer> r4(cx, cx);
JS::Rooted<MyContainer> r5(cx, cx, cx, cx);
JS::Rooted<Value> rv(cx);
CHECK_EQUAL(r1.constructor(), 101); // copy of SafelyInitialized<T>
CHECK_EQUAL(r2.constructor(), 2); // direct MyContainer(3.4)
CHECK_EQUAL(r3.constructor(), 103); // copy of MyContainer(cx)
CHECK_EQUAL(r4.constructor(), 3); // direct MyContainer(cx)
CHECK_EQUAL(r5.constructor(), 4); // direct MyContainer(cx, cx, cx)
// Test Rooted constructor forwarding for a non-copyable type.
JS::Rooted<MyNonCopyableContainer> nc1(cx);
JS::Rooted<MyNonCopyableContainer> nc2(cx, 3.4);
// Compile error: cannot copy
// JS::Rooted<MyNonCopyableContainer> nc3(cx, MyNonCopyableContainer(cx));
JS::Rooted<MyNonCopyableContainer> nc4(cx, cx);
JS::Rooted<MyNonCopyableContainer> nc5(cx, cx, cx, cx);
CHECK_EQUAL(nc1.constructor(), 1); // direct MyNonCopyableContainer()
CHECK_EQUAL(nc2.constructor(), 2); // direct MyNonCopyableContainer(3.4)
CHECK_EQUAL(nc4.constructor(), 3); // direct MyNonCopyableContainer(cx)
CHECK_EQUAL(nc5.constructor(),
4); // direct MyNonCopyableContainer(cx, cx, cx)
JS::Rooted<MyContainer> container(cx);
container.obj() = JS_NewObject(cx, nullptr);
container.str() = JS_NewStringCopyZ(cx, "Hello");
@ -163,30 +86,6 @@ BEGIN_TEST(testGCRootedStaticStructInternalStackStorageAugmented) {
// Automatic move from stack to heap.
JS::PersistentRooted<MyContainer> heap(cx, container);
// Copyable types in place.
JS::PersistentRooted<MyContainer> cp1(cx);
JS::PersistentRooted<MyContainer> cp2(cx, 7.8);
JS::PersistentRooted<MyContainer> cp3(cx, cx);
JS::PersistentRooted<MyContainer> cp4(cx, cx, cx, cx);
CHECK_EQUAL(cp1.constructor(), 101); // copy of SafelyInitialized<T>
CHECK_EQUAL(cp2.constructor(), 2); // direct MyContainer(double)
CHECK_EQUAL(cp3.constructor(), 3); // direct MyContainer(cx)
CHECK_EQUAL(cp4.constructor(), 4); // direct MyContainer(cx, cx, cx)
// Construct uncopyable type in place.
JS::PersistentRooted<MyNonCopyableContainer> ncp1(cx);
JS::PersistentRooted<MyNonCopyableContainer> ncp2(cx, 7.8);
// We're not just using a 1-arg constructor, right?
JS::PersistentRooted<MyNonCopyableContainer> ncp3(cx, cx);
JS::PersistentRooted<MyNonCopyableContainer> ncp4(cx, cx, cx, cx);
CHECK_EQUAL(ncp1.constructor(), 1); // direct SafelyInitialized<T>
CHECK_EQUAL(ncp2.constructor(), 2); // direct Ctor(double)
CHECK_EQUAL(ncp3.constructor(), 3); // direct Ctor(cx)
CHECK_EQUAL(ncp4.constructor(), 4); // direct Ctor(cx, cx, cx)
// clear prior rooting.
container.obj() = nullptr;
container.str() = nullptr;
@ -356,7 +255,7 @@ END_TEST(testGCHandleHashMap)
using ShapeVec = GCVector<Shape*>;
BEGIN_TEST(testGCRootedVector) {
JS::Rooted<ShapeVec> shapes(cx, cx);
JS::Rooted<ShapeVec> shapes(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, cx);
Rooted<GCVector<JSLinearString*>> components(cx);
size_t lastSep = 0;
while (lastSep < path->length()) {
int32_t i = IndexOf(path, PathSeparator, lastSep);