summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/debug/Frame-onPop-generators-03.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
commit2aa4a82499d4becd2284cdb482213d541b8804dd (patch)
treeb80bf8bf13c3766139fbacc530efd0dd9d54394c /js/src/jit-test/tests/debug/Frame-onPop-generators-03.js
parentInitial commit. (diff)
downloadfirefox-upstream.tar.xz
firefox-upstream.zip
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/jit-test/tests/debug/Frame-onPop-generators-03.js')
-rw-r--r--js/src/jit-test/tests/debug/Frame-onPop-generators-03.js42
1 files changed, 42 insertions, 0 deletions
diff --git a/js/src/jit-test/tests/debug/Frame-onPop-generators-03.js b/js/src/jit-test/tests/debug/Frame-onPop-generators-03.js
new file mode 100644
index 0000000000..cb7b43a08a
--- /dev/null
+++ b/js/src/jit-test/tests/debug/Frame-onPop-generators-03.js
@@ -0,0 +1,42 @@
+// onPop fires while the [[GeneratorState]] is still "executing".
+//
+// This test checks that Debugger doesn't accidentally make it possible to
+// reenter a generator frame that's on the stack.
+
+load(libdir + "asserts.js");
+
+let g = newGlobal({newCompartment: true});
+g.eval('function* f() { debugger; yield 1; debugger; yield 2; debugger; }');
+let dbg = Debugger(g);
+let genObj = g.f();
+
+let hits = 0;
+dbg.onDebuggerStatement = frame => {
+ frame.onPop = completion => {
+ dbg.removeDebuggee(g); // avoid the DebuggeeWouldRun exception
+ hits++;
+ if (hits < 3) {
+ // We're yielding. Calling .return(), .next(), or .throw() on a
+ // generator that's currently on the stack fails with a TypeError.
+ assertThrowsInstanceOf(() => genObj.next(), g.TypeError);
+ assertThrowsInstanceOf(() => genObj.throw("fit"), g.TypeError);
+ assertThrowsInstanceOf(() => genObj.return(), g.TypeError);
+ } else {
+ // This time we're returning. The generator has already been
+ // closed, so its methods work but are basically no-ops.
+ let result = genObj.next();
+ assertEq(result.done, true);
+ assertEq(result.value, undefined);
+
+ assertThrowsValue(() => genObj.throw("fit"), "fit");
+
+ result = genObj.return();
+ assertEq(result.done, true);
+ assertEq(result.value, undefined);
+ }
+ dbg.addDebuggee(g);
+ };
+};
+
+for (let x of genObj) {}
+assertEq(hits, 3);