eager-function-allowlist.js (1259B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 "use strict"; 6 7 const idlPureAllowlist = require("resource://devtools/server/actors/webconsole/webidl-pure-allowlist.js"); 8 9 const natives = []; 10 if (Components.Constructor && Cu) { 11 const sandbox = Cu.Sandbox( 12 Components.Constructor("@mozilla.org/systemprincipal;1", "nsIPrincipal")(), 13 { 14 invisibleToDebugger: true, 15 wantGlobalProperties: Object.keys(idlPureAllowlist), 16 } 17 ); 18 19 function maybePush(maybeFunc) { 20 if (maybeFunc) { 21 natives.push(maybeFunc); 22 } 23 } 24 25 function collectMethods(obj, methods) { 26 for (const name of methods) { 27 maybePush(obj[name]); 28 } 29 } 30 31 for (const [iface, ifaceData] of Object.entries(idlPureAllowlist)) { 32 const ctor = sandbox[iface]; 33 if (!ctor) { 34 continue; 35 } 36 37 if ("static" in ifaceData) { 38 collectMethods(ctor, ifaceData.static); 39 } 40 41 if ("prototype" in ifaceData) { 42 const proto = ctor.prototype; 43 if (!proto) { 44 continue; 45 } 46 47 collectMethods(proto, ifaceData.prototype); 48 } 49 } 50 } 51 52 module.exports = { natives };