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

primea-wasm-container

Package Overview
Dependencies
Maintainers
1
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

primea-wasm-container - npm Package Compare versions

Comparing version 0.3.1 to 0.3.2

.nyc_output/3c119c67e3d97b4817d486ee25bbe09a.json

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
}))
})
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