1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
/* 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";
const { CC, Cu } = require("chrome");
const idlPureAllowlist = require("devtools/server/actors/webconsole/webidl-pure-allowlist");
// TODO: Bug 1616013 - Move more of these to be part of the pure list.
const customEagerFunctions = {
Document: [
["prototype", "getSelection"],
["prototype", "hasStorageAccess"],
],
Range: [
["prototype", "isPointInRange"],
["prototype", "comparePoint"],
["prototype", "intersectsNode"],
// These two functions aren't pure because they do trigger layout when
// they are called, but in the context of eager evaluation, that should be
// a totally fine thing to do.
["prototype", "getClientRects"],
["prototype", "getBoundingClientRect"],
],
Selection: [
["prototype", "getRangeAt"],
["prototype", "containsNode"],
],
};
const mergedFunctions = {};
for (const [key, values] of Object.entries(idlPureAllowlist)) {
mergedFunctions[key] = [...values];
}
for (const [key, values] of Object.entries(customEagerFunctions)) {
if (!mergedFunctions[key]) {
mergedFunctions[key] = [];
}
mergedFunctions[key].push(...values);
}
const natives = [];
if (CC && Cu) {
const sandbox = Cu.Sandbox(
CC("@mozilla.org/systemprincipal;1", "nsIPrincipal")(),
{
invisibleToDebugger: true,
wantGlobalProperties: Object.keys(mergedFunctions),
}
);
for (const iface of Object.keys(mergedFunctions)) {
for (const path of mergedFunctions[iface]) {
let value = sandbox;
for (const part of [iface, ...path]) {
value = value[part];
if (!value) {
break;
}
}
if (value) {
natives.push(value);
}
}
}
}
module.exports = natives;
|