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 1.0.2 to 1.1.0

src/wasi_none.rs

2

package.json
{
"name": "@wasmer/wasi",
"version": "1.0.2",
"version": "1.1.0",
"main": "dist/Library.cjs.min.js",

@@ -5,0 +5,0 @@ "module": "dist/Library.esm.min.js",

@@ -6,7 +6,7 @@ const fs = require('fs');

async function initWasi(moduleBytes, config) {
async function initWasi(moduleBytes, config, imports = {}) {
let wasi = new WASI(config);
const module = await WebAssembly.compile(moduleBytes);
await wasi.instantiate(module, {});
return wasi;
const instance = await wasi.instantiate(module, imports);
return [wasi, instance];
}

@@ -19,3 +19,3 @@

test('envvar works', async () => {
let wasi = await initWasi(fs.readFileSync(__dirname + '/envvar.wasm'), {
let [wasi, instance] = await initWasi(fs.readFileSync(__dirname + '/envvar.wasm'), {
env: {

@@ -27,3 +27,3 @@ DOG: "X",

});
let code = wasi.start();
let code = wasi.start(instance);
expect(wasi.getStdoutString()).toBe(`Env vars:

@@ -41,4 +41,4 @@ DOG=X

let contents = fs.readFileSync(__dirname + '/demo.wasm');
let wasi = await initWasi(contents, {});
let code = wasi.start();
let [wasi, instance] = await initWasi(contents, {});
let code = wasi.start(instance);
expect(wasi.getStdoutString()).toBe("hello world\n");

@@ -49,5 +49,5 @@ });

let contents = fs.readFileSync(__dirname + '/pipe_reverse.wasm');
let wasi = await initWasi(contents, {});
let [wasi, instance] = await initWasi(contents, {});
wasi.setStdinString("Hello World!");
let code = wasi.start();
let code = wasi.start(instance);
expect(wasi.getStdoutString()).toBe("!dlroW olleH\n");

@@ -58,3 +58,3 @@ });

let contents = fs.readFileSync(__dirname + '/mapdir.wasm');
let wasi = await initWasi(contents, {});
let [wasi, instance] = await initWasi(contents, {});
wasi.fs.createDir("/a");

@@ -67,4 +67,102 @@ wasi.fs.createDir("/b");

// console.log(wasi.fs.readDir("/"));
let code = wasi.start();
let code = wasi.start(instance);
expect(wasi.getStdoutString()).toBe(`"./a"\n"./b"\n"./file"\n`);
});
test('testing wasm', async() => {
let contents = fs.readFileSync(__dirname + '/test.wasm');
let [wasi, instance] = await initWasi(contents, {}, {
'module': {
'external': function() { console.log("external: hello world!") }
}});
// Run the start function
let exitCode = wasi.start(instance);
let stdout = wasi.getStdoutString();
// This should print "hello world (exit code: 0)"
console.log(`${stdout}(exit code: ${exitCode})`);
})
test('wasi start empty fails', async() => {
let moduleBytes = fs.readFileSync(__dirname + '/test.wasm');
let wasi = new WASI({});
const module = await WebAssembly.compile(moduleBytes);
let imports = wasi.get_imports(module);
// console.log(imports);
let instance = await WebAssembly.instantiate(module, {
...imports,
'module': {
'external': function() { console.log("external: hello world!") }
}
});
expect(() => wasi.start()).toThrow("`wasi.start` now receives the instance as the first argument (received none)");
});
test('get imports', async() => {
let moduleBytes = fs.readFileSync(__dirname + '/test.wasm');
let wasi = new WASI({});
const module = await WebAssembly.compile(moduleBytes);
let imports = wasi.get_imports(module);
// console.log(imports);
let instance = await WebAssembly.instantiate(module, {
...imports,
'module': {
'external': function() { console.log("external: hello world!") }
}
});
let exitCode = wasi.start(instance);
let stdout = wasi.getStdoutString();
// This should print "hello world (exit code: 0)"
console.log(`${stdout}(exit code: ${exitCode})`);
// expect(Object.keys(imports["wasi_snapshot_preview1"])).toStrictEqual([
// "fd_datasync",
// "fd_write",
// "poll_oneoff",
// "fd_advise",
// "sock_shutdown",
// "fd_prestat_dir_name",
// "path_readlink",
// "args_sizes_get",
// "fd_sync",
// "path_symlink",
// "path_rename",
// "clock_res_get",
// "path_unlink_file",
// "path_link",
// "path_remove_directory",
// "fd_allocate",
// "path_create_directory",
// "environ_sizes_get",
// "proc_exit",
// "random_get",
// "fd_fdstat_set_flags",
// "fd_close",
// "environ_get",
// "fd_readdir",
// "fd_read",
// "fd_seek",
// "fd_filestat_get",
// "path_open",
// "proc_raise",
// "fd_tell",
// "fd_fdstat_get",
// "sched_yield",
// "fd_pread",
// "fd_renumber",
// "fd_pwrite",
// "path_filestat_set_times",
// "sock_recv",
// "fd_fdstat_set_rights",
// "fd_prestat_get",
// "path_filestat_get",
// "fd_filestat_set_times",
// "fd_filestat_set_size",
// "sock_send",
// "args_get",
// "clock_time_get"
// ]);
})

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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

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

Sorry, the diff of this file is not supported yet

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