Skip to content
This repository has been archived by the owner on Feb 1, 2025. It is now read-only.

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
Contributor

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 subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants