]> git.kaiwu.me - njs.git/commit
QuickJS: add missing btoa() and atob() and improve njs version master
authorDmitry Volyntsev <xeioex@nginx.com>
Thu, 25 Jun 2026 00:28:02 +0000 (17:28 -0700)
committerDmitry Volyntsev <xeioexception@gmail.com>
Thu, 25 Jun 2026 01:44:40 +0000 (18:44 -0700)
commitf078f14372ee789ea1435f35672407c13917b5e7
tree45dce1bfc1a3158797c7cbbdec75af5f8e49bdb9
parent909019db49ba6cf8f33382f977565a74b671ea64
QuickJS: add missing btoa() and atob() and improve njs version

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.
src/njs_string.c
src/qjs.c
src/qjs.h
src/qjs_buffer.c
src/test/njs_unit_test.c
test/btoa.t.js [new file with mode: 0644]