primea-wasm-container
Advanced tools
Comparing version 0.3.1 to 0.3.2
15
index.js
@@ -8,9 +8,8 @@ const ReferanceMap = require('reference-map') | ||
* The wasm container runs wasm code and provides a basic API for wasm | ||
* interfaces for interacting with the kernel | ||
* @param {object} kernel - the kernel instance | ||
* interfaces for interacting with the actor | ||
* @param {object} actor - the actor instance | ||
* @param {object} interfaces - a map of interfaces to expose to the wasm binary | ||
*/ | ||
constructor (kernel, interfaces) { | ||
super() | ||
this.kernel = kernel | ||
constructor (actor, interfaces) { | ||
super(actor) | ||
this.imports = interfaces | ||
@@ -21,3 +20,3 @@ this.referanceMap = new ReferanceMap() | ||
async onCreation (message) { | ||
let code = this.kernel.code | ||
let code = this.actor.code | ||
if (!WebAssembly.validate(code)) { | ||
@@ -32,3 +31,3 @@ throw new Error('invalid wasm binary') | ||
} | ||
this.kernel.state.code = code | ||
this.actor.state.code = code | ||
} | ||
@@ -64,3 +63,3 @@ return this._run(message, 'onCreation') | ||
const result = await WebAssembly.instantiate(this.kernel.code, importMap) | ||
const result = await WebAssembly.instantiate(this.actor.code, importMap) | ||
this.instance = result.instance | ||
@@ -67,0 +66,0 @@ |
{ | ||
"name": "primea-wasm-container", | ||
"version": "0.3.1", | ||
"version": "0.3.2", | ||
"description": "", | ||
@@ -22,11 +22,11 @@ "main": "index.js", | ||
"webassembly", | ||
"primae" | ||
"primea" | ||
], | ||
"devDependencies": { | ||
"coveralls": "^3.0.0", | ||
"dfinity-radix-tree": "0.0.4", | ||
"coveralls": "^3.0.0", | ||
"level": "^2.0.0", | ||
"nyc": "^11.2.1", | ||
"primea-hypervisor": "0.3.0", | ||
"primea-message": "0.0.2", | ||
"level-browserify": "^1.1.1", | ||
"nyc": "^11.3.0", | ||
"primea-hypervisor": "^0.4.1", | ||
"primea-message": "^0.6.0", | ||
"standard": "^10.0.0", | ||
@@ -37,3 +37,3 @@ "tape": "^4.6.3", | ||
"dependencies": { | ||
"primea-abstract-container": "0.0.5", | ||
"primea-abstract-container": "0.0.6", | ||
"primea-container-table": "0.0.0", | ||
@@ -40,0 +40,0 @@ "reference-map": "1.0.0" |
@@ -7,10 +7,27 @@ [![NPM Package](https://img.shields.io/npm/v/primea-wasm-container.svg?style=flat-square)](https://www.npmjs.org/package/primea-wasm-container) | ||
# install | ||
`npm install primea-wasm-container` | ||
# SYNOPSIS | ||
This implements a wasm container for the ewasm-kernel | ||
# INSTALL | ||
`npm install primea-wasm-container` | ||
# USAGE | ||
```javascript | ||
const WasmContainer = require('primea-wasm-container') | ||
// this class with get instantiated when a new wasm container instance is created | ||
// its methods with be exposed to the wasm binary as `imports` | ||
class HelloWorld { | ||
test () { | ||
console.log('hello world!') | ||
} | ||
} | ||
// regester the container with the a hypervisor instance | ||
hypervisor.registerContainer(WasmContainer, { | ||
env: HelloWorld | ||
}) | ||
``` | ||
# LICENSE | ||
[MPL-2.0](https://tldrlegal.com/license/mozilla-public-license-2.0-(mpl-2)) |
@@ -7,3 +7,3 @@ const tape = require('tape') | ||
const testInterface = require('./testInterface.js') | ||
const level = require('level') | ||
const level = require('level-browserify') | ||
const RadixTree = require('dfinity-radix-tree') | ||
@@ -50,8 +50,6 @@ const db = level('./testdb') | ||
const port = hypervisor.creationService.getPort() | ||
let instance = await hypervisor.send(port, new Message({ | ||
data: Buffer.concat([Buffer.from([0]), Buffer.from([WasmContainer.typeId]), main]) | ||
let cap = await hypervisor.createActor(WasmContainer.typeId, new Message({ | ||
data: main | ||
})) | ||
instance.message(instance.createMessage()) | ||
hypervisor.send(cap, new Message()) | ||
}) | ||
@@ -67,8 +65,5 @@ | ||
}) | ||
const ports = hypervisor.createChannel() | ||
const port = hypervisor.creationService.getPort() | ||
hypervisor.send(port, new Message({ | ||
data: Buffer.concat([Buffer.from([0]), Buffer.from([WasmContainer.typeId]), main]), | ||
ports: ports | ||
hypervisor.createActor(WasmContainer.typeId, new Message({ | ||
data: main | ||
})) | ||
@@ -86,6 +81,4 @@ }) | ||
const port = hypervisor.creationService.getPort() | ||
hypervisor.send(port, new Message({ | ||
data: Buffer.concat([Buffer.from([0]), Buffer.from([WasmContainer.typeId]), readMem]) | ||
hypervisor.createActor(WasmContainer.typeId, new Message({ | ||
data: readMem | ||
})) | ||
@@ -97,3 +90,8 @@ }) | ||
const readMem = fs.readFileSync(`${__dirname}/wasm/writeMem.wasm`) | ||
hypervisor.registerContainer(WasmContainer, { | ||
class WasmContainerNoIdle extends WasmContainer { | ||
onIdle () {} | ||
} | ||
hypervisor.registerContainer(WasmContainerNoIdle, { | ||
env: ContainerTestInterface, | ||
@@ -103,7 +101,7 @@ test: testInterface(t) | ||
const port = hypervisor.creationService.getPort() | ||
const root = await hypervisor.send(port, new Message({ | ||
data: Buffer.concat([Buffer.from([0]), Buffer.from([WasmContainer.typeId]), readMem]) | ||
const cap = await hypervisor.createActor(WasmContainerNoIdle.typeId, new Message({ | ||
data: readMem | ||
})) | ||
const mem = root.container.getMemory(0, 1) | ||
const actor = await hypervisor.getActor(cap.destId) | ||
const mem = actor.container.getMemory(0, 1) | ||
t.equals(mem[0], 9) | ||
@@ -122,5 +120,4 @@ t.end() | ||
const port = hypervisor.creationService.getPort() | ||
await hypervisor.send(port, new Message({ | ||
data: Buffer.concat([Buffer.from([0]), Buffer.from([WasmContainer.typeId]), callBackWasm]) | ||
await hypervisor.createActor(WasmContainer.typeId, new Message({ | ||
data: callBackWasm | ||
})) | ||
@@ -138,11 +135,10 @@ }) | ||
const message = new Message({ | ||
data: Buffer.concat([Buffer.from([0]), Buffer.from([WasmContainer.typeId]), Buffer.from([0])]) | ||
data: Buffer.from([0]) | ||
}) | ||
const rp = message.responsePort = {destPort: {messages: []}} | ||
message.on('execution:error', (e) => { | ||
t.pass('should cature error') | ||
}) | ||
const port = hypervisor.creationService.getPort() | ||
await hypervisor.send(port, message) | ||
t.equals(rp.destPort.messages[0].data.exception, true) | ||
await hypervisor.createActor(WasmContainer.typeId, message) | ||
}) | ||
@@ -180,6 +176,5 @@ | ||
const port = hypervisor.creationService.getPort() | ||
hypervisor.send(port, new Message({ | ||
data: Buffer.concat([Buffer.from([0]), Buffer.from([WasmContainer.typeId]), callBackWasm]) | ||
await hypervisor.createActor(WasmContainer.typeId, new Message({ | ||
data: callBackWasm | ||
})) | ||
}) |
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
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
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
177084
53
33
684
5
+ Addedprimea-abstract-container@0.0.6(transitive)
- Removedprimea-abstract-container@0.0.5(transitive)