New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

@schleifner/assemblyscript-transform

Package Overview
Dependencies
Maintainers
5
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@schleifner/assemblyscript-transform

const utf8 string literal in AssemblyScript

latest
Source
npmnpm
Version
0.1.1
Version published
Weekly downloads
0
-100%
Maintainers
5
Weekly downloads
 
Created
Source

Introduction

This repo is AssemblyScript transforms to enhance AssemblyScript features

Utf8 string literal

This is a transform of AssemblyScript to store const utf8 string literal.

The string literal in AssemblyScript is utf16 encoded into Wasm data section, this brings two problems:

  • String storage has too much overhead for ascii strings
  • Need to convert utf16 to utf8 string when calling native API which receives utf8/ascii strings.

To solve this problem, this repo provides a transform of AssemblyScript to define utf8 string literals

Principle

This transform scans function call pattern

utf8.build("string literal");

and replace it to

utf8.build_internal(memory.data<u8>([bytes in utf8]), length of bytes);

For example:

utf8.build("test3");

is transferred to

utf8.build_internal(memory.data<u8>([116, 101, 115, 116, 51]), 5);

Attentions:

  • The AST transform is based on string pattern matcher, so alias is not supported. Please don't use name alias of import and indirect function call to utf8.build, for example import {utf8 as utf_8} or let foo = utf8.build; foo("abc").

  • The parameter of utf8.build must be string literal

Usage

Install assemblyscript-transform

npm install @schleifner/assemblyscript-transform

In AssemblyScript code, src/index.ts

import {utf8} from "../node_modules/@schleifner/assemblyscript-transform/as/utf8ConstStr"
const str = utf8.build("test3");

Build with transform

asc -o out.wasm --transform ./node_modules/@schleifner/assemblyscript-transform/dist/transformBuildUtf8ConstStr.mjs ./src/index.ts

Keywords

Assemblyscript

FAQs

Package last updated on 14 Apr 2025

Did you know?

Socket

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