Commit d97cc734 authored by hiroshige's avatar hiroshige Committed by Commit bot

Introduce ModuleScript::CreateInternal()

This is preparation for https://codereview.chromium.org/2850673002
to create a place to insert RegisterModuleScript() both for
Create() and CreateForTest().

This doesn't change the behavior.

BUG=594639, 715369

Review-Url: https://codereview.chromium.org/2844413003
Cr-Commit-Position: refs/heads/master@{#467891}
parent 63b1a036
...@@ -18,6 +18,7 @@ ModuleScript* ModuleScript::Create( ...@@ -18,6 +18,7 @@ ModuleScript* ModuleScript::Create(
ParserDisposition parser_state, ParserDisposition parser_state,
WebURLRequest::FetchCredentialsMode credentials_mode, WebURLRequest::FetchCredentialsMode credentials_mode,
AccessControlStatus access_control_status) { AccessControlStatus access_control_status) {
// https://html.spec.whatwg.org/#creating-a-module-script
// Step 1. Let script be a new module script that this algorithm will // Step 1. Let script be a new module script that this algorithm will
// subsequently initialize. // subsequently initialize.
// Step 2. Set script's settings object to the environment settings object // Step 2. Set script's settings object to the environment settings object
...@@ -30,6 +31,19 @@ ModuleScript* ModuleScript::Create( ...@@ -30,6 +31,19 @@ ModuleScript* ModuleScript::Create(
// Step 6: "...return null, and abort these steps." // Step 6: "...return null, and abort these steps."
if (result.IsNull()) if (result.IsNull())
return nullptr; return nullptr;
return CreateInternal(modulator, result, base_url, nonce, parser_state,
credentials_mode);
}
ModuleScript* ModuleScript::CreateInternal(
Modulator* modulator,
ScriptModule result,
const KURL& base_url,
const String& nonce,
ParserDisposition parser_state,
WebURLRequest::FetchCredentialsMode credentials_mode) {
// https://html.spec.whatwg.org/#creating-a-module-script
// Step 7. Set script's module record to result. // Step 7. Set script's module record to result.
// Step 8. Set script's base URL to the script base URL provided. // Step 8. Set script's base URL to the script base URL provided.
// Step 9. Set script's cryptographic nonce to the cryptographic nonce // Step 9. Set script's cryptographic nonce to the cryptographic nonce
...@@ -41,6 +55,17 @@ ModuleScript* ModuleScript::Create( ...@@ -41,6 +55,17 @@ ModuleScript* ModuleScript::Create(
credentials_mode); credentials_mode);
} }
ModuleScript* ModuleScript::CreateForTest(
Modulator* modulator,
ScriptModule record,
const KURL& base_url,
const String& nonce,
ParserDisposition parser_state,
WebURLRequest::FetchCredentialsMode credentials_mode) {
return CreateInternal(modulator, record, base_url, nonce, parser_state,
credentials_mode);
}
void ModuleScript::SetInstantiationErrorAndClearRecord(ScriptValue error) { void ModuleScript::SetInstantiationErrorAndClearRecord(ScriptValue error) {
// Implements Step 7.1 of: // Implements Step 7.1 of:
// https://html.spec.whatwg.org/multipage/webappapis.html#internal-module-script-graph-fetching-procedure // https://html.spec.whatwg.org/multipage/webappapis.html#internal-module-script-graph-fetching-procedure
......
...@@ -39,16 +39,15 @@ class CORE_EXPORT ModuleScript final : public Script, public TraceWrapperBase { ...@@ -39,16 +39,15 @@ class CORE_EXPORT ModuleScript final : public Script, public TraceWrapperBase {
WebURLRequest::FetchCredentialsMode, WebURLRequest::FetchCredentialsMode,
AccessControlStatus); AccessControlStatus);
static ModuleScript* CreateForTest( // Mostly corresponds to Create() but accepts ScriptModule as the argument
Modulator* settings_object, // and allows null ScriptModule.
ScriptModule record, static ModuleScript* CreateForTest(Modulator*,
const KURL& base_url, ScriptModule,
const String& nonce, const KURL& base_url,
ParserDisposition parser_state, const String& nonce,
WebURLRequest::FetchCredentialsMode credentials_mode) { ParserDisposition,
return new ModuleScript(settings_object, record, base_url, nonce, WebURLRequest::FetchCredentialsMode);
parser_state, credentials_mode);
}
~ModuleScript() override = default; ~ModuleScript() override = default;
const ScriptModule& Record() const { return record_; } const ScriptModule& Record() const { return record_; }
...@@ -89,6 +88,13 @@ class CORE_EXPORT ModuleScript final : public Script, public TraceWrapperBase { ...@@ -89,6 +88,13 @@ class CORE_EXPORT ModuleScript final : public Script, public TraceWrapperBase {
parser_state_(parser_state), parser_state_(parser_state),
credentials_mode_(credentials_mode) {} credentials_mode_(credentials_mode) {}
static ModuleScript* CreateInternal(Modulator*,
ScriptModule,
const KURL& base_url,
const String& nonce,
ParserDisposition,
WebURLRequest::FetchCredentialsMode);
ScriptType GetScriptType() const override { return ScriptType::kModule; } ScriptType GetScriptType() const override { return ScriptType::kModule; }
bool IsEmpty() const override; bool IsEmpty() const override;
bool CheckMIMETypeBeforeRunScript(Document* context_document, bool CheckMIMETypeBeforeRunScript(Document* context_document,
......
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