Skip to content

Array destructuring rest over a typed array binds a typed array instead of a fresh Array (interpreter) #781

@nickna

Description

@nickna

Summary

A rest element over a typed-array source binds a typed array rather than a fresh Array, unlike ECMA-262 (array destructuring collects the rest into a new Array via the iterator protocol):

const [a, ...rest] = new Uint8Array([1, 2, 3]);
console.log(rest, Array.isArray(rest));
// SharpTS (interp): Uint8Array(2) [2, 3]  false
// tsc/JS         : [2, 3]                  true

This is the typed-array analog of #753 (which fixed the string case). Typed arrays stay on the index/slice fast path in Interpreter.NormalizeArrayDestructureSource (and the compiled ArrayDestructureSource IList pass-through), and TypedArray.prototype.slice yields a typed array.

Fix shape

Mirror the #753 string fix: drop SharpTSTypedArray/SharpTSBuffer from the destructure pass-through so the source materializes through GetIterableElements into a SharpTSArray (a small copy per typed-array destructure; the issue author for #753 accepted the equivalent trade-off). Non-rest element values are unchanged. NOTE: compiled-mode typed arrays are blocked by a separate constructor bug — see the companion issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions