summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/debug/Object-isSameNative.js
blob: 0b26144f2159ac9fd75b0543041bf5b42ae0206c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// 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);

assertEq(gdbg.getProperty("print").return.isSameNative(print), true);
assertEq(gdbg.getProperty("print").return.isSameNative(newGlobal), false);

g.eval(`
const x = [];
Object.defineProperty(x, "a", {
  get: print,
  set: print,
});
function f() {
  x.a++;
  x.length = 0;
  x.push(4, 5, 6);
  x.sort(print);
}
`);

const comparisons = [
  print,
  Array.prototype.push,
  Array.prototype.sort, // Note: self-hosted
  newGlobal
];

const rv = [];
dbg.onNativeCall = (callee, reason) => {
  for (const fn of comparisons) {
    if (callee.isSameNative(fn)) {
      rv.push(fn.name);
    }
  }
}

for (let i = 0; i < 5; i++) {
  rv.length = 0;
  gdbg.executeInGlobal(`f()`);
  assertEqArray(rv, [
    "print", "print", "push",
    "sort", "print", "print",
  ]);
}