@@ -6562,7 +6562,8 @@ annotate are called <dfn export for="annotated types" lt="inner type">inner type
65626562The following extended attributes are <dfn for="extended attributes">applicable to types</dfn>:
65636563[{{AllowShared}}],
65646564[{{Clamp}}],
6565- [{{EnforceRange}}], and
6565+ [{{EnforceRange}}],
6566+ [{{StringContext}}] and
65666567[{{TreatNullAs}}].
65676568
65686569<div algorithm>
@@ -7623,6 +7624,13 @@ value when its bit pattern is interpreted as an unsigned 64 bit integer.
76237624 An ECMAScript value |V| is [=converted to an IDL value|converted=]
76247625 to an IDL {{DOMString}} value by running the following algorithm:
76257626
7627+ 1. If the conversion is to an IDL type [=extended attribute associated with|associated with=] the
7628+ [{{StringContext}}] extended attribute, then set |V| to the result of [=validate the string in context=], passing
7629+ [=this=], |V|, the {{StringContext}} extended attribute [=identifier=], and the [=identifier=]
7630+ of the [{{StringContext}}] extended attribute [=related construct=].
7631+
7632+ Note: That algorithm may [=ECMAScript/throw=] a {{ECMAScript/TypeError}}.
7633+
76267634 1. If |V| is <emu-val>null</emu-val> and the conversion is to an IDL type
76277635 [=extended attribute associated with|associated with=] the [{{TreatNullAs}}] extended
76287636 attribute, then return the {{DOMString}} value that represents the empty string.
@@ -10496,6 +10504,40 @@ that does specify [{{SecureContext}}].
1049610504 </pre>
1049710505</div>
1049810506
10507+ <h4 id="StringContext" extended-attribute lt="StringContext">[StringContext]</h4>
10508+
10509+ If the [{{StringContext}}] [=extended attribute=] appears on {{DOMString}} or {{USVString}}, it
10510+ modifies how the value is converted to the IDL type, causing additional value validation to
10511+ adhere to the context the string is used in.
10512+
10513+ The [{{StringContext}}] extended attribute must [=takes an identifier|take an identifier=]. The [=identifier=]
10514+ must be one of "<code>html</code>", "<code>script-url</code>" and "<code>script</code>".
10515+
10516+ A type annotated with the [{{StringContext}}] extended attribute must not appear in a construct
10517+ that is not a [=regular attribute=] or a [=regular operation=]. A type annotated with the [{{StringContext}}]
10518+ extended attribute must not appear in a [=read only=] attribute. The construct that the type annotated with
10519+ the [{{StringContext}}] extended attribute appears in is its <dfn>related construct</dfn>.
10520+
10521+ A type that is not {{DOMString}} or {{USVString}} must not be [=extended attributes associated with|associated with=]
10522+ the [{{StringContext}}] extended attribute.
10523+
10524+ See the rules for converting ECMAScript values to the IDL types in [[#es-DOMString]] and [[#es-USVString]]
10525+ for the specific requirements that the use of [{{StringContext}}] entails.
10526+
10527+ <div class="example">
10528+
10529+ In the following [=IDL fragment=],
10530+ a [=variadic=] [=operation=] is declared
10531+ that uses the [{{StringContext}}] [=extended attribute=]
10532+ on all its arguments:
10533+
10534+ <pre highlight="webidl">
10535+ interface Document {
10536+ void write([StringContext=html] DOMString... text);
10537+ };
10538+ </pre>
10539+ </div>
10540+
1049910541
1050010542<h4 id="TreatNonObjectAsNull" extended-attribute lt="TreatNonObjectAsNull">[TreatNonObjectAsNull]</h4>
1050110543
@@ -10826,6 +10868,21 @@ allowed. The security check takes the following three inputs:
1082610868
1082710869Note: The HTML Standard defines how a security check is performed. [[!HTML]]
1082810870
10871+ Certain algorithms in [[#es-type-mapping]] are defined to
10872+ <dfn id="dfn-validate-the-string-in-context" export>validate the string in context</dfn> on a given
10873+ value. This check is used to determine whether a given value
10874+ is appropriate for its {{StringContext}}. This validation takes the following four inputs:
10875+
10876+ 1. the [=platform object=] on
10877+ which the operation invocation or attribute access is being done,
10878+ 1. the value to validate,
10879+ 1. the {{StringContext}} [=identifier=], and
10880+ 1. the [=identifier=] of the operation or attribute.
10881+
10882+ The algorithm returns an ECMAScript String value, or [=ECMAScript/throws=] a {{ECMAScript/TypeError}}.
10883+
10884+ Note: The HTML Standard defines how the validation is performed. [[!HTML]]
10885+
1082910886
1083010887<h3 id="es-overloads">Overload resolution algorithm</h3>
1083110888
0 commit comments