Skip to content

paralin/go-quickjs-wasi

Repository files navigation

go-quickjs-wasi

GoDoc Widget Go Report Card Widget

A Go module that embeds the QuickJS-NG WASI WebAssembly runtime.

Variants

This repository provides the command model WASM binary, where QuickJS runs to completion in _start(). If you need re-entrant execution with host-controlled scheduling (for browsers, Node.js, Deno, or event-loop integration), see the reactor model variant:

About QuickJS-NG

QuickJS is a small and embeddable JavaScript engine. It aims to support the latest ECMAScript specification.

This project uses QuickJS-NG which is a fork of the original QuickJS project by Fabrice Bellard and Charlie Gordon, after it went dormant, with the intent of reigniting its development.

Purpose

This module provides easy access to the QuickJS-NG JavaScript engine compiled to WebAssembly with WASI support. The WASM binary is embedded directly in the Go module, making it easy to use QuickJS in Go applications without external dependencies.

Features

  • Embeds the latest QuickJS-NG WASI WebAssembly binary
  • Provides version information about the embedded QuickJS release
  • Automatic update script to fetch the latest QuickJS-NG release

Usage

package main

import (
    "fmt"
    "github.com/paralin/go-quickjs-wasi"
)

func main() {
    // Access the embedded WASM binary
    wasmBytes := quickjswasi.QuickJSWASM
    fmt.Printf("QuickJS WASM size: %d bytes\n", len(wasmBytes))

    // Get version information
    fmt.Printf("QuickJS version: %s\n", quickjswasi.Version)
    fmt.Printf("Download URL: %s\n", quickjswasi.DownloadURL)
}

Example

A complete example interactive JS REPL is provided in the ./wazero-quickjs directory. This demonstrates how to run QuickJS in a Wazero WebAssembly runtime.

To run the REPL:

cd ./wazero-quickjs && go run ./

This will start an interactive JavaScript shell powered by QuickJS-NG.

To install the repl run in your home directory:

go install github.com/paralin/go-quickjs-wasi/wazero-quickjs@master

The wazero-quickjs command will now run the wazero repl.

Updating

To update to the latest QuickJS-NG release:

./update-quickjs.bash

This script will:

  1. Fetch the latest release information from the QuickJS-NG GitHub repository
  2. Download the qjs-wasi.wasm file
  3. Generate version information constants

Testing

go test

License

This module is released under the same license as the embedded QuickJS-NG project.

MIT

About

Go module containing an embedded quickjs wasi binary.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Contributors