Skip to content

Spread elements in array literals and call arguments are iterated after later elements are evaluated #5316

Open

Description

@trackoor

Spread elements in array literals and function call argument lists are not iterated until after subsequent elements or arguments in the list have been evaluated. As a result, side effects in later expressions mutate the iterable before the spread runs.

Per ECMA-262 ArrayAccumulation and ArgumentListEvaluation, a SpreadElement must be evaluated and iterated to completion before evaluating the next element or argument in the list.

JerryScript revision

v3.0.0, b706935 (master)

Build platform

macOS 26.3 (Darwin 25.3.0 arm64)

Build steps
tools/build.py --clean --debug
Test case
var a = [1];
print(JSON.stringify([...a, a.push(2)]));

var b = [1];
print(JSON.stringify(Array(...b, b.push(2))));
Execution steps
build/bin/jerry testcase.js
Output
[1,2,2]
[1,2,2]
Expected behavior
[1,2]
[1,2]

Credit: https://ucsbplse.github.io/

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions