git ssb

0+

wanderer🌟 / js-primea-hypervisor



Commit 229256951b870dc5f3a910c2e413c4df95f6cefa

added comments

wanderer committed on 11/18/2016, 11:18:11 AM
Parent: e214b19ee2bdfeef044a0c6277beab1b4d7472bb

Files changed

EVMinterface.jschanged
interfaceAPI.jschanged
EVMinterface.jsView
@@ -213,9 +213,10 @@
213213 */
214214 getCodeSize (cbIndex) {
215215 this.takeGas(2)
216216
217- const opPromise = this.kernel.environment.state.get('code')
217+ const opPromise = this.kernel.environment.state
218+ .get('code')
218219 .then(vertex => vertex.value.length)
219220
220221 // wait for all the prevouse async ops to finish before running the callback
221222 this.kernel.pushOpsQueue(opPromise, cbIndex, length => length)
@@ -232,9 +233,10 @@
232233
233234 let opPromise
234235
235236 if (length) {
236- opPromise = this.kernel.environment.state.get('code')
237+ opPromise = this.kernel.environment.state
238+ .get('code')
237239 .then(vertex => vertex.value)
238240 } else {
239241 opPromise = Promise.resolve([])
240242 }
@@ -255,9 +257,10 @@
255257 */
256258 getExternalCodeSize (addressOffset, cbOffset) {
257259 this.takeGas(20)
258260 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)
260263 .then(vertex => vertex.value.length)
261264 .catch(() => 0)
262265
263266 // wait for all the prevouse async ops to finish before running the callback
interfaceAPI.jsView
@@ -6,8 +6,11 @@
66 constructor (code) {
77 this._module = WebAssembly.Module(code)
88 }
99
10+ /**
11+ * Runs the core VM with a given environment and imports
12+ */
1013 run (environment, imports) {
1114 this._environment = environment
1215 // TODO, delete the instance once done.
1316 const instance = this._instance = WebAssembly.Instance(this._module, imports)
@@ -16,17 +19,22 @@
1619 }
1720 return this.onDone()
1821 }
1922
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+ */
2126 async onDone () {
2227 let prevOps
2328 while (prevOps !== this._opsQueue) {
2429 prevOps = this._opsQueue
2530 await this._opsQueue
2631 }
2732 }
2833
34+ /**
35+ * addes an aync operation to the operations queue
36+ */
2937 pushOpsQueue (promise, callbackIndex, intefaceCallback) {
3038 this._opsQueue = Promise.all([this._opsQueue, promise]).then(values => {
3139 const result = intefaceCallback(values.pop())
3240 this._instance.exports[callbackIndex.toString()](result)

Built with git-ssb-web