tor-browser

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

test_FrameScriptEnvironment.js (1819B)


      1 let ppmm = Services.ppmm.getChildAt(0);
      2 
      3 Services.prefs.setBoolPref("security.allow_eval_with_system_principal", true);
      4 registerCleanupFunction(() => {
      5  Services.prefs.clearUserPref("security.allow_eval_with_system_principal");
      6 });
      7 
      8 add_task(async function test_bindings() {
      9    let {strict, bound} = await new Promise(function(resolve) {
     10        // Use a listener to get results from child
     11        ppmm.addMessageListener("results", function listener(msg) {
     12            ppmm.removeMessageListener("results", listener);
     13            resolve(msg.data);
     14        });
     15 
     16        // Bind vars in first process script
     17        ppmm.loadProcessScript("resource://test/environment_script.js", false);
     18 
     19        // Check visibility in second process script
     20        ppmm.loadProcessScript(`data:,
     21            let strict = (function() { return this; })() === undefined;
     22            var bound = "";
     23 
     24            try { void vu; bound += "vu,"; } catch (e) {}
     25            try { void vq; bound += "vq,"; } catch (e) {}
     26            try { void vl; bound += "vl,"; } catch (e) {}
     27            try { void gt; bound += "gt,"; } catch (e) {}
     28            try { void ed; bound += "ed,"; } catch (e) {}
     29            try { void ei; bound += "ei,"; } catch (e) {}
     30            try { void fo; bound += "fo,"; } catch (e) {}
     31            try { void fi; bound += "fi,"; } catch (e) {}
     32            try { void fd; bound += "fd,"; } catch (e) {}
     33 
     34            sendAsyncMessage("results", { strict, bound });
     35            `, false);
     36    });
     37 
     38    // FrameScript loader should share |this| access
     39    if (strict) {
     40        if (bound != "gt,ed,ei,fo,")
     41            throw new Error("Unexpected global binding set - " + bound);
     42    } else {
     43        if (bound != "gt,ed,ei,fo,fi,fd,")
     44            throw new Error("Unexpected global binding set - " + bound);
     45    }
     46 });