diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /devtools/client/debugger/test/mochitest/browser_dbg-returnvalues.js | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'devtools/client/debugger/test/mochitest/browser_dbg-returnvalues.js')
-rw-r--r-- | devtools/client/debugger/test/mochitest/browser_dbg-returnvalues.js | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/devtools/client/debugger/test/mochitest/browser_dbg-returnvalues.js b/devtools/client/debugger/test/mochitest/browser_dbg-returnvalues.js new file mode 100644 index 0000000000..a0c070ab2d --- /dev/null +++ b/devtools/client/debugger/test/mochitest/browser_dbg-returnvalues.js @@ -0,0 +1,106 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */ + +"use strict"; + +add_task(async function () { + const dbg = await initDebugger("doc-return-values.html"); + await togglePauseOnExceptions(dbg, true, true); + + info("Test return values"); + await testReturnValue(dbg, "to sender", [ + { label: "return_something" }, + { label: "<return>", value: uneval("to sender") }, + ]); + await testReturnValue(dbg, "undefined", [ + { label: "return_something" }, + { label: "<return>", value: '"undefined"' }, + ]); + await testReturnValue(dbg, 2, [ + { label: "return_something" }, + { label: "<return>", value: "2" }, + ]); + await testReturnValue(dbg, new Error("blah"), [ + { label: "return_something" }, + { label: "<return>", value: "Restricted" }, + ]); + + info("Test throw values"); + await testThrowValue(dbg, "a fit", [ + { label: "callee" }, + // The "uneval" call here gives us the way one would write `val` as + // a JavaScript expression, similar to the way the debugger + // displays values, so this test works when `val` is a string. + { label: "<exception>", value: uneval("a fit") }, + ]); + await testThrowValue(dbg, "undefined", [ + { label: "callee" }, + { label: "<exception>", value: '"undefined"' }, + ]); + await testThrowValue(dbg, 2, [ + { label: "callee" }, + { label: "<exception>", value: "2" }, + ]); + await testThrowValue(dbg, new Error("blah"), [ + { label: "callee" }, + { label: "<exception>", value: "Restricted" }, + ]); +}); + +async function testReturnValue(dbg, val, expectedScopeNodes) { + invokeInTab("return_something", val); + await waitForPaused(dbg); + + // "Step in" 2 times to get to the point where the debugger can + // see the return value. + await stepIn(dbg); + await stepIn(dbg); + + for (const [i, scopeNode] of expectedScopeNodes.entries()) { + const index = i + 1; + is( + getScopeNodeLabel(dbg, index), + scopeNode.label, + `check for ${scopeNode.label}` + ); + if (scopeNode.value) { + is( + getScopeNodeValue(dbg, index), + scopeNode.value, + `check value is ${scopeNode.value}` + ); + } + } + + await resume(dbg); + assertNotPaused(dbg); +} + +async function testThrowValue(dbg, val, expectedScopeNodes) { + invokeInTab("throw_something", val); + await waitForPaused(dbg); + + // "Step in" once to get to the point where the debugger can see the + // exception. + await stepIn(dbg); + + for (const [i, scopeNode] of expectedScopeNodes.entries()) { + const index = i + 1; + is( + getScopeNodeLabel(dbg, index), + scopeNode.label, + `check for ${scopeNode.label}` + ); + if (scopeNode.value) { + is( + getScopeNodeValue(dbg, index), + scopeNode.value, + `check exception is ${scopeNode.value}` + ); + } + } + + await resume(dbg); + assertNotPaused(dbg); +} |