Commit 8fb216c62276f508a5fd349383be046d162baaa7
fix typos
Norton Wang committed on 4/25/2018, 11:31:18 PMParent: 6d8733c40b8d0082927219c30a05351081c913eb
Files changed
docs/index.md | changed |
index.js | changed |
package-lock.json | changed |
tests/index.js | changed |
docs/index.md | |||
---|---|---|---|
@@ -7,56 +7,70 @@ | |||
7 | 7 … | - [resume][3] | |
8 | 8 … | ||
9 | 9 … | ## prepare | |
10 | 10 … | ||
11 … | +[index.js:16-18][4] | ||
12 … | + | ||
11 | 13 … | Prepares a binary by injecting getter and setter function for memory, globals and tables. | |
12 | 14 … | ||
13 | 15 … | **Parameters** | |
14 | 16 … | ||
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. | ||
21 | 23 … | Indexes that are set to false or left undefined will not be persisted. By | |
22 | 24 … | 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 `'_'`) | ||
24 | 26 … | ||
25 | -Returns **[ArrayBuffer][4]** the resulting wasm binary | ||
27 … | +Returns **[ArrayBuffer][5]** the resulting wasm binary | ||
26 | 28 … | ||
27 | 29 … | ## hibernate | |
28 | 30 … | ||
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 | ||
30 | 34 … | the instance | |
31 | 35 … | ||
32 | 36 … | **Parameters** | |
33 | 37 … | ||
34 | 38 … | - `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 `'_'`) | ||
36 | 40 … | ||
37 | -Returns **[Object][5]** the state of the wasm instance | ||
41 … | +Returns **[Object][6]** the state of the wasm instance | ||
38 | 42 … | ||
39 | 43 … | ## resume | |
40 | 44 … | ||
41 | -resumes a prevously hibranted webassembly instance | ||
45 … | +[index.js:72-102][11] | ||
42 | 46 … | ||
47 … | +Resumes a previously hibernated Webassembly instance | ||
48 … | + | ||
43 | 49 … | **Parameters** | |
44 | 50 … | ||
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 | ||
47 | 53 … | ||
54 … | +Returns **WebAssembly.Instance** | ||
55 … | + | ||
48 | 56 … | [1]: #prepare | |
49 | 57 … | ||
50 | 58 … | [2]: #hibernate | |
51 | 59 … | ||
52 | 60 … | [3]: #resume | |
53 | 61 … | ||
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" | ||
55 | 63 … | ||
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 | ||
57 | 65 … | ||
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 | ||
59 | 67 … | ||
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 | ||
61 | 69 … | ||
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.js | ||
---|---|---|
@@ -3,27 +3,27 @@ | ||
3 | 3 … | /** |
4 | 4 … | * Prepares a binary by injecting getter and setter function for memory, globals and tables. |
5 | 5 … | * @param {ArrayBuffer} binary - a wasm binary |
6 | 6 … | * @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 | |
9 | 9 … | * @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. | |
11 | 11 … | * Indexes that are set to false or left undefined will not be persisted. By |
12 | 12 … | * 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 | |
14 | 14 … | * @return {ArrayBuffer} the resulting wasm binary |
15 | 15 … | */ |
16 | 16 … | function prepare (binary, include = {memory: true, table: true}, symbol = '_') { |
17 | 17 … | return inject(binary, include, symbol) |
18 | 18 … | } |
19 | 19 … | |
20 | 20 … | /** |
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 | |
22 | 22 … | * the instance |
23 | 23 … | * @param {Webassembly.Instance} instance |
24 | 24 … | * @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 | |
26 | 26 … | */ |
27 | 27 … | function hibernate (instance, symbol = '_') { |
28 | 28 … | const json = { |
29 | 29 … | globals: [], |
@@ -58,38 +58,38 @@ | ||
58 | 58 … | } |
59 | 59 … | } |
60 | 60 … | } |
61 | 61 … | } |
62 | - instance.__hibrenated = true | |
62 … | + instance.__hibernated = true | |
63 | 63 … | return json |
64 | 64 … | } |
65 | 65 … | |
66 | 66 … | /** |
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} | |
71 | 71 … | */ |
72 | 72 … | function resume (instance, state) { |
73 | - if (instance.__hibrenated) { | |
74 | - instance.__hibrenated = false | |
73 … | + if (instance.__hibernated) { | |
74 … | + instance.__hibernated = false | |
75 | 75 … | } else { |
76 | - // initailize memory | |
76 … | + // initialize memory | |
77 | 77 … | const mem = instance.exports[`${state.symbol}memory`] |
78 | 78 … | if (mem) { |
79 | 79 … | // console.log(mem.length) |
80 | 80 … | (new Uint32Array(mem.buffer)).set(state.memory, 0) |
81 | 81 … | } |
82 | 82 … | |
83 | - // initailize table | |
83 … | + // initialize table | |
84 | 84 … | if (instance.exports._table) { |
85 | 85 … | for (const index in state.table) { |
86 | 86 … | const funcIndex = state.table[index] |
87 | 87 … | instance.exports._table.set(index, instance.exports[`${state.symbol}func_${funcIndex}`]) |
88 | 88 … | } |
89 | 89 … | } |
90 | 90 … | |
91 | - // intialize globals | |
91 … | + // initialize globals | |
92 | 92 … | for (const index in state.globals) { |
93 | 93 … | const val = state.globals[index] |
94 | 94 … | if (Array.isArray(val)) { |
95 | 95 … | instance.exports[`${state.symbol}global_setter_i64_${index}`](val[1], val[0]) |
package-lock.json | ||
---|---|---|
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.js | ||
---|---|---|
@@ -69,9 +69,9 @@ | ||
69 | 69 … | |
70 | 70 … | t.end() |
71 | 71 … | }) |
72 | 72 … | |
73 | -tape('single table with foregn fuction', async t => { | |
73 … | +tape('single table with foreign fuction', async t => { | |
74 | 74 … | let wasm = fs.readFileSync(`${__dirname}/wasm/singleTable.wasm`) |
75 | 75 … | wasm = persit.prepare(wasm) |
76 | 76 … | const wasmInstance = await WebAssembly.instantiate(wasm) |
77 | 77 … | const wasmInstance2 = await WebAssembly.instantiate(wasm) |
Built with git-ssb-web