Skip to content

QuickJS: add missing btoa() and atob()#1084

Merged
xeioex merged 1 commit into
nginx:masterfrom
xeioex:qjs_atob
Jun 25, 2026
Merged

QuickJS: add missing btoa() and atob()#1084
xeioex merged 1 commit into
nginx:masterfrom
xeioex:qjs_atob

Conversation

@xeioex

@xeioex xeioex commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

The functions implement the WHATWG btoa()/atob() global functions for the QuickJS engine, mirroring the built-in njs engine.

The narrower njs-only btoa()/atob() unit tests are dropped in favor of test/btoa.t.js, which exercises both engines.

Comment thread src/qjs_buffer.c Outdated
Comment thread src/qjs_buffer.c Outdated
Comment thread src/qjs.h Outdated
Comment thread src/qjs_buffer.c Outdated
VadimZhestikov
VadimZhestikov previously approved these changes Jun 24, 2026

@VadimZhestikov VadimZhestikov left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Few notes, otherwise looks good

@xeioex

xeioex commented Jun 25, 2026

Copy link
Copy Markdown
Contributor Author

@VadimZhestikov

Applied fixes and implemented " algorithm strips all ASCII whitespace", and removed extra tmp allocation from original njs atob(). The same changes applied to qjs version.

VadimZhestikov
VadimZhestikov previously approved these changes Jun 25, 2026

@VadimZhestikov VadimZhestikov left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good

The functions implement the WHATWG btoa()/atob() global functions for
the QuickJS engine, mirroring the built-in njs engine.

Both engines decode forgiving-base64 in a single pass using a bit
accumulator, without allocating a scratch buffer for the
whitespace-stripped copy.

The shared behaviour is corrected and aligned with WHATWG:
- atob() strips all ASCII whitespace (TAB, LF, FF, CR, SPACE), not only
  SPACE; VT and NBSP are not ASCII whitespace and are rejected.
- btoa() error text says "(> U+00FF)" to match the cp > 0xff check.

The narrower njs-only btoa()/atob() unit tests are dropped in favor of
test/btoa.t.js, which exercises both engines.
@xeioex

xeioex commented Jun 25, 2026

Copy link
Copy Markdown
Contributor Author

@VadimZhestikov Fixed assert() for size == 0 in js_malloc_rt() in QuickJS, for empty string output.

@VadimZhestikov VadimZhestikov self-requested a review June 25, 2026 01:35

@VadimZhestikov VadimZhestikov left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good

@xeioex xeioex merged commit f078f14 into nginx:master Jun 25, 2026
2 checks passed
@github-project-automation github-project-automation Bot moved this from In Progress to Done in NGINX OSS Unified Workspace Jun 25, 2026
@xeioex xeioex deleted the qjs_atob branch June 25, 2026 01:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants