tor-browser

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

Debugger-onNativeCall-05.js (900B)


      1 // Test that the onNativeCall hook cannot return a primitive value.
      2 
      3 var g = newGlobal({newCompartment: true});
      4 var dbg = Debugger(g);
      5 var gdbg = dbg.addDebuggee(g);
      6 
      7 // Returning the callee accidentally is a common mistake when implementing C++
      8 // methods, but the debugger should not trip any checks if it does this on
      9 // purpose.
     10 dbg.onNativeCall = (callee, reason) => {
     11    return {return: callee};
     12 };
     13 v = gdbg.executeInGlobal("new Object")
     14 assertEq(v.return, gdbg.makeDebuggeeValue(g.Object));
     15 
     16 // Returning a primitive should cause the hook to throw.
     17 dbg.onNativeCall = (callee, reason) => {
     18    return {return: "primitive"};
     19 };
     20 v = gdbg.executeInGlobal("new Object")
     21 assertEq(v.throw.proto, gdbg.makeDebuggeeValue(g.Error.prototype))
     22 
     23 // A no-op hook shouldn't break any checks.
     24 dbg.onNativeCall = (callee, reason) => { };
     25 v = gdbg.executeInGlobal("new Object")
     26 assertEq("return" in v, true);