Stage 1
Classification: API Change
Human Validated: KW
Title: DataView get/set Uint8Clamped methods
Authors: Jordan Harband
Champions: Jordan Harband
Last Presented: July 2023
Stage Upgrades:
Stage 1: 2023-07-15
Stage 2: NA
Stage 2.7: NA
Stage 3: NA
Stage 4: NA
Last Commit: 2024-10-10
Topics: arrays numbers
Keywords: typedarray dataview uint8
GitHub Link: https://github.com/tc39/proposal-dataview-get-set-uint8clamped
GitHub Note Link: https://github.com/tc39/notes/blob/HEAD/meetings/2023-07/july-13.md#dataview-getset-uint8clamped-methods-for-stage-1-or-2-or-3
Proposal Description:
DataView get/set Uint8Clamped methods
There are currently 11 kinds of Typed Array in the language.
Stage: 1
Motivation/Use Case
I’d like to dynamically dispatch to DataView methods based on the “type” of the Typed Array. This works great for all of the types except Uint8Clamped.
Problem
Only 10 of them have DataView get/set methods.
Here’s a matrix representing the consistently available functionality for each of them:
Name | constructor | shared prototype | ArrayBuffers | DataView get method | DataView set method |
---|---|---|---|---|---|
Int8Array | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
Uint8Array | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
Uint8ClampedArray | :white_check_mark: | :white_check_mark: | :white_check_mark: | :x: | :x: |
Int16Array | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
Uint16Array | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
Int32Array | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
Uint32Array | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
BigInt64Array | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
BigUint64Array | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
Float32Array | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
Float64Array | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
Solution
Add the get and set methods to round out Typed Array support.
Use Cases
- dynamic dispatch based on Typed Array type: https://github.com/esfx/esfx/blob/main/packages/struct-type/src/internal/numbers.ts#L122-L133