ffi/wasm/README.md
WebAssembly bindings for Boa, a Javascript engine written in Rust.
This package provides WebAssembly bindings to run JavaScript code using the Boa engine directly in the browser or Node.js environments. Boa supports more than 90% of the latest ECMAScript specification.
npm install @boa-dev/boa_wasm
Or with yarn:
yarn add @boa-dev/boa_wasm
import init, { evaluate } from "@boa-dev/boa_wasm";
// Initialize the Wasm module
await init();
// Evaluate JavaScript code
try {
const result = evaluate("1 + 1");
console.log(result); // "2"
} catch (error) {
console.error("Evaluation error:", error);
}
const { evaluate } = require("@boa-dev/boa_wasm");
try {
const result = evaluate("1 + 1");
console.log(result); // "2"
} catch (error) {
console.error("Evaluation error:", error);
}
import init, { evaluate } from "@boa-dev/boa_wasm";
await init();
const code = `
function fibonacci(n) {
if (n <= 1) return n;
return fibonacci(n - 1) + fibonacci(n - 2);
}
fibonacci(10)
`;
const result = evaluate(code);
console.log(result); // "55"
evaluate(src: string): stringEvaluates the given ECMAScript code and returns the result as a string.
Parameters:
src - A string containing the JavaScript code to evaluateReturns:
Throws:
JsValue error if the execution throws an exceptionBoa's Wasm build includes:
Try Boa in your browser at our live playground!
Check out Boa's ECMAScript Test262 conformance results to see our progress on implementing the ECMAScript specification.
Contributions are welcome! Please check out the contributing guide to get started.
This project is licensed under the Unlicense or MIT licenses, at your option.