diff --git a/dom/bindings/BindingUtils.h b/dom/bindings/BindingUtils.h index 5543ceeeefc..3f46ed3fbdf 100644 --- a/dom/bindings/BindingUtils.h +++ b/dom/bindings/BindingUtils.h @@ -3111,6 +3111,14 @@ CreateGlobal(JSContext* aCx, T* aNative, nsWrapperCache* aCache, return nullptr; } + bool succeeded; + if (!JS_SetImmutablePrototype(aCx, aGlobal, &succeeded)) { + return nullptr; + } + MOZ_ASSERT(succeeded, + "making a fresh global object's [[Prototype]] immutable can " + "internally fail, but it should never be unsuccessful"); + return proto; } diff --git a/dom/bindings/Codegen.py b/dom/bindings/Codegen.py index 8ccab38a3c6..6459e7afd49 100644 --- a/dom/bindings/Codegen.py +++ b/dom/bindings/Codegen.py @@ -2953,9 +2953,32 @@ class CGCreateInterfaceObjectsMethod(CGAbstractMethod): else: unforgeableHolderSetup = None + if (self.descriptor.interface.isOnGlobalProtoChain() and + needInterfacePrototypeObject): + makeProtoPrototypeImmutable = CGGeneric(fill( + """ + if (*${protoCache}) { + bool succeeded; + JS::Handle prot = GetProtoObjectHandle(aCx, aGlobal); + if (!JS_SetImmutablePrototype(aCx, prot, &succeeded)) { + $*{failureCode} + } + + MOZ_ASSERT(succeeded, + "making a fresh prototype object's [[Prototype]] " + "immutable can internally fail, but it should " + "never be unsuccessful"); + } + """, + protoCache=protoCache, + failureCode=failureCode)) + else: + makeProtoPrototypeImmutable = None + return CGList( [getParentProto, CGGeneric(getConstructorProto), initIds, - prefCache, CGGeneric(call), defineAliases, unforgeableHolderSetup], + prefCache, CGGeneric(call), defineAliases, unforgeableHolderSetup, + makeProtoPrototypeImmutable], "\n").define() diff --git a/js/src/builtin/Object.cpp b/js/src/builtin/Object.cpp index bf8ba22a300..5375da75cfb 100644 --- a/js/src/builtin/Object.cpp +++ b/js/src/builtin/Object.cpp @@ -1056,6 +1056,13 @@ CreateObjectPrototype(JSContext* cx, JSProtoKey key) if (!objectProto) return nullptr; + bool succeeded; + if (!SetImmutablePrototype(cx, objectProto, &succeeded)) + return nullptr; + MOZ_ASSERT(succeeded, + "should have been able to make a fresh Object.prototype's " + "[[Prototype]] immutable"); + /* * The default 'new' type of Object.prototype is required by type inference * to have unknown properties, to simplify handling of e.g. heterogenous