test_SubscriptLoaderEnvironment.js (1399B)
1 let tgt = {}; 2 3 Services.prefs.setBoolPref("security.allow_eval_with_system_principal", true); 4 5 registerCleanupFunction(() => { 6 Services.prefs.clearUserPref("security.allow_eval_with_system_principal"); 7 }); 8 9 Services.scriptloader.loadSubScript("resource://test/environment_script.js", tgt); 10 11 var bound = ""; 12 var tgt_bound = ""; 13 14 // Check global bindings 15 try { void vu; bound += "vu,"; } catch (e) {} 16 try { void vq; bound += "vq,"; } catch (e) {} 17 try { void vl; bound += "vl,"; } catch (e) {} 18 try { void gt; bound += "gt,"; } catch (e) {} 19 try { void ed; bound += "ed,"; } catch (e) {} 20 try { void ei; bound += "ei,"; } catch (e) {} 21 try { void fo; bound += "fo,"; } catch (e) {} 22 try { void fi; bound += "fi,"; } catch (e) {} 23 try { void fd; bound += "fd,"; } catch (e) {} 24 25 // Check target bindings 26 for (var name of ["vu", "vq", "vl", "gt", "ed", "ei", "fo", "fi", "fd"]) 27 if (tgt.hasOwnProperty(name)) 28 tgt_bound += name + ","; 29 30 31 // Expected subscript loader behavior is as follows: 32 // - Qualified vars and |this| access occur on target object 33 // - Lexical vars occur on ExtensibleLexicalEnvironment of target object 34 // - Bareword assignments and global |this| access occur on caller's global 35 if (bound != "vu,ei,fo,fi,") 36 throw new Error("Unexpected global binding set - " + bound); 37 if (tgt_bound != "vq,gt,ed,fd,") 38 throw new Error("Unexpected target binding set - " + tgt_bound);