summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/debug/Environment-inspectable-01.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /js/src/jit-test/tests/debug/Environment-inspectable-01.js
parentInitial commit. (diff)
downloadfirefox-esr-upstream.tar.xz
firefox-esr-upstream.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--js/src/jit-test/tests/debug/Environment-inspectable-01.js80
1 files changed, 80 insertions, 0 deletions
diff --git a/js/src/jit-test/tests/debug/Environment-inspectable-01.js b/js/src/jit-test/tests/debug/Environment-inspectable-01.js
new file mode 100644
index 0000000000..7ced83aa41
--- /dev/null
+++ b/js/src/jit-test/tests/debug/Environment-inspectable-01.js
@@ -0,0 +1,80 @@
+// Environments are only inspectable while their globals are debuggees.
+
+load(libdir + 'asserts.js');
+
+var g1 = newGlobal({newCompartment: true});
+var g2 = newGlobal({newCompartment: true});
+g2.g1 = g1;
+g1.g2 = g2;
+
+g1.eval('function f(xf) { return function h(xh) { eval(""); debugger; } }');
+g1.eval('var h = f("value of xf");');
+
+// To ensure that xk gets located on the heap, and thus outlives its stack frame, we
+// store a function that captures it here. Kind of a kludge.
+g2.eval('var capture;');
+g2.eval('function k(xk) { capture = function () { return xk; }; g1.h("value of xh"); }');
+
+var dbg = new Debugger;
+dbg.addDebuggee(g1);
+dbg.addDebuggee(g2);
+
+dbg.onDebuggerStatement = debuggerHandler;
+
+var log = '';
+
+g1.eval('g2.k("value of xk");');
+
+var he, ke, ee;
+
+function debuggerHandler(frame) {
+ log += 'd';
+
+ assertEq(frame.type, 'call');
+ he = frame.environment;
+
+ assertEq(frame.older.type, 'call');
+ ke = frame.older.environment;
+
+ assertEq(frame.older.older.type, 'eval');
+ ee = frame.older.older.environment;
+
+ assertEq(he.inspectable, true);
+ assertEq(he.getVariable('xh'), 'value of xh');
+ assertEq(he.parent.parent.getVariable('xf'), 'value of xf');
+ assertEq(ke.inspectable, true);
+ assertEq(ke.getVariable('xk'), 'value of xk');
+ assertEq(ee.inspectable, true);
+ assertEq(ee.type, 'declarative');
+ assertEq(ee.parent.type, 'object');
+
+ dbg.removeDebuggee(g2);
+
+ assertEq(he.inspectable, true);
+ assertEq(he.type, 'declarative');
+ assertEq(ke.inspectable, false);
+ assertThrowsInstanceOf(() => ke.getVariable('xk'), Error);
+ assertEq(ee.inspectable, true);
+ assertEq(ee.type, 'declarative');
+ assertEq(ee.parent.type, 'object');
+
+ dbg.removeDebuggee(g1);
+
+ assertEq(he.inspectable, false);
+ assertThrowsInstanceOf(() => he.getVariable('xh'), Error);
+ assertEq(ke.inspectable, false);
+ assertThrowsInstanceOf(() => ke.getVariable('xk'), Error);
+ assertEq(ee.inspectable, false);
+ assertThrowsInstanceOf(() => ee.type, Error);
+}
+
+assertEq(log, 'd');
+
+dbg.addDebuggee(g2);
+
+assertEq(he.inspectable, false);
+assertThrowsInstanceOf(() => he.getVariable('xh'), Error);
+assertEq(ke.inspectable, true);
+assertEq(ke.getVariable('xk'), 'value of xk');
+assertEq(ee.inspectable, false);
+assertThrowsInstanceOf(() => ee.type, Error);