Skip to content

Read the array iterator index and array before the length - #647

Open
feroxbyte wants to merge 1 commit into
bellard:masterfrom
feroxbyte:fix-array-iterator-index
Open

feroxbyte wants to merge 1 commit into
bellard:masterfrom
feroxbyte:fix-array-iterator-index

Conversation

@feroxbyte

Copy link
Copy Markdown

%ArrayIteratorPrototype%.next reads the index and the array (steps 4 and 6) before LengthOfArrayLike (step 9.a), whose getter can call next() on the same iterator. QuickJS read them after the length, so the outer call skipped an index, or returned done when the nested calls had finished the iteration.

let it, nested = false, inner;
const o = { get length() {
    if (!nested) { nested = true; inner = it.next().value; }
    return 2;
} };
it = Array.prototype.keys.call(o);
const outer = it.next().value;
console.log(inner, outer);  // 0 0 (QuickJS: 0 1)

test262: built-ins/ArrayIteratorPrototype/next/next-reads-index-before-length.js. With test262 at 44cb921, the only change is that this test passes, also with CONFIG_ASAN=y. make test passes (test_intl.js needs TZ=UTC here, with or without this change).

%ArrayIteratorPrototype%.next reads [[ArrayLikeNextIndex]] and
[[IteratedArrayLike]] before LengthOfArrayLike, whose getter can call
next() on the same iterator. Reading them after the length made the
outer call skip an index, or end early when the nested calls finished
the iteration.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant