Bug 1398601 - Add testcase for loading subscripts within a JSM r=kmag
authorTed Campbell <tcampbell@mozilla.com>
Sun, 10 Sep 2017 14:57:04 -0400
changeset 430221 51d0521b16aa83197e4c032da894484b00cda7c1
parent 430220 675444347ccd1f4ceeefc4203851e8d2d9a984fe
child 430222 f70469dfd87a13d1dec503f51f463ce05fd637ea
push id7761
push userjlund@mozilla.com
push dateFri, 15 Sep 2017 00:19:52 +0000
treeherdermozilla-beta@c38455951db4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskmag
bugs1398601
milestone57.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1398601 - Add testcase for loading subscripts within a JSM r=kmag 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]