tor-browser

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

Object-name-03.js (1286B)


      1 // Test `name` and `displayName` getters on a bound function Debugger.Object.
      2 
      3 var g = newGlobal({newCompartment: true});
      4 var hits = 0;
      5 var dbg = new Debugger(g);
      6 
      7 var nameResults = [];
      8 var displayNameResults = [];
      9 dbg.onDebuggerStatement = function (frame) {
     10    nameResults.push(frame.arguments[0].name);
     11    displayNameResults.push(frame.arguments[0].displayName);
     12 };
     13 g.eval(`
     14 function f(val) { debugger; }
     15 
     16 function foo() {};
     17 let bound1 = foo.bind(null);
     18 let bound2 = bound1.bind();
     19 let bound3 = bound2.bind();
     20 f(bound1);
     21 f(bound2);
     22 f(bound3);
     23 
     24 // Change bound1.name to "bar".
     25 Object.defineProperty(bound1, "name", {value: "bar", configurable: true, writable: true});
     26 f(bound1);
     27 
     28 // Change bound1.name to 123. Not a string so now "bound" will be returned.
     29 bound1.name = 123;
     30 f(bound1);
     31 
     32 // Delete bound2.name so now "bound" will be used.
     33 delete bound2.name;
     34 f(bound2);
     35 
     36 // Binding a native function.
     37 f(print.bind().bind().bind());
     38 `)
     39 
     40 for (let res of [nameResults, displayNameResults]) {
     41    assertEq(res.length, 7);
     42    assertEq(res[0], "bound foo");
     43    assertEq(res[1], "bound bound foo");
     44    assertEq(res[2], "bound bound bound foo");
     45    assertEq(res[3], "bar");
     46    assertEq(res[4], "bound");
     47    assertEq(res[5], "bound");
     48    assertEq(res[6], "bound bound bound print");
     49 }