Commit b4b93954 authored by Hiroshige Hayashizaki's avatar Hiroshige Hayashizaki Committed by Commit Bot

Introduce Script::RunOnWorkerOrWorklet()

In order to use ClassicScript in worklet unit tests,
this CL changes Script::RunOnWorker() to
Script::RunOnWorkerOrWorklet().

This CL removes a DCHECK() in WorkerOrWorkletScriptController
to allow kSanitize in non-importScripts() cases.
This is to allow ClassicScript::UnspecifiedScript()'s default
kSanitize value to be used in worklet unit tests in
https://chromium-review.googlesource.com/c/chromium/src/+/2331758

kSanitize doesn't occur here in non-test environment, but
allowing kSanitize here and using
ClassicScript::UnspecifiedScript()'s default kSanitize value
in worklet unit tests makes it easier to track
ClassicScript::UnspecifiedScript() with kDoNotSanitize cases
as exceptional.

Bug: 1111134
Change-Id: Id4c35427391b263b5bdc9568be95266bb8715a83
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2332096
Commit-Queue: Hiroshige Hayashizaki <hiroshige@chromium.org>
Reviewed-by: default avatarHiroki Nakagawa <nhiroki@chromium.org>
Reviewed-by: default avatarDominic Farolino <dom@chromium.org>
Reviewed-by: default avatarKenichi Ishibashi <bashi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#794601}
parent b74fd4b1
...@@ -433,7 +433,6 @@ bool WorkerOrWorkletScriptController::Evaluate( ...@@ -433,7 +433,6 @@ bool WorkerOrWorkletScriptController::Evaluate(
state.exception, world_.get()); state.exception, world_.get());
} }
} else { } else {
DCHECK_EQ(sanitize_script_errors, SanitizeScriptErrors::kDoNotSanitize);
ErrorEvent* event = nullptr; ErrorEvent* event = nullptr;
if (state.error_event_from_imported_script_) { if (state.error_event_from_imported_script_) {
event = state.error_event_from_imported_script_; event = state.error_event_from_imported_script_;
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
#include "third_party/blink/renderer/bindings/core/v8/script_source_code.h" #include "third_party/blink/renderer/bindings/core/v8/script_source_code.h"
#include "third_party/blink/renderer/bindings/core/v8/worker_or_worklet_script_controller.h" #include "third_party/blink/renderer/bindings/core/v8/worker_or_worklet_script_controller.h"
#include "third_party/blink/renderer/core/frame/local_frame.h" #include "third_party/blink/renderer/core/frame/local_frame.h"
#include "third_party/blink/renderer/core/workers/worker_global_scope.h" #include "third_party/blink/renderer/core/workers/worker_or_worklet_global_scope.h"
#include "third_party/blink/renderer/core/workers/worker_reporting_proxy.h" #include "third_party/blink/renderer/core/workers/worker_reporting_proxy.h"
namespace blink { namespace blink {
...@@ -53,12 +53,13 @@ v8::Local<v8::Value> ClassicScript::RunScriptInIsolatedWorldAndReturnValue( ...@@ -53,12 +53,13 @@ v8::Local<v8::Value> ClassicScript::RunScriptInIsolatedWorldAndReturnValue(
world_id, GetScriptSourceCode(), BaseURL(), sanitize_script_errors_); world_id, GetScriptSourceCode(), BaseURL(), sanitize_script_errors_);
} }
bool ClassicScript::RunScriptOnWorker(WorkerGlobalScope& worker_global_scope) { bool ClassicScript::RunScriptOnWorkerOrWorklet(
DCHECK(worker_global_scope.IsContextThread()); WorkerOrWorkletGlobalScope& global_scope) {
DCHECK(global_scope.IsContextThread());
bool success = worker_global_scope.ScriptController()->Evaluate( bool success = global_scope.ScriptController()->Evaluate(
GetScriptSourceCode(), sanitize_script_errors_, nullptr /* error_event */, GetScriptSourceCode(), sanitize_script_errors_, nullptr /* error_event */,
worker_global_scope.GetV8CacheOptions()); global_scope.GetV8CacheOptions());
return success; return success;
} }
......
...@@ -50,10 +50,10 @@ class CORE_EXPORT ClassicScript final : public Script { ...@@ -50,10 +50,10 @@ class CORE_EXPORT ClassicScript final : public Script {
// a tentative interface. When crbug/1111134 is done, this should be gone. // a tentative interface. When crbug/1111134 is done, this should be gone.
void RunScript(LocalFrame*) override; void RunScript(LocalFrame*) override;
void RunScript(LocalFrame*, ScriptController::ExecuteScriptPolicy); void RunScript(LocalFrame*, ScriptController::ExecuteScriptPolicy);
bool RunScriptOnWorker(WorkerGlobalScope&) override; bool RunScriptOnWorkerOrWorklet(WorkerOrWorkletGlobalScope&) override;
// Unlike RunScript() and RunScriptOnWorker(), callers of the following // Unlike RunScript() and RunScriptOnWorkerOrWorklet(), callers of the
// methods must enter a v8::HandleScope before calling. // following methods must enter a v8::HandleScope before calling.
v8::Local<v8::Value> RunScriptAndReturnValue( v8::Local<v8::Value> RunScriptAndReturnValue(
LocalFrame*, LocalFrame*,
ScriptController::ExecuteScriptPolicy = ScriptController:: ScriptController::ExecuteScriptPolicy = ScriptController::
......
...@@ -7,8 +7,7 @@ ...@@ -7,8 +7,7 @@
#include "third_party/blink/renderer/bindings/core/v8/module_record.h" #include "third_party/blink/renderer/bindings/core/v8/module_record.h"
#include "third_party/blink/renderer/bindings/core/v8/script_value.h" #include "third_party/blink/renderer/bindings/core/v8/script_value.h"
#include "third_party/blink/renderer/core/script/module_record_resolver.h" #include "third_party/blink/renderer/core/script/module_record_resolver.h"
#include "third_party/blink/renderer/core/workers/worker_global_scope.h" #include "third_party/blink/renderer/core/workers/worker_or_worklet_global_scope.h"
#include "third_party/blink/renderer/core/workers/worker_reporting_proxy.h"
#include "third_party/blink/renderer/platform/bindings/script_state.h" #include "third_party/blink/renderer/platform/bindings/script_state.h"
#include "v8/include/v8.h" #include "v8/include/v8.h"
...@@ -111,11 +110,12 @@ void ModuleScript::RunScript(LocalFrame* frame) { ...@@ -111,11 +110,12 @@ void ModuleScript::RunScript(LocalFrame* frame) {
Modulator::CaptureEvalErrorFlag::kReport); Modulator::CaptureEvalErrorFlag::kReport);
} }
bool ModuleScript::RunScriptOnWorker(WorkerGlobalScope& worker_global_scope) { bool ModuleScript::RunScriptOnWorkerOrWorklet(
WorkerOrWorkletGlobalScope& global_scope) {
// We need a HandleScope for the ModuleEvaluationResult that is created // We need a HandleScope for the ModuleEvaluationResult that is created
// in ::ExecuteModule(...). // in ::ExecuteModule(...).
ScriptState::Scope scope(SettingsObject()->GetScriptState()); ScriptState::Scope scope(SettingsObject()->GetScriptState());
DCHECK(worker_global_scope.IsContextThread()); DCHECK(global_scope.IsContextThread());
// This |error| is always null because the second argument is |kReport|. // This |error| is always null because the second argument is |kReport|.
// TODO(nhiroki): Catch an error when an evaluation error happens. // TODO(nhiroki): Catch an error when an evaluation error happens.
...@@ -126,7 +126,6 @@ bool ModuleScript::RunScriptOnWorker(WorkerGlobalScope& worker_global_scope) { ...@@ -126,7 +126,6 @@ bool ModuleScript::RunScriptOnWorker(WorkerGlobalScope& worker_global_scope) {
} }
std::pair<size_t, size_t> ModuleScript::GetClassicScriptSizes() const { std::pair<size_t, size_t> ModuleScript::GetClassicScriptSizes() const {
NOTREACHED();
return std::pair<size_t, size_t>(0, 0); return std::pair<size_t, size_t>(0, 0);
} }
......
...@@ -68,7 +68,7 @@ class CORE_EXPORT ModuleScript : public Script { ...@@ -68,7 +68,7 @@ class CORE_EXPORT ModuleScript : public Script {
return mojom::ScriptType::kModule; return mojom::ScriptType::kModule;
} }
void RunScript(LocalFrame*) override; void RunScript(LocalFrame*) override;
bool RunScriptOnWorker(WorkerGlobalScope&) override; bool RunScriptOnWorkerOrWorklet(WorkerOrWorkletGlobalScope&) override;
std::pair<size_t, size_t> GetClassicScriptSizes() const override; std::pair<size_t, size_t> GetClassicScriptSizes() const override;
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
namespace blink { namespace blink {
class LocalFrame; class LocalFrame;
class WorkerGlobalScope; class WorkerOrWorkletGlobalScope;
// https://html.spec.whatwg.org/C/#concept-script // https://html.spec.whatwg.org/C/#concept-script
class CORE_EXPORT Script : public GarbageCollected<Script> { class CORE_EXPORT Script : public GarbageCollected<Script> {
...@@ -34,9 +34,9 @@ class CORE_EXPORT Script : public GarbageCollected<Script> { ...@@ -34,9 +34,9 @@ class CORE_EXPORT Script : public GarbageCollected<Script> {
// https://html.spec.whatwg.org/C/#run-a-module-script, // https://html.spec.whatwg.org/C/#run-a-module-script,
// depending on the script type, // depending on the script type,
// on Window or on WorkerGlobalScope, respectively. // on Window or on WorkerGlobalScope, respectively.
// RunScriptOnWorker returns true if evaluated successfully. // RunScriptOnWorkerOrWorklet returns true if evaluated successfully.
virtual void RunScript(LocalFrame*) = 0; virtual void RunScript(LocalFrame*) = 0;
virtual bool RunScriptOnWorker(WorkerGlobalScope&) = 0; virtual bool RunScriptOnWorkerOrWorklet(WorkerOrWorkletGlobalScope&) = 0;
const ScriptFetchOptions& FetchOptions() const { return fetch_options_; } const ScriptFetchOptions& FetchOptions() const { return fetch_options_; }
const KURL& BaseURL() const { return base_url_; } const KURL& BaseURL() const { return base_url_; }
......
...@@ -456,7 +456,8 @@ void WorkerGlobalScope::RunWorkerScript() { ...@@ -456,7 +456,8 @@ void WorkerGlobalScope::RunWorkerScript() {
// Step 24. If script is a classic script, then run the classic script script. // Step 24. If script is a classic script, then run the classic script script.
// Otherwise, it is a module script; run the module script script. [spec text] // Otherwise, it is a module script; run the module script script. [spec text]
bool is_success = std::move(worker_script_)->RunScriptOnWorker(*this); bool is_success =
std::move(worker_script_)->RunScriptOnWorkerOrWorklet(*this);
ReportingProxy().DidEvaluateTopLevelScript(is_success); ReportingProxy().DidEvaluateTopLevelScript(is_success);
......
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