tor-browser

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

Debugger-onNativeCall-07.js (850B)


      1 // Test that the onNativeCall hook is called when native function is
      2 // called inside self-hosted JS with Function.prototype.{call,apply}.
      3 
      4 load(libdir + 'eqArrayHelper.js');
      5 
      6 var g = newGlobal({ newCompartment: true });
      7 var dbg = new Debugger();
      8 var gdbg = dbg.addDebuggee(g);
      9 
     10 const rv = [];
     11 dbg.onNativeCall = (callee, reason) => {
     12  rv.push(callee.name);
     13 };
     14 
     15 gdbg.executeInGlobal(`
     16 // Directly call.
     17 dateNow.call();
     18 dateNow.apply();
     19 
     20 // Call via bind.
     21 Function.prototype.call.bind(Function.prototype.call)(dateNow);
     22 Function.prototype.apply.bind(Function.prototype.apply)(dateNow);
     23 
     24 // Call via std_Function_apply
     25 Reflect.apply(dateNow, null, []);
     26 `);
     27 assertEqArray(rv, [
     28  "call", "dateNow",
     29  "apply", "dateNow",
     30  "bind", "bound call", "call", "call", "dateNow",
     31  "bind", "bound apply", "apply", "apply", "dateNow",
     32  "apply", "dateNow",
     33 ]);