summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/debug/Frame-environment-06.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
commit26a029d407be480d791972afb5975cf62c9360a6 (patch)
treef435a8308119effd964b339f76abb83a57c29483 /js/src/jit-test/tests/debug/Frame-environment-06.js
parentInitial commit. (diff)
downloadfirefox-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 'js/src/jit-test/tests/debug/Frame-environment-06.js')
-rw-r--r--js/src/jit-test/tests/debug/Frame-environment-06.js105
1 files changed, 105 insertions, 0 deletions
diff --git a/js/src/jit-test/tests/debug/Frame-environment-06.js b/js/src/jit-test/tests/debug/Frame-environment-06.js
new file mode 100644
index 0000000000..6faea6ad52
--- /dev/null
+++ b/js/src/jit-test/tests/debug/Frame-environment-06.js
@@ -0,0 +1,105 @@
+// |jit-test| error:all-jobs-completed-successfully
+// Test that Debugger.Frame.prototype.environment works on suspended
+// async function.
+
+load(libdir + "asserts.js");
+
+const g = newGlobal({ newCompartment: true });
+const dbg = new Debugger(g);
+
+g.eval(`
+var resolveTop;
+var resolveBlock;
+var resolveLoop;
+var resolveCatch;
+
+async function f() {
+ var promises = {
+ top: new Promise(r => { resolveTop = r; }),
+ block: new Promise(r => { resolveBlock = r; }),
+ loop: new Promise(r => { resolveLoop = r; }),
+ catch: new Promise(r => { resolveCatch = r; }),
+ };
+
+ var value = 42;
+ Promise.resolve().then(resolveTop);
+ await promises.top;
+ {
+ let block = "block";
+ Promise.resolve().then(resolveBlock);
+ await promises.block;
+ }
+ for (let loop of ["loop"]) {
+ Promise.resolve().then(resolveLoop);
+ await promises.loop;
+ }
+ try {
+ throw "err";
+ } catch (err) {
+ Promise.resolve().then(resolveCatch);
+ await promises.catch;
+ }
+ return value;
+}
+`);
+
+const waitForOnPop = frame => new Promise(r => {
+ assertEq(frame.onPop, undefined);
+ frame.onPop = () => {
+ frame.onPop = undefined;
+ r();
+ };
+});
+
+let frame;
+dbg.onEnterFrame = f => {
+ frame = f;
+ dbg.onEnterFrame = undefined;
+};
+
+(async () => {
+ const promise = g.f();
+
+ assertEq(!!frame, true);
+ assertEq(
+ JSON.stringify(frame.environment.names()),
+ JSON.stringify(["arguments", "promises", "value"])
+ );
+ assertEq(frame.environment.getVariable("value"), 42);
+
+ frame.environment.setVariable("value", 43);
+
+ assertEq(frame.environment.getVariable("value"), 43);
+
+ await waitForOnPop(frame);
+
+ assertEq(
+ JSON.stringify(frame.environment.names()),
+ JSON.stringify(["block"])
+ );
+ assertEq(frame.environment.getVariable("block"), "block");
+
+ await waitForOnPop(frame);
+
+ assertEq(
+ JSON.stringify(frame.environment.names()),
+ JSON.stringify(["loop"])
+ );
+ assertEq(frame.environment.getVariable("loop"), "loop");
+
+ await waitForOnPop(frame);
+
+ assertEq(
+ JSON.stringify(frame.environment.names()),
+ JSON.stringify(["err"])
+ );
+ assertEq(frame.environment.getVariable("err"), "err");
+
+ const result = await promise;
+
+ assertEq(result, 43);
+
+ assertThrowsInstanceOf(() => frame.environment, Error);
+
+ throw "all-jobs-completed-successfully";
+})();