Skip to content

Add Uint8Array base64/hex methods#1445

Draft
saghul wants to merge 2 commits intomasterfrom
uint8array-base64
Draft

Add Uint8Array base64/hex methods#1445
saghul wants to merge 2 commits intomasterfrom
uint8array-base64

Conversation

@saghul
Copy link
Copy Markdown
Contributor

@saghul saghul commented Apr 10, 2026

The first commit is #1444

JS_EXTERN int JS_AddPerformance(JSContext *ctx);
JS_EXTERN int JS_AddIntrinsicDOMException(JSContext *ctx);
JS_EXTERN int JS_AddIntrinsicBase64(JSContext *ctx);
JS_EXTERN int JS_AddIntrinsicAToB(JSContext *ctx);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I should adjust this in the other PR too.

'q','r','s','t','u','v','w','x','y','z',
'0','1','2','3','4','5','6','7','8','9',
'-','_'
'+','/'
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I should adjust this in the other PR.

written = b64_encode(data, len, dst);

if (alphabet == B64_ALPHABET_BASE64URL) {
for (size_t i = 0; i < written; i++) {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Is it technically correct to use base64url for atob / btoa? If so, we could perhaps simplify?

}
}
if (omit_padding) {
while (written > 0 && dst[written - 1] == '=')
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Should iterate in reverse.

@saghul saghul marked this pull request as draft April 10, 2026 09:28
Lucas and others added 2 commits April 11, 2026 09:52
- Introduce global btoa() and atob() functions
- Standard base64 alphabet (RFC 4648)
- Decoder implements forgiving-base64-decode (WHATWG Infra spec)
- Tolerant to whitespace, validates padding per spec
- JS_AddIntrinsicAToB() ensures DOMException is registered

Co-authored-by: Saúl Ibarra Corretgé <s@saghul.net>
@saghul saghul force-pushed the uint8array-base64 branch from 30d081c to 3038569 Compare April 11, 2026 08:40
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.

1 participant