Bug 1399997: Part 3 - Update module environment tests with TODOs for shared module eval bindings. r?tcampbell draft
authorKris Maglione <maglione.k@gmail.com>
Thu, 14 Sep 2017 13:08:17 -0700
changeset 665022 dfd6bc2b271e1a89441a99a71a7938a35804e549
parent 665021 08c6e4a74bbaa57118b169b6a8d123fcca8fa84c
child 731628 0907187c3a06fd70e8502966d3e2269e0caa396a
push id79900
push usermaglione.k@gmail.com
push dateThu, 14 Sep 2017 20:08:57 +0000
reviewerstcampbell
bugs1399997
milestone57.0a1
Bug 1399997: Part 3 - Update module environment tests with TODOs for shared module eval bindings. r?tcampbell MozReview-Commit-ID: LVTNnN3HlKK
js/xpconnect/tests/unit/test_ComponentEnvironment.js
js/xpconnect/tests/unit/test_SubscriptLoaderJSMEnvironment.js
--- a/js/xpconnect/tests/unit/test_ComponentEnvironment.js
+++ b/js/xpconnect/tests/unit/test_ComponentEnvironment.js
@@ -1,8 +1,16 @@
+const {utils: Cu} = Components;
+
 let tgt = {};
-Components.utils.import("resource://test/environment_script.js", tgt);
-Components.utils.import("resource://test/environment_checkscript.jsm", tgt);
+const a = Components.utils.import("resource://test/environment_script.js", tgt);
+const b = Components.utils.import("resource://test/environment_checkscript.jsm", tgt);
+
+const isShared = Cu.getGlobalForObject(a) === Cu.getGlobalForObject(b);
 
 
 // Components should not share namespace
-if (tgt.bound != "")
-    throw new Error("Unexpected shared binding set - " + tgt.bound);
+if (isShared) {
+  todo_check_eq(tgt.bound, "");
+  Assert.equal(tgt.bound, "ei,fo,", "Modules should have no shared non-eval bindings");
+} else {
+  Assert.equal(tgt.bound, "", "Modules should have no shared bindings");
+}
--- a/js/xpconnect/tests/unit/test_SubscriptLoaderJSMEnvironment.js
+++ b/js/xpconnect/tests/unit/test_SubscriptLoaderJSMEnvironment.js
@@ -1,23 +1,29 @@
+const {utils: Cu} = Components;
+
 let tgt_load = {};
 let tgt_check = {};
-Components.utils.import("resource://test/environment_loadscript.jsm", tgt_load);
-Components.utils.import("resource://test/environment_checkscript.jsm", tgt_check);
+const a = Components.utils.import("resource://test/environment_loadscript.jsm", tgt_load);
+const b = Components.utils.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
-if (tgt_load.bound != "vu,ei,fo,fi,")
-    throw new Error("Unexpected global binding set - " + tgt_load.bound);
-if (tgt_subscript_bound != "vq,gt,ed,fd,")
-    throw new Error("Unexpected target binding set - " + tgt_subscript_bound);
+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 (tgt_check.bound != "")
-    throw new Error("Unexpected shared binding set - " + tgt_check.bound);
+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");
+}