File tree Expand file tree Collapse file tree 3 files changed +17
-2
lines changed Expand file tree Collapse file tree 3 files changed +17
-2
lines changed Original file line number Diff line number Diff line change @@ -512,14 +512,15 @@ Module['FS_createPreloadedFile'] = FS.createPreloadedFile;
512
512
#include "URIUtils.js"
513
513
514
514
#if ASSERTIONS
515
- function createExportWrapper ( name ) {
515
+ function createExportWrapper ( name , nargs ) {
516
516
return ( ...args ) => {
517
517
assert ( runtimeInitialized , `native function \`${ name } \` called before runtime initialization` ) ;
518
518
#if EXIT_RUNTIME
519
519
assert ( ! runtimeExited , `native function \`${ name } \` called after runtime exit (use NO_EXIT_RUNTIME to keep it alive after main() exits)` ) ;
520
520
#endif
521
521
var f = wasmExports [ name ] ;
522
522
assert ( f , `exported native function \`${ name } \` not found` ) ;
523
+ assert ( args . length <= nargs , `native function \`${ name } \` called with ${ args . length } args but expects ${ nargs } ` ) ;
523
524
return f ( ...args ) ;
524
525
} ;
525
526
}
Original file line number Diff line number Diff line change @@ -11985,6 +11985,20 @@ def test_native_call_after_exit(self):
11985
11985
out = self.run_js('foo.js', assert_returncode=NON_ZERO)
11986
11986
self.assertContained('native function `main` called after runtime exit', out)
11987
11987
11988
+ def test_native_call_nargs(self):
11989
+ self.set_setting('ASSERTIONS')
11990
+ self.set_setting('EXPORTED_FUNCTIONS', ['_main', '_foo'])
11991
+ create_file('foo.c', r'''
11992
+ #include <emscripten.h>
11993
+ void foo(int arg) {}
11994
+ int main() {
11995
+ EM_ASM(_foo(99, 100));
11996
+ }
11997
+ ''')
11998
+ self.build('foo.c')
11999
+ out = self.run_js('foo.js', assert_returncode=NON_ZERO)
12000
+ self.assertContained('native function `foo` called with 2 args but expects 1', out)
12001
+
11988
12002
def test_metadce_wasm2js_i64(self):
11989
12003
# handling i64 unsigned remainder brings in some i64 support code. metadce
11990
12004
# must not remove it.
Original file line number Diff line number Diff line change @@ -851,7 +851,7 @@ def install_wrapper(sym):
851
851
if settings .ASSERTIONS and install_wrapper (name ):
852
852
# With assertions enabled we create a wrapper that are calls get routed through, for
853
853
# the lifetime of the program.
854
- wrapper += "createExportWrapper('%s' );" % name
854
+ wrapper += f "createExportWrapper('{ name } ', { nargs } );"
855
855
elif settings .WASM_ASYNC_COMPILATION :
856
856
# With WASM_ASYNC_COMPILATION wrapper will replace the global var and Module var on
857
857
# first use.
You can’t perform that action at this time.
0 commit comments