From c0d0fa51739abe8a2b5c271d0396f531cefb2fbe Mon Sep 17 00:00:00 2001 From: Alexandre Poirot Date: Thu, 14 Apr 2016 14:32:21 -0700 Subject: [PATCH] Bug 1263629 - Use promise module invisible to the debugger for the browser toolbox server. r=jryans --- devtools/shared/Loader.jsm | 61 +++++++++++++------ .../tests/unit/test_invisible_loader.js | 12 ++++ 2 files changed, 53 insertions(+), 20 deletions(-) diff --git a/devtools/shared/Loader.jsm b/devtools/shared/Loader.jsm index 1cbec5e8f6df..b2b956756495 100644 --- a/devtools/shared/Loader.jsm +++ b/devtools/shared/Loader.jsm @@ -26,7 +26,6 @@ this.EXPORTED_SYMBOLS = ["DevToolsLoader", "devtools", "BuiltinProvider", var loaderModules = { "Services": Object.create(Services), "toolkit/loader": Loader, - promise, PromiseDebugging, ChromeUtils, ThreadSafeChromeUtils, @@ -82,6 +81,24 @@ XPCOMUtils.defineLazyGetter(loaderModules, "URL", () => { return sandbox.URL; }); +const loaderPaths = { + // ⚠ DISCUSSION ON DEV-DEVELOPER-TOOLS REQUIRED BEFORE MODIFYING ⚠ + "": "resource://gre/modules/commonjs/", + // ⚠ DISCUSSION ON DEV-DEVELOPER-TOOLS REQUIRED BEFORE MODIFYING ⚠ + "devtools": "resource://devtools", + // ⚠ DISCUSSION ON DEV-DEVELOPER-TOOLS REQUIRED BEFORE MODIFYING ⚠ + "gcli": "resource://devtools/shared/gcli/source/lib/gcli", + // ⚠ DISCUSSION ON DEV-DEVELOPER-TOOLS REQUIRED BEFORE MODIFYING ⚠ + "acorn": "resource://devtools/acorn", + // ⚠ DISCUSSION ON DEV-DEVELOPER-TOOLS REQUIRED BEFORE MODIFYING ⚠ + "acorn/util/walk": "resource://devtools/acorn/walk.js", + // ⚠ DISCUSSION ON DEV-DEVELOPER-TOOLS REQUIRED BEFORE MODIFYING ⚠ + "source-map": "resource://devtools/shared/sourcemap/source-map.js", + // ⚠ DISCUSSION ON DEV-DEVELOPER-TOOLS REQUIRED BEFORE MODIFYING ⚠ + // Allow access to xpcshell test items from the loader. + "xpcshell-test": "resource://test", +}; + var sharedGlobalBlocklist = ["sdk/indexed-db"]; /** @@ -91,27 +108,31 @@ var sharedGlobalBlocklist = ["sdk/indexed-db"]; function BuiltinProvider() {} BuiltinProvider.prototype = { load: function() { + // Copy generic paths and modules for this loader instance + let paths = {}; + for (let path in loaderPaths) { + paths[path] = loaderPaths[path]; + } + let modules = {}; + for (let name in loaderModules) { + XPCOMUtils.defineLazyGetter(modules, name, (function (name) { + return loaderModules[name]; + }).bind(null, name)); + } + // When creating a Loader invisible to the Debugger, we have to ensure + // using only modules and not depend on any JSM. As everything that is + // not loaded with Loader isn't going to respect `invisibleToDebugger`. + // But we have to keep using Promise.jsm for other loader to prevent + // breaking unhandled promise rejection in tests. + if (this.invisibleToDebugger) { + paths["promise"] = "resource://gre/modules/Promise-backend.js"; + } else { + modules["promise"] = promise; + } this.loader = new Loader.Loader({ id: "fx-devtools", - modules: loaderModules, - paths: { - // ⚠ DISCUSSION ON DEV-DEVELOPER-TOOLS REQUIRED BEFORE MODIFYING ⚠ - "": "resource://gre/modules/commonjs/", - // ⚠ DISCUSSION ON DEV-DEVELOPER-TOOLS REQUIRED BEFORE MODIFYING ⚠ - "devtools": "resource://devtools", - // ⚠ DISCUSSION ON DEV-DEVELOPER-TOOLS REQUIRED BEFORE MODIFYING ⚠ - "gcli": "resource://devtools/shared/gcli/source/lib/gcli", - // ⚠ DISCUSSION ON DEV-DEVELOPER-TOOLS REQUIRED BEFORE MODIFYING ⚠ - "acorn": "resource://devtools/acorn", - // ⚠ DISCUSSION ON DEV-DEVELOPER-TOOLS REQUIRED BEFORE MODIFYING ⚠ - "acorn/util/walk": "resource://devtools/acorn/walk.js", - // ⚠ DISCUSSION ON DEV-DEVELOPER-TOOLS REQUIRED BEFORE MODIFYING ⚠ - "source-map": "resource://devtools/shared/sourcemap/source-map.js", - // ⚠ DISCUSSION ON DEV-DEVELOPER-TOOLS REQUIRED BEFORE MODIFYING ⚠ - // Allow access to xpcshell test items from the loader. - "xpcshell-test": "resource://test" - // ⚠ DISCUSSION ON DEV-DEVELOPER-TOOLS REQUIRED BEFORE MODIFYING ⚠ - }, + modules, + paths, globals: this.globals, invisibleToDebugger: this.invisibleToDebugger, sharedGlobal: true, diff --git a/devtools/shared/tests/unit/test_invisible_loader.js b/devtools/shared/tests/unit/test_invisible_loader.js index c29995d4d2a2..225131c10c06 100644 --- a/devtools/shared/tests/unit/test_invisible_loader.js +++ b/devtools/shared/tests/unit/test_invisible_loader.js @@ -27,6 +27,11 @@ function visible_loader() { } catch(e) { do_throw("debugger could not add visible value"); } + + // Check that for common loader used for tabs, promise modules is Promise.jsm + // Which is required to support unhandled promises rejection in mochitests + const promise = Cu.import("resource://gre/modules/Promise.jsm", {}).Promise; + do_check_eq(loader.require("promise"), promise); } function invisible_loader() { @@ -43,4 +48,11 @@ function invisible_loader() { } catch(e) { do_check_true(true); } + + // But for browser toolbox loader, promise is loaded as a regular modules out + // of Promise-backend.js, that to be invisible to the debugger and not step + // into it. + const promise = loader.require("promise"); + const promiseModule = loader._provider.loader.modules["resource://gre/modules/Promise-backend.js"]; + do_check_eq(promise, promiseModule.exports); }