Skip to content

Add a new QuickJS JSEngine - #446

Open
ryuwd wants to merge 7 commits into
common-workflow-language:mainfrom
ryuwd:quickjs-engine
Open

Add a new QuickJS JSEngine#446
ryuwd wants to merge 7 commits into
common-workflow-language:mainfrom
ryuwd:quickjs-engine

Conversation

@ryuwd

@ryuwd ryuwd commented Aug 7, 2026

Copy link
Copy Markdown

This PR adds bellard's quickjs engine as a supported CWL JS engine, a lighter dependency alternative to node. This PR also makes a JS engine configurable via environment variable e.g.CWL_JS_ENGINE="quickjs".

Some refactoring was needed: I've moved regex_eval into JSEngine to have the logic shared between the node and quickjs engines - AFAIU it doesn't really depend on a JS engine itself(?)

@codecov

codecov Bot commented Aug 14, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 87.34177% with 30 lines in your changes missing coverage. Please review.
✅ Project coverage is 39.13%. Comparing base (bcbd9dd) to head (7692230).

Files with missing lines Patch % Lines
src/cwl_utils/sandboxjs.py 69.38% 20 Missing and 10 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #446      +/-   ##
==========================================
+ Coverage   38.78%   39.13%   +0.34%     
==========================================
  Files          50       51       +1     
  Lines       34620    34813     +193     
  Branches     8803     8813      +10     
==========================================
+ Hits        13428    13623     +195     
+ Misses      18308    18306       -2     
  Partials     2884     2884              

☔ 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.

Comment on lines +757 to +772
def _default_js_engine() -> JSEngine:
"""Instantiate the JS engine named by the CWL_JS_ENGINE environment variable."""
choice = os.environ.get("CWL_JS_ENGINE", "node")
if choice == "node":
return NodeJSEngine()
if choice == "quickjs":
qjs_path = shutil.which("qjs")
if qjs_path is None:
raise JavascriptException(
"CWL_JS_ENGINE is set to 'quickjs', but the qjs executable "
"was not found on PATH."
)
return QuickJSEngine(qjs_path)
raise ValueError(
f"Unsupported CWL_JS_ENGINE value {choice!r}: expected 'node' or 'quickjs'."
)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If QuickJS is faster, why not default to it if the executable is found and CWL_JS_ENGINE is unset?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Sounds great! Is it worth running the CWL conformance tests first?

Comment thread src/cwl_utils/sandboxjs.py
ryuwd added a commit to ryuwd/cwl-utils that referenced this pull request Aug 28, 2026
QuickJS distributions do not share a version scheme (the original
QuickJS uses dates while quickjs-ng uses semantic versions), so the
check probes the interpreter with a small script exercising the
features the engine relies on instead of parsing version strings.
A missing or broken interpreter fails the probe rather than raising.

Requested in review of common-workflow-language#446.
ryuwd added a commit to ryuwd/cwl-utils that referenced this pull request Aug 28, 2026
As suggested in review of common-workflow-language#446. When CWL_JS_ENGINE is unset, the
default engine is now QuickJS if a qjs executable is found on the PATH
and passes check_js_threshold_version, NodeJS otherwise. Setting
CWL_JS_ENGINE to 'node' or 'quickjs' still forces a specific engine,
and set_js_engine() still takes precedence.

The tests that specifically exercise the NodeJS engine and its
software container fallback (which deliberately hide node from the
PATH) now pin NodeJSEngine explicitly so they keep testing that code
path on systems where qjs is installed, such as CI.
ryuwd added 7 commits August 28, 2026 16:13
Parameter-reference walking is pure Python and engine independent, so
implementations of the JSEngine interface should not each need to
provide identical copies. The body is moved verbatim from NodeJSEngine;
the return annotation now matches the interface's existing declaration.
QuickJSEngine evaluates CWL expressions with the qjs interpreter.
QuickJS starts in about a millisecond, so each evaluation (and each
exec_js_process call, as used by cwltool's JS expression validation)
runs in one short-lived subprocess with no persistent process or wire
protocol.

get_js_engine() now creates the process-wide engine lazily, honouring
the CWL_JS_ENGINE environment variable ('node', the default, or
'quickjs'); engines installed with set_js_engine() take precedence.
Fixes the three D213 violations flagged by the pydocstyle CI job.
QuickJS distributions do not share a version scheme (the original
QuickJS uses dates while quickjs-ng uses semantic versions), so the
check probes the interpreter with a small script exercising the
features the engine relies on instead of parsing version strings.
A missing or broken interpreter fails the probe rather than raising.

Requested in review of common-workflow-language#446.
As suggested in review of common-workflow-language#446. When CWL_JS_ENGINE is unset, the
default engine is now QuickJS if a qjs executable is found on the PATH
and passes check_js_threshold_version, NodeJS otherwise. Setting
CWL_JS_ENGINE to 'node' or 'quickjs' still forces a specific engine,
and set_js_engine() still takes precedence.

The tests that specifically exercise the NodeJS engine and its
software container fallback (which deliberately hide node from the
PATH) now pin NodeJSEngine explicitly so they keep testing that code
path on systems where qjs is installed, such as CI.
@ryuwd
ryuwd marked this pull request as ready for review September 1, 2026 13:36
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.

2 participants