[debug] handle termination after break

If termination was requested on pause we should handle it properly as
soon as execution resumed.

R=yangguo@chromium.org

Cq-Include-Trybots: master.tryserver.blink:linux_trusty_blink_rel
Change-Id: Ica50500094138097f115545db716264126fbe59e
Reviewed-on: https://chromium-review.googlesource.com/1049486
Commit-Queue: Aleksey Kozyatinskiy <kozyatinskiy@chromium.org>
Reviewed-by: Yang Guo <yangguo@chromium.org>
Reviewed-by: Jakob Gruber <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/master@{#53074}
This commit is contained in:
Alexey Kozyatinskiy 2018-05-08 06:44:36 -07:00 committed by Commit Bot
parent 8ae6bc6068
commit 4c5926d593
7 changed files with 62 additions and 4 deletions

View File

@ -90,6 +90,7 @@ v8::MaybeLocal<v8::Value> V8InspectorImpl::compileAndRunInternalScript(
v8::MicrotasksScope microtasksScope(m_isolate,
v8::MicrotasksScope::kDoNotRunMicrotasks);
v8::Context::Scope contextScope(context);
v8::Isolate::SafeForTerminationScope allowTermination(m_isolate);
return unboundScript->BindToCurrentContext()->Run(context);
}

View File

@ -80,8 +80,16 @@ RUNTIME_FUNCTION_RETURN_PAIR(Runtime_DebugBreakOnBytecode) {
isolate->interpreter()->GetAndMaybeDeserializeBytecodeHandler(bytecode,
operand_scale);
return MakePair(side_effect_check_failed ? isolate->heap()->exception()
: isolate->debug()->return_value(),
if (side_effect_check_failed) {
return MakePair(isolate->heap()->exception(),
Smi::FromInt(static_cast<uint8_t>(bytecode)));
}
Object* interrupt_object = isolate->stack_guard()->HandleInterrupts();
if (interrupt_object->IsException(isolate)) {
return MakePair(interrupt_object,
Smi::FromInt(static_cast<uint8_t>(bytecode)));
}
return MakePair(isolate->debug()->return_value(),
Smi::FromInt(static_cast<uint8_t>(bytecode)));
}
@ -116,7 +124,7 @@ RUNTIME_FUNCTION(Runtime_HandleDebuggerStatement) {
if (isolate->debug()->break_points_active()) {
isolate->debug()->HandleDebugBreak(kIgnoreIfTopFrameBlackboxed);
}
return isolate->heap()->undefined_value();
return isolate->stack_guard()->HandleInterrupts();
}

View File

@ -6021,7 +6021,6 @@ static void DebugBreakInlineListener(
result->Int32Value(context).FromJust()));
}
SetDebugEventListener(CcTest::isolate(), nullptr);
CcTest::isolate()->TerminateExecution();
}

View File

@ -0,0 +1,5 @@
Tests Runtime.terminateExecution on pause
Running test: testTerminateOnDebugger
Running test: testTerminateAtBreakpoint

View File

@ -0,0 +1,43 @@
// Copyright 2018 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
let {session, contextGroup, Protocol} =
InspectorTest.start('Tests Runtime.terminateExecution on pause');
Protocol.Runtime.enable();
Protocol.Runtime.onConsoleAPICalled(
message => InspectorTest.logMessage(message.params.args[0]));
Protocol.Debugger.enable();
InspectorTest.runAsyncTestSuite([
async function testTerminateOnDebugger() {
Protocol.Runtime.evaluate({expression: `
function callback() {
debugger;
console.log(42);
setTimeout(callback, 0);
}
callback();
//# sourceURL=test.js`});
await Protocol.Debugger.oncePaused();
const terminated = Protocol.Runtime.terminateExecution();
Protocol.Debugger.resume();
await terminated;
},
async function testTerminateAtBreakpoint() {
Protocol.Debugger.setBreakpointByUrl({url: 'test.js', lineNumber: 2});
Protocol.Runtime.evaluate({expression: `
function callback() {
console.log(42);
setTimeout(callback, 0);
}
callback();
//# sourceURL=test.js`});
await Protocol.Debugger.oncePaused();
const terminated = Protocol.Runtime.terminateExecution();
Protocol.Debugger.resume();
await terminated;
}
]);

View File

@ -240,6 +240,7 @@ class ExecuteStringTask : public TaskRunner::Task {
expression_utf8_.length());
v8::ScriptCompiler::Source scriptSource(source, origin);
v8::Isolate::SafeForTerminationScope allowTermination(data->isolate());
if (!is_module_) {
v8::Local<v8::Script> script;
if (!v8::ScriptCompiler::Compile(context, &scriptSource).ToLocal(&script))

View File

@ -63,6 +63,7 @@ IsolateData::IsolateData(TaskRunner* task_runner,
params.array_buffer_allocator =
v8::ArrayBuffer::Allocator::NewDefaultAllocator();
params.snapshot_blob = startup_data;
params.only_terminate_in_safe_scope = true;
isolate_.reset(v8::Isolate::New(params));
isolate_->SetMicrotasksPolicy(v8::MicrotasksPolicy::kScoped);
if (with_inspector) {