primea-wasm-container
Advanced tools
Comparing version 0.6.0 to 0.7.0
52
index.js
@@ -1,3 +0,3 @@ | ||
const {Message, FunctionRef, ModuleRef, getType} = require('primea-objects') | ||
const {wasm2json, json2wasm} = require('wasm-json-toolkit') | ||
const { ID, Message, FunctionRef, ModuleRef, ActorRef, getType } = require('primea-objects') | ||
const { wasm2json, json2wasm } = require('wasm-json-toolkit') | ||
const annotations = require('primea-annotations') | ||
@@ -12,3 +12,3 @@ const persist = require('wasm-persist') | ||
function fromMetaJSON (json, id) { | ||
function getWasmExports (json) { | ||
const exports = {} | ||
@@ -19,3 +19,3 @@ for (const ex in json.exports) { | ||
} | ||
return new ModuleRef(exports, id) | ||
return exports | ||
} | ||
@@ -128,14 +128,26 @@ | ||
const bin = self.refs.get(dataRef, 'data') | ||
const {module} = self.actor.createActor(WasmContainer.typeId, bin) | ||
return self.refs.add(module, 'mod') | ||
const mod = self.actor.createModule(WasmContainer, bin) | ||
return self.refs.add(mod, 'mod') | ||
} | ||
}, | ||
actor: { | ||
new: modRef => { | ||
const module = self.refs.get(modRef, 'mod') | ||
const actor = self.actor.createActor(module) | ||
return self.refs.add(actor, 'actor') | ||
}, | ||
export: (modRef, dataRef) => { | ||
const mod = self.refs.get(modRef, 'mod') | ||
export: (actorRef, dataRef) => { | ||
const actor = self.refs.get(actorRef, 'actor') | ||
let name = self.refs.get(dataRef, 'data') | ||
name = Buffer.from(name).toString() | ||
const funcRef = mod.getFuncRef(name) | ||
const funcRef = actor.getFuncRef(name) | ||
return self.refs.add(funcRef, 'func') | ||
}, | ||
is_instance: (actorRef, modRef) => { | ||
const actor = self.refs.get(actorRef, 'actor') | ||
const module = self.refs.get(modRef, 'mod') | ||
return actor.modRef.id.id.equals(module.id.id) | ||
}, | ||
self: () => { | ||
return self.refs.add(this.modSelf, 'mod') | ||
return self.refs.add(this.actorSelf, 'actor') | ||
} | ||
@@ -189,3 +201,3 @@ }, | ||
static createModule (wasm, id) { | ||
static createModule (wasm) { | ||
if (!WebAssembly.validate(wasm)) { | ||
@@ -213,7 +225,7 @@ throw new Error('invalid wasm binary') | ||
}) | ||
const modRef = fromMetaJSON(json, id) | ||
const exports = getWasmExports(json) | ||
return { | ||
wasm, | ||
json, | ||
modRef, | ||
exports, | ||
state: json.persist.map(entry => { | ||
@@ -227,4 +239,4 @@ if (entry.type === 'anyref') { | ||
static onCreation (unverifiedWasm, id) { | ||
return this.createModule(unverifiedWasm, id) | ||
static onCreation (unverifiedWasm) { | ||
return this.createModule(unverifiedWasm) | ||
} | ||
@@ -321,7 +333,11 @@ | ||
async onStartup () { | ||
const code = this.actor.code | ||
const {json, wasm, modRef} = WasmContainer.createModule(code, this.actor.id) | ||
const module = this.actor.module | ||
const code = module[1][1]['/'] | ||
const {json, wasm, exports} = WasmContainer.createModule(code) | ||
this.mod = WebAssembly.Module(wasm) | ||
this.json = json | ||
this.modSelf = modRef | ||
const moduleID = new ID(module[1][0]) | ||
const state = module[2]['/'] | ||
const modRef = new ModuleRef(moduleID, WasmContainer.typeId, exports, state, code) | ||
this.actorSelf = new ActorRef(this.actor.id, modRef) | ||
} | ||
@@ -328,0 +344,0 @@ |
{ | ||
"name": "primea-wasm-container", | ||
"version": "0.6.0", | ||
"version": "0.7.0", | ||
"description": "", | ||
@@ -29,3 +29,3 @@ "main": "index.js", | ||
"nyc": "^11.7.1", | ||
"primea-hypervisor": "^0.7.1", | ||
"primea-hypervisor": "^0.8.0", | ||
"standard": "^11.0.1", | ||
@@ -36,5 +36,5 @@ "tape": "^4.9.0", | ||
"dependencies": { | ||
"primea-annotations": "^0.0.5", | ||
"primea-objects": "^0.0.4", | ||
"reference-map": "1.2.6", | ||
"primea-annotations": "^0.0.6", | ||
"primea-objects": "0.0.6", | ||
"reference-map": "^1.2.6", | ||
"wasm-json-toolkit": "^0.3.0", | ||
@@ -41,0 +41,0 @@ "wasm-metering": "^0.2.1", |
@@ -18,3 +18,3 @@ const tape = require('tape') | ||
class TestWasmContainer extends WasmContainer { | ||
class TestWasmModule extends WasmContainer { | ||
constructor (actor) { | ||
@@ -46,8 +46,8 @@ super(actor) | ||
const hypervisor = new Hypervisor({ | ||
tree | ||
tree, | ||
modules: [TestWasmModule] | ||
}) | ||
hypervisor.registerContainer(TestWasmContainer) | ||
const {module} = await hypervisor.createActor(TestWasmContainer.typeId, wasm) | ||
const funcRef = module.getFuncRef('main') | ||
const actorRef = await hypervisor.newActor(TestWasmModule, wasm) | ||
const funcRef = actorRef.getFuncRef('main') | ||
funcRef.gas = 322000 | ||
@@ -67,7 +67,9 @@ | ||
const hypervisor = new Hypervisor({tree}) | ||
hypervisor.registerContainer(TestWasmContainer) | ||
const hypervisor = new Hypervisor({ | ||
tree, | ||
modules: [TestWasmModule] | ||
}) | ||
const {module} = await hypervisor.createActor(TestWasmContainer.typeId, wasm) | ||
const funcRef = module.getFuncRef('main') | ||
const actorRef = await hypervisor.newActor(TestWasmModule, wasm) | ||
const funcRef = actorRef.getFuncRef('main') | ||
funcRef.gas = 322000 | ||
@@ -81,3 +83,3 @@ | ||
tape('reintinalizing', async t => { | ||
tape('reinternalizing', async t => { | ||
t.plan(1) | ||
@@ -88,7 +90,9 @@ tester = t | ||
const hypervisor = new Hypervisor({tree}) | ||
hypervisor.registerContainer(TestWasmContainer) | ||
const hypervisor = new Hypervisor({ | ||
tree, | ||
modules: [TestWasmModule] | ||
}) | ||
const {module} = await hypervisor.createActor(TestWasmContainer.typeId, wasm) | ||
const funcRef = module.getFuncRef('main') | ||
const actorRef = await hypervisor.newActor(TestWasmModule, wasm) | ||
const funcRef = actorRef.getFuncRef('main') | ||
funcRef.gas = 322000 | ||
@@ -112,7 +116,9 @@ | ||
const hypervisor = new Hypervisor({tree}) | ||
hypervisor.registerContainer(TestWasmContainer) | ||
const hypervisor = new Hypervisor({ | ||
tree, | ||
modules: [TestWasmModule] | ||
}) | ||
const {module} = await hypervisor.createActor(TestWasmContainer.typeId, wasm) | ||
const funcRef = module.getFuncRef('receive') | ||
const actorRef = await hypervisor.newActor(TestWasmModule, wasm) | ||
const funcRef = actorRef.getFuncRef('receive') | ||
funcRef.gas = 3000 | ||
@@ -136,9 +142,11 @@ | ||
const hypervisor = new Hypervisor({tree}) | ||
hypervisor.registerContainer(TestWasmContainer) | ||
const hypervisor = new Hypervisor({ | ||
tree, | ||
modules: [TestWasmModule] | ||
}) | ||
const {module: receiverMod} = await hypervisor.createActor(TestWasmContainer.typeId, recieverWasm) | ||
const {module: callerMod} = await hypervisor.createActor(TestWasmContainer.typeId, callerWasm) | ||
const callFuncRef = callerMod.getFuncRef('call') | ||
const recvFuncRef = receiverMod.getFuncRef('receive') | ||
const receiverActorRef = await hypervisor.newActor(TestWasmModule, recieverWasm) | ||
const callerActorRef = await hypervisor.newActor(TestWasmModule, callerWasm) | ||
const callFuncRef = callerActorRef.getFuncRef('call') | ||
const recvFuncRef = receiverActorRef.getFuncRef('receive') | ||
callFuncRef.gas = 100000 | ||
@@ -165,10 +173,12 @@ recvFuncRef.gas = 1000 | ||
const hypervisor = new Hypervisor({tree}) | ||
hypervisor.registerContainer(TestWasmContainer) | ||
const hypervisor = new Hypervisor({ | ||
tree, | ||
modules: [TestWasmModule] | ||
}) | ||
const {module: callerMod} = await hypervisor.createActor(TestWasmContainer.typeId, callerWasm) | ||
const {module: receiverMod} = await hypervisor.createActor(TestWasmContainer.typeId, recieverWasm) | ||
const callerActorRef = await hypervisor.newActor(TestWasmModule, callerWasm) | ||
const receiverActorRef = await hypervisor.newActor(TestWasmModule, recieverWasm) | ||
const callFuncRef = callerMod.getFuncRef('call') | ||
const recvFuncRef = receiverMod.getFuncRef('receive') | ||
const callFuncRef = callerActorRef.getFuncRef('call') | ||
const recvFuncRef = receiverActorRef.getFuncRef('receive') | ||
callFuncRef.gas = 1000000 | ||
@@ -196,10 +206,12 @@ recvFuncRef.gas = 100000 | ||
const hypervisor = new Hypervisor({tree}) | ||
hypervisor.registerContainer(TestWasmContainer) | ||
const hypervisor = new Hypervisor({ | ||
tree, | ||
modules: [TestWasmModule] | ||
}) | ||
const {module: callerMod} = await hypervisor.createActor(TestWasmContainer.typeId, callerWasm) | ||
const {module: receiverMod} = await hypervisor.createActor(TestWasmContainer.typeId, recieverWasm) | ||
const callerActorRef = await hypervisor.newActor(TestWasmModule, callerWasm) | ||
const receiverActorRef = await hypervisor.newActor(TestWasmModule, recieverWasm) | ||
const callFuncRef = callerMod.getFuncRef('call') | ||
const recvFuncRef = receiverMod.getFuncRef('receive') | ||
const callFuncRef = callerActorRef.getFuncRef('call') | ||
const recvFuncRef = receiverActorRef.getFuncRef('receive') | ||
callFuncRef.gas = 1000000 | ||
@@ -225,7 +237,9 @@ recvFuncRef.gas = 100000 | ||
const hypervisor = new Hypervisor({tree}) | ||
hypervisor.registerContainer(TestWasmContainer) | ||
const hypervisor = new Hypervisor({ | ||
tree, | ||
modules: [TestWasmModule] | ||
}) | ||
const {module} = await hypervisor.createActor(TestWasmContainer.typeId, wasm) | ||
const funcRef = module.getFuncRef('test') | ||
const actorRef = await hypervisor.newActor(TestWasmModule, wasm) | ||
const funcRef = actorRef.getFuncRef('test') | ||
funcRef.gas = 10000 | ||
@@ -249,8 +263,10 @@ | ||
const wasm = fs.readFileSync(WASM_PATH + '/table.wasm') | ||
const hypervisor = new Hypervisor({tree}) | ||
hypervisor.registerContainer(TestWasmContainer) | ||
const hypervisor = new Hypervisor({ | ||
tree, | ||
modules: [TestWasmModule] | ||
}) | ||
const {module} = await hypervisor.createActor(TestWasmContainer.typeId, wasm) | ||
const actorRef = await hypervisor.newActor(TestWasmModule, wasm) | ||
const funcRef = module.getFuncRef('test') | ||
const funcRef = actorRef.getFuncRef('test') | ||
funcRef.gas = 10000 | ||
@@ -273,7 +289,9 @@ | ||
const hypervisor = new Hypervisor({tree}) | ||
hypervisor.registerContainer(TestWasmContainer) | ||
const hypervisor = new Hypervisor({ | ||
tree, | ||
modules: [TestWasmModule] | ||
}) | ||
const {module} = await hypervisor.createActor(TestWasmContainer.typeId, wasm) | ||
const funcRef = module.getFuncRef('main') | ||
const actorRef = await hypervisor.newActor(TestWasmModule, wasm) | ||
const funcRef = actorRef.getFuncRef('main') | ||
funcRef.gas = 322000 | ||
@@ -302,8 +320,8 @@ | ||
tree, | ||
containers: [TestWasmContainer], | ||
modules: [TestWasmModule], | ||
drivers: [egress] | ||
}) | ||
const {module} = await hypervisor.createActor(TestWasmContainer.typeId, wasm) | ||
const funcRef = module.getFuncRef('main') | ||
const actorRef = await hypervisor.newActor(TestWasmModule, wasm) | ||
const funcRef = actorRef.getFuncRef('main') | ||
funcRef.gas = 322000 | ||
@@ -317,3 +335,3 @@ | ||
const funcRef2 = module.getFuncRef('load') | ||
const funcRef2 = actorRef.getFuncRef('load') | ||
funcRef2.gas = 322000 | ||
@@ -337,7 +355,9 @@ | ||
const hypervisor = new Hypervisor({tree}) | ||
hypervisor.registerContainer(TestWasmContainer) | ||
const hypervisor = new Hypervisor({ | ||
tree, | ||
modules: [TestWasmModule] | ||
}) | ||
try { | ||
await hypervisor.createActor(TestWasmContainer.typeId, wasm) | ||
await hypervisor.newActor(TestWasmModule, wasm) | ||
} catch (e) { | ||
@@ -353,7 +373,9 @@ t.pass() | ||
const hypervisor = new Hypervisor({tree}) | ||
hypervisor.registerContainer(TestWasmContainer) | ||
const hypervisor = new Hypervisor({ | ||
tree, | ||
modules: [TestWasmModule] | ||
}) | ||
const {module} = await hypervisor.createActor(TestWasmContainer.typeId, wasm) | ||
const funcRef = module.getFuncRef('main') | ||
const actorRef = await hypervisor.newActor(TestWasmModule, wasm) | ||
const funcRef = actorRef.getFuncRef('main') | ||
@@ -373,7 +395,9 @@ const message = new Message({ | ||
const hypervisor = new Hypervisor({tree}) | ||
hypervisor.registerContainer(TestWasmContainer) | ||
const hypervisor = new Hypervisor({ | ||
tree, | ||
modules: [TestWasmModule] | ||
}) | ||
try { | ||
await hypervisor.createActor(TestWasmContainer.typeId, wasm) | ||
await hypervisor.newActor(TestWasmModule, wasm) | ||
} catch (e) { | ||
@@ -384,3 +408,3 @@ t.pass(e.message) | ||
tape('persitant globals', async t => { | ||
tape('persistent globals', async t => { | ||
tester = t | ||
@@ -392,7 +416,7 @@ const tree = new RadixTree({db}) | ||
tree, | ||
containers: [TestWasmContainer] | ||
modules: [TestWasmModule] | ||
}) | ||
const {module} = await hypervisor.createActor(TestWasmContainer.typeId, wasm) | ||
const funcRef = module.getFuncRef('e') | ||
const actorRef = await hypervisor.newActor(TestWasmModule, wasm) | ||
const funcRef = actorRef.getFuncRef('e') | ||
funcRef.gas = 322000 | ||
@@ -406,3 +430,3 @@ | ||
hypervisor.scheduler.on('idle', async () => { | ||
const actor = await hypervisor.loadActor(module.id) | ||
const actor = await hypervisor.loadActor(actorRef.id) | ||
t.deepEquals(actor.storage, [[], 5, [0, 3]]) | ||
@@ -414,3 +438,3 @@ }) | ||
hypervisor.scheduler.on('idle', async () => { | ||
const actor = await hypervisor.loadActor(module.id) | ||
const actor = await hypervisor.loadActor(actorRef.id) | ||
t.deepEquals(actor.storage, [[], 5, [0, 3]]) | ||
@@ -417,0 +441,0 @@ }) |
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 not supported yet
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 not supported yet
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 not supported yet
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 not supported yet
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 not supported yet
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 not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
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
4
28
867191
93
1488
+ Addedprimea-annotations@0.0.6(transitive)
+ Addedprimea-objects@0.0.6(transitive)
+ Addedreference-map@1.2.8(transitive)
- Removedprimea-annotations@0.0.5(transitive)
- Removedprimea-objects@0.0.4(transitive)
- Removedreference-map@1.2.6(transitive)
Updatedprimea-annotations@^0.0.6
Updatedprimea-objects@0.0.6
Updatedreference-map@^1.2.6