Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added new overloaded constructor options to match TypedArray pattern #2

Closed

Conversation

zipzapzanigan
Copy link

@zipzapzanigan zipzapzanigan commented Apr 23, 2022

added additional overloaded arguments to accomodate byteOffset and length at init to match the TypedArray constructor pattern

new TypedArray(buffer)
new TypedArray(buffer, byteOffset)
new TypedArray(buffer, byteOffset, length)

also added a few test cases to cover the new constructor patterns, with various lengths of arrays, as well as testing byteOffset to ensure it offsets by 8 bits per byte

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray#constructor

closes #1

@swiing swiing added the enhancement New feature or request label Apr 24, 2022
@swiing
Copy link
Owner

swiing commented Apr 26, 2022

I am going to close this PR for the following reasons:

  1. as said here, I need a compelling argument why ByteOffset would make sense for bit arrays.

  2. even if we would like to allow byteOffset/length, the code does not comply to the standard.
    E.g. new BitArray("011010", 0, 9).length === 9 should be false, not true. In order to convince you, check new Uint32Array([0,1,1,0,1,0], 0, 9).length (the value of which is 6, not 9). This is because the proposed code applies byteOffset/length to iterables, not to ArrayBuffers.

Anyway, thanks for sharing this. It raises interesting considerations.

@swiing swiing closed this Apr 26, 2022
@swiing swiing added the wontfix This will not be worked on label Apr 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request wontfix This will not be worked on
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bit-TypedArray does not support bitOffset, length in constructor
2 participants