Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/wasm2js.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ class Wasm2JSBuilder {
std::to_string(index))
.c_str(),
false);
ret = fromName(ret, NameScope::Local);
}
if (func->localIndices.find(ret) == func->localIndices.end()) {
Builder::addVar(func, ret, type);
Expand Down
10 changes: 9 additions & 1 deletion test/wasm2js/refs.2asm.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ function asmFunc(imports) {
funcref_temps(funcref_temps, +(+((wasm2js_funcref$0 = $2, wasm2js_funcref$1 = $3 || wasm2js_trap(), wasm2js_i32$0 = 0, wasm2js_i32$0 ? wasm2js_funcref$0 : wasm2js_funcref$1) == null | 0)));
}

function named_type_temps() {
var $0 = null, wasm2js__ref_null_$func_0_$0_1 = null, wasm2js__ref_null_$func_0_$1_1 = null, wasm2js_i32$0 = 0;
$0 = named_type_temps;
return wasm2js__ref_null_$func_0_$0 = null, wasm2js__ref_null_$func_0_$1 = $0 || wasm2js_trap(), wasm2js_i32$0 = 0, wasm2js_i32$0 ? wasm2js__ref_null_$func_0_$0 : wasm2js__ref_null_$func_0_$1;
}

return {
"null_": null_,
"is_null": is_null,
Expand All @@ -69,7 +75,8 @@ function asmFunc(imports) {
"ref_as": ref_as,
"use_global": use_global,
"use_global_ref": use_global_ref,
"funcref_temps": funcref_temps
"funcref_temps": funcref_temps,
"named_type_temps": named_type_temps
};
}

Expand All @@ -83,3 +90,4 @@ export var ref_as = retasmFunc.ref_as;
export var use_global = retasmFunc.use_global;
export var use_global_ref = retasmFunc.use_global_ref;
export var funcref_temps = retasmFunc.funcref_temps;
export var named_type_temps = retasmFunc.named_type_temps;
8 changes: 7 additions & 1 deletion test/wasm2js/refs.2asm.js.opt
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ function asmFunc(imports) {
funcref_temps(funcref_temps, 0.0);
}

function named_type_temps() {
return named_type_temps;
}

return {
"null_": null_,
"is_null": is_null,
Expand All @@ -61,7 +65,8 @@ function asmFunc(imports) {
"ref_as": ref_as,
"use_global": use_global,
"use_global_ref": use_global_ref,
"funcref_temps": funcref_temps
"funcref_temps": funcref_temps,
"named_type_temps": named_type_temps
};
}

Expand All @@ -75,3 +80,4 @@ export var ref_as = retasmFunc.ref_as;
export var use_global = retasmFunc.use_global;
export var use_global_ref = retasmFunc.use_global_ref;
export var funcref_temps = retasmFunc.funcref_temps;
export var named_type_temps = retasmFunc.named_type_temps;
22 changes: 22 additions & 0 deletions test/wasm2js/refs.wast
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
(module
(type $func (func (result funcref)))

(global $global (mut anyref) (ref.null any))

(global $global-ref (mut funcref) (ref.func $use-global-ref))
Expand Down Expand Up @@ -81,4 +83,24 @@
)
)
)

(func $named_type_temps (export "named_type_temps") (result funcref)
;; This nested expression ends up needing to use temp vars, and one such
;; name contains the type $func. We should emit that in form that is
;; mangled for JS, without '(' which appears in the stringified name of the
;; type, "(ref null $func)".
(select (result (ref null $func))
(ref.null nofunc)
(if (result (ref $func))
(i32.const 1)
(then
(ref.func $named_type_temps)
)
(else
(unreachable)
)
)
(i32.const 0)
)
)
)