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 /js/src/jit-test/tests/debug/onEnterFrame-generator-01.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 '')
-rw-r--r-- | js/src/jit-test/tests/debug/onEnterFrame-generator-01.js | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/js/src/jit-test/tests/debug/onEnterFrame-generator-01.js b/js/src/jit-test/tests/debug/onEnterFrame-generator-01.js new file mode 100644 index 0000000000..6f94496eaf --- /dev/null +++ b/js/src/jit-test/tests/debug/onEnterFrame-generator-01.js @@ -0,0 +1,82 @@ +// Frame properties and methods work in generator-resuming onEnterFrame events. +// Also tests onPop events, for good measure. + +let g = newGlobal({newCompartment: true}); +g.eval(`\ + function* gen(lo, hi) { + var a = 1/2; + yield a; + yield a * a; + } +`); +let dbg = new Debugger; +let gw = dbg.addDebuggee(g); + +let hits = 0; +let savedScript = null; +let savedEnv = null; +let savedOffsets = new Set; + +function check(frame) { + assertEq(frame.type, "call"); + assertEq(frame.constructing, false); + assertEq(frame.callee, gw.makeDebuggeeValue(g.gen)); + + // `arguments` elements don't work in resumed generator frames, + // because generators don't keep the arguments around. + // However, some of this is initialized when the frame.arguments object is + // created, so if they are created during the first onEnterFrame or onPop + // event, the properties exist, and those events can also see the values. + assertEq(frame.arguments.length, args.length); + for (var i = 0; i < args.length; i++) { + assertEq(frame.arguments.hasOwnProperty(i), true); + + if (hits < 2) + assertEq(frame.arguments[i], gw.makeDebuggeeValue(args[i]), `arguments[${i}]`); + else + assertEq(frame.arguments[i], undefined); + } + + if (savedEnv === null) { + savedEnv = frame.environment; + assertEq(savedScript, null); + savedScript = frame.script; + } else { + assertEq(frame.environment, savedEnv); + assertEq(frame.script, savedScript); + } + let a_expected = hits < 3 ? undefined : 1/2; + assertEq(savedEnv.getVariable("a"), a_expected); + + assertEq(frame.onStack, true); + + let pc = frame.offset; + assertEq(savedOffsets.has(pc), false); + savedOffsets.add(pc); + + assertEq(frame.older, null); + assertEq(frame.this, gw.makeDebuggeeValue(g)); + assertEq(typeof frame.implementation, "string"); + + // And the moment of truth: + assertEq(frame.eval("2 + 2").return, 4); + assertEq(frame.eval("a").return, a_expected); + assertEq(frame.eval("if (a !== undefined) { assertEq(a < (lo + hi) / 2, true); } 7;").return, 7); +} + +dbg.onEnterFrame = frame => { + if (frame.type === "eval") + return; + check(frame); + hits++; + frame.onPop = completion => { + check(frame); + hits++; + }; +}; + +// g.gen ignores the arguments passed to it, but we use them to test +// frame.arguments. +let args = [0, 10, g, dbg]; +for (let v of g.gen(...args)) {} +assertEq(hits, 8); |