[debug] Handle exception thrown in CompileTopLevel
This fixes a bug in which CompileTopLevel has a pending exception that is never taken care of. This CL adds a check for the output of CompileTopLevel and clears the pending exceptions if existent. Also-by: bmeurer@chromium.org Bug: chromium:1190290 Change-Id: Ieba537d5af78fc35475f9547c240c70850bea608 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2773346 Commit-Queue: Kim-Anh Tran <kimanh@chromium.org> Reviewed-by: Yang Guo <yangguo@chromium.org> Reviewed-by: Benedikt Meurer <bmeurer@chromium.org> Cr-Commit-Position: refs/heads/master@{#73561}
This commit is contained in:
parent
7f38169b2e
commit
23c45bf351
@ -1430,13 +1430,22 @@ void FindBreakablePositions(Handle<DebugInfo> debug_info, int start_position,
|
||||
GetBreakablePositions(&it, start_position, end_position, locations);
|
||||
}
|
||||
|
||||
void CompileTopLevel(Isolate* isolate, Handle<Script> script) {
|
||||
bool CompileTopLevel(Isolate* isolate, Handle<Script> script) {
|
||||
UnoptimizedCompileState compile_state(isolate);
|
||||
UnoptimizedCompileFlags flags =
|
||||
UnoptimizedCompileFlags::ForScriptCompile(isolate, *script);
|
||||
ParseInfo parse_info(isolate, flags, &compile_state);
|
||||
IsCompiledScope is_compiled_scope;
|
||||
Compiler::CompileToplevel(&parse_info, script, isolate, &is_compiled_scope);
|
||||
const MaybeHandle<SharedFunctionInfo> maybe_result =
|
||||
Compiler::CompileToplevel(&parse_info, script, isolate,
|
||||
&is_compiled_scope);
|
||||
if (maybe_result.is_null()) {
|
||||
if (isolate->has_pending_exception()) {
|
||||
isolate->clear_pending_exception();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
@ -1606,8 +1615,9 @@ bool Debug::FindSharedFunctionInfosIntersectingRange(
|
||||
maybeToplevel->GetHeapObject(&heap_object) &&
|
||||
!heap_object.IsUndefined();
|
||||
if (!topLevelInfoExists) {
|
||||
CompileTopLevel(isolate_, script);
|
||||
triedTopLevelCompile = true;
|
||||
const bool success = CompileTopLevel(isolate_, script);
|
||||
if (!success) return false;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@ -1660,7 +1670,8 @@ Handle<Object> Debug::FindInnermostContainingFunctionInfo(Handle<Script> script,
|
||||
// It might be that the shared function info is not available as the
|
||||
// top level functions are removed due to the GC. Try to recompile
|
||||
// the top level functions.
|
||||
CompileTopLevel(isolate_, script);
|
||||
const bool success = CompileTopLevel(isolate_, script);
|
||||
if (!success) break;
|
||||
continue;
|
||||
}
|
||||
// We found it if it's already compiled.
|
||||
|
10
test/inspector/debugger/regress-1190290-expected.txt
Normal file
10
test/inspector/debugger/regress-1190290-expected.txt
Normal file
@ -0,0 +1,10 @@
|
||||
Checks if we correctly handle exceptions thrown on setBreakpointByUrl if script is invalid.
|
||||
[
|
||||
]
|
||||
[
|
||||
[0] : {
|
||||
columnNumber : 22
|
||||
lineNumber : 0
|
||||
scriptId : <scriptId>
|
||||
}
|
||||
]
|
42
test/inspector/debugger/regress-1190290.js
Normal file
42
test/inspector/debugger/regress-1190290.js
Normal file
@ -0,0 +1,42 @@
|
||||
// Copyright 2021 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.
|
||||
|
||||
// Flags: --allow-natives-syntax
|
||||
|
||||
let {session, contextGroup, Protocol} = InspectorTest.start(
|
||||
'Checks if we correctly handle exceptions thrown on setBreakpointByUrl if script is invalid.');
|
||||
|
||||
session.setupScriptMap();
|
||||
var executionContextId;
|
||||
|
||||
const invalidFunction = `console.lo g('This is a top level function')`;
|
||||
const moduleFunction =
|
||||
`function testFunc() { console.log('This is a module function') }`;
|
||||
|
||||
Protocol.Debugger.enable().then(onDebuggerEnabled);
|
||||
|
||||
function onDebuggerEnabled() {
|
||||
Protocol.Runtime.enable();
|
||||
Protocol.Runtime.onExecutionContextCreated(onExecutionContextCreated);
|
||||
}
|
||||
|
||||
async function onExecutionContextCreated(messageObject) {
|
||||
executionContextId = messageObject.params.context.id;
|
||||
await testSetBreakpoint(
|
||||
executionContextId, invalidFunction, 'invalidFunc.js');
|
||||
await testSetBreakpoint(executionContextId, moduleFunction, 'moduleFunc.js');
|
||||
InspectorTest.completeTest();
|
||||
}
|
||||
|
||||
async function testSetBreakpoint(executionContextId, func, url) {
|
||||
await Protocol.Runtime.compileScript({
|
||||
expression: func,
|
||||
sourceURL: url,
|
||||
persistScript: true,
|
||||
executionContextId: executionContextId
|
||||
});
|
||||
const {result: {locations}} =
|
||||
await Protocol.Debugger.setBreakpointByUrl({lineNumber: 0, url});
|
||||
InspectorTest.logMessage(locations);
|
||||
}
|
Loading…
Reference in New Issue
Block a user