Skip to content

runtime: typed-array out-of-bounds index returns 0 instead of undefined #6088

Description

@proggeramlug

Symptom

Reading a typed array out of bounds returns 0 instead of undefined:

const t = new Uint8Array([5, 6, 7]);
console.log(t[9]);          // node: undefined   perry: 0
const a: any = t;
console.log(a[9]);          // node: undefined   perry: 0

Reproduces for both a statically-typed Uint8Array receiver and an any-typed
one (so it is not generator/CPS-specific). In-bounds reads are correct
(t[0] === 5).

Notes

Spec: an integer-indexed exotic object returns undefined for a
CanonicalNumericIndexString that is out of [0, length). The dynamic path
(js_dyn_index_getjs_typed_array_index_get_dynamic) and the inline
fast/slow typed-array get appear to fall through to a 0 default on OOB rather
than undefined.

Found tangentially while fixing #6067 (generator local string OOB index);
independent of that (string-only) fix. Low urgency — filing for tracking.

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