Skip to content

Support running test262 using boa cli#5234

Open
ivankra wants to merge 4 commits intoboa-dev:mainfrom
ivankra:test262
Open

Support running test262 using boa cli#5234
ivankra wants to merge 4 commits intoboa-dev:mainfrom
ivankra:test262

Conversation

@ivankra
Copy link

@ivankra ivankra commented Mar 23, 2026

This Pull Request fixes/closes #5054

It changes the following:

  • Move tests/tester/src/exec/js262.rs to core/runtime/src/test262.rs so it can be reused by both cli and boa_tester
  • Add --test262-object flag to CLI
  • Add print() to CLI with --test262-object
  • Enable [[CanBlock]] by default in CLI to match boa_tester as well as d8/jsc/sm shells default behavior
  • Add --no-can-block flag to CLI to support Atomics CanBlockIsFalse tests (same flag name as d8 has)
  • Auto-detect .mjs files as modules in CLI (a small optional quality-of-life improvement; matches behavior of most other major JS engine shells)

These changes make it possible to reproduce boa_tester's test262 results using external test262 harnesses with boa cli binary.

@ivankra ivankra requested a review from a team as a code owner March 23, 2026 09:16
@github-actions github-actions bot added C-Dependencies Pull requests that update a dependency file C-Documentation update documentation C-CLI Issues and PRs related to the Boa command line interface. C-Tests Issues and PRs related to the tests. C-Runtime Issues and PRs related to Boa's runtime features Waiting On Review Waiting on reviews from the maintainers labels Mar 23, 2026
@github-actions github-actions bot added this to the v1.0.0 milestone Mar 23, 2026
let clock = START
.get()
.ok_or_else(|| JsNativeError::typ().with_message("could not get the monotonic clock"))?;
let clock = START.get_or_init(Instant::now);
Copy link
Member

@jedel1043 jedel1043 Mar 23, 2026

Choose a reason for hiding this comment

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

I don't think this is correct. This will always return 0 or something close to 0 for the first call to monotonic_now, which could fail some tests that assume some amount of time already passed

Copy link
Author

@ivankra ivankra Mar 23, 2026

Choose a reason for hiding this comment

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

Thanks, I think you're right -- looking at the spec for DOMHighResTimeStamp, it does suggest to use worker/binary's start time as the time origin.

I moved initialization of START to the beginning of register_js262() (diff) and tested:

$ ./target/release/boa --test262-object -e '$262.agent.sleep(100); print($262.agent.monotonicNow());'
100
undefined

(before it printed 0 as clock got initialized on first use)

test262 tests aren't affected, no regressions either way.

ivankra added 4 commits March 23, 2026 18:31
Move `$262` implementation from `tests/tester/src/exec/js262.rs` to
`core/runtime/src/test262.rs` behind a new `test262` feature gate
(pulls `bus` as optional dep). Add `annex-b` feature to boa_runtime
forwarding to `boa_engine/annex-b` for `$262.IsHTMLDDA`.

Both cli and boa_tester now use `boa_runtime/test262`, removing the
tester's direct `bus` and `boa_gc` deps.

CLI registers `$262` when `--test262-object` flag is passed.

This change makes CLI more suitable for running test262 via an external
harness such as eshost + test262-harness. The exact same `$262` object as
used by the internal boa_tester can now be directly accessed in CLI.
Existing `$boa` object doesn't expose some of the methods (like IsHTMLDDA,
detachArrayBuffer and agent helpers) needed for full test262 support,
and would have required users to maintain a custom shim mapping it to `$262`.

Fixes boa-dev#5054
test262 tests use print() to signal async completion and errors.
The tester has its own print() implementation to catch reported errors,
but CLI should just print them, so let's alias it to console.log().
Treat files with .mjs extension as modules without requiring --module flag.

Many other JavaScript shells do the same - d8, jsc, graaljs, xs, escargot.
A small quality-of-life improvement that among other things simplifies
configuration for an external test262 harness. The harness could simply
stage module tests into *.mjs and forget about --module flag.
Make boa's cli consistent with the behaviour of other major JavaScript
shells (d8, jsc, spidermonkey at least) as well as boa_tester by
enabling [[CanBlock]] by default.

Add --no-can-block flag to opt out, same as V8
(https://github.com/v8/v8/blob/main/src/d8/d8.cc#L6417).

Needed for Atomics tests to pass when using an external test262 harness.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C-CLI Issues and PRs related to the Boa command line interface. C-Dependencies Pull requests that update a dependency file C-Documentation update documentation C-Runtime Issues and PRs related to Boa's runtime features C-Tests Issues and PRs related to the tests. Waiting On Review Waiting on reviews from the maintainers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Expose full $262 object in boa_cli

2 participants