Fix crash when enumerating properties of global object (#36491)

These changes make our implementation of the enumeration hook for
globals [match
Gecko's](https://searchfox.org/mozilla-central/rev/1f65969e57c757146e3e548614b49d3a4168eeb8/dom/base/nsGlobalWindowInner.cpp#3297),
fixing an assertion failure that occurred in the previous
implementation.

Our enumeration hook is supposed to fill a vector with names of
properties on the global object without modifying the global in any way;
instead we were defining all of the missing webidl interfaces. We now do
much less work and crash less.

Testing: New crashtest based on manual testcase.
Fixes: #34686

---------

Signed-off-by: Josh Matthews <josh@joshmatthews.net>
This commit is contained in:
Josh Matthews 2025-04-16 23:32:53 -04:00 committed by GitHub
parent a1b9949f75
commit 30390f8c5e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 98 additions and 34 deletions

View file

@ -2972,7 +2972,8 @@ class CGConstructorEnabled(CGAbstractMethod):
'ConstructorEnabled', 'bool',
[Argument("SafeJSContext", "aCx"),
Argument("HandleObject", "aObj")],
templateArgs=['D: DomTypes'])
templateArgs=['D: DomTypes'],
pub=True)
def definition_body(self):
conditions = []
@ -8531,8 +8532,7 @@ class GlobalGenRoots():
def InterfaceObjectMap(config):
mods = [
"crate::dom::bindings::codegen",
"crate::script_runtime::JSContext",
"js::rust::HandleObject",
"script_bindings::interfaces::Interface",
]
imports = CGList([CGGeneric(f"use {mod};") for mod in mods], "\n")
@ -8555,9 +8555,13 @@ class GlobalGenRoots():
for ctor in d.interface.legacyFactoryFunctions:
pairs.append((ctor.identifier.name, binding_mod, binding_ns))
pairs.sort(key=operator.itemgetter(0))
def bindingPath(pair):
return f'codegen::Bindings::{pair[1]}::{pair[2]}'
mappings = [
CGGeneric(f'"{pair[0]}": "codegen::Bindings::{pair[1]}'
f'::{pair[2]}::DefineDOMInterface::<crate::DomTypeHolder>"')
CGGeneric(f'"{pair[0]}": ["{bindingPath(pair)}::DefineDOMInterface::<crate::DomTypeHolder>", '
f'"{bindingPath(pair)}::ConstructorEnabled::<crate::DomTypeHolder>"]')
for pair in pairs
]
return CGWrapper(