1 | 'use strict';
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | const internals = {};
|
9 |
|
10 |
|
11 | exports.detect = function (customGlobals) {
|
12 |
|
13 | const whitelist = {
|
14 | _labScriptRun: true,
|
15 |
|
16 |
|
17 | setTimeout: true,
|
18 | setInterval: true,
|
19 | setImmediate: true,
|
20 | clearTimeout: true,
|
21 | clearInterval: true,
|
22 | clearImmediate: true,
|
23 | console: true,
|
24 | Buffer: true,
|
25 | process: true,
|
26 | global: true,
|
27 | GLOBAL: true,
|
28 | root: true,
|
29 | constructor: true,
|
30 | ArrayBuffer: true,
|
31 | Int8Array: true,
|
32 | Uint8Array: true,
|
33 | Uint8ClampedArray: true,
|
34 | Int16Array: true,
|
35 | Uint16Array: true,
|
36 | Int32Array: true,
|
37 | Uint32Array: true,
|
38 | Float32Array: true,
|
39 | Float64Array: true,
|
40 | DataView: true,
|
41 | __$$labCov: true,
|
42 | gc: true,
|
43 |
|
44 | // Non-Enumerable globals
|
45 | Array: true,
|
46 | isNaN: true,
|
47 | ReferenceError: true,
|
48 | Number: true,
|
49 | RangeError: true,
|
50 | EvalError: true,
|
51 | Function: true,
|
52 | isFinite: true,
|
53 | Object: true,
|
54 | undefined: true,
|
55 | Date: true,
|
56 | SyntaxError: true,
|
57 | String: true,
|
58 | eval: true,
|
59 | parseFloat: true,
|
60 | unescape: true,
|
61 | Error: true,
|
62 | encodeURI: true,
|
63 | NaN: true,
|
64 | RegExp: true,
|
65 | encodeURIComponent: true,
|
66 | Math: true,
|
67 | decodeURI: true,
|
68 | parseInt: true,
|
69 | Infinity: true,
|
70 | escape: true,
|
71 | decodeURIComponent: true,
|
72 | JSON: true,
|
73 | TypeError: true,
|
74 | URIError: true,
|
75 | Boolean: true,
|
76 | Intl: true,
|
77 | Map: true,
|
78 | Promise: true,
|
79 | Set: true,
|
80 | Symbol: true,
|
81 | WeakMap: true,
|
82 | WeakSet: true
|
83 | };
|
84 |
|
85 | if (customGlobals) {
|
86 | for (let i = 0; i < customGlobals.length; ++i) {
|
87 | whitelist[customGlobals[i]] = true;
|
88 | }
|
89 | }
|
90 |
|
91 |
|
92 | if (global.Atomics) {
|
93 | whitelist.Atomics = true;
|
94 | }
|
95 |
|
96 |
|
97 | if (global.Proxy) {
|
98 | whitelist.Proxy = true;
|
99 | }
|
100 |
|
101 | if (global.Reflect) {
|
102 | whitelist.Reflect = true;
|
103 | }
|
104 |
|
105 |
|
106 | if (global.SharedArrayBuffer) {
|
107 | whitelist.SharedArrayBuffer = true;
|
108 | }
|
109 |
|
110 |
|
111 |
|
112 | if (global.WebAssembly) {
|
113 |
|
114 | whitelist.WebAssembly = true;
|
115 | }
|
116 |
|
117 |
|
118 | if (global.URL) {
|
119 | whitelist.URL = true;
|
120 | whitelist.URLSearchParams = true;
|
121 | }
|
122 |
|
123 |
|
124 |
|
125 | if (global.TextEncoder) {
|
126 | whitelist.TextEncoder = true;
|
127 | }
|
128 |
|
129 |
|
130 |
|
131 | if (global.TextDecoder) {
|
132 | whitelist.TextDecoder = true;
|
133 | }
|
134 |
|
135 |
|
136 |
|
137 | if (global.BigInt) {
|
138 | whitelist.BigInt = true;
|
139 | whitelist.BigUint64Array = true;
|
140 | whitelist.BigInt64Array = true;
|
141 | }
|
142 |
|
143 |
|
144 | if (global.DTRACE_HTTP_SERVER_RESPONSE) {
|
145 | whitelist.DTRACE_HTTP_SERVER_RESPONSE = true;
|
146 | whitelist.DTRACE_HTTP_SERVER_REQUEST = true;
|
147 | whitelist.DTRACE_HTTP_CLIENT_RESPONSE = true;
|
148 | whitelist.DTRACE_HTTP_CLIENT_REQUEST = true;
|
149 | whitelist.DTRACE_NET_STREAM_END = true;
|
150 | whitelist.DTRACE_NET_SERVER_CONNECTION = true;
|
151 | whitelist.DTRACE_NET_SOCKET_READ = true;
|
152 | whitelist.DTRACE_NET_SOCKET_WRITE = true;
|
153 | }
|
154 |
|
155 | if (global.COUNTER_NET_SERVER_CONNECTION) {
|
156 | whitelist.COUNTER_NET_SERVER_CONNECTION = true;
|
157 | whitelist.COUNTER_NET_SERVER_CONNECTION_CLOSE = true;
|
158 | whitelist.COUNTER_HTTP_SERVER_REQUEST = true;
|
159 | whitelist.COUNTER_HTTP_SERVER_RESPONSE = true;
|
160 | whitelist.COUNTER_HTTP_CLIENT_REQUEST = true;
|
161 | whitelist.COUNTER_HTTP_CLIENT_RESPONSE = true;
|
162 | }
|
163 |
|
164 |
|
165 | if ('queueMicrotask' in global) {
|
166 | whitelist.queueMicrotask = true;
|
167 | }
|
168 |
|
169 |
|
170 | const leaks = [];
|
171 | const globals = Object.getOwnPropertyNames(global);
|
172 | for (let i = 0; i < globals.length; ++i) {
|
173 | if (!whitelist[globals[i]] &&
|
174 | global[globals[i]] !== global) {
|
175 |
|
176 | leaks.push(globals[i]);
|
177 | }
|
178 | }
|
179 |
|
180 | return leaks;
|
181 | };
|