Skip to content

Add eval and try_native to the C FFI - #5689

Open
rrogerc wants to merge 9 commits into
boa-dev:mainfrom
rrogerc:ffi-eval
Open

rrogerc wants to merge 9 commits into
boa-dev:mainfrom
rrogerc:ffi-eval

Conversation

@rrogerc

@rrogerc rrogerc commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

This Pull Request is related to #332. It follows #5618 and adds what that PR left for later: eval, try_native, and engine features for boa_ffi.

It changes the following:

  • Added boa_BoaContext_eval. It runs a script and returns a JsValue or a JsError. The error is passed through from Context::eval as is, which means a syntax error is Native while throw 7 and throw new Error('boom') both come back Opaque.
  • eval checks that the source is valid UTF-8 before the engine sees it. UTF8Input decodes without validating, and an encoded surrogate inside a string literal parsed and ran when I tried it. Invalid source returns a native TypeError and nothing runs.
  • Added boa_JsError_try_native, which reads the kind and message out of a thrown Error object and needs a context to do it, because reading those properties can run a getter. The result is a new Native error and the original is left alone. An error that's already Native is cloned, backtrace included. When it fails, C gets a JsTryNativeError code with one variant for each TryNativeError variant. If a getter threw, that exception is dropped.
  • boa_BoaContext_new now builds the context with IdleJobExecutor. C can't run jobs yet, so a queued promise callback would never run and would only keep whatever it captured alive. eval and try_native also call clear_kept_objects before they return, so a WeakRef target isn't held alive after the call.
  • Turned on the same engine features as ffi/wasm by default. Most of the size is intl_bundled: on my Mac the release dylib is 7.5 MiB without it and 22 MiB with it. I kept it on so Intl works without extra flags. --no-default-features drops all six (6.5 MiB).
  • Added Rust tests, a C test (tests/c/eval.c, which run.sh now runs), and README sections for both functions.

boa_engine is untouched. The new defaults enable dependencies already in Cargo.lock. The bridge change in ffi/boa_ffi/src/lib.rs is ~100 lines out of ~1,100, with the rest mostly tests and the README. I also ran the C tests under ASan and UBSan on Linux and they came back clean.

@rrogerc
rrogerc requested a review from a team as a code owner November 24, 2026 15:31
@github-actions github-actions Bot added C-Dependencies Pull requests that update a dependency file C-Documentation update documentation C-Tests Issues and PRs related to the tests. C-FFI Foreign Function Interface, to be able to use Boa from a different language, such as C Waiting On Review Waiting on reviews from the maintainers labels Nov 24, 2026
@github-actions github-actions Bot added this to the v0.23 milestone Nov 24, 2026
@github-actions

github-actions Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Test262 conformance changes

Test result main count PR count difference
Total 53,578 53,578 0
Passed 51,464 51,464 0
Ignored 1,629 1,629 0
Failed 485 485 0
Panics 0 0 0
Conformance 96.05% 96.05% 0.00%

Tested main commit: 6801ee246df7bb801434c0dd65138b8f95e0065b
Tested PR commit: c543422fda05f7ddcc885028502c87f41848f10e
Compare commits: 6801ee2...c543422

@codecov

codecov Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 62.44%. Comparing base (6ddc2b4) to head (c543422).
⚠️ Report is 1089 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff             @@
##             main    #5689       +/-   ##
===========================================
+ Coverage   47.24%   62.44%   +15.20%     
===========================================
  Files         476      538       +62     
  Lines       46892    59406    +12514     
===========================================
+ Hits        22154    37096    +14942     
+ Misses      24738    22310     -2428     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C-Dependencies Pull requests that update a dependency file C-Documentation update documentation C-FFI Foreign Function Interface, to be able to use Boa from a different language, such as C 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.

2 participants