Commit 7da9cf91 authored by hiroshige's avatar hiroshige Committed by Commit bot

Enable module scripts in ScriptLoader

This enables module scripts in Blink behind a flag.

This CL implements module-script-related steps of "prepare a script"
in ScriptLoader and thus makes the module implementation code paths that
are committed previously to be executed, if the runtime flag is enabled.

This CL also reorganizes the test expectations for module-related tests.

BUG=594639

Review-Url: https://codereview.chromium.org/2781713003
Cr-Commit-Position: refs/heads/master@{#467866}
parent f7b4872f
...@@ -2415,9 +2415,18 @@ crbug.com/490015 virtual/stable/http/tests/sendbeacon/beacon-blob-with-non-simpl ...@@ -2415,9 +2415,18 @@ crbug.com/490015 virtual/stable/http/tests/sendbeacon/beacon-blob-with-non-simpl
# This test fails with the stable release mode. # This test fails with the stable release mode.
crbug.com/694958 virtual/stable/http/tests/navigation/same-and-different-back.html [ Skip ] crbug.com/694958 virtual/stable/http/tests/navigation/same-and-different-back.html [ Skip ]
# These tests have console error messages whose order is not deterministic. # Failing because of module-related implementation/test issues and
crbug.com/679742 external/wpt/html/semantics/scripting-1/the-script-element/module/crossorigin.html [ Pass Failure ] # lack of inline module script support.
crbug.com/679742 external/wpt/html/semantics/scripting-1/the-script-element/module/errorhandling.html [ Pass Failure ] crbug.com/594639 external/wpt/html/semantics/scripting-1/the-script-element/module/crossorigin.html [ Failure ]
crbug.com/594639 external/wpt/html/semantics/scripting-1/the-script-element/module/errorhandling.html [ Failure ]
crbug.com/594639 external/wpt/html/semantics/scripting-1/the-script-element/module/imports.html [ Failure Crash ]
crbug.com/594639 external/wpt/html/semantics/scripting-1/the-script-element/module/execorder.html [ Failure Timeout ]
crbug.com/594639 external/wpt/html/semantics/scripting-1/the-script-element/module/instantiation-error-1.html [ Failure Crash ]
# Inline module scripts are not yet supported.
crbug.com/715369 external/wpt/html/semantics/scripting-1/the-script-element/nomodule-set-on-inline-module-script.html [ Failure ]
crbug.com/715369 fast/dom/HTMLScriptElement/module-script.html [ Failure ]
crbug.com/715369 virtual/sharedarraybuffer/fast/dom/HTMLScriptElement/module-script.html [ Failure ]
# This test has a failure console message with specific performance # This test has a failure console message with specific performance
# numbers so a consistent baseline cannot be added. This test could be # numbers so a consistent baseline cannot be added. This test could be
...@@ -2709,7 +2718,6 @@ crbug.com/626703 external/wpt/mediacapture-streams/MediaStreamTrack-end-manual.h ...@@ -2709,7 +2718,6 @@ crbug.com/626703 external/wpt/mediacapture-streams/MediaStreamTrack-end-manual.h
crbug.com/626703 external/wpt/webvtt/rendering/cues-with-video/processing-model/selectors/cue_function/underline_object/underline_with_class_object_specific_selector.html [ Failure ] crbug.com/626703 external/wpt/webvtt/rendering/cues-with-video/processing-model/selectors/cue_function/underline_object/underline_with_class_object_specific_selector.html [ Failure ]
crbug.com/626703 external/wpt/webvtt/rendering/cues-with-video/processing-model/selectors/default_styles/inherit_as_default_value_inherits_values_from_media_element.html [ Failure ] crbug.com/626703 external/wpt/webvtt/rendering/cues-with-video/processing-model/selectors/default_styles/inherit_as_default_value_inherits_values_from_media_element.html [ Failure ]
crbug.com/626703 external/wpt/pointerevents/pointerevent_click_during_capture-manual.html [ Timeout ] crbug.com/626703 external/wpt/pointerevents/pointerevent_click_during_capture-manual.html [ Timeout ]
crbug.com/626703 [ Linux ] external/wpt/html/semantics/scripting-1/the-script-element/module/execorder.html [ Timeout ]
crbug.com/626703 external/wpt/html/webappapis/scripting/processing-model-2/unhandled-promise-rejections/allow-crossorigin.html [ Timeout ] crbug.com/626703 external/wpt/html/webappapis/scripting/processing-model-2/unhandled-promise-rejections/allow-crossorigin.html [ Timeout ]
crbug.com/626703 external/wpt/html/webappapis/scripting/processing-model-2/unhandled-promise-rejections/disallow-crossorigin.html [ Timeout ] crbug.com/626703 external/wpt/html/webappapis/scripting/processing-model-2/unhandled-promise-rejections/disallow-crossorigin.html [ Timeout ]
crbug.com/626703 external/wpt/html/webappapis/idle-callbacks/cancel-invoked.html [ Timeout ] crbug.com/626703 external/wpt/html/webappapis/idle-callbacks/cancel-invoked.html [ Timeout ]
......
This is a testharness.js-based test.
PASS Unordered module script execution (parsed, unordered #1)
PASS Unordered module script execution (parsed, unordered #2)
PASS Unordered module script execution (dynamic, unordered #1)
PASS Unordered module script execution (dynamic, unordered #2)
FAIL Interlaced module/non-module script execution (parsed, async-ordered) assert_equals: Inline module-typed script element should have fired third expected 3 but got 1
PASS Interlaced module/non-module script execution (dynamic, async-ordered)
Harness: the test ran to completion.
This is a testharness.js-based test.
FAIL html-script-module-imports Uncaught SyntaxError: Unexpected token import
Harness: the test ran to completion.
This is a testharness.js-based test.
FAIL An external module script with nomodule must run Uncaught SyntaxError: Unexpected token import
Harness: the test ran to completion.
This is a testharness.js-based test.
FAIL An inline module script with nomodule must run Uncaught SyntaxError: Unexpected token import
Harness: the test ran to completion.
...@@ -39,6 +39,9 @@ class Script; ...@@ -39,6 +39,9 @@ class Script;
class ResourceFetcher; class ResourceFetcher;
class ScriptResource; class ScriptResource;
class Modulator;
class ModulePendingScriptTreeClient;
class CORE_EXPORT ScriptLoader : public GarbageCollectedFinalized<ScriptLoader>, class CORE_EXPORT ScriptLoader : public GarbageCollectedFinalized<ScriptLoader>,
public PendingScriptClient { public PendingScriptClient {
USING_GARBAGE_COLLECTED_MIXIN(ScriptLoader); USING_GARBAGE_COLLECTED_MIXIN(ScriptLoader);
...@@ -75,7 +78,7 @@ class CORE_EXPORT ScriptLoader : public GarbageCollectedFinalized<ScriptLoader>, ...@@ -75,7 +78,7 @@ class CORE_EXPORT ScriptLoader : public GarbageCollectedFinalized<ScriptLoader>,
String ScriptContent() const; String ScriptContent() const;
// Creates a PendingScript for external script whose fetch is started in // Creates a PendingScript for external script whose fetch is started in
// FetchClassicScript(). // FetchClassicScript()/FetchModuleScriptTree().
PendingScript* CreatePendingScript(); PendingScript* CreatePendingScript();
// Returns false if and only if execution was blocked. // Returns false if and only if execution was blocked.
...@@ -150,6 +153,12 @@ class CORE_EXPORT ScriptLoader : public GarbageCollectedFinalized<ScriptLoader>, ...@@ -150,6 +153,12 @@ class CORE_EXPORT ScriptLoader : public GarbageCollectedFinalized<ScriptLoader>,
CrossOriginAttributeValue, CrossOriginAttributeValue,
SecurityOrigin*, SecurityOrigin*,
const String& encoding); const String& encoding);
// https://html.spec.whatwg.org/#fetch-a-module-script-tree
void FetchModuleScriptTree(const KURL&,
Modulator*,
const String& nonce,
ParserDisposition,
WebURLRequest::FetchCredentialsMode);
bool DoExecuteScript(const Script*); bool DoExecuteScript(const Script*);
...@@ -184,9 +193,6 @@ class CORE_EXPORT ScriptLoader : public GarbageCollectedFinalized<ScriptLoader>, ...@@ -184,9 +193,6 @@ class CORE_EXPORT ScriptLoader : public GarbageCollectedFinalized<ScriptLoader>,
// https://html.spec.whatwg.org/#concept-script-type // https://html.spec.whatwg.org/#concept-script-type
// "It is determined when the script is prepared" // "It is determined when the script is prepared"
// TODO(hiroshige): Currently |script_type_| is set but ignored, and
// thus is handled as if it is a classic script even if type is "module"
// and module scripts is enabled.
ScriptType script_type_ = ScriptType::kClassic; ScriptType script_type_ = ScriptType::kClassic;
// https://html.spec.whatwg.org/#concept-script-external // https://html.spec.whatwg.org/#concept-script-external
...@@ -219,6 +225,7 @@ class CORE_EXPORT ScriptLoader : public GarbageCollectedFinalized<ScriptLoader>, ...@@ -219,6 +225,7 @@ class CORE_EXPORT ScriptLoader : public GarbageCollectedFinalized<ScriptLoader>,
DocumentWriteIntervention document_write_intervention_; DocumentWriteIntervention document_write_intervention_;
Member<PendingScript> pending_script_; Member<PendingScript> pending_script_;
Member<ModulePendingScriptTreeClient> module_tree_client_;
}; };
} // namespace blink } // namespace blink
......
...@@ -288,6 +288,7 @@ void FetchBlockedDocWriteScript(ScriptElementBase* element, ...@@ -288,6 +288,7 @@ void FetchBlockedDocWriteScript(ScriptElementBase* element,
DCHECK(script_loader); DCHECK(script_loader);
script_loader->SetFetchDocWrittenScriptDeferIdle(); script_loader->SetFetchDocWrittenScriptDeferIdle();
script_loader->PrepareScript(script_start_position); script_loader->PrepareScript(script_start_position);
CHECK_EQ(script_loader->GetScriptType(), ScriptType::kClassic);
} }
void EmitWarningForDocWriteScripts(const String& url, Document& document) { void EmitWarningForDocWriteScripts(const String& url, Document& document) {
......
...@@ -452,6 +452,7 @@ void XMLDocumentParser::NotifyFinished(Resource* unused_resource) { ...@@ -452,6 +452,7 @@ void XMLDocumentParser::NotifyFinished(Resource* unused_resource) {
ScriptLoader* script_loader = ScriptLoader* script_loader =
ScriptElementBase::FromElementIfPossible(e)->Loader(); ScriptElementBase::FromElementIfPossible(e)->Loader();
DCHECK(script_loader); DCHECK(script_loader);
CHECK_EQ(script_loader->GetScriptType(), ScriptType::kClassic);
if (error_occurred) { if (error_occurred) {
script_loader->DispatchErrorEvent(); script_loader->DispatchErrorEvent();
...@@ -1112,9 +1113,16 @@ void XMLDocumentParser::EndElementNs() { ...@@ -1112,9 +1113,16 @@ void XMLDocumentParser::EndElementNs() {
DCHECK(!pending_script_); DCHECK(!pending_script_);
requesting_script_ = true; requesting_script_ = true;
if (script_loader->PrepareScript( bool success = script_loader->PrepareScript(
script_start_position_, script_start_position_, ScriptLoader::kAllowLegacyTypeInTypeAttribute);
ScriptLoader::kAllowLegacyTypeInTypeAttribute)) {
if (script_loader->GetScriptType() != ScriptType::kClassic) {
// XMLDocumentParser does not support a module script, and thus ignores it.
success = false;
VLOG(0) << "Module scripts in XML documents are not supported.";
}
if (success) {
// FIXME: Script execution should be shared between // FIXME: Script execution should be shared between
// the libxml2 and Qt XMLDocumentParser implementations. // the libxml2 and Qt XMLDocumentParser implementations.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment