@@ -64215,6 +64215,21 @@ o............A....e
64215
64215
response has a MIME type that is not a <span>JavaScript MIME type</span>.</p>
64216
64216
</div>
64217
64217
64218
+ <div class="example" id="bytes-module-script-example">
64219
+ <p>The following sample shows how a <span>bytes module script</span> can be imported from inside
64220
+ a <span>JavaScript module script</span>:</p>
64221
+
64222
+ <pre><code class="html" data-x=""><script type="module">
64223
+ import logoBytes from "https://resources.whatwg.org/logo.png" with { type: "bytes" };
64224
+
64225
+ console.log("Binary data length:", logoBytes.byteLength);
64226
+ </script></code></pre>
64227
+
64228
+ <p>The <span>Bytes module script</span> will return a <code>Uint8Array</code> object containing
64229
+ the raw bytes of the fetched resource. Unlike <span data-x="JSON module script">JSON module scripts</span>
64230
+ which require a specific MIME type, bytes modules can be used to import binary data from any resource.</p>
64231
+ </div>
64232
+
64218
64233
<div w-nodev>
64219
64234
64220
64235
<h5 id="script-processing-model">Processing model</h5>
@@ -112113,7 +112128,7 @@ document.querySelector("button").addEventListener("click", bound);
112113
112128
script">JavaScript module scripts</span>;</p></li>
112114
112129
112115
112130
<li><p>a <span>Synthetic Module Record</span>, for <span data-x="CSS module script">CSS module
112116
- scripts</span> and <span data-x="JSON module script">JSON module scripts</span>;</p></li>
112131
+ scripts</span>, <span data-x="JSON module script">JSON module scripts</span>, and <span data-x="Bytes module script">Bytes module scripts</span>;</p></li>
112117
112132
112118
112133
<li><p>a <span>WebAssembly Module Record</span>, for <span data-x="WebAssembly module
112119
112134
script">WebAssembly module scripts</span>; or</p></li>
@@ -112215,18 +112230,32 @@ document.querySelector("button").addEventListener("click", bound);
112215
112230
-->
112216
112231
</li>
112217
112232
112233
+ <li>
112234
+ <p>A <span>module script</span> is a <dfn export>Bytes module script</dfn> if its <span
112235
+ data-x="concept-script-record">record</span> is a <span>Synthetic Module Record</span>, and it
112236
+ was created via the <span data-x="creating a Bytes module script">create a Bytes module
112237
+ script</span> algorithm. Bytes module scripts represent binary data as Uint8Array backed by
112238
+ an immutable ArrayBuffer.</p>
112239
+
112240
+ <!--
112241
+ This definition is not super-rigorous, but it doesn't need to be for now. If we ever start
112242
+ testing if something is a Bytes module script in algorithms, instead of just referring to the
112243
+ concept, then we should consider adding a type item to the module script struct.
112244
+ -->
112245
+ </li>
112246
+
112218
112247
<li>
112219
112248
<p>A <span>module script</span> is a <dfn export>WebAssembly module script</dfn> if
112220
112249
its <span data-x="concept-script-record">record</span> is a <span>WebAssembly Module
112221
112250
Record</span>.</p>
112222
112251
</li>
112223
112252
</ul>
112224
112253
112225
- <p class="note">As CSS stylesheets and JSON documents do not import dependent modules, and do not
112254
+ <p class="note">As CSS stylesheets, JSON documents, and binary data do not import dependent modules, and do not
112226
112255
throw exceptions on evaluation, the <span data-x="concept-script-script-fetch-options">fetch
112227
112256
options</span> and <span data-x="concept-script-base-url">base URL</span> of <span data-x="CSS
112228
- module script">CSS module scripts</span> and <span data-x="JSON module script">JSON module
112229
- scripts</span> and are always null.</p>
112257
+ module script">CSS module scripts</span>, <span data-x="JSON module script">JSON module
112258
+ scripts</span>, and <span data-x="Bytes module script">Bytes module scripts</span> are always null.</p>
112230
112259
112231
112260
<p>The <dfn>active script</dfn> is determined by the following algorithm:</p>
112232
112261
@@ -113121,6 +113150,10 @@ document.querySelector("button").addEventListener("click", bound);
113121
113150
<var>settingsObject</var>, <var>response</var>'s <span
113122
113151
data-x="concept-response-url">URL</span>, and <var>options</var>.</p></li>
113123
113152
113153
+ <li><p>If <var>moduleType</var> is "<code data-x="">bytes</code>", then set <var>moduleScript</var> to
113154
+ the result of <span>creating a Bytes module script</span> given <var>bodyBytes</var> and
113155
+ <var>settingsObject</var>.</p></li>
113156
+
113124
113157
<li>
113125
113158
<p>Otherwise:</p>
113126
113159
<ol>
@@ -113441,6 +113474,31 @@ document.querySelector("button").addEventListener("click", bound);
113441
113474
<li><p>Return <var>script</var>.</p></li>
113442
113475
</ol>
113443
113476
113477
+ <p>To <dfn data-x="creating a Bytes module script">create a Bytes module script</dfn>, given a
113478
+ byte sequence <var>bytes</var> and an <span>environment settings object</span> <var>settings</var>:</p>
113479
+
113480
+ <ol>
113481
+ <li><p>Let <var>script</var> be a new <span>module script</span> that this algorithm will
113482
+ subsequently initialize.</p></li>
113483
+
113484
+ <li><p>Set <var>script</var>'s <span data-x="concept-script-settings-object">settings
113485
+ object</span> to <var>settings</var>.</p></li>
113486
+
113487
+ <li><p>Set <var>script</var>'s <span data-x="concept-script-base-url">base URL</span> and
113488
+ <span data-x="concept-script-script-fetch-options">fetch options</span> to null.</p></li>
113489
+
113490
+ <li><p>Set <var>script</var>'s <span data-x="concept-script-parse-error">parse error</span> and
113491
+ <span data-x="concept-script-error-to-rethrow">error to rethrow</span> to null.</p></li>
113492
+
113493
+ <li><p>Let <var>result</var> be a new <code>Uint8Array</code> object, in <var>settings</var>'s
113494
+ <span data-x="environment settings object's realm">realm</span>, whose backing bytes are <var>bytes</var>.</p></li>
113495
+
113496
+ <li><p>Set <var>script</var>'s <span data-x="concept-script-record">record</span> to the result
113497
+ of <span>CreateDefaultExportSyntheticModule</span>(<var>result</var>).</p></li>
113498
+
113499
+ <li><p>Return <var>script</var>.</p></li>
113500
+ </ol>
113501
+
113444
113502
<p>The <dfn>module type from module request</dfn> steps, given a <span>ModuleRequest
113445
113503
Record</span> <var>moduleRequest</var>, are as follows:</p>
113446
113504
@@ -113476,7 +113534,7 @@ document.querySelector("button").addEventListener("click", bound);
113476
113534
113477
113535
<ol>
113478
113536
<li><p>If <var>moduleType</var> is not "<code data-x="">javascript-or-wasm</code>", "<code
113479
- data-x="">css</code>", or "<code data-x="">json </code>", then return false.</p></li>
113537
+ data-x="">css</code>", "<code data-x="">json</code>", or "<code data-x="">bytes </code>", then return false.</p></li>
113480
113538
113481
113539
<li><p>If <var>moduleType</var> is "<code data-x="">css</code>" and the
113482
113540
<code>CSSStyleSheet</code> interface is not <span data-x="idl-exposed">exposed</span> in
@@ -113497,6 +113555,9 @@ document.querySelector("button").addEventListener("click", bound);
113497
113555
<li>If <var>moduleType</var> is "<code data-x="">css</code>", then return "<code
113498
113556
data-x="">style</code>".</li>
113499
113557
113558
+ <li>If <var>moduleType</var> is "<code data-x="">bytes</code>", then return "<code
113559
+ data-x="">empty</code>".</li>
113560
+
113500
113561
<li>Return <var>defaultDestination</var>.</li>
113501
113562
</ol>
113502
113563
0 commit comments