зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1394490
- Javascript loader environments test. r=kmag
This are some unit tests to track regressions in the environment behavior exposed to embeddings for various javascript loaders inside Gecko. MozReview-Commit-ID: 8pn56Skwbat
This commit is contained in:
Родитель
07b5b84c71
Коммит
3d936e31cf
|
@ -0,0 +1,13 @@
|
|||
var EXPORTED_SYMBOLS = ["bound"];
|
||||
|
||||
var bound = "";
|
||||
|
||||
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) {}
|
|
@ -0,0 +1,14 @@
|
|||
let strict = (function() { return this; })() === undefined;
|
||||
|
||||
// Allow this to be used as a JSM
|
||||
var EXPORTED_SYMBOLS = [];
|
||||
|
||||
if (!strict) vu = 1; // Unqualified Variable
|
||||
var vq = 2; // Qualified Variable
|
||||
let vl = 3; // Lexical
|
||||
this.gt = 4; // Global This
|
||||
eval("this.ed = 5"); // Direct Eval
|
||||
(1,eval)("this.ei = 6"); // Indirect Eval
|
||||
(new Function("this.fo = 7"))(); // Dynamic Function Object
|
||||
if (!strict) (function() { this.fi = 8; })(); // Indirect Function This
|
||||
function fd_() { this.fd = 9; }; if (!strict) fd_(); // Direct Function Implicit
|
|
@ -0,0 +1,8 @@
|
|||
let tgt = {};
|
||||
Components.utils.import("resource://test/environment_script.js", tgt);
|
||||
Components.utils.import("resource://test/environment_checkscript.jsm", tgt);
|
||||
|
||||
|
||||
// Components should not share namespace
|
||||
if (tgt.bound != "")
|
||||
throw new Error("Unexpected shared binding set - " + tgt.bound);
|
|
@ -0,0 +1,43 @@
|
|||
Components.utils.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
let ppmm = Services.ppmm.getChildAt(0);
|
||||
|
||||
add_task(async function test_bindings() {
|
||||
let {strict, bound} = await new Promise(function(resolve) {
|
||||
// Use a listener to get results from child
|
||||
ppmm.addMessageListener("results", function listener(msg) {
|
||||
ppmm.removeMessageListener("results", listener);
|
||||
resolve(msg.data);
|
||||
});
|
||||
|
||||
// Bind vars in first process script
|
||||
ppmm.loadProcessScript("resource://test/environment_script.js", false);
|
||||
|
||||
// Check visibility in second process script
|
||||
ppmm.loadProcessScript(`data:,
|
||||
let strict = (function() { return this; })() === undefined;
|
||||
var bound = "";
|
||||
|
||||
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) {}
|
||||
|
||||
sendAsyncMessage("results", { strict, bound });
|
||||
`, false);
|
||||
});
|
||||
|
||||
// FrameScript loader should share |this| access
|
||||
if (strict) {
|
||||
if (bound != "gt,ed,ei,fo,")
|
||||
throw new Error("Unexpected global binding set - " + bound);
|
||||
} else {
|
||||
if (bound != "gt,ed,ei,fo,fi,fd,")
|
||||
throw new Error("Unexpected global binding set - " + bound);
|
||||
}
|
||||
});
|
|
@ -0,0 +1,33 @@
|
|||
Components.utils.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
let tgt = {};
|
||||
Services.scriptloader.loadSubScript("resource://test/environment_script.js", tgt);
|
||||
|
||||
var bound = "";
|
||||
var tgt_bound = "";
|
||||
|
||||
// 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) {}
|
||||
|
||||
// Check target bindings
|
||||
for (var name of ["vu", "vq", "vl", "gt", "ed", "ei", "fo", "fi", "fd"])
|
||||
if (tgt.hasOwnProperty(name))
|
||||
tgt_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 (bound != "vu,ei,fo,fi,")
|
||||
throw new Error("Unexpected global binding set - " + bound);
|
||||
if (tgt_bound != "vq,gt,ed,fd,")
|
||||
throw new Error("Unexpected target binding set - " + tgt_bound);
|
|
@ -0,0 +1,32 @@
|
|||
Components.utils.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
let tgt = Components.utils.Sandbox(Services.scriptSecurityManager.getSystemPrincipal());
|
||||
Services.scriptloader.loadSubScript("resource://test/environment_script.js", tgt);
|
||||
|
||||
var bound = "";
|
||||
var tgt_bound = "";
|
||||
|
||||
// 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) {}
|
||||
|
||||
// Check target bindings
|
||||
for (var name of ["vu", "vq", "vl", "gt", "ed", "ei", "fo", "fi", "fd"])
|
||||
if (tgt.hasOwnProperty(name))
|
||||
tgt_bound += name + ",";
|
||||
|
||||
|
||||
// Expected subscript loader behavior with a Sandbox is as follows:
|
||||
// - Lexicals occur on ExtensibleLexicalEnvironment of target
|
||||
// - Everything else occurs on Sandbox global
|
||||
if (bound != "")
|
||||
throw new Error("Unexpected global binding set - " + bound);
|
||||
if (tgt_bound != "vu,vq,gt,ed,ei,fo,fi,fd,")
|
||||
throw new Error("Unexpected target binding set - " + tgt_bound);
|
|
@ -11,6 +11,8 @@ support-files =
|
|||
component-file.manifest
|
||||
component_import.js
|
||||
component_import.manifest
|
||||
environment_script.js
|
||||
environment_checkscript.jsm
|
||||
file_simple_script.js
|
||||
importer.jsm
|
||||
recursive_importA.jsm
|
||||
|
@ -137,3 +139,7 @@ head = head_watchdog.js
|
|||
[test_resolve_dead_promise.js]
|
||||
[test_asyncLoadSubScriptError.js]
|
||||
[test_function_names.js]
|
||||
[test_FrameScriptEnvironment.js]
|
||||
[test_SubscriptLoaderEnvironment.js]
|
||||
[test_SubscriptLoaderSandboxEnvironment.js]
|
||||
[test_ComponentEnvironment.js]
|
||||
|
|
Загрузка…
Ссылка в новой задаче