Support static and instance members having the same name in IDLs (#36523)

This is needed to implement features like `Response.json` which is a
static helper added to the fetch spec which overlaps with the `json`
instance method `Response` has from `Body`.

Partly based these changes on what Firefox does for this same issue.
(https://searchfox.org/mozilla-central/source/dom/bindings/Codegen.py
and
https://searchfox.org/mozilla-central/source/dom/bindings/Configuration.py
specifically keying `binaryNameFor` on name and `isStatic`).

Testing: I locally updated the Response.webidl to contain the new static
`json` and it compiles.

Signed-off-by: Sebastian C <sebsebmc@gmail.com>
This commit is contained in:
Sebastian C 2025-04-16 16:00:52 -05:00 committed by GitHub
parent f2ee40e40b
commit a1b9949f75
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 35 additions and 21 deletions

View file

@ -353,8 +353,8 @@ class Descriptor(DescriptorProvider):
add('all', [config], attribute)
self._binaryNames = desc.get('binaryNames', {})
self._binaryNames.setdefault('__legacycaller', 'LegacyCall')
self._binaryNames.setdefault('__stringifier', 'Stringifier')
self._binaryNames.setdefault(('__legacycaller', False), 'LegacyCall')
self._binaryNames.setdefault(('__stringifier', False), 'Stringifier')
self._internalNames = desc.get('internalNames', {})
@ -365,7 +365,7 @@ class Descriptor(DescriptorProvider):
if binaryName:
assert isinstance(binaryName, list)
assert len(binaryName) == 1
self._binaryNames.setdefault(member.identifier.name,
self._binaryNames.setdefault((member.identifier.name, member.isStatic()),
binaryName[0])
self._internalNames.setdefault(member.identifier.name,
member.identifier.name.replace('-', '_'))
@ -391,8 +391,8 @@ class Descriptor(DescriptorProvider):
return filename
return None
def binaryNameFor(self, name):
return self._binaryNames.get(name, name)
def binaryNameFor(self, name, isStatic):
return self._binaryNames.get((name, isStatic), name)
def internalNameFor(self, name):
return self._internalNames.get(name, name)