Skip to content

Commit 282bb0a

Browse files
committed
Move __deps type checking into mergeInto. NFC
Doing the checks here gives better error message that include the filename.
1 parent 7320016 commit 282bb0a

File tree

3 files changed

+51
-8
lines changed

3 files changed

+51
-8
lines changed

src/jsifier.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -251,10 +251,6 @@ function ${name}(${args}) {
251251
}
252252

253253
const deps = LibraryManager.library[symbol + '__deps'] || [];
254-
if (!Array.isArray(deps)) {
255-
error(`JS library directive ${symbol}__deps=${deps.toString()} is of type ${typeof deps}, but it should be an array!`);
256-
return;
257-
}
258254

259255
if (symbolsOnly) {
260256
if (!isJsOnlySymbol(symbol) && LibraryManager.library.hasOwnProperty(symbol)) {

src/utility.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,17 @@ function mergeInto(obj, other, options = null) {
134134
const oldsig = obj[key];
135135
const newsig = other[key];
136136
if (oldsig != newsig) {
137-
console.warn(`Signature redefinition mismatch for : ${key}. (old=${oldsig} vs new=${newsig})`);
137+
error(`Signature redefinition for: ${key}. (old=${oldsig} vs new=${newsig})`);
138138
}
139139
}
140140
}
141+
142+
if (key.endsWith('__deps')) {
143+
const deps = other[key];
144+
if (!Array.isArray(deps)) {
145+
error(`JS library directive ${key}=${deps.toString()} is of type ${typeof deps}, but it should be an array`);
146+
}
147+
}
141148
}
142149

143150
return Object.assign(obj, other);

test/test_other.py

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3839,16 +3839,56 @@ def test_js_internal_deps(self):
38393839
},
38403840
});
38413841
''')
3842-
create_file('src.cpp', r'''
3842+
create_file('src.c', r'''
38433843
#include <stdio.h>
3844-
extern "C" int jslibfunc();
3844+
int jslibfunc();
38453845
int main() {
38463846
printf("c calling: %d\n", jslibfunc());
38473847
}
38483848
''')
3849-
err = self.run_process([EMXX, 'src.cpp', '--js-library', 'lib.js'], stderr=PIPE).stderr
3849+
err = self.run_process([EMCC, 'src.c', '--js-library', 'lib.js'], stderr=PIPE).stderr
38503850
self.assertContained("warning: user library symbol 'jslibfunc' depends on internal symbol '$callRuntimeCallbacks'", err)
38513851

3852+
def test_js_lib_sig_mismatch(self):
3853+
create_file('lib.js', r'''
3854+
mergeInto(LibraryManager.library, {
3855+
jslibfunc__sig: 'ii',
3856+
jslibfunc: function(x) {},
3857+
});
3858+
3859+
mergeInto(LibraryManager.library, {
3860+
jslibfunc__sig: 'dd',
3861+
jslibfunc: function(x) {},
3862+
});
3863+
3864+
''')
3865+
create_file('src.c', r'''
3866+
#include <stdio.h>
3867+
int jslibfunc();
3868+
int main() {
3869+
printf("c calling: %d\n", jslibfunc());
3870+
}
3871+
''')
3872+
err = self.expect_fail([EMCC, 'src.c', '--js-library', 'lib.js'])
3873+
self.assertContained('lib.js: Signature redefinition for: jslibfunc__sig. (old=ii vs new=dd)', err)
3874+
3875+
def test_js_lib_invalid_deps(self):
3876+
create_file('lib.js', r'''
3877+
mergeInto(LibraryManager.library, {
3878+
jslibfunc__deps: 'hello',
3879+
jslibfunc: function(x) {},
3880+
});
3881+
''')
3882+
create_file('src.c', r'''
3883+
#include <stdio.h>
3884+
int jslibfunc();
3885+
int main() {
3886+
printf("c calling: %d\n", jslibfunc());
3887+
}
3888+
''')
3889+
err = self.expect_fail([EMCC, 'src.c', '--js-library', 'lib.js'])
3890+
self.assertContained('lib.js: JS library directive jslibfunc__deps=hello is of type string, but it should be an array', err)
3891+
38523892
def test_EMCC_BUILD_DIR(self):
38533893
# EMCC_BUILD_DIR env var contains the dir we were building in, when running the js compiler (e.g. when
38543894
# running a js library). We force the cwd to be src/ for technical reasons, so this lets you find out

0 commit comments

Comments
 (0)