tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

Object-isSameNative.js (957B)


      1 // Test that the onNativeCall hook is called when expected.
      2 
      3 load(libdir + 'eqArrayHelper.js');
      4 
      5 var g = newGlobal({newCompartment: true});
      6 var dbg = Debugger(g);
      7 var gdbg = dbg.addDebuggee(g);
      8 
      9 assertEq(gdbg.getProperty("print").return.isSameNative(print), true);
     10 assertEq(gdbg.getProperty("print").return.isSameNative(newGlobal), false);
     11 
     12 g.eval(`
     13 const x = [];
     14 Object.defineProperty(x, "a", {
     15  get: print,
     16  set: print,
     17 });
     18 function f() {
     19  x.a++;
     20  x.length = 0;
     21  x.push(4, 5, 6);
     22  x.sort(print);
     23 }
     24 `);
     25 
     26 const comparisons = [
     27  print,
     28  Array.prototype.push,
     29  Array.prototype.sort, // Note: self-hosted
     30  newGlobal
     31 ];
     32 
     33 const rv = [];
     34 dbg.onNativeCall = (callee, reason) => {
     35  for (const fn of comparisons) {
     36    if (callee.isSameNative(fn)) {
     37      rv.push(fn.name);
     38    }
     39  }
     40 }
     41 
     42 for (let i = 0; i < 5; i++) {
     43  rv.length = 0;
     44  gdbg.executeInGlobal(`f()`);
     45  assertEqArray(rv, [
     46    "print", "print", "push",
     47    "sort", "print", "print",
     48  ]);
     49 }