Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

assemblyscript-loader

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

assemblyscript-loader - npm Package Compare versions

Comparing version 0.1.0 to 0.2.0

14

index.d.ts

@@ -31,4 +31,4 @@ /// <reference types="webassembly-js-api" />

export interface IArrayMemoryAccessor {
/** Gets an array from memory at the specified pointer and returns its length and element base pointer. */
get(ptr: number): { length: number, base: number };
/** Gets an array from memory at the specified pointer and returns its capacity, length and element base pointer. */
get(ptr: number): { capacity: number, length: number, base: number };
/** Creates an array in memory and returns its pointer and element base pointer. */

@@ -46,2 +46,10 @@ create(length: number, elementByteSize: number): { ptr: number, base: number };

/** Log message type. */
export enum LogType {
LOG = 0,
INFO = 1,
WARN = 2,
ERROR = 3
}
/** Common module interface as returned by {@link load}. */

@@ -63,2 +71,4 @@ export interface IModule {

growMemory(numPages: number): number;
/** An overridable function called for each log message. */
log(type: LogType, message: string): void;

@@ -65,0 +75,0 @@ /** Signed 8-bit integer accessors. */

48

index.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.load = exports.default = load;
module.exports = load;

@@ -8,2 +8,7 @@ var Long; try { Long = require("long"); } catch (e) { /**/ }

var arrayHeaderSize = 8; // capacity and length
load.LogType = { LOG: 0, INFO: 1, WARN: 2, ERROR: 3 };
load.load = load.default = load;
function load(file, options) {

@@ -15,4 +20,11 @@ if (!options) options = {};

imports.memory = options.memory;
if (!imports.env)
imports.env = {};
var buffer;
if (!imports.env.log)
imports.env.log = function log(type, message) {
return module.log(type, module.string.get(message));
}
var module = {

@@ -29,2 +41,11 @@ memory: options.memory || null,

return previousPages;
},
log: function log(type, message) {
switch (type) {
case 1: type = "info"; break;
case 2: type = "warn"; break;
case 3: type = "error"; break;
default: type = "log";
}
console[type](message);
}

@@ -223,14 +244,17 @@ };

get: function(ptr) {
var length = module.uint.get(ptr);
var capacity = module.int.get(ptr);
var length = module.int.get(ptr + 4);
return {
capacity: capacity,
length: length,
base: ptr + 4
base: ptr + arrayHeaderSize
};
},
create: function(length, elementByteSize) {
var ptr = (module.exports.malloc || imports.env.malloc)(4 + length * elementByteSize);
module.uint.set(ptr, length);
var ptr = (module.exports.malloc || imports.env.malloc)(arrayHeaderSize + length * elementByteSize);
module.int.set(ptr, length); // capacity
module.int.set(ptr + 4, length); // length
return {
ptr: ptr,
base: ptr + 4
base: ptr + arrayHeaderSize
};

@@ -242,5 +266,6 @@ }

get: function(ptr) {
var length = module.uint.get(ptr);
var capacity = module.int.get(ptr);
var length = module.int.get(ptr + 4);
var chars = new Array(length);
for (var i = 0, base = 4 + ptr; i < length; ++i)
for (var i = 0, base = arrayHeaderSize + ptr; i < length; ++i)
chars[i] = module.ushort.get(base + (i << 1));

@@ -250,5 +275,6 @@ return String.fromCharCode.apply(String, chars); // TODO: chunking

create: function(value) {
var ptr = (module.exports.malloc || imports.env.malloc)(4 + (value.length << 1));
module.uint.set(ptr, value.length);
for (var i = 0, base = 4 + ptr; i < value.length; ++i)
var ptr = (module.exports.malloc || imports.env.malloc)(arrayHeaderSize + (value.length << 1));
module.int.set(ptr, value.length); // capacity
module.int.set(ptr + 4, value.length); // length
for (var i = 0, base = arrayHeaderSize + ptr; i < value.length; ++i)
module.ushort.set(base + (i << 1), value.charCodeAt(i));

@@ -255,0 +281,0 @@ return ptr;

{
"name": "assemblyscript-loader",
"description": "AssemblyScript's loader component as a stand-alone module.",
"version": "0.1.0",
"version": "0.2.0",
"author": "Daniel Wirtz <dcode+assemblyscript@dcode.io>",

@@ -6,0 +6,0 @@ "license": "Apache-2.0",

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc