зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1789980 - [devtools] Import "wantGlobalProperties" symbols from the module Sandbox. r=jdescottes
That, instead of involving the "debuggerSandbox", which is only meant for exposing the "Debugger" symbol. Differential Revision: https://phabricator.services.mozilla.com/D156934
This commit is contained in:
Родитель
c27b002b63
Коммит
3ce07c3d24
|
@ -8,13 +8,11 @@
|
|||
const { VariablesView } = ChromeUtils.importESModule(
|
||||
"resource://devtools/client/storage/VariablesView.sys.mjs"
|
||||
);
|
||||
const { globals } = require("devtools/shared/loader/builtin-modules");
|
||||
|
||||
const DOMParser = new globals.DOMParser();
|
||||
DOMParser.forceEnableXULXBL();
|
||||
|
||||
function run_test() {
|
||||
const doc = DOMParser.parseFromString("<div>", "text/html");
|
||||
const parser = new DOMParser();
|
||||
parser.forceEnableXULXBL();
|
||||
const doc = parser.parseFromString("<div>", "text/html");
|
||||
const container = doc.body.firstChild;
|
||||
ok(container, "Got a container.");
|
||||
|
||||
|
|
|
@ -112,6 +112,36 @@ function Sandbox(options) {
|
|||
// Do not expose `Components` if you really need them (bad idea!) you
|
||||
// still can expose via prototype.
|
||||
wantComponents: false,
|
||||
// By default, Sandbox come with a very limited set of global.
|
||||
// The list of all available symbol names is available over there:
|
||||
// https://searchfox.org/mozilla-central/rev/31368c7795f44b7a15531d6c5e52dc97f82cf2d5/js/xpconnect/src/Sandbox.cpp#905-997
|
||||
// Request to expose all meaningful global here:
|
||||
wantGlobalProperties: [
|
||||
"AbortController",
|
||||
"atob",
|
||||
"btoa",
|
||||
"Blob",
|
||||
"crypto",
|
||||
"ChromeUtils",
|
||||
"CSS",
|
||||
"CSSRule",
|
||||
"DOMParser",
|
||||
"Element",
|
||||
"Event",
|
||||
"FileReader",
|
||||
"FormData",
|
||||
"Headers",
|
||||
"indexedDB",
|
||||
"InspectorUtils",
|
||||
"Node",
|
||||
"TextDecoder",
|
||||
"TextEncoder",
|
||||
"URL",
|
||||
"URLSearchParams",
|
||||
"Window",
|
||||
"XMLHttpRequest",
|
||||
],
|
||||
|
||||
sandboxName: options.name,
|
||||
sandboxPrototype: "prototype" in options ? options.prototype : {},
|
||||
invisibleToDebugger:
|
||||
|
|
|
@ -8,6 +8,8 @@
|
|||
* This module defines custom globals injected in all our modules and also
|
||||
* pseudo modules that aren't separate files but just dynamically set values.
|
||||
*
|
||||
* Note that some globals are being defined by base-loader.js via wantGlobalProperties property.
|
||||
*
|
||||
* As it does so, the module itself doesn't have access to these globals,
|
||||
* nor the pseudo modules. Be careful to avoid loading any other js module as
|
||||
* they would also miss them.
|
||||
|
@ -41,67 +43,6 @@ const {
|
|||
TelemetryStopwatch,
|
||||
} = Cu.getGlobalForObject(jsmScope);
|
||||
|
||||
// Create a single Sandbox to access global properties needed in this module.
|
||||
// Sandbox are memory expensive, so we should create as little as possible.
|
||||
const debuggerSandbox = (exports.internalSandbox = Cu.Sandbox(systemPrincipal, {
|
||||
// This sandbox is also reused for ChromeDebugger implementation.
|
||||
// As we want to load the `Debugger` API for debugging chrome contexts,
|
||||
// we have to ensure loading it in a distinct compartment from its debuggee.
|
||||
freshCompartment: true,
|
||||
|
||||
wantGlobalProperties: [
|
||||
"AbortController",
|
||||
"atob",
|
||||
"btoa",
|
||||
"Blob",
|
||||
"ChromeUtils",
|
||||
"crypto",
|
||||
"CSS",
|
||||
"CSSRule",
|
||||
"DOMParser",
|
||||
"Element",
|
||||
"Event",
|
||||
"FileReader",
|
||||
"FormData",
|
||||
"Headers",
|
||||
"indexedDB",
|
||||
"InspectorUtils",
|
||||
"Node",
|
||||
"TextDecoder",
|
||||
"TextEncoder",
|
||||
"URL",
|
||||
"URLSearchParams",
|
||||
"Window",
|
||||
"XMLHttpRequest",
|
||||
],
|
||||
}));
|
||||
|
||||
const {
|
||||
AbortController,
|
||||
atob,
|
||||
btoa,
|
||||
Blob,
|
||||
ChromeUtils,
|
||||
crypto,
|
||||
CSS,
|
||||
CSSRule,
|
||||
DOMParser,
|
||||
Element,
|
||||
Event,
|
||||
FileReader,
|
||||
FormData,
|
||||
Headers,
|
||||
indexedDB,
|
||||
InspectorUtils,
|
||||
Node,
|
||||
TextDecoder,
|
||||
TextEncoder,
|
||||
URL,
|
||||
URLSearchParams,
|
||||
Window,
|
||||
XMLHttpRequest,
|
||||
} = debuggerSandbox;
|
||||
|
||||
/**
|
||||
* Defines a getter on a specified object that will be created upon first use.
|
||||
*
|
||||
|
@ -241,6 +182,14 @@ defineLazyGetter(exports.modules, "Debugger", () => {
|
|||
});
|
||||
|
||||
defineLazyGetter(exports.modules, "ChromeDebugger", () => {
|
||||
// Sandbox are memory expensive, so we should create as little as possible.
|
||||
const debuggerSandbox = Cu.Sandbox(systemPrincipal, {
|
||||
// This sandbox is used for the ChromeDebugger implementation.
|
||||
// As we want to load the `Debugger` API for debugging chrome contexts,
|
||||
// we have to ensure loading it in a distinct compartment from its debuggee.
|
||||
freshCompartment: true,
|
||||
});
|
||||
|
||||
const { addDebuggerToGlobal } = ChromeUtils.import(
|
||||
"resource://gre/modules/jsdebugger.jsm"
|
||||
);
|
||||
|
@ -255,10 +204,6 @@ defineLazyGetter(exports.modules, "xpcInspector", () => {
|
|||
// List of all custom globals exposed to devtools modules.
|
||||
// Changes here should be mirrored to devtools/.eslintrc.
|
||||
exports.globals = {
|
||||
AbortController,
|
||||
atob,
|
||||
Blob,
|
||||
btoa,
|
||||
CanonicalBrowsingContext,
|
||||
ChromeUtils,
|
||||
BrowsingContext,
|
||||
|
@ -266,20 +211,11 @@ exports.globals = {
|
|||
WindowGlobalParent,
|
||||
WindowGlobalChild,
|
||||
console,
|
||||
crypto,
|
||||
CSS,
|
||||
CSSRule,
|
||||
DOMParser,
|
||||
DOMPoint,
|
||||
DOMQuad,
|
||||
Event,
|
||||
NamedNodeMap,
|
||||
NodeFilter,
|
||||
DOMRect,
|
||||
Element,
|
||||
FileReader,
|
||||
FormData,
|
||||
Headers,
|
||||
IOUtils,
|
||||
isWorker: false,
|
||||
L10nRegistry,
|
||||
|
@ -292,17 +228,10 @@ exports.globals = {
|
|||
id: null,
|
||||
},
|
||||
Localization,
|
||||
Node,
|
||||
PathUtils,
|
||||
reportError: Cu.reportError,
|
||||
Services: Object.create(Services),
|
||||
StructuredCloneHolder,
|
||||
TextDecoder,
|
||||
TextEncoder,
|
||||
URL,
|
||||
URLSearchParams,
|
||||
Window,
|
||||
XMLHttpRequest,
|
||||
};
|
||||
// DevTools loader copy globals property descriptors on each module global
|
||||
// object so that we have to memoize them from here in order to instantiate each
|
||||
|
|
|
@ -98,12 +98,12 @@ exports.allocationTracker = function({
|
|||
let accept = !!location.match(/devtools/i);
|
||||
|
||||
// Also ignore the dedicated Sandbox used to spawn builtin-modules,
|
||||
// as well as its internal Sandbox used to fetch various platform globals.
|
||||
// as well as its internal ChromeDebugger Sandbox.
|
||||
// We ignore the global used by the dedicated loader used to load
|
||||
// the allocation-tracker module.
|
||||
if (
|
||||
ref == Cu.getGlobalForObject(builtinGlobal) ||
|
||||
ref == builtinGlobal.internalSandbox
|
||||
ref == Cu.getGlobalForObject(builtinGlobal.modules.ChromeDebugger)
|
||||
) {
|
||||
accept = false;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче