wasm-imports-parser
TypeScript icon, indicating that this package has built-in type declarations

1.0.4 • Public • Published

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' }
// >   }
// > ]

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

Engine Status Note
V8 Available in Chrome 78 and later, and Node.js 13.0.0 and later
SpiderMonkey 🚧 Available in Firefox Nightly
JavaScriptCore Not available as of 2024-06

License

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

Readme

Keywords

Package Sidebar

Install

npm i wasm-imports-parser

Weekly Downloads

66

Version

1.0.4

License

MIT

Unpacked Size

22.6 kB

Total Files

10

Last publish

Collaborators

  • kateinoigakukun