Bug 1333990: Part 1b - Add tests for script precompiler. r=shu

MozReview-Commit-ID: DVFFdyzY6Kn

--HG--
extra : rebase_source : d41324f18ee2c13e98f94ecec3af73e67da873ea
This commit is contained in:
Kris Maglione 2017-03-16 16:55:59 -07:00
Родитель 437f4e37d4
Коммит aaaea39c13
3 изменённых файлов: 58 добавлений и 0 удалений

Просмотреть файл

@ -0,0 +1 @@
this.bar = ({foo: "®"});

Просмотреть файл

@ -0,0 +1,55 @@
"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")
// Test return-value version.
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");
// Test no-return-value version.
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");
sandbox2.bar = null;
equal(sandbox2.bar, null);
obj = script2.executeInGlobal(sandbox2);
equal(obj, undefined, "No-return script has no return value");
equal(Cu.getObjectPrincipal(sandbox2.bar).origin, "http://example.org", "Object value origin is correct");
equal(sandbox2.bar.foo, "\u00ae", "Object value has the correct charset");
});

Просмотреть файл

@ -11,6 +11,7 @@ support-files =
component-file.manifest
component_import.js
component_import.manifest
file_simple_script.js
importer.jsm
recursive_importA.jsm
recursive_importB.jsm
@ -61,6 +62,7 @@ support-files =
[test_bug_442086.js]
[test_callFunctionWithAsyncStack.js]
[test_classesByID_instanceof.js]
[test_compileScript.js]
[test_deepFreezeClone.js]
[test_file.js]
[test_blob.js]