Commit 229256951b870dc5f3a910c2e413c4df95f6cefa
added comments
wanderer committed on 11/18/2016, 11:18:11 AMParent: e214b19ee2bdfeef044a0c6277beab1b4d7472bb
Files changed
EVMinterface.js | changed |
interfaceAPI.js | changed |
EVMinterface.js | ||
---|---|---|
@@ -213,9 +213,10 @@ | ||
213 | 213 | */ |
214 | 214 | getCodeSize (cbIndex) { |
215 | 215 | this.takeGas(2) |
216 | 216 | |
217 | - const opPromise = this.kernel.environment.state.get('code') | |
217 | + const opPromise = this.kernel.environment.state | |
218 | + .get('code') | |
218 | 219 | .then(vertex => vertex.value.length) |
219 | 220 | |
220 | 221 | // wait for all the prevouse async ops to finish before running the callback |
221 | 222 | this.kernel.pushOpsQueue(opPromise, cbIndex, length => length) |
@@ -232,9 +233,10 @@ | ||
232 | 233 | |
233 | 234 | let opPromise |
234 | 235 | |
235 | 236 | if (length) { |
236 | - opPromise = this.kernel.environment.state.get('code') | |
237 | + opPromise = this.kernel.environment.state | |
238 | + .get('code') | |
237 | 239 | .then(vertex => vertex.value) |
238 | 240 | } else { |
239 | 241 | opPromise = Promise.resolve([]) |
240 | 242 | } |
@@ -255,9 +257,10 @@ | ||
255 | 257 | */ |
256 | 258 | getExternalCodeSize (addressOffset, cbOffset) { |
257 | 259 | this.takeGas(20) |
258 | 260 | const address = [...this.getMemory(addressOffset, ADDRESS_SIZE_BYTES), 'code'] |
259 | - const opPromise = this.kernel.environment.state.root.get(address) | |
261 | + const opPromise = this.kernel.environment.state.root | |
262 | + .get(address) | |
260 | 263 | .then(vertex => vertex.value.length) |
261 | 264 | .catch(() => 0) |
262 | 265 | |
263 | 266 | // wait for all the prevouse async ops to finish before running the callback |
interfaceAPI.js | ||
---|---|---|
@@ -6,8 +6,11 @@ | ||
6 | 6 | constructor (code) { |
7 | 7 | this._module = WebAssembly.Module(code) |
8 | 8 | } |
9 | 9 | |
10 | + /** | |
11 | + * Runs the core VM with a given environment and imports | |
12 | + */ | |
10 | 13 | run (environment, imports) { |
11 | 14 | this._environment = environment |
12 | 15 | // TODO, delete the instance once done. |
13 | 16 | const instance = this._instance = WebAssembly.Instance(this._module, imports) |
@@ -16,17 +19,22 @@ | ||
16 | 19 | } |
17 | 20 | return this.onDone() |
18 | 21 | } |
19 | 22 | |
20 | - // returns a promise that resolves when the wasm instance is done running | |
23 | + /** | |
24 | + * returns a promise that resolves when the wasm instance is done running | |
25 | + */ | |
21 | 26 | async onDone () { |
22 | 27 | let prevOps |
23 | 28 | while (prevOps !== this._opsQueue) { |
24 | 29 | prevOps = this._opsQueue |
25 | 30 | await this._opsQueue |
26 | 31 | } |
27 | 32 | } |
28 | 33 | |
34 | + /** | |
35 | + * addes an aync operation to the operations queue | |
36 | + */ | |
29 | 37 | pushOpsQueue (promise, callbackIndex, intefaceCallback) { |
30 | 38 | this._opsQueue = Promise.all([this._opsQueue, promise]).then(values => { |
31 | 39 | const result = intefaceCallback(values.pop()) |
32 | 40 | this._instance.exports[callbackIndex.toString()](result) |
Built with git-ssb-web