1.0.4 • Published 9 months ago

wasm-imports-parser v1.0.4

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

wasm-imports-parser

npm version

A simple parser for WebAssembly imports with WebAssembly Type Reflection JS API compatibility.

Typically useful for constructing shared memory with a limit requested by imports of a WebAssembly module.

Installation

npm install wasm-imports-parser

Example

import { parseImports } from 'wasm-imports-parser';

const moduleBytes = new Uint8Array([
    0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00,
    0x02, 0x06, 0x01, 0x00, 0x00, 0x02, 0x00, 0x01,
]);
const imports = parseImports(moduleBytes);
console.log(imports);
// > [
// >   {
// >     module: '',
// >     name: '',
// >     kind: 'memory',
// >     type: { minimum: 1, shared: false, index: 'i32' }
// >   }
// > ]

As a polyfill for WebAssembly Type Reflection JS API

This parser can be used as a polyfill for the WebAssembly Type Reflection JS API.

import { polyfill } from 'wasm-imports-parser/polyfill.js';

const WebAssembly = polyfill(globalThis.WebAssembly);

const moduleBytes = new Uint8Array([
    0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00,
    0x02, 0x06, 0x01, 0x00, 0x00, 0x02, 0x00, 0x01,
]);
const module = await WebAssembly.compile(moduleBytes);
const imports = WebAssembly.Module.imports(module);
console.log(imports);
// > [
// >   {
// >     module: '',
// >     name: '',
// >     kind: 'memory',
// >     type: { minimum: 1, shared: false, index: 'i32' }
// >   }
// > ]

Implementation Status in JavaScript engines

EngineStatusNote
V8:white_check_mark:Available in Chrome 78 and later, and Node.js 13.0.0 and later
SpiderMonkey:construction:Available in Firefox Nightly
JavaScriptCore:x:Not available as of 2024-06

License

This project is licensed under the MIT License - see the LICENSE file for details.

1.0.4

9 months ago

1.0.3

10 months ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago