testing/xpcshell/example/unit/import_module.jsm

Wed, 31 Dec 2014 06:55:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:55:50 +0100
changeset 2
7e26c7da4463
permissions
-rw-r--r--

Added tag UPSTREAM_283F7C6 for changeset ca08bd8f51b2

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

mercurial