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

[WIP] new module jsarrays: ArrayBuffer, DataView + typed js API's #14128

Closed

Conversation

timotheecour
Copy link
Member

@timotheecour timotheecour commented Apr 26, 2020

Do not review but early feedback welcome.

This PR adds a module jsarrays.nim, wrapping ArrayBuffer, DataView + typed js API's, see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView
This is useful for cases where the 1-size-fits-all js type Number falls short.

This PR will allow #14095 to have streams.read[T] (and write[T]) with T integer or FP types
(right now #14095 only supports T string)

This PR will be cleaned up to remove the commits from #14095 and only introduce jsarrays module + tests, but right now they're included to show this works with streams, see test tests/js/tstreams.nim

#14095 (or a followup PR) can thus use jsarrays to support read/write[T]

BigInt (for nim-lang/RFCs#187) could belong here (see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getBigInt64) or be introduced in another module and imported here.

note

  • ArrayBuffer + DataView can be used to implement string in js more efficiently: right now it uses Array (which is dynamically typed), but with ArrayBuffer + DataView it would be backed by a strongly typed array of char.
  • this should either fix or help Casting of pointers in JS backend #5667 once completed

EDIT

merge with lib/std/private/jsutils.nim

@timotheecour timotheecour changed the title [WIP] new module jsarrays, wraps ArrayBuffer, DataView + typed js API's (eg setUint16, getInt8) for nim js [WIP] new module jsarrays: ArrayBuffer, DataView + typed js API's Apr 26, 2020
@RSDuck
Copy link
Contributor

RSDuck commented Apr 28, 2020

are typed arrays such as Uint8Array planned as well?

@stale
Copy link

stale bot commented Jan 25, 2022

This pull request has been automatically marked as stale because it has not had recent activity. If you think it is still a valid PR, please rebase it on the latest devel; otherwise it will be closed. Thank you for your contributions.

@stale stale bot added the stale Staled PR/issues; remove the label after fixing them label Jan 25, 2022
@stale stale bot closed this Feb 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale Staled PR/issues; remove the label after fixing them
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants