tor-browser

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

function_dot_caller_restrictions.js (1753B)


      1 function g() { }
      2 function strict() {
      3    "use strict";
      4 }
      5 
      6 let bound = g.bind();
      7 let arrow = x => 0;
      8 
      9 async function fn_async() { }
     10 function * fn_generator() { }
     11 
     12 let o = {
     13    mtd() {},
     14    get x() {},
     15    set x(v) {},
     16 };
     17 
     18 class Base { }
     19 class Derived extends Base { }
     20 
     21 function asm_mod() {
     22    "use asm";
     23    function mtd() {}
     24    return { mtd: mtd }
     25 }
     26 
     27 let asm_fun = (new asm_mod).mtd;
     28 
     29 let builtin_selfhost = [].sort;
     30 let builtin_native = Math.sin;
     31 
     32 let dot_caller = Object.getOwnPropertyDescriptor(Function.__proto__,
     33                                                 "caller").get;
     34 
     35 // Returns true if fn.caller is allowed
     36 function check(fn) {
     37    try {
     38        (function() {
     39            fn.caller;
     40        })();
     41    }
     42    catch (e) {
     43        assertEq(e instanceof TypeError, true);
     44        return false;
     45    }
     46    return true;
     47 }
     48 
     49 // Normal sloppy functions are allowed, even if they also are intended as
     50 // asm.js.
     51 assertEq(check(g), true);
     52 assertEq(check(asm_mod), true);
     53 assertEq(check(asm_fun), true);
     54 
     55 // Most others are not
     56 assertEq(check(strict), false);
     57 assertEq(check(bound), false);
     58 assertEq(check(arrow), false);
     59 assertEq(check(fn_async), false);
     60 assertEq(check(fn_generator), false);
     61 assertEq(check(o.mtd), false)
     62 assertEq(check(Object.getOwnPropertyDescriptor(o, "x").get), false)
     63 assertEq(check(Object.getOwnPropertyDescriptor(o, "x").set), false)
     64 assertEq(check(Base), false);
     65 assertEq(check(Derived), false);
     66 assertEq(check(builtin_selfhost), false);
     67 assertEq(check(builtin_native), false);
     68 assertEq(check(dot_caller), false);
     69 
     70 // Have a native invoke .caller on our behalf.
     71 function foo() {
     72    function inner() {
     73        return callFunctionFromNativeFrame(dot_caller.bind(inner))
     74    }
     75    return inner();
     76 }
     77 assertEq(foo, foo());