Bug 1747059 - Ensure ShadowRealmsGlobalScope has an ordinary object prototype. r=edgar

(Patch largely written by peterv; I just made some compilation tweaks)

Differential Revision: https://phabricator.services.mozilla.com/D146350
This commit is contained in:
Matthew Gaudet 2022-06-28 22:04:19 +00:00
parent 580a35d01e
commit 13db76bd1b
4 changed files with 26 additions and 4 deletions

View File

@ -785,6 +785,10 @@ DOMInterfaces = {
'implicitJSContext': [ 'pushManager' ],
},
'ShadowRealmGlobalScope': {
'hasOrdinaryObjectPrototype': True,
},
'SharedWorkerGlobalScope': {
'headerFile': 'mozilla/dom/WorkerScope.h',
},

View File

@ -571,13 +571,18 @@ def DOMClass(descriptor):
else:
wrapperCacheGetter = "nullptr"
if descriptor.hasOrdinaryObjectPrototype:
getProto = "JS::GetRealmObjectPrototypeHandle"
else:
getProto = "GetProtoObjectHandle"
return fill(
"""
{ ${protoChain} },
std::is_base_of_v<nsISupports, ${nativeType}>,
${hooks},
FindAssociatedGlobalForNative<${nativeType}>::Get,
GetProtoObjectHandle,
${getProto},
GetCCParticipant<${nativeType}>::Get(),
${serializer},
${wrapperCacheGetter}
@ -587,6 +592,7 @@ def DOMClass(descriptor):
hooks=NativePropertyHooks(descriptor),
serializer=serializer,
wrapperCacheGetter=wrapperCacheGetter,
getProto=getProto,
)
@ -3883,9 +3889,11 @@ class CGCreateInterfaceObjectsMethod(CGAbstractMethod):
else:
unforgeableHolderSetup = None
# FIXME Unclear whether this is needed for hasOrdinaryObjectPrototype
if (
self.descriptor.interface.isOnGlobalProtoChain()
and needInterfacePrototypeObject
and not self.descriptor.hasOrdinaryObjectPrototype
):
makeProtoPrototypeImmutable = CGGeneric(
fill(
@ -4794,13 +4802,17 @@ class CGWrapGlobalMethod(CGAbstractMethod):
else:
unforgeable = ""
if self.descriptor.hasOrdinaryObjectPrototype:
getProto = "JS::GetRealmObjectPrototypeHandle"
else:
getProto = "GetProtoObjectHandle"
return fill(
"""
$*{assertions}
MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
"nsISupports must be on our primary inheritance chain");
if (!CreateGlobal<${nativeType}, GetProtoObjectHandle>(aCx,
if (!CreateGlobal<${nativeType}, ${getProto}>(aCx,
aObject,
aCache,
sClass.ToJSClass(),
@ -4826,6 +4838,7 @@ class CGWrapGlobalMethod(CGAbstractMethod):
""",
assertions=AssertInheritanceChain(self.descriptor),
nativeType=self.descriptor.nativeType,
getProto=getProto,
properties=properties,
chromeProperties=chromeProperties,
failureCode=failureCode,
@ -16520,7 +16533,10 @@ class CGDescriptor(CGThing):
# CGGetProtoObjectMethod and CGGetConstructorObjectMethod need
# to come after CGCreateInterfaceObjectsMethod.
if descriptor.interface.hasInterfacePrototypeObject():
if (
descriptor.interface.hasInterfacePrototypeObject()
and not descriptor.hasOrdinaryObjectPrototype
):
cgThings.append(CGGetProtoObjectHandleMethod(descriptor))
if descriptor.interface.hasChildInterfaces():
cgThings.append(CGGetProtoObjectMethod(descriptor))

View File

@ -677,6 +677,8 @@ class Descriptor(DescriptorProvider):
config.maxProtoChainLength, len(self.prototypeChain)
)
self.hasOrdinaryObjectPrototype = desc.get("hasOrdinaryObjectPrototype", False)
def binaryNameFor(self, name):
return self._binaryNames.get(name, name)

View File

@ -7,5 +7,5 @@
// This interface exists purely to register a new global as part of
// code generation so that we can properly hook this into
// shadow realms.
[Global=(ShadowRealmGlobal), Exposed=ShadowRealmGlobal]
[Global=(ShadowRealmGlobal), Exposed=ShadowRealmGlobal, LegacyNoInterfaceObject]
interface ShadowRealmGlobalScope { };