Files
roytam1 e80d4ec416 import changes from `dev' branch of rmottola/Arctic-Fox:
- Bug 1246036 - Don't let the "hey there's no allocation stacks" message throw and break rendering; r=jsantell (971bc73915)
- Bug 1249789, 1249791, 1249792, 1249796, 1249798 - Clean up memory tool breakdowns; r=jsantell (38f2e5972f)
- Bug 1219554 - Enable the browser_memory_breakdowns_01.js test on DEBUG builds; r=jsantell (e338361288)
- Bug 1219554 - Enable the browser_memory_filter_01.js test on DEBUG builds; r=jsantell (c20f3fb8b0)
- Bug 1249779 - Remove the "invert tree" checkbox and make inverting a property of the "group by" selection; r=jsantell (c69072ebd3)
- Bug 1237428 - Don't cap number of attributes on DOM nodes in console;r=jryans (433a8a8ec4)
- Bug 1251084 - Remove WebConsoleUtils.abbreviateSourceURL with source-utils function. r=linclark (f0a8c12569)
- Bug 1224196 - Applies word wrap fix to toolbar-group in devtools. r=ntim (d49e35a598)
- Bug 1253806 - [DevTools][Memory] label.label-by > span element does not have margin-inline-end. r=fitzgen (14fcdc8aad)
- Bug 1248609 - Fix debugger when reloading via the addon. r=jryans (975d3ac429)
- Bug 1119490 - Test for source maps in workers;r=jryans (b84ec1211e)
- Bug 1207997 - about:debugging use factories/dom helpers instead of createElement;r=janx (6c961ba35e)
- Bug 1251033 - Part 1 - BrowserLoader now has an option to only load shared components and not require an additional directory. r=jryans (15b77338d2)
- Bug 1251033 - Part 2 - FrameComponent should correctly handle erroneous line/column formats. r=fitzgen (ca50f5c6fc)
- Bug 1251033 - Part 3 - Fix unmerged chunk from eb9b84702b2c. a=philor (76bee30b34)
- Bug 1254736 - Do not link to unlinkable frames in Frame component. r=fitzgen (6865247c55)
- Bug 1251033 - Part 4 - Integrate Frame component in webconsole. r=linclark (6f2ff13b21)
- Bug 1256163 - Fix all other code styles in webconsole.js. r=lclark (147317f091)
- Bug 1260071 - Call resize() when searching happens on frontend to reset width;r=vporof (5588b67fe7)
- Bug 1239992 - Focus input field if text is not selected in webconsole output;r=linclark (90a6217ea0)
- Bug 1233865 - Remove deprecated dbg_assert. r=fitzgen (28692df9b4)
- Bug 1235901 - Remove FrameActor.pop from the RDP. r=fitzgen (815938da80)
- Bug 1235375 - Change FrameActor to protocol.js. r=ejpbruel (0db2443443)
- Bug 1235374 - Change BreakpointActor to protocol.js. r=jryans (9f3b335fe0)
- Bug 1222087: Part 1 - Fix ignoring of exceptions in blackboxed code. r=fitzgen (2da35341f8)
- Bug 1222087: Part 2 - Ignore NS_ERROR_NO_INTERFACE exceptions when pausing on exceptions. r=fitzgen (b84622cee7)
- Bug 1235371 - Move EnvironmentActor into its own file;r=jryans (1b5e03cdb8)
- Bug 1255133 - Surface links to external documentation alongside relevant error messages 1/2; r=bgrins (a588f0e279)
- Bug 1255133 - Surface the most common JavaScript errors; r=bgrins (a34470af5b)
- Bug 1163540 - make sure the debugger treats XBL inline sources correctly r=Gijs (682a78f3de)
- Bug 1247192 - Replace all usage of Services in TabSources with URL;r=fitzgen,jryans (7d7ff572a4)
- Bug 1250896 - Move SourceActor into its own file;r=jryans (eea5852174)
- Bug 1250896 - Refactor SourceActor to use protocol.js;r=jryans (469948ee2a)
- Bug 1232014 - Give wasm Debugger.Sources the text/wasm mimetype and use their .text property. (r=ejpbruel) (087d349e75)
- Bug 1227474 - Promisify all client methods. r=jryans (d7b175eb83)
- Bug 1177279 - Create a SourceLocationController to manage the state of updating sources for source mapping. r=jlong,jryans (0a18496656)
- No bug - Remove spurious debugger comment;r=me (de1c2319b9)
- Bug 1235371 - Refactor EnvironmentActor to use protocol.js;r=jryans (7091450275)
- Bug 1253976 - Protocol.js error packets should have meaningful `error` and `message` fields;r=jryans (701d65e54b)
- Bug 1207506 - Replace all uses of Services.io in path.js with URL;r=janx (71f835123e)
- Bug 1250110 - Clean up the path utility functions. r=ejpbruel (f3a378c3cf)
- Bug 1227978 - Convert all DebuggerClient request methods to return promises. r=jlongster (134a0cc416)
- Bug 1239287 - Promisify DebugerClient.attach* requests. r=jryans (37ffc27f4a)
- Bug 1238939 - Fix reentrance loop with active requests during client close. r=jryans (6c95a524cf)
- Bug 1209559 - "Figure out why opening a toolbox on certain workers works only once.". r=janx (5613bfbbc2)
- Bug 1119490 - Enable source maps for workers;r=jryans (8e7710ac7e)
- Bug 1248303 - respect break on exceptions flag in subsequent debugger instances r=ejpbruel (572f93e1b5)
- Bug 1122102 - post json params shouldn't be displayed as text in params>request payload, r=vporof (c200feba9a)
- Bug 1255734 - DevTools: Inspecting a primitive value in console throws a TypeError. r=vporof (6aac84ec60)
- Bug 1238467 - add tooltiptext on SideMenuWidget group checkbox. r=vporof (4c932a8538)
- Bug 1211796 - Do not convert CSS filters to computed values before opening the Filter Widget; r=tromey (3f3d594c06)
- Bug 1249147 - Add a resizable split pane component to devtools/client/shared/components; r=jsantell,linclark (1b57ff9aef)
- Bug 1251492 - Don't prevent default behavior of unrelated mouse events in HSplitBox. r=linclark (225bdb0bd1)
- Bug 1198326 - Prevent event propagation on click events of the inplace editor;r=bgrins (0055705234)
- Bug 1137561 part.6 Store some strings which may be inputted by the key with some modifier state before dispatching keydown event r=m_kato (f9f7c6b4ea)
- Bug 1137561 part.7 Rename whole members added by the previous patch r=m_kato (370b3a32d9)
- Bug 1137561 part.8 Implement WinTextEventDispatcherListener::WillDispatchKeyboardEvent() r=m_kato (b585bd6e17)
- Bug 1137561 part.9 NativeKey should dispatch keypress events after removing following char messages if there are two or more characters to be inputted r=m_kato (3347ff96a8)
- Bug 1243695 - reduce inplace editor size in ruleview;r=miker (5c109ab678)
- Bug 1254194: Add XPCOMUtils.defineLazyPreferenceGetter. r=billm (625f92b590)
- Bug 1257042: Remove the worker descriptor for PushEvent and PushMessageData. r=bz (632ff26069)
- Bug 1137563 part.1 Implement TextEventDispatcherListener in TextEventInputHandlerBase and IMEInputHandler r=m_kato (a720bf2936)
- Bug 1137563 part.2 IMEInputHandler should use TextEventDispatcher r=m_kato (f85440ce2c)
- Bug 1137563 part.3 TextInputHandler should use TextEventDispatcher r=m_kato (21c8ce033e)
- Bug 1137563 part.4 Implement IMEInputHandler::WillDispatchKeyboardEvent() r=m_kato (147d48d198)
- Bug 1137563 part.5 Set charCode of dead key's keypress event on Mac to the dead char r=m_kato (41d03e394d)
- Bug 1137565 part.1 Implement TextEventDispatcherListener in IMContextWrapper r=m_kato (a4c16286a4)
- Bug 1137565 part.2 IMContextWrapper should use TextEventDispatcher r=m_kato (59865f1e6b)
- Bug 1137565 part.3 nsWindow for GTK should use TextEventDispatcher for dispatching keyboard events r=m_kato (56ea1d10fb)
- Bug 1137565 part.4 Implement IMContextWrapper::WillDispatchKeyboardEvent() r=m_kato (b9c1e394e9)
- Bug 1258153 Initialize mozilla::widget::Native key with actual inputting character if it's created for WM_CHAR r=m_kato (d95afe4565)
- Bug 1158264 - Send an observer service event when a service worker intercept a request. r=bkelly (195ab33181)
- Bug 1247623 Cancel intercepted channel in more service worker failure cases. r=jdm (8307094514)
2024-03-30 09:31:19 +08:00

518 lines
16 KiB
JavaScript

/* 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";
// A CommonJS module loader that is designed to run inside a worker debugger.
// We can't simply use the SDK module loader, because it relies heavily on
// Components, which isn't available in workers.
//
// In principle, the standard instance of the worker loader should provide the
// same built-in modules as its devtools counterpart, so that both loaders are
// interchangable on the main thread, making them easier to test.
//
// On the worker thread, some of these modules, in particular those that rely on
// the use of Components, and for which the worker debugger doesn't provide an
// alternative API, will be replaced by vacuous objects. Consequently, they can
// still be required, but any attempts to use them will lead to an exception.
this.EXPORTED_SYMBOLS = ["WorkerDebuggerLoader", "worker"];
// Some notes on module ids and URLs:
//
// An id is either a relative id or an absolute id. An id is relative if and
// only if it starts with a dot. An absolute id is a normalized id if and only
// if it contains no redundant components.
//
// Every normalized id is a URL. A URL is either an absolute URL or a relative
// URL. A URL is absolute if and only if it starts with a scheme name followed
// by a colon and 2 or 3 slashes.
/**
* Convert the given relative id to an absolute id.
*
* @param String id
* The relative id to be resolved.
* @param String baseId
* The absolute base id to resolve the relative id against.
*
* @return String
* An absolute id
*/
function resolveId(id, baseId) {
return baseId + "/../" + id;
};
/**
* Convert the given absolute id to a normalized id.
*
* @param String id
* The absolute id to be normalized.
*
* @return String
* A normalized id.
*/
function normalizeId(id) {
// An id consists of an optional root and a path. A root consists of either
// a scheme name followed by 2 or 3 slashes, or a single slash. Slashes in the
// root are not used as separators, so only normalize the path.
let [_, root, path] = id.match(/^(\w+:\/\/\/?|\/)?(.*)/);
let stack = [];
path.split("/").forEach(function (component) {
switch (component) {
case "":
case ".":
break;
case "..":
if (stack.length === 0) {
if (root !== undefined) {
throw new Error("Can't normalize absolute id '" + id + "'!");
} else {
stack.push("..");
}
} else {
if (stack[stack.length - 1] == "..") {
stack.push("..");
} else {
stack.pop();
}
}
break;
default:
stack.push(component);
break;
}
});
return (root ? root : "") + stack.join("/");
}
/**
* Create a module object with the given normalized id.
*
* @param String
* The normalized id of the module to be created.
*
* @return Object
* A module with the given id.
*/
function createModule(id) {
return Object.create(null, {
// CommonJS specifies the id property to be non-configurable and
// non-writable.
id: {
configurable: false,
enumerable: true,
value: id,
writable: false
},
// CommonJS does not specify an exports property, so follow the NodeJS
// convention, which is to make it non-configurable and writable.
exports: {
configurable: false,
enumerable: true,
value: Object.create(null),
writable: true
}
});
};
/**
* Create a CommonJS loader with the following options:
* - createSandbox:
* A function that will be used to create sandboxes. It should take the name
* and prototype of the sandbox to be created, and return the newly created
* sandbox as result. This option is required.
* - globals:
* A map of names to built-in globals that will be exposed to every module.
* Defaults to the empty map.
* - loadSubScript:
* A function that will be used to load scripts in sandboxes. It should take
* the URL from and the sandbox in which the script is to be loaded, and not
* return a result. This option is required.
* - modules:
* A map from normalized ids to built-in modules that will be added to the
* module cache. Defaults to the empty map.
* - paths:
* A map of paths to base URLs that will be used to resolve relative URLs to
* absolute URLS. Defaults to the empty map.
* - resolve:
* A function that will be used to resolve relative ids to absolute ids. It
* should take the relative id of a module to be required and the absolute
* id of the requiring module as arguments, and return the absolute id of
* the module to be required as result. Defaults to resolveId above.
*/
function WorkerDebuggerLoader(options) {
/**
* Convert the given relative URL to an absolute URL, using the map of paths
* given below.
*
* @param String url
* The relative URL to be resolved.
*
* @return String
* An absolute URL.
*/
function resolveURL(url) {
let found = false;
for (let [path, baseURL] of paths) {
if (url.startsWith(path)) {
found = true;
url = url.replace(path, baseURL);
break;
}
}
if (!found) {
throw new Error("Can't resolve relative URL '" + url + "'!");
}
// If the url has no extension, use ".js" by default.
return url.endsWith(".js") ? url : url + ".js";
}
/**
* Load the given module with the given url.
*
* @param Object module
* The module object to be loaded.
* @param String url
* The URL to load the module from.
*/
function loadModule(module, url) {
// CommonJS specifies 3 free variables: require, exports, and module. These
// must be exposed to every module, so define these as properties on the
// sandbox prototype. Additional built-in globals are exposed by making
// the map of built-in globals the prototype of the sandbox prototype.
let prototype = Object.create(globals);
prototype.Components = {};
prototype.require = createRequire(module);
prototype.exports = module.exports;
prototype.module = module;
let sandbox = createSandbox(url, prototype);
try {
loadSubScript(url, sandbox);
} catch (error) {
if (/^Error opening input stream/.test(String(error))) {
throw new Error("Can't load module '" + module.id + "' with url '" +
url + "'!");
}
throw error;
}
// The value of exports may have been changed by the module script, so
// freeze it if and only if it is still an object.
if (typeof module.exports === "object" && module.exports !== null) {
Object.freeze(module.exports);
}
};
/**
* Create a require function for the given module. If no module is given,
* create a require function for the top-level module instead.
*
* @param Object requirer
* The module for which the require function is to be created.
*
* @return Function
* A require function for the given module.
*/
function createRequire(requirer) {
return function require(id) {
// Make sure an id was passed.
if (id === undefined) {
throw new Error("Can't require module without id!");
}
// Built-in modules are cached by id rather than URL, so try to find the
// module to be required by id first.
let module = modules[id];
if (module === undefined) {
// Failed to find the module to be required by id, so convert the id to
// a URL and try again.
// If the id is relative, convert it to an absolute id.
if (id.startsWith(".")) {
if (requirer === undefined) {
throw new Error("Can't require top-level module with relative id " +
"'" + id + "'!");
}
id = resolve(id, requirer.id);
}
// Convert the absolute id to a normalized id.
id = normalizeId(id);
// Convert the normalized id to a URL.
let url = id;
// If the URL is relative, resolve it to an absolute URL.
if (url.match(/^\w+:\/\//) === null) {
url = resolveURL(id);
}
// Try to find the module to be required by URL.
module = modules[url];
if (module === undefined) {
// Failed to find the module to be required in the cache, so create
// a new module, load it from the given URL, and add it to the cache.
// Add modules to the cache early so that any recursive calls to
// require for the same module will return the partially-loaded module
// from the cache instead of triggering a new load.
module = modules[url] = createModule(id);
try {
loadModule(module, url);
} catch (error) {
// If the module failed to load, remove it from the cache so that
// subsequent calls to require for the same module will trigger a
// new load, instead of returning a partially-loaded module from
// the cache.
delete modules[url];
throw error;
}
Object.freeze(module);
}
}
return module.exports;
};
}
let createSandbox = options.createSandbox;
let globals = options.globals || Object.create(null);
let loadSubScript = options.loadSubScript;
// Create the module cache, by converting each entry in the map from
// normalized ids to built-in modules to a module object, with the exports
// property of each module set to a frozen version of the original entry.
let modules = options.modules || {};
for (let id in modules) {
let module = createModule(id);
module.exports = Object.freeze(modules[id]);
modules[id] = module;
}
// Convert the map of paths to base URLs into an array for use by resolveURL.
// The array is sorted from longest to shortest path to ensure that the
// longest path is always the first to be found.
let paths = options.paths || Object.create(null);
paths = Object.keys(paths)
.sort((a, b) => b.length - a.length)
.map(path => [path, paths[path]]);
let resolve = options.resolve || resolveId;
this.require = createRequire();
}
this.WorkerDebuggerLoader = WorkerDebuggerLoader;
// The following APIs rely on the use of Components, and the worker debugger
// does not provide alternative definitions for them. Consequently, they are
// stubbed out both on the main thread and worker threads.
var PromiseDebugging = {
getState: function () {
throw new Error("PromiseDebugging is not available in workers!");
}
};
var chrome = {
CC: undefined,
Cc: undefined,
ChromeWorker: undefined,
Cm: undefined,
Ci: undefined,
Cu: undefined,
Cr: undefined,
components: undefined
};
var loader = {
lazyGetter: function (object, name, lambda) {
Object.defineProperty(object, name, {
get: function () {
delete object[name];
return object[name] = lambda.apply(object);
},
configurable: true,
enumerable: true
});
},
lazyImporter: function () {
throw new Error("Can't import JSM from worker thread!");
},
lazyServiceGetter: function () {
throw new Error("Can't import XPCOM service from worker thread!");
},
lazyRequireGetter: function (obj, property, module, destructure) {
Object.defineProperty(obj, property, {
get: () => destructure ? worker.require(module)[property]
: worker.require(module || property)
});
}
};
// The following APIs are defined differently depending on whether we are on the
// main thread or a worker thread. On the main thread, we use the Components
// object to implement them. On worker threads, we use the APIs provided by
// the worker debugger.
var {
Debugger,
URL,
createSandbox,
dump,
rpc,
loadSubScript,
reportError,
setImmediate,
xpcInspector
} = (function () {
if (typeof Components === "object") { // Main thread
let {
Constructor: CC,
classes: Cc,
manager: Cm,
interfaces: Ci,
results: Cr,
utils: Cu
} = Components;
let principal = CC('@mozilla.org/systemprincipal;1', 'nsIPrincipal')();
// To ensure that the this passed to addDebuggerToGlobal is a global, the
// Debugger object needs to be defined in a sandbox.
let sandbox = Cu.Sandbox(principal, {});
Cu.evalInSandbox(
"Components.utils.import('resource://gre/modules/jsdebugger.jsm');" +
"addDebuggerToGlobal(this);",
sandbox
);
let Debugger = sandbox.Debugger;
let createSandbox = function(name, prototype) {
return Cu.Sandbox(principal, {
invisibleToDebugger: true,
sandboxName: name,
sandboxPrototype: prototype,
wantComponents: false,
wantXrays: false
});
};
let rpc = undefined;
let subScriptLoader = Cc['@mozilla.org/moz/jssubscript-loader;1'].
getService(Ci.mozIJSSubScriptLoader);
let loadSubScript = function (url, sandbox) {
subScriptLoader.loadSubScript(url, sandbox, "UTF-8");
};
let reportError = Cu.reportError;
let Timer = Cu.import("resource://gre/modules/Timer.jsm", {});
let setImmediate = function (callback) {
Timer.setTimeout(callback, 0);
}
let xpcInspector = Cc["@mozilla.org/jsinspector;1"].
getService(Ci.nsIJSInspector);
return {
Debugger,
URL: this.URL,
createSandbox,
dump: this.dump,
rpc,
loadSubScript,
reportError,
setImmediate,
xpcInspector
};
} else { // Worker thread
let requestors = [];
let scope = this;
let xpcInspector = {
get eventLoopNestLevel() {
return requestors.length;
},
get lastNestRequestor() {
return requestors.length === 0 ? null : requestors[requestors.length - 1];
},
enterNestedEventLoop: function (requestor) {
requestors.push(requestor);
scope.enterEventLoop();
return requestors.length;
},
exitNestedEventLoop: function () {
requestors.pop();
scope.leaveEventLoop();
return requestors.length;
}
};
return {
Debugger: this.Debugger,
URL: this.URL,
createSandbox: this.createSandbox,
dump: this.dump,
rpc: this.rpc,
loadSubScript: this.loadSubScript,
reportError: this.reportError,
setImmediate: this.setImmediate,
xpcInspector: xpcInspector
};
}
}).call(this);
// Create the default instance of the worker loader, using the APIs we defined
// above.
this.worker = new WorkerDebuggerLoader({
createSandbox: createSandbox,
globals: {
"isWorker": true,
"dump": dump,
"loader": loader,
"reportError": reportError,
"rpc": rpc,
"setImmediate": setImmediate
},
loadSubScript: loadSubScript,
modules: {
"Debugger": Debugger,
"PromiseDebugging": PromiseDebugging,
"Services": Object.create(null),
"URL": URL,
"chrome": chrome,
"xpcInspector": xpcInspector
},
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 ⚠
"promise": "resource://gre/modules/Promise-backend.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 ⚠
"xpcshell-test": "resource://test"
// ⚠ DISCUSSION ON DEV-DEVELOPER-TOOLS REQUIRED BEFORE MODIFYING ⚠
}
});