Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1032)

Unified Diff: test/inspector/debugger/get-possible-breakpoints-restrict-to-function.js

Issue 2710953004: [inspector] added restrictToFunction flag for getPossibleBreakpoints (Closed)
Patch Set: addressed comments Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: test/inspector/debugger/get-possible-breakpoints-restrict-to-function.js
diff --git a/test/inspector/debugger/get-possible-breakpoints-restrict-to-function.js b/test/inspector/debugger/get-possible-breakpoints-restrict-to-function.js
new file mode 100644
index 0000000000000000000000000000000000000000..1ce440594d127cd471e963f94e2e4f969166d6bc
--- /dev/null
+++ b/test/inspector/debugger/get-possible-breakpoints-restrict-to-function.js
@@ -0,0 +1,120 @@
+// Copyright 2016 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.
+
+print('Checks Debugger.getPossibleBreakpoints with ignoreNestedFunctions');
+
+var source = `
+function test() {
+ Array.from([1,2]).map(() => 1).filter(() => true);
+ function nested1() {
+ Array.from([1,2]).map(() => 1).filter(() => true);
+ }
+ function nested2() {
+ Array.from([1,2]).map(() => 1).filter(() => true);
+ }
+ nested1();
+ nested2();
+}
+//# sourceURL=test.js`;
+InspectorTest.addScript(source);
+
+var scriptId;
+Protocol.Debugger.onceScriptParsed().then(message => {
+ if (message.params.url === 'test.js')
+ scriptId = message.params.scriptId;
+}).then(() => InspectorTest.runTestSuite(tests));
+
+InspectorTest.setupScriptMap();
+Protocol.Debugger.onPaused(dumpBreakLocationInSourceAndResume);
+
+Protocol.Debugger.enable();
+var tests = [
+ function testWholeFunction(next) {
+ Protocol.Debugger.getPossibleBreakpoints({ start: location(1, 18), ignoreNestedFunctions: false })
+ .then(dumpAllLocations)
+ .then(next);
+ },
+
+ function testWholeFunctionWithoutNested(next) {
+ Protocol.Debugger.getPossibleBreakpoints({ start: location(1, 18), ignoreNestedFunctions: true })
+ .then(dumpAllLocations)
+ .then(next);
+ },
+
+ function testPartOfFunctionWithoutNested(next) {
+ Protocol.Debugger.getPossibleBreakpoints({ start: location(1, 18), end: location(2, 18), ignoreNestedFunctions: true })
+ .then(dumpAllLocations)
+ .then(next);
+ },
+
+ function testNestedFunction(next) {
+ Protocol.Debugger.getPossibleBreakpoints({ start: location(4, 0), ignoreNestedFunctions: true })
+ .then(dumpAllLocations)
+ .then(setAllBreakpoints)
+ .then(() => InspectorTest.log('Run test() to check breakpoints..'))
+ .then(() => Protocol.Runtime.evaluate({ expression: 'test()' }))
+ .then(next);
+ }
+];
+
+function location(lineNumber, columnNumber) {
+ return { lineNumber: lineNumber, columnNumber: columnNumber, scriptId: scriptId };
+}
+
+function setAllBreakpoints(message) {
+ var promises = [];
+ for (var location of message.result.locations)
+ promises.push(Protocol.Debugger.setBreakpoint({ location: location }).then(checkBreakpoint));
+ return Promise.all(promises);
+}
+
+function checkBreakpoint(message) {
+ if (message.error) {
+ InspectorTest.log('FAIL: error in setBreakpoint');
+ InspectorTest.logMessage(message);
+ return;
+ }
+ var id_data = message.result.breakpointId.split(':');
+ if (parseInt(id_data[1]) !== message.result.actualLocation.lineNumber || parseInt(id_data[2]) !== message.result.actualLocation.columnNumber) {
+ InspectorTest.log('FAIL: possible breakpoint was resolved in another location');
+ }
+}
+
+function dumpAllLocations(message) {
+ if (message.error) {
+ InspectorTest.logMessage(message);
+ return;
+ }
+
+ var sourceLines = source.split('\n')
+ var lineOffsets = Array(sourceLines.length).fill(0);
+ for (var location of message.result.locations) {
+ var lineNumber = location.lineNumber;
+ var columnNumber = location.columnNumber;
+ var line = sourceLines[lineNumber] || '';
+ var offset = lineOffsets[lineNumber];
+ line = line.slice(0, columnNumber + offset) + '#' + line.slice(columnNumber + offset);
+ ++lineOffsets[lineNumber];
+ sourceLines[lineNumber] = line;
+ }
+ InspectorTest.log(sourceLines.join('\n'));
+ return message;
+}
+
+function dumpBreakLocationInSourceAndResume(message) {
+ InspectorTest.logCallFrames([ message.params.callFrames[0] ]);
+
+ var location = message.params.callFrames[0].location;
+ var sourceLines = source.split('\n')
+
+ var lineNumber = location.lineNumber
+ var columnNumber = location.columnNumber;
+
+ var line = sourceLines[lineNumber];
+ line = line.slice(0, columnNumber) + '^' + line.slice(columnNumber);
+ sourceLines[lineNumber] = line;
+ InspectorTest.log(sourceLines.join('\n'));
+ InspectorTest.log('');
+ Protocol.Debugger.resume();
+}

Powered by Google App Engine
This is Rietveld 408576698