[WIP] new module jsarrays: ArrayBuffer, DataView + typed js API's #14128
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Do not review but early feedback welcome.
This PR adds a module
jsarrays.nim
, wrappingArrayBuffer
,DataView
+ typed js API's, see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataViewThis 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 implementstring
in js more efficiently: right now it usesArray
(which is dynamically typed), but withArrayBuffer
+DataView
it would be backed by a strongly typed array of char.EDIT
merge with lib/std/private/jsutils.nim