Bug 1398601 - Add testcase for loading subscripts within a JSM r=kmag
☠☠ backed out by a45742d015d3 ☠ ☠
authorTed Campbell <tcampbell@mozilla.com>
Sun, 10 Sep 2017 14:57:04 -0400
changeset 380447 05957a92b1a56cbf8f7c71afa4fef2b3f46b2ae3
parent 380446 f5c26c3407c02ecb15b4d0080d6f7fa20aa7c082
child 380448 b728872f4d9ad911854b90ca9893cdb7604fa9bf
push id32487
push userarchaeopteryx@coole-files.de
push dateWed, 13 Sep 2017 11:33:24 +0000
treeherdermozilla-central@1888ec2f277f [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]