[webkit-changes] [WebKit/WebKit] c40873: Module scripts should always decode using UTF-8

Chris Dumez noreply at github.com
Mon Jan 23 16:21:58 PST 2023


  Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: c40873d23eeadf0fe542b79eca7652f9f19689f5
      https://github.com/WebKit/WebKit/commit/c40873d23eeadf0fe542b79eca7652f9f19689f5
  Author: Chris Dumez <cdumez at apple.com>
  Date:   2023-01-23 (Mon, 23 Jan 2023)

  Changed paths:
    A LayoutTests/http/wpt/html/semantics/scripting-1/the-script-element/module/module-fails-decoding-then-load-as-classic-script-expected.txt
    A LayoutTests/http/wpt/html/semantics/scripting-1/the-script-element/module/module-fails-decoding-then-load-as-classic-script.html
    M LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/module/charset-01-expected.txt
    M LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/module/charset-02-expected.txt
    M LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/module/charset-03-expected.txt
    M Source/WebCore/bindings/js/CachedScriptSourceProvider.h
    M Source/WebCore/loader/cache/CachedScript.cpp
    M Source/WebCore/loader/cache/CachedScript.h

  Log Message:
  -----------
  Module scripts should always decode using UTF-8
https://bugs.webkit.org/show_bug.cgi?id=203481
rdar://98222621

Reviewed by Youenn Fablet.

By default, CachedScript tries to use the best encoding when decoding script
data. However, per the specification [1], we should always decode as UTF-8 when
it is used as a module (unlike in the classic script case).

This patch adds a ShouldDecodeAsUTF8Only to CachedScript::script() and
scriptHash() and updates CachedScriptSourceProvider pass
ShouldDecodeAsUTF8Only::Yes when used for a module script.

I believe that in theory, the same CachedScript could be used both for a module
script and a classic script, which is why I implemented it this way.

[1] https://html.spec.whatwg.org/multipage/webappapis.html#fetch-a-single-module-script (step 12.2)

* LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/module/charset-01-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/module/charset-02-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/module/charset-03-expected.txt:
Rebaseline tests that are now passing.

* Source/WebCore/bindings/js/CachedScriptSourceProvider.h:
(WebCore::CachedScriptSourceProvider::hash const):
(WebCore::CachedScriptSourceProvider::source const):
(): Deleted.
* Source/WebCore/loader/cache/CachedScript.cpp:
(WebCore::CachedScript::script):
(WebCore::CachedScript::scriptHash):
* Source/WebCore/loader/cache/CachedScript.h:

Canonical link: https://commits.webkit.org/259251@main




More information about the webkit-changes mailing list