Commit 78df5549b3d8b084519490f3fb698ff93970c907
updated for new creation container api
Signed-off-by: wanderer <mjbecze@gmail.com>wanderer committed on 10/22/2017, 8:53:26 PM
Parent: dd301b31b19cf39b3a8a6f691ba55a84c675f81f
Files changed
index.js | changed |
package-lock.json | changed |
tests/index.js | changed |
index.js | ||
---|---|---|
@@ -16,9 +16,9 @@ | ||
16 | 16 … | this.referanceMap = new ReferanceMap() |
17 | 17 … | } |
18 | 18 … | |
19 | 19 … | async onCreation (message) { |
20 | - let code = message.data.code | |
20 … | + let code = this.kernel.code | |
21 | 21 … | if (!WebAssembly.validate(code)) { |
22 | 22 … | throw new Error('invalid wasm binary') |
23 | 23 … | } else { |
24 | 24 … | for (const name in this.imports) { |
@@ -57,9 +57,9 @@ | ||
57 | 57 … | } |
58 | 58 … | } |
59 | 59 … | } |
60 | 60 … | |
61 | - const result = await WebAssembly.instantiate(this.kernel.state.code, importMap) | |
61 … | + const result = await WebAssembly.instantiate(this.kernel.code, importMap) | |
62 | 62 … | this.instance = result.instance |
63 | 63 … | |
64 | 64 … | // add the message and ports to the refereance map |
65 | 65 … | const messageRef = this.referanceMap.add(message) |
package-lock.json | ||
---|---|---|
The diff is too large to show. Use a local git client to view these changes. Old file size: 183413 bytes New file size: 182822 bytes |
tests/index.js | ||
---|---|---|
@@ -48,12 +48,9 @@ | ||
48 | 48 … | |
49 | 49 … | const port = hypervisor.creationService.getPort() |
50 | 50 … | |
51 | 51 … | let instance = await hypervisor.send(port, new Message({ |
52 | - data: { | |
53 | - type: WasmContainer.typeId, | |
54 | - code: main | |
55 | - } | |
52 … | + data: Buffer.concat([Buffer.from([0]), Buffer.from([WasmContainer.typeId]), main]) | |
56 | 53 … | })) |
57 | 54 … | instance.message(instance.createMessage()) |
58 | 55 … | }) |
59 | 56 … | |
@@ -68,12 +65,9 @@ | ||
68 | 65 … | const ports = hypervisor.createChannel() |
69 | 66 … | const port = hypervisor.creationService.getPort() |
70 | 67 … | |
71 | 68 … | hypervisor.send(port, new Message({ |
72 | - data: { | |
73 | - type: WasmContainer.typeId, | |
74 | - code: main | |
75 | - }, | |
69 … | + data: Buffer.concat([Buffer.from([0]), Buffer.from([WasmContainer.typeId]), main]), | |
76 | 70 … | ports: ports |
77 | 71 … | })) |
78 | 72 … | }) |
79 | 73 … | |
@@ -88,12 +82,9 @@ | ||
88 | 82 … | |
89 | 83 … | const port = hypervisor.creationService.getPort() |
90 | 84 … | |
91 | 85 … | hypervisor.send(port, new Message({ |
92 | - data: { | |
93 | - type: WasmContainer.typeId, | |
94 | - code: readMem | |
95 | - } | |
86 … | + data: Buffer.concat([Buffer.from([0]), Buffer.from([WasmContainer.typeId]), readMem]) | |
96 | 87 … | })) |
97 | 88 … | }) |
98 | 89 … | |
99 | 90 … | tape('write mem', async t => { |
@@ -105,12 +96,9 @@ | ||
105 | 96 … | }) |
106 | 97 … | |
107 | 98 … | const port = hypervisor.creationService.getPort() |
108 | 99 … | const root = await hypervisor.send(port, new Message({ |
109 | - data: { | |
110 | - type: WasmContainer.typeId, | |
111 | - code: readMem | |
112 | - } | |
100 … | + data: Buffer.concat([Buffer.from([0]), Buffer.from([WasmContainer.typeId]), readMem]) | |
113 | 101 … | })) |
114 | 102 … | const mem = root.container.getMemory(0, 1) |
115 | 103 … | t.equals(mem[0], 9) |
116 | 104 … | t.end() |
@@ -126,12 +114,9 @@ | ||
126 | 114 … | }) |
127 | 115 … | |
128 | 116 … | const port = hypervisor.creationService.getPort() |
129 | 117 … | await hypervisor.send(port, new Message({ |
130 | - data: { | |
131 | - type: WasmContainer.typeId, | |
132 | - code: callBackWasm | |
133 | - } | |
118 … | + data: Buffer.concat([Buffer.from([0]), Buffer.from([WasmContainer.typeId]), callBackWasm]) | |
134 | 119 … | })) |
135 | 120 … | }) |
136 | 121 … | |
137 | 122 … | tape('wasm container - invalid', async t => { |
@@ -142,12 +127,9 @@ | ||
142 | 127 … | test: testInterface(t) |
143 | 128 … | }) |
144 | 129 … | |
145 | 130 … | const message = new Message({ |
146 | - data: { | |
147 | - type: WasmContainer.typeId, | |
148 | - code: Buffer.from([0x00]) | |
149 | - } | |
131 … | + data: Buffer.concat([Buffer.from([0]), Buffer.from([WasmContainer.typeId]), Buffer.from([0])]) | |
150 | 132 … | }) |
151 | 133 … | |
152 | 134 … | const rp = message.responsePort = {destPort: {messages: []}} |
153 | 135 … | |
@@ -166,12 +148,8 @@ | ||
166 | 148 … | constructor (wasmContainer) { |
167 | 149 … | this.wasmContainer = wasmContainer |
168 | 150 … | } |
169 | 151 … | |
170 | - readMem (offset) { | |
171 | - return this.wasmContainer.getMemory(offset, 1) | |
172 | - } | |
173 | - | |
174 | 152 … | async callback (cb) { |
175 | 153 … | const promise = new Promise((resolve, reject) => { |
176 | 154 … | resolve() |
177 | 155 … | }) |
@@ -179,9 +157,9 @@ | ||
179 | 157 … | this.wasmContainer.execute(cb) |
180 | 158 … | } |
181 | 159 … | |
182 | 160 … | static initialize (code) { |
183 | - t.equals(code, callBackWasm) | |
161 … | + t.deepEquals(code, callBackWasm) | |
184 | 162 … | return code |
185 | 163 … | } |
186 | 164 … | } |
187 | 165 … | |
@@ -192,10 +170,7 @@ | ||
192 | 170 … | }) |
193 | 171 … | |
194 | 172 … | const port = hypervisor.creationService.getPort() |
195 | 173 … | hypervisor.send(port, new Message({ |
196 | - data: { | |
197 | - type: WasmContainer.typeId, | |
198 | - code: callBackWasm | |
199 | - } | |
174 … | + data: Buffer.concat([Buffer.from([0]), Buffer.from([WasmContainer.typeId]), callBackWasm]) | |
200 | 175 … | })) |
201 | 176 … | }) |
Built with git-ssb-web