Skip to content

Commit 31298f7

Browse files
authored
fix(ses): fixup async iterator helpers (#1670)
2 parents 7f2d29f + 0c56f2d commit 31298f7

6 files changed

+29
-37
lines changed

packages/ses/src/get-anonymous-intrinsics.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ export const getAnonymousIntrinsics = () => {
146146
);
147147
}
148148

149-
if (globalThis.AsyncInterator) {
149+
if (globalThis.AsyncIterator) {
150150
intrinsics['%AsyncIteratorHelperPrototype%'] = getPrototypeOf(
151151
// eslint-disable-next-line @endo/no-polymorphic-call
152152
globalThis.AsyncIterator.from([]).take(0),

packages/ses/src/permits.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1317,7 +1317,7 @@ export const permitted = {
13171317

13181318
// https://github.com/tc39/proposal-async-iterator-helpers
13191319
'%AsyncIteratorHelperPrototype%': {
1320-
'[[Proto]]': 'Async%IteratorPrototype%',
1320+
'[[Proto]]': '%AsyncIteratorPrototype%',
13211321
next: fn,
13221322
return: fn,
13231323
'@@toStringTag': 'string',
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import configurator from 'core-js/configurator.js';
2+
3+
configurator({ USE_FUNCTION_CONSTRUCTOR: true });
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import module from 'node:module';
2+
3+
module.wrapper[0] += '"use strict";';

packages/ses/test/test-anticipate-async-iterator-helpers-shimmed.js

+17-20
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,23 @@
1-
// KLUDGE HAZARD The core-js shims are written as sloppy code
2-
// and so introduce sloppy functions.
1+
import './enforce-cjs-strict.js';
2+
import './core-js-configuration.js';
33
import 'core-js/actual/async-iterator/index.js';
4-
import test from 'ava';
54
import '../index.js';
5+
import './lockdown-safe.js';
6+
import test from 'ava';
67

7-
// KLUDGE HAZARD only for testing with the sloppy modules of the
8-
// core-js iterator shim.
9-
// We mutate the permits to tolerates the sloppy functions for testing
10-
// by sacrificing security. The caller and arguments properties of
11-
// sloppy functions violate ocap encapsulation rules.
12-
import { AsyncFunctionInstance } from '../src/permits.js';
13-
14-
AsyncFunctionInstance.arguments = {};
15-
AsyncFunctionInstance.caller = {};
16-
17-
// Skipped because the core-js shim seems to miss the
18-
// actual %AsyncIteratorPrototype%,
19-
// so it creates a new one, causing us to fail because lockdown correctly
20-
// detects the conflicting definitions.
21-
// TODO report the bug to core-js
22-
test.skip('shimmed async-iterator helpers', t => {
23-
lockdown();
8+
test('shimmed async-iterator helpers', async t => {
9+
t.deepEqual(
10+
await (async function* g(i) {
11+
// eslint-disable-next-line no-plusplus
12+
while (true) yield i++;
13+
})(1)
14+
.drop(1)
15+
.take(5)
16+
.filter(it => it % 2)
17+
.map(it => it ** 2)
18+
.toArray(),
19+
[9, 25],
20+
);
2421

2522
const AsyncIteratorHelperPrototype = Object.getPrototypeOf(
2623
AsyncIterator.from([]).take(0),

packages/ses/test/test-anticipate-iterator-helpers-shimmed.js

+4-15
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,11 @@
1-
// KLUDGE HAZARD The core-js shims are written as sloppy code
2-
// and so introduce sloppy functions.
1+
import './enforce-cjs-strict.js';
2+
import './core-js-configuration.js';
33
import 'core-js/actual/iterator/index.js';
4-
import test from 'ava';
54
import '../index.js';
6-
7-
// KLUDGE HAZARD only for testing with the sloppy modules of the
8-
// core-js iterator shim.
9-
// We mutate the permits to tolerates the sloppy functions for testing
10-
// by sacrificing security. The caller and arguments properties of
11-
// sloppy functions violate ocap encapsulation rules.
12-
import { FunctionInstance } from '../src/permits.js';
13-
14-
FunctionInstance.arguments = {};
15-
FunctionInstance.caller = {};
5+
import './lockdown-safe.js';
6+
import test from 'ava';
167

178
test('shimmed iterator helpers', t => {
18-
lockdown();
19-
209
t.deepEqual(
2110
(function* g(i) {
2211
// eslint-disable-next-line no-plusplus

0 commit comments

Comments
 (0)