@@ -64211,6 +64211,21 @@ o............A....e
64211
64211
response has a MIME type that is not a <span>JavaScript MIME type</span>.</p>
64212
64212
</div>
64213
64213
64214
+ <div class="example" id="bytes-module-script-example">
64215
+ <p>The following sample shows how a <span>bytes module script</span> can be imported from inside
64216
+ a <span>JavaScript module script</span>:</p>
64217
+
64218
+ <pre><code class="html" data-x=""><script type="module">
64219
+ import logoBytes from "https://resources.whatwg.org/logo.png" with { type: "bytes" };
64220
+
64221
+ console.log("Binary data length:", logoBytes.byteLength);
64222
+ </script></code></pre>
64223
+
64224
+ <p>The <span>Bytes module script</span> will return a <code>Uint8Array</code> object containing
64225
+ the raw bytes of the fetched resource. Unlike <span data-x="JSON module script">JSON module scripts</span>
64226
+ which require a specific MIME type, bytes modules can be used to import binary data from any resource.</p>
64227
+ </div>
64228
+
64214
64229
<div w-nodev>
64215
64230
64216
64231
<h5 id="script-processing-model">Processing model</h5>
@@ -112104,7 +112119,7 @@ document.querySelector("button").addEventListener("click", bound);
112104
112119
script">JavaScript module scripts</span>;</p></li>
112105
112120
112106
112121
<li><p>a <span>Synthetic Module Record</span>, for <span data-x="CSS module script">CSS module
112107
- scripts</span> and <span data-x="JSON module script">JSON module scripts</span>;</p></li>
112122
+ 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>
112108
112123
112109
112124
<li><p>a <span>WebAssembly Module Record</span>, for <span data-x="WebAssembly module
112110
112125
script">WebAssembly module scripts</span>; or</p></li>
@@ -112206,18 +112221,32 @@ document.querySelector("button").addEventListener("click", bound);
112206
112221
-->
112207
112222
</li>
112208
112223
112224
+ <li>
112225
+ <p>A <span>module script</span> is a <dfn export>Bytes module script</dfn> if its <span
112226
+ data-x="concept-script-record">record</span> is a <span>Synthetic Module Record</span>, and it
112227
+ was created via the <span data-x="creating a Bytes module script">create a Bytes module
112228
+ script</span> algorithm. Bytes module scripts represent binary data as Uint8Array backed by
112229
+ an immutable ArrayBuffer.</p>
112230
+
112231
+ <!--
112232
+ This definition is not super-rigorous, but it doesn't need to be for now. If we ever start
112233
+ testing if something is a Bytes module script in algorithms, instead of just referring to the
112234
+ concept, then we should consider adding a type item to the module script struct.
112235
+ -->
112236
+ </li>
112237
+
112209
112238
<li>
112210
112239
<p>A <span>module script</span> is a <dfn export>WebAssembly module script</dfn> if
112211
112240
its <span data-x="concept-script-record">record</span> is a <span>WebAssembly Module
112212
112241
Record</span>.</p>
112213
112242
</li>
112214
112243
</ul>
112215
112244
112216
- <p class="note">As CSS style sheets and JSON documents do not import dependent modules, and do not
112245
+ <p class="note">As CSS stylesheets, JSON documents, and binary data do not import dependent modules, and do not
112217
112246
throw exceptions on evaluation, the <span data-x="concept-script-script-fetch-options">fetch
112218
112247
options</span> and <span data-x="concept-script-base-url">base URL</span> of <span data-x="CSS
112219
- module script">CSS module scripts</span> and <span data-x="JSON module script">JSON module
112220
- scripts</span> and are always null.</p>
112248
+ module script">CSS module scripts</span>, <span data-x="JSON module script">JSON module
112249
+ scripts</span>, and <span data-x="Bytes module script">Bytes module scripts</span> are always null.</p>
112221
112250
112222
112251
<p>The <dfn>active script</dfn> is determined by the following algorithm:</p>
112223
112252
@@ -113112,6 +113141,10 @@ document.querySelector("button").addEventListener("click", bound);
113112
113141
<var>settingsObject</var>, <var>response</var>'s <span
113113
113142
data-x="concept-response-url">URL</span>, and <var>options</var>.</p></li>
113114
113143
113144
+ <li><p>If <var>moduleType</var> is "<code data-x="">bytes</code>", then set <var>moduleScript</var> to
113145
+ the result of <span>creating a Bytes module script</span> given <var>bodyBytes</var> and
113146
+ <var>settingsObject</var>.</p></li>
113147
+
113115
113148
<li>
113116
113149
<p>Otherwise:</p>
113117
113150
<ol>
@@ -113432,6 +113465,31 @@ document.querySelector("button").addEventListener("click", bound);
113432
113465
<li><p>Return <var>script</var>.</p></li>
113433
113466
</ol>
113434
113467
113468
+ <p>To <dfn data-x="creating a Bytes module script">create a Bytes module script</dfn>, given a
113469
+ byte sequence <var>bytes</var> and an <span>environment settings object</span> <var>settings</var>:</p>
113470
+
113471
+ <ol>
113472
+ <li><p>Let <var>script</var> be a new <span>module script</span> that this algorithm will
113473
+ subsequently initialize.</p></li>
113474
+
113475
+ <li><p>Set <var>script</var>'s <span data-x="concept-script-settings-object">settings
113476
+ object</span> to <var>settings</var>.</p></li>
113477
+
113478
+ <li><p>Set <var>script</var>'s <span data-x="concept-script-base-url">base URL</span> and
113479
+ <span data-x="concept-script-script-fetch-options">fetch options</span> to null.</p></li>
113480
+
113481
+ <li><p>Set <var>script</var>'s <span data-x="concept-script-parse-error">parse error</span> and
113482
+ <span data-x="concept-script-error-to-rethrow">error to rethrow</span> to null.</p></li>
113483
+
113484
+ <li><p>Let <var>result</var> be a new <code>Uint8Array</code> object, in <var>settings</var>'s
113485
+ <span data-x="environment settings object's realm">realm</span>, whose backing bytes are <var>bytes</var>.</p></li>
113486
+
113487
+ <li><p>Set <var>script</var>'s <span data-x="concept-script-record">record</span> to the result
113488
+ of <span>CreateDefaultExportSyntheticModule</span>(<var>result</var>).</p></li>
113489
+
113490
+ <li><p>Return <var>script</var>.</p></li>
113491
+ </ol>
113492
+
113435
113493
<p>The <dfn>module type from module request</dfn> steps, given a <span>ModuleRequest
113436
113494
Record</span> <var>moduleRequest</var>, are as follows:</p>
113437
113495
@@ -113467,7 +113525,7 @@ document.querySelector("button").addEventListener("click", bound);
113467
113525
113468
113526
<ol>
113469
113527
<li><p>If <var>moduleType</var> is not "<code data-x="">javascript-or-wasm</code>", "<code
113470
- data-x="">css</code>", or "<code data-x="">json </code>", then return false.</p></li>
113528
+ data-x="">css</code>", "<code data-x="">json</code>", or "<code data-x="">bytes </code>", then return false.</p></li>
113471
113529
113472
113530
<li><p>If <var>moduleType</var> is "<code data-x="">css</code>" and the
113473
113531
<code>CSSStyleSheet</code> interface is not <span data-x="idl-exposed">exposed</span> in
@@ -113488,6 +113546,9 @@ document.querySelector("button").addEventListener("click", bound);
113488
113546
<li>If <var>moduleType</var> is "<code data-x="">css</code>", then return "<code
113489
113547
data-x="">style</code>".</li>
113490
113548
113549
+ <li>If <var>moduleType</var> is "<code data-x="">bytes</code>", then return "<code
113550
+ data-x="">empty</code>".</li>
113551
+
113491
113552
<li>Return <var>defaultDestination</var>.</li>
113492
113553
</ol>
113493
113554
0 commit comments