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
5 changes: 5 additions & 0 deletions test/core/test_em_js.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ EM_JS(int, _prefixed, (void), {
return 1;
});

EM_JS(int, strip_whitespace, ( void ), {
return 1;
});

EM_JS(int, transitive, (void), {
// Verify that EM_JS functions can call other EM_JS functions by their
// unmangled name.
Expand Down Expand Up @@ -126,6 +130,7 @@ int main() {
free(s2);

printf(" _prefixed: %d\n", _prefixed());
printf(" strip_whitespace: %d\n", strip_whitespace());
printf(" transitive: %d\n", transitive());

printf("END\n");
Expand Down
1 change: 1 addition & 0 deletions test/core/test_em_js.out
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ no args returning double
return_str returned: hello from js
return_utf8_str returned: こんにちは
_prefixed: 1
strip_whitespace: 1
no args returning int
transitive: 12
END
18 changes: 10 additions & 8 deletions tools/emscripten.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,14 +382,16 @@ def emscript(in_wasm, out_wasm, outfile_js, js_syms, finalize=True, base_metadat

if not settings.WASM_BIGINT and metadata.em_js_funcs:
for em_js_func, raw in metadata.em_js_funcs.items():
c_sig = raw.split('<::>')[0].strip('()')
if not c_sig or c_sig == 'void':
c_sig = []
args, _ = raw.split('<::>', 1)
args = args[1:-1].strip()

if not args or args == 'void':
args = []
else:
c_sig = c_sig.split(',')
args = args.split(',')
signature = metadata.em_js_func_types.get(em_js_func)
if signature and len(signature.params) != len(c_sig):
diagnostics.warning('em-js-i64', 'using 64-bit arguments in EM_JS function without WASM_BIGINT is not yet fully supported: `%s` (%s, %s)', em_js_func, c_sig, signature.params)
if signature and len(signature.params) != len(args):
diagnostics.warning('em-js-i64', 'using 64-bit arguments in EM_JS function without WASM_BIGINT is not yet fully supported: `%s` (%s, %s)', em_js_func, args, signature.params)

asm_consts = create_asm_consts(metadata)
em_js_funcs = create_em_js(metadata)
Expand Down Expand Up @@ -793,8 +795,8 @@ def create_em_js(metadata):
for name, raw in metadata.em_js_funcs.items():
assert separator in raw
args, body = raw.split(separator, 1)
args = args[1:-1]
if args == 'void':
args = args[1:-1].strip()
if not args or args == 'void':
args = []
else:
args = args.split(',')
Expand Down