wasm-webidl-bindings
Read, write, and manipulate the Wasm WebIDL bindings custom section.
What's Inside
-
A parser for the straw proposal text format. See
crates/text-parser/src/grammar.lalrpop
. -
A set of AST types for representing and manipulating WebIDL bindings. See
src/ast.rs
. -
An encoder and decoder for the straw proposal binary format. See the implementation at
src/binary/encode.rs
and details on the format atBINARY.md
.
Example
Parsing the Text Format and Encoding it in the Binary Format
use ;
// Get the `walrus::Module` that this webidl-bindings section is for.
//
// The Wasm type and func that are being bound are:
//
// (type $EncodeIntoFuncWasm
// (param anyref anyref i32 i32)
// (result i64 i64))
//
// (func $encodeInto
// (import "TextEncoder" "encodeInto")
// (type $EncodeIntoFuncWasm))
let raw_wasm: = get_wasm_buffer_from_somewhere;
let mut config = default;
// Register a function to run after the module is parsed, but with access to the
// mapping from indices in the original Wasm binary to their newly assigned
// walrus IDs.
//
// This is where we will parse the Web IDL bindings text.
config.on_parse;
let mut module = config.parse?;
// Reserialize the Wasm module along with its new Web IDL bindings
// section.
let new_raw_wasm = module.emit_wasm;