diff --git a/js/src/builtin/FinalizationRegistryObject.cpp b/js/src/builtin/FinalizationRegistryObject.cpp index 17a326f3ff75..04e119f7c3f5 100644 --- a/js/src/builtin/FinalizationRegistryObject.cpp +++ b/js/src/builtin/FinalizationRegistryObject.cpp @@ -852,7 +852,8 @@ bool GlobalObject::initFinalizationIteratorProto(JSContext* cx, if (!base) { return false; } - RootedPlainObject proto(cx, NewObjectWithGivenProto(cx, base)); + RootedPlainObject proto( + cx, GlobalObject::createBlankPrototypeInheriting(cx, base)); if (!proto) { return false; } diff --git a/js/src/builtin/MapObject.cpp b/js/src/builtin/MapObject.cpp index c8f4cb91ea46..74065a743f2b 100644 --- a/js/src/builtin/MapObject.cpp +++ b/js/src/builtin/MapObject.cpp @@ -177,7 +177,8 @@ bool GlobalObject::initMapIteratorProto(JSContext* cx, if (!base) { return false; } - RootedPlainObject proto(cx, NewObjectWithGivenProto(cx, base)); + RootedPlainObject proto( + cx, GlobalObject::createBlankPrototypeInheriting(cx, base)); if (!proto) { return false; } @@ -959,7 +960,8 @@ bool GlobalObject::initSetIteratorProto(JSContext* cx, if (!base) { return false; } - RootedPlainObject proto(cx, NewObjectWithGivenProto(cx, base)); + RootedPlainObject proto( + cx, GlobalObject::createBlankPrototypeInheriting(cx, base)); if (!proto) { return false; } diff --git a/js/src/vm/GlobalObject.h b/js/src/vm/GlobalObject.h index fc289aa4e668..35a0b6872cce 100644 --- a/js/src/vm/GlobalObject.h +++ b/js/src/vm/GlobalObject.h @@ -298,6 +298,12 @@ class GlobalObject : public NativeObject { const JSClass* clasp, HandleObject proto); + template + static T* createBlankPrototypeInheriting(JSContext* cx, HandleObject proto) { + NativeObject* res = createBlankPrototypeInheriting(cx, &T::class_, proto); + return res ? &res->template as() : nullptr; + } + template static T* createBlankPrototype(JSContext* cx, Handle global) { NativeObject* res = createBlankPrototype(cx, global, &T::class_);