summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/debug/Debugger-onNativeCall-01.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/Debugger-onNativeCall-01.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/Debugger-onNativeCall-01.js')
-rw-r--r--js/src/jit-test/tests/debug/Debugger-onNativeCall-01.js74
1 files changed, 74 insertions, 0 deletions
diff --git a/js/src/jit-test/tests/debug/Debugger-onNativeCall-01.js b/js/src/jit-test/tests/debug/Debugger-onNativeCall-01.js
new file mode 100644
index 0000000000..d21b6d1e5f
--- /dev/null
+++ b/js/src/jit-test/tests/debug/Debugger-onNativeCall-01.js
@@ -0,0 +1,74 @@
+// Test that the onNativeCall hook is called when expected.
+
+load(libdir + 'eqArrayHelper.js');
+
+var g = newGlobal({newCompartment: true});
+var dbg = Debugger(g);
+var gdbg = dbg.addDebuggee(g);
+
+g.eval(`
+const x = [];
+Object.defineProperty(x, "a", {
+ get: print,
+ set: print,
+});
+function f() {
+ x.a++;
+ x.push(4);
+}
+`);
+
+for (let i = 0; i < 5; i++) {
+ g.f();
+}
+
+const rv = [];
+dbg.onNativeCall = (callee, reason) => { rv.push(callee.name, reason); };
+
+var dbg2 = Debugger(g);
+var gdbg2 = dbg2.addDebuggee(g);
+
+const fscript = gdbg.getOwnPropertyDescriptor('f').value.script;
+
+for (let i = 0; i < 5; i++) {
+ // The onNativeCall hook is called when doing global evaluations.
+ rv.length = 0;
+ gdbg.executeInGlobal(`f()`);
+ assertEqArray(rv, ["print", "get", "print", "set", "push", "call"]);
+
+ // The onNativeCall hook is called when doing frame evaluations.
+ let handlerCalled = false;
+ const handler = {
+ hit(frame) {
+ fscript.clearBreakpoint(handler);
+ rv.length = 0;
+ frame.eval(`f()`);
+ assertEqArray(rv, ["print", "get", "print", "set", "push", "call"]);
+ handlerCalled = true;
+ },
+ };
+ fscript.setBreakpoint(fscript.mainOffset, handler);
+ g.f();
+ assertEq(handlerCalled, true);
+
+ // The onNativeCall hook is also called when not in a debugger evaluation.
+ rv.length = 0;
+ g.f();
+ assertEqArray(rv, ["print", "get", "print", "set", "push", "call"]);
+
+ // The onNativeCall hook is *not* called when in a debugger evaluation
+ // associated with a different debugger using exclusiveDebuggerOnEval.
+ rv.length = 0;
+ dbg2.exclusiveDebuggerOnEval = true;
+ assertEq(dbg2.exclusiveDebuggerOnEval, true);
+ gdbg2.executeInGlobal(`f()`);
+ assertEqArray(rv, []);
+
+ // The onNativeCall hook is called when that same distinct debugger
+ // doesn't have the exclusiveDebuggerOnEval flag set to true
+ rv.length = 0;
+ dbg2.exclusiveDebuggerOnEval = false;
+ assertEq(dbg2.exclusiveDebuggerOnEval, false);
+ gdbg2.executeInGlobal(`f()`);
+ assertEqArray(rv, ["print", "get", "print", "set", "push", "call"]);
+}