ses 2.0.0 → 2.1.0
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/dist/lockdown.cjs +356 -104
- package/dist/lockdown.mjs +356 -104
- package/dist/lockdown.umd.js +356 -104
- package/dist/lockdown.umd.min.js +1 -1
- package/dist/ses-hermes.cjs +356 -104
- package/dist/ses.cjs +356 -104
- package/dist/ses.mjs +356 -104
- package/dist/ses.umd.js +356 -104
- package/dist/ses.umd.min.js +1 -1
- package/package.json +5 -39
- package/src/assert-sloppy-mode.js +2 -1
- package/src/cauterize-property.js +3 -2
- package/src/commons.js +61 -9
- package/src/compartment.js +8 -6
- package/src/error/assert.js +16 -21
- package/src/error/tame-error-constructor.js +6 -0
- package/src/error/tame-v8-error-constructor.js +24 -10
- package/src/get-anonymous-intrinsics.js +1 -1
- package/src/get-source-url.js +11 -4
- package/src/permits.js +7 -1
- package/src/scope-constants.js +4 -3
- package/src/tame-locale-methods.js +2 -1
- package/src/tame-nan-sidechannel.js +184 -34
- package/src/transforms.js +5 -5
- package/src-xs/commons.js +29 -0
- package/src-xs/compartment-shim.js +134 -0
- package/src-xs/compartment.js +318 -0
- package/src-xs/index.js +27 -0
- package/src-xs/lockdown-shim.js +29 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ses",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "Hardened JavaScript for Fearless Cooperation",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"lockdown",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"supply-chain attack",
|
|
19
19
|
"plugin"
|
|
20
20
|
],
|
|
21
|
-
"author": "
|
|
21
|
+
"author": "Endo contributors",
|
|
22
22
|
"license": "Apache-2.0",
|
|
23
23
|
"homepage": "https://github.com/Agoric/SES-shim/tree/master/packages/ses#readme",
|
|
24
24
|
"repository": {
|
|
@@ -75,47 +75,13 @@
|
|
|
75
75
|
"./console-shim.js": "./console-shim.js",
|
|
76
76
|
"./package.json": "./package.json"
|
|
77
77
|
},
|
|
78
|
-
"scripts": {
|
|
79
|
-
"build:vanilla": "node scripts/bundle.js",
|
|
80
|
-
"build:hermes": "node scripts/bundle.js hermes",
|
|
81
|
-
"build": "yarn build:vanilla && yarn build:hermes",
|
|
82
|
-
"clean": "rm -rf dist",
|
|
83
|
-
"cover": "c8 ava --config test/_ava-ses.config.js",
|
|
84
|
-
"demo": "python3 -m http.server",
|
|
85
|
-
"lint": "yarn lint:types && yarn lint:eslint",
|
|
86
|
-
"lint-fix": "eslint --fix .",
|
|
87
|
-
"lint:eslint": "eslint .",
|
|
88
|
-
"lint:types": "tsc",
|
|
89
|
-
"prepare": "npm run clean && npm run build",
|
|
90
|
-
"qt": "ava",
|
|
91
|
-
"test": "tsd && ava",
|
|
92
|
-
"test:hermes": "./scripts/hermes-test.sh",
|
|
93
|
-
"test:xs": "xst dist/ses.umd.js test/_lockdown-safe.js && node scripts/generate-test-xs.js && xst tmp/test-xs.js && rm -rf tmp",
|
|
94
|
-
"postpack": "git clean -fX -e node_modules/"
|
|
95
|
-
},
|
|
96
78
|
"dependencies": {
|
|
97
79
|
"@endo/cache-map": "^1.1.0",
|
|
98
80
|
"@endo/env-options": "^1.1.11",
|
|
99
81
|
"@endo/immutable-arraybuffer": "^1.1.2"
|
|
100
82
|
},
|
|
101
|
-
"devDependencies": {
|
|
102
|
-
"@babel/generator": "^7.28.3",
|
|
103
|
-
"@babel/parser": "~7.28.3",
|
|
104
|
-
"@babel/traverse": "~7.28.3",
|
|
105
|
-
"@babel/types": "~7.28.2",
|
|
106
|
-
"@endo/compartment-mapper": "^2.1.0",
|
|
107
|
-
"@endo/module-source": "^1.4.1",
|
|
108
|
-
"@endo/test262-runner": "^0.1.50",
|
|
109
|
-
"ava": "catalog:dev",
|
|
110
|
-
"c8": "catalog:dev",
|
|
111
|
-
"core-js": "^3.31.0",
|
|
112
|
-
"eslint": "catalog:dev",
|
|
113
|
-
"hermes-engine-cli": "^0.12.0",
|
|
114
|
-
"terser": "^5.16.6",
|
|
115
|
-
"tsd": "catalog:dev",
|
|
116
|
-
"typescript": "catalog:dev"
|
|
117
|
-
},
|
|
118
83
|
"files": [
|
|
84
|
+
"./*.d.js",
|
|
119
85
|
"./*.d.ts",
|
|
120
86
|
"./*.js",
|
|
121
87
|
"./*.map",
|
|
@@ -124,6 +90,7 @@
|
|
|
124
90
|
"dist",
|
|
125
91
|
"lib",
|
|
126
92
|
"src",
|
|
93
|
+
"src-xs",
|
|
127
94
|
"tools"
|
|
128
95
|
],
|
|
129
96
|
"publishConfig": {
|
|
@@ -142,6 +109,5 @@
|
|
|
142
109
|
},
|
|
143
110
|
"typeCoverage": {
|
|
144
111
|
"atLeast": 81.17
|
|
145
|
-
}
|
|
146
|
-
"gitHead": "c3616c39c35f2d052f7083aba31054910951beb4"
|
|
112
|
+
}
|
|
147
113
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { TypeError } from './commons.js';
|
|
2
2
|
|
|
3
|
-
/**
|
|
3
|
+
/** @this {unknown} */
|
|
4
|
+
// getThis returns globalThis in sloppy mode or undefined in strict mode.
|
|
4
5
|
function getThis() {
|
|
5
6
|
return this;
|
|
6
7
|
}
|
|
@@ -52,6 +52,7 @@ export const cauterizeProperty = (
|
|
|
52
52
|
try {
|
|
53
53
|
delete obj[prop];
|
|
54
54
|
} catch (err) {
|
|
55
|
+
const reason = /** @type {string | object} */ (err);
|
|
55
56
|
if (hasOwn(obj, prop)) {
|
|
56
57
|
if (typeof obj === 'function' && prop === 'prototype') {
|
|
57
58
|
obj.prototype = undefined;
|
|
@@ -60,9 +61,9 @@ export const cauterizeProperty = (
|
|
|
60
61
|
return;
|
|
61
62
|
}
|
|
62
63
|
}
|
|
63
|
-
error(`failed to delete ${subPath}`,
|
|
64
|
+
error(`failed to delete ${subPath}`, reason);
|
|
64
65
|
} else {
|
|
65
|
-
error(`deleting ${subPath} threw`,
|
|
66
|
+
error(`deleting ${subPath} threw`, reason);
|
|
66
67
|
}
|
|
67
68
|
throw err;
|
|
68
69
|
}
|
package/src/commons.js
CHANGED
|
@@ -64,7 +64,6 @@ export const {
|
|
|
64
64
|
create,
|
|
65
65
|
defineProperties,
|
|
66
66
|
entries,
|
|
67
|
-
freeze,
|
|
68
67
|
getOwnPropertyDescriptor,
|
|
69
68
|
getOwnPropertyDescriptors,
|
|
70
69
|
getOwnPropertyNames,
|
|
@@ -82,18 +81,32 @@ export const {
|
|
|
82
81
|
fromEntries,
|
|
83
82
|
} = Object;
|
|
84
83
|
|
|
84
|
+
/**
|
|
85
|
+
* For use with any value except a regular expression (@see {@link sealRegexp}
|
|
86
|
+
* and {@link freezeRegexp}).
|
|
87
|
+
*
|
|
88
|
+
* @type { &
|
|
89
|
+
* ((obj: RegExp) => void) &
|
|
90
|
+
* typeof Object.freeze
|
|
91
|
+
* }
|
|
92
|
+
*/
|
|
93
|
+
export const freeze = /** @type {any} */ (Object.freeze);
|
|
94
|
+
|
|
85
95
|
export const {
|
|
86
96
|
species: speciesSymbol,
|
|
87
97
|
toStringTag: toStringTagSymbol,
|
|
88
98
|
iterator: iteratorSymbol,
|
|
89
99
|
matchAll: matchAllSymbol,
|
|
90
100
|
replace: replaceSymbol,
|
|
101
|
+
search: searchSymbol,
|
|
91
102
|
unscopables: unscopablesSymbol,
|
|
92
103
|
keyFor: symbolKeyFor,
|
|
93
104
|
for: symbolFor,
|
|
94
105
|
} = Symbol;
|
|
95
106
|
|
|
96
|
-
export const {
|
|
107
|
+
export const { max, min, trunc } = Math;
|
|
108
|
+
|
|
109
|
+
export const { MAX_SAFE_INTEGER, isInteger } = Number;
|
|
97
110
|
|
|
98
111
|
export const { stringify: stringifyJson } = JSON;
|
|
99
112
|
|
|
@@ -135,6 +148,7 @@ export const {
|
|
|
135
148
|
|
|
136
149
|
export const { isArray, prototype: arrayPrototype } = Array;
|
|
137
150
|
export const { prototype: arrayBufferPrototype } = ArrayBuffer;
|
|
151
|
+
export const { prototype: dataViewPrototype } = DataView;
|
|
138
152
|
export const { prototype: mapPrototype } = Map;
|
|
139
153
|
export const { revocable: proxyRevocable } = Proxy;
|
|
140
154
|
export const { prototype: regexpPrototype } = RegExp;
|
|
@@ -236,6 +250,7 @@ export const iterateSet = uncurryThis(setPrototype[iteratorSymbol]);
|
|
|
236
250
|
* vulnerable to RegExp.prototype poisoning.
|
|
237
251
|
*/
|
|
238
252
|
export const regexpExec = uncurryThis(regexpPrototype.exec);
|
|
253
|
+
|
|
239
254
|
/**
|
|
240
255
|
* @type { &
|
|
241
256
|
* ((thisArg: RegExp, string: string, replaceValue: string) => string) &
|
|
@@ -245,21 +260,57 @@ export const regexpExec = uncurryThis(regexpPrototype.exec);
|
|
|
245
260
|
export const regexpReplace = /** @type {any} */ (
|
|
246
261
|
uncurryThis(regexpPrototype[replaceSymbol])
|
|
247
262
|
);
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* `regexpSearch` can be used with a frozen non-global non-sticky RegExp.
|
|
266
|
+
*
|
|
267
|
+
* @type {(thisArg: RegExp, string: string) => number}
|
|
268
|
+
*/
|
|
269
|
+
export const regexpSearch = uncurryThis(regexpPrototype[searchSymbol]);
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* `matchAll` internally creates a new RegExp vulnerable to prototype poisoning,
|
|
273
|
+
* but this function is still needed to reach %RegExpStringIteratorPrototype%.
|
|
274
|
+
* @private
|
|
275
|
+
*/
|
|
248
276
|
export const matchAllRegExp = uncurryThis(regexpPrototype[matchAllSymbol]);
|
|
249
|
-
|
|
250
|
-
|
|
277
|
+
|
|
278
|
+
const regexpDescriptors = getOwnPropertyDescriptors(regexpPrototype);
|
|
251
279
|
arrayForEach(ownKeys(regexpDescriptors), key => {
|
|
252
280
|
const desc = regexpDescriptors[/** @type {any} */ (key)];
|
|
253
281
|
desc.configurable = false;
|
|
254
282
|
if (desc.writable) desc.writable = false;
|
|
255
283
|
});
|
|
284
|
+
// Don't follow Symbol.species
|
|
285
|
+
// https://tc39.es/ecma262/multipage/abstract-operations.html#sec-speciesconstructor
|
|
286
|
+
defineProperty(regexpDescriptors, 'constructor', {
|
|
287
|
+
value: undefined,
|
|
288
|
+
enumerable: false,
|
|
289
|
+
configurable: false,
|
|
290
|
+
writable: false,
|
|
291
|
+
});
|
|
292
|
+
|
|
256
293
|
/**
|
|
257
294
|
* Protect a RegExp instance against RegExp.prototype poisoning ("exec",
|
|
258
|
-
* "flags", Symbol.replace, etc.)
|
|
295
|
+
* "flags", Symbol.replace, etc.) while still maintaining mutability of its
|
|
296
|
+
* "lastIndex" property (which is necessary with flags "g" and/or "y" for some
|
|
297
|
+
* operations, most notably {@link regexpReplace}).
|
|
298
|
+
*
|
|
259
299
|
* @type {<T extends RegExp>(regexp: T) => T}
|
|
260
300
|
*/
|
|
261
301
|
export const sealRegexp = regexp =>
|
|
262
302
|
seal(defineProperties(regexp, regexpDescriptors));
|
|
303
|
+
|
|
304
|
+
/**
|
|
305
|
+
* Protect a RegExp instance against RegExp.prototype poisoning ("exec",
|
|
306
|
+
* "flags", Symbol.replace, etc.) and freeze its "lastIndex" property, rendering
|
|
307
|
+
* it fully inert but (absent flags "g" and/or "y") still usable by
|
|
308
|
+
* {@link regexpExec} and {@link regexpSearch}.
|
|
309
|
+
*
|
|
310
|
+
* @type {<T extends RegExp>(regexp: T) => T}
|
|
311
|
+
*/
|
|
312
|
+
export const freezeRegexp = regexp =>
|
|
313
|
+
freeze(/** @type {any} */ (defineProperties(regexp, regexpDescriptors)));
|
|
263
314
|
//
|
|
264
315
|
export const stringEndsWith = uncurryThis(stringPrototype.endsWith);
|
|
265
316
|
export const stringIncludes = uncurryThis(stringPrototype.includes);
|
|
@@ -386,7 +437,7 @@ const makeTypeError = () => {
|
|
|
386
437
|
null.null;
|
|
387
438
|
throw TypeError('obligatory'); // To convince the type flow inferrence.
|
|
388
439
|
} catch (error) {
|
|
389
|
-
return error;
|
|
440
|
+
return /** @type {TypeError} */ (error);
|
|
390
441
|
}
|
|
391
442
|
};
|
|
392
443
|
|
|
@@ -459,9 +510,10 @@ const getAsyncGeneratorFunctionInstance = () => {
|
|
|
459
510
|
'return (async function* AsyncGeneratorFunctionInstance() {})',
|
|
460
511
|
)();
|
|
461
512
|
} catch (error) {
|
|
513
|
+
const err = /** @type {Error} */ (error);
|
|
462
514
|
// Note: `Error.prototype.jsEngine` is only set by React Native runtime, not Hermes:
|
|
463
515
|
// https://github.com/facebook/react-native/blob/main/packages/react-native/ReactCommon/hermes/executor/HermesExecutorFactory.cpp#L224-L230
|
|
464
|
-
if (
|
|
516
|
+
if (err.name === 'SyntaxError') {
|
|
465
517
|
// Swallows Hermes error `async generators are unsupported` at runtime.
|
|
466
518
|
// Note: `console` is not a JS built-in, so Hermes engine throws:
|
|
467
519
|
// Uncaught ReferenceError: Property 'console' doesn't exist
|
|
@@ -469,11 +521,11 @@ const getAsyncGeneratorFunctionInstance = () => {
|
|
|
469
521
|
// However React Native provides a `console` implementation when setting up error handling:
|
|
470
522
|
// https://github.com/facebook/react-native/blob/main/packages/react-native/Libraries/Core/InitializeCore.js
|
|
471
523
|
return undefined;
|
|
472
|
-
} else if (
|
|
524
|
+
} else if (err.name === 'EvalError') {
|
|
473
525
|
// eslint-disable-next-line no-empty-function
|
|
474
526
|
return async function* AsyncGeneratorFunctionInstance() {};
|
|
475
527
|
} else {
|
|
476
|
-
throw
|
|
528
|
+
throw err;
|
|
477
529
|
}
|
|
478
530
|
}
|
|
479
531
|
};
|
package/src/compartment.js
CHANGED
|
@@ -335,9 +335,9 @@ export const makeCompartmentConstructor = (
|
|
|
335
335
|
{ parentCompartment = undefined, enforceNew = false } = {},
|
|
336
336
|
) => {
|
|
337
337
|
/**
|
|
338
|
-
*
|
|
339
|
-
* @param {CompartmentOptionsArgs|LegacyCompartmentOptionsArgs} args
|
|
338
|
+
* @param {...CompartmentOptionsArgs|LegacyCompartmentOptionsArgs} args
|
|
340
339
|
*/
|
|
340
|
+
/** @this {Compartment} */
|
|
341
341
|
function Compartment(...args) {
|
|
342
342
|
if (enforceNew && new.target === undefined) {
|
|
343
343
|
throw TypeError(
|
|
@@ -359,7 +359,9 @@ export const makeCompartmentConstructor = (
|
|
|
359
359
|
importMetaHook,
|
|
360
360
|
__noNamespaceBox__: noNamespaceBox = false,
|
|
361
361
|
noAggregateLoadErrors = false,
|
|
362
|
-
} = compartmentOptions(
|
|
362
|
+
} = compartmentOptions(
|
|
363
|
+
.../** @type {Parameters<typeof compartmentOptions>} */ (args),
|
|
364
|
+
);
|
|
363
365
|
const globalTransforms = arrayFlatMap(
|
|
364
366
|
[transforms, __shimTransforms__],
|
|
365
367
|
identity,
|
|
@@ -376,7 +378,7 @@ export const makeCompartmentConstructor = (
|
|
|
376
378
|
|
|
377
379
|
const globalObject = {};
|
|
378
380
|
|
|
379
|
-
const compartment = this;
|
|
381
|
+
const compartment = /** @type {Compartment} */ (this);
|
|
380
382
|
|
|
381
383
|
setGlobalObjectSymbolUnscopables(globalObject);
|
|
382
384
|
|
|
@@ -397,7 +399,7 @@ export const makeCompartmentConstructor = (
|
|
|
397
399
|
intrinsics,
|
|
398
400
|
newGlobalPropertyNames: sharedGlobalPropertyNames,
|
|
399
401
|
makeCompartmentConstructor: targetMakeCompartmentConstructor,
|
|
400
|
-
parentCompartment:
|
|
402
|
+
parentCompartment: compartment,
|
|
401
403
|
markVirtualizedNativeFunction,
|
|
402
404
|
});
|
|
403
405
|
|
|
@@ -449,7 +451,7 @@ export const makeCompartmentConstructor = (
|
|
|
449
451
|
return exportsProxy;
|
|
450
452
|
};
|
|
451
453
|
|
|
452
|
-
weakmapSet(privateFields,
|
|
454
|
+
weakmapSet(privateFields, compartment, {
|
|
453
455
|
name: `${name}`,
|
|
454
456
|
globalTransforms,
|
|
455
457
|
globalObject,
|
package/src/error/assert.js
CHANGED
|
@@ -22,12 +22,12 @@ import {
|
|
|
22
22
|
assign,
|
|
23
23
|
freeze,
|
|
24
24
|
defineProperty,
|
|
25
|
+
freezeRegexp,
|
|
25
26
|
globalThis,
|
|
26
27
|
is,
|
|
27
28
|
isError,
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
sealRegexp,
|
|
29
|
+
regexpSearch,
|
|
30
|
+
stringEndsWith,
|
|
31
31
|
stringIndexOf,
|
|
32
32
|
stringSlice,
|
|
33
33
|
stringStartsWith,
|
|
@@ -74,13 +74,13 @@ const quote = (value, spaces = undefined) => {
|
|
|
74
74
|
};
|
|
75
75
|
freeze(quote);
|
|
76
76
|
|
|
77
|
-
const canBeBare =
|
|
77
|
+
const canBeBare = freezeRegexp(/^[\w:-]( ?[\w:-])*$/);
|
|
78
78
|
|
|
79
79
|
/**
|
|
80
80
|
* @type {AssertionUtilities['bare']}
|
|
81
81
|
*/
|
|
82
82
|
const bare = (text, spaces = undefined) => {
|
|
83
|
-
if (typeof text !== 'string' ||
|
|
83
|
+
if (typeof text !== 'string' || regexpSearch(canBeBare, text) === -1) {
|
|
84
84
|
return quote(text, spaces);
|
|
85
85
|
}
|
|
86
86
|
const result = freeze({
|
|
@@ -201,9 +201,6 @@ const unredactedDetails = (template, ...args) => {
|
|
|
201
201
|
freeze(unredactedDetails);
|
|
202
202
|
export { unredactedDetails };
|
|
203
203
|
|
|
204
|
-
const leadingSpacePattern = sealRegexp(/^ /);
|
|
205
|
-
const trailingSpacePattern = sealRegexp(/ $/);
|
|
206
|
-
|
|
207
204
|
/**
|
|
208
205
|
* Get arguments suitable for a console logger function (e.g., `console.error`)
|
|
209
206
|
* from `details` template literal contents, unquoting quoted substitution
|
|
@@ -221,20 +218,18 @@ const getLogArgs = ({ template, args }) => {
|
|
|
221
218
|
}
|
|
222
219
|
// Remove substitution-adjacent spaces from template fixed-string parts
|
|
223
220
|
// (since console logging inserts its own argument-separating spaces).
|
|
224
|
-
const prevLiteralPart =
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
)
|
|
229
|
-
|
|
230
|
-
arrayPush(logArgs, prevLiteralPart);
|
|
221
|
+
const prevLiteralPart = arrayPop(logArgs) || '';
|
|
222
|
+
const trimmedPrev = stringEndsWith(prevLiteralPart, ' ')
|
|
223
|
+
? stringSlice(prevLiteralPart, 0, -1)
|
|
224
|
+
: prevLiteralPart;
|
|
225
|
+
if (trimmedPrev !== '') {
|
|
226
|
+
arrayPush(logArgs, trimmedPrev);
|
|
231
227
|
}
|
|
232
|
-
const nextLiteralPart =
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
);
|
|
237
|
-
arrayPush(logArgs, arg, nextLiteralPart);
|
|
228
|
+
const nextLiteralPart = template[i + 1];
|
|
229
|
+
const trimmedNext = stringStartsWith(nextLiteralPart, ' ')
|
|
230
|
+
? stringSlice(nextLiteralPart, 1)
|
|
231
|
+
: nextLiteralPart;
|
|
232
|
+
arrayPush(logArgs, arg, trimmedNext);
|
|
238
233
|
}
|
|
239
234
|
if (logArgs[logArgs.length - 1] === '') {
|
|
240
235
|
arrayPop(logArgs);
|
|
@@ -42,10 +42,16 @@ export default function tameErrorConstructor(
|
|
|
42
42
|
typeof originalCaptureStackTrace === 'function' ? 'v8' : 'unknown';
|
|
43
43
|
|
|
44
44
|
const makeErrorConstructor = (_ = {}) => {
|
|
45
|
+
/**
|
|
46
|
+
* @this {ErrorConstructor}
|
|
47
|
+
* @param {...any} rest
|
|
48
|
+
*/
|
|
45
49
|
// eslint-disable-next-line no-shadow
|
|
46
50
|
const ResultError = function Error(...rest) {
|
|
47
51
|
let error;
|
|
48
52
|
if (new.target === undefined) {
|
|
53
|
+
// Forward caller's `this` to FERAL_ERROR to keep the shim transparent.
|
|
54
|
+
// Error() as a function ignores `this` per spec, but do not narrow it.
|
|
49
55
|
error = apply(FERAL_ERROR, this, rest);
|
|
50
56
|
} else {
|
|
51
57
|
error = construct(FERAL_ERROR, rest, new.target);
|
|
@@ -8,9 +8,11 @@ import {
|
|
|
8
8
|
arraySlice,
|
|
9
9
|
create,
|
|
10
10
|
defineProperties,
|
|
11
|
+
freezeRegexp,
|
|
11
12
|
fromEntries,
|
|
12
13
|
reflectSet,
|
|
13
14
|
regexpExec,
|
|
15
|
+
regexpSearch,
|
|
14
16
|
weakmapGet,
|
|
15
17
|
weakmapSet,
|
|
16
18
|
weaksetAdd,
|
|
@@ -63,27 +65,33 @@ const safeV8SST = sst => arrayMap(sst, safeV8CallSiteFacet);
|
|
|
63
65
|
// If it has `/node_modules/` anywhere in it, on Node it is likely
|
|
64
66
|
// to be a dependent package of the current package, and so to
|
|
65
67
|
// be an infrastructure frame to be dropped from concise stack traces.
|
|
66
|
-
const FILENAME_NODE_DEPENDENTS_CENSOR = /\/node_modules
|
|
68
|
+
const FILENAME_NODE_DEPENDENTS_CENSOR = freezeRegexp(/\/node_modules\//);
|
|
67
69
|
|
|
68
70
|
// If it begins with `internal/` or `node:internal` then it is likely
|
|
69
71
|
// part of the node infrustructre itself, to be dropped from concise
|
|
70
72
|
// stack traces.
|
|
71
|
-
const FILENAME_NODE_INTERNALS_CENSOR = /^(?:node:)?internal
|
|
73
|
+
const FILENAME_NODE_INTERNALS_CENSOR = freezeRegexp(/^(?:node:)?internal\//);
|
|
72
74
|
|
|
73
75
|
// Frames within SES `assert.js` should be dropped from concise stack traces, as
|
|
74
76
|
// these are just steps towards creating the error object in question.
|
|
75
|
-
const FILENAME_ASSERT_CENSOR =
|
|
77
|
+
const FILENAME_ASSERT_CENSOR = freezeRegexp(
|
|
78
|
+
/\/packages\/ses\/src\/error\/assert\.js$/,
|
|
79
|
+
);
|
|
76
80
|
|
|
77
81
|
// Frames within the `eventual-send` shim should be dropped so that concise
|
|
78
82
|
// deep stacks omit the internals of the eventual-sending mechanism causing
|
|
79
83
|
// asynchronous messages to be sent.
|
|
80
84
|
// Note that the eventual-send package will move from agoric-sdk to
|
|
81
85
|
// Endo, so this rule will be of general interest.
|
|
82
|
-
const FILENAME_EVENTUAL_SEND_CENSOR =
|
|
86
|
+
const FILENAME_EVENTUAL_SEND_CENSOR = freezeRegexp(
|
|
87
|
+
/\/packages\/eventual-send\/src\//,
|
|
88
|
+
);
|
|
83
89
|
|
|
84
90
|
// Frames within the `ses-ava` package should be dropped from concise stack
|
|
85
91
|
// traces, as they just support exposing error details to AVA.
|
|
86
|
-
const FILENAME_SES_AVA_CENSOR =
|
|
92
|
+
const FILENAME_SES_AVA_CENSOR = freezeRegexp(
|
|
93
|
+
/\/packages\/ses-ava\/src\/ses-ava-test\.js$/,
|
|
94
|
+
);
|
|
87
95
|
|
|
88
96
|
// Any stack frame whose `fileName` matches any of these censor patterns
|
|
89
97
|
// will be omitted from concise stacks.
|
|
@@ -106,7 +114,7 @@ export const filterFileName = fileName => {
|
|
|
106
114
|
return false;
|
|
107
115
|
}
|
|
108
116
|
for (const filter of FILENAME_CENSORS) {
|
|
109
|
-
if (
|
|
117
|
+
if (regexpSearch(filter, fileName) !== -1) {
|
|
110
118
|
return false;
|
|
111
119
|
}
|
|
112
120
|
}
|
|
@@ -123,7 +131,9 @@ export const filterFileName = fileName => {
|
|
|
123
131
|
//
|
|
124
132
|
// See thread starting at
|
|
125
133
|
// https://github.com/Agoric/agoric-sdk/issues/2326#issuecomment-773020389
|
|
126
|
-
const CALLSITE_ELLIPSIS_PATTERN1 =
|
|
134
|
+
const CALLSITE_ELLIPSIS_PATTERN1 = freezeRegexp(
|
|
135
|
+
/^((?:.*[( ])?)[:/\w_-]*\/\.\.\.\/(.+)$/,
|
|
136
|
+
);
|
|
127
137
|
|
|
128
138
|
// The ad-hoc rule of the current pattern is that any likely-file-path or
|
|
129
139
|
// likely url-path prefix consisting of `.../` should get dropped.
|
|
@@ -135,7 +145,7 @@ const CALLSITE_ELLIPSIS_PATTERN1 = /^((?:.*[( ])?)[:/\w_-]*\/\.\.\.\/(.+)$/;
|
|
|
135
145
|
//
|
|
136
146
|
// See thread starting at
|
|
137
147
|
// https://github.com/Agoric/agoric-sdk/issues/2326#issuecomment-773020389
|
|
138
|
-
const CALLSITE_ELLIPSIS_PATTERN2 = /^((?:.*[( ])?)\.\.\.\/(.+)
|
|
148
|
+
const CALLSITE_ELLIPSIS_PATTERN2 = freezeRegexp(/^((?:.*[( ])?)\.\.\.\/(.+)$/);
|
|
139
149
|
|
|
140
150
|
// The ad-hoc rule of the current pattern is that any likely-file-path or
|
|
141
151
|
// likely url-path prefix, ending in a `/` and prior to `package/` should get
|
|
@@ -147,7 +157,9 @@ const CALLSITE_ELLIPSIS_PATTERN2 = /^((?:.*[( ])?)\.\.\.\/(.+)$/;
|
|
|
147
157
|
// `'Object.bar (packages/errors/test/deep-send.test.js:13:21)'`.
|
|
148
158
|
// Note that `/packages/` is a convention for monorepos encouraged by
|
|
149
159
|
// lerna.
|
|
150
|
-
const CALLSITE_PACKAGES_PATTERN =
|
|
160
|
+
const CALLSITE_PACKAGES_PATTERN = freezeRegexp(
|
|
161
|
+
/^((?:.*[( ])?)[:/\w_-]*\/(packages\/.+)$/,
|
|
162
|
+
);
|
|
151
163
|
|
|
152
164
|
// The ad-hoc rule of the current pattern is that any likely-file-path or
|
|
153
165
|
// likely url-path prefix of the form `file://` but not `file:///` gets
|
|
@@ -163,7 +175,9 @@ const CALLSITE_PACKAGES_PATTERN = /^((?:.*[( ])?)[:/\w_-]*\/(packages\/.+)$/;
|
|
|
163
175
|
// clickable without removing the `file:///`, whereas `file://` usually precedes
|
|
164
176
|
// a relative path which, for whatever vscode reason, is not clickable until the
|
|
165
177
|
// `file://` is removed.
|
|
166
|
-
const CALLSITE_FILE_2SLASH_PATTERN =
|
|
178
|
+
const CALLSITE_FILE_2SLASH_PATTERN = freezeRegexp(
|
|
179
|
+
/^((?:.*[( ])?)file:\/\/([^/].*)$/,
|
|
180
|
+
);
|
|
167
181
|
|
|
168
182
|
// The use of these callSite patterns below assumes that any match will bind
|
|
169
183
|
// capture groups containing the parts of the original string we want
|
|
@@ -60,7 +60,7 @@ export const getAnonymousIntrinsics = () => {
|
|
|
60
60
|
|
|
61
61
|
// 21.2.7.1 The %RegExpStringIteratorPrototype% Object
|
|
62
62
|
const RegExpStringIterator =
|
|
63
|
-
regexpPrototype[matchAllSymbol] && matchAllRegExp(
|
|
63
|
+
regexpPrototype[matchAllSymbol] && matchAllRegExp(/./, '');
|
|
64
64
|
const RegExpStringIteratorPrototype =
|
|
65
65
|
RegExpStringIterator && getPrototypeOf(RegExpStringIterator);
|
|
66
66
|
|
package/src/get-source-url.js
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
FERAL_REG_EXP,
|
|
3
|
+
freezeRegexp,
|
|
4
|
+
regexpExec,
|
|
5
|
+
stringSlice,
|
|
6
|
+
} from './commons.js';
|
|
2
7
|
|
|
3
8
|
// Captures a key and value of the form #key=value or @key=value
|
|
4
9
|
const sourceMetaEntryRegExp =
|
|
@@ -9,8 +14,10 @@ const sourceMetaEntryRegExp =
|
|
|
9
14
|
// On account of the mechanics of regular expressions, scanning from the end
|
|
10
15
|
// does not allow us to capture every pair, so getSourceURL must capture and
|
|
11
16
|
// trim until there are no matching comments.
|
|
12
|
-
const sourceMetaEntriesRegExp =
|
|
13
|
-
|
|
17
|
+
const sourceMetaEntriesRegExp = freezeRegexp(
|
|
18
|
+
new FERAL_REG_EXP(
|
|
19
|
+
`(?:\\s*//${sourceMetaEntryRegExp}|/\\*${sourceMetaEntryRegExp}\\s*\\*/)\\s*$`,
|
|
20
|
+
),
|
|
14
21
|
);
|
|
15
22
|
|
|
16
23
|
/**
|
|
@@ -31,7 +38,7 @@ export const getSourceURL = src => {
|
|
|
31
38
|
if (match === null) {
|
|
32
39
|
break;
|
|
33
40
|
}
|
|
34
|
-
src = stringSlice(src, 0,
|
|
41
|
+
src = stringSlice(src, 0, -match[0].length);
|
|
35
42
|
|
|
36
43
|
// We skip $0 since it contains the entire match.
|
|
37
44
|
// The match contains four capture groups,
|
package/src/permits.js
CHANGED
|
@@ -338,7 +338,7 @@ arrayForEach(['caller', 'arguments'], prop => {
|
|
|
338
338
|
strict[prop];
|
|
339
339
|
} catch (e) {
|
|
340
340
|
// https://github.com/facebook/hermes/blob/main/test/hermes/function-non-strict.js
|
|
341
|
-
if (e.message === 'Restricted in strict mode') {
|
|
341
|
+
if (/** @type {Error} */ (e).message === 'Restricted in strict mode') {
|
|
342
342
|
// Fixed in Static Hermes: https://github.com/facebook/hermes/issues/1582
|
|
343
343
|
FunctionInstance[prop] = accessor;
|
|
344
344
|
}
|
|
@@ -865,6 +865,8 @@ export const permitted = {
|
|
|
865
865
|
getYear: fn,
|
|
866
866
|
setYear: fn,
|
|
867
867
|
toGMTString: fn,
|
|
868
|
+
|
|
869
|
+
toTemporalInstant: false,
|
|
868
870
|
},
|
|
869
871
|
|
|
870
872
|
// Text Processing
|
|
@@ -1253,6 +1255,8 @@ export const permitted = {
|
|
|
1253
1255
|
entries: fn,
|
|
1254
1256
|
forEach: fn,
|
|
1255
1257
|
get: fn,
|
|
1258
|
+
getOrInsert: fn,
|
|
1259
|
+
getOrInsertComputed: fn,
|
|
1256
1260
|
has: fn,
|
|
1257
1261
|
keys: fn,
|
|
1258
1262
|
set: fn,
|
|
@@ -1324,6 +1328,8 @@ export const permitted = {
|
|
|
1324
1328
|
constructor: 'WeakMap',
|
|
1325
1329
|
delete: fn,
|
|
1326
1330
|
get: fn,
|
|
1331
|
+
getOrInsert: fn,
|
|
1332
|
+
getOrInsertComputed: fn,
|
|
1327
1333
|
has: fn,
|
|
1328
1334
|
set: fn,
|
|
1329
1335
|
'@@toStringTag': 'string',
|
package/src/scope-constants.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
2
|
arrayFilter,
|
|
3
3
|
arrayIncludes,
|
|
4
|
+
freezeRegexp,
|
|
4
5
|
getOwnPropertyDescriptor,
|
|
5
6
|
getOwnPropertyNames,
|
|
6
7
|
hasOwn,
|
|
7
|
-
|
|
8
|
+
regexpSearch,
|
|
8
9
|
Set,
|
|
9
10
|
setHas,
|
|
10
11
|
} from './commons.js';
|
|
@@ -91,7 +92,7 @@ const reservedNames = new Set([
|
|
|
91
92
|
* Note: \w is equivalent [a-zA-Z_0-9]
|
|
92
93
|
* See 11.6.1 Identifier Names
|
|
93
94
|
*/
|
|
94
|
-
const identifierPattern = /^[a-zA-Z_$][\w$]
|
|
95
|
+
const identifierPattern = freezeRegexp(/^[a-zA-Z_$][\w$]*$/);
|
|
95
96
|
|
|
96
97
|
/**
|
|
97
98
|
* isValidIdentifierName()
|
|
@@ -100,7 +101,7 @@ const identifierPattern = /^[a-zA-Z_$][\w$]*$/;
|
|
|
100
101
|
* @param {string} name
|
|
101
102
|
*/
|
|
102
103
|
export const isValidIdentifierName = name =>
|
|
103
|
-
!setHas(reservedNames, name) &&
|
|
104
|
+
!setHas(reservedNames, name) && regexpSearch(identifierPattern, name) !== -1;
|
|
104
105
|
|
|
105
106
|
/*
|
|
106
107
|
* isImmutableDataProperty
|
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
String,
|
|
4
4
|
TypeError,
|
|
5
5
|
defineProperty,
|
|
6
|
+
freezeRegexp,
|
|
6
7
|
getOwnPropertyNames,
|
|
7
8
|
isPrimitive,
|
|
8
9
|
regexpExec,
|
|
@@ -11,7 +12,7 @@ import { assert } from './error/assert.js';
|
|
|
11
12
|
|
|
12
13
|
const { Fail, quote: q } = assert;
|
|
13
14
|
|
|
14
|
-
const localePattern = /^(\w*[a-z])Locale([A-Z]\w*)
|
|
15
|
+
const localePattern = freezeRegexp(/^(\w*[a-z])Locale([A-Z]\w*)$/);
|
|
15
16
|
|
|
16
17
|
// Use concise methods to obtain named functions without constructor
|
|
17
18
|
// behavior or `.prototype` property.
|