Running Modern ES2023 JavaScript Inside Go Using QJS and WebAssembly
Briefly

Running Modern ES2023 JavaScript Inside Go Using QJS and WebAssembly
"QJS targets Go developers who want to run modern JavaScript inside Go processes without linking to native C libraries. Instead of binding QuickJS directly via CGO, it compiles QuickJS-NG to WebAssembly and executes it under Wazero, providing: Full ES2023 support (modules, async/await, BigInt, etc.). A fully sandboxed, memory-safe execution model. No CGO toolchain or C runtime dependency."
"The runtime is compatible with Go 1.22+ and is distributed as a regular Go module: go get github.com/fastschema/qjs and then: import "github.com/fastschema/qjs" QJS exposes a and Context API that lets Go code evaluate JavaScript, bind functions, and exchange data structures. A minimal example creates a runtime, evaluates a script, and reads structured results back into Go: rt, err := qjs.New() if err != nil { log.Fatal(err) } defer rt.Close() ctx := rt.Context() result, err := ctx.Eval("test.js", qjs.Code(` const person = { name: "Alice", age: 30, city: "New York" }; const info = Object.keys(person).map(key => key + ": " + person[key] ).join(", "); ({ person: person, info: info }); `)) if err != nil { log.Fatal("Eval error:", err) } defer result.Free() log.Println(result.GetPropertyStr("info").String()) log.Println(result.GetPropertyStr("person").GetPropertyStr("name").String()) log.Println(result.GetPropertyStr("person").GetPropertyStr("age").Int32())"
QJS provides a CGO-free JavaScript runtime for Go by compiling QuickJS-NG to WebAssembly and executing it with Wazero. The runtime implements full ES2023 features including modules, async/await, and BigInt while enforcing a sandboxed, memory-safe execution model without requiring a CGO toolchain or a C runtime. QJS targets Go 1.22+ and is distributed as a standard Go module installable via go get. The API exposes Runtime and Context objects to evaluate scripts, bind Go functions for use in JavaScript, convert JS functions to typed Go callables, and exchange structured data between Go and JavaScript.
Read at InfoQ
Unable to calculate read time
[
|
]