summaryrefslogtreecommitdiffstats
path: root/js/xpconnect/tests/unit/test_SubscriptLoaderJSMEnvironment.js
blob: 1ae9bc3b74d9b8375059a2a9d1bbbb81cbb3a65a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
let tgt_load = {};
let tgt_check = {};

Services.prefs.setBoolPref("security.allow_eval_with_system_principal", true);
registerCleanupFunction(() => {
  Services.prefs.clearUserPref("security.allow_eval_with_system_principal");
});
const a = ChromeUtils.import("resource://test/environment_loadscript.jsm", tgt_load);
const b = ChromeUtils.import("resource://test/environment_checkscript.jsm", tgt_check);

const isShared = Cu.getGlobalForObject(a) === Cu.getGlobalForObject(b);

// Check target bindings
var tgt_subscript_bound = "";
for (var name of ["vu", "vq", "vl", "gt", "ed", "ei", "fo", "fi", "fd"])
    if (tgt_load.target.hasOwnProperty(name))
        tgt_subscript_bound += name + ",";

// Expected subscript loader behavior is as follows:
//  - Qualified vars and |this| access occur on target object
//  - Lexical vars occur on ExtensibleLexicalEnvironment of target object
//  - Bareword assignments and global |this| access occur on caller's global
Assert.equal(tgt_load.bound, "vu,ei,fo,fi,", "Should have expected module binding set");
Assert.equal(tgt_subscript_bound, "vq,gt,ed,fd,", "Should have expected subscript binding set");

// Components should not share namespace
if (isShared) {
  todo_check_eq(tgt_check.bound, "");
  Assert.equal(tgt_check.bound, "ei,fo,", "Modules should have no shared non-eval bindings");
} else {
  Assert.equal(tgt_check.bound, "", "Modules should have no shared bindings");
}