summaryrefslogtreecommitdiff
path: root/deps/v8/test/inspector/runtime/exception-thrown-breakpoint-conditions.js
diff options
context:
space:
mode:
Diffstat (limited to 'deps/v8/test/inspector/runtime/exception-thrown-breakpoint-conditions.js')
-rw-r--r--deps/v8/test/inspector/runtime/exception-thrown-breakpoint-conditions.js71
1 files changed, 71 insertions, 0 deletions
diff --git a/deps/v8/test/inspector/runtime/exception-thrown-breakpoint-conditions.js b/deps/v8/test/inspector/runtime/exception-thrown-breakpoint-conditions.js
new file mode 100644
index 0000000000..e569eea8a0
--- /dev/null
+++ b/deps/v8/test/inspector/runtime/exception-thrown-breakpoint-conditions.js
@@ -0,0 +1,71 @@
+// Copyright 2023 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.
+
+const { session, contextGroup, Protocol } = InspectorTest.start("Check that throwing breakpoint conditions report exceptions via Runtime.exceptionThrown.");
+
+contextGroup.addScript(`
+function smallFnWithLogpoint(x) {
+ return x + 42;
+}
+`, 0, 0, 'test.js');
+
+Protocol.Runtime.onExceptionThrown(({ params: { exceptionDetails } }) => {
+ const { description } = exceptionDetails.exception;
+ InspectorTest.log(`Exception thrown: ${description}`);
+});
+
+async function testSyntaxError() {
+ const { result: { breakpointId } } = await Protocol.Debugger.setBreakpointByUrl({
+ lineNumber: 3,
+ url: 'test.js',
+ condition: 'x ===',
+ });
+ await Protocol.Runtime.evaluate({ expression: 'smallFnWithLogpoint(5)' });
+ await Protocol.Debugger.removeBreakpoint({ breakpointId });
+}
+
+async function testRepeatedErrorsOnlyCauseOneEvent() {
+ const { result: { breakpointId } } = await Protocol.Debugger.setBreakpointByUrl({
+ lineNumber: 3,
+ url: 'test.js',
+ condition: 'x ===',
+ });
+ await Protocol.Runtime.evaluate({
+ expression: 'for (let i = 0; i < 5; ++i) smallFnWithLogpoint(5);' });
+ await Protocol.Debugger.removeBreakpoint({ breakpointId });
+}
+
+async function testSporadicThrowing() {
+ // Tests that a breakpoint condition going from throwing -> succeeding -> throwing
+ // logs two events.
+ const { result: { breakpointId } } = await Protocol.Debugger.setBreakpointByUrl({
+ lineNumber: 3,
+ url: 'test.js',
+ condition: 'y === 42',
+ });
+ // Causes a reference error as `y` is not defined.
+ await Protocol.Runtime.evaluate({ expression: 'smallFnWithLogpoint(5)' });
+
+ // Introduce y and trigger breakpoint again.
+ const evalPromise = Protocol.Runtime.evaluate({ expression: 'globalThis.y = 42; smallFnWithLogpoint(5)' });
+ await Protocol.Debugger.oncePaused();
+ InspectorTest.log('Paused on conditional logpoint');
+ await Promise.all([Protocol.Debugger.resume(), evalPromise]);
+
+ // Delete 'y' again, trigger breakpoint and expect an exception event.
+ await Protocol.Runtime.evaluate({ expression: 'delete globalThis.y; smallFnWithLogpoint(5)' });
+
+ await Protocol.Debugger.removeBreakpoint({ breakpointId });
+}
+
+InspectorTest.runAsyncTestSuite([
+ async function setUp() {
+ Protocol.Debugger.enable();
+ Protocol.Runtime.enable();
+ await Protocol.Debugger.onceScriptParsed();
+ },
+ testSyntaxError,
+ testRepeatedErrorsOnlyCauseOneEvent,
+ testSporadicThrowing,
+]);