-
Notifications
You must be signed in to change notification settings - Fork 3k
add import bytes #11657
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
base: main
Are you sure you want to change the base?
add import bytes #11657
Conversation
<li><p>Set <var>script</var>'s <span data-x="concept-script-parse-error">parse error</span> and | ||
<span data-x="concept-script-error-to-rethrow">error to rethrow</span> to null.</p></li> | ||
|
||
<li><p>Let <var>result</var> be a new <code>Uint8Array</code> object, in <var>settings</var>'s |
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.
You may want to use the creating an ArrayBufferView operation here (see e.g. the bytes()
method on Response), although this does not allow you to specify specifically an immutable ArrayBuffer (yet?).
I don't think "backing bytes" is really a concept which exists anywhere.
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.
Yeah, you might have to add a new argument for that or a separate operation.
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.
I'm not sure I fully understand. Mind leaving a code suggestion?
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.
This is the algorithm where creation of Uint8Array&friends is defined: https://github.com/whatwg/webidl/blob/a79e69ef7398ece546e526a1eebec977363c7304/index.bs#L9277-L9291
It needs to take a new parameter (I guess either a boolean or an enum like preserveResizability of https://tc39.es/proposal-immutable-arraybuffer/#sec-arraybuffercopyanddetach), propagate it to https://github.com/whatwg/webidl/blob/a79e69ef7398ece546e526a1eebec977363c7304/index.bs#L9252 and then call AllocateImmutableArrayBuffer (or ArrayBufferCopyAndDetach, depending on what is simpler) appropriately.
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.
More precisely, as mentioned below, HTML should only be creating the ArrayBuffer, and then calling CreateBytesModule from the proposal.
So it's only the create an ArrayBuffer algorithm which needs updated with the new parameter, not the algorithm for creating new views like Uint8Array.
source
Outdated
script</span> algorithm. Bytes module scripts represent binary data as Uint8Array backed by | ||
an immutable ArrayBuffer.</p> |
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.
Might need to add references for both Uint8Array
and Immutable Array Buffer
here.
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.
Fixed in b894372
source
Outdated
<!-- | ||
This definition is not super-rigorous, but it doesn't need to be for now. If we ever start | ||
testing if something is a Bytes module script in algorithms, instead of just referring to the | ||
concept, then we should consider adding a type item to the module script struct. | ||
--> |
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.
This definition is perfectly rigorous IMO - a bytes module script === the output of the creating a bytes module script steps. That's the definition.
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.
Removed in 9647411
<li><p>Let <var>result</var> be a new <code>Uint8Array</code> object, in <var>settings</var>'s | ||
<span data-x="environment settings object's realm">realm</span>, whose backing bytes are <var>bytes</var>.</p></li> |
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.
This needs to initialize and reference the immutable array buffer spec as well, as a direct reference to https://tc39.es/proposal-immutable-arraybuffer/#sec-arraybuffer-objects.
Also we only need to create the ArrayBuffer here that is immutable, the Uint8Array typed array view is added on the TC39 spec side.
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.
I'm not sure I fully understand. Mind leaving a code suggestion?
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.
I think we want to use Web IDL for this, similar to what the Encoding Standard does for instance. But to make the backing buffer immutable we'll have to make a small change to Web IDL to allow for that.
source
Outdated
<li><p>Set <var>script</var>'s <span data-x="concept-script-record">record</span> to the result | ||
of <span>CreateDefaultExportSyntheticModule</span>(<var>result</var>).</p></li> |
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.
Rather than calling CreatedefaultExportSyntheticModule
directly, it would be good to reference the TC39 spec here by making this:
<li><p>Let <var>record</var> be <span>CreateBytesModule</span>(<var>immutableBytes</var>).</p>
<li><p>Set <var>script</var>'s <span data-x="concept-script-record">record</span> to <var>record</var>.</p></li>
sort of thing.
Where CreateBytesModule
is then a reference to the https://tc39.es/proposal-import-bytes/ spec.
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.
Added in 9828655
@guybedford @nicolo-ribaudo How's that look now?
<li><p>Set <var>script</var>'s <span data-x="concept-script-parse-error">parse error</span> and | ||
<span data-x="concept-script-error-to-rethrow">error to rethrow</span> to null.</p></li> | ||
|
||
<li><p>Let <var>result</var> be a new <code>Uint8Array</code> object, in <var>settings</var>'s |
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.
Yeah, you might have to add a new argument for that or a separate operation.
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.
To see how to link to a proposal, search for <ref>JSDYNAMICCODEBRANDCHECKS</ref>
and [JSDYNAMICCODEBRANDCHECKS]
through the document.
b6deeac
to
e5b9757
Compare
|
||
<p>The <span>bytes module script</span> will return a <code>Uint8Array</code> object containing | ||
the raw bytes of the fetched resource. Unlike <span data-x="JSON module script">JSON module scripts</span> | ||
which require a specific MIME type, bytes modules can be used to import binary data from any resource.</p> |
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.
which require a specific MIME type, bytes modules can be used to import binary data from any resource.</p> | |
which require a specific MIME type, bytes module scripts can be used to import binary data from any resource.</p> |
<p>A <span>module script</span> is a <dfn export>bytes module script</dfn> if its <span | ||
data-x="concept-script-record">record</span> is a <span>Synthetic Module Record</span>, and it | ||
was created via the <span data-x="creating a bytes module script">create a bytes module | ||
script</span> algorithm. bytes module scripts represent binary data as <code>Uint8Array</code> |
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.
script</span> algorithm. bytes module scripts represent binary data as <code>Uint8Array</code> | |
script</span> algorithm. Bytes module scripts represent binary data as <code>Uint8Array</code> |
|
||
<li><p>Let <var>record</var> be <span>CreateBytesModule</span>(<var>immutableBytes</var>).</p></li> | ||
|
||
<ref>JSIMPORTBYTES</ref> |
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.
This appears in the wrong place. It should usually appear just before a </p>
.
<li><p>Return <var>script</var>.</p></li> | ||
</ol> | ||
|
||
<p>User agents that support JavaScript must also implement the <cite>Import Bytes</cite> proposal. |
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.
Indentation here is wrong.
<p>User agents that support JavaScript must also implement the <cite>Import Bytes</cite> proposal. | ||
The following terms are defined there, and used in this specification: <ref>JSIMPORTBYTES</ref></p> |
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.
This seems to be in the wrong place as well?
<var>settingsObject</var>, <var>response</var>'s <span | ||
data-x="concept-response-url">URL</span>, and <var>options</var>.</p></li> | ||
|
||
<li><p>If <var>moduleType</var> is "<code data-x="">bytes</code>", then set <var>moduleScript</var> to |
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.
I would move this before <li><p>Let <var>referrerPolicy</var> be the result of ...
, and put the steps from it to the one that created the various other module scrips in an Else clause.
It's just an editorial suggestion to make it clear that those steps are useless for bytes module scripts, it does not actually affect behavior.
(See WHATWG Working Mode: Changes for more details.)