@assemblyscript/loader
Advanced tools
Comparing version 0.16.1 to 0.17.0
@@ -28,6 +28,2 @@ /// <reference lib="esnext.bigint" /> | ||
_start(): void; | ||
/** Allocates a new string in the module's memory and returns a reference (pointer) to it. */ | ||
__allocString(str: string): number; | ||
/** Allocates a new array in the module's memory and returns a reference (pointer) to it. */ | ||
__allocArray(id: number, values: ArrayLike<number>): number; | ||
@@ -89,2 +85,8 @@ /** Copies a string's value from the module's memory. */ | ||
/** Allocates an instance of the class represented by the specified id. */ | ||
__new(size: number, id: number): number; | ||
/** Allocates a new string in the module's memory and returns a reference (pointer) to it. */ | ||
__newString(str: string): number; | ||
/** Allocates a new array in the module's memory and returns a reference (pointer) to it. */ | ||
__newArray(id: number, values: ArrayLike<number>): number; | ||
/** Retains a reference to a managed object externally, making sure that it doesn't become collected prematurely. Returns the pointer. */ | ||
@@ -96,4 +98,2 @@ __retain(ptr: number): number; | ||
__reset?(): void; | ||
/** Allocates an instance of the class represented by the specified id. */ | ||
__alloc(size: number, id: number): number; | ||
/** Tests whether a managed object is an instance of the class represented by the specified base id. */ | ||
@@ -100,0 +100,0 @@ __instanceof(ptr: number, baseId: number): boolean; |
39
index.js
@@ -1,3 +0,1 @@ | ||
"use strict"; | ||
// Runtime header offsets | ||
@@ -86,3 +84,3 @@ const ID_OFFSET = -8; | ||
const table = exports.table; | ||
const alloc = exports["__alloc"]; | ||
const new_ = exports["__new"]; | ||
const retain = exports["__retain"]; | ||
@@ -125,5 +123,5 @@ const rttiBase = exports["__rtti_base"] || ~0; // oob if not present | ||
/** Allocates a new string in the module's memory and returns its retained pointer. */ | ||
function __allocString(str) { | ||
function __newString(str) { | ||
const length = str.length; | ||
const ptr = alloc(length << 1, STRING_ID); | ||
const ptr = new_(length << 1, STRING_ID); | ||
const U16 = new Uint16Array(memory.buffer); | ||
@@ -134,3 +132,3 @@ for (var i = 0, p = ptr >>> 1; i < length; ++i) U16[p + i] = str.charCodeAt(i); | ||
extendedExports.__allocString = __allocString; | ||
extendedExports.__newString = __newString; | ||
@@ -167,7 +165,7 @@ /** Reads a string from the module's memory by its pointer. */ | ||
/** Allocates a new array in the module's memory and returns its retained pointer. */ | ||
function __allocArray(id, values) { | ||
function __newArray(id, values) { | ||
const info = getArrayInfo(id); | ||
const align = getValueAlign(info); | ||
const length = values.length; | ||
const buf = alloc(length << align, info & STATICARRAY ? id : ARRAYBUFFER_ID); | ||
const buf = new_(length << align, info & STATICARRAY ? id : ARRAYBUFFER_ID); | ||
let result; | ||
@@ -177,3 +175,3 @@ if (info & STATICARRAY) { | ||
} else { | ||
const arr = alloc(info & ARRAY ? ARRAY_SIZE : ARRAYBUFFERVIEW_SIZE, id); | ||
const arr = new_(info & ARRAY ? ARRAY_SIZE : ARRAYBUFFERVIEW_SIZE, id); | ||
const U32 = new Uint32Array(memory.buffer); | ||
@@ -195,3 +193,3 @@ U32[arr + ARRAYBUFFERVIEW_BUFFER_OFFSET >>> 2] = retain(buf); | ||
extendedExports.__allocArray = __allocArray; | ||
extendedExports.__newArray = __newArray; | ||
@@ -306,3 +304,3 @@ /** Gets a live view on an array's values in the module's memory. Infers the array type from RTTI. */ | ||
/** Asynchronously instantiates an AssemblyScript module from anything that can be instantiated. */ | ||
async function instantiate(source, imports = {}) { | ||
export async function instantiate(source, imports = {}) { | ||
if (isResponse(source = await source)) return instantiateStreaming(source, imports); | ||
@@ -316,6 +314,4 @@ const module = isModule(source) ? source : await WebAssembly.compile(source); | ||
exports.instantiate = instantiate; | ||
/** Synchronously instantiates an AssemblyScript module from a WebAssembly.Module or binary buffer. */ | ||
function instantiateSync(source, imports = {}) { | ||
export function instantiateSync(source, imports = {}) { | ||
const module = isModule(source) ? source : new WebAssembly.Module(source); | ||
@@ -328,6 +324,4 @@ const extended = preInstantiate(imports); | ||
exports.instantiateSync = instantiateSync; | ||
/** Asynchronously instantiates an AssemblyScript module from a response, i.e. as obtained by `fetch`. */ | ||
async function instantiateStreaming(source, imports = {}) { | ||
export async function instantiateStreaming(source, imports = {}) { | ||
if (!WebAssembly.instantiateStreaming) { | ||
@@ -347,6 +341,4 @@ return instantiate( | ||
exports.instantiateStreaming = instantiateStreaming; | ||
/** Demangles an AssemblyScript module's exports to a friendly object structure. */ | ||
function demangle(exports, extendedExports = {}) { | ||
export function demangle(exports, extendedExports = {}) { | ||
extendedExports = Object.create(extendedExports); | ||
@@ -433,2 +425,7 @@ const setArgumentsLength = exports["__argumentsLength"] | ||
exports.demangle = demangle; | ||
export default { | ||
instantiate, | ||
instantiateSync, | ||
instantiateStreaming, | ||
demangle | ||
}; |
@@ -12,3 +12,3 @@ { | ||
], | ||
"version": "0.16.1", | ||
"version": "0.17.0", | ||
"author": "Daniel Wirtz <dcode+assemblyscript@dcode.io>", | ||
@@ -25,4 +25,9 @@ "license": "Apache-2.0", | ||
}, | ||
"type": "module", | ||
"main": "index.js", | ||
"types": "index.d.ts", | ||
"exports": { | ||
"import": "./index.js", | ||
"require": "./umd/index.js" | ||
}, | ||
"scripts": { | ||
@@ -32,3 +37,4 @@ "asbuild": "npm run asbuild:default && npm run asbuild:legacy", | ||
"asbuild:legacy": "node ../../bin/asc tests/assembly/index.ts --disable mutable-globals -b tests/build/legacy.wasm", | ||
"test": "node tests" | ||
"build": "npx esm2umd loader index.js > umd/index.js", | ||
"test": "node tests && node tests/umd" | ||
}, | ||
@@ -39,4 +45,7 @@ "files": [ | ||
"package.json", | ||
"umd/index.d.ts", | ||
"umd/index.js", | ||
"umd/package.json", | ||
"README.md" | ||
] | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
39734
7
879
Yes