-
Notifications
You must be signed in to change notification settings - Fork 163
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added a definition of {{StringContext}} extended attribute. #841
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -6353,8 +6353,10 @@ The following extended attributes are <dfn for="extended attributes">applicable | |||||
[{{AllowResizable}}], | ||||||
[{{AllowShared}}], | ||||||
[{{Clamp}}], | ||||||
[{{EnforceRange}}], and | ||||||
[{{LegacyNullToEmptyString}}]. | ||||||
[{{EnforceRange}}], | ||||||
[{{LegacyNullToEmptyString}}] and | ||||||
[{{StringContext}}]. | ||||||
|
||||||
|
||||||
<div algorithm> | ||||||
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. | |||||
A JavaScript value |V| is [=converted to an IDL value|converted=] | ||||||
to an IDL {{DOMString}} value by running the following algorithm: | ||||||
|
||||||
1. If the conversion is to an IDL type [=extended attribute associated with|associated with=] the | ||||||
[{{StringContext}}] extended attribute, then set |V| to the result of [=validate the string in context=], passing | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. validating* |
||||||
[=this=], |V|, the {{StringContext}} extended attribute [=identifier=], and the [=identifier=] | ||||||
of the [{{StringContext}}] extended attribute [=related construct=]. | ||||||
Comment on lines
+7588
to
+7589
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This has some extreme magic that I don't really understand. As far as I know when we do type conversion there is no "this" and there is no access to something like a "related construct". I'd like to hear what @domenic and @Ms2ger think, but it seems to me you have to patch algorithms such as https://webidl.spec.whatwg.org/#dfn-attribute-setter instead. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree that this doesn't work with the layering as it currently exists. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, you cannot access "this" here. Some call sites don't have a "this". Putting it in the appropriate call sites instead (e.g., the overload resolution algorithm and attribute setters) seems like the best approach. |
||||||
|
||||||
Note: That algorithm may [=ECMAScript/throw=] a {{ECMAScript/TypeError}}. | ||||||
|
||||||
1. If |V| is <emu-val>null</emu-val> and the conversion is to an IDL type | ||||||
[=extended attribute associated with|associated with=] the [{{LegacyNullToEmptyString}}] extended | ||||||
attribute, then return the {{DOMString}} value that represents the empty string. | ||||||
|
@@ -10259,6 +10268,41 @@ that does specify [{{SecureContext}}]. | |||||
</pre> | ||||||
</div> | ||||||
|
||||||
<h4 id="StringContext" extended-attribute lt="StringContext">[StringContext]</h4> | ||||||
|
||||||
If the [{{StringContext}}] [=extended attribute=] appears on {{DOMString}} or {{USVString}}, it | ||||||
modifies how the value is converted to the IDL type, causing additional value validation to | ||||||
adhere to the context the string is used in. | ||||||
|
||||||
The [{{StringContext}}] extended attribute must [=takes an identifier|take an identifier=]. The [=identifier=] | ||||||
must be one of "<code>html</code>", "<code>script-url</code>" and "<code>script</code>". | ||||||
|
||||||
[{{StringContext}}] extended attribute may only annotate a type of a [=regular attribute=] or | ||||||
a [=regular operation=] argument. A type annotated with the [{{StringContext}}] | ||||||
extended attribute must not appear in a [=read only=] attribute. The [=regular attribute=] or | ||||||
a [=regular operation=] argument that the type annotated with the [{{StringContext}}] extended | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
attribute appears in is its <dfn>related construct</dfn>. | ||||||
|
||||||
A type that is not {{DOMString}} or {{USVString}} must not be [=extended attributes associated with|associated with=] | ||||||
the [{{StringContext}}] extended attribute. | ||||||
|
||||||
See the rules for converting ECMAScript values to the IDL types in [[#es-DOMString]] and [[#es-USVString]] | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These two es-X references are fails in bikeshed which is breaking the preview |
||||||
for the specific requirements that the use of [{{StringContext}}] entails. | ||||||
|
||||||
<div class="example"> | ||||||
|
||||||
In the following [=IDL fragment=], | ||||||
a [=variadic=] [=operation=] is declared | ||||||
that uses the [{{StringContext}}] [=extended attribute=] | ||||||
on all its arguments: | ||||||
|
||||||
<pre highlight="webidl"> | ||||||
interface Document { | ||||||
void write([StringContext=html] DOMString... text); | ||||||
}; | ||||||
</pre> | ||||||
</div> | ||||||
|
||||||
|
||||||
<h4 id="Unscopable" extended-attribute lt="Unscopable">[Unscopable]</h4> | ||||||
|
||||||
|
@@ -11056,6 +11100,21 @@ allowed. The security check takes the following three inputs: | |||||
|
||||||
Note: The HTML Standard defines how a security check is performed. [[!HTML]] | ||||||
|
||||||
Certain algorithms in [[#es-type-mapping]] are defined to | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This es-X is likewise a bikeshed fail |
||||||
<dfn id="dfn-validate-the-string-in-context" export>validate the string in context</dfn> on a given | ||||||
value. This check is used to determine whether a given value | ||||||
is appropriate for its {{StringContext}}. This validation takes the following four inputs: | ||||||
|
||||||
1. the [=platform object=] on | ||||||
which the operation invocation or attribute access is being done, | ||||||
1. the value to validate, | ||||||
1. the {{StringContext}} [=identifier=], and | ||||||
1. the [=identifier=] of the operation or attribute. | ||||||
|
||||||
The algorithm returns an ECMAScript String value, or [=ECMAScript/throws=] a {{ECMAScript/TypeError}}. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note that https://w3c.github.io/trusted-types/dist/spec/#html-validate-the-string-in-context doesn't necessarily return a string, and if it did, the conversion algorithm above does some unnecessary work. |
||||||
|
||||||
Note: The HTML Standard defines how the validation is performed. [[!HTML]] | ||||||
|
||||||
|
||||||
<h3 id="js-overloads" oldids="es-overloads">Overload resolution algorithm</h3> | ||||||
|
||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please bring back the Oxford comma.