Skip to content

Commit d0d9966

Browse files
authored
Add some sanity checks when using __i53abi decorator (emscripten-core#22557)
See emscripten-core#21335
1 parent d9c260d commit d0d9966

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

src/jsifier.mjs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,16 @@ function(${args}) {
299299

300300
const sig = LibraryManager.library[symbol + '__sig'];
301301
const i53abi = LibraryManager.library[symbol + '__i53abi'];
302+
if (i53abi) {
303+
if (!sig) {
304+
error(`JS library error: '__i53abi' decorator requires '__sig' decorator: '${symbol}'`);
305+
}
306+
if (!sig.includes('j')) {
307+
error(
308+
`JS library error: '__i53abi' only makes sense when '__sig' includes 'j' (int64): '${symbol}'`,
309+
);
310+
}
311+
}
302312
if (
303313
sig &&
304314
((i53abi && sig.includes('j')) || ((MEMORY64 || CAN_ADDRESS_2GB) && sig.includes('p')))

src/library_webgpu.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2883,7 +2883,10 @@ for (var value in LibraryWebGPU.$WebGPU.FeatureName) {
28832883

28842884
for (const key of Object.keys(LibraryWebGPU)) {
28852885
if (typeof LibraryWebGPU[key] === 'function') {
2886-
LibraryWebGPU[key + '__i53abi'] = true;
2886+
const sig = LibraryWebGPU[key + '__sig'];
2887+
if (sig?.includes('j')) {
2888+
LibraryWebGPU[key + '__i53abi'] = true;
2889+
}
28872890
}
28882891
}
28892892

test/test_other.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4681,6 +4681,26 @@ def test_js_lib_invalid_decorator(self):
46814681
err = self.expect_fail([EMCC, test_file('hello_world.c'), '--js-library', 'lib.js'])
46824682
self.assertContained("lib.js: Decorator (jslibfunc__async} has wrong type. Expected 'boolean' not 'string'", err)
46834683

4684+
def test_js_lib_i53abi(self):
4685+
create_file('lib.js', r'''
4686+
mergeInto(LibraryManager.library, {
4687+
jslibfunc__i53abi: true,
4688+
jslibfunc: (x) => { return 42 },
4689+
});
4690+
''')
4691+
err = self.expect_fail([EMCC, test_file('hello_world.c'), '-sDEFAULT_LIBRARY_FUNCS_TO_INCLUDE=jslibfunc', '--js-library', 'lib.js'])
4692+
self.assertContained("error: JS library error: '__i53abi' decorator requires '__sig' decorator: 'jslibfunc'", err)
4693+
4694+
create_file('lib.js', r'''
4695+
mergeInto(LibraryManager.library, {
4696+
jslibfunc__i53abi: true,
4697+
jslibfunc__sig: 'ii',
4698+
jslibfunc: (x) => { return 42 },
4699+
});
4700+
''')
4701+
err = self.expect_fail([EMCC, test_file('hello_world.c'), '-sDEFAULT_LIBRARY_FUNCS_TO_INCLUDE=jslibfunc', '--js-library', 'lib.js'])
4702+
self.assertContained("error: JS library error: '__i53abi' only makes sense when '__sig' includes 'j' (int64): 'jslibfunc'", err)
4703+
46844704
def test_js_lib_legacy(self):
46854705
create_file('lib.js', r'''
46864706
mergeInto(LibraryManager.library, {

0 commit comments

Comments
 (0)