ses 1.15.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ses",
3
- "version": "1.15.0",
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": "Agoric",
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 \"*.d.ts*\" \"*.d.cts*\" \"*.d.mts*\" \"*.tsbuildinfo\""
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.0.0",
107
- "@endo/module-source": "^1.4.0",
108
- "@endo/test262-runner": "^0.1.49",
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": "~5.9.2"
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": "f91329e8616a19f131d009356a5f11ef11c839cc"
112
+ }
147
113
  }
@@ -1,6 +1,7 @@
1
1
  import { TypeError } from './commons.js';
2
2
 
3
- /** getThis returns globalThis in sloppy mode or undefined in strict mode. */
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}`, err);
64
+ error(`failed to delete ${subPath}`, reason);
64
65
  } else {
65
- error(`deleting ${subPath} threw`, err);
66
+ error(`deleting ${subPath} threw`, reason);
66
67
  }
67
68
  throw err;
68
69
  }
package/src/commons.js CHANGED
@@ -26,11 +26,14 @@ export const {
26
26
  ArrayBuffer,
27
27
  Date,
28
28
  FinalizationRegistry,
29
- Float32Array,
29
+ // Renamed to FERAL_* because it enables the NaN side-channel
30
+ Float64Array: FERAL_FLOAT64_ARRAY,
31
+ DataView,
30
32
  JSON,
31
33
  Map,
32
34
  Math,
33
35
  Number,
36
+ BigInt,
34
37
  Object,
35
38
  Promise,
36
39
  Proxy,
@@ -61,7 +64,6 @@ export const {
61
64
  create,
62
65
  defineProperties,
63
66
  entries,
64
- freeze,
65
67
  getOwnPropertyDescriptor,
66
68
  getOwnPropertyDescriptors,
67
69
  getOwnPropertyNames,
@@ -79,18 +81,32 @@ export const {
79
81
  fromEntries,
80
82
  } = Object;
81
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
+
82
95
  export const {
83
96
  species: speciesSymbol,
84
97
  toStringTag: toStringTagSymbol,
85
98
  iterator: iteratorSymbol,
86
99
  matchAll: matchAllSymbol,
87
100
  replace: replaceSymbol,
101
+ search: searchSymbol,
88
102
  unscopables: unscopablesSymbol,
89
103
  keyFor: symbolKeyFor,
90
104
  for: symbolFor,
91
105
  } = Symbol;
92
106
 
93
- export const { isInteger } = Number;
107
+ export const { max, min, trunc } = Math;
108
+
109
+ export const { MAX_SAFE_INTEGER, isInteger } = Number;
94
110
 
95
111
  export const { stringify: stringifyJson } = JSON;
96
112
 
@@ -132,6 +148,7 @@ export const {
132
148
 
133
149
  export const { isArray, prototype: arrayPrototype } = Array;
134
150
  export const { prototype: arrayBufferPrototype } = ArrayBuffer;
151
+ export const { prototype: dataViewPrototype } = DataView;
135
152
  export const { prototype: mapPrototype } = Map;
136
153
  export const { revocable: proxyRevocable } = Proxy;
137
154
  export const { prototype: regexpPrototype } = RegExp;
@@ -233,6 +250,7 @@ export const iterateSet = uncurryThis(setPrototype[iteratorSymbol]);
233
250
  * vulnerable to RegExp.prototype poisoning.
234
251
  */
235
252
  export const regexpExec = uncurryThis(regexpPrototype.exec);
253
+
236
254
  /**
237
255
  * @type { &
238
256
  * ((thisArg: RegExp, string: string, replaceValue: string) => string) &
@@ -242,21 +260,57 @@ export const regexpExec = uncurryThis(regexpPrototype.exec);
242
260
  export const regexpReplace = /** @type {any} */ (
243
261
  uncurryThis(regexpPrototype[replaceSymbol])
244
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
+ */
245
276
  export const matchAllRegExp = uncurryThis(regexpPrototype[matchAllSymbol]);
246
- const { _regexpConstructor, ...regexpDescriptors } =
247
- getOwnPropertyDescriptors(regexpPrototype);
277
+
278
+ const regexpDescriptors = getOwnPropertyDescriptors(regexpPrototype);
248
279
  arrayForEach(ownKeys(regexpDescriptors), key => {
249
280
  const desc = regexpDescriptors[/** @type {any} */ (key)];
250
281
  desc.configurable = false;
251
282
  if (desc.writable) desc.writable = false;
252
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
+
253
293
  /**
254
294
  * Protect a RegExp instance against RegExp.prototype poisoning ("exec",
255
- * "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
+ *
256
299
  * @type {<T extends RegExp>(regexp: T) => T}
257
300
  */
258
301
  export const sealRegexp = regexp =>
259
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)));
260
314
  //
261
315
  export const stringEndsWith = uncurryThis(stringPrototype.endsWith);
262
316
  export const stringIncludes = uncurryThis(stringPrototype.includes);
@@ -383,7 +437,7 @@ const makeTypeError = () => {
383
437
  null.null;
384
438
  throw TypeError('obligatory'); // To convince the type flow inferrence.
385
439
  } catch (error) {
386
- return error;
440
+ return /** @type {TypeError} */ (error);
387
441
  }
388
442
  };
389
443
 
@@ -456,9 +510,10 @@ const getAsyncGeneratorFunctionInstance = () => {
456
510
  'return (async function* AsyncGeneratorFunctionInstance() {})',
457
511
  )();
458
512
  } catch (error) {
513
+ const err = /** @type {Error} */ (error);
459
514
  // Note: `Error.prototype.jsEngine` is only set by React Native runtime, not Hermes:
460
515
  // https://github.com/facebook/react-native/blob/main/packages/react-native/ReactCommon/hermes/executor/HermesExecutorFactory.cpp#L224-L230
461
- if (error.name === 'SyntaxError') {
516
+ if (err.name === 'SyntaxError') {
462
517
  // Swallows Hermes error `async generators are unsupported` at runtime.
463
518
  // Note: `console` is not a JS built-in, so Hermes engine throws:
464
519
  // Uncaught ReferenceError: Property 'console' doesn't exist
@@ -466,11 +521,11 @@ const getAsyncGeneratorFunctionInstance = () => {
466
521
  // However React Native provides a `console` implementation when setting up error handling:
467
522
  // https://github.com/facebook/react-native/blob/main/packages/react-native/Libraries/Core/InitializeCore.js
468
523
  return undefined;
469
- } else if (error.name === 'EvalError') {
524
+ } else if (err.name === 'EvalError') {
470
525
  // eslint-disable-next-line no-empty-function
471
526
  return async function* AsyncGeneratorFunctionInstance() {};
472
527
  } else {
473
- throw error;
528
+ throw err;
474
529
  }
475
530
  }
476
531
  };
@@ -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(...args);
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: this,
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, this, {
454
+ weakmapSet(privateFields, compartment, {
453
455
  name: `${name}`,
454
456
  globalTransforms,
455
457
  globalObject,
@@ -95,38 +95,39 @@ export const moderateEnablements = {
95
95
  ...minEnablements,
96
96
 
97
97
  '%ObjectPrototype%': {
98
- toString: true,
98
+ ...minEnablements['%ObjectPrototype%'],
99
99
  valueOf: true,
100
100
  },
101
101
 
102
- '%ArrayPrototype%': {
103
- toString: true,
104
- push: true, // set by "Google Analytics"
105
- concat: true, // set by mobx generated code (old TS compiler?)
106
- [iteratorSymbol]: true, // set by mobx generated code (old TS compiler?)
107
- },
108
-
109
- '%IteratorPrototype%': {
110
- [iteratorSymbol]: true, // is sometimes used in custom iterators and generators implementations eg. @rive-app/canvas
111
- },
112
-
113
102
  // Function.prototype has no 'prototype' property to enable.
114
103
  // Function instances have their own 'name' and 'length' properties
115
104
  // which are configurable and non-writable. Thus, they are already
116
105
  // non-assignable anyway.
117
106
  '%FunctionPrototype%': {
107
+ ...minEnablements['%FunctionPrototype%'],
118
108
  constructor: true, // set by "regenerator-runtime"
119
109
  bind: true, // set by "underscore", "express"
120
- toString: true, // set by "rollup"
121
110
  },
122
111
 
123
112
  '%ErrorPrototype%': {
113
+ ...minEnablements['%ErrorPrototype%'],
124
114
  constructor: true, // set by "fast-json-patch", "node-fetch"
125
115
  message: true,
126
- name: true, // set by "precond", "ava", "node-fetch", "node 14"
127
116
  toString: true, // set by "bluebird"
128
117
  },
129
118
 
119
+ '%IteratorPrototype%': {
120
+ ...minEnablements['%IteratorPrototype%'],
121
+ [iteratorSymbol]: true, // is sometimes used in custom iterators and generators implementations eg. @rive-app/canvas
122
+ },
123
+
124
+ '%ArrayPrototype%': {
125
+ toString: true,
126
+ push: true, // set by "Google Analytics"
127
+ concat: true, // set by mobx generated code (old TS compiler?)
128
+ [iteratorSymbol]: true, // set by mobx generated code (old TS compiler?)
129
+ },
130
+
130
131
  '%TypeErrorPrototype%': {
131
132
  constructor: true, // set by "readable-stream"
132
133
  message: true, // set by "tape"
@@ -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
- regexpExec,
29
- regexpReplace,
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 = freeze(/^[\w:-]( ?[\w:-])*$/);
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' || !regexpExec(canBeBare, text)) {
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 = regexpReplace(
225
- trailingSpacePattern,
226
- arrayPop(logArgs) || '',
227
- '',
228
- );
229
- if (prevLiteralPart !== '') {
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 = regexpReplace(
233
- leadingSpacePattern,
234
- template[i + 1],
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 = /\/packages\/ses\/src\/error\/assert\.js$/;
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 = /\/packages\/eventual-send\/src\//;
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 = /\/packages\/ses-ava\/src\/ses-ava-test\.js$/;
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 (regexpExec(filter, fileName)) {
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 = /^((?:.*[( ])?)[:/\w_-]*\/\.\.\.\/(.+)$/;
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 = /^((?:.*[( ])?)[:/\w_-]*\/(packages\/.+)$/;
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 = /^((?:.*[( ])?)file:\/\/([^/].*)$/;
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
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  FERAL_FUNCTION,
3
- Float32Array,
3
+ FERAL_FLOAT64_ARRAY,
4
4
  Map,
5
5
  Set,
6
6
  String,
@@ -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
 
@@ -72,7 +72,7 @@ export const getAnonymousIntrinsics = () => {
72
72
 
73
73
  // 22.2.1 The %TypedArray% Intrinsic Object
74
74
 
75
- const TypedArray = getPrototypeOf(Float32Array);
75
+ const TypedArray = getPrototypeOf(FERAL_FLOAT64_ARRAY);
76
76
 
77
77
  // 23.1.5.2 The %MapIteratorPrototype% Object
78
78
 
@@ -1,4 +1,9 @@
1
- import { FERAL_REG_EXP, regexpExec, stringSlice } from './commons.js';
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 = new FERAL_REG_EXP(
13
- `(?:\\s*//${sourceMetaEntryRegExp}|/\\*${sourceMetaEntryRegExp}\\s*\\*/)\\s*$`,
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, src.length - match[0].length);
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/lockdown.js CHANGED
@@ -36,6 +36,7 @@ import removeUnpermittedIntrinsics from './permits-intrinsics.js';
36
36
  import tameFunctionConstructors from './tame-function-constructors.js';
37
37
  import tameDateConstructor from './tame-date-constructor.js';
38
38
  import tameMathObject from './tame-math-object.js';
39
+ import { tameNaNSideChannel } from './tame-nan-sidechannel.js';
39
40
  import tameRegExpConstructor from './tame-regexp-constructor.js';
40
41
  import enablePropertyOverrides from './enable-property-overrides.js';
41
42
  import tameLocaleMethods from './tame-locale-methods.js';
@@ -353,6 +354,7 @@ export const repairIntrinsics = (options = {}) => {
353
354
  addIntrinsics(tameDateConstructor());
354
355
  addIntrinsics(tameErrorConstructor(errorTaming, stackFiltering));
355
356
  addIntrinsics(tameMathObject());
357
+ tameNaNSideChannel();
356
358
  addIntrinsics(tameRegExpConstructor(regExpTaming));
357
359
  addIntrinsics(tameSymbolConstructor());
358
360
  addIntrinsics(shimArrayBufferTransfer());