ses 0.14.2 → 0.15.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +64 -0
- package/NEWS.md +60 -1
- package/README.md +0 -1
- package/dist/lockdown.cjs +1769 -992
- package/dist/lockdown.mjs +1769 -992
- package/dist/lockdown.umd.js +1769 -992
- package/dist/lockdown.umd.min.js +1 -1
- package/dist/ses.cjs +1769 -992
- package/dist/ses.mjs +1769 -992
- package/dist/ses.umd.js +1769 -992
- package/dist/ses.umd.min.js +1 -1
- package/index.d.ts +2 -1
- package/index.js +6 -13
- package/package.json +24 -11
- package/src/commons.js +44 -9
- package/src/compartment-evaluate.js +102 -0
- package/src/compartment-shim.js +78 -106
- package/src/enable-property-overrides.js +5 -4
- package/src/enablements.js +7 -2
- package/src/environment-options.js +125 -0
- package/src/error/assert.js +51 -39
- package/src/error/console.js +32 -14
- package/src/error/fatal-assert.js +2 -0
- package/src/error/stringify-utils.js +26 -3
- package/src/error/tame-console.js +12 -4
- package/src/error/tame-error-constructor.js +18 -17
- package/src/error/tame-v8-error-constructor.js +30 -14
- package/src/get-anonymous-intrinsics.js +11 -8
- package/src/get-source-url.js +4 -4
- package/src/global-object.js +33 -26
- package/src/intrinsics.js +76 -67
- package/src/lockdown-shim.js +111 -119
- package/src/make-eval-function.js +3 -5
- package/src/make-function-constructor.js +3 -4
- package/src/make-safe-evaluator.js +117 -0
- package/src/module-instance.js +31 -17
- package/src/module-link.js +11 -4
- package/src/module-load.js +169 -44
- package/src/module-proxy.js +12 -4
- package/src/scope-constants.js +6 -3
- package/src/scope-handler.js +41 -17
- package/src/tame-date-constructor.js +8 -2
- package/src/tame-domains.js +46 -0
- package/src/tame-function-constructors.js +1 -0
- package/src/tame-locale-methods.js +6 -6
- package/src/tame-math-object.js +2 -2
- package/src/tame-regexp-constructor.js +7 -7
- package/src/transforms.js +13 -6
- package/src/whitelist-intrinsics.js +9 -3
- package/src/evaluate.js +0 -98
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
2
|
+
FERAL_ERROR,
|
|
3
|
+
TypeError,
|
|
3
4
|
apply,
|
|
4
5
|
construct,
|
|
5
6
|
defineProperties,
|
|
@@ -11,7 +12,7 @@ import { tameV8ErrorConstructor } from './tame-v8-error-constructor.js';
|
|
|
11
12
|
|
|
12
13
|
// Present on at least FF. Proposed by Error-proposal. Not on SES whitelist
|
|
13
14
|
// so grab it before it is removed.
|
|
14
|
-
const stackDesc = getOwnPropertyDescriptor(
|
|
15
|
+
const stackDesc = getOwnPropertyDescriptor(FERAL_ERROR.prototype, 'stack');
|
|
15
16
|
const stackGetter = stackDesc && stackDesc.get;
|
|
16
17
|
|
|
17
18
|
// Use concise methods to obtain named functions without constructors.
|
|
@@ -32,29 +33,29 @@ export default function tameErrorConstructor(
|
|
|
32
33
|
stackFiltering = 'concise',
|
|
33
34
|
) {
|
|
34
35
|
if (errorTaming !== 'safe' && errorTaming !== 'unsafe') {
|
|
35
|
-
throw new
|
|
36
|
+
throw new TypeError(`unrecognized errorTaming ${errorTaming}`);
|
|
36
37
|
}
|
|
37
38
|
if (stackFiltering !== 'concise' && stackFiltering !== 'verbose') {
|
|
38
|
-
throw new
|
|
39
|
+
throw new TypeError(`unrecognized stackFiltering ${stackFiltering}`);
|
|
39
40
|
}
|
|
40
|
-
const
|
|
41
|
-
const ErrorPrototype = OriginalError.prototype;
|
|
41
|
+
const ErrorPrototype = FERAL_ERROR.prototype;
|
|
42
42
|
|
|
43
43
|
const platform =
|
|
44
|
-
typeof
|
|
44
|
+
typeof FERAL_ERROR.captureStackTrace === 'function' ? 'v8' : 'unknown';
|
|
45
|
+
const { captureStackTrace: originalCaptureStackTrace } = FERAL_ERROR;
|
|
45
46
|
|
|
46
47
|
const makeErrorConstructor = (_ = {}) => {
|
|
47
48
|
// eslint-disable-next-line no-shadow
|
|
48
49
|
const ResultError = function Error(...rest) {
|
|
49
50
|
let error;
|
|
50
51
|
if (new.target === undefined) {
|
|
51
|
-
error = apply(
|
|
52
|
+
error = apply(FERAL_ERROR, this, rest);
|
|
52
53
|
} else {
|
|
53
|
-
error = construct(
|
|
54
|
+
error = construct(FERAL_ERROR, rest, new.target);
|
|
54
55
|
}
|
|
55
56
|
if (platform === 'v8') {
|
|
56
57
|
// TODO Likely expensive!
|
|
57
|
-
|
|
58
|
+
apply(originalCaptureStackTrace, FERAL_ERROR, [error, ResultError]);
|
|
58
59
|
}
|
|
59
60
|
return error;
|
|
60
61
|
};
|
|
@@ -99,9 +100,9 @@ export default function tameErrorConstructor(
|
|
|
99
100
|
defineProperties(InitialError, {
|
|
100
101
|
stackTraceLimit: {
|
|
101
102
|
get() {
|
|
102
|
-
if (typeof
|
|
103
|
-
//
|
|
104
|
-
return
|
|
103
|
+
if (typeof FERAL_ERROR.stackTraceLimit === 'number') {
|
|
104
|
+
// FERAL_ERROR.stackTraceLimit is only on v8
|
|
105
|
+
return FERAL_ERROR.stackTraceLimit;
|
|
105
106
|
}
|
|
106
107
|
return undefined;
|
|
107
108
|
},
|
|
@@ -113,9 +114,9 @@ export default function tameErrorConstructor(
|
|
|
113
114
|
// harmless seems the safer option.
|
|
114
115
|
return;
|
|
115
116
|
}
|
|
116
|
-
if (typeof
|
|
117
|
-
//
|
|
118
|
-
|
|
117
|
+
if (typeof FERAL_ERROR.stackTraceLimit === 'number') {
|
|
118
|
+
// FERAL_ERROR.stackTraceLimit is only on v8
|
|
119
|
+
FERAL_ERROR.stackTraceLimit = newLimit;
|
|
119
120
|
// We place the useless return on the next line to ensure
|
|
120
121
|
// that anything we place after the if in the future only
|
|
121
122
|
// happens if the then-case does not.
|
|
@@ -148,7 +149,7 @@ export default function tameErrorConstructor(
|
|
|
148
149
|
let initialGetStackString = tamedMethods.getStackString;
|
|
149
150
|
if (platform === 'v8') {
|
|
150
151
|
initialGetStackString = tameV8ErrorConstructor(
|
|
151
|
-
|
|
152
|
+
FERAL_ERROR,
|
|
152
153
|
InitialError,
|
|
153
154
|
errorTaming,
|
|
154
155
|
stackFiltering,
|
|
@@ -1,15 +1,22 @@
|
|
|
1
1
|
import {
|
|
2
2
|
WeakMap,
|
|
3
3
|
WeakSet,
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
apply,
|
|
5
|
+
arrayFilter,
|
|
6
|
+
arrayJoin,
|
|
7
|
+
arrayMap,
|
|
8
|
+
arraySlice,
|
|
9
9
|
create,
|
|
10
10
|
defineProperties,
|
|
11
11
|
fromEntries,
|
|
12
12
|
reflectSet,
|
|
13
|
+
regexpExec,
|
|
14
|
+
regexpTest,
|
|
15
|
+
weakmapGet,
|
|
16
|
+
weakmapHas,
|
|
17
|
+
weakmapSet,
|
|
18
|
+
weaksetAdd,
|
|
19
|
+
weaksetHas,
|
|
13
20
|
} from '../commons.js';
|
|
14
21
|
|
|
15
22
|
// Whitelist names from https://v8.dev/docs/stack-trace-api
|
|
@@ -44,12 +51,15 @@ const safeV8CallSiteMethodNames = [
|
|
|
44
51
|
// TODO this is a ridiculously expensive way to attenuate callsites.
|
|
45
52
|
// Before that matters, we should switch to a reasonable representation.
|
|
46
53
|
const safeV8CallSiteFacet = callSite => {
|
|
47
|
-
const methodEntry = name =>
|
|
48
|
-
|
|
54
|
+
const methodEntry = name => {
|
|
55
|
+
const method = callSite[name];
|
|
56
|
+
return [name, () => apply(method, callSite, [])];
|
|
57
|
+
};
|
|
58
|
+
const o = fromEntries(arrayMap(safeV8CallSiteMethodNames, methodEntry));
|
|
49
59
|
return create(o, {});
|
|
50
60
|
};
|
|
51
61
|
|
|
52
|
-
const safeV8SST = sst => sst
|
|
62
|
+
const safeV8SST = sst => arrayMap(sst, safeV8CallSiteFacet);
|
|
53
63
|
|
|
54
64
|
// If it has `/node_modules/` anywhere in it, on Node it is likely
|
|
55
65
|
// to be a dependent package of the current package, and so to
|
|
@@ -93,7 +103,7 @@ export const filterFileName = fileName => {
|
|
|
93
103
|
return true;
|
|
94
104
|
}
|
|
95
105
|
for (const filter of FILENAME_CENSORS) {
|
|
96
|
-
if (filter
|
|
106
|
+
if (regexpTest(filter, fileName)) {
|
|
97
107
|
return false;
|
|
98
108
|
}
|
|
99
109
|
}
|
|
@@ -141,9 +151,9 @@ const CALLSITE_PATTERNS = [
|
|
|
141
151
|
// TODO Move so that it applies not just to v8.
|
|
142
152
|
export const shortenCallSiteString = callSiteString => {
|
|
143
153
|
for (const filter of CALLSITE_PATTERNS) {
|
|
144
|
-
const match = filter
|
|
154
|
+
const match = regexpExec(filter, callSiteString);
|
|
145
155
|
if (match) {
|
|
146
|
-
return match
|
|
156
|
+
return arrayJoin(arraySlice(match, 1), '');
|
|
147
157
|
}
|
|
148
158
|
}
|
|
149
159
|
return callSiteString;
|
|
@@ -155,11 +165,14 @@ export const tameV8ErrorConstructor = (
|
|
|
155
165
|
errorTaming,
|
|
156
166
|
stackFiltering,
|
|
157
167
|
) => {
|
|
168
|
+
const originalCaptureStackTrace = OriginalError.captureStackTrace;
|
|
169
|
+
|
|
158
170
|
// const callSiteFilter = _callSite => true;
|
|
159
171
|
const callSiteFilter = callSite => {
|
|
160
172
|
if (stackFiltering === 'verbose') {
|
|
161
173
|
return true;
|
|
162
174
|
}
|
|
175
|
+
// eslint-disable-next-line @endo/no-polymorphic-call
|
|
163
176
|
return filterFileName(callSite.getFileName());
|
|
164
177
|
};
|
|
165
178
|
|
|
@@ -172,7 +185,10 @@ export const tameV8ErrorConstructor = (
|
|
|
172
185
|
};
|
|
173
186
|
|
|
174
187
|
const stackStringFromSST = (_error, sst) =>
|
|
175
|
-
|
|
188
|
+
arrayJoin(
|
|
189
|
+
arrayMap(arrayFilter(sst, callSiteFilter), callSiteStringifier),
|
|
190
|
+
'',
|
|
191
|
+
);
|
|
176
192
|
|
|
177
193
|
// Mapping from error instance to the structured stack trace capturing the
|
|
178
194
|
// stack for that instance.
|
|
@@ -186,9 +202,9 @@ export const tameV8ErrorConstructor = (
|
|
|
186
202
|
// but instead calls the real one, if no other cutoff is provided,
|
|
187
203
|
// we cut this one off.
|
|
188
204
|
captureStackTrace(error, optFn = tamedMethods.captureStackTrace) {
|
|
189
|
-
if (typeof
|
|
205
|
+
if (typeof originalCaptureStackTrace === 'function') {
|
|
190
206
|
// OriginalError.captureStackTrace is only on v8
|
|
191
|
-
OriginalError
|
|
207
|
+
apply(originalCaptureStackTrace, OriginalError, [error, optFn]);
|
|
192
208
|
return;
|
|
193
209
|
}
|
|
194
210
|
reflectSet(error, 'stack', '');
|
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
import {
|
|
2
|
-
Array,
|
|
3
2
|
FERAL_FUNCTION,
|
|
4
3
|
Float32Array,
|
|
5
4
|
Map,
|
|
6
|
-
RegExp,
|
|
7
5
|
Set,
|
|
8
6
|
String,
|
|
9
7
|
getOwnPropertyDescriptor,
|
|
10
8
|
getPrototypeOf,
|
|
11
|
-
|
|
9
|
+
iterateArray,
|
|
10
|
+
iterateMap,
|
|
11
|
+
iterateSet,
|
|
12
|
+
iterateString,
|
|
13
|
+
matchAllRegExp,
|
|
12
14
|
matchAllSymbol,
|
|
15
|
+
regexpPrototype,
|
|
13
16
|
} from './commons.js';
|
|
14
17
|
import { InertCompartment } from './compartment-shim.js';
|
|
15
18
|
|
|
@@ -48,19 +51,19 @@ export const getAnonymousIntrinsics = () => {
|
|
|
48
51
|
// 21.1.5.2 The %StringIteratorPrototype% Object
|
|
49
52
|
|
|
50
53
|
// eslint-disable-next-line no-new-wrappers
|
|
51
|
-
const StringIteratorObject = new String()
|
|
54
|
+
const StringIteratorObject = iterateString(new String());
|
|
52
55
|
const StringIteratorPrototype = getPrototypeOf(StringIteratorObject);
|
|
53
56
|
|
|
54
57
|
// 21.2.7.1 The %RegExpStringIteratorPrototype% Object
|
|
55
58
|
const RegExpStringIterator =
|
|
56
|
-
|
|
59
|
+
regexpPrototype[matchAllSymbol] && matchAllRegExp(/./);
|
|
57
60
|
const RegExpStringIteratorPrototype =
|
|
58
61
|
RegExpStringIterator && getPrototypeOf(RegExpStringIterator);
|
|
59
62
|
|
|
60
63
|
// 22.1.5.2 The %ArrayIteratorPrototype% Object
|
|
61
64
|
|
|
62
65
|
// eslint-disable-next-line no-array-constructor
|
|
63
|
-
const ArrayIteratorObject =
|
|
66
|
+
const ArrayIteratorObject = iterateArray([]);
|
|
64
67
|
const ArrayIteratorPrototype = getPrototypeOf(ArrayIteratorObject);
|
|
65
68
|
|
|
66
69
|
// 22.2.1 The %TypedArray% Intrinsic Object
|
|
@@ -69,12 +72,12 @@ export const getAnonymousIntrinsics = () => {
|
|
|
69
72
|
|
|
70
73
|
// 23.1.5.2 The %MapIteratorPrototype% Object
|
|
71
74
|
|
|
72
|
-
const MapIteratorObject = new Map()
|
|
75
|
+
const MapIteratorObject = iterateMap(new Map());
|
|
73
76
|
const MapIteratorPrototype = getPrototypeOf(MapIteratorObject);
|
|
74
77
|
|
|
75
78
|
// 23.2.5.2 The %SetIteratorPrototype% Object
|
|
76
79
|
|
|
77
|
-
const SetIteratorObject = new Set()
|
|
80
|
+
const SetIteratorObject = iterateSet(new Set());
|
|
78
81
|
const SetIteratorPrototype = getPrototypeOf(SetIteratorObject);
|
|
79
82
|
|
|
80
83
|
// 25.1.2 The %IteratorPrototype% Object
|
package/src/get-source-url.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { FERAL_REG_EXP, regexpExec, stringSlice } from './commons.js';
|
|
2
2
|
|
|
3
3
|
// Captures a key and value of the form #key=value or @key=value
|
|
4
4
|
const sourceMetaEntryRegExp =
|
|
@@ -9,7 +9,7 @@ const sourceMetaEntryRegExp =
|
|
|
9
9
|
// On account of the mechanics of regular expressions, scanning from the end
|
|
10
10
|
// does not allow us to capture every pair, so getSourceURL must capture and
|
|
11
11
|
// trim until there are no matching comments.
|
|
12
|
-
const sourceMetaEntriesRegExp = new
|
|
12
|
+
const sourceMetaEntriesRegExp = new FERAL_REG_EXP(
|
|
13
13
|
`(?:\\s*//${sourceMetaEntryRegExp}|/\\*${sourceMetaEntryRegExp}\\s*\\*/)\\s*$`,
|
|
14
14
|
);
|
|
15
15
|
|
|
@@ -24,11 +24,11 @@ export const getSourceURL = src => {
|
|
|
24
24
|
// So, we sublimate the comments out of the source until no source or no
|
|
25
25
|
// comments remain.
|
|
26
26
|
while (src.length > 0) {
|
|
27
|
-
const match = sourceMetaEntriesRegExp
|
|
27
|
+
const match = regexpExec(sourceMetaEntriesRegExp, src);
|
|
28
28
|
if (match === null) {
|
|
29
29
|
break;
|
|
30
30
|
}
|
|
31
|
-
src = src
|
|
31
|
+
src = stringSlice(src, 0, src.length - match[0].length);
|
|
32
32
|
|
|
33
33
|
// We skip $0 since it contains the entire match.
|
|
34
34
|
// The match contains four capture groups,
|
package/src/global-object.js
CHANGED
|
@@ -4,29 +4,14 @@ import { makeFunctionConstructor } from './make-function-constructor.js';
|
|
|
4
4
|
import { constantProperties, universalPropertyNames } from './whitelist.js';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* (
|
|
10
|
-
* `
|
|
11
|
-
* `sharedGlobalPropertyNames`.
|
|
7
|
+
* setGlobalObjectConstantProperties()
|
|
8
|
+
* Initializes a new global object using a process similar to ECMA specifications
|
|
9
|
+
* (SetDefaultGlobalBindings). This process is split between this function and
|
|
10
|
+
* `setGlobalObjectMutableProperties`.
|
|
12
11
|
*
|
|
13
12
|
* @param {Object} globalObject
|
|
14
|
-
* @param {Object} intrinsics
|
|
15
|
-
* @param {Object} newGlobalPropertyNames
|
|
16
|
-
* @param {Function} makeCompartmentConstructor
|
|
17
|
-
* @param {Object} compartmentPrototype
|
|
18
|
-
* @param {Object} [options]
|
|
19
|
-
* @param {Array<Transform>} [options.globalTransforms]
|
|
20
|
-
* @param {(Object) => void} [options.markVirtualizedNativeFunction]
|
|
21
13
|
*/
|
|
22
|
-
export const
|
|
23
|
-
globalObject,
|
|
24
|
-
intrinsics,
|
|
25
|
-
newGlobalPropertyNames,
|
|
26
|
-
makeCompartmentConstructor,
|
|
27
|
-
compartmentPrototype,
|
|
28
|
-
{ globalTransforms, markVirtualizedNativeFunction },
|
|
29
|
-
) => {
|
|
14
|
+
export const setGlobalObjectConstantProperties = globalObject => {
|
|
30
15
|
for (const [name, constant] of entries(constantProperties)) {
|
|
31
16
|
defineProperty(globalObject, name, {
|
|
32
17
|
value: constant,
|
|
@@ -35,7 +20,33 @@ export const initGlobalObject = (
|
|
|
35
20
|
configurable: false,
|
|
36
21
|
});
|
|
37
22
|
}
|
|
23
|
+
};
|
|
38
24
|
|
|
25
|
+
/**
|
|
26
|
+
* setGlobalObjectMutableProperties()
|
|
27
|
+
* Create new global object using a process similar to ECMA specifications
|
|
28
|
+
* (portions of SetRealmGlobalObject and SetDefaultGlobalBindings).
|
|
29
|
+
* `newGlobalPropertyNames` should be either `initialGlobalPropertyNames` or
|
|
30
|
+
* `sharedGlobalPropertyNames`.
|
|
31
|
+
*
|
|
32
|
+
* @param {Object} globalObject
|
|
33
|
+
* @param {Object} param1
|
|
34
|
+
* @param {Object} param1.intrinsics
|
|
35
|
+
* @param {Object} param1.newGlobalPropertyNames
|
|
36
|
+
* @param {Function} param1.makeCompartmentConstructor
|
|
37
|
+
* @param {(string, Object?) => any} param1.safeEvaluate
|
|
38
|
+
* @param {(Object) => void} param1.markVirtualizedNativeFunction
|
|
39
|
+
*/
|
|
40
|
+
export const setGlobalObjectMutableProperties = (
|
|
41
|
+
globalObject,
|
|
42
|
+
{
|
|
43
|
+
intrinsics,
|
|
44
|
+
newGlobalPropertyNames,
|
|
45
|
+
makeCompartmentConstructor,
|
|
46
|
+
safeEvaluate,
|
|
47
|
+
markVirtualizedNativeFunction,
|
|
48
|
+
},
|
|
49
|
+
) => {
|
|
39
50
|
for (const [name, intrinsicName] of entries(universalPropertyNames)) {
|
|
40
51
|
if (objectHasOwnProperty(intrinsics, intrinsicName)) {
|
|
41
52
|
defineProperty(globalObject, name, {
|
|
@@ -60,12 +71,8 @@ export const initGlobalObject = (
|
|
|
60
71
|
|
|
61
72
|
const perCompartmentGlobals = {
|
|
62
73
|
globalThis: globalObject,
|
|
63
|
-
eval: makeEvalFunction(
|
|
64
|
-
|
|
65
|
-
}),
|
|
66
|
-
Function: makeFunctionConstructor(globalObject, {
|
|
67
|
-
globalTransforms,
|
|
68
|
-
}),
|
|
74
|
+
eval: makeEvalFunction(safeEvaluate),
|
|
75
|
+
Function: makeFunctionConstructor(safeEvaluate),
|
|
69
76
|
};
|
|
70
77
|
|
|
71
78
|
perCompartmentGlobals.Compartment = makeCompartmentConstructor(
|
package/src/intrinsics.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
|
+
TypeError,
|
|
2
3
|
WeakSet,
|
|
3
|
-
|
|
4
|
-
Object,
|
|
4
|
+
arrayFilter,
|
|
5
5
|
defineProperty,
|
|
6
6
|
entries,
|
|
7
7
|
freeze,
|
|
@@ -9,9 +9,10 @@ import {
|
|
|
9
9
|
getOwnPropertyDescriptors,
|
|
10
10
|
globalThis,
|
|
11
11
|
is,
|
|
12
|
+
isObject,
|
|
12
13
|
objectHasOwnProperty,
|
|
13
14
|
values,
|
|
14
|
-
|
|
15
|
+
weaksetHas,
|
|
15
16
|
} from './commons.js';
|
|
16
17
|
|
|
17
18
|
import {
|
|
@@ -40,7 +41,7 @@ function initProperty(obj, name, desc) {
|
|
|
40
41
|
preDesc.enumerable !== desc.enumerable ||
|
|
41
42
|
preDesc.configurable !== desc.configurable
|
|
42
43
|
) {
|
|
43
|
-
throw new
|
|
44
|
+
throw new TypeError(`Conflicting definitions of ${name}`);
|
|
44
45
|
}
|
|
45
46
|
}
|
|
46
47
|
defineProperty(obj, name, desc);
|
|
@@ -72,68 +73,78 @@ export const makeIntrinsicsCollector = () => {
|
|
|
72
73
|
const intrinsics = { __proto__: null };
|
|
73
74
|
let pseudoNatives;
|
|
74
75
|
|
|
75
|
-
const
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
}
|
|
97
|
-
const namePrototype = permit.prototype;
|
|
98
|
-
if (!namePrototype) {
|
|
99
|
-
throw new Error(`${name}.prototype property not whitelisted`);
|
|
100
|
-
}
|
|
101
|
-
if (
|
|
102
|
-
typeof namePrototype !== 'string' ||
|
|
103
|
-
!objectHasOwnProperty(whitelist, namePrototype)
|
|
104
|
-
) {
|
|
105
|
-
throw new Error(`Unrecognized ${name}.prototype whitelist entry`);
|
|
106
|
-
}
|
|
107
|
-
const intrinsicPrototype = intrinsic.prototype;
|
|
108
|
-
if (objectHasOwnProperty(intrinsics, namePrototype)) {
|
|
109
|
-
if (intrinsics[namePrototype] !== intrinsicPrototype) {
|
|
110
|
-
throw new Error(`Conflicting bindings of ${namePrototype}`);
|
|
111
|
-
}
|
|
112
|
-
// eslint-disable-next-line no-continue
|
|
113
|
-
continue;
|
|
114
|
-
}
|
|
115
|
-
intrinsics[namePrototype] = intrinsicPrototype;
|
|
76
|
+
const addIntrinsics = newIntrinsics => {
|
|
77
|
+
initProperties(intrinsics, getOwnPropertyDescriptors(newIntrinsics));
|
|
78
|
+
};
|
|
79
|
+
freeze(addIntrinsics);
|
|
80
|
+
|
|
81
|
+
// For each intrinsic, if it has a `.prototype` property, use the
|
|
82
|
+
// whitelist to find out the intrinsic name for that prototype and add it
|
|
83
|
+
// to the intrinsics.
|
|
84
|
+
const completePrototypes = () => {
|
|
85
|
+
for (const [name, intrinsic] of entries(intrinsics)) {
|
|
86
|
+
if (!isObject(intrinsic)) {
|
|
87
|
+
// eslint-disable-next-line no-continue
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
if (!objectHasOwnProperty(intrinsic, 'prototype')) {
|
|
91
|
+
// eslint-disable-next-line no-continue
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
const permit = whitelist[name];
|
|
95
|
+
if (typeof permit !== 'object') {
|
|
96
|
+
throw new TypeError(`Expected permit object at whitelist.${name}`);
|
|
116
97
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
pseudoNatives = new WeakSet(arrayFilter(values(intrinsics), isFunction));
|
|
121
|
-
return intrinsics;
|
|
122
|
-
},
|
|
123
|
-
isPseudoNative(obj) {
|
|
124
|
-
if (!pseudoNatives) {
|
|
125
|
-
throw new Error(
|
|
126
|
-
'isPseudoNative can only be called after finalIntrinsics',
|
|
127
|
-
);
|
|
98
|
+
const namePrototype = permit.prototype;
|
|
99
|
+
if (!namePrototype) {
|
|
100
|
+
throw new TypeError(`${name}.prototype property not whitelisted`);
|
|
128
101
|
}
|
|
129
|
-
|
|
130
|
-
|
|
102
|
+
if (
|
|
103
|
+
typeof namePrototype !== 'string' ||
|
|
104
|
+
!objectHasOwnProperty(whitelist, namePrototype)
|
|
105
|
+
) {
|
|
106
|
+
throw new TypeError(`Unrecognized ${name}.prototype whitelist entry`);
|
|
107
|
+
}
|
|
108
|
+
const intrinsicPrototype = intrinsic.prototype;
|
|
109
|
+
if (objectHasOwnProperty(intrinsics, namePrototype)) {
|
|
110
|
+
if (intrinsics[namePrototype] !== intrinsicPrototype) {
|
|
111
|
+
throw new TypeError(`Conflicting bindings of ${namePrototype}`);
|
|
112
|
+
}
|
|
113
|
+
// eslint-disable-next-line no-continue
|
|
114
|
+
continue;
|
|
115
|
+
}
|
|
116
|
+
intrinsics[namePrototype] = intrinsicPrototype;
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
freeze(completePrototypes);
|
|
120
|
+
|
|
121
|
+
const finalIntrinsics = () => {
|
|
122
|
+
freeze(intrinsics);
|
|
123
|
+
pseudoNatives = new WeakSet(arrayFilter(values(intrinsics), isFunction));
|
|
124
|
+
return intrinsics;
|
|
125
|
+
};
|
|
126
|
+
freeze(finalIntrinsics);
|
|
127
|
+
|
|
128
|
+
const isPseudoNative = obj => {
|
|
129
|
+
if (!pseudoNatives) {
|
|
130
|
+
throw new TypeError(
|
|
131
|
+
'isPseudoNative can only be called after finalIntrinsics',
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
return weaksetHas(pseudoNatives, obj);
|
|
135
|
+
};
|
|
136
|
+
freeze(isPseudoNative);
|
|
137
|
+
|
|
138
|
+
const intrinsicsCollector = {
|
|
139
|
+
addIntrinsics,
|
|
140
|
+
completePrototypes,
|
|
141
|
+
finalIntrinsics,
|
|
142
|
+
isPseudoNative,
|
|
131
143
|
};
|
|
144
|
+
freeze(intrinsicsCollector);
|
|
132
145
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
sampleGlobals(globalThis, universalPropertyNames),
|
|
136
|
-
);
|
|
146
|
+
addIntrinsics(constantProperties);
|
|
147
|
+
addIntrinsics(sampleGlobals(globalThis, universalPropertyNames));
|
|
137
148
|
|
|
138
149
|
return intrinsicsCollector;
|
|
139
150
|
};
|
|
@@ -152,11 +163,9 @@ export const makeIntrinsicsCollector = () => {
|
|
|
152
163
|
* @param {Object} globalObject
|
|
153
164
|
*/
|
|
154
165
|
export const getGlobalIntrinsics = globalObject => {
|
|
155
|
-
const
|
|
166
|
+
const { addIntrinsics, finalIntrinsics } = makeIntrinsicsCollector();
|
|
156
167
|
|
|
157
|
-
|
|
158
|
-
sampleGlobals(globalObject, sharedGlobalPropertyNames),
|
|
159
|
-
);
|
|
168
|
+
addIntrinsics(sampleGlobals(globalObject, sharedGlobalPropertyNames));
|
|
160
169
|
|
|
161
|
-
return
|
|
170
|
+
return finalIntrinsics();
|
|
162
171
|
};
|