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

The async-iterator-helpers shim makes its own AsyncIteratorPrototype rather that enhancing the real one. #1267

Closed
erights opened this issue Jul 6, 2023 · 3 comments
Labels

Comments

@erights
Copy link

erights commented Jul 6, 2023

For the sync iterator-helpers shim, it correctly finds and enhances the existing IteratorPrototype if there.

However, for the async-iterator-helpers shim, it does not succeed at finding the existing one. It therefore makes its own, rather than enhancing the existing one.

This bug causes the SES shim to fail to initialize during lockdown with

TypeError('Conflicting bindings of %AsyncIteratorPrototype%')

(Thus SES does correctly fails safe.) See endojs/endo#1655 (comment)

import 'core-js/actual/iterator/index.js';
import 'core-js/actual/async-iterator/index.js';

const { getPrototypeOf } = Object;

// /////////////////////////////////////////////////////////////////
// See that the synchronous case works, i.e., that it reuses the
// existing IteratorPrototype if there is one.

// Normal JS that also works without core-js

const ArrayIterator = [][Symbol.iterator]();

const ArrayIteratorPrototype = getPrototypeOf(ArrayIterator);

// This is the real one.
const IteratorPrototype = getPrototypeOf(ArrayIteratorPrototype);

// End normal JS

console.log(Iterator.prototype === IteratorPrototype);
// Should return true, and does


// /////////////////////////////////////////////////////////////////
// See that the asynchronous case does not reuse the existing
// AsyncIteratorPrototype if there is one.

// Normal JS that also works without core-js

async function* AsyncGeneratorFunctionInstance() {}
const AsyncGeneratorFunction = getPrototypeOf(
  AsyncGeneratorFunctionInstance,
).constructor;

const AsyncGenerator = AsyncGeneratorFunction.prototype;
const AsyncGeneratorPrototype = AsyncGenerator.prototype;

// This is the real one.
const AsyncIteratorPrototype = getPrototypeOf(AsyncGeneratorPrototype);

// End normal JS

console.log(AsyncIterator.prototype === AsyncIteratorPrototype);
// Should return true, but does return false
@erights erights changed the title The async-iterator-helpers makes its own AsyncIteratorPrototype rather that enhancing the real one. The async-iterator-helpers shim makes its own AsyncIteratorPrototype rather that enhancing the real one. Jul 6, 2023
@zloirock
Copy link
Owner

zloirock commented Jul 6, 2023

It's not a bug, see this note.

@mhofman
Copy link

mhofman commented Jul 6, 2023

I've confirmed that USE_FUNCTION_CONSTRUCTOR does work as intended. Thanks for pointing that out.

@zloirock
Copy link
Owner

zloirock commented Jul 6, 2023

I think that it can be closed.

@zloirock zloirock closed this as completed Jul 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants