Bug 1333990: Part 1b - Add tests for script precompiler. r?shu draft
authorKris Maglione <maglione.k@gmail.com>
Wed, 15 Mar 2017 17:24:42 -0700
changeset 499604 757b8ca1b75a751e2f0c80c9e476ae6e309c7432
parent 499603 5941cb6855a41f842ae72ab6672e536733dd62c1
child 499605 c3fdb20ac0442c327c88d0e61ecf5479adba1a67
push id49456
push usermaglione.k@gmail.com
push dateThu, 16 Mar 2017 00:44:19 +0000
reviewersshu
bugs1333990
milestone54.0a1
Bug 1333990: Part 1b - Add tests for script precompiler. r?shu MozReview-Commit-ID: DVFFdyzY6Kn
js/xpconnect/tests/unit/file_simple_script.js
js/xpconnect/tests/unit/test_compileScript.js
js/xpconnect/tests/unit/xpcshell.ini
new file mode 100644
--- /dev/null
+++ b/js/xpconnect/tests/unit/file_simple_script.js
@@ -0,0 +1,1 @@
+this.bar = ({foo: "®"});
new file mode 100644
--- /dev/null
+++ b/js/xpconnect/tests/unit/test_compileScript.js
@@ -0,0 +1,39 @@
+"use strict";
+
+const Cu = Components.utils;
+
+Cu.import("resource://gre/modules/Services.jsm");
+
+add_task(function*() {
+  let scriptUrl = Services.io.newFileURI(do_get_file("file_simple_script.js")).spec;
+
+
+  let script1 = yield ChromeUtils.compileScript(scriptUrl, {hasReturnValue: true});
+  let script2 = yield ChromeUtils.compileScript(scriptUrl, {hasReturnValue: false});
+
+  equal(script1.url, scriptUrl, "Script URL is correct")
+  equal(script2.url, scriptUrl, "Script URL is correct")
+
+  equal(script1.hasReturnValue, true, "Script hasReturnValue property is correct")
+  equal(script2.hasReturnValue, false, "Script hasReturnValue property is correct")
+
+  let sandbox1 = Cu.Sandbox("http://example.com");
+  let sandbox2 = Cu.Sandbox("http://example.org");
+
+  let obj = script1.executeInGlobal(sandbox1);
+  equal(Cu.getObjectPrincipal(obj).origin, "http://example.com", "Return value origin is correct");
+  equal(obj.foo, "\u00ae", "Return value has the correct charset");
+
+  obj = script1.executeInGlobal(sandbox2);
+  equal(Cu.getObjectPrincipal(obj).origin, "http://example.org", "Return value origin is correct");
+  equal(obj.foo, "\u00ae", "Return value has the correct charset");
+
+  sandbox1.bar = null;
+  equal(sandbox1.bar, null);
+
+  obj = script2.executeInGlobal(sandbox1);
+  equal(obj, undefined, "No-return script has no return value");
+
+  equal(Cu.getObjectPrincipal(sandbox1.bar).origin, "http://example.com", "Object value origin is correct");
+  equal(sandbox1.bar.foo, "\u00ae", "Object value has the correct charset");
+});
--- a/js/xpconnect/tests/unit/xpcshell.ini
+++ b/js/xpconnect/tests/unit/xpcshell.ini
@@ -6,16 +6,17 @@ support-files =
   bogus_exports_type.jsm
   bug451678_subscript.js
   component-blob.js
   component-blob.manifest
   component-file.js
   component-file.manifest
   component_import.js
   component_import.manifest
+  file_simple_script.js
   importer.jsm
   recursive_importA.jsm
   recursive_importB.jsm
   subScriptWithEarlyError.js
   syntax_error.jsm
 
 [test_allowWaivers.js]
 [test_bogus_files.js]
@@ -56,16 +57,17 @@ support-files =
 [test_bug1150106.js]
 [test_bug1150771.js]
 [test_bug1151385.js]
 [test_bug1170311.js]
 [test_bug1244222.js]
 [test_bug_442086.js]
 [test_callFunctionWithAsyncStack.js]
 [test_classesByID_instanceof.js]
+[test_compileScript.js]
 [test_deepFreezeClone.js]
 [test_file.js]
 [test_blob.js]
 [test_blob2.js]
 [test_file2.js]
 [test_import.js]
 [test_import_fail.js]
 [test_interposition.js]