8319882972
Use case: anonymous script with sourceMappingUrl. User can set breakpoint in source with sourceUrl from sourceMap, we persist this breakpoint in DevTools and on page reload breakpoint should be restored correctly. Debugger.setBreakpointByUrl method provides capabilities to set provisional breakpoints and looks like best candidate for new "scriptHash" argument. I considered other options such as replacing scriptId with something more persistent like "script-hash:script-with-this-hash-number" but it looks more complicated and doesn't provide clear advantages. One pager: http://bit.ly/2wkRHnt R=pfeldman@chromium.org Bug: chromium:459499 Cq-Include-Trybots: master.tryserver.blink:linux_trusty_blink_rel Change-Id: I0e2833fceffe6b04afac01d1a4522d6874b6067a Reviewed-on: https://chromium-review.googlesource.com/683597 Commit-Queue: Aleksey Kozyatinskiy <kozyatinskiy@chromium.org> Reviewed-by: Dmitry Gozman <dgozman@chromium.org> Cr-Commit-Position: refs/heads/master@{#48357}
70 lines
3.2 KiB
JavaScript
70 lines
3.2 KiB
JavaScript
// Copyright 2017 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('Checks provisional breakpoints by hash in anonymous scripts');
|
|
session.setupScriptMap();
|
|
|
|
InspectorTest.runAsyncTestSuite([
|
|
async function testNextScriptParsed() {
|
|
await Protocol.Debugger.enable();
|
|
// set breakpoint in anonymous script..
|
|
Protocol.Runtime.evaluate({expression: 'function foo(){}'});
|
|
let {params:{hash}} = await Protocol.Debugger.onceScriptParsed();
|
|
let {result:{breakpointId}} = await Protocol.Debugger.setBreakpointByUrl({
|
|
scriptHash: hash,
|
|
lineNumber: 0,
|
|
columnNumber: 15
|
|
});
|
|
// evaluate the same anonymous script again..
|
|
Protocol.Runtime.evaluate({expression: 'function foo(){}'});
|
|
// run function and check Debugger.paused event..
|
|
let evaluation = Protocol.Runtime.evaluate({expression: 'foo()'});
|
|
let result = await Promise.race([evaluation, Protocol.Debugger.oncePaused()]);
|
|
if (result.method !== 'Debugger.paused') {
|
|
InspectorTest.log('FAIL: breakpoint was ignored');
|
|
} else {
|
|
await session.logSourceLocation(result.params.callFrames[0].location);
|
|
}
|
|
// remove breakpoint and run again..
|
|
await Protocol.Debugger.removeBreakpoint({breakpointId});
|
|
evaluation = Protocol.Runtime.evaluate({expression: 'foo()'});
|
|
result = await Promise.race([evaluation, Protocol.Debugger.oncePaused()]);
|
|
if (result.method === 'Debugger.paused') {
|
|
InspectorTest.log('FAIL: breakpoint was not removed');
|
|
}
|
|
await Protocol.Debugger.disable();
|
|
},
|
|
async function testPreviousScriptParsed() {
|
|
await Protocol.Debugger.enable();
|
|
// run script and store function to global list..
|
|
await Protocol.Runtime.evaluate({expression: 'var list = list ? list.concat(foo) : [foo]; function foo(){}'});
|
|
// run same script again..
|
|
Protocol.Runtime.evaluate({expression: 'var list = list ? list.concat(foo) : [foo]; function foo(){}'});
|
|
let {params:{hash}} = await Protocol.Debugger.onceScriptParsed();
|
|
// set breakpoint by hash of latest script..
|
|
let {result:{breakpointId}} = await Protocol.Debugger.setBreakpointByUrl({
|
|
scriptHash: hash,
|
|
lineNumber: 0,
|
|
columnNumber: 49
|
|
});
|
|
// call each function in global list and wait for Debugger.paused events..
|
|
let evaluation = Protocol.Runtime.evaluate({expression: 'list.forEach(x => x())'});
|
|
let result = await Promise.race([evaluation, Protocol.Debugger.oncePaused()]);
|
|
while (result.method === 'Debugger.paused') {
|
|
await session.logSourceLocation(result.params.callFrames[0].location);
|
|
Protocol.Debugger.resume();
|
|
result = await Promise.race([evaluation, Protocol.Debugger.oncePaused()]);
|
|
}
|
|
// remove breakpoint and call functions again..
|
|
await Protocol.Debugger.removeBreakpoint({breakpointId});
|
|
evaluation = Protocol.Runtime.evaluate({expression: 'foo()'});
|
|
result = await Promise.race([evaluation, Protocol.Debugger.oncePaused()]);
|
|
if (result.method === 'Debugger.paused') {
|
|
InspectorTest.log('FAIL: breakpoint was not removed');
|
|
}
|
|
await Protocol.Debugger.disable();
|
|
}
|
|
]);
|