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

@wasmer/wasi

Package Overview
Dependencies
Maintainers
1
Versions
44
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@wasmer/wasi - npm Package Compare versions

Comparing version 0.11.1 to 0.11.2

9

lib/bindings/browser.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
// @ts-ignore
const randomfill = tslib_1.__importStar(require("randomfill"));
const browser_hrtime_1 = tslib_1.__importDefault(require("../polyfills/browser-hrtime"));
const randomfill = require("randomfill");
const browser_hrtime_1 = require("../polyfills/browser-hrtime");
// @ts-ignore
const path = tslib_1.__importStar(require("path-browserify"));
const path = require("path-browserify");
const index_1 = require("../index");
const hrtime_bigint_1 = tslib_1.__importDefault(require("../polyfills/hrtime.bigint"));
const hrtime_bigint_1 = require("../polyfills/hrtime.bigint");
const bindings = {

@@ -12,0 +11,0 @@ hrtime: hrtime_bigint_1.default(browser_hrtime_1.default),

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const crypto = require("crypto");

@@ -8,3 +7,3 @@ const fs = require("fs");

const path = require("path");
const hrtime_bigint_1 = tslib_1.__importDefault(require("../polyfills/hrtime.bigint"));
const hrtime_bigint_1 = require("../polyfills/hrtime.bigint");
let bigIntHrtime = hrtime_bigint_1.default(process.hrtime);

@@ -11,0 +10,0 @@ if (process.hrtime && process.hrtime.bigint) {

@@ -179,5 +179,5 @@ export declare const WASI_ESUCCESS = 0;

export declare const WASI_STDERR_FILENO = 2;
export declare const WASI_WHENCE_CUR = 0;
export declare const WASI_WHENCE_END = 1;
export declare const WASI_WHENCE_SET = 2;
export declare const WASI_WHENCE_SET = 0;
export declare const WASI_WHENCE_CUR = 1;
export declare const WASI_WHENCE_END = 2;
export declare const ERROR_MAP: {

@@ -184,0 +184,0 @@ [key: string]: number;

@@ -281,5 +281,5 @@ "use strict";

exports.WASI_STDERR_FILENO = 2;
exports.WASI_WHENCE_CUR = 0;
exports.WASI_WHENCE_END = 1;
exports.WASI_WHENCE_SET = 2;
exports.WASI_WHENCE_SET = 0;
exports.WASI_WHENCE_CUR = 1;
exports.WASI_WHENCE_END = 2;
// http://man7.org/linux/man-pages/man3/errno.3.html

@@ -286,0 +286,0 @@ exports.ERROR_MAP = {

@@ -1,5 +0,3 @@

/// <reference types="node" />
import { BigIntPolyfillType } from "./polyfills/bigint";
import { DataViewPolyfillType } from "./polyfills/dataview";
import { Readable as ReadableStream, Writable as WritableStream } from 'stream';
import { WASI_FILETYPE } from "./constants";

@@ -61,8 +59,2 @@ interface Rights {

}
declare class StdinStream extends WritableStream {
buffer: Buffer;
constructor();
write(chunk: any, encoding: any, next?: (error: Error | null | undefined) => void): boolean;
readSync(iov: Uint8Array, offset: number, length: number): number;
}
export default class WASIDefault {

@@ -74,5 +66,2 @@ memory: WebAssembly.Memory;

bindings: WASIBindings;
stdin: StdinStream;
stdout: ReadableStream;
stderr: ReadableStream;
static defaultBindings: WASIBindings;

@@ -79,0 +68,0 @@ constructor(wasiConfig?: WASIConfigOld | WASIConfig);

"use strict";
/* eslint-disable no-unused-vars */
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const bigint_1 = require("./polyfills/bigint");
const dataview_1 = require("./polyfills/dataview");
const buffer_1 = tslib_1.__importDefault(require("./polyfills/buffer"));
const stream_1 = require("stream");
const buffer_1 = require("./polyfills/buffer");
// Import our default bindings depending on the environment

@@ -67,6 +65,13 @@ let defaultBindings;

const msInt = Math.trunc(ms);
const decimal = bigint_1.BigIntPolyfill(Math.round((ms - msInt) * 1000));
const ns = bigint_1.BigIntPolyfill(msInt) * bigint_1.BigIntPolyfill(1000);
const decimal = bigint_1.BigIntPolyfill(Math.round((ms - msInt) * 1000000));
const ns = bigint_1.BigIntPolyfill(msInt) * bigint_1.BigIntPolyfill(1000000);
return ns + decimal;
};
const nsToMs = (ns) => {
if (typeof ns === 'number') {
ns = Math.trunc(ns);
}
const nsInt = bigint_1.BigIntPolyfill(ns);
return Number(nsInt / bigint_1.BigIntPolyfill(1000000));
};
const wrap = (f) => (...args) => {

@@ -192,25 +197,2 @@ try {

exports.WASIKillError = WASIKillError;
class StdinStream extends stream_1.Writable {
constructor() {
super();
this.buffer = buffer_1.default.alloc(0);
}
write(chunk, encoding, next) {
// console.log("wasi.stdin.write() called", chunk, chunk.toString());
let newBuf = buffer_1.default.from(chunk);
this.buffer = buffer_1.default.concat([this.buffer, newBuf]);
if (next)
next(undefined);
return true;
}
readSync(iov, offset, length) {
console.log("READ SYNC internal");
iov.set(this.buffer, offset);
/// If we are asking for less data than we have available
let consumed = Math.min(length, this.buffer.byteLength);
// We adjust the buffer removing the used data
this.buffer = this.buffer.slice(consumed);
return consumed;
}
}
class WASIDefault {

@@ -239,13 +221,2 @@ constructor(wasiConfig) {

}
let self = this;
let pendingStdin = new Array();
this.stdin = new StdinStream();
this.stdout = new stream_1.Readable({
read: () => { return true; }
});
this.stdout.resume();
this.stderr = new stream_1.Readable({
read: () => { return true; }
});
this.stderr.resume();
// @ts-ignore

@@ -343,3 +314,3 @@ this.memory = undefined;

case constants_1.WASI_CLOCK_REALTIME:
return msToNs(new Date().valueOf());
return msToNs(Date.now());
case constants_1.WASI_CLOCK_PROCESS_CPUTIME_ID:

@@ -492,8 +463,27 @@ case constants_1.WASI_CLOCK_THREAD_CPUTIME_ID:

const stats = CHECK_FD(fd, constants_1.WASI_RIGHT_FD_FILESTAT_SET_TIMES);
const n = now(constants_1.WASI_CLOCK_REALTIME);
const atimNow = (fstflags & constants_1.WASI_FILESTAT_SET_ATIM_NOW) ===
constants_1.WASI_FILESTAT_SET_ATIM_NOW;
const mtimNow = (fstflags & constants_1.WASI_FILESTAT_SET_MTIM_NOW) ===
constants_1.WASI_FILESTAT_SET_MTIM_NOW;
fs.futimesSync(stats.real, atimNow ? n : stAtim, mtimNow ? n : stMtim);
const rstats = fs.fstatSync(stats.real);
let atim = rstats.atime;
let mtim = rstats.mtime;
const n = nsToMs(now(constants_1.WASI_CLOCK_REALTIME));
const atimflags = constants_1.WASI_FILESTAT_SET_ATIM | constants_1.WASI_FILESTAT_SET_ATIM_NOW;
if ((fstflags & atimflags) === atimflags) {
return constants_1.WASI_EINVAL;
}
const mtimflags = constants_1.WASI_FILESTAT_SET_MTIM | constants_1.WASI_FILESTAT_SET_MTIM_NOW;
if ((fstflags & mtimflags) === mtimflags) {
return constants_1.WASI_EINVAL;
}
if ((fstflags & constants_1.WASI_FILESTAT_SET_ATIM) === constants_1.WASI_FILESTAT_SET_ATIM) {
atim = nsToMs(stAtim);
}
else if ((fstflags & constants_1.WASI_FILESTAT_SET_ATIM_NOW) === constants_1.WASI_FILESTAT_SET_ATIM_NOW) {
atim = n;
}
if ((fstflags & constants_1.WASI_FILESTAT_SET_MTIM) === constants_1.WASI_FILESTAT_SET_MTIM) {
mtim = nsToMs(stMtim);
}
else if ((fstflags & constants_1.WASI_FILESTAT_SET_MTIM_NOW) === constants_1.WASI_FILESTAT_SET_MTIM_NOW) {
mtim = n;
}
fs.futimesSync(stats.real, new Date(atim), new Date(mtim));
return constants_1.WASI_ESUCCESS;

@@ -523,20 +513,6 @@ }),

let written = 0;
const IS_STDOUT = stats.real === 1;
const IS_STDERR = stats.real === 2;
getiovs(iovs, iovsLen).forEach(iov => {
let w = 0;
while (w < iov.byteLength) {
if (IS_STDOUT) {
let i = iov.byteLength - w;
this.stdout.push(iov.slice(w, i));
w += i;
continue;
}
else if (IS_STDERR) {
let i = iov.byteLength - w;
this.stderr.push(iov.slice(w, i));
w += i;
continue;
}
w += fs.writeSync(stats.real, iov, w, iov.byteLength - w, offset + written + w);
w += fs.writeSync(stats.real, iov, w, iov.byteLength - w, Number(offset) + written + w);
}

@@ -551,19 +527,5 @@ written += w;

let written = 0;
const IS_STDOUT = stats.real === 1;
const IS_STDERR = stats.real === 2;
getiovs(iovs, iovsLen).forEach(iov => {
let w = 0;
while (w < iov.byteLength) {
if (IS_STDOUT) {
let i = iov.byteLength - w;
this.stdout.push(buffer_1.default.from(iov.slice(w, i)));
w += i;
continue;
}
else if (IS_STDERR) {
let i = iov.byteLength - w;
this.stderr.push(buffer_1.default.from(iov.slice(w, i)));
w += i;
continue;
}
const i = fs.writeSync(stats.real, iov, w, iov.byteLength - w, stats.offset ? Number(stats.offset) : null);

@@ -582,9 +544,17 @@ if (stats.offset)

let read = 0;
getiovs(iovs, iovsLen).forEach(iov => {
outer: for (const iov of getiovs(iovs, iovsLen)) {
let r = 0;
while (r < iov.byteLength) {
r += fs.readSync(stats.real, iov, r, iov.byteLength - r, offset + read + r);
const length = iov.byteLength - r;
const rr = fs.readSync(stats.real, iov, r, iov.byteLength - r, Number(offset) + read + r);
r += rr;
read += rr;
// If we don't read anything, or we receive less than requested
if (rr === 0 || rr < length) {
break outer;
}
}
read += r;
});
}
;
this.view.setUint32(nread, read, true);

@@ -601,13 +571,3 @@ return constants_1.WASI_ESUCCESS;

let length = iov.byteLength - r;
if (IS_STDIN) {
let rr = this.stdin.readSync(iov, r, length);
console.log(rr);
r += rr;
read += rr;
if (rr === 0 || rr < length) {
break outer;
}
continue;
}
let position = stats.offset === undefined
let position = IS_STDIN || stats.offset === undefined
? null

@@ -621,4 +581,6 @@ : Number(stats.offset);

);
stats.offset =
(stats.offset ? stats.offset : bigint_1.BigIntPolyfill(0)) + bigint_1.BigIntPolyfill(rr);
if (!IS_STDIN) {
stats.offset =
(stats.offset ? stats.offset : bigint_1.BigIntPolyfill(0)) + bigint_1.BigIntPolyfill(rr);
}
r += rr;

@@ -769,5 +731,5 @@ read += rr;

this.view.setUint8(bufPtr, translateFileAttributes(this, undefined, rstats).filetype);
bufPtr += 4;
this.view.setUint32(bufPtr, Number(rstats.nlink), true);
bufPtr += 4;
bufPtr += 8;
this.view.setBigUint64(bufPtr, bigint_1.BigIntPolyfill(rstats.nlink), true);
bufPtr += 8;
this.view.setBigUint64(bufPtr, bigint_1.BigIntPolyfill(rstats.size), true);

@@ -780,6 +742,5 @@ bufPtr += 8;

this.view.setBigUint64(bufPtr, msToNs(rstats.ctimeMs), true);
bufPtr += 8;
return constants_1.WASI_ESUCCESS;
}),
path_filestat_set_times: wrap((fd, fstflags, pathPtr, pathLen, stAtim, stMtim) => {
path_filestat_set_times: wrap((fd, dirflags, pathPtr, pathLen, stAtim, stMtim, fstflags) => {
const stats = CHECK_FD(fd, constants_1.WASI_RIGHT_PATH_FILESTAT_SET_TIMES);

@@ -790,9 +751,28 @@ if (!stats.path) {

this.refreshMemory();
const n = now(constants_1.WASI_CLOCK_REALTIME);
const atimNow = (fstflags & constants_1.WASI_FILESTAT_SET_ATIM_NOW) ===
constants_1.WASI_FILESTAT_SET_ATIM_NOW;
const mtimNow = (fstflags & constants_1.WASI_FILESTAT_SET_MTIM_NOW) ===
constants_1.WASI_FILESTAT_SET_MTIM_NOW;
const rstats = fs.fstatSync(stats.real);
let atim = rstats.atime;
let mtim = rstats.mtime;
const n = nsToMs(now(constants_1.WASI_CLOCK_REALTIME));
const atimflags = constants_1.WASI_FILESTAT_SET_ATIM | constants_1.WASI_FILESTAT_SET_ATIM_NOW;
if ((fstflags & atimflags) === atimflags) {
return constants_1.WASI_EINVAL;
}
const mtimflags = constants_1.WASI_FILESTAT_SET_MTIM | constants_1.WASI_FILESTAT_SET_MTIM_NOW;
if ((fstflags & mtimflags) === mtimflags) {
return constants_1.WASI_EINVAL;
}
if ((fstflags & constants_1.WASI_FILESTAT_SET_ATIM) === constants_1.WASI_FILESTAT_SET_ATIM) {
atim = nsToMs(stAtim);
}
else if ((fstflags & constants_1.WASI_FILESTAT_SET_ATIM_NOW) === constants_1.WASI_FILESTAT_SET_ATIM_NOW) {
atim = n;
}
if ((fstflags & constants_1.WASI_FILESTAT_SET_MTIM) === constants_1.WASI_FILESTAT_SET_MTIM) {
mtim = nsToMs(stMtim);
}
else if ((fstflags & constants_1.WASI_FILESTAT_SET_MTIM_NOW) === constants_1.WASI_FILESTAT_SET_MTIM_NOW) {
mtim = n;
}
const p = buffer_1.default.from(this.memory.buffer, pathPtr, pathLen).toString();
fs.utimesSync(path.resolve(stats.path, p), atimNow ? n : stAtim, mtimNow ? n : stMtim);
fs.utimesSync(path.resolve(stats.path, p), new Date(atim), new Date(mtim));
return constants_1.WASI_ESUCCESS;

@@ -905,3 +885,9 @@ }),

}
const realfd = fs.openSync(full, noflags);
let realfd;
if (fs.statSync(full).isDirectory()) {
realfd = fs.openSync(full, fs.constants.O_RDONLY);
}
else {
realfd = fs.openSync(full, noflags);
}
const newfd = [...this.FD_MAP.keys()].reverse()[0] + 1;

@@ -1080,17 +1066,16 @@ this.FD_MAP.set(newfd, {

// Wrap each of the imports to show the calls in the console
Object.keys(this.wasiImport).forEach((key) => {
const prevImport = this.wasiImport[key];
this.wasiImport[key] = function (...args) {
console.log(`WASI: wasiImport called: ${key} (${args})`);
try {
let result = prevImport(...args);
console.log(`WASI: => ${result}`);
return result;
}
catch (e) {
console.log(`Catched error: ${e}`);
throw e;
}
};
});
// Object.keys(this.wasiImport).forEach((key: string) => {
// const prevImport = this.wasiImport[key];
// this.wasiImport[key] = function(...args: any[]) {
// console.log(`WASI: wasiImport called: ${key} (${args})`);
// try {
// let result = prevImport(...args);
// console.log(`WASI: => ${result}`);
// return result;
// } catch (e) {
// console.log(`Catched error: ${e}`);
// throw e;
// }
// };
// });
}

@@ -1119,6 +1104,2 @@ refreshMemory() {

}
// We indicate to the stdout and stderr that
// they will be no longer sending more data
this.stdout.push(null);
this.stderr.push(null);
}

@@ -1125,0 +1106,0 @@ getImportNamespace(module) {

@@ -179,5 +179,5 @@ export declare const WASI_ESUCCESS = 0;

export declare const WASI_STDERR_FILENO = 2;
export declare const WASI_WHENCE_CUR = 0;
export declare const WASI_WHENCE_END = 1;
export declare const WASI_WHENCE_SET = 2;
export declare const WASI_WHENCE_SET = 0;
export declare const WASI_WHENCE_CUR = 1;
export declare const WASI_WHENCE_END = 2;
export declare const ERROR_MAP: {

@@ -184,0 +184,0 @@ [key: string]: number;

@@ -1,5 +0,3 @@

/// <reference types="node" />
import { BigIntPolyfillType } from "./polyfills/bigint";
import { DataViewPolyfillType } from "./polyfills/dataview";
import { Readable as ReadableStream, Writable as WritableStream } from 'stream';
import { WASI_FILETYPE } from "./constants";

@@ -61,8 +59,2 @@ interface Rights {

}
declare class StdinStream extends WritableStream {
buffer: Buffer;
constructor();
write(chunk: any, encoding: any, next?: (error: Error | null | undefined) => void): boolean;
readSync(iov: Uint8Array, offset: number, length: number): number;
}
export default class WASIDefault {

@@ -74,5 +66,2 @@ memory: WebAssembly.Memory;

bindings: WASIBindings;
stdin: StdinStream;
stdout: ReadableStream;
stderr: ReadableStream;
static defaultBindings: WASIBindings;

@@ -79,0 +68,0 @@ constructor(wasiConfig?: WASIConfigOld | WASIConfig);

{
"name": "@wasmer/wasi",
"version": "0.11.1",
"version": "0.11.2",
"description": "Isomorphic Javascript library for interacting with WASI Modules in Node.js and the Browser. 📚",

@@ -53,3 +53,3 @@ "main": "lib/index.cjs.js",

},
"gitHead": "57fcb5d000f092c4681c4b8a6a4f4672e153fcf0"
"gitHead": "73410bde9d50945deef4824fb8ce6c0fd01c0145"
}

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

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