From 6bf0a5cb5034a7e684dcc3500e841785237ce2dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 19:32:43 +0200 Subject: Adding upstream version 1:115.7.0. Signed-off-by: Daniel Baumann --- devtools/server/tests/xpcshell/test_nesting-04.js | 86 +++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 devtools/server/tests/xpcshell/test_nesting-04.js (limited to 'devtools/server/tests/xpcshell/test_nesting-04.js') diff --git a/devtools/server/tests/xpcshell/test_nesting-04.js b/devtools/server/tests/xpcshell/test_nesting-04.js new file mode 100644 index 0000000000..dcee257c40 --- /dev/null +++ b/devtools/server/tests/xpcshell/test_nesting-04.js @@ -0,0 +1,86 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +/** + * Verify that we never pause while being already paused. + * i.e. we don't support more than one nested event loops. + */ + +add_task( + threadFrontTest(async ({ commands, threadFront, debuggee }) => { + await threadFront.setBreakpoint({ sourceUrl: "nesting-04.js", line: 2 }); + + const packet = await executeOnNextTickAndWaitForPause( + () => evalCode(debuggee), + threadFront + ); + + Assert.equal(packet.frame.where.line, 5); + Assert.equal(packet.why.type, "debuggerStatement"); + + info("Test calling interrupt"); + const onPaused = waitForPause(threadFront); + await threadFront.interrupt(); + // interrupt() doesn't return anything, but bailout while emitting a paused packet + // But we don't pause again, the reason prove it so + const paused = await onPaused; + equal(paused.why.type, "alreadyPaused"); + + info("Test by evaluating code via the console"); + const { result } = await commands.scriptCommand.execute( + "debugger; functionWithDebuggerStatement()", + { + frameActor: packet.frame.actorID, + } + ); + // The fact that it returned immediately means that we did not pause + equal(result, 42); + + info("Test by calling code from chrome context"); + // This should be equivalent to any actor somehow triggering some page's JS + const rv = debuggee.functionWithDebuggerStatement(); + // The fact that it returned immediately means that we did not pause + equal(rv, 42); + + info("Test by stepping over a function that breaks"); + // This will only step over the debugger; statement we just break on + const step1 = await stepOver(threadFront); + equal(step1.why.type, "resumeLimit"); + equal(step1.frame.where.line, 6); + + // stepOver will actually resume and re-pause on the breakpoint + const step2 = await stepOver(threadFront); + equal(step2.why.type, "breakpoint"); + equal(step2.frame.where.line, 2); + + // Sanity check to ensure that the functionWithDebuggerStatement really pauses + info("Resume and pause on the breakpoint"); + const pausedPacket = await resumeAndWaitForPause(threadFront); + Assert.equal(pausedPacket.frame.where.line, 2); + // The breakpoint takes over the debugger statement + Assert.equal(pausedPacket.why.type, "breakpoint"); + + await threadFront.resume(); + }) +); + +function evalCode(debuggee) { + /* eslint-disable */ + Cu.evalInSandbox( + `function functionWithDebuggerStatement() { + debugger; + return 42; + } + debugger; + functionWithDebuggerStatement(); + var a = 1; + functionWithDebuggerStatement();`, + debuggee, + "1.8", + "nesting-04.js", + 1 + ); + /* eslint-enable */ +} -- cgit v1.2.3