Skip to content

Commit b6deeac

Browse files
committed
add import bytes
1 parent abb4ae5 commit b6deeac

File tree

1 file changed

+66
-5
lines changed

1 file changed

+66
-5
lines changed

source

Lines changed: 66 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64215,6 +64215,21 @@ o............A....e
6421564215
response has a MIME type that is not a <span>JavaScript MIME type</span>.</p>
6421664216
</div>
6421764217

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="">&lt;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+
&lt;/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+
6421864233
<div w-nodev>
6421964234

6422064235
<h5 id="script-processing-model">Processing model</h5>
@@ -112113,7 +112128,7 @@ document.querySelector("button").addEventListener("click", bound);
112113112128
script">JavaScript module scripts</span>;</p></li>
112114112129

112115112130
<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>
112117112132

112118112133
<li><p>a <span>WebAssembly Module Record</span>, for <span data-x="WebAssembly module
112119112134
script">WebAssembly module scripts</span>; or</p></li>
@@ -112215,18 +112230,32 @@ document.querySelector("button").addEventListener("click", bound);
112215112230
-->
112216112231
</li>
112217112232

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+
112218112247
<li>
112219112248
<p>A <span>module script</span> is a <dfn export>WebAssembly module script</dfn> if
112220112249
its <span data-x="concept-script-record">record</span> is a <span>WebAssembly Module
112221112250
Record</span>.</p>
112222112251
</li>
112223112252
</ul>
112224112253

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
112226112255
throw exceptions on evaluation, the <span data-x="concept-script-script-fetch-options">fetch
112227112256
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>
112230112259

112231112260
<p>The <dfn>active script</dfn> is determined by the following algorithm:</p>
112232112261

@@ -113121,6 +113150,10 @@ document.querySelector("button").addEventListener("click", bound);
113121113150
<var>settingsObject</var>, <var>response</var>'s <span
113122113151
data-x="concept-response-url">URL</span>, and <var>options</var>.</p></li>
113123113152

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+
113124113157
<li>
113125113158
<p>Otherwise:</p>
113126113159
<ol>
@@ -113441,6 +113474,31 @@ document.querySelector("button").addEventListener("click", bound);
113441113474
<li><p>Return <var>script</var>.</p></li>
113442113475
</ol>
113443113476

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+
113444113502
<p>The <dfn>module type from module request</dfn> steps, given a <span>ModuleRequest
113445113503
Record</span> <var>moduleRequest</var>, are as follows:</p>
113446113504

@@ -113476,7 +113534,7 @@ document.querySelector("button").addEventListener("click", bound);
113476113534

113477113535
<ol>
113478113536
<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>
113480113538

113481113539
<li><p>If <var>moduleType</var> is "<code data-x="">css</code>" and the
113482113540
<code>CSSStyleSheet</code> interface is not <span data-x="idl-exposed">exposed</span> in
@@ -113497,6 +113555,9 @@ document.querySelector("button").addEventListener("click", bound);
113497113555
<li>If <var>moduleType</var> is "<code data-x="">css</code>", then return "<code
113498113556
data-x="">style</code>".</li>
113499113557

113558+
<li>If <var>moduleType</var> is "<code data-x="">bytes</code>", then return "<code
113559+
data-x="">empty</code>".</li>
113560+
113500113561
<li>Return <var>defaultDestination</var>.</li>
113501113562
</ol>
113502113563

0 commit comments

Comments
 (0)