@@ -671,16 +671,17 @@ function convertJsFunctionToWasm(func, sig) {
671671}
672672
673673// Add a wasm function to the table.
674- function addWasmFunction ( func , sig ) {
674+ function addFunctionWasm ( func , sig ) {
675675 var table = wasmTable ;
676676 var ret = table . length ;
677677
678678 // Grow the table
679679 try {
680680 table . grow ( 1 ) ;
681681 } catch ( err ) {
682- if ( ! err instanceof RangeError )
682+ if ( ! err instanceof RangeError ) {
683683 throw err ;
684+ }
684685 throw 'Unable to grow wasm table. Use a higher value for RESERVED_FUNCTION_POINTERS or set ALLOW_TABLE_GROWTH.' ;
685686 }
686687
@@ -689,19 +690,24 @@ function addWasmFunction(func, sig) {
689690 // Attempting to call this with JS function will cause of table.set() to fail
690691 table . set ( ret , func ) ;
691692 } catch ( err ) {
692- if ( ! err instanceof TypeError )
693+ if ( ! err instanceof TypeError ) {
693694 throw err ;
695+ }
694696 assert ( typeof sig !== 'undefined' , 'Missing signature argument to addFunction' ) ;
695697 var wrapped = convertJsFunctionToWasm ( func , sig ) ;
696698 table . set ( ret , wrapped ) ;
697699 }
698700
699701 return ret ;
700702}
703+
704+ function removeFunctionWasm ( index ) {
705+ // TODO(sbc): Look into implementing this to allow re-using of table slots
706+ }
701707#endif
702708
703709// 'sig' parameter is required for the llvm backend but only when func is not
704- // already as WebAssembly function.
710+ // already a WebAssembly function.
705711function addFunction ( func , sig ) {
706712#if ASSERTIONS == 2
707713 if ( typeof sig === 'undefined' ) {
@@ -710,7 +716,7 @@ function addFunction(func, sig) {
710716#endif // ASSERTIONS
711717
712718#if WASM_BACKEND
713- return addWasmFunction ( func , sig ) ;
719+ return addFunctionWasm ( func , sig ) ;
714720#else
715721
716722#if EMULATED_FUNCTION_POINTERS == 0
@@ -726,9 +732,9 @@ function addFunction(func, sig) {
726732#else // EMULATED_FUNCTION_POINTERS == 0
727733
728734#if WASM
729- return addWasmFunction ( func , sig ) ;
735+ return addFunctionWasm ( func , sig ) ;
730736#else
731- alignFunctionTables ( ) ; // XXX we should rely on this being an invariant
737+ alignFunctionTables ( ) ; // TODO: we should rely on this being an invariant
732738 var tables = getFunctionTables ( ) ;
733739 var ret = - 1 ;
734740 for ( var sig in tables ) {
@@ -738,28 +744,32 @@ function addFunction(func, sig) {
738744 table . push ( func ) ;
739745 }
740746 return ret ;
741- #endif
747+ #endif // WASM
742748
743749#endif // EMULATED_FUNCTION_POINTERS == 0
744-
745750#endif // WASM_BACKEND
746751}
747752
748753function removeFunction ( index ) {
749754#if WASM_BACKEND
755+ removeFunctionWasm ( index ) ;
750756#else
757+
751758#if EMULATED_FUNCTION_POINTERS == 0
752759 functionPointers [ index - jsCallStartIndex ] = null ;
753760#else
754- #if ! WASM
761+ #if WASM
762+ removeFunctionWasm ( index ) ;
763+ #else
755764 alignFunctionTables ( ) ; // XXX we should rely on this being an invariant
756765 var tables = getFunctionTables ( ) ;
757766 for ( var sig in tables ) {
758767 tables [ sig ] [ index ] = null ;
759768 }
760- #endif
761- #endif
762- #endif
769+ #endif // WASM
770+
771+ #endif // EMULATE_FUNCTION_POINTER_CASTS == 0
772+ #endif // WASM_BACKEND
763773}
764774
765775var funcWrappers = { } ;
0 commit comments