Skip to content
This repository was archived by the owner on Jan 5, 2019. It is now read-only.

Commit d475c5c

Browse files
committed
Fix CREATE
Update input and output. This opcode requires special treatment hence an additional case in the conditional. We only overwrite the value stored in the opointer (with zero) if the call does not succeed.
1 parent 6a24b67 commit d475c5c

File tree

3 files changed

+27
-18
lines changed

3 files changed

+27
-18
lines changed

wasm/generateInterface.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@ const interfaceManifest = {
116116
CREATE: {
117117
name: 'create',
118118
async: true,
119-
input: ['i128', 'readOffset', 'length'],
120-
output: ['address']
119+
input: ['i128', 'readOffset', 'length', 'opointer'],
120+
output: ['i32']
121121
},
122122
CALL: {
123123
name: 'call',
@@ -329,6 +329,15 @@ function generateManifest (interfaceManifest, opts) {
329329
call += `)
330330
(drop (call $bswap_m256 (i32.add (i32.const 32) (get_global $sp))))
331331
`
332+
} else if (opcode === 'CREATE') {
333+
// Check the return value from the EEI method.
334+
// 0 = success, 1 = failure, 2 = revert
335+
// iff return === 0, there is nothing to do as the address has already been loaded.
336+
// otherwise, we must return 0 instead, overwriting whatever was read from memory.
337+
call = `(if (i32.ne ${call}) (i32.const 0))
338+
(then (i64.store
339+
(i32.add (get_global $sp) (i32.const ${spOffset * 32}))
340+
(i64.const 0))))`
332341
} else if (output === 'i32') {
333342
if (useAsyncAPI && op.async) {
334343
call += '(get_local $callback)'

0 commit comments

Comments
 (0)