Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ses): fixup async iterator helpers #1670

Merged
merged 3 commits into from
Jul 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/ses/src/get-anonymous-intrinsics.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export const getAnonymousIntrinsics = () => {
);
}

if (globalThis.AsyncInterator) {
if (globalThis.AsyncIterator) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops! Thanks for catching this.

intrinsics['%AsyncIteratorHelperPrototype%'] = getPrototypeOf(
// eslint-disable-next-line @endo/no-polymorphic-call
globalThis.AsyncIterator.from([]).take(0),
Expand Down
2 changes: 1 addition & 1 deletion packages/ses/src/permits.js
Original file line number Diff line number Diff line change
Expand Up @@ -1317,7 +1317,7 @@ export const permitted = {

// https://github.com/tc39/proposal-async-iterator-helpers
'%AsyncIteratorHelperPrototype%': {
'[[Proto]]': 'Async%IteratorPrototype%',
'[[Proto]]': '%AsyncIteratorPrototype%',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops! Thanks for catching this too.

next: fn,
return: fn,
'@@toStringTag': 'string',
Expand Down
3 changes: 3 additions & 0 deletions packages/ses/test/core-js-configuration.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import configurator from 'core-js/configurator.js';

configurator({ USE_FUNCTION_CONSTRUCTOR: true });
3 changes: 3 additions & 0 deletions packages/ses/test/enforce-cjs-strict.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import module from 'node:module';

module.wrapper[0] += '"use strict";';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Frankly, much less painful than I feared ;)

37 changes: 17 additions & 20 deletions packages/ses/test/test-anticipate-async-iterator-helpers-shimmed.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,23 @@
// KLUDGE HAZARD The core-js shims are written as sloppy code
// and so introduce sloppy functions.
import './enforce-cjs-strict.js';
import './core-js-configuration.js';
import 'core-js/actual/async-iterator/index.js';
import test from 'ava';
import '../index.js';
import './lockdown-safe.js';
import test from 'ava';

// KLUDGE HAZARD only for testing with the sloppy modules of the
// core-js iterator shim.
// We mutate the permits to tolerates the sloppy functions for testing
// by sacrificing security. The caller and arguments properties of
// sloppy functions violate ocap encapsulation rules.
import { AsyncFunctionInstance } from '../src/permits.js';

AsyncFunctionInstance.arguments = {};
AsyncFunctionInstance.caller = {};

// Skipped because the core-js shim seems to miss the
// actual %AsyncIteratorPrototype%,
// so it creates a new one, causing us to fail because lockdown correctly
// detects the conflicting definitions.
// TODO report the bug to core-js
test.skip('shimmed async-iterator helpers', t => {
lockdown();
test('shimmed async-iterator helpers', async t => {
t.deepEqual(
await (async function* g(i) {
// eslint-disable-next-line no-plusplus
while (true) yield i++;
})(1)
.drop(1)
.take(5)
.filter(it => it % 2)
.map(it => it ** 2)
.toArray(),
[9, 25],
);

const AsyncIteratorHelperPrototype = Object.getPrototypeOf(
AsyncIterator.from([]).take(0),
Expand Down
19 changes: 4 additions & 15 deletions packages/ses/test/test-anticipate-iterator-helpers-shimmed.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,11 @@
// KLUDGE HAZARD The core-js shims are written as sloppy code
// and so introduce sloppy functions.
import './enforce-cjs-strict.js';
import './core-js-configuration.js';
import 'core-js/actual/iterator/index.js';
import test from 'ava';
import '../index.js';

// KLUDGE HAZARD only for testing with the sloppy modules of the
// core-js iterator shim.
// We mutate the permits to tolerates the sloppy functions for testing
// by sacrificing security. The caller and arguments properties of
// sloppy functions violate ocap encapsulation rules.
import { FunctionInstance } from '../src/permits.js';

FunctionInstance.arguments = {};
FunctionInstance.caller = {};
import './lockdown-safe.js';
import test from 'ava';

test('shimmed iterator helpers', t => {
lockdown();

t.deepEqual(
(function* g(i) {
// eslint-disable-next-line no-plusplus
Expand Down