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
21 changes: 12 additions & 9 deletions src/jsifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,19 +137,22 @@ function runJSify() {
const newArgs = [];
let innerArgs = [];
let argConvertions = '';
for (let i = 1; i < sig.length; i++) {
const name = argNames[i - 1];
if (!name) {
error(`handleI64Signatures: missing name for argument ${i} in ${symbol}`);
return snippet;
}
if (WASM_BIGINT && ((MEMORY64 && sig[i] == 'p') || (i53abi && sig[i] == 'j'))) {
if (sig.length > argNames.length + 1) {
error(`handleI64Signatures: signature too long for ${symbol}`);
return snippet;
}
for (let i = 0; i < argNames.length; i++) {
const name = argNames[i];
// If sig is shorter than argNames list then argType will be undefined
// here, which will result in the default case below.
const argType = sig[i + 1];
if (WASM_BIGINT && ((MEMORY64 && argType == 'p') || (i53abi && argType == 'j'))) {
argConvertions += ` ${receiveI64ParamAsI53(name, undefined, false)}\n`;
} else {
if (sig[i] == 'j' && i53abi) {
if (argType == 'j' && i53abi) {
argConvertions += ` ${receiveI64ParamAsI53(name, undefined, false)}\n`;
newArgs.push(defineI64Param(name));
} else if (sig[i] == 'p' && CAN_ADDRESS_2GB) {
} else if (argType == 'p' && CAN_ADDRESS_2GB) {
argConvertions += ` ${name} >>>= 0;\n`;
newArgs.push(name);
} else {
Expand Down
22 changes: 22 additions & 0 deletions test/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -4029,6 +4029,28 @@ def test_js_lib_missing_sig(self):
err = self.expect_fail([EMCC, 'some_func.c'] + self.get_emcc_args())
self.assertContained('some_func.js: __sig is missing for function: someFunc. Do not use checkSig if this is intended', err)

def test_js_lib_extra_args(self):
# Verify that extra arguments in addition to those listed in `__sig` are still present
# in the generated JS library function.
# See https://github.com/emscripten-core/emscripten/issues/21056
create_file('some_func.js', '''
addToLibrary({
someFunc: (arg1, arg2) => {
err('arg1:' + arg1);
err('arg2:' + arg2);
},
someFunc__sig: 'pp',
});
''')
create_file('test.c', '''
void someFunc(long p);
int main() {
someFunc(42);
}
''')
self.emcc_args += ['--js-library', 'some_func.js', '-sALLOW_MEMORY_GROWTH', '-sMAXIMUM_MEMORY=4Gb']
self.do_runf('test.c', 'arg1:42\narg2:undefined\n')

def test_js_lib_quoted_key(self):
create_file('lib.js', r'''
addToLibrary({
Expand Down