@@ -6353,8 +6353,10 @@ The following extended attributes are <dfn for="extended attributes">applicable
6353
6353
[{{AllowResizable}}],
6354
6354
[{{AllowShared}}],
6355
6355
[{{Clamp}}],
6356
- [{{EnforceRange}}], and
6357
- [{{LegacyNullToEmptyString}}].
6356
+ [{{EnforceRange}}],
6357
+ [{{LegacyNullToEmptyString}}] and
6358
+ [{{StringContext}}].
6359
+
6358
6360
6359
6361
<div algorithm>
6360
6362
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.
7581
7583
A JavaScript value |V| is [=converted to an IDL value|converted=]
7582
7584
to an IDL {{DOMString}} value by running the following algorithm:
7583
7585
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
+
7584
7593
1. If |V| is <emu-val>null</emu-val> and the conversion is to an IDL type
7585
7594
[=extended attribute associated with|associated with=] the [{{LegacyNullToEmptyString}}] extended
7586
7595
attribute, then return the {{DOMString}} value that represents the empty string.
@@ -10259,6 +10268,40 @@ that does specify [{{SecureContext}}].
10259
10268
</pre>
10260
10269
</div>
10261
10270
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
+
10262
10305
10263
10306
<h4 id="Unscopable" extended-attribute lt="Unscopable">[Unscopable]</h4>
10264
10307
@@ -11056,6 +11099,21 @@ allowed. The security check takes the following three inputs:
11056
11099
11057
11100
Note: The HTML Standard defines how a security check is performed. [[!HTML]]
11058
11101
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
+
11059
11117
11060
11118
<h3 id="js-overloads" oldids="es-overloads">Overload resolution algorithm</h3>
11061
11119
0 commit comments