Bug 1398601 - Add testcase for loading subscripts within a JSM draft
authorTed Campbell <tcampbell@mozilla.com>
Sun, 10 Sep 2017 14:57:04 -0400
changeset 664084 9d3481f3e0d8b9ad66ecb55c7b901d514c09b619
parent 664083 10cdd94404a218b27c15f0645d8729fba0889891
child 664085 d4f129feb476cc2d6fb731124d6dc025a3504ac5
push id79624
push userbmo:tcampbell@mozilla.com
push dateWed, 13 Sep 2017 18:23:23 +0000
bugs1398601
milestone57.0a1
Bug 1398601 - Add testcase for loading subscripts within a JSM MozReview-Commit-ID: I09eoUnQYCG
js/xpconnect/tests/unit/environment_loadscript.jsm
js/xpconnect/tests/unit/test_SubscriptLoaderJSMEnvironment.js
js/xpconnect/tests/unit/xpcshell.ini
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]