Commit 101ecb62 authored by Camillo Bruni's avatar Camillo Bruni Committed by Chromium LUCI CQ

[blink] Move ScriptLocationType to ModuleScriptCreationParams

Additionally add checks to make the contract as per spec [1]
for the source_url and base_url clear that kExternalFile modules
have source_url == base_url.

[1] https://html.spec.whatwg.org/multipage/webappapis.html#concept-script-base-url

Bug: 1154943
Change-Id: I761e5fcdef2298c43b908ba09257e9d99dc40df9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2595415
Commit-Queue: Camillo Bruni <cbruni@chromium.org>
Reviewed-by: default avatarHiroshige Hayashizaki <hiroshige@chromium.org>
Reviewed-by: default avatarKouhei Ueno <kouhei@chromium.org>
Cr-Commit-Position: refs/heads/master@{#838762}
parent 86da4247
......@@ -52,7 +52,6 @@ v8::Local<v8::Module> ModuleRecord::Compile(
const TextPosition& text_position,
ExceptionState& exception_state,
mojom::blink::V8CacheOptions v8_cache_options,
ScriptSourceLocationType source_location_type,
ModuleRecordProduceCacheData** out_produce_cache_data) {
v8::TryCatch try_catch(isolate);
v8::Local<v8::Module> module;
......@@ -71,7 +70,7 @@ v8::Local<v8::Module> ModuleRecord::Compile(
std::tie(compile_options, produce_cache_options, no_cache_reason) =
V8CodeCache::GetCompileOptions(v8_cache_options, params.CacheHandler(),
params.GetSourceText().length(),
source_location_type);
params.SourceLocationType());
if (!V8ScriptRunner::CompileModule(
isolate, params, text_position, compile_options, no_cache_reason,
......
......@@ -69,8 +69,6 @@ class CORE_EXPORT ModuleRecord final {
const TextPosition&,
ExceptionState&,
mojom::blink::V8CacheOptions = mojom::blink::V8CacheOptions::kDefault,
ScriptSourceLocationType source_location_type =
ScriptSourceLocationType::kInternal,
ModuleRecordProduceCacheData** out_produce_cache_data = nullptr);
// Returns exception, if any.
......
......@@ -65,7 +65,8 @@ void DocumentModuleScriptFetcher::NotifyFinished(Resource* resource) {
// Create an external module script where base_url == source_url.
// https://html.spec.whatwg.org/multipage/webappapis.html#concept-script-base-url
client_->NotifyFetchFinishedSuccess(ModuleScriptCreationParams(
/*source_url=*/url, /*base_url=*/url, module_type,
/*source_url=*/url, /*base_url=*/url,
ScriptSourceLocationType::kExternalFile, module_type,
script_resource->SourceText(), script_resource->CacheHandler(),
script_resource->GetResourceRequest().GetCredentialsMode(), streamer,
not_streamed_reason));
......
......@@ -6,6 +6,7 @@
#include "third_party/blink/public/common/features.h"
#include "third_party/blink/public/mojom/appcache/appcache.mojom-blink.h"
#include "third_party/blink/renderer/bindings/core/v8/script_source_location_type.h"
#include "third_party/blink/renderer/core/dom/dom_implementation.h"
#include "third_party/blink/renderer/core/inspector/console_message.h"
#include "third_party/blink/renderer/core/workers/installed_scripts_manager.h"
......@@ -107,7 +108,8 @@ void InstalledServiceWorkerModuleScriptFetcher::Fetch(
// https://html.spec.whatwg.org/multipage/webappapis.html#concept-script-base-url
client->NotifyFetchFinishedSuccess(ModuleScriptCreationParams(
/*source_url=*/fetch_params.Url(), /*base_url=*/fetch_params.Url(),
module_type, ParkableString(script_data->TakeSourceText().Impl()),
ScriptSourceLocationType::kExternalFile, module_type,
ParkableString(script_data->TakeSourceText().Impl()),
/*cache_handler=*/nullptr,
fetch_params.GetResourceRequest().GetCredentialsMode()));
}
......
......@@ -7,6 +7,7 @@
#include "base/optional.h"
#include "third_party/blink/public/platform/web_url_request.h"
#include "third_party/blink/renderer/bindings/core/v8/script_source_location_type.h"
#include "third_party/blink/renderer/bindings/core/v8/script_streamer.h"
#include "third_party/blink/renderer/core/script/modulator.h"
#include "third_party/blink/renderer/platform/bindings/parkable_string.h"
......@@ -28,6 +29,7 @@ class ModuleScriptCreationParams {
ModuleScriptCreationParams(
const KURL& source_url,
const KURL& base_url,
ScriptSourceLocationType source_location_type,
const ModuleScriptCreationParams::ModuleType module_type,
const ParkableString& source_text,
SingleCachedMetadataHandler* cache_handler,
......@@ -37,6 +39,7 @@ class ModuleScriptCreationParams {
ScriptStreamer::NotStreamingReason::kStreamingDisabled)
: source_url_(source_url),
base_url_(base_url),
source_location_type_(source_location_type),
module_type_(module_type),
is_isolated_(false),
source_text_(source_text),
......@@ -45,6 +48,12 @@ class ModuleScriptCreationParams {
credentials_mode_(credentials_mode),
script_streamer_(script_streamer),
not_streaming_reason_(not_streaming_reason) {
DCHECK(source_location_type == ScriptSourceLocationType::kExternalFile ||
source_location_type == ScriptSourceLocationType::kInline);
// https://html.spec.whatwg.org/multipage/webappapis.html#concept-script-base-url
if (source_location_type == ScriptSourceLocationType::kExternalFile) {
DCHECK_EQ(source_url, base_url);
}
DCHECK_EQ(
!script_streamer,
not_streaming_reason != ScriptStreamer::NotStreamingReason::kInvalid);
......@@ -56,9 +65,9 @@ class ModuleScriptCreationParams {
String isolated_source_text =
isolated_source_text_ ? isolated_source_text_.IsolatedCopy()
: GetSourceText().ToString().IsolatedCopy();
return ModuleScriptCreationParams(SourceURL().Copy(), BaseURL().Copy(),
module_type_, isolated_source_text,
GetFetchCredentialsMode());
return ModuleScriptCreationParams(
SourceURL().Copy(), BaseURL().Copy(), source_location_type_,
GetModuleType(), isolated_source_text, GetFetchCredentialsMode());
}
ModuleScriptCreationParams::ModuleType GetModuleType() const {
......@@ -77,10 +86,14 @@ class ModuleScriptCreationParams {
return source_text_;
}
ScriptSourceLocationType SourceLocationType() const {
return source_location_type_;
}
ModuleScriptCreationParams CopyWithClearedSourceText() const {
return ModuleScriptCreationParams(
source_url_, base_url_, module_type_, ParkableString(),
/*cache_handler=*/nullptr, credentials_mode_,
source_url_, base_url_, source_location_type_, module_type_,
ParkableString(), /*cache_handler=*/nullptr, credentials_mode_,
/*script_streamer=*/nullptr,
ScriptStreamer::NotStreamingReason::kStreamingDisabled);
}
......@@ -103,11 +116,13 @@ class ModuleScriptCreationParams {
ModuleScriptCreationParams(
const KURL& source_url,
const KURL& base_url,
ScriptSourceLocationType source_location_type,
const ModuleScriptCreationParams::ModuleType& module_type,
const String& isolated_source_text,
network::mojom::CredentialsMode credentials_mode)
: source_url_(source_url),
base_url_(base_url),
source_location_type_(source_location_type),
module_type_(module_type),
is_isolated_(true),
source_text_(),
......@@ -123,6 +138,7 @@ class ModuleScriptCreationParams {
const KURL source_url_;
const KURL base_url_;
const ScriptSourceLocationType source_location_type_;
const ModuleType module_type_;
// Mutable because an isolated copy can become bound to a thread when
......
......@@ -275,9 +275,7 @@ void ModuleScriptLoader::NotifyFetchFinishedSuccess(
// Step 10. "Let module script be the result of creating
// a module script given source text, module map settings object,
// response's url, and options." [spec text]
module_script_ = JSModuleScript::Create(
params, ScriptSourceLocationType::kExternalFile, modulator_,
options_);
module_script_ = JSModuleScript::Create(params, modulator_, options_);
break;
};
}
......
......@@ -10,6 +10,7 @@
#include "services/network/public/mojom/referrer_policy.mojom-blink.h"
#include "third_party/blink/public/common/features.h"
#include "third_party/blink/public/common/loader/network_utils.h"
#include "third_party/blink/renderer/bindings/core/v8/script_source_location_type.h"
#include "third_party/blink/renderer/core/inspector/console_message.h"
#include "third_party/blink/renderer/core/origin_trials/origin_trial_context.h"
#include "third_party/blink/renderer/core/workers/worker_global_scope.h"
......@@ -185,7 +186,8 @@ void WorkerModuleScriptFetcher::NotifyClient(
// Create an external module script where base_url == source_url.
// https://html.spec.whatwg.org/multipage/webappapis.html#concept-script-base-url
client_->NotifyFetchFinishedSuccess(ModuleScriptCreationParams(
/*source_url=*/url, /*base_url=*/url, module_type, source_text,
/*source_url=*/url, /*base_url=*/url,
ScriptSourceLocationType::kExternalFile, module_type, source_text,
cache_handler, credentials_mode));
}
......
......@@ -4,6 +4,7 @@
#include "third_party/blink/renderer/core/loader/modulescript/worklet_module_script_fetcher.h"
#include "third_party/blink/renderer/bindings/core/v8/script_source_location_type.h"
#include "third_party/blink/renderer/platform/loader/fetch/resource_fetcher.h"
namespace blink {
......@@ -52,7 +53,8 @@ void WorkletModuleScriptFetcher::NotifyFinished(Resource* resource) {
const KURL& url = script_resource->GetResponse().CurrentRequestUrl();
// Create an external module script where base_url == source_url.
// https://html.spec.whatwg.org/multipage/webappapis.html#concept-script-base-url
params.emplace(/*source_url=*/url, /*base_url=*/url, module_type,
params.emplace(/*source_url=*/url, /*base_url=*/url,
ScriptSourceLocationType::kExternalFile, module_type,
script_resource->SourceText(),
script_resource->CacheHandler(),
script_resource->GetResourceRequest().GetCredentialsMode());
......
......@@ -19,7 +19,6 @@ namespace blink {
// href="https://html.spec.whatwg.org/C/#creating-a-javascript-module-script">
JSModuleScript* JSModuleScript::Create(
const ModuleScriptCreationParams& original_params,
ScriptSourceLocationType source_location_type,
Modulator* modulator,
const ScriptFetchOptions& options,
const TextPosition& start_position) {
......@@ -47,10 +46,9 @@ JSModuleScript* JSModuleScript::Create(
ModuleRecordProduceCacheData* produce_cache_data = nullptr;
v8::Local<v8::Module> result =
ModuleRecord::Compile(isolate, params, options, start_position,
exception_state, modulator->GetV8CacheOptions(),
source_location_type, &produce_cache_data);
v8::Local<v8::Module> result = ModuleRecord::Compile(
isolate, params, options, start_position, exception_state,
modulator->GetV8CacheOptions(), &produce_cache_data);
// CreateInternal processes Steps 4 and 8-10.
//
......
......@@ -26,7 +26,6 @@ class CORE_EXPORT JSModuleScript final : public ModuleScript,
// https://html.spec.whatwg.org/C/#creating-a-javascript-module-script
static JSModuleScript* Create(
const ModuleScriptCreationParams& params,
ScriptSourceLocationType,
Modulator*,
const ScriptFetchOptions&,
const TextPosition& start_position = TextPosition::MinimumPosition());
......
......@@ -6,6 +6,7 @@
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/platform/platform.h"
#include "third_party/blink/renderer/bindings/core/v8/script_source_location_type.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_binding_for_core.h"
#include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/loader/modulescript/module_script_fetch_request.h"
......@@ -153,7 +154,8 @@ class ModuleMapTestModulator final : public DummyModulator {
: url_(url), credential_mode_(credential_mode), client_(client) {}
void NotifyFetchFinished() {
client_->NotifyFetchFinishedSuccess(ModuleScriptCreationParams(
url_, url_, ModuleScriptCreationParams::ModuleType::kJavaScriptModule,
url_, url_, ScriptSourceLocationType::kExternalFile,
ModuleScriptCreationParams::ModuleType::kJavaScriptModule,
ParkableString(String("").ReleaseImpl()), nullptr, credential_mode_));
}
void Trace(Visitor* visitor) const { visitor->Trace(client_); }
......
......@@ -83,12 +83,11 @@ class ModuleScriptTest : public ::testing::Test, public ParametrizedModuleTest {
SingleCachedMetadataHandler* cache_handler) {
ModuleScriptCreationParams params(
KURL("https://fox.url/script.js"), KURL("https://fox.url/"),
ScriptSourceLocationType::kInline,
ModuleScriptCreationParams::ModuleType::kJavaScriptModule,
ParkableString(source_text.IsolatedCopy().ReleaseImpl()), cache_handler,
network::mojom::CredentialsMode::kOmit);
return JSModuleScript::Create(params,
ScriptSourceLocationType::kExternalFile,
modulator, ScriptFetchOptions());
return JSModuleScript::Create(params, modulator, ScriptFetchOptions());
}
static ValueWrapperSyntheticModuleScript*
......
......@@ -710,13 +710,12 @@ bool ScriptLoader::PrepareScript(const TextPosition& script_start_position,
// text, settings object, base URL, and options.</spec>
ModuleScriptCreationParams params(
source_url, base_url,
source_url, base_url, ScriptSourceLocationType::kInline,
ModuleScriptCreationParams::ModuleType::kJavaScriptModule,
ParkableString(source_text.Impl()), nullptr,
options.CredentialsMode());
ModuleScript* module_script =
JSModuleScript::Create(params, ScriptSourceLocationType::kInline,
modulator, options, position);
JSModuleScript::Create(params, modulator, options, position);
// <spec label="fetch-an-inline-module-script-graph" step="2">If script
// is null, asynchronously complete this algorithm with null, and abort
......
......@@ -6,6 +6,7 @@
#include "third_party/blink/renderer/bindings/core/v8/module_record.h"
#include "third_party/blink/renderer/bindings/core/v8/script_function.h"
#include "third_party/blink/renderer/bindings/core/v8/script_promise.h"
#include "third_party/blink/renderer/bindings/core/v8/script_source_location_type.h"
#include "third_party/blink/renderer/bindings/core/v8/script_value.h"
#include "third_party/blink/renderer/core/loader/modulescript/module_script_creation_params.h"
#include "third_party/blink/renderer/platform/bindings/exception_state.h"
......@@ -28,6 +29,7 @@ v8::Local<v8::Module> ModuleTestBase::CompileModule(
ExceptionState& exception_state) {
ModuleScriptCreationParams params(
/*source_url=*/url, /*base_url=*/url,
ScriptSourceLocationType::kExternalFile,
ModuleScriptCreationParams::ModuleType::kJavaScriptModule,
ParkableString(source.Impl()), nullptr,
network::mojom::CredentialsMode::kOmit);
......
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