quickjs_runtime 0.3.0
quickjs_runtime: ^0.3.0 copied to clipboard
Pure-Dart QuickJS JavaScript runtime on dart:ffi with synchronous host callbacks. Vendored QuickJS 2024-01-13 + a C bridge with JSON marshaling.
0.3.0 #
-
Sync
fetch(opt-in):NodeCompatConfig.httpFetchhook + realHeaders/Response(text()/json()/arrayBuffer(),bodyUsed,ok/status/headers); failures surface asTypeError: fetch failedwithcause. Bodies are plain values, soawait res.text()works through them;AbortSignalis not supported (documented deviation). Without the hook,fetchstays a self-documenting stub — the runtime remains I/O-clean. -
Real timers + microtask auto-drain + events: promise reactions,
queueMicrotaskandprocess.nextTicknow actually run — the QuickJS pending-job queue is drained (capped) after every successful eval.setTimeout/setInterval/setImmediate+clear*are real, host-driven callbacks viaNodeCompatHandle.drainTimers()inready(default, UI-safe) /block(sleeps until the nearest reffed timer — CLI "setTimeout as sleep") /nonemodes, withunref(), a callback-count guard and a wall-clock budget.require('events')provides the full synchronousEventEmitter. -
Node parity pack (issue #3 follow-up): real
Buffer(Uint8Array subclass, Node encodings + LE/BE accessors),URL/URLSearchParams(WHATWG subset verified against real Node),console.time/table/group/count/dir/trace, Node-styleutil.inspect,os+url+bufferbuiltin modules,process.argv/pid/hrtime/uptime/memoryUsage/stdout/stderr/on('exit'),__filename/__dirname(+NodeCompatHandle.setScriptPath), typeof-safeIntlstubs. Default text codecs are now real UTF-8 (dart:convert) — the latin-1 approximation is gone;Bufferremoved from tier-2 stubs;installNodeCompatreturns aNodeCompatHandle. -
Node/js compat layer (issue #3), opt-in via
installNodeCompat(rt, cfg):- Tier 1 — real:
global,console.*(pluggable sink),process(env/platform/arch/version/exitCode/cwd/exit),path(posix subset),assert(node-like subset),util(subset),TextEncoder/TextDecoder(utf-8),atob/btoa,performance.now(),crypto.randomUUID()/getRandomValues(),structuredClone(JSON fidelity),require()builtin registry + consumer modules (installNodeCompatModule) + fallback to a pre-existing loader. - Tier 2 — self-documenting stub:
AbortController—typeof-safe, throws the alternative on call (fetch has no signal support yet). - Host hooks: env, cwd, clock, secure random, utf-8/base64 codecs, console sink, exit notification. Without hooks, safe defaults.
- Tier 1 — real:
0.2.0 #
AsyncEnginePool: pre-spawned engine-worker isolates for parallel JavaScript execution over the synchronous host-callback bridge. Consumer owns the worker body (top-levelAsyncWorkerMainwith anAsyncWorkerLinknext/complete protocol, or a simplerAsyncJobExecutorone-engine-per-job hook); the pool owns transport and lifecycle — dispatch/wait mailbox protocol (pthreads condvar vianative_synchronization), FIFO backpressure, fire-and-forget envelope caching, dead-worker error completion.runAsync(fn, args)scripting surface:AsyncEnginePool.attachMainRuntimeregisters the__jsrDispatchHost/__jsrWaitHosthost functions and the prelude exposingrunAsync/AsyncJob/runAsync.allwith a blockingwait().runAsyncJobOnRuntime: runs one dispatched (closure-free) function on a consumer-wired runtime and returns itsAsyncJobEnvelope.
0.1.0 #
- Initial release: QuickJS 2024-01-13 runtime on
dart:ffiwith synchronous host callbacks (NativeCallable). QuickjsRuntime: eval (JSON results),registerHostFunction,setGlobal,executePendingJobs,close.QuickjsFfi: flat C ABI bindings toquickjs_bridge.c(JSON marshaling).tool/build_quickjs.shbuildslibquickjs_bridge.so(gcc); lookup viaJSR_QUICKJS_LIB,.dart_tool/package_config.json, script dir, or cwd.