Skip to content

Commit bb5665b

Browse files
authored
Improve check for invalid proxying mode. NFC (emscripten-core#26001)
1 parent e85c04b commit bb5665b

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/jsifier.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -442,8 +442,8 @@ function(${args}) {
442442

443443
const proxyingMode = LibraryManager.library[symbol + '__proxy'];
444444
if (proxyingMode) {
445-
if (proxyingMode !== 'sync' && proxyingMode !== 'async' && proxyingMode !== 'none') {
446-
throw new Error(`Invalid proxyingMode ${symbol}__proxy: '${proxyingMode}' specified!`);
445+
if (!['sync', 'async', 'none'].includes(proxyingMode)) {
446+
error(`JS library error: invalid proxying mode '${symbol}__proxy: ${proxyingMode}' specified`);
447447
}
448448
if (SHARED_MEMORY && proxyingMode != 'none') {
449449
const sync = proxyingMode === 'sync';

test/test_jslib.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,16 @@ def test_jslib_i53abi_errors(self):
325325
err = self.expect_fail([EMCC, test_file('hello_world.c'), '-sDEFAULT_LIBRARY_FUNCS_TO_INCLUDE=jslibfunc', '--js-library', 'lib.js'])
326326
self.assertContained("error: JS library error: '__i53abi' only makes sense when '__sig' includes 'j' (int64): 'jslibfunc'", err)
327327

328+
def test_jslib_invalid_proxy_mode(self):
329+
create_file('lib.js', r'''
330+
addToLibrary({
331+
jslibfunc__proxy: 'foo',
332+
jslibfunc: (x) => 42,
333+
});
334+
''')
335+
err = self.expect_fail([EMCC, test_file('hello_world.c'), '-sDEFAULT_LIBRARY_FUNCS_TO_INCLUDE=jslibfunc', '--js-library', 'lib.js'])
336+
self.assertContained("error: JS library error: invalid proxying mode 'jslibfunc__proxy: foo' specified", err)
337+
328338
def test_jslib_legacy(self):
329339
create_file('lib.js', r'''
330340
mergeInto(LibraryManager.library, {

0 commit comments

Comments
 (0)