Revert "[inspector] Pass the Context into terminateExecution"

This reverts commit 8016f5c667.

Reason for revert: Causes https://crbug.com/v8/13521 (Cannot create a handle without a HandleScope (v8::HandleScope::CreateHandle())

Original change's description:
> [inspector] Pass the Context into terminateExecution
>
> Adding and removing the MicrotasksCompletedCallback should be
> associated with the microtask queue of the Context. We store the
> context as WeakPtr and always remove the callback when it completes
> regardless of the state of the debugger.
>
> BUG=v8:13450
>
> Change-Id: I40d623b05952575febfb76accc15512a38d14ab9
> Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/4004602
> Commit-Queue: Dave Tapuska <dtapuska@chromium.org>
> Reviewed-by: Simon Zünd <szuend@chromium.org>
> Reviewed-by: Camillo Bruni <cbruni@chromium.org>
> Cr-Commit-Position: refs/heads/main@{#84302}

Bug: v8:13521, v8:13450
Change-Id: Id772d192833e7adba7f4f80c28c437c336f792d2
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/4043829
Reviewed-by: Simon Zünd <szuend@chromium.org>
Commit-Queue: Simon Zünd <szuend@chromium.org>
Auto-Submit: Andrey Kosyakov <caseq@chromium.org>
Cr-Commit-Position: refs/heads/main@{#84410}
This commit is contained in:
Andrey Kosyakov 2022-11-21 21:11:48 +00:00 committed by V8 LUCI CQ
parent a608436b48
commit b908eb3fd2
3 changed files with 10 additions and 43 deletions

View File

@ -84,14 +84,8 @@ V8Debugger::V8Debugger(v8::Isolate* isolate, V8InspectorImpl* inspector)
V8Debugger::~V8Debugger() { V8Debugger::~V8Debugger() {
m_isolate->RemoveCallCompletedCallback( m_isolate->RemoveCallCompletedCallback(
&V8Debugger::terminateExecutionCompletedCallback); &V8Debugger::terminateExecutionCompletedCallback);
if (!m_terminateExecutionCallbackContext.IsEmpty()) { m_isolate->RemoveMicrotasksCompletedCallback(
v8::MicrotaskQueue* microtask_queue = &V8Debugger::terminateExecutionCompletedCallbackIgnoringData);
m_terminateExecutionCallbackContext.Get(m_isolate)
->GetMicrotaskQueue();
microtask_queue->RemoveMicrotasksCompletedCallback(
&V8Debugger::terminateExecutionCompletedCallbackIgnoringData,
microtask_queue);
}
} }
void V8Debugger::enable() { void V8Debugger::enable() {
@ -289,7 +283,6 @@ void V8Debugger::stepOutOfFunction(int targetContextGroupId) {
} }
void V8Debugger::terminateExecution( void V8Debugger::terminateExecution(
v8::Local<v8::Context> context,
std::unique_ptr<TerminateExecutionCallback> callback) { std::unique_ptr<TerminateExecutionCallback> callback) {
if (m_terminateExecutionCallback) { if (m_terminateExecutionCallback) {
if (callback) { if (callback) {
@ -299,35 +292,22 @@ void V8Debugger::terminateExecution(
return; return;
} }
m_terminateExecutionCallback = std::move(callback); m_terminateExecutionCallback = std::move(callback);
m_terminateExecutionCallbackContext.Reset(m_isolate, context);
m_terminateExecutionCallbackContext.SetWeak();
m_isolate->AddCallCompletedCallback( m_isolate->AddCallCompletedCallback(
&V8Debugger::terminateExecutionCompletedCallback); &V8Debugger::terminateExecutionCompletedCallback);
v8::MicrotaskQueue* microtask_queue = context->GetMicrotaskQueue(); m_isolate->AddMicrotasksCompletedCallback(
microtask_queue->AddMicrotasksCompletedCallback( &V8Debugger::terminateExecutionCompletedCallbackIgnoringData);
&V8Debugger::terminateExecutionCompletedCallbackIgnoringData,
microtask_queue);
m_isolate->TerminateExecution(); m_isolate->TerminateExecution();
} }
void V8Debugger::reportTermination() { void V8Debugger::reportTermination() {
if (!m_terminateExecutionCallback) { if (!m_terminateExecutionCallback) return;
DCHECK(m_terminateExecutionCallbackContext.IsEmpty());
return;
}
m_isolate->RemoveCallCompletedCallback( m_isolate->RemoveCallCompletedCallback(
&V8Debugger::terminateExecutionCompletedCallback); &V8Debugger::terminateExecutionCompletedCallback);
if (!m_terminateExecutionCallbackContext.IsEmpty()) { m_isolate->RemoveMicrotasksCompletedCallback(
v8::MicrotaskQueue* microtask_queue = &V8Debugger::terminateExecutionCompletedCallbackIgnoringData);
m_terminateExecutionCallbackContext.Get(m_isolate)->GetMicrotaskQueue();
microtask_queue->RemoveMicrotasksCompletedCallback(
&V8Debugger::terminateExecutionCompletedCallbackIgnoringData,
microtask_queue);
}
m_isolate->CancelTerminateExecution(); m_isolate->CancelTerminateExecution();
m_terminateExecutionCallback->sendSuccess(); m_terminateExecutionCallback->sendSuccess();
m_terminateExecutionCallback.reset(); m_terminateExecutionCallback.reset();
m_terminateExecutionCallbackContext.Reset();
} }
void V8Debugger::terminateExecutionCompletedCallback(v8::Isolate* isolate) { void V8Debugger::terminateExecutionCompletedCallback(v8::Isolate* isolate) {
@ -338,12 +318,7 @@ void V8Debugger::terminateExecutionCompletedCallback(v8::Isolate* isolate) {
} }
void V8Debugger::terminateExecutionCompletedCallbackIgnoringData( void V8Debugger::terminateExecutionCompletedCallbackIgnoringData(
v8::Isolate* isolate, void* data) { v8::Isolate* isolate, void*) {
DCHECK(data);
// Ensure that after every microtask completed callback we remove the
// callback regardless of how `terminateExecutionCompletedCallback` behaves.
static_cast<v8::MicrotaskQueue*>(data)->RemoveMicrotasksCompletedCallback(
&V8Debugger::terminateExecutionCompletedCallbackIgnoringData, data);
terminateExecutionCompletedCallback(isolate); terminateExecutionCompletedCallback(isolate);
} }

View File

@ -71,8 +71,7 @@ class V8Debugger : public v8::debug::DebugDelegate,
void stepOverStatement(int targetContextGroupId); void stepOverStatement(int targetContextGroupId);
void stepOutOfFunction(int targetContextGroupId); void stepOutOfFunction(int targetContextGroupId);
void terminateExecution(v8::Local<v8::Context> context, void terminateExecution(std::unique_ptr<TerminateExecutionCallback> callback);
std::unique_ptr<TerminateExecutionCallback> callback);
Response continueToLocation(int targetContextGroupId, Response continueToLocation(int targetContextGroupId,
V8DebuggerScript* script, V8DebuggerScript* script,
@ -298,7 +297,6 @@ class V8Debugger : public v8::debug::DebugDelegate,
std::unordered_map<int, internal::V8DebuggerId> m_contextGroupIdToDebuggerId; std::unordered_map<int, internal::V8DebuggerId> m_contextGroupIdToDebuggerId;
std::unique_ptr<TerminateExecutionCallback> m_terminateExecutionCallback; std::unique_ptr<TerminateExecutionCallback> m_terminateExecutionCallback;
v8::Global<v8::Context> m_terminateExecutionCallbackContext;
}; };
} // namespace v8_inspector } // namespace v8_inspector

View File

@ -709,13 +709,7 @@ Response V8RuntimeAgentImpl::getHeapUsage(double* out_usedSize,
void V8RuntimeAgentImpl::terminateExecution( void V8RuntimeAgentImpl::terminateExecution(
std::unique_ptr<TerminateExecutionCallback> callback) { std::unique_ptr<TerminateExecutionCallback> callback) {
v8::HandleScope handles(m_inspector->isolate()); m_inspector->debugger()->terminateExecution(std::move(callback));
v8::Local<v8::Context> defaultContext =
m_inspector->client()->ensureDefaultContextInGroup(
m_session->contextGroupId());
m_inspector->debugger()->terminateExecution(defaultContext,
std::move(callback));
} }
namespace { namespace {