git ssb

0+

wanderer🌟 / wasm-persist



Commit eb6e3c58849bac99fc0c9984b3b53fdff0c3c551

added check for undefined values in resume state

Signed-off-by: wanderer <mjbecze@gmail.com>
wanderer committed on 4/26/2018, 9:27:13 PM
Parent: f74b2f64270fd00c432ee293362b293055ca8e9d

Files changed

index.jschanged
tests/index.jschanged
index.jsView
@@ -75,9 +75,8 @@
7575 } else {
7676 // initialize memory
7777 const mem = instance.exports[`${state.symbol}memory`]
7878 if (mem) {
79- // console.log(mem.length)
8079 (new Uint32Array(mem.buffer)).set(state.memory, 0)
8180 }
8281
8382 // initialize table
@@ -90,12 +89,14 @@
9089
9190 // initialize globals
9291 for (const index in state.globals) {
9392 const val = state.globals[index]
94- if (Array.isArray(val)) {
95- instance.exports[`${state.symbol}global_setter_i64_${index}`](val[1], val[0])
96- } else {
97- instance.exports[`${state.symbol}global_setter_i32_${index}`](val)
93 + if (val !== undefined) {
94 + if (Array.isArray(val)) {
95 + instance.exports[`${state.symbol}global_setter_i64_${index}`](val[1], val[0])
96 + } else {
97 + instance.exports[`${state.symbol}global_setter_i32_${index}`](val)
98 + }
9899 }
99100 }
100101 }
101102 return instance
tests/index.jsView
@@ -211,4 +211,22 @@
211211 t.equals(Object.keys(wasmInstance.instance.exports).length, 5)
212212
213213 t.end()
214214 })
215 +
216 +tape('initailizing with missing values', async t => {
217 + let wasm = fs.readFileSync(`${__dirname}/wasm/doubleGlobals.wasm`)
218 + wasm = persit.prepare(wasm, {
219 + globals: [false, true]
220 + }, '_@')
221 + const wasmInstance = await WebAssembly.instantiate(wasm)
222 + const json = persit.hibernate(wasmInstance.instance, '_@')
223 + t.deepEquals(json, {globals: [[-1, -2]], table: [], symbol: '_@'})
224 + t.equals(Object.keys(wasmInstance.instance.exports).length, 5)
225 + json.globals = [undefined]
226 + wasmInstance.instance.__hibrenated = false
227 + persit.resume(wasmInstance.instance, json)
228 + const json2 = persit.hibernate(wasmInstance.instance, '_@')
229 + t.deepEquals(json2, {globals: [[-1, -2]], table: [], symbol: '_@'})
230 +
231 + t.end()
232 +})

Built with git-ssb-web