Libjs
Simple and ABI stable C bindings to V8 built on libuv
Install / Use
/learn @holepunchto/LibjsREADME
libjs
Simple and ABI stable C bindings to V8 built on libuv. It tightly integrates with libuv, using a dedicated V8 platform implementation for scheduling platform and isolate tasks on libuv event loops.
API
See include/js.h for the public API.
Exceptions
JavaScript exceptions are used for all error handling. A negative return value therefore indicates that an exception is either pending in the case of js_pending_exception, or uncaught if the JavaScript execution stack is empty and an uncaught exception handler is installed in case of js_uncaught_exception. Furthermore, certain functions will immediately return an error value if an exception is already pending when the function was called.
To handle a pending exception in native code, rather than defer it to JavaScript, use the js_get_and_clear_last_exception() function. If the exception cannot be handled, it may be rethrown with js_throw(). If the JavaScript execution stack becomes empty without the exception being handled, it will trigger the uncaught exception handler if installed. If no exception handler is installed and the exception isn't handled explicitly it will be swallowed.
Building
By default, the library is compiled with static V8 prebuilds generated by https://github.com/holepunchto/chromium-prebuilds. You can bring along your own build of V8 by defining the v8 target in your build definition. If you rely on the default V8 prebuilds, make sure to first checkout https://github.com/holepunchto/chromium-prebuilds and follow the instructions on how to make a prebuild.
When configuring the build tree, make sure to define the GN_DIR and GN_OUT_DIR variables, pointing them to your Chromium checkout and the GN output directory:
bare-make generate -D GN_DIR=<chromium>/src -D GN_OUT_DIR=<chromium>/src/<out>
For more information about the GN to CMake bridge, see https://github.com/holepunchto/cmake-gn.
Alternatives
The API is designed in a way that minimises its coupling to V8, making it possible to implement ABI compatible alternatives for cases where V8 might not be ideal. We maintain several such alternatives that might be more appropriate for your use case:
-
https://github.com/holepunchto/libjsc
Based on the builtin JavaScriptCore framework on Darwin. -
https://github.com/holepunchto/libqjs
Based on QuickJS. -
https://github.com/holepunchto/libmqjs
Based on Micro QuickJS. -
https://github.com/holepunchto/libjerry
Based on JerryScript.
License
Apache-2.0
Related Skills
node-connect
349.9kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
109.8kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
349.9kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
349.9kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
