diff --git a/browser/devtools/shared/test/browser.ini b/browser/devtools/shared/test/browser.ini index 8351047a6a49..b61f8edb784c 100644 --- a/browser/devtools/shared/test/browser.ini +++ b/browser/devtools/shared/test/browser.ini @@ -95,7 +95,6 @@ skip-if = e10s # Test intermittently fails with e10s. Bug 1124162. [browser_poller.js] [browser_prefs-01.js] [browser_prefs-02.js] -[browser_require_basic.js] [browser_spectrum.js] [browser_theme.js] [browser_tableWidget_basic.js] diff --git a/browser/devtools/shared/test/browser_require_basic.js b/browser/devtools/shared/test/browser_require_basic.js deleted file mode 100644 index f86974df45b8..000000000000 --- a/browser/devtools/shared/test/browser_require_basic.js +++ /dev/null @@ -1,140 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - * http://creativecommons.org/publicdomain/zero/1.0/ */ - -// Tests that source URLs in the Web Console can be clicked to display the -// standard View Source window. - -let [ define, require ] = (function() { - let tempScope = {}; - Components.utils.import("resource://gre/modules/devtools/Require.jsm", tempScope); - return [ tempScope.define, tempScope.require ]; -})(); - -function test() { - addTab("about:blank", function() { - info("Starting Require Tests"); - setup(); - - testWorking(); - testDomains(); - testLeakage(); - testMultiImport(); - testRecursive(); - testUncompilable(); - testFirebug(); - - shutdown(); - }); -} - -function setup() { - define('gclitest/requirable', [ 'require', 'exports', 'module' ], function(require, exports, module) { - exports.thing1 = 'thing1'; - exports.thing2 = 2; - - let status = 'initial'; - exports.setStatus = function(aStatus) { status = aStatus; }; - exports.getStatus = function() { return status; }; - }); - - define('gclitest/unrequirable', [ 'require', 'exports', 'module' ], function(require, exports, module) { - null.throwNPE(); - }); - - define('gclitest/recurse', [ 'require', 'exports', 'module', 'gclitest/recurse' ], function(require, exports, module) { - require('gclitest/recurse'); - }); - - define('gclitest/firebug', [ 'gclitest/requirable' ], function(requirable) { - return { requirable: requirable, fb: true }; - }); -} - -function shutdown() { - delete define.modules['gclitest/requirable']; - delete define.globalDomain.modules['gclitest/requirable']; - delete define.modules['gclitest/unrequirable']; - delete define.globalDomain.modules['gclitest/unrequirable']; - delete define.modules['gclitest/recurse']; - delete define.globalDomain.modules['gclitest/recurse']; - delete define.modules['gclitest/firebug']; - delete define.globalDomain.modules['gclitest/firebug']; - - define = undefined; - require = undefined; - - finish(); -} - -function testWorking() { - // There are lots of requirement tests that we could be doing here - // The fact that we can get anything at all working is a testament to - // require doing what it should - we don't need to test the - let requireable = require('gclitest/requirable'); - is('thing1', requireable.thing1, 'thing1 was required'); - is(2, requireable.thing2, 'thing2 was required'); - is(requireable.thing3, undefined, 'thing3 was not required'); -} - -function testDomains() { - let requireable = require('gclitest/requirable'); - is(requireable.status, undefined, 'requirable has no status'); - requireable.setStatus(null); - is(null, requireable.getStatus(), 'requirable.getStatus changed to null'); - is(requireable.status, undefined, 'requirable still has no status'); - requireable.setStatus('42'); - is('42', requireable.getStatus(), 'requirable.getStatus changed to 42'); - is(requireable.status, undefined, 'requirable *still* has no status'); - - let domain = new define.Domain(); - let requireable2 = domain.require('gclitest/requirable'); - is(requireable2.status, undefined, 'requirable2 has no status'); - is('initial', requireable2.getStatus(), 'requirable2.getStatus is initial'); - requireable2.setStatus(999); - is(999, requireable2.getStatus(), 'requirable2.getStatus changed to 999'); - is(requireable2.status, undefined, 'requirable2 still has no status'); - - is('42', requireable.getStatus(), 'status 42'); - ok(requireable.status === undefined, 'requirable has no status (as expected)'); - - delete domain.modules['gclitest/requirable']; -} - -function testLeakage() { - let requireable = require('gclitest/requirable'); - is(requireable.setup, null, 'leakage of setup'); - is(requireable.shutdown, null, 'leakage of shutdown'); - is(requireable.testWorking, null, 'leakage of testWorking'); -} - -function testMultiImport() { - let r1 = require('gclitest/requirable'); - let r2 = require('gclitest/requirable'); - is(r1, r2, 'double require was strict equal'); -} - -function testUncompilable() { - // It's not totally clear how a module loader should perform with unusable - // modules, however at least it should go into a flat spin ... - // GCLI mini_require reports an error as it should - try { - let unrequireable = require('gclitest/unrequirable'); - fail(); - } - catch (ex) { - // an exception is expected - } -} - -function testRecursive() { - // See Bug 658583 - // require('gclitest/recurse'); - // Also see the comments in the testRecursive() function -} - -function testFirebug() { - let requirable = require('gclitest/requirable'); - let firebug = require('gclitest/firebug'); - ok(firebug.fb, 'firebug.fb is true'); - is(requirable, firebug.requirable, 'requirable pass-through'); -} diff --git a/toolkit/devtools/Require.jsm b/toolkit/devtools/Require.jsm deleted file mode 100644 index ab72b526b72b..000000000000 --- a/toolkit/devtools/Require.jsm +++ /dev/null @@ -1,195 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -"use strict"; - -/** - * Require.jsm is a small module loader that loads JavaScript modules as - * defined by AMD/RequireJS and CommonJS, or specifically as used by: - * GCLI, Orion, Firebug, CCDump, NetPanel/HTTPMonitor and others. - * - * To date, no attempt has been made to ensure that Require.jsm closely follows - * either the AMD or CommonJS specs. It is hoped that a more formal JavaScript - * module standard will arrive before this is necessary. In the mean time it - * serves the projects it loads. - */ - -this.EXPORTED_SYMBOLS = [ "define", "require" ]; - -const console = (function() { - const tempScope = {}; - Components.utils.import("resource://gre/modules/devtools/Console.jsm", tempScope); - return tempScope.console; -})(); - -/** - * Define a module along with a payload. - * @param moduleName Name for the payload - * @param deps Ignored. For compatibility with CommonJS AMD Spec - * @param payload Function with (require, exports, module) params - */ -this.define = function define(moduleName, deps, payload) { - if (typeof moduleName != "string") { - throw new Error("Error: Module name is not a string"); - } - - if (arguments.length == 2) { - payload = deps; - } - else { - payload.deps = deps; - } - - if (define.debugDependencies) { - console.log("define: " + moduleName + " -> " + payload.toString() - .slice(0, 40).replace(/\n/, '\\n').replace(/\r/, '\\r') + "..."); - } - - if (moduleName in define.modules) { - throw new Error("Error: Redefining module: " + moduleName); - } - - // Mark the payload so we know we need to call it to get the real module - payload.__uncompiled = true; - define.modules[moduleName] = payload; -} - -/** - * The global store of un-instantiated modules - */ -define.modules = {}; - -/** - * Should we console.log on module definition/instantiation/requirement? - */ -define.debugDependencies = false; - - -/** - * We invoke require() in the context of a Domain so we can have multiple - * sets of modules running separate from each other. - * This contrasts with JSMs which are singletons, Domains allows us to - * optionally load a CommonJS module twice with separate data each time. - * Perhaps you want 2 command lines with a different set of commands in each, - * for example. - */ -function Domain() { - this.modules = {}; - - if (define.debugDependencies) { - this.depth = ""; - } -} - -/** - * Lookup module names and resolve them by calling the definition function if - * needed. - * There are 2 ways to call this, either with an array of dependencies and a - * callback to call when the dependencies are found (which can happen - * asynchronously in an in-page context) or with a single string an no - * callback where the dependency is resolved synchronously and returned. - * The API is designed to be compatible with the CommonJS AMD spec and - * RequireJS. - * @param deps A name, or array of names for the payload - * @param callback Function to call when the dependencies are resolved - * @return The module required or undefined for array/callback method - */ -Domain.prototype.require = function(config, deps, callback) { - if (arguments.length <= 2) { - callback = deps; - deps = config; - config = undefined; - } - - if (Array.isArray(deps)) { - var params = deps.map(function(dep) { - return this.lookup(dep); - }, this); - if (callback) { - callback.apply(null, params); - } - return undefined; - } - else { - return this.lookup(deps); - } -}; - -/** - * Lookup module names and resolve them by calling the definition function if - * needed. - * @param moduleName A name for the payload to lookup - * @return The module specified by aModuleName or null if not found - */ -Domain.prototype.lookup = function(moduleName) { - if (moduleName in this.modules) { - var module = this.modules[moduleName]; - if (define.debugDependencies) { - console.log(this.depth + " Using module: " + moduleName); - } - return module; - } - - if (!(moduleName in define.modules)) { - throw new Error("Missing module: " + moduleName); - } - - var module = define.modules[moduleName]; - - if (define.debugDependencies) { - console.log(this.depth + " Compiling module: " + moduleName); - } - - if (module.__uncompiled) { - if (define.debugDependencies) { - this.depth += "."; - } - - var exports = {}; - try { - var params = module.deps.map((dep) => { - if (dep === "require") { - return this.require.bind(this); - } - if (dep === "exports") { - return exports; - } - if (dep === "module") { - return { id: moduleName, uri: "" }; - } - return this.lookup(dep); - }); - - var reply = module.apply(null, params); - module = (reply !== undefined) ? reply : exports; - } - catch (ex) { - dump("Error using module '" + moduleName + "' - " + ex + "\n"); - throw ex; - } - - if (define.debugDependencies) { - this.depth = this.depth.slice(0, -1); - } - } - - // cache the resulting module object for next time - this.modules[moduleName] = module; - - return module; -}; - -/** - * Expose the Domain constructor and a global domain (on the define function - * to avoid exporting more than we need. This is a common pattern with - * require systems) - */ -define.Domain = Domain; -define.globalDomain = new Domain(); - -/** - * Expose a default require function which is the require of the global - * sandbox to make it easy to use. - */ -this.require = define.globalDomain.require.bind(define.globalDomain); diff --git a/toolkit/devtools/moz.build b/toolkit/devtools/moz.build index 11db268096ec..3a2a9c4e5b81 100644 --- a/toolkit/devtools/moz.build +++ b/toolkit/devtools/moz.build @@ -44,7 +44,6 @@ EXTRA_JS_MODULES.devtools += [ EXTRA_JS_MODULES.devtools += [ 'Console.jsm', 'Loader.jsm', - 'Require.jsm', ] EXTRA_JS_MODULES.devtools.server.actors += [