Skip to content

Commit 648f6b2

Browse files
committed
Rewrite metadata functions
- getAttributeType and getPropertyType now use lookup tables.
1 parent 51d9e37 commit 648f6b2

File tree

1 file changed

+61
-30
lines changed

1 file changed

+61
-30
lines changed

spec/index.bs

Lines changed: 61 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -671,15 +671,31 @@ initially empty.
671671

672672
1. Set |localName| to |tagName| in [=ASCII lowercase=].
673673
1. If |elementNs| is an empty string, set |elementNs| to [=HTML namespace=].
674+
1. If |property| starts with "on", then return {{TrustedScript}}.
674675
1. Let |interface| be the [=element interface=] for |localName| and |elementNs|.
675-
1. If |interface| has an IDL <a spec="webidl">attribute</a> member which identifier is |attribute|, and
676-
{{StringContext}} IDL extended attribute appears on that attribute, return
677-
stringified {{StringContext}}'s identifier and abort further steps.
678-
679-
Note: This also takes into account all members of [=interface mixins=] that
680-
|interface| [=includes=].
681-
682-
1. Return null.
676+
1. Let |expectedType| be null.
677+
1. Find the row in the following table, where the first column is "*" or |interface|'s name, and |property| is in the second column.
678+
If a matching row is found, set |expectedType| to the value of the third column.
679+
680+
<table>
681+
<thead>
682+
<tr><th>Element<th>Property name<th>TrustedType
683+
<tbody>
684+
<tr><td>{{HTMLEmbedElement}}<td>"src"<td>{{TrustedScriptURL}}
685+
<tr><td>{{HTMLIFrameElement}}<td>"srcdoc"<td>{{TrustedHTML}}
686+
<tr><td>{{HTMLObjectElement}}<td>"codeBase"<td>{{TrustedScriptURL}}
687+
<tr><td>{{HTMLObjectElement}}<td>"data"<td>{{TrustedScriptURL}}
688+
<tr><td>{{HTMLScriptElement}}<td>"innerText"<td>{{TrustedScript}}
689+
<tr><td>{{HTMLScriptElement}}<td>"src"<td>{{TrustedScriptURL}}
690+
<tr><td>{{HTMLScriptElement}}<td>"text"<td>{{TrustedScript}}
691+
<tr><td>{{HTMLScriptElement}}<td>"textContent"<td>{{TrustedScript}}
692+
<tr><td>"*"<td>"innerHTML"<td>{{TrustedHTML}}
693+
<tr><td>"*"<td>"outerHTML"<td>{{TrustedHTML}}
694+
</tbody>
695+
</table>
696+
1. Return |expectedType|.
697+
698+
Note: Step 3 is a special case for <a href=https://html.spec.whatwg.org/#event-handler-name>event handler names</a>, as they always start with "on".
683699

684700
<div class="example" id="get-property-type-example">
685701
<xmp highlight="js">
@@ -698,15 +714,19 @@ initially empty.
698714

699715
1. Set |localName| to |tagName| in [=ASCII lowercase=].
700716
1. Set |attribute| to |attribute| in [=ASCII lowercase=].
717+
1. If |attribute| starts with "on", then return {{TrustedScript}}.
701718
1. If |elementNs| is an empty string, set |elementNs| to [=HTML namespace=].
702719
1. If |attrNs| is an empty string, set |attrNs| to null.
703720
1. Let |interface| be the [=element interface=] for |localName| and |elementNs|.
704-
1. If |interface| does not have an IDL <a spec="webidl">attribute</a> that [=reflects=] a content attribute with
705-
|localName| local name and |attrNs| namespace,
706-
return undefined and abort further steps. Otherwise, let |idlAttribute| be that IDL <a spec="webidl">attribute</a>.
707-
1. If {{StringContext}} IDL extended attribute appears on |idlAttribute|, return
708-
stringified {{StringContext}}'s identifier and abort further steps.
709-
1. Return null.
721+
1. Let |expectedType| be null.
722+
1. Set |attributeData| to the result of [$Get Trusted Type data for attribute$] algorithm, with the following arguments:
723+
* |interface| as |element|
724+
* |attribute|
725+
* |attrNs|
726+
1. If |attributeData| is not null, then set |expectedType| to the value of the third member of |attributeData|.
727+
1. Return |expectedType|.
728+
729+
Note: Step 3 is a special case for <a href=https://html.spec.whatwg.org/#event-handler-name>event handler names</a>, as they always start with "on".
710730

711731
<div class="example" id="get-attribute-type-example">
712732
<xmp highlight="js">
@@ -1083,10 +1103,32 @@ Given an {{HTMLScriptElement}} (|script|), this algorithm performs the following
10831103
## Get Trusted Types-compliant attribute value ## {#validate-attribute-mutation}
10841104
To <dfn abstract-op export>get Trusted Types-compliant attribute value</dfn> on {{Attr}} |attribute| with {{Element}} |element| and {{TrustedType}} or a string |newValue|, perform the following steps:
10851105

1086-
1. Let |expectedType| be null.
1087-
1. Let |sink| be null.
1088-
1. Find the row in the following table, where |element| 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.
1089-
If a matching row is found, set |expectedType| and |sink| to the value of the fourth, and fifth column in that row, respectively.
1106+
1. Set |attributeData| to the result of [$Get Trusted Type data for attribute$] algorithm, with the following arguments:
1107+
* |element|
1108+
* |attribute|'s <a for="Attr">local name</a> as |attribute|
1109+
* |attribute|'s <a for="Attr">namespace</a> as |attributeNs|
1110+
1. If |attributeData| is null, then:
1111+
1. If |newValue| is a string, return |newValue|.
1112+
1. <a>Assert</a>: |newValue| is {{TrustedHTML}} or {{TrustedScript}} or {{TrustedScriptURL}}.
1113+
1. Return |value|'s `[[Data]]` internal slot value.
1114+
1. Let |expectedType| be the value of the third member of |attributeData|.
1115+
1. Let |sink| be the value of the fourth member of |attributeData|.
1116+
1. Return the result of executing [$Get Trusted Type compliant string$] with the following arguments:
1117+
* |expectedType|
1118+
* |newValue| as |input|
1119+
* |element|'s <a>node document</a>'s <a>relevant global object</a> as |global|
1120+
* |sink|
1121+
* 'script' as |sinkGroup|
1122+
1123+
If the algorithm threw an error, rethrow the error.
1124+
1125+
## Get Trusted Type data for attribute ## {#get-trusted-type-data-for-attribute}
1126+
To <dfn abstract-op>Get Trusted Type data for attribute</dfn> given |element|, |attribute|, |attributeNs|, perform the following steps:
1127+
1128+
1. Let |data| be null.
1129+
1. Find the row in the following table, where |element| is in the first column, |attributeNs| is in the second column,
1130+
and |attribute| is in the third column.
1131+
If a matching row is found, set |data| to that row.
10901132

10911133
<table>
10921134
<thead>
@@ -1102,18 +1144,7 @@ To <dfn abstract-op export>get Trusted Types-compliant attribute value</dfn> on
11021144
</tbody>
11031145
</table>
11041146

1105-
1. If |expectedType| is null, then:
1106-
1. If |newValue| is a string, return |newValue|.
1107-
1. <a>Assert</a>: |newValue| is {{TrustedHTML}} or {{TrustedScript}} or {{TrustedScriptURL}}.
1108-
1. Return |value|'s `[[Data]]` internal slot value.
1109-
1. Return the result of executing [$Get Trusted Type compliant string$] with the following arguments:
1110-
* |expectedType|
1111-
* |newValue| as |input|
1112-
* |element|'s <a>node document</a>'s <a>relevant global object</a> as |global|
1113-
* |sink|
1114-
* 'script' as |sinkGroup|
1115-
1116-
If the algorithm threw an error, rethrow the error.
1147+
1. Return |data|.
11171148

11181149
# Integrations # {#integrations}
11191150

0 commit comments

Comments
 (0)