Skip to content

Commit

Permalink
Bug 1832769 - Move ensureSideEffectFreeGetters into lazy getter r=dev…
Browse files Browse the repository at this point in the history
…tools-reviewers,nchevobbe

Depends on D178884

Differential Revision: https://phabricator.services.mozilla.com/D178885
  • Loading branch information
arai-a committed May 26, 2023
1 parent bcd1fe1 commit b129138
Showing 1 changed file with 16 additions and 26 deletions.
42 changes: 16 additions & 26 deletions devtools/shared/DevToolsUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,21 @@ ChromeUtils.defineModuleGetter(
"resource://gre/modules/ObjectUtils.jsm"
);

ChromeUtils.defineLazyGetter(lazy, "eagerEcmaAllowlist", () => {
return require("resource://devtools/server/actors/webconsole/eager-ecma-allowlist.js");
// Native getters which are considered to be side effect free.
ChromeUtils.defineLazyGetter(lazy, "sideEffectFreeGetters", () => {
const {
getters,
} = require("resource://devtools/server/actors/webconsole/eager-ecma-allowlist.js");

const map = new Map();
for (const n of getters) {
if (!map.has(n.name)) {
map.set(n.name, []);
}
map.get(n.name).push(n);
}

return map;
});

// Using this name lets the eslint plugin know about lazy defines in
Expand Down Expand Up @@ -270,28 +283,6 @@ exports.isSafeDebuggerObject = function (obj) {
return true;
};

// Native getters which are considered to be side effect free.
let gSideEffectFreeGetters; // string => Array(Function)

/**
* Generate gSideEffectFreeGetters map.
*/
function ensureSideEffectFreeGetters() {
if (gSideEffectFreeGetters) {
return;
}

const map = new Map();
for (const n of lazy.eagerEcmaAllowlist.getters) {
if (!map.has(n.name)) {
map.set(n.name, []);
}
map.get(n.name).push(n);
}

gSideEffectFreeGetters = map;
}

/**
* Determines if a descriptor has a getter which doesn't call into JavaScript.
*
Expand Down Expand Up @@ -331,8 +322,7 @@ exports.hasSafeGetter = function (desc) {
}

// Apply explicit allowlist.
ensureSideEffectFreeGetters();
const natives = gSideEffectFreeGetters.get(fn.name);
const natives = lazy.sideEffectFreeGetters.get(fn.name);
return natives && natives.some(n => fn.isSameNative(n));
};

Expand Down

0 comments on commit b129138

Please sign in to comment.