Skip to content

fix(@stdlib/string/base/atob): guard global atob reference to prevent ReferenceError#13329

Draft
Planeshifter wants to merge 2 commits into
developfrom
philipp/ci-fix-atob-node-legacy-2026-07-06
Draft

fix(@stdlib/string/base/atob): guard global atob reference to prevent ReferenceError#13329
Planeshifter wants to merge 2 commits into
developfrom
philipp/ci-fix-atob-node-legacy-2026-07-06

Conversation

@Planeshifter

Copy link
Copy Markdown
Member

Description

What is the purpose of this pull request?

This pull request:

  • Fixes lib/node_modules/@stdlib/string/base/atob/lib/global.js, which re-exported the bare global atob identifier directly. On Node.js runtimes that predate the global atob/btoa (added in Node 16+), referencing an undeclared identifier without a typeof guard throws ReferenceError: atob is not defined at module-evaluation time. Because main.js requires global.js at its top level, outside any try/catch, merely requiring the package crashed on Node 12/14. This broke the linux_test CI workflow's Node.js v12 and v14 jobs on every scheduled run against develop. The fix guards the reference with typeof atob === 'function', matching the identical pattern already used by the sibling @stdlib/assert/has-atob-support package.

Related Issues

Does this pull request have any related issues?

None.

Questions

Any questions for reviewers of this pull request?

No.

Other

Any other information relevant to this pull request? This may include screenshots, references, and/or implementation notes.

Found and fixed as part of automated CI-failure triage. Failing run: https://github.com/stdlib-js/stdlib/actions/runs/28785480753 (job: linux_test, Node.js v14; also reproduced on Node.js v12 and the macOS Node.js v16 job of the same run).

Validated by reproducing the crash and fix locally via a Node script that deletes globalThis.atob and confirms require() no longer throws. Reviewed by three independent passes (correctness, regression scope, style/conventions); all approved with no blocking findings.

Checklist

Please ensure the following tasks are completed before submitting this pull request.

AI Assistance

When authoring the changes proposed in this PR, did you use any kind of AI assistance?

  • Yes
  • No

If you answered "yes" above, how did you use AI assistance?

  • Code generation (e.g., when writing an implementation or fixing a bug)
  • Test/benchmark generation
  • Documentation (including examples)
  • Research and understanding

Disclosure

If you answered "yes" to using AI assistance, please provide a short disclosure indicating how you used AI assistance. This helps reviewers determine how much scrutiny to apply when reviewing your contribution. Example disclosures: "This PR was written primarily by Claude Code." or "I consulted ChatGPT to understand the codebase, but the proposed changes were fully authored manually by myself.".

This PR was written primarily by Claude Code as part of an automated CI-failure triage and fix routine, based on live GitHub Actions job log analysis. The fix was reviewed by three independent automated review passes before being proposed here.


@stdlib-js/reviewers


Generated by Claude Code

claude added 2 commits July 6, 2026 14:15
…nt ReferenceError

The `linux_test` workflow's Node.js v12/v14 jobs failed on every
scheduled run on develop with `ReferenceError: atob is not defined`
at `lib/global.js:23`. Root cause: the file re-exported the bare
`atob` identifier directly; on Node runtimes that predate the global
`atob`/`btoa` (added in Node 16+), referencing an undeclared
identifier without `typeof` throws at module-evaluation time, so
merely requiring `main.js` (which requires `global.js` at its top
level) crashed before any test ran.

This commit guards the reference with `typeof atob === 'function'`,
mirroring the identical, already-correct idiom used by the sibling
`@stdlib/assert/has-atob-support` package, so requiring the module
now yields `null` instead of throwing on environments lacking a
global `atob`.

Ref: https://github.com/stdlib-js/stdlib/actions/runs/28785480753
…guarded `atob` reference

The `lint_changed_files` CI check on PR #13329 flagged the guarded
`typeof atob === 'function'` reference with
`n/no-unsupported-features/node-builtins`, since the package's
`engines` range (`>=0.12.18`) predates the stable global `atob`.
This is the same intentional, guarded pattern already used for other
version-gated globals (e.g. `@stdlib/bigint/ctor`, `@stdlib/proxy/ctor`),
which disable the corresponding rule on the same line. Do the same here.

Ref: https://github.com/stdlib-js/stdlib/actions/runs/28798431195
@stdlib-bot

stdlib-bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Coverage Report

Package Statements Branches Functions Lines
string/base/atob $\\color{green}217/217$
$\\color{green}+100.00\\%$
$\\color{red}11/12$
$\\color{green}+91.67\\%$
$\\color{green}2/2$
$\\color{green}+100.00\\%$
$\\color{green}217/217$
$\\color{green}+100.00\\%$

The above coverage report was generated for the changes in this PR.

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.

3 participants