Socket
Socket
Sign inDemoInstall

@webassemblyjs/ast

Package Overview
Dependencies
5
Maintainers
1
Versions
86
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

@webassemblyjs/ast

AST utils for webassemblyjs


Version published
Maintainers
1
Weekly downloads
23,600,035
decreased by-7%

Weekly downloads

Package description

What is @webassemblyjs/ast?

The @webassemblyjs/ast package is a toolchain for WebAssembly manipulation which allows you to parse, validate, and generate WebAssembly code. It provides an Abstract Syntax Tree (AST) representation of WebAssembly modules, enabling programmatic analysis and transformation of Wasm code.

What are @webassemblyjs/ast's main functionalities?

Parsing WebAssembly binary

This feature allows you to parse a WebAssembly binary into an AST. The code sample demonstrates how to use the wasm-parser submodule to decode a binary representation of a WebAssembly module.

"use strict";\nconst { decode } = require('@webassemblyjs/wasm-parser');\nconst binary = new Uint8Array([0x00, 0x61, 0x73, 0x6d, ...]);\nconst ast = decode(binary);\nconsole.log(ast);

Generating WebAssembly binary

This feature enables you to generate a WebAssembly binary from an AST. The code sample shows how to create an empty WebAssembly module using the ast submodule and then encode it into a binary with wasm-gen.

"use strict";\nconst { encode } = require('@webassemblyjs/wasm-gen');\nconst t = require('@webassemblyjs/ast');\nconst module = t.module([], []);\nconst binary = encode(module);\nconsole.log(new Uint8Array(binary));

Traversing and modifying the AST

This feature is for traversing the AST and applying modifications. The code sample illustrates how to traverse an existing AST and log each ModuleImport node encountered.

"use strict";\nconst { traverse } = require('@webassemblyjs/ast');\nconst ast = ...; // Assume this is an existing AST\ntraverse(ast, {\n  ModuleImport(path) {\n    console.log(path.node);\n  }\n});

Other packages similar to @webassemblyjs/ast

Readme

Source

@webassemblyjs/ast

AST utils for webassemblyjs

Installation

yarn add @webassemblyjs/ast

Usage

Traverse

import { traverse } from "@webassemblyjs/ast";

traverse(ast, {
  Module(path) {
    console.log(path.node);
  }
});

Instruction signatures

import { signatures } from "@webassemblyjs/ast";

console.log(signatures);

Path methods

  • findParent: NodeLocator
  • replaceWith: Node => void
  • remove: () => void
  • insertBefore: Node => void
  • insertAfter: Node => void
  • stop: () => void

AST utils

  • function module(id, fields, metadata)
  • function moduleMetadata(sections, functionNames, localNames)
  • function moduleNameMetadata(value)
  • function functionNameMetadata(value, index)
  • function localNameMetadata(value, localIndex, functionIndex)
  • function binaryModule(id, blob)
  • function quoteModule(id, string)
  • function sectionMetadata(section, startOffset, size, vectorOfSize)
  • function loopInstruction(label, resulttype, instr)
  • function instruction(id, args, namedArgs)
  • function objectInstruction(id, object, args, namedArgs)
  • function ifInstruction(testLabel, test, result, consequent, alternate)
  • function stringLiteral(value)
  • function numberLiteralFromRaw(value, raw)
  • function longNumberLiteral(value, raw)
  • function floatLiteral(value, nan, inf, raw)
  • function elem(table, offset, funcs)
  • function indexInFuncSection(index)
  • function valtypeLiteral(name)
  • function typeInstruction(id, functype)
  • function start(index)
  • function globalType(valtype, mutability)
  • function leadingComment(value)
  • function blockComment(value)
  • function data(memoryIndex, offset, init)
  • function global(globalType, init, name)
  • function table(elementType, limits, name, elements)
  • function memory(limits, id)
  • function funcImportDescr(id, signature)
  • function moduleImport(module, name, descr)
  • function moduleExportDescr(exportType, id)
  • function moduleExport(name, descr)
  • function limit(min, max)
  • function signature(params, results)
  • function program(body)
  • function identifier(value, raw)
  • function blockInstruction(label, instr, result)
  • function callInstruction(index, instrArgs)
  • function callIndirectInstruction(signature, intrs)
  • function byteArray(values)
  • function func(name, signature, body, isExternal, metadata)
  • ConstantisModule
  • ConstantisModuleMetadata
  • ConstantisModuleNameMetadata
  • ConstantisFunctionNameMetadata
  • ConstantisLocalNameMetadata
  • ConstantisBinaryModule
  • ConstantisQuoteModule
  • ConstantisSectionMetadata
  • ConstantisLoopInstruction
  • ConstantisInstruction
  • ConstantisObjectInstruction
  • ConstantisIfInstruction
  • ConstantisStringLiteral
  • ConstantisNumberLiteral
  • ConstantisLongNumberLiteral
  • ConstantisFloatLiteral
  • ConstantisElem
  • ConstantisIndexInFuncSection
  • ConstantisValtypeLiteral
  • ConstantisTypeInstruction
  • ConstantisStart
  • ConstantisGlobalType
  • ConstantisLeadingComment
  • ConstantisBlockComment
  • ConstantisData
  • ConstantisGlobal
  • ConstantisTable
  • ConstantisMemory
  • ConstantisFuncImportDescr
  • ConstantisModuleImport
  • ConstantisModuleExportDescr
  • ConstantisModuleExport
  • ConstantisLimit
  • ConstantisSignature
  • ConstantisProgram
  • ConstantisIdentifier
  • ConstantisBlockInstruction
  • ConstantisCallInstruction
  • ConstantisCallIndirectInstruction
  • ConstantisByteArray
  • ConstantisFunc
  • ConstantassertModule
  • ConstantassertModuleMetadata
  • ConstantassertModuleNameMetadata
  • ConstantassertFunctionNameMetadata
  • ConstantassertLocalNameMetadata
  • ConstantassertBinaryModule
  • ConstantassertQuoteModule
  • ConstantassertSectionMetadata
  • ConstantassertLoopInstruction
  • ConstantassertInstruction
  • ConstantassertObjectInstruction
  • ConstantassertIfInstruction
  • ConstantassertStringLiteral
  • ConstantassertNumberLiteral
  • ConstantassertLongNumberLiteral
  • ConstantassertFloatLiteral
  • ConstantassertElem
  • ConstantassertIndexInFuncSection
  • ConstantassertValtypeLiteral
  • ConstantassertTypeInstruction
  • ConstantassertStart
  • ConstantassertGlobalType
  • ConstantassertLeadingComment
  • ConstantassertBlockComment
  • ConstantassertData
  • ConstantassertGlobal
  • ConstantassertTable
  • ConstantassertMemory
  • ConstantassertFuncImportDescr
  • ConstantassertModuleImport
  • ConstantassertModuleExportDescr
  • ConstantassertModuleExport
  • ConstantassertLimit
  • ConstantassertSignature
  • ConstantassertProgram
  • ConstantassertIdentifier
  • ConstantassertBlockInstruction
  • ConstantassertCallInstruction
  • ConstantassertCallIndirectInstruction
  • ConstantassertByteArray
  • ConstantassertFunc

Keywords

FAQs

Last updated on 09 May 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc