Skip to content

Conversation

styfle
Copy link

@styfle styfle commented Sep 15, 2025

  • At least two implementers are interested (and none opposed):
    • Deno
  • Tests are written and can be reviewed and commented upon at:
  • Implementation bugs are filed:
    • Chromium: …
    • Gecko: …
    • WebKit: …
    • Deno (only for timers, structured clone, base64 utils, channel messaging, module resolution, web workers, and web storage): …
    • Node.js (only for timers, structured clone, base64 utils, channel messaging, and module resolution): …
  • Corresponding HTML AAM & ARIA in HTML issues & PRs:
  • MDN issue is filed: …
  • The top of this comment includes a clear commit message to use.

(See WHATWG Working Mode: Changes for more details.)

<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
Copy link
Contributor

@bakkot bakkot Sep 15, 2025

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.

Copy link
Member

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.

Copy link
Author

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?

Copy link
Contributor

@nicolo-ribaudo nicolo-ribaudo Sep 17, 2025

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.

Copy link
Contributor

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
Comment on lines 112237 to 112238
script</span> algorithm. Bytes module scripts represent binary data as Uint8Array backed by
an immutable ArrayBuffer.</p>
Copy link
Contributor

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.

Copy link
Author

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
Comment on lines 112240 to 112244
<!--
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.
-->
Copy link
Contributor

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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed in 9647411

Comment on lines 113493 to 113494
<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>
Copy link
Contributor

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.

Copy link
Author

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?

Copy link
Member

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
Comment on lines 113496 to 113497
<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>
Copy link
Contributor

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.

Copy link
Author

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
Copy link
Member

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.

Copy link
Contributor

@nicolo-ribaudo nicolo-ribaudo left a 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.

@styfle styfle force-pushed the styfle/import-bytes branch from b6deeac to e5b9757 Compare September 17, 2025 00:05

<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>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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>
Copy link
Member

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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation here is wrong.

Comment on lines +113489 to +113490
<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>
Copy link
Member

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
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

5 participants