Skip to content
This repository was archived by the owner on Oct 24, 2023. It is now read-only.
This repository was archived by the owner on Oct 24, 2023. It is now read-only.

Seemingly inconsistent behavior in TypedArray constructor #57

Closed
@jugglinmike

Description

@jugglinmike

When constructing a TypedArray from an existing TypedArray whose underlying ArrayBuffer is out-of-bounds, an error is thrown only if the array being created is of a different type.

const resizableAb = new ArrayBuffer(100, {maxByteLength: 100});
const source = new Int8Array(resizableAb, 50);

resizableAb.resize(1);
// The `source` array is now out-of-bounds.

new Int8Array(source);  // creates an Int8Array of length 0
new Uint8Array(source); // throws a TypeError

I can see a rationale for either behavior, but I'm having trouble explaining why both should be observed based on the constructor. Is this intentional?

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