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

No consistency of enumerable in the next method #1073

Open
jimmywarting opened this issue Dec 2, 2021 · 1 comment
Open

No consistency of enumerable in the next method #1073

jimmywarting opened this issue Dec 2, 2021 · 1 comment

Comments

@jimmywarting
Copy link

jimmywarting commented Dec 2, 2021

I run some test from WPT on a polyfill of mine
And one of the test made sure that the next() method was enumerable.
My polyfill isn't exact 100% compatible but it's just good enough to get the job done...

I tough to my self... how come that it's not compliant to my generator function that i'm using...? it's not like I'm reinventing the hole Iterator class with next, throw, return methods... I'm using something like: class Polyfill { *values() {...} }

So i run some test agains on some built in classes that exist on the web/js and run this test

for (const Klass of [Headers, URLSearchParams, Array, Map, Set, Uint8Array]) {
  const iterator = new Klass().values()
  const prototype = Object.getPrototypeOf(iterator)
  const descriptor = Object.getOwnPropertyDescriptor(prototype, 'next')
  console.log(descriptor.enumerable)
}

function * foo() {}
const prototype = Object.getPrototypeOf(Object.getPrototypeOf(foo()))
const descriptor = Object.getOwnPropertyDescriptor(prototype, 'next')
console.log(descriptor.enumerable)

yields: (2) true, (5) false

How come that some next() methods are enumerable and some are not? it's so confusing and inconsistent. when should they be enumerable and when shouldn't they?
could this not please be normalized through out everything that is iterable to make life easier and more consistent?

@TimothyGu
Copy link
Member

All Web IDL methods are enumerable (e.g., Headers.prototype.get), which is different from ECMAScript (e.g., Map.prototype.get). What you see in iterators is just an extension of this difference. It’s too late to change enumerability for all objects, so the most we could do is make it consistent within Web IDL.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants