NitroWasmModule class final
A loaded nitro WASM module: the Emscripten Module object plus typed heap I/O and the module-allocator entry points generated bridges rely on.
All heap access is bulk (set/slice) — per-element access from Dart is a
JS call per byte under dart2wasm, and cached views detach on memory growth.
Constructors
- NitroWasmModule(String libName, EmscriptenModule module)
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- libName → String
-
The nitro library name this module was registered under (
@NitroModule.lib).final - module → EmscriptenModule
-
The raw Emscripten Module object.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
addFunction(
JSFunction< Function> f, String signature) → int -
Adds
fto the module function table; the returned index is a C function pointer.signatureuses Emscripten sig letters (v=void,i=i32,j=i64/BigInt,d=f64), return type first. -
call(
String cSymbol, List< JSAny?> args) → JSAny? -
Calls the exported C symbol
cSymbol(without the leading underscore) with pre-converted JS arguments. -
free(
int ptr) → void - Frees a malloc allocation.
-
malloc(
int byteCount) → int -
Dart-owned scratch memory (Emscripten
malloc). Pair with free. -
nitroAlloc(
int byteCount) → int -
The module's
<lib>_nitro_alloc— for buffers whose ownership transfers to native code (the C side frees them with its ownfree).size_t/void*are i32 on wasm32 — plain JS numbers, never BigInt. -
nitroAllocBytes(
Uint8List bytes) → int -
Copies
bytesinto a<lib>_nitro_alloc'd buffer — for framed payloads whose ownership transfers to native, such as a@HybridRecordreturned from a Dart callback. The C side frees it with its own free. -
nitroAllocCString(
String s) → int -
Copies
sinto a<lib>_nitro_alloc'd NUL-terminated buffer — for values whose ownership transfers to native (e.g. callback string returns, which the bridge frees with its ownfree). -
nitroFree(
int ptr) → void -
The module's
<lib>_nitro_free— frees native-owned returns (strings, framed buffers) that crossed with ownership transfer to Dart. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
providesSymbol(
String cSymbol) → bool -
True when the module exports
cSymbol. -
readBytes(
int ptr, int len) → Uint8List -
Copies
lenbytes atptrout of the module heap. -
readCString(
int ptr) → String -
Decodes a NUL-terminated C string at
ptr(chunked scan — avoids a JS call per byte). Preserves a leading BOM, tolerates malformed UTF-8. -
readF64(
int ptr) → double -
readFramed(
int ptr) → Uint8List -
Reads a framed buffer (
[4B len][payload]) atptr— the standard record/variant/map envelope — as one bulk copy of the whole frame. -
readI32(
int ptr) → int -
readI64(
int ptr) → int -
readU32(
int ptr) → int -
readU8(
int ptr) → int -
removeFunction(
int fnPtr) → void - Releases a function-table entry created by addFunction.
-
toString(
) → String -
A string representation of this object.
inherited
-
writeBytes(
int ptr, Uint8List bytes) → void -
Copies
bytesinto the module heap atptrin one bulk write.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
encodeCString(
String s) → Uint8List -
Encodes
sas NUL-terminated UTF-8 bytes (not yet in the heap — copy in via aWasmArenaor writeBytes).