Conversation
This enables converting strings into byte sequences of pre-allocated buffers. Also cleanup TextEncoder a bit. Tests: ... Fixes #69.
|
The reason this does not contain the StringView dictionary is because it can be added later if there's indeed a need for it. This also does not require any particular destination length as either way out-of-band needs to be dealt with and it seems better to be flexible for simple string use cases that would otherwise have to write completely different code. |
|
Looks correct to me, but it took me a moment to realize that the algorithm always loops over all tokens and the loop just does not necessarily write all the output. While an early return might be just an optimization, it might make the algorithm more comprehensible. |
|
Thanks for pointing that out, I think it's actually wrong. Say we had 3 bytes left and the next input required 4 bytes and the input after that 1 byte. This would skip the 4 bytes input and then write the 1 byte one. |
ricea
left a comment
There was a problem hiding this comment.
Generally looks good. There's a few areas where the wording needs tightening up, as you've noted.
|
Do you know what the wording for those places should be? IDL doesn't really define any language around IDL ArrayBuffer objects... I guess I can file an issue upstream at least. Other things:
|
|
I think this is implied by your last comment, but just to confirm: as written, destination's view bounds (offset, length) onto its ArrayBuffer is seemingly ignored by the current algorithm. i.e. in this case: const ab = new ArrayBuffer(5);
const ua = new Uint8Array(ab, 1, 2);
new TextEncoder().encodeInto("ABCDE", ua);... I would expect (I don't see test cases for this either) |
|
Yeah, that clearly needs to be worded better. (I added tests.) |
|
I think this is good now apart from the example which I'd like feedback on over at #69 (comment). (And there's a Bikeshed issue I'll resolve with Tab.) |
|
I haven't explained why there's no Anyone want to do a final review pass? (Tests need one too.) |
|
I'll land this and the tests tomorrow, unless there are further comments. |
|
cc @whatwg/documentation |
This enables converting strings into byte sequences of pre-allocated buffers.
Also cleanup TextEncoder a bit.
Tests: ...
Fixes #69.
Preview | Diff