Skip to content

Commit 238a0ad

Browse files
committed
Added a definition of {{StringContext}} extended attribute for
(DOM|USV)String. This is to hook up the Trusted Types validation during the ES->IDL type conversion to avoid funky issues with its default policy. See w3c/trusted-types#248, w3c/trusted-types#176
1 parent 47c5c92 commit 238a0ad

File tree

1 file changed

+60
-2
lines changed

1 file changed

+60
-2
lines changed

index.bs

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6353,8 +6353,10 @@ The following extended attributes are <dfn for="extended attributes">applicable
63536353
[{{AllowResizable}}],
63546354
[{{AllowShared}}],
63556355
[{{Clamp}}],
6356-
[{{EnforceRange}}], and
6357-
[{{LegacyNullToEmptyString}}].
6356+
[{{EnforceRange}}],
6357+
[{{LegacyNullToEmptyString}}] and
6358+
[{{StringContext}}].
6359+
63586360

63596361
<div algorithm>
63606362
The <dfn for="IDL type" lt="extended attribute associated with|extended attributes associated with">extended attributes associated with</dfn>
@@ -7581,6 +7583,13 @@ value when its bit pattern is interpreted as an unsigned 64-bit integer.
75817583
A JavaScript value |V| is [=converted to an IDL value|converted=]
75827584
to an IDL {{DOMString}} value by running the following algorithm:
75837585

7586+
1. If the conversion is to an IDL type [=extended attribute associated with|associated with=] the
7587+
[{{StringContext}}] extended attribute, then set |V| to the result of [=validate the string in context=], passing
7588+
[=this=], |V|, the {{StringContext}} extended attribute [=identifier=], and the [=identifier=]
7589+
of the [{{StringContext}}] extended attribute [=related construct=].
7590+
7591+
Note: That algorithm may [=ECMAScript/throw=] a {{ECMAScript/TypeError}}.
7592+
75847593
1. If |V| is <emu-val>null</emu-val> and the conversion is to an IDL type
75857594
[=extended attribute associated with|associated with=] the [{{LegacyNullToEmptyString}}] extended
75867595
attribute, then return the {{DOMString}} value that represents the empty string.
@@ -10259,6 +10268,40 @@ that does specify [{{SecureContext}}].
1025910268
</pre>
1026010269
</div>
1026110270

10271+
<h4 id="StringContext" extended-attribute lt="StringContext">[StringContext]</h4>
10272+
10273+
If the [{{StringContext}}] [=extended attribute=] appears on {{DOMString}} or {{USVString}}, it
10274+
modifies how the value is converted to the IDL type, causing additional value validation to
10275+
adhere to the context the string is used in.
10276+
10277+
The [{{StringContext}}] extended attribute must [=takes an identifier|take an identifier=]. The [=identifier=]
10278+
must be one of "<code>html</code>", "<code>script-url</code>" and "<code>script</code>".
10279+
10280+
A type annotated with the [{{StringContext}}] extended attribute must not appear in a construct
10281+
that is not a [=regular attribute=] or a [=regular operation=]. A type annotated with the [{{StringContext}}]
10282+
extended attribute must not appear in a [=read only=] attribute. The construct that the type annotated with
10283+
the [{{StringContext}}] extended attribute appears in is its <dfn>related construct</dfn>.
10284+
10285+
A type that is not {{DOMString}} or {{USVString}} must not be [=extended attributes associated with|associated with=]
10286+
the [{{StringContext}}] extended attribute.
10287+
10288+
See the rules for converting ECMAScript values to the IDL types in [[#es-DOMString]] and [[#es-USVString]]
10289+
for the specific requirements that the use of [{{StringContext}}] entails.
10290+
10291+
<div class="example">
10292+
10293+
In the following [=IDL fragment=],
10294+
a [=variadic=] [=operation=] is declared
10295+
that uses the [{{StringContext}}] [=extended attribute=]
10296+
on all its arguments:
10297+
10298+
<pre highlight="webidl">
10299+
interface Document {
10300+
void write([StringContext=html] DOMString... text);
10301+
};
10302+
</pre>
10303+
</div>
10304+
1026210305

1026310306
<h4 id="Unscopable" extended-attribute lt="Unscopable">[Unscopable]</h4>
1026410307

@@ -11056,6 +11099,21 @@ allowed. The security check takes the following three inputs:
1105611099

1105711100
Note: The HTML Standard defines how a security check is performed. [[!HTML]]
1105811101

11102+
Certain algorithms in [[#es-type-mapping]] are defined to
11103+
<dfn id="dfn-validate-the-string-in-context" export>validate the string in context</dfn> on a given
11104+
value. This check is used to determine whether a given value
11105+
is appropriate for its {{StringContext}}. This validation takes the following four inputs:
11106+
11107+
1. the [=platform object=] on
11108+
which the operation invocation or attribute access is being done,
11109+
1. the value to validate,
11110+
1. the {{StringContext}} [=identifier=], and
11111+
1. the [=identifier=] of the operation or attribute.
11112+
11113+
The algorithm returns an ECMAScript String value, or [=ECMAScript/throws=] a {{ECMAScript/TypeError}}.
11114+
11115+
Note: The HTML Standard defines how the validation is performed. [[!HTML]]
11116+
1105911117

1106011118
<h3 id="js-overloads" oldids="es-overloads">Overload resolution algorithm</h3>
1106111119

0 commit comments

Comments
 (0)