`bytes` as alias for `list<u8>`
Maintainers usually reply within 4 days
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 35/100
- Issue type
- Feature
- Clarity
- Mostly clear
- Activity status
- Active
- Tech stack
- javascript, wasm
Research direction
Start by reading the new JS explainer in #686 and the issue’s discussion of list at the ABI level. Determine whether bytes should remain an alias there, then establish the accepted JavaScript mappings for list and bytes, including parameter behavior and Uint8Array handling.
Written by the indexing model from the issue text.
Description
While reading through the new JS explainer in #686, I found myself going back and forth on whether to use typed arrays for list<num>. For list<u8> it seems fairly natural to map that to Uint8Array, but less so for other number types. Like, it's probably quite a footgun to return Int32Array for list<s32>, since most JS devs don't use typed arrays very often, and typed arrays look juuuuuust enough like normal arrays to do some really surprising things:
> new Int32Array([1, 2, 3]).map(n => `item ${n}`)
Int32Array [0, 0, 0]
Surely no one would complain about this.
But that got me thinking - the main difference seems to be that sometimes you want a list of numbers, using whatever list type is idiomatic, but sometimes you just want a blob of bytes. Sure, you can have Int32Array and Float64Array and so on, but at least 95% of the time in JS you just want Array. And after further reflection, I think this is true of other languages too! In C++, do you really want a std::vector<uint8_t>, or would you maybe prefer std::string or some other kind of slice type? In Java, do you want List<Byte> or byte[]? In Python, do you want list or bytes? In Rust, do you want Vec<u8> or &[u8]?
(This is not true for some languages, e.g. Go would always do []byte, but that's fine, the distinction doesn't have to be meaningful in every language.)
So, purely as a hint to bindings generators, I think there is probably some value in having a bytes type that is in every way just an alias for list<u8>. Certainly there is no need for it to be different at the ABI level.
If accepted, I would suggest the following for the JS mapping:
list<T>is returned as a JS array, and as a param only accepts a JS array (...or iterable? idk)bytesis returned as aUint8Array, and a param accepts anything the TypedArray constructor would (which encompasses all typed arrays, ArrayBuffers, and JS iterables)
- Dominant language
- WebAssembly
- Stars
- 1.4k
- Forks
- 134
- Avg merge
- 3d 19h
- Merged PRs (30d)
- 8
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from WebAssembly/component-model
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
WebAssembly/component-model#609 · 2 comments · 1 reaction ·
Maintainers usually reply within 4 days
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
WebAssembly/component-model#769 · 1 comment ·
Maintainers usually reply within 4 days
-
Difficulty 5/5 Over a week Newbie friendliness 12/100
WebAssembly/component-model#768 · 1 comment ·
Maintainers usually reply within 4 days
-
Difficulty 5/5 Over a week Newbie friendliness 30/100
WebAssembly/component-model#765 · 1 comment ·
Maintainers usually reply within 4 days
-
Difficulty 4/5 3-5 days Newbie friendliness 45/100
WebAssembly/component-model#753 · 1 comment · 1 reaction ·
Maintainers usually reply within 4 days
All issues in WebAssembly/component-model
Similar issues
-
opensubtitlescom: provider rejects pt-PT even though its own converter maps itPossibly taken @paulo-0308 claimed this today. Open
Difficulty 1/5 Under an hour Newbie friendliness 88/100
Diaoul/subliminal#1405 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
oxc-project/oxc-htmlish-parser#34 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
GitHub PATCH issue endpoint is deprecatedPossibly taken A pull request linked to this issue is open or already merged. Opencomponent-test
Difficulty 2/5 1-3 hours Newbie friendliness 63/100
OpenLightingProject/open-fixture-library#6417 ·
Maintainers usually reply within 1 day
-
bug rust
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 2 days