Skip to content

Commit

Permalink
Never include unsupported event attributes into attributeNamesWithInt…
Browse files Browse the repository at this point in the history
…erfaceName

This is a small refactoring of #49473

Instead of skipping unsupported attributes in the for loop, we filter
them out when building the list.

Technically, interfaceName is no longer used in the for loop, but we
keep it in case that's needed for future setAttribute/setAttributeNS
tests.
  • Loading branch information
fred-wang committed Jan 10, 2025
1 parent f371b41 commit 122c87c
Showing 1 changed file with 16 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,20 @@
<script>
promise_setup(async function() {
let attributeNamesWithInterfaceName = [];
function isAttributeImplemented(interfaceName, name) {
switch (interfaceName) {
case 'GlobalEventHandlers':
return name in HTMLElement.prototype;
case 'WindowEventHandlers':
return name in HTMLBodyElement.prototype;
case 'HTMLMediaElement':
return name in HTMLMediaElement.prototype;
case 'SVGAnimationElement':
return name in SVGAnimationElement.prototype;
default:
throw "Unknown interface";
}
}
function addOnAttributes(IDL, interfaceName) {
// Parsing the whole IDL file is slow, so use a small regexp to extract only
// the part that is relevant for this test.
Expand All @@ -19,7 +33,8 @@
parsedIDL.find(idl => idl.name === interfaceName)
.members.map(member => member.name)
.filter(name => name.length >= 3 && name.startsWith("on") &&
!name.startsWith("onwebkit"))
!name.startsWith("onwebkit") &&
isAttributeImplemented(interfaceName, name))
.forEach(name => attributeNamesWithInterfaceName.push({name, interfaceName}));
}

Expand All @@ -39,20 +54,6 @@
addOnAttributes(svgAnimationsIDL, "SVGAnimationElement");

for (const attributeNameWithInterfaceName of attributeNamesWithInterfaceName) {
// Skip attributes that are not implemented in the browser.
if (attributeNameWithInterfaceName.interfaceName === 'GlobalEventHandlers' && !(attributeNameWithInterfaceName.name in HTMLElement.prototype)) {
continue;
}
if (attributeNameWithInterfaceName.interfaceName === 'WindowEventHandlers' && !(attributeNameWithInterfaceName.name in HTMLBodyElement.prototype)) {
continue;
}
if (attributeNameWithInterfaceName.interfaceName === 'HTMLMediaElement' && !(attributeNameWithInterfaceName.name in HTMLMediaElement.prototype)) {
continue;
}
if (attributeNameWithInterfaceName.interfaceName === 'SVGAnimationElement' && !(attributeNameWithInterfaceName.name in SVGAnimationElement.prototype)) {
continue;
}

promise_test(async () => {
NSURI_ARRAY.forEach(attrNs => {
assert_equals(trustedTypes.getAttributeType(
Expand Down

0 comments on commit 122c87c

Please sign in to comment.