feat(http): add QuickJS script handler - #871
Open
ithewei wants to merge 13 commits into
Open
Conversation
ithewei
force-pushed
the
js-http-script-handler
branch
from
August 21, 2026 06:42
a767821 to
65bb368
Compare
Expose stable JS-layer run helpers mirroring hvlua_dofile/hvlua_dostring so callers can run a script on a loop's per-loop QuickJS runtime without touching the task/runtime plumbing. The script body is wrapped in an async function, so top-level await works; global require/print/arg are installed. Returns 1 when finished synchronously, 0 when pending on async work (caller runs the loop), <0 on setup/load/runtime error, with an optional exit_code set on reject/timeout. Thin examples/hvjs.cpp down to a hvlua.cpp-style runner that just creates the loop, publishes TLS, and calls hvjs_dofile.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
WITH_JS/ QuickJS support and installHttpJsHandler.hplus publichv/hvjs.hwhen enabled.HttpJsHandlerplusHttpScriptHandlerdispatch for.jsscripts.js/with controlled modules:hv,hv/http,hv/ws,hv/redis, andhv/mqtt; no Node.js/npm module loading.hloop_tviahloop_set_js_runtime/hloop_js_runtime, with oneJSContextper HTTP request.async/await, including request-level timeout, built-in QuickJS memory/stack limits, and interrupt handling for CPU-bound scripts.ws/mqtt recv()remain message-driven and rely on requesttimeout_msas the HTTP lifecycle safety budget.AsyncRedisClientpending request callback reentrancy by popping completed/failed requests before invoking callbacks.--with-jsshared/static libhv build instead of the previous static-only JS pass plus second libhv rebuild.Testing
git diff --checkbellard/quickjsat04be246001599f5995fa2f2d8c91a0f198d3f34c, appendCFLAGS_OPT+=-fPIC, buildlibquickjs.a; verified compile commands keepCONFIG_VERSIONand include-fPIC..github/workflows/CI.ymlshell block syntax: extracted eachrun: |block and ranbash -n..github/workflows/CI.ymlYAML parse:ruby -e 'require "yaml"; YAML.load_file(".github/workflows/CI.yml"); puts "yaml ok"'.cmake -S . -B /tmp/libhv-js-final-check -DWITH_JS=ON -DWITH_HTTP=ON -DWITH_HTTP_SERVER=ON -DWITH_HTTP_CLIENT=ON -DWITH_REDIS=ON -DWITH_MQTT=ON -DBUILD_SHARED=OFF -DBUILD_STATIC=ON -DBUILD_EXAMPLES=ON -DBUILD_UNITTEST=ON -DQUICKJS_ROOT=/opt/homebrew/opt/quickjscmake --build /tmp/libhv-js-final-check --target hvjs http_js_handler_test http_js_redis_test http_js_ws_test http_js_mqtt_test -j2/tmp/libhv-js-final-check/bin/http_js_handler_test && /tmp/libhv-js-final-check/bin/http_js_redis_test && /tmp/libhv-js-final-check/bin/http_js_ws_test && /tmp/libhv-js-final-check/bin/http_js_mqtt_test && /tmp/libhv-js-final-check/bin/hvjs examples/js/sleep.jscmake --install /tmp/libhv-js-final-check --prefix /tmp/libhv-install-js-finalfind_package(libhv REQUIRED CONFIG),#include <hv/hvjs.h>, linklibhv::hv_static, build and run with-DCMAKE_PREFIX_PATH=/tmp/libhv-install-js-final -DQUICKJS_ROOT=/opt/homebrew/opt/quickjsmake libhv hvjs unittest WITH_JS=yes WITH_HTTP=yes WITH_MQTT=yes WITH_REDIS=yes -j2DYLD_LIBRARY_PATH=$(pwd)/lib:$DYLD_LIBRARY_PATH bash scripts/unittest.shmake http_server_test WITH_JS=yes WITH_HTTP=yes -j2