Array iterator's next() reads [[ArrayLikeNextIndex]] after reading length
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 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時間
- マージ済み PR(30日)
- 19
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- 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 日以内に返信