From 7fa72e21cb5bff9da3749b155b5835060647995f Mon Sep 17 00:00:00 2001 From: Eemeli Aro Date: Thu, 20 Nov 2025 14:58:34 +0900 Subject: [PATCH 1/2] Add text imports Adds support for the `{ type: 'text' }` import attribute, which enables importing text content as a JavaScript string. --- source | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 65 insertions(+), 5 deletions(-) diff --git a/source b/source index ca1389014e0..3ba163fc407 100644 --- a/source +++ b/source @@ -3189,6 +3189,13 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
  • The HostGetCodeForEval abstract operation
  • +

    User agents that support JavaScript must also implement the Import Text proposal. + The following term is defined there, and used in this specification: JSIMPORTTEXT

    + + +

    User agents that support JavaScript must also implement ECMAScript Internationalization API. JSINTL

    @@ -116056,7 +116063,8 @@ document.querySelector("button").addEventListener("click", bound); script">JavaScript module scripts;

  • a Synthetic Module Record, for CSS module - scripts and JSON module scripts;

  • + scripts, JSON module scripts, and + text module scripts;

  • a WebAssembly Module Record, for WebAssembly module scripts; or

  • @@ -116166,6 +116174,15 @@ document.querySelector("button").addEventListener("click", bound); --> +
  • +
    +

    A module script is a text module script if its record is a Synthetic Module Record, and it + was created via the create a text module + script algorithm. Text module scripts represent a text document.

    +
    +
  • +
  • A module script is a WebAssembly module script if @@ -116175,11 +116192,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 text 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 text module scripts are always null.

    The active script is determined by the following algorithm:

    @@ -117115,6 +117132,10 @@ document.querySelector("button").addEventListener("click", bound);
  • Let sourceText be the result of UTF-8 decoding bodyBytes.

  • +
  • If moduleType is "text", then set + moduleScript to the result of creating a text module script given + sourceText and settingsObject.

  • +
  • If mimeType is a JavaScript MIME type and moduleType is "javascript-or-wasm", then set moduleScript to the result of creating a JavaScript module script given sourceText, @@ -117442,6 +117463,38 @@ document.querySelector("button").addEventListener("click", bound);

  • +
    +

    To create a text module script, given a + string text and an environment settings object settings:

    + +
      +
    1. Let script be a new module script that this algorithm will + subsequently initialize.

    2. + +
    3. Set script's settings + object to settings.

    4. + +
    5. Set script's base URL and + fetch options to null.

    6. + +
    7. Set script's parse error and + error to rethrow to null.

    8. + +
    9. +

      Let result be CreateTextModule(text).

      + +

      If this throws an exception, catch it, and set script's parse error to that exception, and return + script.

      +
    10. + +
    11. Set script's record to + result.

    12. + +
    13. Return script.

    14. +
    +
    +

    The module type from module request steps, given a ModuleRequest Record moduleRequest, are as follows:

    @@ -117480,7 +117533,8 @@ document.querySelector("button").addEventListener("click", bound);
    1. If moduleType is not "javascript-or-wasm", "css", or "json", then return false.

    2. + data-x="">css", "json", or "text", then + return false.

    3. If moduleType is "css" and the CSSStyleSheet interface is not exposed in @@ -117503,6 +117557,9 @@ document.querySelector("button").addEventListener("click", bound);

    4. If moduleType is "css", then return "style".
    5. +
    6. If moduleType is "text", then return "text".
    7. +
    8. Return defaultDestination.
    @@ -155474,6 +155531,9 @@ INSERT INTERFACES HERE
    [JSDYNAMICCODEBRANDCHECKS]
    Dynamic code brand checks. Ecma International.
    +
    [JSIMPORTTEXT]
    +
    Import Text. Ecma International.
    +
    [JSINTL]
    ECMAScript Internationalization API Specification. Ecma International.
    From 2b4eeaf662ec1f1b6b187f029ae088a08e5c7066 Mon Sep 17 00:00:00 2001 From: Eemeli Aro Date: Wed, 17 Dec 2025 17:37:44 +0200 Subject: [PATCH 2/2] Fix CreateTextModule definition + ignore mimetype when preloading text modules --- source | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source b/source index 3ba163fc407..8c20bc9dc77 100644 --- a/source +++ b/source @@ -3193,7 +3193,7 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute The following term is defined there, and used in this specification: JSIMPORTTEXT

    User agents that support JavaScript must also implement ECMAScript @@ -28940,7 +28940,7 @@ document.body.appendChild(wbr);

    1. If type is an empty string, then return true.

    2. -
    3. If destination is "fetch", then return true.

    4. +
    5. If destination is "fetch" or "text", then return true.

    6. Let mimeTypeRecord be the result of parsing type.