mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 998291 - Allow for relatively-loaded modules to be loaded into a given scope. r=bsmedberg
This commit is contained in:
parent
39b924ec2e
commit
efed059bea
@ -279,13 +279,13 @@ this.XPCOMUtils = {
|
||||
* Allows you to fake a relative import. Expects the global object from the
|
||||
* module that's calling us, and the relative filename that we wish to import.
|
||||
*/
|
||||
importRelative: function XPCOMUtils__importRelative(that, path) {
|
||||
importRelative: function XPCOMUtils__importRelative(that, path, scope) {
|
||||
if (!("__URI__" in that))
|
||||
throw Error("importRelative may only be used from a JSM, and its first argument "+
|
||||
"must be that JSM's global object (hint: use this)");
|
||||
let uri = that.__URI__;
|
||||
let i = uri.lastIndexOf("/");
|
||||
Components.utils.import(uri.substring(0, i+1) + path, that);
|
||||
Components.utils.import(uri.substring(0, i+1) + path, scope || that);
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
// Module used by test_import_module.js
|
||||
|
||||
const EXPORTED_SYMBOLS = [ "MODULE_IMPORTED", "MODULE_URI", "SUBMODULE_IMPORTED", "same_scope" ];
|
||||
const EXPORTED_SYMBOLS = [ "MODULE_IMPORTED", "MODULE_URI", "SUBMODULE_IMPORTED", "same_scope", "SUBMODULE_IMPORTED_TO_SCOPE" ];
|
||||
|
||||
const MODULE_IMPORTED = true;
|
||||
const MODULE_URI = __URI__;
|
||||
@ -26,3 +26,9 @@ XPCOMUtils.importRelative(scope2, "duh/../import_sub_module.jsm");
|
||||
// We'll leave it up to test_import_module.js to check that this variable is
|
||||
// true.
|
||||
var same_scope = (scope1.test_obj.i == scope2.test_obj.i);
|
||||
|
||||
// Check that importRelative can also import into a given scope
|
||||
var testScope = {};
|
||||
XPCOMUtils.importRelative(this, "import_sub_module.jsm", testScope);
|
||||
var SUBMODULE_IMPORTED_TO_SCOPE = testScope.SUBMODULE_IMPORTED;
|
||||
|
||||
|
@ -18,4 +18,5 @@ function run_test() {
|
||||
do_check_true(MODULE_IMPORTED);
|
||||
do_check_true(SUBMODULE_IMPORTED);
|
||||
do_check_true(same_scope);
|
||||
do_check_true(SUBMODULE_IMPORTED_TO_SCOPE);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user