Commit 01eff54b authored by Camillo Bruni's avatar Camillo Bruni Committed by Chromium LUCI CQ

[blink] Clean up ModuleScriptCreationParam

Instead of mutating the const ref, we copy the params object in
JSModuleScript::Create when clearing the source text.

Introduce ModuleScriptFetcher::NotifyFetchFinishedError and
ModuleScriptFetcher::NotifyFetchFinishedSuccess to make it clearer which
arguments are used.

Bug: 1154943
Change-Id: I4ed2ca75e56c8cbefb8d49c11e77d1846ce43f16
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2571877
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@{#837978}
parent 4c50825a
...@@ -37,20 +37,21 @@ void DocumentModuleScriptFetcher::NotifyFinished(Resource* resource) { ...@@ -37,20 +37,21 @@ void DocumentModuleScriptFetcher::NotifyFinished(Resource* resource) {
auto* script_resource = To<ScriptResource>(resource); auto* script_resource = To<ScriptResource>(resource);
HeapVector<Member<ConsoleMessage>> error_messages;
ModuleScriptCreationParams::ModuleType module_type; ModuleScriptCreationParams::ModuleType module_type;
if (!WasModuleLoadSuccessful(script_resource, &error_messages, {
&module_type)) { HeapVector<Member<ConsoleMessage>> error_messages;
client_->NotifyFetchFinished(base::nullopt, error_messages); if (!WasModuleLoadSuccessful(script_resource, &error_messages,
return; &module_type)) {
client_->NotifyFetchFinishedError(error_messages);
return;
}
} }
// TODO(crbug.com/1061857): Pass ScriptStreamer to the client here. // TODO(crbug.com/1061857): Pass ScriptStreamer to the client here.
ModuleScriptCreationParams params( client_->NotifyFetchFinishedSuccess(ModuleScriptCreationParams(
script_resource->GetResponse().CurrentRequestUrl(), module_type, script_resource->GetResponse().CurrentRequestUrl(), module_type,
script_resource->SourceText(), script_resource->CacheHandler(), script_resource->SourceText(), script_resource->CacheHandler(),
script_resource->GetResourceRequest().GetCredentialsMode(), nullptr, script_resource->GetResourceRequest().GetCredentialsMode(), nullptr,
ScriptStreamer::NotStreamingReason::kStreamingDisabled); ScriptStreamer::NotStreamingReason::kStreamingDisabled));
client_->NotifyFetchFinished(params, error_messages);
} }
void DocumentModuleScriptFetcher::Trace(Visitor* visitor) const { void DocumentModuleScriptFetcher::Trace(Visitor* visitor) const {
......
...@@ -46,7 +46,7 @@ void InstalledServiceWorkerModuleScriptFetcher::Fetch( ...@@ -46,7 +46,7 @@ void InstalledServiceWorkerModuleScriptFetcher::Fetch(
mojom::ConsoleMessageLevel::kError, mojom::ConsoleMessageLevel::kError,
"Failed to load the script unexpectedly", "Failed to load the script unexpectedly",
fetch_params.Url().GetString(), nullptr, 0)); fetch_params.Url().GetString(), nullptr, 0));
client->NotifyFetchFinished(base::nullopt, error_messages); client->NotifyFetchFinishedError(error_messages);
return; return;
} }
...@@ -99,16 +99,15 @@ void InstalledServiceWorkerModuleScriptFetcher::Fetch( ...@@ -99,16 +99,15 @@ void InstalledServiceWorkerModuleScriptFetcher::Fetch(
mojom::ConsoleMessageLevel::kError, mojom::ConsoleMessageLevel::kError,
"Failed to load the script unexpectedly", "Failed to load the script unexpectedly",
fetch_params.Url().GetString(), nullptr, 0)); fetch_params.Url().GetString(), nullptr, 0));
client->NotifyFetchFinished(base::nullopt, error_messages); client->NotifyFetchFinishedError(error_messages);
return; return;
} }
ModuleScriptCreationParams params( client->NotifyFetchFinishedSuccess(ModuleScriptCreationParams(
fetch_params.Url(), module_type, fetch_params.Url(), module_type,
ParkableString(script_data->TakeSourceText().Impl()), ParkableString(script_data->TakeSourceText().Impl()),
nullptr /* cache_handler */, nullptr /* cache_handler */,
fetch_params.GetResourceRequest().GetCredentialsMode()); fetch_params.GetResourceRequest().GetCredentialsMode()));
client->NotifyFetchFinished(params, HeapVector<Member<ConsoleMessage>>());
} }
void InstalledServiceWorkerModuleScriptFetcher::Trace(Visitor* visitor) const { void InstalledServiceWorkerModuleScriptFetcher::Trace(Visitor* visitor) const {
......
...@@ -74,11 +74,10 @@ class ModuleScriptCreationParams { ...@@ -74,11 +74,10 @@ class ModuleScriptCreationParams {
return source_text_; return source_text_;
} }
// TODO(crbug.com/1154943): Make this non-const. ModuleScriptCreationParams CopyWithClearedSourceText() const {
void ClearSourceText() const { return ModuleScriptCreationParams(
source_text_ = ParkableString(); source_url_, module_type_, ParkableString(), cache_handler_,
isolated_source_text_ = String(); credentials_mode_, script_streamer_, not_streaming_reason_);
is_isolated_ = false;
} }
SingleCachedMetadataHandler* CacheHandler() const { return cache_handler_; } SingleCachedMetadataHandler* CacheHandler() const { return cache_handler_; }
......
...@@ -21,12 +21,12 @@ ModuleScriptFetcher::ModuleScriptFetcher( ...@@ -21,12 +21,12 @@ ModuleScriptFetcher::ModuleScriptFetcher(
base::PassKey<ModuleScriptLoader> pass_key) {} base::PassKey<ModuleScriptLoader> pass_key) {}
void ModuleScriptFetcher::Client::OnFetched( void ModuleScriptFetcher::Client::OnFetched(
const base::Optional<ModuleScriptCreationParams>& params) { const ModuleScriptCreationParams& params) {
NotifyFetchFinished(params, HeapVector<Member<ConsoleMessage>>()); NotifyFetchFinishedSuccess(params);
} }
void ModuleScriptFetcher::Client::OnFailed() { void ModuleScriptFetcher::Client::OnFailed() {
NotifyFetchFinished(base::nullopt, HeapVector<Member<ConsoleMessage>>()); NotifyFetchFinishedError(HeapVector<Member<ConsoleMessage>>());
} }
void ModuleScriptFetcher::Trace(Visitor* visitor) const { void ModuleScriptFetcher::Trace(Visitor* visitor) const {
......
...@@ -29,13 +29,14 @@ class CORE_EXPORT ModuleScriptFetcher : public ResourceClient { ...@@ -29,13 +29,14 @@ class CORE_EXPORT ModuleScriptFetcher : public ResourceClient {
class CORE_EXPORT Client : public GarbageCollectedMixin { class CORE_EXPORT Client : public GarbageCollectedMixin {
public: public:
virtual void NotifyFetchFinished( virtual void NotifyFetchFinishedError(
const base::Optional<ModuleScriptCreationParams>&,
const HeapVector<Member<ConsoleMessage>>& error_messages) = 0; const HeapVector<Member<ConsoleMessage>>& error_messages) = 0;
virtual void NotifyFetchFinishedSuccess(
const ModuleScriptCreationParams&) = 0;
// These helpers are used only from WorkletModuleResponsesMap. // These helpers are used only from WorkletModuleResponsesMap.
// TODO(nhiroki): Move these helpers to WorkletModuleResponsesMap. // TODO(nhiroki): Move these helpers to WorkletModuleResponsesMap.
void OnFetched(const base::Optional<ModuleScriptCreationParams>&); void OnFetched(const ModuleScriptCreationParams&);
void OnFailed(); void OnFailed();
}; };
......
...@@ -224,8 +224,7 @@ void ModuleScriptLoader::FetchInternal( ...@@ -224,8 +224,7 @@ void ModuleScriptLoader::FetchInternal(
} }
// <specdef href="https://html.spec.whatwg.org/C/#fetch-a-single-module-script"> // <specdef href="https://html.spec.whatwg.org/C/#fetch-a-single-module-script">
void ModuleScriptLoader::NotifyFetchFinished( void ModuleScriptLoader::NotifyFetchFinishedError(
const base::Optional<ModuleScriptCreationParams>& params,
const HeapVector<Member<ConsoleMessage>>& error_messages) { const HeapVector<Member<ConsoleMessage>>& error_messages) {
// [nospec] Abort the steps if the browsing context is discarded. // [nospec] Abort the steps if the browsing context is discarded.
if (!modulator_->HasValidContext()) { if (!modulator_->HasValidContext()) {
...@@ -238,11 +237,17 @@ void ModuleScriptLoader::NotifyFetchFinished( ...@@ -238,11 +237,17 @@ void ModuleScriptLoader::NotifyFetchFinished(
// <spec step="9">If any of the following conditions are met, set // <spec step="9">If any of the following conditions are met, set
// moduleMap[url] to null, asynchronously complete this algorithm with null, // moduleMap[url] to null, asynchronously complete this algorithm with null,
// and abort these steps: ...</spec> // and abort these steps: ...</spec>
if (!params.has_value()) { for (ConsoleMessage* error_message : error_messages) {
for (ConsoleMessage* error_message : error_messages) { ExecutionContext::From(modulator_->GetScriptState())
ExecutionContext::From(modulator_->GetScriptState()) ->AddConsoleMessage(error_message);
->AddConsoleMessage(error_message); }
} AdvanceState(State::kFinished);
}
void ModuleScriptLoader::NotifyFetchFinishedSuccess(
const ModuleScriptCreationParams& params) {
// [nospec] Abort the steps if the browsing context is discarded.
if (!modulator_->HasValidContext()) {
AdvanceState(State::kFinished); AdvanceState(State::kFinished);
return; return;
} }
...@@ -253,7 +258,7 @@ void ModuleScriptLoader::NotifyFetchFinished( ...@@ -253,7 +258,7 @@ void ModuleScriptLoader::NotifyFetchFinished(
// <spec step="12.2">Set module script to the result of creating a JavaScript // <spec step="12.2">Set module script to the result of creating a JavaScript
// module script given source text, module map settings object, response's // module script given source text, module map settings object, response's
// url, and options.</spec> // url, and options.</spec>
switch (params->GetModuleType()) { switch (params.GetModuleType()) {
case ModuleScriptCreationParams::ModuleType::kJSONModule: case ModuleScriptCreationParams::ModuleType::kJSONModule:
DCHECK(base::FeatureList::IsEnabled(blink::features::kJSONModules)); DCHECK(base::FeatureList::IsEnabled(blink::features::kJSONModules));
module_script_ = ValueWrapperSyntheticModuleScript:: module_script_ = ValueWrapperSyntheticModuleScript::
...@@ -264,16 +269,17 @@ void ModuleScriptLoader::NotifyFetchFinished( ...@@ -264,16 +269,17 @@ void ModuleScriptLoader::NotifyFetchFinished(
module_script_ = ValueWrapperSyntheticModuleScript:: module_script_ = ValueWrapperSyntheticModuleScript::
CreateCSSWrapperSyntheticModuleScript(params, modulator_); CreateCSSWrapperSyntheticModuleScript(params, modulator_);
break; break;
case ModuleScriptCreationParams::ModuleType::kJavaScriptModule: case ModuleScriptCreationParams::ModuleType::kJavaScriptModule: {
// Step 9. "Let source text be the result of UTF-8 decoding response's // Step 9. "Let source text be the result of UTF-8 decoding response's
// body." [spec text] // body." [spec text]
// Step 10. "Let module script be the result of creating // Step 10. "Let module script be the result of creating
// a module script given source text, module map settings object, // a module script given source text, module map settings object,
// response's url, and options." [spec text] // response's url, and options." [spec text]
module_script_ = JSModuleScript::Create( module_script_ = JSModuleScript::Create(
params.value(), params->SourceURL() /* base URL */, params, /*base_url=*/params.SourceURL(),
ScriptSourceLocationType::kExternalFile, modulator_, options_); ScriptSourceLocationType::kExternalFile, modulator_, options_);
break; break;
};
} }
AdvanceState(State::kFinished); AdvanceState(State::kFinished);
......
...@@ -58,8 +58,8 @@ class CORE_EXPORT ModuleScriptLoader final ...@@ -58,8 +58,8 @@ class CORE_EXPORT ModuleScriptLoader final
ModuleScriptLoaderClient*); ModuleScriptLoaderClient*);
// Implements ModuleScriptFetcher::Client. // Implements ModuleScriptFetcher::Client.
void NotifyFetchFinished( void NotifyFetchFinishedSuccess(const ModuleScriptCreationParams&) override;
const base::Optional<ModuleScriptCreationParams>&, void NotifyFetchFinishedError(
const HeapVector<Member<ConsoleMessage>>& error_messages) override; const HeapVector<Member<ConsoleMessage>>& error_messages) override;
bool IsInitialState() const { return state_ == State::kInitial; } bool IsInitialState() const { return state_ == State::kInitial; }
......
...@@ -90,12 +90,14 @@ void WorkerModuleScriptFetcher::NotifyFinished(Resource* resource) { ...@@ -90,12 +90,14 @@ void WorkerModuleScriptFetcher::NotifyFinished(Resource* resource) {
ClearResource(); ClearResource();
auto* script_resource = To<ScriptResource>(resource); auto* script_resource = To<ScriptResource>(resource);
HeapVector<Member<ConsoleMessage>> error_messages;
ModuleScriptCreationParams::ModuleType module_type; ModuleScriptCreationParams::ModuleType module_type;
if (!WasModuleLoadSuccessful(script_resource, &error_messages, {
&module_type)) { HeapVector<Member<ConsoleMessage>> error_messages;
client_->NotifyFetchFinished(base::nullopt, error_messages); if (!WasModuleLoadSuccessful(script_resource, &error_messages,
return; &module_type)) {
client_->NotifyFetchFinishedError(error_messages);
return;
}
} }
NotifyClient(resource->Url(), module_type, NotifyClient(resource->Url(), module_type,
...@@ -147,7 +149,7 @@ void WorkerModuleScriptFetcher::NotifyClient( ...@@ -147,7 +149,7 @@ void WorkerModuleScriptFetcher::NotifyClient(
mojom::ConsoleMessageSource::kSecurity, mojom::ConsoleMessageSource::kSecurity,
mojom::ConsoleMessageLevel::kError, mojom::ConsoleMessageLevel::kError,
"Refused to cross-origin redirects of the top-level worker script.")); "Refused to cross-origin redirects of the top-level worker script."));
client_->NotifyFetchFinished(base::nullopt, error_messages); client_->NotifyFetchFinishedError(error_messages);
return; return;
} }
...@@ -176,13 +178,12 @@ void WorkerModuleScriptFetcher::NotifyClient( ...@@ -176,13 +178,12 @@ void WorkerModuleScriptFetcher::NotifyClient(
response_origin_trial_tokens.get(), response.AppCacheID()); response_origin_trial_tokens.get(), response.AppCacheID());
} }
ModuleScriptCreationParams params(response.CurrentRequestUrl(), module_type,
source_text, cache_handler,
credentials_mode);
// <spec step="12.7">Asynchronously complete the perform the fetch steps with // <spec step="12.7">Asynchronously complete the perform the fetch steps with
// response.</spec> // response.</spec>
client_->NotifyFetchFinished(params, error_messages); client_->NotifyFetchFinishedSuccess(
ModuleScriptCreationParams(response.CurrentRequestUrl(), module_type,
source_text, cache_handler, credentials_mode));
} }
void WorkerModuleScriptFetcher::DidReceiveData(base::span<const char> span) { void WorkerModuleScriptFetcher::DidReceiveData(base::span<const char> span) {
...@@ -213,7 +214,7 @@ void WorkerModuleScriptFetcher::OnStartLoadingBody( ...@@ -213,7 +214,7 @@ void WorkerModuleScriptFetcher::OnStartLoadingBody(
resource_response.CurrentRequestUrl().GetString(), /*loader=*/nullptr, resource_response.CurrentRequestUrl().GetString(), /*loader=*/nullptr,
-1)); -1));
worker_main_script_loader_->Cancel(); worker_main_script_loader_->Cancel();
client_->NotifyFetchFinished(base::nullopt, error_messages); client_->NotifyFetchFinishedError(error_messages);
return; return;
} }
} }
...@@ -230,8 +231,7 @@ void WorkerModuleScriptFetcher::OnFinishedLoadingWorkerMainScript() { ...@@ -230,8 +231,7 @@ void WorkerModuleScriptFetcher::OnFinishedLoadingWorkerMainScript() {
} }
void WorkerModuleScriptFetcher::OnFailedLoadingWorkerMainScript() { void WorkerModuleScriptFetcher::OnFailedLoadingWorkerMainScript() {
client_->NotifyFetchFinished(base::nullopt, client_->NotifyFetchFinishedError(HeapVector<Member<ConsoleMessage>>());
HeapVector<Member<ConsoleMessage>>());
} }
} // namespace blink } // namespace blink
...@@ -18,7 +18,7 @@ namespace blink { ...@@ -18,7 +18,7 @@ namespace blink {
// <specdef // <specdef
// href="https://html.spec.whatwg.org/C/#creating-a-javascript-module-script"> // href="https://html.spec.whatwg.org/C/#creating-a-javascript-module-script">
JSModuleScript* JSModuleScript::Create( JSModuleScript* JSModuleScript::Create(
const ModuleScriptCreationParams& params, const ModuleScriptCreationParams& original_params,
const KURL& base_url, const KURL& base_url,
ScriptSourceLocationType source_location_type, ScriptSourceLocationType source_location_type,
Modulator* modulator, Modulator* modulator,
...@@ -26,8 +26,10 @@ JSModuleScript* JSModuleScript::Create( ...@@ -26,8 +26,10 @@ JSModuleScript* JSModuleScript::Create(
const TextPosition& start_position) { const TextPosition& start_position) {
// <spec step="1">If scripting is disabled for settings's responsible browsing // <spec step="1">If scripting is disabled for settings's responsible browsing
// context, then set source to the empty string.</spec> // context, then set source to the empty string.</spec>
if (modulator->IsScriptingDisabled()) const ModuleScriptCreationParams& params =
params.ClearSourceText(); modulator->IsScriptingDisabled()
? original_params.CopyWithClearedSourceText()
: original_params;
// <spec step="2">Let script be a new module script that this algorithm will // <spec step="2">Let script be a new module script that this algorithm will
// subsequently initialize.</spec> // subsequently initialize.</spec>
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include "third_party/blink/renderer/platform/heap/handle.h" #include "third_party/blink/renderer/platform/heap/handle.h"
#include "third_party/blink/renderer/platform/loader/fetch/fetch_client_settings_object_snapshot.h" #include "third_party/blink/renderer/platform/loader/fetch/fetch_client_settings_object_snapshot.h"
#include "third_party/blink/renderer/platform/testing/testing_platform_support_with_mock_scheduler.h" #include "third_party/blink/renderer/platform/testing/testing_platform_support_with_mock_scheduler.h"
#include "third_party/blink/renderer/platform/weborigin/kurl.h"
namespace blink { namespace blink {
...@@ -116,11 +117,7 @@ class ModuleMapTestModulator final : public DummyModulator { ...@@ -116,11 +117,7 @@ class ModuleMapTestModulator final : public DummyModulator {
ModuleScriptFetcher::Client* client) override { ModuleScriptFetcher::Client* client) override {
CHECK_EQ(request.GetScriptType(), mojom::blink::ScriptType::kModule); CHECK_EQ(request.GetScriptType(), mojom::blink::ScriptType::kModule);
TestRequest* test_request = MakeGarbageCollected<TestRequest>( TestRequest* test_request = MakeGarbageCollected<TestRequest>(
ModuleScriptCreationParams( request.Url(), request.GetResourceRequest().GetCredentialsMode(),
request.Url(),
ModuleScriptCreationParams::ModuleType::kJavaScriptModule,
ParkableString(String("").ReleaseImpl()), nullptr,
request.GetResourceRequest().GetCredentialsMode()),
client); client);
modulator_->test_requests_.push_back(test_request); modulator_->test_requests_.push_back(test_request);
} }
...@@ -150,17 +147,20 @@ class ModuleMapTestModulator final : public DummyModulator { ...@@ -150,17 +147,20 @@ class ModuleMapTestModulator final : public DummyModulator {
} }
struct TestRequest final : public GarbageCollected<TestRequest> { struct TestRequest final : public GarbageCollected<TestRequest> {
TestRequest(const ModuleScriptCreationParams& params, TestRequest(const KURL& url,
network::mojom::CredentialsMode credential_mode,
ModuleScriptFetcher::Client* client) ModuleScriptFetcher::Client* client)
: params_(params), client_(client) {} : url_(url), credential_mode_(credential_mode), client_(client) {}
void NotifyFetchFinished() { void NotifyFetchFinished() {
client_->NotifyFetchFinished(*params_, client_->NotifyFetchFinishedSuccess(ModuleScriptCreationParams(
HeapVector<Member<ConsoleMessage>>()); url_, ModuleScriptCreationParams::ModuleType::kJavaScriptModule,
ParkableString(String("").ReleaseImpl()), nullptr, credential_mode_));
} }
void Trace(Visitor* visitor) const { visitor->Trace(client_); } void Trace(Visitor* visitor) const { visitor->Trace(client_); }
private: private:
base::Optional<ModuleScriptCreationParams> params_; const KURL url_;
const network::mojom::CredentialsMode credential_mode_;
Member<ModuleScriptFetcher::Client> client_; Member<ModuleScriptFetcher::Client> client_;
}; };
HeapVector<Member<TestRequest>> test_requests_; HeapVector<Member<TestRequest>> test_requests_;
......
...@@ -464,11 +464,6 @@ bool ScriptLoader::PrepareScript(const TextPosition& script_start_position, ...@@ -464,11 +464,6 @@ bool ScriptLoader::PrepareScript(const TextPosition& script_start_position,
SecurityPolicy::ReferrerPolicyFromString( SecurityPolicy::ReferrerPolicyFromString(
referrerpolicy_attr, kDoNotSupportReferrerPolicyLegacyKeywords, referrerpolicy_attr, kDoNotSupportReferrerPolicyLegacyKeywords,
&referrer_policy); &referrer_policy);
if (context_window->IsSecureContext() &&
referrer_policy == network::mojom::ReferrerPolicy::kAlways) {
UseCounter::Count(*context_window,
WebFeature::kSetReferrerPolicyUnsafeUrlInSecureContext);
}
} }
// Priority Hints is currently a non-standard feature, but we can assume the // Priority Hints is currently a non-standard feature, but we can assume the
......
...@@ -25,7 +25,7 @@ namespace blink { ...@@ -25,7 +25,7 @@ namespace blink {
// https://whatpr.org/html/4898/webappapis.html#creating-a-css-module-script // https://whatpr.org/html/4898/webappapis.html#creating-a-css-module-script
ValueWrapperSyntheticModuleScript* ValueWrapperSyntheticModuleScript*
ValueWrapperSyntheticModuleScript::CreateCSSWrapperSyntheticModuleScript( ValueWrapperSyntheticModuleScript::CreateCSSWrapperSyntheticModuleScript(
const base::Optional<ModuleScriptCreationParams>& params, const ModuleScriptCreationParams& params,
Modulator* settings_object) { Modulator* settings_object) {
DCHECK(settings_object->HasValidContext()); DCHECK(settings_object->HasValidContext());
ScriptState* script_state = settings_object->GetScriptState(); ScriptState* script_state = settings_object->GetScriptState();
...@@ -40,7 +40,7 @@ ValueWrapperSyntheticModuleScript::CreateCSSWrapperSyntheticModuleScript( ...@@ -40,7 +40,7 @@ ValueWrapperSyntheticModuleScript::CreateCSSWrapperSyntheticModuleScript(
v8::Local<v8::Value> error = V8ThrowException::CreateTypeError( v8::Local<v8::Value> error = V8ThrowException::CreateTypeError(
isolate, "Cannot create CSS Module in non-document context"); isolate, "Cannot create CSS Module in non-document context");
return ValueWrapperSyntheticModuleScript::CreateWithError( return ValueWrapperSyntheticModuleScript::CreateWithError(
v8::Local<v8::Value>(), settings_object, params->SourceURL(), KURL(), v8::Local<v8::Value>(), settings_object, params.SourceURL(), KURL(),
ScriptFetchOptions(), error); ScriptFetchOptions(), error);
} }
CSSStyleSheetInit* init = CSSStyleSheetInit::Create(); CSSStyleSheetInit* init = CSSStyleSheetInit::Create();
...@@ -50,26 +50,26 @@ ValueWrapperSyntheticModuleScript::CreateCSSWrapperSyntheticModuleScript( ...@@ -50,26 +50,26 @@ ValueWrapperSyntheticModuleScript::CreateCSSWrapperSyntheticModuleScript(
v8::Local<v8::Value> error = exception_state.GetException(); v8::Local<v8::Value> error = exception_state.GetException();
exception_state.ClearException(); exception_state.ClearException();
return ValueWrapperSyntheticModuleScript::CreateWithError( return ValueWrapperSyntheticModuleScript::CreateWithError(
v8::Local<v8::Value>(), settings_object, params->SourceURL(), KURL(), v8::Local<v8::Value>(), settings_object, params.SourceURL(), KURL(),
ScriptFetchOptions(), error); ScriptFetchOptions(), error);
} }
style_sheet->replaceSync(params->GetSourceText().ToString(), exception_state); style_sheet->replaceSync(params.GetSourceText().ToString(), exception_state);
if (exception_state.HadException()) { if (exception_state.HadException()) {
v8::Local<v8::Value> error = exception_state.GetException(); v8::Local<v8::Value> error = exception_state.GetException();
exception_state.ClearException(); exception_state.ClearException();
return ValueWrapperSyntheticModuleScript::CreateWithError( return ValueWrapperSyntheticModuleScript::CreateWithError(
v8::Local<v8::Value>(), settings_object, params->SourceURL(), KURL(), v8::Local<v8::Value>(), settings_object, params.SourceURL(), KURL(),
ScriptFetchOptions(), error); ScriptFetchOptions(), error);
} }
v8::Local<v8::Value> v8_value_stylesheet = ToV8(style_sheet, script_state); v8::Local<v8::Value> v8_value_stylesheet = ToV8(style_sheet, script_state);
return ValueWrapperSyntheticModuleScript::CreateWithDefaultExport( return ValueWrapperSyntheticModuleScript::CreateWithDefaultExport(
v8_value_stylesheet, settings_object, params->SourceURL(), KURL(), v8_value_stylesheet, settings_object, params.SourceURL(), KURL(),
ScriptFetchOptions()); ScriptFetchOptions());
} }
ValueWrapperSyntheticModuleScript* ValueWrapperSyntheticModuleScript*
ValueWrapperSyntheticModuleScript::CreateJSONWrapperSyntheticModuleScript( ValueWrapperSyntheticModuleScript::CreateJSONWrapperSyntheticModuleScript(
const base::Optional<ModuleScriptCreationParams>& params, const ModuleScriptCreationParams& params,
Modulator* settings_object) { Modulator* settings_object) {
DCHECK(settings_object->HasValidContext()); DCHECK(settings_object->HasValidContext());
ScriptState::Scope scope(settings_object->GetScriptState()); ScriptState::Scope scope(settings_object->GetScriptState());
...@@ -78,7 +78,7 @@ ValueWrapperSyntheticModuleScript::CreateJSONWrapperSyntheticModuleScript( ...@@ -78,7 +78,7 @@ ValueWrapperSyntheticModuleScript::CreateJSONWrapperSyntheticModuleScript(
v8::Isolate* isolate = context->GetIsolate(); v8::Isolate* isolate = context->GetIsolate();
v8::TryCatch try_catch(isolate); v8::TryCatch try_catch(isolate);
v8::Local<v8::String> original_json = v8::Local<v8::String> original_json =
V8String(isolate, params->GetSourceText()); V8String(isolate, params.GetSourceText());
v8::Local<v8::Value> parsed_json; v8::Local<v8::Value> parsed_json;
ExceptionState exception_state(isolate, ExceptionState::kExecutionContext, ExceptionState exception_state(isolate, ExceptionState::kExecutionContext,
"ModuleScriptLoader", "ModuleScriptLoader",
...@@ -102,11 +102,11 @@ ValueWrapperSyntheticModuleScript::CreateJSONWrapperSyntheticModuleScript( ...@@ -102,11 +102,11 @@ ValueWrapperSyntheticModuleScript::CreateJSONWrapperSyntheticModuleScript(
v8::Local<v8::Value> error = exception_state.GetException(); v8::Local<v8::Value> error = exception_state.GetException();
exception_state.ClearException(); exception_state.ClearException();
return ValueWrapperSyntheticModuleScript::CreateWithError( return ValueWrapperSyntheticModuleScript::CreateWithError(
parsed_json, settings_object, params->SourceURL(), KURL(), parsed_json, settings_object, params.SourceURL(), KURL(),
ScriptFetchOptions(), error); ScriptFetchOptions(), error);
} else { } else {
return ValueWrapperSyntheticModuleScript::CreateWithDefaultExport( return ValueWrapperSyntheticModuleScript::CreateWithDefaultExport(
parsed_json, settings_object, params->SourceURL(), KURL(), parsed_json, settings_object, params.SourceURL(), KURL(),
ScriptFetchOptions()); ScriptFetchOptions());
} }
} }
......
...@@ -26,14 +26,12 @@ class CORE_EXPORT ValueWrapperSyntheticModuleScript final ...@@ -26,14 +26,12 @@ class CORE_EXPORT ValueWrapperSyntheticModuleScript final
: public ModuleScript { : public ModuleScript {
public: public:
static ValueWrapperSyntheticModuleScript* static ValueWrapperSyntheticModuleScript*
CreateCSSWrapperSyntheticModuleScript( CreateCSSWrapperSyntheticModuleScript(const ModuleScriptCreationParams&,
const base::Optional<ModuleScriptCreationParams>& params, Modulator* settings_object);
Modulator* settings_object);
static ValueWrapperSyntheticModuleScript* static ValueWrapperSyntheticModuleScript*
CreateJSONWrapperSyntheticModuleScript( CreateJSONWrapperSyntheticModuleScript(const ModuleScriptCreationParams&,
const base::Optional<ModuleScriptCreationParams>& params, Modulator* settings_object);
Modulator* settings_object);
static ValueWrapperSyntheticModuleScript* CreateWithDefaultExport( static ValueWrapperSyntheticModuleScript* CreateWithDefaultExport(
v8::Local<v8::Value> value, v8::Local<v8::Value> value,
...@@ -78,4 +76,4 @@ class CORE_EXPORT ValueWrapperSyntheticModuleScript final ...@@ -78,4 +76,4 @@ class CORE_EXPORT ValueWrapperSyntheticModuleScript final
} // namespace blink } // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_CORE_SCRIPT_VALUE_WRAPPER_SYNTHETIC_MODULE_SCRIPT_H_ #endif // THIRD_PARTY_BLINK_RENDERER_CORE_SCRIPT_VALUE_WRAPPER_SYNTHETIC_MODULE_SCRIPT_H_
\ No newline at end of file
...@@ -47,23 +47,22 @@ class WorkletModuleResponsesMapTest : public testing::Test { ...@@ -47,23 +47,22 @@ class WorkletModuleResponsesMapTest : public testing::Test {
public: public:
enum class Result { kInitial, kOK, kFailed }; enum class Result { kInitial, kOK, kFailed };
void NotifyFetchFinished( void NotifyFetchFinishedError(
const base::Optional<ModuleScriptCreationParams>& params,
const HeapVector<Member<ConsoleMessage>>&) override { const HeapVector<Member<ConsoleMessage>>&) override {
ASSERT_EQ(Result::kInitial, result_); ASSERT_EQ(Result::kInitial, result_);
if (params) { result_ = Result::kFailed;
result_ = Result::kOK;
params_.emplace(*params);
} else {
result_ = Result::kFailed;
}
} }
Result GetResult() const { return result_; } void NotifyFetchFinishedSuccess(
base::Optional<ModuleScriptCreationParams> GetParams() const { const ModuleScriptCreationParams& params) override {
return params_; ASSERT_EQ(Result::kInitial, result_);
result_ = Result::kOK;
params_.emplace(std::move(params));
} }
Result GetResult() const { return result_; }
bool HasParams() const { return params_.has_value(); }
private: private:
Result result_ = Result::kInitial; Result result_ = Result::kInitial;
base::Optional<ModuleScriptCreationParams> params_; base::Optional<ModuleScriptCreationParams> params_;
...@@ -108,7 +107,7 @@ TEST_F(WorkletModuleResponsesMapTest, Basic) { ...@@ -108,7 +107,7 @@ TEST_F(WorkletModuleResponsesMapTest, Basic) {
clients.push_back(MakeGarbageCollected<ClientImpl>()); clients.push_back(MakeGarbageCollected<ClientImpl>());
Fetch(kUrl, clients[0]); Fetch(kUrl, clients[0]);
EXPECT_EQ(ClientImpl::Result::kInitial, clients[0]->GetResult()); EXPECT_EQ(ClientImpl::Result::kInitial, clients[0]->GetResult());
EXPECT_FALSE(clients[0]->GetParams().has_value()); EXPECT_FALSE(clients[0]->HasParams());
// The entry is now being fetched. Following read calls should wait for the // The entry is now being fetched. Following read calls should wait for the
// completion. // completion.
...@@ -125,7 +124,7 @@ TEST_F(WorkletModuleResponsesMapTest, Basic) { ...@@ -125,7 +124,7 @@ TEST_F(WorkletModuleResponsesMapTest, Basic) {
RunUntilIdle(); RunUntilIdle();
for (auto client : clients) { for (auto client : clients) {
EXPECT_EQ(ClientImpl::Result::kOK, client->GetResult()); EXPECT_EQ(ClientImpl::Result::kOK, client->GetResult());
EXPECT_TRUE(client->GetParams().has_value()); EXPECT_TRUE(client->HasParams());
} }
} }
...@@ -139,7 +138,7 @@ TEST_F(WorkletModuleResponsesMapTest, Failure) { ...@@ -139,7 +138,7 @@ TEST_F(WorkletModuleResponsesMapTest, Failure) {
clients.push_back(MakeGarbageCollected<ClientImpl>()); clients.push_back(MakeGarbageCollected<ClientImpl>());
Fetch(kUrl, clients[0]); Fetch(kUrl, clients[0]);
EXPECT_EQ(ClientImpl::Result::kInitial, clients[0]->GetResult()); EXPECT_EQ(ClientImpl::Result::kInitial, clients[0]->GetResult());
EXPECT_FALSE(clients[0]->GetParams().has_value()); EXPECT_FALSE(clients[0]->HasParams());
// The entry is now being fetched. Following read calls should wait for the // The entry is now being fetched. Following read calls should wait for the
// completion. // completion.
...@@ -156,7 +155,7 @@ TEST_F(WorkletModuleResponsesMapTest, Failure) { ...@@ -156,7 +155,7 @@ TEST_F(WorkletModuleResponsesMapTest, Failure) {
RunUntilIdle(); RunUntilIdle();
for (auto client : clients) { for (auto client : clients) {
EXPECT_EQ(ClientImpl::Result::kFailed, client->GetResult()); EXPECT_EQ(ClientImpl::Result::kFailed, client->GetResult());
EXPECT_FALSE(client->GetParams().has_value()); EXPECT_FALSE(client->HasParams());
} }
} }
...@@ -174,7 +173,7 @@ TEST_F(WorkletModuleResponsesMapTest, Isolation) { ...@@ -174,7 +173,7 @@ TEST_F(WorkletModuleResponsesMapTest, Isolation) {
clients.push_back(MakeGarbageCollected<ClientImpl>()); clients.push_back(MakeGarbageCollected<ClientImpl>());
Fetch(kUrl1, clients[0]); Fetch(kUrl1, clients[0]);
EXPECT_EQ(ClientImpl::Result::kInitial, clients[0]->GetResult()); EXPECT_EQ(ClientImpl::Result::kInitial, clients[0]->GetResult());
EXPECT_FALSE(clients[0]->GetParams().has_value()); EXPECT_FALSE(clients[0]->HasParams());
// The entry is now being fetched. Following read calls for |kUrl1| should // The entry is now being fetched. Following read calls for |kUrl1| should
// wait for the completion. // wait for the completion.
...@@ -186,7 +185,7 @@ TEST_F(WorkletModuleResponsesMapTest, Isolation) { ...@@ -186,7 +185,7 @@ TEST_F(WorkletModuleResponsesMapTest, Isolation) {
clients.push_back(MakeGarbageCollected<ClientImpl>()); clients.push_back(MakeGarbageCollected<ClientImpl>());
Fetch(kUrl2, clients[2]); Fetch(kUrl2, clients[2]);
EXPECT_EQ(ClientImpl::Result::kInitial, clients[2]->GetResult()); EXPECT_EQ(ClientImpl::Result::kInitial, clients[2]->GetResult());
EXPECT_FALSE(clients[2]->GetParams().has_value()); EXPECT_FALSE(clients[2]->HasParams());
// The entry is now being fetched. Following read calls for |kUrl2| should // The entry is now being fetched. Following read calls for |kUrl2| should
// wait for the completion. // wait for the completion.
...@@ -201,13 +200,13 @@ TEST_F(WorkletModuleResponsesMapTest, Isolation) { ...@@ -201,13 +200,13 @@ TEST_F(WorkletModuleResponsesMapTest, Isolation) {
platform_->GetURLLoaderMockFactory()->ServeAsynchronousRequests(); platform_->GetURLLoaderMockFactory()->ServeAsynchronousRequests();
RunUntilIdle(); RunUntilIdle();
EXPECT_EQ(ClientImpl::Result::kFailed, clients[0]->GetResult()); EXPECT_EQ(ClientImpl::Result::kFailed, clients[0]->GetResult());
EXPECT_FALSE(clients[0]->GetParams().has_value()); EXPECT_FALSE(clients[0]->HasParams());
EXPECT_EQ(ClientImpl::Result::kFailed, clients[1]->GetResult()); EXPECT_EQ(ClientImpl::Result::kFailed, clients[1]->GetResult());
EXPECT_FALSE(clients[1]->GetParams().has_value()); EXPECT_FALSE(clients[1]->HasParams());
EXPECT_EQ(ClientImpl::Result::kOK, clients[2]->GetResult()); EXPECT_EQ(ClientImpl::Result::kOK, clients[2]->GetResult());
EXPECT_TRUE(clients[2]->GetParams().has_value()); EXPECT_TRUE(clients[2]->HasParams());
EXPECT_EQ(ClientImpl::Result::kOK, clients[3]->GetResult()); EXPECT_EQ(ClientImpl::Result::kOK, clients[3]->GetResult());
EXPECT_TRUE(clients[3]->GetParams().has_value()); EXPECT_TRUE(clients[3]->HasParams());
} }
TEST_F(WorkletModuleResponsesMapTest, InvalidURL) { TEST_F(WorkletModuleResponsesMapTest, InvalidURL) {
...@@ -217,7 +216,7 @@ TEST_F(WorkletModuleResponsesMapTest, InvalidURL) { ...@@ -217,7 +216,7 @@ TEST_F(WorkletModuleResponsesMapTest, InvalidURL) {
Fetch(kEmptyURL, client1); Fetch(kEmptyURL, client1);
RunUntilIdle(); RunUntilIdle();
EXPECT_EQ(ClientImpl::Result::kFailed, client1->GetResult()); EXPECT_EQ(ClientImpl::Result::kFailed, client1->GetResult());
EXPECT_FALSE(client1->GetParams().has_value()); EXPECT_FALSE(client1->HasParams());
const KURL kNullURL = NullURL(); const KURL kNullURL = NullURL();
ASSERT_TRUE(kNullURL.IsNull()); ASSERT_TRUE(kNullURL.IsNull());
...@@ -225,7 +224,7 @@ TEST_F(WorkletModuleResponsesMapTest, InvalidURL) { ...@@ -225,7 +224,7 @@ TEST_F(WorkletModuleResponsesMapTest, InvalidURL) {
Fetch(kNullURL, client2); Fetch(kNullURL, client2);
RunUntilIdle(); RunUntilIdle();
EXPECT_EQ(ClientImpl::Result::kFailed, client2->GetResult()); EXPECT_EQ(ClientImpl::Result::kFailed, client2->GetResult());
EXPECT_FALSE(client2->GetParams().has_value()); EXPECT_FALSE(client2->HasParams());
const KURL kInvalidURL; const KURL kInvalidURL;
ASSERT_FALSE(kInvalidURL.IsValid()); ASSERT_FALSE(kInvalidURL.IsValid());
...@@ -233,7 +232,7 @@ TEST_F(WorkletModuleResponsesMapTest, InvalidURL) { ...@@ -233,7 +232,7 @@ TEST_F(WorkletModuleResponsesMapTest, InvalidURL) {
Fetch(kInvalidURL, client3); Fetch(kInvalidURL, client3);
RunUntilIdle(); RunUntilIdle();
EXPECT_EQ(ClientImpl::Result::kFailed, client3->GetResult()); EXPECT_EQ(ClientImpl::Result::kFailed, client3->GetResult());
EXPECT_FALSE(client3->GetParams().has_value()); EXPECT_FALSE(client3->HasParams());
} }
TEST_F(WorkletModuleResponsesMapTest, Dispose) { TEST_F(WorkletModuleResponsesMapTest, Dispose) {
...@@ -252,7 +251,7 @@ TEST_F(WorkletModuleResponsesMapTest, Dispose) { ...@@ -252,7 +251,7 @@ TEST_F(WorkletModuleResponsesMapTest, Dispose) {
clients.push_back(MakeGarbageCollected<ClientImpl>()); clients.push_back(MakeGarbageCollected<ClientImpl>());
Fetch(kUrl1, clients[0]); Fetch(kUrl1, clients[0]);
EXPECT_EQ(ClientImpl::Result::kInitial, clients[0]->GetResult()); EXPECT_EQ(ClientImpl::Result::kInitial, clients[0]->GetResult());
EXPECT_FALSE(clients[0]->GetParams().has_value()); EXPECT_FALSE(clients[0]->HasParams());
// The entry is now being fetched. Following read calls for |kUrl1| should // The entry is now being fetched. Following read calls for |kUrl1| should
// wait for the completion. // wait for the completion.
...@@ -265,7 +264,7 @@ TEST_F(WorkletModuleResponsesMapTest, Dispose) { ...@@ -265,7 +264,7 @@ TEST_F(WorkletModuleResponsesMapTest, Dispose) {
clients.push_back(MakeGarbageCollected<ClientImpl>()); clients.push_back(MakeGarbageCollected<ClientImpl>());
Fetch(kUrl2, clients[2]); Fetch(kUrl2, clients[2]);
EXPECT_EQ(ClientImpl::Result::kInitial, clients[2]->GetResult()); EXPECT_EQ(ClientImpl::Result::kInitial, clients[2]->GetResult());
EXPECT_FALSE(clients[2]->GetParams().has_value()); EXPECT_FALSE(clients[2]->HasParams());
// The entry is now being fetched. Following read calls for |kUrl2| should // The entry is now being fetched. Following read calls for |kUrl2| should
// wait for the completion. // wait for the completion.
...@@ -278,7 +277,7 @@ TEST_F(WorkletModuleResponsesMapTest, Dispose) { ...@@ -278,7 +277,7 @@ TEST_F(WorkletModuleResponsesMapTest, Dispose) {
RunUntilIdle(); RunUntilIdle();
for (auto client : clients) { for (auto client : clients) {
EXPECT_EQ(ClientImpl::Result::kFailed, client->GetResult()); EXPECT_EQ(ClientImpl::Result::kFailed, client->GetResult());
EXPECT_FALSE(client->GetParams().has_value()); EXPECT_FALSE(client->HasParams());
} }
} }
......
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