Bug 1398601 - Add testcase for loading subscripts within a JSM
MozReview-Commit-ID: I09eoUnQYCG
new file mode 100644
--- /dev/null
+++ b/js/xpconnect/tests/unit/environment_loadscript.jsm
@@ -0,0 +1,18 @@
+Components.utils.import("resource://gre/modules/Services.jsm");
+
+var EXPORTED_SYMBOLS = ["target", "bound"];
+
+var bound = "";
+var target = {};
+Services.scriptloader.loadSubScript("resource://test/environment_script.js", target);
+
+// Check global bindings
+try { void vu; bound += "vu,"; } catch (e) {}
+try { void vq; bound += "vq,"; } catch (e) {}
+try { void vl; bound += "vl,"; } catch (e) {}
+try { void gt; bound += "gt,"; } catch (e) {}
+try { void ed; bound += "ed,"; } catch (e) {}
+try { void ei; bound += "ei,"; } catch (e) {}
+try { void fo; bound += "fo,"; } catch (e) {}
+try { void fi; bound += "fi,"; } catch (e) {}
+try { void fd; bound += "fd,"; } catch (e) {}
new file mode 100644
--- /dev/null
+++ b/js/xpconnect/tests/unit/test_SubscriptLoaderJSMEnvironment.js
@@ -0,0 +1,23 @@
+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);
+
+// 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);
+
+// Components should not share namespace
+if (tgt_check.bound != "")
+ throw new Error("Unexpected shared binding set - " + tgt_check.bound);
--- a/js/xpconnect/tests/unit/xpcshell.ini
+++ b/js/xpconnect/tests/unit/xpcshell.ini
@@ -7,16 +7,17 @@ support-files =
bug451678_subscript.js
component-blob.js
component-blob.manifest
component-file.js
component-file.manifest
component_import.js
component_import.manifest
environment_script.js
+ environment_loadscript.jsm
environment_checkscript.jsm
file_simple_script.js
importer.jsm
recursive_importA.jsm
recursive_importB.jsm
subScriptWithEarlyError.js
syntax_error.jsm
@@ -137,9 +138,10 @@ head = head_watchdog.js
[test_xray_SavedFrame-02.js]
[test_xray_regexp.js]
[test_resolve_dead_promise.js]
[test_asyncLoadSubScriptError.js]
[test_function_names.js]
[test_FrameScriptEnvironment.js]
[test_SubscriptLoaderEnvironment.js]
[test_SubscriptLoaderSandboxEnvironment.js]
+[test_SubscriptLoaderJSMEnvironment.js]
[test_ComponentEnvironment.js]