hax / hax/hax.github.com

V8引擎迭代器bug一则

Open
#51 0 comments 2 reactions 0 assignees View on GitHub
Dominant language
HTML
Stars
464
Forks
27
PR merge metrics
No merged PRs in 30d

Description

```js
{ // code 1
const [a, b, c, ...d] = test()
print(d[0], d[1])
}
{ // code 2
const [a, b, c, d, e] = test()
print(d, e)
}
```

上述两段代码显然我们期望结果是一样的。

然而

```js
function test() {
let i = 0
return {
[Symbol.iterator]() {
return {
next() {
return {value: ++i, done: i % 3 === 0}
},
}
}
}
}
```

结果 V8 前者返回 `4, 5`,后者返回 `undefined, undefined`。显然V8的实现有bug。

其他引擎中,SpiderMonkey、JavaScriptCore、Hermes、engine262 的结果是符合预期的(都是`undefined, undefined`)。XS 和 Chakra 返回的都是 `4, 5` 好歹是一致的。

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.