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

Remove dependency from WorkerThreadDebugger to global scope's Url()

Previously, WorkerThreadDebugger::ContextCreated() sets
V8ContextInfo using global scope's Url().
However, After [1] Url() can be null when the global scope is
created and thus ContextCreated() can't use Url().

This CL uses |GlobalScopeCreationParams::script_url| instead.
This CL shouldn't change the behavior, because currently
global scope's Url() is equal to
|GlobalScopeCreationParams::script_url|.

[1] https://chromium-review.googlesource.com/1139074

Bug: 866666, 861564
Change-Id: Ic19a87d77c4b01d3f850e51ce734dae11e1b4e44
Reviewed-on: https://chromium-review.googlesource.com/1139052Reviewed-by: default avatarAleksey Kozyatinskiy <kozyatinskiy@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Reviewed-by: default avatarIan Kilpatrick <ikilpatrick@chromium.org>
Reviewed-by: default avatarHiroki Nakagawa <nhiroki@chromium.org>
Commit-Queue: Hiroshige Hayashizaki <hiroshige@chromium.org>
Cr-Commit-Position: refs/heads/master@{#579702}
parent 38f920aa
......@@ -129,8 +129,7 @@ void WorkerOrWorkletScriptController::DisposeContextIfNeeded() {
if (!IsContextInitialized())
return;
if (global_scope_->IsWorkerGlobalScope() ||
global_scope_->IsThreadedWorkletGlobalScope()) {
if (!global_scope_->IsMainThreadWorkletGlobalScope()) {
ScriptState::Scope scope(script_state_);
WorkerThreadDebugger* debugger = WorkerThreadDebugger::From(isolate_);
debugger->ContextWillBeDestroyed(global_scope_->GetThread(),
......@@ -142,7 +141,8 @@ void WorkerOrWorkletScriptController::DisposeContextIfNeeded() {
}
bool WorkerOrWorkletScriptController::InitializeContextIfNeeded(
const String& human_readable_name) {
const String& human_readable_name,
const KURL& url_for_debugger) {
v8::HandleScope handle_scope(isolate_);
if (IsContextInitialized())
......@@ -230,19 +230,19 @@ bool WorkerOrWorkletScriptController::InitializeContextIfNeeded(
// So we explicitly call constructorForType for the global object.
V8PerContextData::From(context)->ConstructorForType(wrapper_type_info);
// Name new context for debugging. For main thread worklet global scopes
// this is done once the context is initialized.
if (global_scope_->IsWorkerGlobalScope() ||
global_scope_->IsThreadedWorkletGlobalScope()) {
if (global_scope_->IsMainThreadWorkletGlobalScope()) {
// Set the human readable name for the world if the call passes an actual
// |human_readable name|.
if (!human_readable_name.IsEmpty()) {
world_->SetNonMainWorldHumanReadableName(world_->GetWorldId(),
human_readable_name);
}
} else {
// Name new context for debugging. For main thread worklet global scopes
// this is done once the context is initialized.
WorkerThreadDebugger* debugger = WorkerThreadDebugger::From(isolate_);
debugger->ContextCreated(global_scope_->GetThread(), context);
}
// Set the human readable name for the world if the call passes an actual
// |human_readable name|.
if (!human_readable_name.IsEmpty()) {
world_->SetNonMainWorldHumanReadableName(world_->GetWorldId(),
human_readable_name);
debugger->ContextCreated(global_scope_->GetThread(), url_for_debugger,
context);
}
wrapper_type_info->InstallConditionalFeatures(
......@@ -262,11 +262,11 @@ bool WorkerOrWorkletScriptController::InitializeContextIfNeeded(
ScriptValue WorkerOrWorkletScriptController::EvaluateInternal(
const ScriptSourceCode& source_code,
V8CacheOptions v8_cache_options) {
DCHECK(IsContextInitialized());
TRACE_EVENT1("devtools.timeline", "EvaluateScript", "data",
InspectorEvaluateScriptEvent::Data(nullptr, source_code.Url(),
source_code.StartPosition()));
if (!InitializeContextIfNeeded(String()))
return ScriptValue();
ScriptState::Scope scope(script_state_);
......
......@@ -69,7 +69,12 @@ class CORE_EXPORT WorkerOrWorkletScriptController final
// Used by WorkerThread. Returns true if the context is successfully
// initialized or already initialized.
bool InitializeContextIfNeeded(const String& human_readable_name);
// For WorkerGlobalScope and ThreadedWorkletGlobalScope, |url_for_debugger| is
// and should be used only for setting name/origin that appears in DevTools.
// For other global scopes, |human_readable_name| is used for setting
// DOMWrapperWorld's human readable name.
bool InitializeContextIfNeeded(const String& human_readable_name,
const KURL& url_for_debugger);
// Used by WorkerGlobalScope:
void RethrowExceptionFromImportedScript(ErrorEvent*, ExceptionState&);
......
......@@ -101,12 +101,13 @@ void WorkerThreadDebugger::WorkerThreadDestroyed(WorkerThread* worker_thread) {
}
void WorkerThreadDebugger::ContextCreated(WorkerThread* worker_thread,
const KURL& url_for_debugger,
v8::Local<v8::Context> context) {
int worker_context_group_id = ContextGroupId(worker_thread);
DCHECK(worker_threads_.Contains(worker_context_group_id));
v8_inspector::V8ContextInfo context_info(context, worker_context_group_id,
v8_inspector::StringView());
String origin = worker_thread->GlobalScope()->Url().GetString();
String origin = url_for_debugger;
context_info.origin = ToV8InspectorStringView(origin);
GetV8Inspector()->contextCreated(context_info);
}
......
......@@ -52,7 +52,9 @@ class CORE_EXPORT WorkerThreadDebugger final : public ThreadDebugger {
int ContextGroupId(WorkerThread*);
void WorkerThreadCreated(WorkerThread*);
void WorkerThreadDestroyed(WorkerThread*);
void ContextCreated(WorkerThread*, v8::Local<v8::Context>);
void ContextCreated(WorkerThread*,
const KURL& url_for_debugger,
v8::Local<v8::Context>);
void ContextWillBeDestroyed(WorkerThread*, v8::Local<v8::Context>);
void ExceptionThrown(WorkerThread*, ErrorEvent*);
......
......@@ -31,7 +31,8 @@ LayoutWorkletGlobalScope* LayoutWorkletGlobalScope::Create(
reporting_proxy, pending_layout_registry);
String context_name("LayoutWorklet #");
context_name.append(String::Number(global_scope_number));
global_scope->ScriptController()->InitializeContextIfNeeded(context_name);
global_scope->ScriptController()->InitializeContextIfNeeded(context_name,
NullURL());
MainThreadDebugger::Instance()->ContextCreated(
global_scope->ScriptController()->GetScriptState(),
global_scope->GetFrame(), global_scope->DocumentSecurityOrigin());
......
......@@ -192,7 +192,8 @@ void ModuleScriptLoaderTest::InitializeForWorklet() {
kV8CacheOptionsDefault, new WorkletModuleResponsesMap);
global_scope_ = new MainThreadWorkletGlobalScope(
&GetFrame(), std::move(creation_params), *reporting_proxy_);
global_scope_->ScriptController()->InitializeContextIfNeeded("Dummy Context");
global_scope_->ScriptController()->InitializeContextIfNeeded("Dummy Context",
NullURL());
modulator_ = new ModuleScriptLoaderTestModulator(
global_scope_->ScriptController()->GetScriptState(),
GetDocument().GetSecurityOrigin(), fetcher);
......
......@@ -420,6 +420,8 @@ void WorkerThread::InitializeOnWorkerThread(
}
GetWorkerBackingThread().BackingThread().AddTaskObserver(this);
const KURL url_for_debugger = global_scope_creation_params->script_url;
console_message_storage_ = new ConsoleMessageStorage();
global_scope_ =
CreateWorkerGlobalScope(std::move(global_scope_creation_params));
......@@ -436,7 +438,7 @@ void WorkerThread::InitializeOnWorkerThread(
// TODO(nhiroki): Handle a case where the script controller fails to
// initialize the context.
if (GlobalScope()->ScriptController()->InitializeContextIfNeeded(
String())) {
String(), url_for_debugger)) {
worker_reporting_proxy_.DidInitializeWorkerContext();
v8::HandleScope handle_scope(GetIsolate());
Platform::Current()->WorkerContextCreated(
......
......@@ -98,7 +98,8 @@ PaintWorkletGlobalScope* PaintWorkletGlobalScope::Create(
reporting_proxy, pending_generator_registry);
String context_name("PaintWorklet #");
context_name.append(String::Number(global_scope_number));
global_scope->ScriptController()->InitializeContextIfNeeded(context_name);
global_scope->ScriptController()->InitializeContextIfNeeded(context_name,
NullURL());
MainThreadDebugger::Instance()->ContextCreated(
global_scope->ScriptController()->GetScriptState(),
global_scope->GetFrame(), global_scope->DocumentSecurityOrigin());
......
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