@@ -602,7 +602,7 @@ Module['registerFunctions'] = registerFunctions;
602602#if ! WASM_BACKEND && EMULATED_FUNCTION_POINTERS == 0
603603var jsCallStartIndex = 1 ;
604604var functionPointers = new Array ( { { { RESERVED_FUNCTION_POINTERS } } } ) ;
605- #endif // EMULATED_FUNCTION_POINTERS == 0
605+ #endif // !WASM_BACKEND && EMULATED_FUNCTION_POINTERS == 0
606606
607607#if WASM
608608// Wraps a JS function as a wasm function with a given signature.
@@ -671,7 +671,6 @@ function convertJsFunctionToWasm(func, sig) {
671671}
672672
673673// Add a wasm function to the table.
674- // Attempting to call this with JS function will cause of table.set() to fail
675674function addWasmFunction ( func , sig ) {
676675 var table = wasmTable ;
677676 var ret = table . length ;
@@ -687,10 +686,12 @@ function addWasmFunction(func, sig) {
687686
688687 // Insert new element
689688 try {
689+ // Attempting to call this with JS function will cause of table.set() to fail
690690 table . set ( ret , func ) ;
691691 } catch ( err ) {
692692 if ( ! err instanceof TypeError )
693693 throw err ;
694+ assert ( typeof sig !== 'undefined' , 'Missing signature argument to addFunction' ) ;
694695 var wrapped = convertJsFunctionToWasm ( func , sig ) ;
695696 table . set ( ret , wrapped ) ;
696697 }
@@ -709,9 +710,6 @@ function addFunction(func, sig) {
709710#endif // ASSERTIONS
710711
711712#if WASM_BACKEND
712- assert ( typeof sig !== 'undefined' ,
713- 'Second argument of addFunction should be a wasm function signature ' +
714- 'string' ) ;
715713 return addWasmFunction ( func , sig ) ;
716714#else
717715
@@ -753,13 +751,15 @@ function removeFunction(index) {
753751#if EMULATED_FUNCTION_POINTERS == 0
754752 functionPointers [ index - jsCallStartIndex ] = null ;
755753#else
754+ #if ! WASM
756755 alignFunctionTables ( ) ; // XXX we should rely on this being an invariant
757756 var tables = getFunctionTables ( ) ;
758757 for ( var sig in tables ) {
759758 tables [ sig ] [ index ] = null ;
760759 }
761760#endif
762761#endif
762+ #endif
763763}
764764
765765var funcWrappers = { } ;
0 commit comments