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

yield*, strings #157

Closed
sebmck opened this issue Dec 18, 2014 · 2 comments
Closed

yield*, strings #157

sebmck opened this issue Dec 18, 2014 · 2 comments

Comments

@sebmck
Copy link
Contributor

sebmck commented Dec 18, 2014

Currently it's not possible to yield non-objects such as primitives etc due to the use of in in the runtime. May be necessary to just use Object.prototype.hasOwnProperty.

For example the following taken from compat-table wont work:

var iterator = (function* generator() {
  yield* "56";
}());
var item = iterator.next();
var passed = item.value === "5" && item.done === false;
item = iterator.next();
passed    &= item.value === "6" && item.done === false;
item = iterator.next();
passed    &= item.value === undefined && item.done === true;
return passed;
@benjamn
Copy link
Collaborator

benjamn commented Dec 18, 2014

Hmm, but String.prototype is where the Symbol.iterator property lives, so Object.prototype.hasOwnProperty("asdf", Symbol.iterator) will be false. And that's true for most iterable objects.

It might work to fall through to the case that uses .length to synthesize an iterator object, but I'd really prefer to use iterable[Symbol.iterator]() when it's available.

Perhaps we can just test that iterable[Symbol.iterator] !== undefined.

@sebmck
Copy link
Contributor Author

sebmck commented Dec 18, 2014

@benjamn Ah right, duh. I misinterpreted the use of in in this case.

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

No branches or pull requests

2 participants