git ssb

0+

wanderer🌟 / wasm-persist



Commit 8fb216c62276f508a5fd349383be046d162baaa7

fix typos

Norton Wang committed on 4/25/2018, 11:31:18 PM
Parent: 6d8733c40b8d0082927219c30a05351081c913eb

Files changed

docs/index.mdchanged
index.jschanged
package-lock.jsonchanged
tests/index.jschanged
docs/index.mdView
@@ -7,56 +7,70 @@
77 - [resume][3]
88
99 ## prepare
1010
11 +[index.js:16-18][4]
12 +
1113 Prepares a binary by injecting getter and setter function for memory, globals and tables.
1214
1315 **Parameters**
1416
15-- `binary` **[ArrayBuffer][4]** a wasm binary
16-- `include` **[Object][5]** (optional, default `{memory:true,table:true}`)
17- - `include.memory` **[Boolean][6]** whether or not to included memory (optional, default `true`)
18- - `include.table` **[Boolean][6]** whether or not to included the function table (optional, default `true`)
19- - `include.globals` **[Array][7]<[Boolean][6]>** whether or not to
20- included a given global. Each index in the array stands for a global index.
17 +- `binary` **[ArrayBuffer][5]** a wasm binary
18 +- `include` **[Object][6]** (optional, default `{memory:true,table:true}`)
19 + - `include.memory` **[Boolean][7]** whether or not to include memory (optional, default `true`)
20 + - `include.table` **[Boolean][7]** whether or not to include the function table (optional, default `true`)
21 + - `include.globals` **[Array][8]<[Boolean][7]>** whether or not to
22 + include a given global. Each index in the array stands for a global index.
2123 Indexes that are set to false or left undefined will not be persisted. By
2224 default all globals are persisted. (optional, default `Array.<true>`)
23-- `symbol` **[String][8]** a sting used to prefix the injected setter and getter functions (optional, default `'_'`)
25 +- `symbol` **[String][9]** a string used to prefix the injected setter and getter functions (optional, default `'_'`)
2426
25-Returns **[ArrayBuffer][4]** the resulting wasm binary
27 +Returns **[ArrayBuffer][5]** the resulting wasm binary
2628
2729 ## hibernate
2830
29-Given a wasm Instance this will produce an Object containing the current state of
31 +[index.js:27-64][10]
32 +
33 +Given a Webassembly Instance this will produce an Object containing the current state of
3034 the instance
3135
3236 **Parameters**
3337
3438 - `instance` **Webassembly.Instance**
35-- `symbol` **[String][8]** the symbol that will be used to find the injected functions (optional, default `'_'`)
39 +- `symbol` **[String][9]** the symbol that will be used to find the injected functions (optional, default `'_'`)
3640
37-Returns **[Object][5]** the state of the wasm instance
41 +Returns **[Object][6]** the state of the wasm instance
3842
3943 ## resume
4044
41-resumes a prevously hibranted webassembly instance
45 +[index.js:72-102][11]
4246
47 +Resumes a previously hibernated Webassembly instance
48 +
4349 **Parameters**
4450
45-- `instance` **WebAssemby.Instance**
46-- `state` **[Object][5]** the pervous state of the wasm instance
51 +- `instance` **WebAssembly.Instance**
52 +- `state` **[Object][6]** the previous state of the wasm instance
4753
54 +Returns **WebAssembly.Instance**
55 +
4856 [1]: #prepare
4957
5058 [2]: #hibernate
5159
5260 [3]: #resume
5361
54-[4]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer
62 +[4]: https://github.com/dfinity/wasm-persist/blob/6d8733c40b8d0082927219c30a05351081c913eb/index.js#L16-L18 "Source code on GitHub"
5563
56-[5]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
64 +[5]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer
5765
58-[6]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
66 +[6]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
5967
60-[7]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array
68 +[7]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
6169
62-[8]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
70 +[8]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array
71 +
72 +[9]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
73 +
74 +[10]: https://github.com/dfinity/wasm-persist/blob/6d8733c40b8d0082927219c30a05351081c913eb/index.js#L27-L64 "Source code on GitHub"
75 +
76 +[11]: https://github.com/dfinity/wasm-persist/blob/6d8733c40b8d0082927219c30a05351081c913eb/index.js#L72-L102 "Source code on GitHub"
index.jsView
@@ -3,27 +3,27 @@
33 /**
44 * Prepares a binary by injecting getter and setter function for memory, globals and tables.
55 * @param {ArrayBuffer} binary - a wasm binary
66 * @param {Object} include
7- * @param {Boolean} [include.memory=true] - whether or not to included memory
8- * @param {Boolean} [include.table=true] - whether or not to included the function table
7 + * @param {Boolean} [include.memory=true] - whether or not to include memory
8 + * @param {Boolean} [include.table=true] - whether or not to include the function table
99 * @param {Array.<Boolean>} [include.globals=Array.<true>] - whether or not to
10- * included a given global. Each index in the array stands for a global index.
10 + * include a given global. Each index in the array stands for a global index.
1111 * Indexes that are set to false or left undefined will not be persisted. By
1212 * default all globals are persisted.
13- * @param {String} [symbol = '_'] - a sting used to prefix the injected setter and getter functions
13 + * @param {String} [symbol = '_'] - a string used to prefix the injected setter and getter functions
1414 * @return {ArrayBuffer} the resulting wasm binary
1515 */
1616 function prepare (binary, include = {memory: true, table: true}, symbol = '_') {
1717 return inject(binary, include, symbol)
1818 }
1919
2020 /**
21- * Given a wasm Instance this will produce an Object containing the current state of
21 + * Given a Webassembly Instance this will produce an Object containing the current state of
2222 * the instance
2323 * @param {Webassembly.Instance} instance
2424 * @param {String} symbol - the symbol that will be used to find the injected functions
25- * @returns {Object} the state of the wasm instance
25 + * @return {Object} the state of the wasm instance
2626 */
2727 function hibernate (instance, symbol = '_') {
2828 const json = {
2929 globals: [],
@@ -58,38 +58,38 @@
5858 }
5959 }
6060 }
6161 }
62- instance.__hibrenated = true
62 + instance.__hibernated = true
6363 return json
6464 }
6565
6666 /**
67- * resumes a prevously hibranted webassembly instance
68- * @param {WebAssemby.Instance} instance
69- * @param {Object} state - the pervous state of the wasm instance
70- * @retrun {WebAssembly.Instance}
67 + * Resumes a previously hibernated Webassembly instance
68 + * @param {WebAssembly.Instance} instance
69 + * @param {Object} state - the previous state of the wasm instance
70 + * @return {WebAssembly.Instance}
7171 */
7272 function resume (instance, state) {
73- if (instance.__hibrenated) {
74- instance.__hibrenated = false
73 + if (instance.__hibernated) {
74 + instance.__hibernated = false
7575 } else {
76- // initailize memory
76 + // initialize memory
7777 const mem = instance.exports[`${state.symbol}memory`]
7878 if (mem) {
7979 // console.log(mem.length)
8080 (new Uint32Array(mem.buffer)).set(state.memory, 0)
8181 }
8282
83- // initailize table
83 + // initialize table
8484 if (instance.exports._table) {
8585 for (const index in state.table) {
8686 const funcIndex = state.table[index]
8787 instance.exports._table.set(index, instance.exports[`${state.symbol}func_${funcIndex}`])
8888 }
8989 }
9090
91- // intialize globals
91 + // initialize globals
9292 for (const index in state.globals) {
9393 const val = state.globals[index]
9494 if (Array.isArray(val)) {
9595 instance.exports[`${state.symbol}global_setter_i64_${index}`](val[1], val[0])
package-lock.jsonView
The diff is too large to show. Use a local git client to view these changes.
Old file size: 322795 bytes
New file size: 321092 bytes
tests/index.jsView
@@ -69,9 +69,9 @@
6969
7070 t.end()
7171 })
7272
73-tape('single table with foregn fuction', async t => {
73 +tape('single table with foreign fuction', async t => {
7474 let wasm = fs.readFileSync(`${__dirname}/wasm/singleTable.wasm`)
7575 wasm = persit.prepare(wasm)
7676 const wasmInstance = await WebAssembly.instantiate(wasm)
7777 const wasmInstance2 = await WebAssembly.instantiate(wasm)

Built with git-ssb-web