diff --git a/source b/source index bf6b1fb9326..ac38ed953aa 100644 --- a/source +++ b/source @@ -64211,6 +64211,21 @@ o............A....e response has a MIME type that is not a JavaScript MIME type.
+The following sample shows how a bytes module script can be imported from inside + a JavaScript module script:
+ +<script type="module">
+ import logoBytes from "https://resources.whatwg.org/logo.png" with { type: "bytes" };
+
+ console.log("Binary data length:", logoBytes.byteLength);
+</script>
+
+ The bytes module script will return a Uint8Array
object containing
+ the raw bytes of the fetched resource. Unlike JSON module scripts
+ which require a specific MIME type, bytes modules can be used to import binary data from any resource.
a Synthetic Module Record, for CSS module - scripts and JSON module scripts;
a WebAssembly Module Record, for WebAssembly module scripts; or
A module script is a bytes module script if its record is a Synthetic Module Record, and it
+ was created via the create a bytes module
+ script algorithm. bytes module scripts represent binary data as Uint8Array
+ backed by an immutable ArrayBuffer
.
A module script is a WebAssembly module script if its record is a WebAssembly Module @@ -112213,11 +112236,11 @@ document.querySelector("button").addEventListener("click", bound);
As CSS style sheets and JSON documents do not import dependent modules, and do not +
As CSS style sheets, JSON documents, and binary data do not import dependent modules, and do not throw exceptions on evaluation, the fetch options and base URL of CSS module scripts and JSON module - scripts and are always null.
+ module script">CSS module scripts, JSON module + scripts, and bytes module scripts are always null.The active script is determined by the following algorithm:
@@ -113112,6 +113135,10 @@ document.querySelector("button").addEventListener("click", bound); settingsObject, response's URL, and options. +If moduleType is "bytes
", then set moduleScript to
+ the result of creating a bytes module script given bodyBytes and
+ settingsObject.
Otherwise:
Return script.
To create a bytes module script, given a + byte sequence bytes and an environment settings object settings:
+ +Let script be a new module script that this algorithm will + subsequently initialize.
Set script's settings + object to settings.
Set script's base URL and + fetch options to null.
Set script's parse error and + error to rethrow to null.
Let result be a new Uint8Array
object, in settings's
+ realm, whose backing bytes are bytes.
Let record be CreateBytesModule(immutableBytes).
Set script's record to record.
Return script.
User agents that support JavaScript must also implement the Import Bytes proposal. + The following terms are defined there, and used in this specification: JSIMPORTBYTES
+The module type from module request steps, given a ModuleRequest Record moduleRequest, are as follows:
@@ -113467,7 +113524,7 @@ document.querySelector("button").addEventListener("click", bound);If moduleType is not "javascript-or-wasm
", "css
", or "json
", then return false.
json
", or "bytes
", then return false.If moduleType is "css
" and the
CSSStyleSheet
interface is not exposed in
@@ -113488,6 +113545,9 @@ document.querySelector("button").addEventListener("click", bound);
css
", then return "style
".bytes
", then return "empty
".