ses 1.7.0 → 1.9.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/types.d.cts CHANGED
@@ -33,6 +33,12 @@ export interface RepairOptions {
33
33
  overrideTaming?: 'moderate' | 'min' | 'severe';
34
34
  overrideDebug?: Array<string>;
35
35
  domainTaming?: 'safe' | 'unsafe';
36
+ /**
37
+ * safe (default): do nothing.
38
+ *
39
+ * unsafe-ignore: make %IteratorPrototype%[@@iterator] to a funky accessor which ignores all assignments.
40
+ */
41
+ legacyRegeneratorRuntimeTaming?: 'safe' | 'unsafe-ignore';
36
42
  __hardenTaming__?: 'safe' | 'unsafe';
37
43
  }
38
44
 
@@ -0,0 +1 @@
1
+ import './src/lockdown-shim.js';
package/lockdown.js ADDED
@@ -0,0 +1 @@
1
+ import './index.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ses",
3
- "version": "1.7.0",
3
+ "version": "1.9.0",
4
4
  "description": "Hardened JavaScript for Fearless Cooperation",
5
5
  "keywords": [
6
6
  "lockdown",
@@ -59,6 +59,7 @@
59
59
  "./assert-shim.js": "./assert-shim.js",
60
60
  "./lockdown-shim.js": "./lockdown-shim.js",
61
61
  "./compartment-shim.js": "./compartment-shim.js",
62
+ "./console-shim.js": "./console-shim.js",
62
63
  "./package.json": "./package.json"
63
64
  },
64
65
  "scripts": {
@@ -73,15 +74,16 @@
73
74
  "prepare": "npm run clean && npm run build",
74
75
  "qt": "ava",
75
76
  "test": "tsd && ava",
76
- "test:platform-compatibility": "node test/package/test.cjs"
77
+ "test:xs": "xst dist/ses.umd.js test/_lockdown-safe.js",
78
+ "postpack": "git clean -f '*.d.ts*' '*.tsbuildinfo'"
77
79
  },
78
80
  "dependencies": {
79
- "@endo/env-options": "^1.1.5"
81
+ "@endo/env-options": "^1.1.7"
80
82
  },
81
83
  "devDependencies": {
82
- "@endo/compartment-mapper": "^1.2.1",
83
- "@endo/module-source": "^1.0.1",
84
- "@endo/test262-runner": "^0.1.39",
84
+ "@endo/compartment-mapper": "^1.3.0",
85
+ "@endo/module-source": "^1.1.0",
86
+ "@endo/test262-runner": "^0.1.41",
85
87
  "ava": "^6.1.3",
86
88
  "babel-eslint": "^10.1.0",
87
89
  "c8": "^7.14.0",
@@ -92,20 +94,20 @@
92
94
  "eslint-plugin-eslint-comments": "^3.2.0",
93
95
  "eslint-plugin-import": "^2.29.1",
94
96
  "prettier": "^3.2.5",
95
- "sinon": "^15.1.0",
96
97
  "terser": "^5.16.6",
97
- "tsd": "^0.30.7",
98
- "typescript": "5.5.2"
98
+ "tsd": "^0.31.2",
99
+ "typescript": "~5.6.2"
99
100
  },
100
101
  "files": [
102
+ "./*.d.ts",
103
+ "./*.js",
104
+ "./*.map",
101
105
  "LICENSE*",
102
- "NEWS*",
103
106
  "SECURITY*",
104
107
  "dist",
105
- "types.d.ts",
106
- "index.js",
107
- "tools.js",
108
- "src"
108
+ "lib",
109
+ "src",
110
+ "tools"
109
111
  ],
110
112
  "publishConfig": {
111
113
  "access": "public"
@@ -117,6 +119,7 @@
117
119
  "rules": {
118
120
  "no-restricted-globals": [
119
121
  "error",
122
+ "AggregateError",
120
123
  "Array",
121
124
  "ArrayBuffer",
122
125
  "Atomics",
@@ -124,6 +127,7 @@
124
127
  "BigInt64Array",
125
128
  "BigUint64Array",
126
129
  "Boolean",
130
+ "Compartment",
127
131
  "DataView",
128
132
  "Date",
129
133
  "Error",
@@ -159,6 +163,7 @@
159
163
  "Uint8ClampedArray",
160
164
  "WeakMap",
161
165
  "WeakSet",
166
+ "assert",
162
167
  "decodeURI",
163
168
  "decodeURIComponent",
164
169
  "encodeURI",
@@ -168,10 +173,10 @@
168
173
  "globalThis",
169
174
  "isFinite",
170
175
  "isNaN",
176
+ "lockdown",
171
177
  "parseFloat",
172
178
  "parseInt",
173
- "unescape",
174
- "AggregateError"
179
+ "unescape"
175
180
  ],
176
181
  "@endo/no-polymorphic-call": "error"
177
182
  },
@@ -191,7 +196,6 @@
191
196
  },
192
197
  "ava": {
193
198
  "files": [
194
- "test/**/test-*.*",
195
199
  "test/**/*.test.*"
196
200
  ],
197
201
  "timeout": "2m"
@@ -199,5 +203,5 @@
199
203
  "typeCoverage": {
200
204
  "atLeast": 81.17
201
205
  },
202
- "gitHead": "444c81ad3ecc1b0a449023a9c65e9be2fa17db21"
206
+ "gitHead": "bbf20fae6726f7d26456714b8852572787d34e05"
203
207
  }
package/src/commons.js CHANGED
@@ -19,6 +19,7 @@ export { universalThis as globalThis };
19
19
 
20
20
  export const {
21
21
  Array,
22
+ ArrayBuffer,
22
23
  Date,
23
24
  FinalizationRegistry,
24
25
  Float32Array,
@@ -34,6 +35,7 @@ export const {
34
35
  Set,
35
36
  String,
36
37
  Symbol,
38
+ Uint8Array,
37
39
  WeakMap,
38
40
  WeakSet,
39
41
  } = globalThis;
@@ -124,6 +126,7 @@ export const {
124
126
  } = Reflect;
125
127
 
126
128
  export const { isArray, prototype: arrayPrototype } = Array;
129
+ export const { prototype: arrayBufferPrototype } = ArrayBuffer;
127
130
  export const { prototype: mapPrototype } = Map;
128
131
  export const { revocable: proxyRevocable } = Proxy;
129
132
  export const { prototype: regexpPrototype } = RegExp;
@@ -137,6 +140,10 @@ export const { prototype: generatorPrototype } = getPrototypeOf(
137
140
  // eslint-disable-next-line no-empty-function, func-names
138
141
  function* () {},
139
142
  );
143
+ export const iteratorPrototype = getPrototypeOf(
144
+ // eslint-disable-next-line @endo/no-polymorphic-call
145
+ getPrototypeOf(arrayPrototype.values()),
146
+ );
140
147
 
141
148
  export const typedArrayPrototype = getPrototypeOf(Uint8Array.prototype);
142
149
 
@@ -174,6 +181,15 @@ export const arraySome = uncurryThis(arrayPrototype.some);
174
181
  export const arraySort = uncurryThis(arrayPrototype.sort);
175
182
  export const iterateArray = uncurryThis(arrayPrototype[iteratorSymbol]);
176
183
  //
184
+ export const arrayBufferSlice = uncurryThis(arrayBufferPrototype.slice);
185
+ /** @type {(b: ArrayBuffer) => number} */
186
+ export const arrayBufferGetByteLength = uncurryThis(
187
+ // @ts-expect-error we know it is there on all conforming platforms
188
+ getOwnPropertyDescriptor(arrayBufferPrototype, 'byteLength').get,
189
+ );
190
+ //
191
+ export const typedArraySet = uncurryThis(typedArrayPrototype.set);
192
+ //
177
193
  export const mapSet = uncurryThis(mapPrototype.set);
178
194
  export const mapGet = uncurryThis(mapPrototype.get);
179
195
  export const mapHas = uncurryThis(mapPrototype.has);
@@ -209,8 +225,10 @@ export const stringReplace = /** @type {any} */ (
209
225
  );
210
226
  export const stringSearch = uncurryThis(stringPrototype.search);
211
227
  export const stringSlice = uncurryThis(stringPrototype.slice);
212
- /** @type {(thisArg: string, splitter: string | RegExp | { [Symbol.split](string: string, limit?: number): string[]; }, limit?: number) => string[]} */
213
- export const stringSplit = uncurryThis(stringPrototype.split);
228
+ export const stringSplit =
229
+ /** @type {(thisArg: string, splitter: string | RegExp | { [Symbol.split](string: string, limit?: number): string[]; }, limit?: number) => string[]} */ (
230
+ uncurryThis(stringPrototype.split)
231
+ );
214
232
  export const stringStartsWith = uncurryThis(stringPrototype.startsWith);
215
233
  export const iterateString = uncurryThis(stringPrototype[iteratorSymbol]);
216
234
  //
@@ -19,7 +19,7 @@ import {
19
19
  setGlobalObjectMutableProperties,
20
20
  setGlobalObjectEvaluators,
21
21
  } from './global-object.js';
22
- import { assertEqual } from './error/assert.js';
22
+ import { assert, assertEqual } from './error/assert.js';
23
23
  import { sharedGlobalPropertyNames } from './permits.js';
24
24
  import { load, loadNow } from './module-load.js';
25
25
  import { link } from './module-link.js';
@@ -368,8 +368,10 @@ export const makeCausalConsole = (baseConsole, loggedErrorHandler) => {
368
368
  const levelMethod = (...logArgs) => {
369
369
  const subErrors = [];
370
370
  const argTags = extractErrorArgs(logArgs, subErrors);
371
- // eslint-disable-next-line @endo/no-polymorphic-call
372
- baseConsole[level](...argTags);
371
+ if (baseConsole[level]) {
372
+ // eslint-disable-next-line @endo/no-polymorphic-call
373
+ baseConsole[level](...argTags);
374
+ }
373
375
  // @ts-expect-error ConsoleProp vs LogSeverity mismatch
374
376
  logSubErrors(level, subErrors);
375
377
  };
@@ -476,12 +478,16 @@ export const defineCausalConsoleFromLogger = loggedErrorHandler => {
476
478
  // the host console will separate them with additional spaces.
477
479
  arrayPush(indents, ' ');
478
480
  });
481
+ } else {
482
+ baseConsole[name] = () => {};
479
483
  }
480
484
  }
481
485
  if (baseConsole.groupEnd) {
482
486
  baseConsole.groupEnd = makeNamed('groupEnd', (...args) => {
483
487
  arrayPop(indents);
484
488
  });
489
+ } else {
490
+ baseConsole.groupEnd = () => {};
485
491
  }
486
492
  harden(baseConsole);
487
493
  const causalConsole = makeCausalConsole(
@@ -120,8 +120,8 @@ export const tameConsole = (
120
120
  }
121
121
 
122
122
  globalProcess.on('uncaughtException', error => {
123
- // causalConsole is born frozen so not vulnerable to method tampering.
124
- ourConsole.error(error);
123
+ // See https://github.com/endojs/endo/blob/master/packages/ses/error-codes/SES_UNCAUGHT_EXCEPTION.md
124
+ ourConsole.error('SES_UNCAUGHT_EXCEPTION:', error);
125
125
  if (terminate) {
126
126
  terminate();
127
127
  }
@@ -133,8 +133,9 @@ export const tameConsole = (
133
133
  typeof globalProcess.on === 'function'
134
134
  ) {
135
135
  const handleRejection = reason => {
136
- // 'platform' and 'report' just log the reason.
136
+ // See https://github.com/endojs/endo/blob/master/packages/ses/error-codes/SES_UNHANDLED_REJECTION.md
137
137
  ourConsole.error('SES_UNHANDLED_REJECTION:', reason);
138
+ // 'platform' and 'report' just log the reason.
138
139
  };
139
140
  // Maybe track unhandled promise rejections.
140
141
  const h = makeRejectionHandlers(handleRejection);
@@ -155,8 +156,9 @@ export const tameConsole = (
155
156
  ) {
156
157
  globalWindow.addEventListener('error', event => {
157
158
  event.preventDefault();
159
+ // See https://github.com/endojs/endo/blob/master/packages/ses/error-codes/SES_UNCAUGHT_EXCEPTION.md
160
+ ourConsole.error('SES_UNCAUGHT_EXCEPTION:', event.error);
158
161
  // 'platform' and 'report' just log the reason.
159
- ourConsole.error(event.error);
160
162
  if (errorTrapping === 'exit' || errorTrapping === 'abort') {
161
163
  globalWindow.location.href = `about:blank`;
162
164
  }
@@ -168,6 +170,7 @@ export const tameConsole = (
168
170
  typeof globalWindow.addEventListener === 'function'
169
171
  ) {
170
172
  const handleRejection = reason => {
173
+ // See https://github.com/endojs/endo/blob/master/packages/ses/error-codes/SES_UNHANDLED_REJECTION.md
171
174
  ourConsole.error('SES_UNHANDLED_REJECTION:', reason);
172
175
  };
173
176
 
@@ -142,7 +142,11 @@ export const getAnonymousIntrinsics = () => {
142
142
  );
143
143
  intrinsics['%WrapForValidIteratorPrototype%'] = getPrototypeOf(
144
144
  // eslint-disable-next-line @endo/no-polymorphic-call
145
- globalThis.Iterator.from({ next() {} }),
145
+ globalThis.Iterator.from({
146
+ next() {
147
+ return { value: undefined };
148
+ },
149
+ }),
146
150
  );
147
151
  }
148
152
 
@@ -10,7 +10,7 @@ import { repairIntrinsics } from './lockdown.js';
10
10
  /** @import {LockdownOptions} from '../types.js' */
11
11
 
12
12
  /**
13
- * @param {LockdownOptions} options
13
+ * @param {LockdownOptions} [options]
14
14
  */
15
15
  globalThis.lockdown = options => {
16
16
  const hardenIntrinsics = repairIntrinsics(options);
@@ -18,7 +18,7 @@ globalThis.lockdown = options => {
18
18
  };
19
19
 
20
20
  /**
21
- * @param {LockdownOptions} options
21
+ * @param {LockdownOptions} [options]
22
22
  */
23
23
  globalThis.repairIntrinsics = options => {
24
24
  const hardenIntrinsics = repairIntrinsics(options);
package/src/lockdown.js CHANGED
@@ -46,6 +46,7 @@ import { makeSafeEvaluator } from './make-safe-evaluator.js';
46
46
  import { initialGlobalPropertyNames } from './permits.js';
47
47
  import { tameFunctionToString } from './tame-function-tostring.js';
48
48
  import { tameDomains } from './tame-domains.js';
49
+ import { tameModuleSource } from './tame-module-source.js';
49
50
 
50
51
  import { tameConsole } from './error/tame-console.js';
51
52
  import tameErrorConstructor from './error/tame-error-constructor.js';
@@ -55,6 +56,8 @@ import { makeCompartmentConstructor } from './compartment.js';
55
56
  import { tameHarden } from './tame-harden.js';
56
57
  import { tameSymbolConstructor } from './tame-symbol-constructor.js';
57
58
  import { tameFauxDataProperties } from './tame-faux-data-properties.js';
59
+ import { tameRegeneratorRuntime } from './tame-regenerator-runtime.js';
60
+ import { shimArrayBufferTransfer } from './shim-arraybuffer-transfer.js';
58
61
 
59
62
  /** @import {LockdownOptions} from '../types.js' */
60
63
 
@@ -180,12 +183,20 @@ export const repairIntrinsics = (options = {}) => {
180
183
  /** @param {string} debugName */
181
184
  debugName => debugName !== '',
182
185
  ),
186
+ legacyRegeneratorRuntimeTaming = getenv(
187
+ 'LOCKDOWN_LEGACY_REGENERATOR_RUNTIME_TAMING',
188
+ 'safe',
189
+ ),
183
190
  __hardenTaming__ = getenv('LOCKDOWN_HARDEN_TAMING', 'safe'),
184
191
  dateTaming = 'safe', // deprecated
185
192
  mathTaming = 'safe', // deprecated
186
193
  ...extraOptions
187
194
  } = options;
188
195
 
196
+ legacyRegeneratorRuntimeTaming === 'safe' ||
197
+ legacyRegeneratorRuntimeTaming === 'unsafe-ignore' ||
198
+ Fail`lockdown(): non supported option legacyRegeneratorRuntimeTaming: ${q(legacyRegeneratorRuntimeTaming)}`;
199
+
189
200
  evalTaming === 'unsafeEval' ||
190
201
  evalTaming === 'safeEval' ||
191
202
  evalTaming === 'noEval' ||
@@ -264,6 +275,7 @@ export const repairIntrinsics = (options = {}) => {
264
275
  const { addIntrinsics, completePrototypes, finalIntrinsics } =
265
276
  makeIntrinsicsCollector();
266
277
 
278
+ // @ts-expect-error __hardenTaming__ could be any string
267
279
  const tamedHarden = tameHarden(safeHarden, __hardenTaming__);
268
280
  addIntrinsics({ harden: tamedHarden });
269
281
 
@@ -274,6 +286,8 @@ export const repairIntrinsics = (options = {}) => {
274
286
  addIntrinsics(tameMathObject(mathTaming));
275
287
  addIntrinsics(tameRegExpConstructor(regExpTaming));
276
288
  addIntrinsics(tameSymbolConstructor());
289
+ addIntrinsics(shimArrayBufferTransfer());
290
+ addIntrinsics(tameModuleSource());
277
291
 
278
292
  addIntrinsics(getAnonymousIntrinsics());
279
293
 
@@ -412,6 +426,9 @@ export const repairIntrinsics = (options = {}) => {
412
426
  // clear yet which is better.
413
427
  // @ts-ignore enablePropertyOverrides does its own input validation
414
428
  enablePropertyOverrides(intrinsics, overrideTaming, overrideDebug);
429
+ if (legacyRegeneratorRuntimeTaming === 'unsafe-ignore') {
430
+ tameRegeneratorRuntime();
431
+ }
415
432
 
416
433
  // Finally register and optionally freeze all the intrinsics. This
417
434
  // must be the operation that modifies the intrinsics.
@@ -156,8 +156,10 @@ export default function whitelistIntrinsics(
156
156
  return;
157
157
  }
158
158
 
159
- // We can't clean [[prototype]], therefore abort.
160
- throw TypeError(`Unexpected intrinsic ${path}.__proto__ at ${protoName}`);
159
+ // We can't clean [[Prototype]], therefore abort.
160
+ throw TypeError(
161
+ `Unexpected [[Prototype]] at ${path}.__proto__ (expected ${protoName || '%ObjectPrototype%'})`,
162
+ );
161
163
  }
162
164
 
163
165
  /*
@@ -212,7 +214,9 @@ export default function whitelistIntrinsics(
212
214
  }
213
215
  }
214
216
 
215
- throw TypeError(`Unexpected whitelist permit ${permit} at ${path}`);
217
+ throw TypeError(
218
+ `Unexpected property ${prop} with permit ${permit} at ${path}`,
219
+ );
216
220
  }
217
221
 
218
222
  /*
package/src/permits.js CHANGED
@@ -101,8 +101,12 @@ export const universalPropertyNames = {
101
101
 
102
102
  // ESNext
103
103
 
104
+ // https://github.com/tc39/proposal-source-phase-imports?tab=readme-ov-file#js-module-source
105
+ ModuleSource: 'ModuleSource',
106
+
104
107
  lockdown: 'lockdown',
105
108
  harden: 'harden',
109
+
106
110
  HandledPromise: 'HandledPromise', // TODO: Until Promise.delegate (see below).
107
111
  };
108
112
 
@@ -1505,6 +1509,32 @@ export const permitted = {
1505
1509
  resolve: fn,
1506
1510
  },
1507
1511
 
1512
+ // https://github.com/tc39/proposal-source-phase-imports?tab=readme-ov-file#js-module-source
1513
+
1514
+ ModuleSource: {
1515
+ '[[Proto]]': '%AbstractModuleSource%',
1516
+ prototype: '%ModuleSourcePrototype%',
1517
+ },
1518
+
1519
+ '%ModuleSourcePrototype%': {
1520
+ '[[Proto]]': '%AbstractModuleSourcePrototype%',
1521
+ constructor: 'ModuleSource',
1522
+ '@@toStringTag': 'string',
1523
+ // https://github.com/tc39/proposal-compartments
1524
+ bindings: getter,
1525
+ needsImport: getter,
1526
+ needsImportMeta: getter,
1527
+ },
1528
+
1529
+ '%AbstractModuleSource%': {
1530
+ '[[Proto]]': '%FunctionPrototype%',
1531
+ prototype: '%AbstractModuleSourcePrototype%',
1532
+ },
1533
+
1534
+ '%AbstractModuleSourcePrototype%': {
1535
+ constructor: '%AbstractModuleSource%',
1536
+ },
1537
+
1508
1538
  Promise: {
1509
1539
  // Properties of the Promise Constructor
1510
1540
  '[[Proto]]': '%FunctionPrototype%',
@@ -0,0 +1,86 @@
1
+ import {
2
+ ArrayBuffer,
3
+ arrayBufferPrototype,
4
+ arrayBufferSlice,
5
+ arrayBufferGetByteLength,
6
+ Uint8Array,
7
+ typedArraySet,
8
+ globalThis,
9
+ TypeError,
10
+ defineProperty,
11
+ } from './commons.js';
12
+
13
+ export const shimArrayBufferTransfer = () => {
14
+ // @ts-expect-error TODO extend ArrayBuffer type to include transfer, etc.
15
+ if (typeof arrayBufferPrototype.transfer === 'function') {
16
+ // Assume already exists so does not need to be shimmed.
17
+ // Such conditional shimming is ok in this case since ArrayBuffer.p.transfer
18
+ // is already officially part of JS.
19
+ //
20
+ // Empty object because this shim has nothing for `addIntrinsics` to add.
21
+ return {};
22
+ }
23
+ const clone = globalThis.structuredClone;
24
+ if (typeof clone !== 'function') {
25
+ // On a platform with neither `Array.prototype.transfer`
26
+ // nor `structuredClone`, this shim does nothing.
27
+ // For example, Node <= 16 has neither.
28
+ //
29
+ // Empty object because this shim has nothing for `addIntrinsics` to add.
30
+ return {};
31
+ // TODO Rather than doing nothing, should the endo ses-shim throw
32
+ // in this case?
33
+ // throw TypeError(
34
+ // `Can only shim missing ArrayBuffer.prototype.transfer on a platform with "structuredClone"`,
35
+ // );
36
+ // For example, endo no longer supports Node <= 16. All browsers have
37
+ // `structuredClone`. XS has `Array.prototype.transfer`. Are there still
38
+ // any platforms without both that Endo should still support?
39
+ // What about Hermes?
40
+ }
41
+
42
+ /**
43
+ * @type {ThisType<ArrayBuffer>}
44
+ */
45
+ const methods = {
46
+ /**
47
+ * @param {number} [newLength]
48
+ */
49
+ transfer(newLength = undefined) {
50
+ // Using this builtin getter also ensures that `this` is a genuine
51
+ // ArrayBuffer.
52
+ const oldLength = arrayBufferGetByteLength(this);
53
+ if (newLength === undefined || newLength === oldLength) {
54
+ return clone(this, { transfer: [this] });
55
+ }
56
+ if (typeof newLength !== 'number') {
57
+ throw TypeError(`transfer newLength if provided must be a number`);
58
+ }
59
+ if (newLength > oldLength) {
60
+ const result = new ArrayBuffer(newLength);
61
+ const taOld = new Uint8Array(this);
62
+ const taNew = new Uint8Array(result);
63
+ typedArraySet(taNew, taOld);
64
+ // Using clone only to detach, and only after the copy succeeds
65
+ clone(this, { transfer: [this] });
66
+ return result;
67
+ } else {
68
+ const result = arrayBufferSlice(this, 0, newLength);
69
+ // Using clone only to detach, and only after the slice succeeds
70
+ clone(this, { transfer: [this] });
71
+ return result;
72
+ }
73
+ },
74
+ };
75
+
76
+ defineProperty(arrayBufferPrototype, 'transfer', {
77
+ // @ts-expect-error
78
+ value: methods.transfer,
79
+ writable: true,
80
+ enumerable: false,
81
+ configurable: true,
82
+ });
83
+
84
+ // Empty object because this shim has nothing for `addIntrinsics` to add.
85
+ return {};
86
+ };
@@ -1,6 +1,9 @@
1
1
  /* eslint-disable no-restricted-globals */
2
2
  import { TypeError, freeze } from './commons.js';
3
3
 
4
+ /** @import {Harden} from '../types.js'; */
5
+
6
+ /** @type {(safeHarden: Harden, hardenTaming: 'safe' | 'unsafe') => Harden} */
4
7
  export const tameHarden = (safeHarden, hardenTaming) => {
5
8
  if (hardenTaming !== 'safe' && hardenTaming !== 'unsafe') {
6
9
  throw TypeError(`unrecognized fakeHardenOption ${hardenTaming}`);
@@ -16,6 +19,7 @@ export const tameHarden = (safeHarden, hardenTaming) => {
16
19
  Object.isSealed = () => true;
17
20
  Reflect.isExtensible = () => false;
18
21
 
22
+ // @ts-expect-error secret property
19
23
  if (safeHarden.isFake) {
20
24
  // The "safe" hardener is already a fake hardener.
21
25
  // Just use it.
@@ -0,0 +1,51 @@
1
+ import {
2
+ functionPrototype,
3
+ getPrototypeOf,
4
+ globalThis,
5
+ objectPrototype,
6
+ setPrototypeOf,
7
+ } from './commons.js';
8
+
9
+ export const tameModuleSource = () => {
10
+ const newIntrinsics = {};
11
+
12
+ const ModuleSource = globalThis.ModuleSource;
13
+ if (ModuleSource !== undefined) {
14
+ newIntrinsics.ModuleSource = ModuleSource;
15
+
16
+ // We introduce ModuleSource.[[Proto]] === AbstractModuleSource
17
+ // and ModuleSource.prototype.[[Proto]] === AbstractModuleSource.prototype
18
+ // if that layer is absent because the permitting system can more
19
+ // gracefully tolerate the absence of an expected prototype than the
20
+ // presence of an unexpected prototype,.
21
+ function AbstractModuleSource() {
22
+ // no-op safe to super()
23
+ }
24
+
25
+ const ModuleSourceProto = getPrototypeOf(ModuleSource);
26
+ if (ModuleSourceProto === functionPrototype) {
27
+ setPrototypeOf(ModuleSource, AbstractModuleSource);
28
+ newIntrinsics['%AbstractModuleSource%'] = AbstractModuleSource;
29
+ newIntrinsics['%AbstractModuleSourcePrototype%'] =
30
+ AbstractModuleSource.prototype;
31
+ } else {
32
+ newIntrinsics['%AbstractModuleSource%'] = ModuleSourceProto;
33
+ newIntrinsics['%AbstractModuleSourcePrototype%'] =
34
+ ModuleSourceProto.prototype;
35
+ }
36
+
37
+ const ModuleSourcePrototype = ModuleSource.prototype;
38
+ if (ModuleSourcePrototype !== undefined) {
39
+ newIntrinsics['%ModuleSourcePrototype%'] = ModuleSourcePrototype;
40
+
41
+ // ModuleSource.prototype.__proto__ should be the
42
+ // AbstractModuleSource.prototype.
43
+ const ModuleSourcePrototypeProto = getPrototypeOf(ModuleSourcePrototype);
44
+ if (ModuleSourcePrototypeProto === objectPrototype) {
45
+ setPrototypeOf(ModuleSource.prototype, AbstractModuleSource.prototype);
46
+ }
47
+ }
48
+ }
49
+
50
+ return newIntrinsics;
51
+ };
@@ -0,0 +1,29 @@
1
+ import {
2
+ defineProperty,
3
+ iteratorPrototype,
4
+ iteratorSymbol,
5
+ objectHasOwnProperty,
6
+ } from './commons.js';
7
+
8
+ export const tameRegeneratorRuntime = () => {
9
+ const iter = iteratorPrototype[iteratorSymbol];
10
+ defineProperty(iteratorPrototype, iteratorSymbol, {
11
+ configurable: true,
12
+ get() {
13
+ return iter;
14
+ },
15
+ set(value) {
16
+ // ignore the assignment on IteratorPrototype
17
+ if (this === iteratorPrototype) return;
18
+ if (objectHasOwnProperty(this, iteratorSymbol)) {
19
+ this[iteratorSymbol] = value;
20
+ }
21
+ defineProperty(this, iteratorSymbol, {
22
+ value,
23
+ writable: true,
24
+ enumerable: true,
25
+ configurable: true,
26
+ });
27
+ },
28
+ });
29
+ };
package/types.d.ts CHANGED
@@ -33,6 +33,12 @@ export interface RepairOptions {
33
33
  overrideTaming?: 'moderate' | 'min' | 'severe';
34
34
  overrideDebug?: Array<string>;
35
35
  domainTaming?: 'safe' | 'unsafe';
36
+ /**
37
+ * safe (default): do nothing.
38
+ *
39
+ * unsafe-ignore: make %IteratorPrototype%[@@iterator] to a funky accessor which ignores all assignments.
40
+ */
41
+ legacyRegeneratorRuntimeTaming?: 'safe' | 'unsafe-ignore';
36
42
  __hardenTaming__?: 'safe' | 'unsafe';
37
43
  }
38
44