Skip to content

Compiled: new Uint8Array([...]) crashes (InvalidCastException in CreateUint8ArrayFromObject) #782

@nickna

Description

@nickna

Summary

Constructing a typed array from an array literal crashes in compiled mode (independent of destructuring):

const x = new Uint8Array([1, 2, 3]);
console.log(x[0], x.length);
Unhandled exception. System.InvalidCastException: Unable to cast object of type '$Array' to type 'System.IConvertible'.
   at System.Convert.ToDouble(Object value)
   at $Runtime.CreateUint8ArrayFromObject(Object)
   at $Program.Main()

The interpreter runs it correctly. Compiled CreateUint8ArrayFromObject calls Convert.ToDouble on the whole $Array instead of iterating its elements. Compiled spread of a typed array is also unsupported (Spread expression must be an iterable type ... got 'Uint8Array').

Discovered

While implementing #753/#754 (testing typed-array rest destructuring). Pre-existing and independent — the repro uses neither destructuring nor spread. Blocks the compiled side of the typed-array-rest 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