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

LibJS: Implement the Uint8Array to/from base64 proposal #1258

Merged
merged 10 commits into from
Sep 3, 2024

Conversation

trflynn89
Copy link
Contributor

test262 diff (we pass all of the Uint8Array tests):

Diff Tests:
    +56 ✅    -56 ❌

Diff Tests:
    test/built-ins/Uint8Array/fromBase64/alphabet.js                         ❌ -> ✅
    test/built-ins/Uint8Array/fromBase64/descriptor.js                       ❌ -> ✅
    test/built-ins/Uint8Array/fromBase64/ignores-receiver.js                 ❌ -> ✅
    test/built-ins/Uint8Array/fromBase64/illegal-characters.js               ❌ -> ✅
    test/built-ins/Uint8Array/fromBase64/last-chunk-handling.js              ❌ -> ✅
    test/built-ins/Uint8Array/fromBase64/length.js                           ❌ -> ✅
    test/built-ins/Uint8Array/fromBase64/name.js                             ❌ -> ✅
    test/built-ins/Uint8Array/fromBase64/nonconstructor.js                   ❌ -> ✅
    test/built-ins/Uint8Array/fromBase64/option-coercion.js                  ❌ -> ✅
    test/built-ins/Uint8Array/fromBase64/results.js                          ❌ -> ✅
    test/built-ins/Uint8Array/fromBase64/whitespace.js                       ❌ -> ✅
    test/built-ins/Uint8Array/fromHex/descriptor.js                          ❌ -> ✅
    test/built-ins/Uint8Array/fromHex/ignores-receiver.js                    ❌ -> ✅
    test/built-ins/Uint8Array/fromHex/illegal-characters.js                  ❌ -> ✅
    test/built-ins/Uint8Array/fromHex/length.js                              ❌ -> ✅
    test/built-ins/Uint8Array/fromHex/name.js                                ❌ -> ✅
    test/built-ins/Uint8Array/fromHex/nonconstructor.js                      ❌ -> ✅
    test/built-ins/Uint8Array/fromHex/odd-length-input.js                    ❌ -> ✅
    test/built-ins/Uint8Array/fromHex/results.js                             ❌ -> ✅
    test/built-ins/Uint8Array/prototype/setFromBase64/alphabet.js            ❌ -> ✅
    test/built-ins/Uint8Array/prototype/setFromBase64/descriptor.js          ❌ -> ✅
    test/built-ins/Uint8Array/prototype/setFromBase64/detached-buffer.js     ❌ -> ✅
    test/built-ins/Uint8Array/prototype/setFromBase64/illegal-characters.js  ❌ -> ✅
    test/built-ins/Uint8Array/prototype/setFromBase64/last-chunk-handling.js ❌ -> ✅
    test/built-ins/Uint8Array/prototype/setFromBase64/length.js              ❌ -> ✅
    test/built-ins/Uint8Array/prototype/setFromBase64/name.js                ❌ -> ✅
    test/built-ins/Uint8Array/prototype/setFromBase64/nonconstructor.js      ❌ -> ✅
    test/built-ins/Uint8Array/prototype/setFromBase64/option-coercion.js     ❌ -> ✅
    test/built-ins/Uint8Array/prototype/setFromBase64/results.js             ❌ -> ✅
    test/built-ins/Uint8Array/prototype/setFromBase64/subarray.js            ❌ -> ✅
    test/built-ins/Uint8Array/prototype/setFromBase64/target-size.js         ❌ -> ✅
    test/built-ins/Uint8Array/prototype/setFromBase64/whitespace.js          ❌ -> ✅
    test/built-ins/Uint8Array/prototype/setFromBase64/writes-up-to-error.js  ❌ -> ✅
    test/built-ins/Uint8Array/prototype/setFromHex/descriptor.js             ❌ -> ✅
    test/built-ins/Uint8Array/prototype/setFromHex/illegal-characters.js     ❌ -> ✅
    test/built-ins/Uint8Array/prototype/setFromHex/length.js                 ❌ -> ✅
    test/built-ins/Uint8Array/prototype/setFromHex/name.js                   ❌ -> ✅
    test/built-ins/Uint8Array/prototype/setFromHex/nonconstructor.js         ❌ -> ✅
    test/built-ins/Uint8Array/prototype/setFromHex/results.js                ❌ -> ✅
    test/built-ins/Uint8Array/prototype/setFromHex/subarray.js               ❌ -> ✅
    test/built-ins/Uint8Array/prototype/setFromHex/target-size.js            ❌ -> ✅
    test/built-ins/Uint8Array/prototype/setFromHex/writes-up-to-error.js     ❌ -> ✅
    test/built-ins/Uint8Array/prototype/toBase64/alphabet.js                 ❌ -> ✅
    test/built-ins/Uint8Array/prototype/toBase64/descriptor.js               ❌ -> ✅
    test/built-ins/Uint8Array/prototype/toBase64/detached-buffer.js          ❌ -> ✅
    test/built-ins/Uint8Array/prototype/toBase64/length.js                   ❌ -> ✅
    test/built-ins/Uint8Array/prototype/toBase64/name.js                     ❌ -> ✅
    test/built-ins/Uint8Array/prototype/toBase64/nonconstructor.js           ❌ -> ✅
    test/built-ins/Uint8Array/prototype/toBase64/omit-padding.js             ❌ -> ✅
    test/built-ins/Uint8Array/prototype/toBase64/option-coercion.js          ❌ -> ✅
    test/built-ins/Uint8Array/prototype/toBase64/results.js                  ❌ -> ✅
    test/built-ins/Uint8Array/prototype/toHex/descriptor.js                  ❌ -> ✅
    test/built-ins/Uint8Array/prototype/toHex/length.js                      ❌ -> ✅
    test/built-ins/Uint8Array/prototype/toHex/name.js                        ❌ -> ✅
    test/built-ins/Uint8Array/prototype/toHex/nonconstructor.js              ❌ -> ✅
    test/built-ins/Uint8Array/prototype/toHex/results.js                     ❌ -> ✅

Copy link
Member

@awesomekling awesomekling left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some callers (LibJS) will want to control the size of the input buffer, to decode up to a maximum length.

Did we mean "output buffer" here?

@trflynn89
Copy link
Contributor Author

I actually meant "the buffer supplied as an input to the function" but I see how that is not at all clear :)

Some callers (LibJS) will want to control the size of the output buffer,
to decode up to a maximum length. They will also want to receive partial
results in the case of an error. This patch adds a method to provide
those capabilities, and makes the existing implementation use it.
In pure JS, we would have to implement a full UTF-8 encoder, so let's
add a helper method to do the work in C++.
Note that we can currently only use simdutf for Base64 decoding if the
provided stopBeforePartial option is loose, which is the default. There
is an open issue for simdutf to implement strict and stop-before-partial
options. Until then, for those options, we implement a slow decoder that
is written exactly as the spec steps dictate.

See: simdutf/simdutf#440
@awesomekling awesomekling merged commit 7d0e33c into LadybirdBrowser:master Sep 3, 2024
6 checks passed
@trflynn89 trflynn89 deleted the js_ta_base64 branch September 3, 2024 15:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants