ses 1.11.0 → 1.13.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
@@ -1,5 +1,6 @@
1
1
  /**
2
- * @module Types of the SES environment
2
+ * Types of the SES environment
3
+ * @module
3
4
  */
4
5
 
5
6
  /* eslint-disable no-restricted-globals, vars-on-top, no-var */
@@ -19,6 +20,10 @@
19
20
  // version of harden.
20
21
  export type Harden = <T>(value: T) => T; // not Hardened<T>;
21
22
 
23
+ // TODO Somehow remove the redundancy between these type deinitions and the
24
+ // inline casts on each call to `getenv` in `lockdown.js`. Hopefully we can
25
+ // keep the type info in those casts so it is easily comparable by eye to
26
+ // the parameters of that call to `genev`.
22
27
  export interface RepairOptions {
23
28
  regExpTaming?: 'safe' | 'unsafe';
24
29
  localeTaming?: 'safe' | 'unsafe';
@@ -35,8 +40,15 @@ export interface RepairOptions {
35
40
  * @deprecated Deprecated and does nothing. In the future specifying it will be an error.
36
41
  */
37
42
  mathTaming?: 'safe' | 'unsafe';
38
- evalTaming?: 'safeEval' | 'unsafeEval' | 'noEval';
39
- stackFiltering?: 'concise' | 'verbose';
43
+ evalTaming?:
44
+ | 'safe-eval'
45
+ | 'unsafe-eval'
46
+ | 'no-eval'
47
+ // deprecated
48
+ | 'safeEval'
49
+ | 'unsafeEval'
50
+ | 'noEval';
51
+ stackFiltering?: 'concise' | 'omit-frames' | 'shorten-paths' | 'verbose';
40
52
  overrideTaming?: 'moderate' | 'min' | 'severe';
41
53
  overrideDebug?: Array<string>;
42
54
  domainTaming?: 'safe' | 'unsafe';
@@ -135,10 +147,12 @@ export type ModuleMapHook = (
135
147
  moduleSpecifier: string,
136
148
  ) => ModuleDescriptor | undefined;
137
149
  export type ImportHook = (moduleSpecifier: string) => Promise<ModuleDescriptor>;
138
- export type ImportNowHook = (moduleSpecifier: string) => ModuleDescriptor;
150
+ export type ImportNowHook = (
151
+ moduleSpecifier: string,
152
+ ) => ModuleDescriptor | undefined;
139
153
  export type ImportMetaHook = (
140
154
  moduleSpecifier: string,
141
- importMeta: Object,
155
+ importMeta: ImportMeta,
142
156
  ) => void;
143
157
 
144
158
  export interface CompartmentOptions {
@@ -569,7 +583,9 @@ declare global {
569
583
 
570
584
  evaluate(code: string, options?: CompartmentEvaluateOptions): any;
571
585
 
572
- import(specifier: string): Promise<{ namespace: ModuleExportsNamespace }>;
586
+ import(
587
+ specifier: string | null,
588
+ ): Promise<{ namespace: ModuleExportsNamespace }>;
573
589
 
574
590
  load(specifier: string): Promise<void>;
575
591
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ses",
3
- "version": "1.11.0",
3
+ "version": "1.13.0",
4
4
  "description": "Hardened JavaScript for Fearless Cooperation",
5
5
  "keywords": [
6
6
  "lockdown",
@@ -56,6 +56,12 @@
56
56
  "default": "./dist/ses.cjs"
57
57
  }
58
58
  },
59
+ "./hermes": {
60
+ "require": {
61
+ "types": "./dist/types.d.cts",
62
+ "default": "./dist/ses-hermes.cjs"
63
+ }
64
+ },
59
65
  "./tools.js": "./tools.js",
60
66
  "./assert-shim.js": "./assert-shim.js",
61
67
  "./lockdown-shim.js": {
@@ -70,7 +76,9 @@
70
76
  "./package.json": "./package.json"
71
77
  },
72
78
  "scripts": {
73
- "build": "node scripts/bundle.js",
79
+ "build:vanilla": "node scripts/bundle.js",
80
+ "build:hermes": "node scripts/bundle.js hermes",
81
+ "build": "yarn build:vanilla && yarn build:hermes",
74
82
  "clean": "rm -rf dist",
75
83
  "cover": "c8 ava",
76
84
  "demo": "python3 -m http.server",
@@ -81,29 +89,37 @@
81
89
  "prepare": "npm run clean && npm run build",
82
90
  "qt": "ava",
83
91
  "test": "tsd && ava",
92
+ "test:hermes": "./scripts/hermes-test.sh",
84
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",
85
94
  "postpack": "git clean -f '*.d.ts*' '*.tsbuildinfo'"
86
95
  },
87
96
  "dependencies": {
88
- "@endo/env-options": "^1.1.8"
97
+ "@endo/env-options": "^1.1.9",
98
+ "@endo/immutable-arraybuffer": "^1.1.0"
89
99
  },
90
100
  "devDependencies": {
91
- "@endo/compartment-mapper": "^1.5.0",
92
- "@endo/module-source": "^1.2.0",
93
- "@endo/test262-runner": "^0.1.44",
101
+ "@babel/generator": "^7.26.3",
102
+ "@babel/parser": "~7.26.2",
103
+ "@babel/traverse": "~7.25.9",
104
+ "@babel/types": "~7.26.0",
105
+ "@endo/compartment-mapper": "^1.6.1",
106
+ "@endo/module-source": "^1.3.1",
107
+ "@endo/test262-runner": "^0.1.46",
108
+ "@types/babel__traverse": "^7.20.5",
94
109
  "ava": "^6.1.3",
95
110
  "babel-eslint": "^10.1.0",
96
111
  "c8": "^7.14.0",
97
112
  "core-js": "^3.31.0",
98
- "eslint": "^8.57.0",
113
+ "eslint": "^8.57.1",
99
114
  "eslint-config-airbnb-base": "^15.0.0",
100
115
  "eslint-config-prettier": "^9.1.0",
101
116
  "eslint-plugin-eslint-comments": "^3.2.0",
102
- "eslint-plugin-import": "^2.29.1",
103
- "prettier": "^3.3.3",
117
+ "eslint-plugin-import": "^2.31.0",
118
+ "hermes-engine-cli": "^0.12.0",
119
+ "prettier": "^3.5.3",
104
120
  "terser": "^5.16.6",
105
121
  "tsd": "^0.31.2",
106
- "typescript": "~5.6.3"
122
+ "typescript": "~5.8.3"
107
123
  },
108
124
  "files": [
109
125
  "./*.d.ts",
@@ -210,5 +226,5 @@
210
226
  "typeCoverage": {
211
227
  "atLeast": 81.17
212
228
  },
213
- "gitHead": "e0683e0bfdbfc84351af332c9e78813d7b67ef89"
229
+ "gitHead": "571b7803cf10df7cb4fa9d70e4d53a0b53767fa8"
214
230
  }
package/src/commons.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @module Captures native intrinsics during initialization, so vetted shims
2
+ * Captures native intrinsics during initialization, so vetted shims
3
3
  * (running between initialization of SES and calling lockdown) are free to
4
4
  * modify the environment without compromising the integrity of SES. For
5
5
  * example, a vetted shim can modify Object.assign because we capture and
@@ -9,6 +9,8 @@
9
9
  * This pattern of use is enforced by eslint rules no-restricted-globals and
10
10
  * no-polymorphic-call.
11
11
  * We maintain the list of restricted globals in ../package.json.
12
+ *
13
+ * @module
12
14
  */
13
15
 
14
16
  /* global globalThis */
@@ -320,7 +322,7 @@ export const FERAL_FUNCTION = Function;
320
322
 
321
323
  export const noEvalEvaluate = () => {
322
324
  // See https://github.com/endojs/endo/blob/master/packages/ses/error-codes/SES_NO_EVAL.md
323
- throw TypeError('Cannot eval with evalTaming set to "noEval" (SES_NO_EVAL)');
325
+ throw TypeError('Cannot eval with evalTaming set to "no-eval" (SES_NO_EVAL)');
324
326
  };
325
327
 
326
328
  // ////////////////// FERAL_STACK_GETTER FERAL_STACK_SETTER ////////////////////
@@ -380,3 +382,43 @@ export const FERAL_STACK_GETTER = feralStackGetter;
380
382
  * @type {((newValue: any) => void) | undefined}
381
383
  */
382
384
  export const FERAL_STACK_SETTER = feralStackSetter;
385
+
386
+ const getAsyncGeneratorFunctionInstance = () => {
387
+ // Test for async generator function syntax support.
388
+ try {
389
+ // Wrapping one in an new Function lets the `hermesc` binary file
390
+ // parse the Metro js bundle without SyntaxError, to generate the
391
+ // optimised Hermes bytecode bundle, when `gradlew` is called to
392
+ // assemble the release build APK for React Native prod Android apps.
393
+ // Delaying the error until runtime lets us customise lockdown behaviour.
394
+ return new FERAL_FUNCTION(
395
+ 'return (async function* AsyncGeneratorFunctionInstance() {})',
396
+ )();
397
+ } catch (error) {
398
+ // Note: `Error.prototype.jsEngine` is only set by React Native runtime, not Hermes:
399
+ // https://github.com/facebook/react-native/blob/main/packages/react-native/ReactCommon/hermes/executor/HermesExecutorFactory.cpp#L224-L230
400
+ if (error.name === 'SyntaxError') {
401
+ // Swallows Hermes error `async generators are unsupported` at runtime.
402
+ // Note: `console` is not a JS built-in, so Hermes engine throws:
403
+ // Uncaught ReferenceError: Property 'console' doesn't exist
404
+ // See: https://github.com/facebook/hermes/issues/675
405
+ // However React Native provides a `console` implementation when setting up error handling:
406
+ // https://github.com/facebook/react-native/blob/main/packages/react-native/Libraries/Core/InitializeCore.js
407
+ return undefined;
408
+ } else if (error.name === 'EvalError') {
409
+ // eslint-disable-next-line no-empty-function
410
+ return async function* AsyncGeneratorFunctionInstance() {};
411
+ } else {
412
+ throw error;
413
+ }
414
+ }
415
+ };
416
+
417
+ /**
418
+ * If the platform supports async generator functions, this will be an
419
+ * async generator function instance. Otherwise, it will be `undefined`.
420
+ *
421
+ * @type {AsyncGeneratorFunction | undefined}
422
+ */
423
+ export const AsyncGeneratorFunctionInstance =
424
+ getAsyncGeneratorFunctionInstance();
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @module Provides the mechanism to create a Compartment constructor that
2
+ * Provides the mechanism to create a Compartment constructor that
3
3
  * can provide either shim-specific or native XS features depending on
4
4
  * the __native__ constructor option.
5
5
  * This is necessary because a native Compartment can handle native ModuleSource
@@ -33,6 +33,8 @@
33
33
  * Evaluating ./compartment.js does not have global side-effects.
34
34
  * We defer modification of the global environment until the evaluation
35
35
  * of ./compartment-shim.js.
36
+ *
37
+ * @module
36
38
  */
37
39
 
38
40
  // @ts-check
@@ -309,6 +311,8 @@ export const makeCompartmentConstructor = (
309
311
 
310
312
  const globalObject = {};
311
313
 
314
+ const compartment = this;
315
+
312
316
  setGlobalObjectSymbolUnscopables(globalObject);
313
317
 
314
318
  // We must initialize all constant properties first because
@@ -367,11 +371,11 @@ export const makeCompartmentConstructor = (
367
371
  `Compartment does not support dynamic import: no configured resolveHook for compartment ${q(name)}`,
368
372
  );
369
373
  }
370
- await load(privateFields, moduleAliases, this, fullSpecifier);
374
+ await load(privateFields, moduleAliases, compartment, fullSpecifier);
371
375
  const { execute, exportsProxy } = link(
372
376
  privateFields,
373
377
  moduleAliases,
374
- this,
378
+ compartment,
375
379
  fullSpecifier,
376
380
  );
377
381
  execute();
@@ -1,13 +1,15 @@
1
1
  import { toStringTagSymbol, iteratorSymbol } from './commons.js';
2
2
 
3
3
  /**
4
- * @module Exports {@code enablements}, a recursively defined
4
+ * Exports {@code enablements}, a recursively defined
5
5
  * JSON record defining the optimum set of intrinsics properties
6
6
  * that need to be "repaired" before hardening is applied on
7
7
  * enviromments subject to the override mistake.
8
8
  *
9
9
  * @author JF Paradis
10
10
  * @author Mark S. Miller
11
+ *
12
+ * @module
11
13
  */
12
14
 
13
15
  /**
@@ -41,10 +41,6 @@ export const tameConsole = (
41
41
  unhandledRejectionTrapping = 'report',
42
42
  optGetStackString = undefined,
43
43
  ) => {
44
- consoleTaming === 'safe' ||
45
- consoleTaming === 'unsafe' ||
46
- failFast(`unrecognized consoleTaming ${consoleTaming}`);
47
-
48
44
  let loggedErrorHandler;
49
45
  if (optGetStackString === undefined) {
50
46
  loggedErrorHandler = defaultHandler;
@@ -1,6 +1,5 @@
1
1
  import {
2
2
  FERAL_ERROR,
3
- TypeError,
4
3
  apply,
5
4
  construct,
6
5
  defineProperties,
@@ -36,16 +35,6 @@ export default function tameErrorConstructor(
36
35
  errorTaming = 'safe',
37
36
  stackFiltering = 'concise',
38
37
  ) {
39
- if (
40
- errorTaming !== 'safe' &&
41
- errorTaming !== 'unsafe' &&
42
- errorTaming !== 'unsafe-debug'
43
- ) {
44
- throw TypeError(`unrecognized errorTaming ${errorTaming}`);
45
- }
46
- if (stackFiltering !== 'concise' && stackFiltering !== 'verbose') {
47
- throw TypeError(`unrecognized stackFiltering ${stackFiltering}`);
48
- }
49
38
  const ErrorPrototype = FERAL_ERROR.prototype;
50
39
 
51
40
  const { captureStackTrace: originalCaptureStackTrace } = FERAL_ERROR;
@@ -71,10 +71,9 @@ const FILENAME_NODE_DEPENDENTS_CENSOR = /\/node_modules\//;
71
71
  // stack traces.
72
72
  const FILENAME_NODE_INTERNALS_CENSOR = /^(?:node:)?internal\//;
73
73
 
74
- // Frames within the `assert.js` package should be dropped from
75
- // concise stack traces, as these are just steps towards creating the
76
- // error object in question.
77
- const FILENAME_ASSERT_CENSOR = /\/packages\/ses\/src\/error\/assert.js$/;
74
+ // Frames within SES `assert.js` should be dropped from concise stack traces, as
75
+ // these are just steps towards creating the error object in question.
76
+ const FILENAME_ASSERT_CENSOR = /\/packages\/ses\/src\/error\/assert\.js$/;
78
77
 
79
78
  // Frames within the `eventual-send` shim should be dropped so that concise
80
79
  // deep stacks omit the internals of the eventual-sending mechanism causing
@@ -83,6 +82,10 @@ const FILENAME_ASSERT_CENSOR = /\/packages\/ses\/src\/error\/assert.js$/;
83
82
  // Endo, so this rule will be of general interest.
84
83
  const FILENAME_EVENTUAL_SEND_CENSOR = /\/packages\/eventual-send\/src\//;
85
84
 
85
+ // Frames within the `ses-ava` package should be dropped from concise stack
86
+ // traces, as they just support exposing error details to AVA.
87
+ const FILENAME_SES_AVA_CENSOR = /\/packages\/ses-ava\/src\/ses-ava-test\.js$/;
88
+
86
89
  // Any stack frame whose `fileName` matches any of these censor patterns
87
90
  // will be omitted from concise stacks.
88
91
  // TODO Enable users to configure FILENAME_CENSORS via `lockdown` options.
@@ -91,6 +94,7 @@ const FILENAME_CENSORS = [
91
94
  FILENAME_NODE_INTERNALS_CENSOR,
92
95
  FILENAME_ASSERT_CENSOR,
93
96
  FILENAME_EVENTUAL_SEND_CENSOR,
97
+ FILENAME_SES_AVA_CENSOR,
94
98
  ];
95
99
 
96
100
  // Should a stack frame with this as its fileName be included in a concise
@@ -114,34 +118,64 @@ export const filterFileName = fileName => {
114
118
  // likely url-path prefix, ending in a `/.../` should get dropped.
115
119
  // Anything to the left of the likely path text is kept.
116
120
  // Everything to the right of `/.../` is kept. Thus
117
- // `'Object.bar (/vat-v1/.../eventual-send/test/test-deep-send.js:13:21)'`
121
+ // `'Object.bar (/vat-v1/.../eventual-send/test/deep-send.test.js:13:21)'`
122
+ // simplifies to
123
+ // `'Object.bar (eventual-send/test/deep-send.test.js:13:21)'`.
124
+ //
125
+ // See thread starting at
126
+ // https://github.com/Agoric/agoric-sdk/issues/2326#issuecomment-773020389
127
+ const CALLSITE_ELLIPSIS_PATTERN1 = /^((?:.*[( ])?)[:/\w_-]*\/\.\.\.\/(.+)$/;
128
+
129
+ // The ad-hoc rule of the current pattern is that any likely-file-path or
130
+ // likely url-path prefix consisting of `.../` should get dropped.
131
+ // Anything to the left of the likely path text is kept.
132
+ // Everything to the right of `.../` is kept. Thus
133
+ // `'Object.bar (.../eventual-send/test/deep-send.test.js:13:21)'`
118
134
  // simplifies to
119
- // `'Object.bar (eventual-send/test/test-deep-send.js:13:21)'`.
135
+ // `'Object.bar (eventual-send/test/deep-send.test.js:13:21)'`.
120
136
  //
121
137
  // See thread starting at
122
138
  // https://github.com/Agoric/agoric-sdk/issues/2326#issuecomment-773020389
123
- const CALLSITE_ELLIPSES_PATTERN = /^((?:.*[( ])?)[:/\w_-]*\/\.\.\.\/(.+)$/;
139
+ const CALLSITE_ELLIPSIS_PATTERN2 = /^((?:.*[( ])?)\.\.\.\/(.+)$/;
124
140
 
125
141
  // The ad-hoc rule of the current pattern is that any likely-file-path or
126
142
  // likely url-path prefix, ending in a `/` and prior to `package/` should get
127
143
  // dropped.
128
144
  // Anything to the left of the likely path prefix text is kept. `package/` and
129
145
  // everything to its right is kept. Thus
130
- // `'Object.bar (/Users/markmiller/src/ongithub/agoric/agoric-sdk/packages/eventual-send/test/test-deep-send.js:13:21)'`
146
+ // `'Object.bar (/Users/markmiller/src/ongithub/agoric/agoric-sdk/packages/eventual-send/test/deep-send.test.js:13:21)'`
131
147
  // simplifies to
132
- // `'Object.bar (packages/eventual-send/test/test-deep-send.js:13:21)'`.
148
+ // `'Object.bar (packages/eventual-send/test/deep-send.test.js:13:21)'`.
133
149
  // Note that `/packages/` is a convention for monorepos encouraged by
134
150
  // lerna.
135
151
  const CALLSITE_PACKAGES_PATTERN = /^((?:.*[( ])?)[:/\w_-]*\/(packages\/.+)$/;
136
152
 
153
+ // The ad-hoc rule of the current pattern is that any likely-file-path or
154
+ // likely url-path prefix of the form `file://` but not `file:///` gets
155
+ // dropped.
156
+ // Anything to the left of the likely path prefix text is kept. Everything to
157
+ // the right of `file://` is kept. Thus
158
+ // `'Object.bar (file:///Users/markmiller/src/ongithub/endojs/endo/packages/eventual-send/test/deep-send.test.js:13:21)'` is unchanged but
159
+ // `'Object.bar (file://test/deep-send.test.js:13:21)'`
160
+
161
+ // simplifies to
162
+ // `'Object.bar (test/deep-send.test.js:13:21)'`.
163
+ // The reason is that `file:///` usually precedes an absolute path which is
164
+ // clickable without removing the `file:///`, whereas `file://` usually precedes
165
+ // a relative path which, for whatever vscode reason, is not clickable until the
166
+ // `file://` is removed.
167
+ const CALLSITE_FILE_2SLASH_PATTERN = /^((?:.*[( ])?)file:\/\/([^/].*)$/;
168
+
137
169
  // The use of these callSite patterns below assumes that any match will bind
138
170
  // capture groups containing the parts of the original string we want
139
171
  // to keep. The parts outside those capture groups will be dropped from concise
140
172
  // stacks.
141
173
  // TODO Enable users to configure CALLSITE_PATTERNS via `lockdown` options.
142
174
  const CALLSITE_PATTERNS = [
143
- CALLSITE_ELLIPSES_PATTERN,
175
+ CALLSITE_ELLIPSIS_PATTERN1,
176
+ CALLSITE_ELLIPSIS_PATTERN2,
144
177
  CALLSITE_PACKAGES_PATTERN,
178
+ CALLSITE_FILE_2SLASH_PATTERN,
145
179
  ];
146
180
 
147
181
  // For a stack frame that should be included in a concise stack trace, if
@@ -149,6 +183,9 @@ const CALLSITE_PATTERNS = [
149
183
  // possibly-shorter stringified stack frame that should be shown instead.
150
184
  // Exported only so it can be unit tested.
151
185
  // TODO Move so that it applies not just to v8.
186
+ /**
187
+ * @param {string} callSiteString
188
+ */
152
189
  export const shortenCallSiteString = callSiteString => {
153
190
  for (const filter of CALLSITE_PATTERNS) {
154
191
  const match = regexpExec(filter, callSiteString);
@@ -175,18 +212,24 @@ export const tameV8ErrorConstructor = (
175
212
 
176
213
  const originalCaptureStackTrace = OriginalError.captureStackTrace;
177
214
 
215
+ const omitFrames =
216
+ stackFiltering === 'concise' || stackFiltering === 'omit-frames';
217
+
218
+ const shortenPaths =
219
+ stackFiltering === 'concise' || stackFiltering === 'shorten-paths';
220
+
178
221
  // const callSiteFilter = _callSite => true;
179
222
  const callSiteFilter = callSite => {
180
- if (stackFiltering === 'verbose') {
181
- return true;
223
+ if (omitFrames) {
224
+ // eslint-disable-next-line @endo/no-polymorphic-call
225
+ return filterFileName(callSite.getFileName());
182
226
  }
183
- // eslint-disable-next-line @endo/no-polymorphic-call
184
- return filterFileName(callSite.getFileName());
227
+ return true;
185
228
  };
186
229
 
187
230
  const callSiteStringifier = callSite => {
188
231
  let callSiteString = `${callSite}`;
189
- if (stackFiltering === 'concise') {
232
+ if (shortenPaths) {
190
233
  callSiteString = shortenCallSiteString(callSiteString);
191
234
  }
192
235
  return `\n at ${callSiteString}`;
@@ -14,6 +14,9 @@ import {
14
14
  matchAllSymbol,
15
15
  regexpPrototype,
16
16
  globalThis,
17
+ assign,
18
+ AsyncGeneratorFunctionInstance,
19
+ ArrayBuffer,
17
20
  } from './commons.js';
18
21
  import { InertCompartment } from './compartment.js';
19
22
 
@@ -95,20 +98,6 @@ export const getAnonymousIntrinsics = () => {
95
98
 
96
99
  const Generator = GeneratorFunction.prototype;
97
100
 
98
- // 25.3.1 The AsyncGeneratorFunction Constructor
99
-
100
- // eslint-disable-next-line no-empty-function
101
- async function* AsyncGeneratorFunctionInstance() {}
102
- const AsyncGeneratorFunction = getConstructorOf(
103
- AsyncGeneratorFunctionInstance,
104
- );
105
-
106
- // 25.3.2.2 AsyncGeneratorFunction.prototype
107
- const AsyncGenerator = AsyncGeneratorFunction.prototype;
108
- // 25.5.1 Properties of the AsyncGenerator Prototype Object
109
- const AsyncGeneratorPrototype = AsyncGenerator.prototype;
110
- const AsyncIteratorPrototype = getPrototypeOf(AsyncGeneratorPrototype);
111
-
112
101
  // 25.7.1 The AsyncFunction Constructor
113
102
 
114
103
  // eslint-disable-next-line no-empty-function
@@ -119,10 +108,6 @@ export const getAnonymousIntrinsics = () => {
119
108
  '%InertFunction%': InertFunction,
120
109
  '%ArrayIteratorPrototype%': ArrayIteratorPrototype,
121
110
  '%InertAsyncFunction%': AsyncFunction,
122
- '%AsyncGenerator%': AsyncGenerator,
123
- '%InertAsyncGeneratorFunction%': AsyncGeneratorFunction,
124
- '%AsyncGeneratorPrototype%': AsyncGeneratorPrototype,
125
- '%AsyncIteratorPrototype%': AsyncIteratorPrototype,
126
111
  '%Generator%': Generator,
127
112
  '%InertGeneratorFunction%': GeneratorFunction,
128
113
  '%IteratorPrototype%': IteratorPrototype,
@@ -135,6 +120,27 @@ export const getAnonymousIntrinsics = () => {
135
120
  '%InertCompartment%': InertCompartment,
136
121
  };
137
122
 
123
+ if (AsyncGeneratorFunctionInstance !== undefined) {
124
+ // 25.3.1 The AsyncGeneratorFunction Constructor
125
+
126
+ const AsyncGeneratorFunction = getConstructorOf(
127
+ AsyncGeneratorFunctionInstance,
128
+ );
129
+
130
+ // 25.3.2.2 AsyncGeneratorFunction.prototype
131
+ const AsyncGenerator = AsyncGeneratorFunction.prototype;
132
+ // 25.5.1 Properties of the AsyncGenerator Prototype Object
133
+ const AsyncGeneratorPrototype = AsyncGenerator.prototype;
134
+ const AsyncIteratorPrototype = getPrototypeOf(AsyncGeneratorPrototype);
135
+
136
+ assign(intrinsics, {
137
+ '%AsyncGenerator%': AsyncGenerator,
138
+ '%InertAsyncGeneratorFunction%': AsyncGeneratorFunction,
139
+ '%AsyncGeneratorPrototype%': AsyncGeneratorPrototype,
140
+ '%AsyncIteratorPrototype%': AsyncIteratorPrototype,
141
+ });
142
+ }
143
+
138
144
  if (globalThis.Iterator) {
139
145
  intrinsics['%IteratorHelperPrototype%'] = getPrototypeOf(
140
146
  // eslint-disable-next-line @endo/no-polymorphic-call
@@ -161,5 +167,15 @@ export const getAnonymousIntrinsics = () => {
161
167
  );
162
168
  }
163
169
 
170
+ const ab = new ArrayBuffer(0);
171
+ // @ts-expect-error TODO How do I add sliceToImmutable to ArrayBuffer type?
172
+ // eslint-disable-next-line @endo/no-polymorphic-call
173
+ const iab = ab.sliceToImmutable();
174
+ const iabProto = getPrototypeOf(iab);
175
+ if (iabProto !== ArrayBuffer.prototype) {
176
+ // In a native implementation, these will be the same prototype
177
+ intrinsics['%ImmutableArrayBufferPrototype%'] = iabProto;
178
+ }
179
+
164
180
  return intrinsics;
165
181
  };