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.js | changed |
tests/index.js | changed |
index.js | ||
---|---|---|
@@ -75,9 +75,8 @@ | ||
75 | 75 … | } else { |
76 | 76 … | // initialize memory |
77 | 77 … | const mem = instance.exports[`${state.symbol}memory`] |
78 | 78 … | if (mem) { |
79 | - // console.log(mem.length) | |
80 | 79 … | (new Uint32Array(mem.buffer)).set(state.memory, 0) |
81 | 80 … | } |
82 | 81 … | |
83 | 82 … | // initialize table |
@@ -90,12 +89,14 @@ | ||
90 | 89 … | |
91 | 90 … | // initialize globals |
92 | 91 … | for (const index in state.globals) { |
93 | 92 … | 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 … | + } | |
98 | 99 … | } |
99 | 100 … | } |
100 | 101 … | } |
101 | 102 … | return instance |
tests/index.js | |||
---|---|---|---|
@@ -211,4 +211,22 @@ | |||
211 | 211 … | t.equals(Object.keys(wasmInstance.instance.exports).length, 5) | |
212 | 212 … | ||
213 | 213 … | t.end() | |
214 | 214 … | }) | |
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