Skip to content

Commit 4c3297b

Browse files
authored
wasm2js: emit calls for memory growth helper only if memory growth is used (#2042)
1 parent 455f431 commit 4c3297b

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

src/wasm2js.h

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1529,18 +1529,19 @@ Ref Wasm2JSBuilder::processFunctionBody(Module* m, Function* func) {
15291529
}
15301530

15311531
Ref visitHost(Host* curr) {
1532-
Ref call;
15331532
if (curr->op == HostOp::GrowMemory) {
1534-
call = ValueBuilder::makeCall(WASM_GROW_MEMORY,
1535-
makeAsmCoercion(
1536-
visit(curr->operands[0], EXPRESSION_RESULT),
1537-
wasmToAsmType(curr->operands[0]->type)));
1533+
if (module->memory.exists && module->memory.max > module->memory.initial) {
1534+
return ValueBuilder::makeCall(WASM_GROW_MEMORY,
1535+
makeAsmCoercion(
1536+
visit(curr->operands[0], EXPRESSION_RESULT),
1537+
wasmToAsmType(curr->operands[0]->type)));
1538+
} else {
1539+
return ValueBuilder::makeCall(ABORT_FUNC);
1540+
}
15381541
} else if (curr->op == HostOp::CurrentMemory) {
1539-
call = ValueBuilder::makeCall(WASM_CURRENT_MEMORY);
1540-
} else {
1541-
return ValueBuilder::makeCall(ABORT_FUNC);
1542+
return ValueBuilder::makeCall(WASM_CURRENT_MEMORY);
15421543
}
1543-
return call;
1544+
WASM_UNREACHABLE(); // TODO
15441545
}
15451546

15461547
Ref visitNop(Nop* curr) {

test/wasm2js/emscripten.2asm.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ function asmFunc(global, env, buffer) {
4747

4848
function __growWasmMemory($0) {
4949
$0 = $0 | 0;
50-
return __wasm_grow_memory($0 | 0) | 0;
50+
return abort() | 0;
5151
}
5252

5353
// EMSCRIPTEN_END_FUNCS;

0 commit comments

Comments
 (0)