🔗 Iterator helpers が使えなくなった
Chrome 122 (現 dev) から再度使えるようになるようです
https://chromestatus.com/feature/5102502917177344
ウェブ互換問題に対応するため 少し特別な扱いをしてるようです
toStringTag に違いがあるみたいです
https://github.com/tc39/proposal-iterator-helpers/pull/287
https://github.com/tc39/test262/pull/3970/files
実際に getOwnPropertyDescriptor で他のクラスと比較してみると
Object.getOwnPropertyDescriptor(Map.prototype, Symbol.toStringTag)
// {value: 'Map', writable: false, enumerable: false, configurable: true}
Object.getOwnPropertyDescriptor(Iterator.prototype, Symbol.toStringTag)
// {enumerable: false, configurable: true, get: ƒ, set: ƒ}
ほかは Map みたいに writable が false で value に値が入ってます
Iterator では getter/setter になっています
通常利用では気にする必要ないかと思いますが 特殊なもののようです
気になったので prototype 構造がどうなってるか少し調べてみました
Iterator.prototype.__proto__ === Object.prototype
// true
const i1 = [].values()
const i2 = i1.take(1)
const i3 = (function*(){})()
const i4 = i3.take(1)
const i5 = i3.map(x => x)
// Iterator Helpers で得られるオブジェクトの prototype は
// 元やメソッドが違っても同じ
i2.__proto__ === i4.__proto__
// true
i2.__proto__ === i5.__proto__
// true
// Iterator Helpers とそれ以外は別
i1.__proto__ === i2.__proto__
// false
// いずれも Iterator を継承してる
i1.__proto__.__proto__ === Iterator.prototype
// true
i2.__proto__.__proto__ === Iterator.prototype
// true
i3.__proto__.__proto__.__proto__ === Iterator.prototype
// true
Iterator を継承したオブジェクトの toStringTag は他と同じで writable が false で value に値が入ってる
Object.getOwnPropertyDescriptor(i1.__proto__, Symbol.toStringTag)
// {value: 'Array Iterator', writable: false, enumerable: false, configurable: true}
Object.getOwnPropertyDescriptor(i2.__proto__, Symbol.toStringTag)
// {value: 'Iterator Helper', writable: false, enumerable: false, configurable: true}
Object.getOwnPropertyDescriptor(i3.__proto__.__proto__, Symbol.toStringTag)
// {value: 'Generator', writable: false, enumerable: false, configurable: true}