Skip to content

Commit 0045b78

Browse files
authored
Add text imports
Adds support for the `{ type: 'text' }` import attribute, which enables importing text content as a JavaScript string. Part of #9444
1 parent f831ea0 commit 0045b78

File tree

1 file changed

+61
-6
lines changed

1 file changed

+61
-6
lines changed

source

Lines changed: 61 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3194,6 +3194,13 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
31943194
<li>The <dfn data-x="js-HostGetCodeForEval" data-x-href="https://tc39.es/proposal-dynamic-code-brand-checks/#sec-hostgetcodeforeval">HostGetCodeForEval</dfn> abstract operation</li>
31953195
</ul>
31963196

3197+
<p>User agents that support JavaScript must also implement the <cite>Import Text</cite> proposal.
3198+
The following term is defined there, and used in this specification: <ref>JSIMPORTTEXT</ref></p>
3199+
3200+
<ul class="brief">
3201+
<li>The <dfn data-x-href="https://tc39.es/proposal-import-text/#sec-create-text-module">CreateTextModule</dfn> abstract operation</li>
3202+
</ul>
3203+
31973204
<p>User agents that support JavaScript must also implement <cite>ECMAScript
31983205
Internationalization API</cite>. <ref>JSINTL</ref></p>
31993206

@@ -28631,7 +28638,7 @@ document.body.appendChild(wbr);</code></pre>
2863128638
<p>A user agent must not <span>delay the load event</span> for this link type.</p>
2863228639

2863328640
<p>A <dfn>module preload destination</dfn> is "<code data-x="">json</code>", "<code
28634-
data-x="">style</code>", or a <span
28641+
data-x="">style</code>", "<code data-x="">text</code>", or a <span
2863528642
data-x="concept-script-like-destination">script-like destination</span>.</p>
2863628643

2863728644
<div algorithm>
@@ -117042,7 +117049,8 @@ document.querySelector("button").addEventListener("click", bound);
117042117049
script">JavaScript module scripts</span>;</p></li>
117043117050

117044117051
<li><p>a <span>Synthetic Module Record</span>, for <span data-x="CSS module script">CSS module
117045-
scripts</span> and <span data-x="JSON module script">JSON module scripts</span>;</p></li>
117052+
scripts</span>, <span data-x="JSON module script">JSON module scripts</span>, and
117053+
<span data-x="text module script">text module scripts</span>;</p></li>
117046117054

117047117055
<li><p>a <span>WebAssembly Module Record</span>, for <span data-x="WebAssembly module
117048117056
script">WebAssembly module scripts</span>; or</p></li>
@@ -117152,6 +117160,15 @@ document.querySelector("button").addEventListener("click", bound);
117152117160
-->
117153117161
</li>
117154117162

117163+
<li>
117164+
<div algorithm>
117165+
<p>A <span>module script</span> is a <dfn export>text module script</dfn> if its <span
117166+
data-x="concept-script-record">record</span> is a <span>Synthetic Module Record</span>, and it
117167+
was created via the <span data-x="creating a text module script">create a text module
117168+
script</span> algorithm. Text module scripts represent textual data encoded as UTF-8.</p>
117169+
</div>
117170+
</li>
117171+
117155117172
<li>
117156117173
<div algorithm>
117157117174
<p>A <span>module script</span> is a <dfn export>WebAssembly module script</dfn> if
@@ -117161,11 +117178,11 @@ document.querySelector("button").addEventListener("click", bound);
117161117178
</li>
117162117179
</ul>
117163117180

117164-
<p class="note">As CSS style sheets and JSON documents do not import dependent modules, and do not
117181+
<p class="note">As CSS style sheets, JSON documents, and text do not import dependent modules, and do not
117165117182
throw exceptions on evaluation, the <span data-x="concept-script-script-fetch-options">fetch
117166117183
options</span> and <span data-x="concept-script-base-url">base URL</span> of <span data-x="CSS
117167-
module script">CSS module scripts</span> and <span data-x="JSON module script">JSON module
117168-
scripts</span> and are always null.</p>
117184+
module script">CSS module scripts</span>, <span data-x="JSON module script">JSON module
117185+
scripts</span>, and <span data-x="text module script">text module scripts</span> are always null.</p>
117169117186

117170117187
<div algorithm>
117171117188
<p>The <dfn>active script</dfn> is determined by the following algorithm:</p>
@@ -118101,6 +118118,10 @@ document.querySelector("button").addEventListener("click", bound);
118101118118
<li><p>Let <var>sourceText</var> be the result of <span data-x="UTF-8 decode">UTF-8
118102118119
decoding</span> <var>bodyBytes</var>.</p></li>
118103118120

118121+
<li><p>If <var>moduleType</var> is "<code data-x="">text</code>", then set
118122+
<var>moduleScript</var> to the result of <span>creating a text module script</span> given
118123+
<var>sourceText</var> and <var>settingsObject</var>.</p></li>
118124+
118104118125
<li><p>If <var>mimeType</var> is a <span>JavaScript MIME type</span> and <var>moduleType</var>
118105118126
is "<code data-x="">javascript-or-wasm</code>", then set <var>moduleScript</var> to the result of
118106118127
<span>creating a JavaScript module script</span> given <var>sourceText</var>,
@@ -118453,6 +118474,32 @@ document.querySelector("button").addEventListener("click", bound);
118453118474
</ol>
118454118475
</div>
118455118476

118477+
<div algorithm>
118478+
<p>To <dfn data-x="creating a text module script">create a text module script</dfn>, given a
118479+
string <var>text</var> and an <span>environment settings object</span> <var>settings</var>:</p>
118480+
118481+
<ol>
118482+
<li><p>Let <var>script</var> be a new <span>module script</span> that this algorithm will
118483+
subsequently initialize.</p></li>
118484+
118485+
<li><p>Set <var>script</var>'s <span data-x="concept-script-settings-object">settings
118486+
object</span> to <var>settings</var>.</p></li>
118487+
118488+
<li><p>Set <var>script</var>'s <span data-x="concept-script-base-url">base URL</span> and
118489+
<span data-x="concept-script-script-fetch-options">fetch options</span> to null.</p></li>
118490+
118491+
<li><p>Set <var>script</var>'s <span data-x="concept-script-parse-error">parse error</span> and
118492+
<span data-x="concept-script-error-to-rethrow">error to rethrow</span> to null.</p></li>
118493+
118494+
<li><p>Let <var>result</var> be <span>CreateTextModule</span>(<var>text</var>).</p></li>
118495+
118496+
<li><p>Set <var>script</var>'s <span data-x="concept-script-record">record</span> to
118497+
<var>result</var>.</p></li>
118498+
118499+
<li><p>Return <var>script</var>.</p></li>
118500+
</ol>
118501+
</div>
118502+
118456118503
<div algorithm>
118457118504
<p>The <dfn>module type from module request</dfn> steps, given a <span>ModuleRequest
118458118505
Record</span> <var>moduleRequest</var>, are as follows:</p>
@@ -118491,7 +118538,8 @@ document.querySelector("button").addEventListener("click", bound);
118491118538

118492118539
<ol>
118493118540
<li><p>If <var>moduleType</var> is not "<code data-x="">javascript-or-wasm</code>", "<code
118494-
data-x="">css</code>", or "<code data-x="">json</code>", then return false.</p></li>
118541+
data-x="">css</code>", "<code data-x="">json</code>", or "<code data-x="">text</code>", then
118542+
return false.</p></li>
118495118543

118496118544
<li><p>If <var>moduleType</var> is "<code data-x="">css</code>" and the
118497118545
<code>CSSStyleSheet</code> interface is not <span data-x="idl-exposed">exposed</span> in
@@ -118514,6 +118562,9 @@ document.querySelector("button").addEventListener("click", bound);
118514118562
<li>If <var>moduleType</var> is "<code data-x="">css</code>", then return "<code
118515118563
data-x="">style</code>".</li>
118516118564

118565+
<li>If <var>moduleType</var> is "<code data-x="">text</code>", then return "<code
118566+
data-x="">text</code>".</li>
118567+
118517118568
<li>Return <var>defaultDestination</var>.</li>
118518118569
</ol>
118519118570
</div>
@@ -156790,6 +156841,9 @@ INSERT INTERFACES HERE
156790156841
<dt id="refsJSDYNAMICCODEBRANDCHECKS">[JSDYNAMICCODEBRANDCHECKS]</dt>
156791156842
<dd><cite><a href="https://tc39.es/proposal-dynamic-code-brand-checks/">Dynamic code brand checks</a></cite>. Ecma International.</dd>
156792156843

156844+
<dt id="refsJSIMPORTTEXT">[JSIMPORTTEXT]</dt>
156845+
<dd><cite><a href="https://tc39.es/proposal-import-text/">Import Text</a></cite>. Ecma International.</dd>
156846+
156793156847
<dt id="refsJSINTL">[JSINTL]</dt>
156794156848
<dd><cite><a href="https://tc39.es/ecma402/">ECMAScript Internationalization API Specification</a></cite>. Ecma International.</dd>
156795156849

@@ -157505,6 +157559,7 @@ INSERT INTERFACES HERE
157505157559
Eduardo Vela,
157506157560
Edward Welbourne,
157507157561
Edward Z. Yang,
157562+
Eemeli Aro, <!-- eemeli on GitHub -->
157508157563
Ehsan Akhgari,
157509157564
Ehsan Karamad,
157510157565
Eira Monstad,

0 commit comments

Comments
 (0)