Skip to content

Commit

Permalink
Rewrite metadata functions
Browse files Browse the repository at this point in the history
- getAttributeType and getPropertyType now use lookup tables.
  • Loading branch information
lukewarlow committed Feb 26, 2024
1 parent 51d9e37 commit 436bc9e
Showing 1 changed file with 41 additions and 14 deletions.
55 changes: 41 additions & 14 deletions spec/index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -671,15 +671,29 @@ initially empty.

1. Set |localName| to |tagName| in [=ASCII lowercase=].
1. If |elementNs| is an empty string, set |elementNs| to [=HTML namespace=].
1. If |property| starts with "on", then return {{TrustedScript}}.
1. Let |interface| be the [=element interface=] for |localName| and |elementNs|.
1. If |interface| has an IDL <a spec="webidl">attribute</a> member which identifier is |attribute|, and
{{StringContext}} IDL extended attribute appears on that attribute, return
stringified {{StringContext}}'s identifier and abort further steps.

Note: This also takes into account all members of [=interface mixins=] that
|interface| [=includes=].

1. Return null.
1. Let |expectedType| be null.
1. Find the row in the following table, where the first column is "*" or |interface|'s name, and |property| is in the second column.
If a matching row is found, set |expectedType| to the value of the third column.

<table>
<thead>
<tr><th>Element<th>Property name<th>TrustedType
<tbody>
<tr><td>{{HTMLEmbedElement}}<td>"src"<td>{{TrustedScriptURL}}
<tr><td>{{HTMLIFrameElement}}<td>"srcdoc"<td>{{TrustedHTML}}
<tr><td>{{HTMLObjectElement}}<td>"codebase"<td>{{TrustedScriptURL}}
<tr><td>{{HTMLObjectElement}}<td>"data"<td>{{TrustedScriptURL}}
<tr><td>{{HTMLScriptElement}}<td>"innerText"<td>{{TrustedScript}}
<tr><td>{{HTMLScriptElement}}<td>"src"<td>{{TrustedScriptURL}}
<tr><td>{{HTMLScriptElement}}<td>"text"<td>{{TrustedScript}}
<tr><td>{{HTMLScriptElement}}<td>"textContent"<td>{{TrustedScript}}
<tr><td>"*"<td>"innerHTML"<td>{{TrustedHTML}}
<tr><td>"*"<td>"outerHTML"<td>{{TrustedHTML}}
</tbody>
</table>
1. Return |expectedType|.

<div class="example" id="get-property-type-example">
<xmp highlight="js">
Expand All @@ -698,15 +712,28 @@ initially empty.

1. Set |localName| to |tagName| in [=ASCII lowercase=].
1. Set |attribute| to |attribute| in [=ASCII lowercase=].
1. If |attribute| starts with "on", then return {{TrustedScript}}.
1. If |elementNs| is an empty string, set |elementNs| to [=HTML namespace=].
1. If |attrNs| is an empty string, set |attrNs| to null.
1. Let |interface| be the [=element interface=] for |localName| and |elementNs|.
1. If |interface| does not have an IDL <a spec="webidl">attribute</a> that [=reflects=] a content attribute with
|localName| local name and |attrNs| namespace,
return undefined and abort further steps. Otherwise, let |idlAttribute| be that IDL <a spec="webidl">attribute</a>.
1. If {{StringContext}} IDL extended attribute appears on |idlAttribute|, return
stringified {{StringContext}}'s identifier and abort further steps.
1. Return null.
1. Let |expectedType| be null.
1. Find the row in the following table, where |interface|'s name is in the first column, and |attribute|'s <a for="Attr">namespace</a> and <a for="Attr">local name</a> match the values in the second and third column, respectively.
If a matching row is found, set |expectedType| to the value of the fourth.

<table>
<thead>
<tr><th>Element<th>Attribute namespace<th>Attribute local name<th>TrustedType
<tbody>
<tr><td>{{HTMLIFrameElement}}<td>null<td>"srcdoc"<td>{{TrustedHTML}}
<tr><td>{{HTMLEmbedElement}}<td>null<td>"src"<td>{{TrustedScriptURL}}
<tr><td>{{HTMLScriptElement}}<td>null<td>"src"<td>{{TrustedScriptURL}}
<tr><td>{{HTMLObjectElement}}<td>null<td>"data"<td>{{TrustedScriptURL}}
<tr><td>{{HTMLObjectElement}}<td>null<td>"codebase"<td>{{TrustedScriptURL}}
<tr><td>{{SVGScriptElement}}<td>null<td>"href"<td>{{TrustedScriptURL}}
<tr><td>{{SVGScriptElement}}<td><a>XLink namespace</a><td>"href"<td>{{TrustedScriptURL}}
</tbody>
</table>
1. Return |expectedType|.

<div class="example" id="get-attribute-type-example">
<xmp highlight="js">
Expand Down

0 comments on commit 436bc9e

Please sign in to comment.