Skip to content

runtime: reading a field of an out-of-bounds array element returns undefined instead of throwing TypeError #7153

Description

@proggeramlug

PR #7149 added test-files/test_gap_repsel_ptr_shape_elements.ts and had to
drop one case from it, because it is red on main:

class Row { id: number; /* … */ }
const short: Row[] = [];
short.push(new Row(9, "s", 9));
const missing = short[5];   // undefined
console.log(missing.id);
output
Node 26.5.1 TypeError: Cannot read properties of undefined (reading 'id')
Perry (main, and PERRY_PTR_SHAPE_LOCALS=0) undefined

Reproduced against the base commit and with the representation-selection knob
off, so it is not a Ptr<Shape> defect — the guarded field-read path
itself is not throwing for an undefined receiver when the binding carries a
class annotation.

The annotation looks load-bearing: const missing: Row = short[5] makes the
declared type Named("Row"), and the field read appears to take a path that
assumes the receiver is an object rather than going through
js_object_get_field_by_name_f64's ToObject check. Worth confirming whether an
Any-typed binding throws correctly, which would localise it to the typed
fast path.

This is a silent wrong answer, not a crash, which is the worse shape: the
program continues with undefined where Node would have aborted.

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