Skip to content

Commit 9aabfb4

Browse files
authored
[dylink] Fix addEmJs when parameter is indirect pointer (#25740)
I'm in the middle of porting [libskk](https://github.com/ueno/libskk) with glib, and encountered a `SyntaxError: Unexpected token '*'`. Given the value of `cSig`, `jsArg` and `jsArgs` in debugger view, it seems straightforward. <img width="972" height="251" src="https://github.com/user-attachments/assets/71d04fcb-ab51-4c38-89a5-0abf77136bf8" />
1 parent caabcdb commit 9aabfb4

File tree

5 files changed

+14
-7
lines changed

5 files changed

+14
-7
lines changed

src/lib/libdylink.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -880,7 +880,7 @@ var LibraryDylink = {
880880
cSig = cSig.split(',');
881881
for (var arg of cSig) {
882882
var jsArg = arg.split(' ').pop();
883-
jsArgs.push(jsArg.replace('*', ''));
883+
jsArgs.push(jsArg.replaceAll('*', ''));
884884
}
885885
}
886886
var func = `(${jsArgs}) => ${body};`;

test/codesize/test_codesize_hello_dylink.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
2-
"a.out.js": 26546,
3-
"a.out.js.gz": 11349,
2+
"a.out.js": 26549,
3+
"a.out.js.gz": 11353,
44
"a.out.nodebug.wasm": 17761,
55
"a.out.nodebug.wasm.gz": 9003,
6-
"total": 44307,
7-
"total_gz": 20352,
6+
"total": 44310,
7+
"total_gz": 20356,
88
"sent": [
99
"__syscall_stat64",
1010
"emscripten_resize_heap",

test/codesize/test_codesize_hello_dylink_all.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
2-
"a.out.js": 245299,
2+
"a.out.js": 245302,
33
"a.out.nodebug.wasm": 574162,
4-
"total": 819461,
4+
"total": 819464,
55
"sent": [
66
"IMG_Init",
77
"IMG_Load",

test/other/test_em_js_main.out

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ in main
22
hello from side module 42 + hello
33
hello again
44
hello from void func
5+
hello

test/other/test_em_js_side.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,15 @@ EM_JS(void, js_side_func_void, (), {
1414
out(`hello from void func`);
1515
});
1616

17+
EM_JS(void, js_side_func_indirect_ptr, (const char **pptr), {
18+
out(UTF8ToString(getValue(pptr, '*')));
19+
});
20+
1721
int test_side() {
22+
const char *hello = "hello";
1823
js_side_func(42, "hello");
1924
js_side_func2("hello again");
2025
js_side_func_void();
26+
js_side_func_indirect_ptr(&hello);
2127
return 0;
2228
}

0 commit comments

Comments
 (0)