2014-04-25 19:23:00 +04:00
|
|
|
/* Any copyright is dedicated to the Public Domain.
|
|
|
|
http://creativecommons.org/publicdomain/zero/1.0/ */
|
|
|
|
|
2016-12-30 17:01:42 +03:00
|
|
|
"use strict";
|
|
|
|
|
2019-01-17 21:18:31 +03:00
|
|
|
const { devtools } = ChromeUtils.import(
|
|
|
|
"resource://devtools/shared/Loader.jsm"
|
|
|
|
);
|
2014-04-25 19:23:00 +04:00
|
|
|
// Test devtools.lazyRequireGetter
|
|
|
|
|
|
|
|
function run_test() {
|
2014-11-11 22:20:35 +03:00
|
|
|
const name = "asyncUtils";
|
2015-09-21 20:04:18 +03:00
|
|
|
const path = "devtools/shared/async-utils";
|
2014-04-25 19:23:00 +04:00
|
|
|
const o = {};
|
2014-11-11 22:20:35 +03:00
|
|
|
devtools.lazyRequireGetter(o, name, path);
|
2015-08-06 15:38:10 +03:00
|
|
|
const asyncUtils = require(path);
|
2014-04-25 19:23:00 +04:00
|
|
|
// XXX: do_check_eq only works on primitive types, so we have this
|
|
|
|
// do_check_true of an equality expression.
|
2017-12-21 13:08:17 +03:00
|
|
|
Assert.ok(o.asyncUtils === asyncUtils);
|
2014-11-11 22:20:35 +03:00
|
|
|
|
|
|
|
// A non-main loader should get a new object via |lazyRequireGetter|, just
|
|
|
|
// as it would via a direct |require|.
|
|
|
|
const o2 = {};
|
2018-06-01 13:36:09 +03:00
|
|
|
const loader = new DevToolsLoader();
|
2016-05-12 13:07:56 +03:00
|
|
|
|
2016-12-30 17:01:42 +03:00
|
|
|
// We have to init the loader by loading any module before
|
|
|
|
// lazyRequireGetter is available
|
2016-05-12 13:07:56 +03:00
|
|
|
loader.require("devtools/shared/DevToolsUtils");
|
|
|
|
|
2014-11-11 22:20:35 +03:00
|
|
|
loader.lazyRequireGetter(o2, name, path);
|
2017-12-21 13:08:17 +03:00
|
|
|
Assert.ok(o2.asyncUtils !== asyncUtils);
|
2014-11-11 22:20:35 +03:00
|
|
|
|
|
|
|
// A module required via a non-main loader that then uses |lazyRequireGetter|
|
|
|
|
// should also get the same object from that non-main loader.
|
2018-06-01 13:36:09 +03:00
|
|
|
const exposeLoader = loader.require("xpcshell-test/exposeLoader");
|
2014-11-11 22:20:35 +03:00
|
|
|
const o3 = exposeLoader.exerciseLazyRequire(name, path);
|
2017-12-21 13:08:17 +03:00
|
|
|
Assert.ok(o3.asyncUtils === o2.asyncUtils);
|
2014-04-25 19:23:00 +04:00
|
|
|
}
|