Bug 1727571 - [devtools] Prevent the allocation tracker to record its own modules. r=jdescottes

It was tracking the special sandbox we spawn for builtin-modules.js
as well as its internal sandbox used to fetch platform globals.

Differential Revision: https://phabricator.services.mozilla.com/D124174
This commit is contained in:
Alexandre Poirot 2021-09-01 16:18:28 +00:00
Родитель 8127145d8f
Коммит c644e2c255
2 изменённых файлов: 17 добавлений и 3 удалений

Просмотреть файл

@ -38,7 +38,7 @@ const {
// 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 = Cu.Sandbox(systemPrincipal, {
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.
@ -66,7 +66,7 @@ const debuggerSandbox = Cu.Sandbox(systemPrincipal, {
"URL",
"XMLHttpRequest",
],
});
}));
const {
AbortController,

Просмотреть файл

@ -82,14 +82,28 @@ exports.allocationTracker = function({
acceptGlobal = () => true;
} else if (watchDevToolsGlobals) {
// Only accept globals related to DevTools
const builtinGlobal = require("devtools/shared/builtin-modules");
acceptGlobal = g => {
// self-hosting-global crashes when trying to call unsafeDereference
if (g.class == "self-hosting-global") {
dump("TRACKER NEW GLOBAL: - : " + g.class + "\n");
return false;
}
const ref = g.unsafeDereference();
const location = Cu.getRealmLocation(ref);
const accept = !!location.match(/devtools/i);
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.
// We ignore the global used by the dedicated loader used to load
// the allocation-tracker module.
if (
ref == Cu.getGlobalForObject(builtinGlobal) ||
ref == builtinGlobal.internalSandbox
) {
accept = false;
}
dump(
"TRACKER NEW GLOBAL: " + (accept ? "+" : "-") + " : " + location + "\n"
);