Array iterator's next() reads [[ArrayLikeNextIndex]] after reading length
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 58/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- c, javascript
调研方向
Start with js_array_iterator_next in quickjs.c, especially the js_get_length32 call and the later read of it->idx. Compare the order with the %ArrayIteratorPrototype%.next steps cited in the issue, then run the reproduction with qjs sample.js; done when it prints 0 0 and the iterator behavior matches the specified order.
由索引模型根据 Issue 内容生成。
描述
Reproduction
// sample.js
var iterator;
var nested = false;
var nestedKey;
var arrayLike = {
get length() {
if (!nested) {
nested = true;
// nested next() while the outer next() is reading length
nestedKey = iterator.next().value;
}
return 2;
}
};
iterator = Array.prototype.keys.call(arrayLike);
var outerKey = iterator.next().value;
print(nestedKey + " " + outerKey);
Expected
V8 (16.0.102):
$ v8 sample.js
0 0
Actual (QuickJS-ng)
$ qjs sample.js
0 1
Spec
%ArrayIteratorPrototype%.next reads the iterator's index before it reads the length:
6. Let index be iteratorObj.[[ArrayLikeNextIndex]].
...
9.a. Let length be ? LengthOfArrayLike(array).
...
11. Set iteratorObj.[[ArrayLikeNextIndex]] to index + 1.
The outer iterator.next() stores [[ArrayLikeNextIndex]] (0) in index (step 6) and then reads length (step 9.a, through LengthOfArrayLike). The length getter calls iterator.next() once more. This nested call also stores 0 in its own index, returns 0, and sets [[ArrayLikeNextIndex]] to 1. When it returns, the outer call continues with the index it stored earlier, so it also returns 0.
QuickJS-ng reads [[ArrayLikeNextIndex]] after reading length, so the outer call sees the 1 written by the nested call and returns 1.
In js_array_iterator_next, QuickJS-ng gets the length with js_get_length32 first and reads it->idx after that:
if (js_get_length32(ctx, &len, it->obj)) {
...
}
...
idx = it->idx;
...
it->idx = idx + 1;
JavaScriptCore, SpiderMonkey and GraalJS agree with V8. XS has the same behavior (Moddable-OpenSource/moddable#1837).
Versions
- QuickJS-ng: 0.18.0
- V8: 16.0.102
- 主要语言
- C
- 星标
- 3.9k
- 派生
- 389
- 平均合并
- 2 天 2 小时
- 30 天内合并 PR
- 19
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
quickjs-ng/quickjs 的其他 Issue
-
难度 1/5 1 小时以内 新手友好度 88/100
quickjs-ng/quickjs#1959 ·
维护者通常 1 天内回复
-
JS_SetPropertyInternal2 loses the value when a lazy property on the prototype runs out of memory可能已有人在做 @TheNetherWatcher 于 6 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
quickjs-ng/quickjs#1852 ·
维护者通常 1 天内回复
-
Object.prototype.propertyIsEnumerable converts `this` before the property key可能已有人在做 @SomSamantray 于 48 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 72/100
quickjs-ng/quickjs#1772 ·
维护者通常 1 天内回复
-
Slow compilation of large lexical scopes可能已有人在做 @0x5457 于 3 天前认领。 未关闭
难度 4/5 3-5 天 新手友好度 25/100
quickjs-ng/quickjs#1953 ·
维护者通常 1 天内回复
-
JS_ToCStringLen2 contract is documented wrong可能已有人在做 @bnoordhuis 于 3 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 45/100
quickjs-ng/quickjs#1950 · 1 条评论 ·
维护者通常 1 天内回复
查看 quickjs-ng/quickjs 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 75/100
维护者通常 2 天内回复
-
难度 1/5 1 小时以内 新手友好度 62/100
libsndfile/libsndfile#1238 ·
-
难度 2/5 1-3 小时 新手友好度 85/100
DaveGamble/cJSON#1143 ·
-
Claude:Bug GPT:Bug triage
难度 2/5 1-3 小时 新手友好度 65/100
open5gs/open5gs#5161 · 2 条评论 ·
维护者通常 1 天内回复
-
难度 1/5 1-3 小时 新手友好度 72/100
维护者通常 2 天内回复