Skip to content

Gap: Int32Array/Float64Array(n) constructor sets length=0; Uint8ClampedArray doesn't clamp #157

@proggeramlug

Description

@proggeramlug

Summary

test_gap_typed_arrays.ts surfaces three related bugs in typed-array constructors + bounded stores.

Repro

const i1 = new Int32Array(3);
i1[0] = -100; i1[1] = 0; i1[2] = 2147483647;
console.log(i1.length);                    // expected 3, perry: 0

const f1 = new Float64Array(3);
console.log(f1.length);                    // expected 3, perry: 0

const clamped = new Uint8ClampedArray(3);
clamped[0] = 300;  // expected 255 (clamped)
clamped[1] = -10;  // expected 0 (clamped)
clamped[2] = 128;
console.log(clamped[0], clamped[1], clamped[2]);
// expected: 255 0 128
// perry:    300 -10 128

Scope

  • new Int32Array(n) / new Float64Array(n) must allocate with length = n and zero-fill (currently appears to default to empty)
  • new Uint8ClampedArray(n) stores: store(i, v) must clamp via Math.min(255, Math.max(0, Math.round(v))) — NOT truncate-wrap like Uint8Array. Perry is storing raw values.

Impact

One of six currently-failing gap tests (baseline 22/28). Touches typed-array allocation + the per-element store path in the runtime's typed_array module. Likely straightforward if the backing implementation already exists; just the length field and clamping arithmetic.

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