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
10 changes: 10 additions & 0 deletions src/jsifier.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,16 @@ function(${args}) {

const sig = LibraryManager.library[symbol + '__sig'];
const i53abi = LibraryManager.library[symbol + '__i53abi'];
if (i53abi) {
if (!sig) {
error(`JS library error: '__i53abi' decorator requires '__sig' decorator: '${symbol}'`);
}
if (!sig.includes('j')) {
error(
`JS library error: '__i53abi' only makes sense when '__sig' includes 'j' (int64): '${symbol}'`,
);
}
}
if (
sig &&
((i53abi && sig.includes('j')) || ((MEMORY64 || CAN_ADDRESS_2GB) && sig.includes('p')))
Expand Down
5 changes: 4 additions & 1 deletion src/library_webgpu.js
Original file line number Diff line number Diff line change
Expand Up @@ -2883,7 +2883,10 @@ for (var value in LibraryWebGPU.$WebGPU.FeatureName) {

for (const key of Object.keys(LibraryWebGPU)) {
if (typeof LibraryWebGPU[key] === 'function') {
LibraryWebGPU[key + '__i53abi'] = true;
const sig = LibraryWebGPU[key + '__sig'];
if (sig?.includes('j')) {
LibraryWebGPU[key + '__i53abi'] = true;
}
}
}

Expand Down
20 changes: 20 additions & 0 deletions test/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -4677,6 +4677,26 @@ def test_js_lib_invalid_decorator(self):
err = self.expect_fail([EMCC, test_file('hello_world.c'), '--js-library', 'lib.js'])
self.assertContained("lib.js: Decorator (jslibfunc__async} has wrong type. Expected 'boolean' not 'string'", err)

def test_js_lib_i53abi(self):
create_file('lib.js', r'''
mergeInto(LibraryManager.library, {
jslibfunc__i53abi: true,
jslibfunc: (x) => { return 42 },
});
''')
err = self.expect_fail([EMCC, test_file('hello_world.c'), '-sDEFAULT_LIBRARY_FUNCS_TO_INCLUDE=jslibfunc', '--js-library', 'lib.js'])
self.assertContained("error: JS library error: '__i53abi' decorator requires '__sig' decorator: 'jslibfunc'", err)

create_file('lib.js', r'''
mergeInto(LibraryManager.library, {
jslibfunc__i53abi: true,
jslibfunc__sig: 'ii',
jslibfunc: (x) => { return 42 },
});
''')
err = self.expect_fail([EMCC, test_file('hello_world.c'), '-sDEFAULT_LIBRARY_FUNCS_TO_INCLUDE=jslibfunc', '--js-library', 'lib.js'])
self.assertContained("error: JS library error: '__i53abi' only makes sense when '__sig' includes 'j' (int64): 'jslibfunc'", err)

def test_js_lib_legacy(self):
create_file('lib.js', r'''
mergeInto(LibraryManager.library, {
Expand Down
Loading