testing/xpcshell/example/unit/import_module.jsm

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 // Module used by test_import_module.js
michael@0 6
michael@0 7 const EXPORTED_SYMBOLS = [ "MODULE_IMPORTED", "MODULE_URI", "SUBMODULE_IMPORTED", "same_scope", "SUBMODULE_IMPORTED_TO_SCOPE" ];
michael@0 8
michael@0 9 const MODULE_IMPORTED = true;
michael@0 10 const MODULE_URI = __URI__;
michael@0 11
michael@0 12 // Will import SUBMODULE_IMPORTED into scope.
michael@0 13 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
michael@0 14 XPCOMUtils.importRelative(this, "import_sub_module.jsm");
michael@0 15
michael@0 16 // Prepare two scopes that we can import the submodule into.
michael@0 17 var scope1 = { __URI__: __URI__ };
michael@0 18 var scope2 = { __URI__: __URI__ };
michael@0 19 // First one is the regular path.
michael@0 20 XPCOMUtils.importRelative(scope1, "import_sub_module.jsm");
michael@0 21 scope1.test_obj.i++;
michael@0 22 // Second one is with a different path (leads to the same file).
michael@0 23 XPCOMUtils.importRelative(scope2, "duh/../import_sub_module.jsm");
michael@0 24 // test_obj belongs to import_sub_module.jsm and has a mutable field name i, if
michael@0 25 // the two modules are actually the same, then they'll share the same value.
michael@0 26 // We'll leave it up to test_import_module.js to check that this variable is
michael@0 27 // true.
michael@0 28 var same_scope = (scope1.test_obj.i == scope2.test_obj.i);
michael@0 29
michael@0 30 // Check that importRelative can also import into a given scope
michael@0 31 var testScope = {};
michael@0 32 XPCOMUtils.importRelative(this, "import_sub_module.jsm", testScope);
michael@0 33 var SUBMODULE_IMPORTED_TO_SCOPE = testScope.SUBMODULE_IMPORTED;
michael@0 34

mercurial