@@ -303,8 +303,8 @@ export class Compiler extends DiagnosticEmitter {
303303 memorySegments : MemorySegment [ ] = [ ] ;
304304 /** Map of already compiled static string segments. */
305305 stringSegments : Map < string , MemorySegment > = new Map ( ) ;
306- /** Function table being compiled. */
307- functionTable : string [ ] = [ "null" ] ;
306+ /** Function table being compiled. First elem is blank. */
307+ functionTable : string [ ] = [ ] ;
308308 /** Argument count helper global. */
309309 argcVar : GlobalRef = 0 ;
310310 /** Argument count helper setter. */
@@ -452,10 +452,9 @@ export class Compiler extends DiagnosticEmitter {
452452 // import memory if requested (default memory is named '0' by Binaryen)
453453 if ( options . importMemory ) module . addMemoryImport ( "0" , "env" , "memory" , isSharedMemory ) ;
454454
455- // set up function table
455+ // set up function table (first elem is blank)
456456 var functionTable = this . functionTable ;
457- module . setFunctionTable ( functionTable . length , Module . UNLIMITED_TABLE , functionTable , module . i32 ( 0 ) ) ;
458- module . addFunction ( "null" , NativeType . None , NativeType . None , null , module . unreachable ( ) ) ;
457+ module . setFunctionTable ( 1 + functionTable . length , Module . UNLIMITED_TABLE , functionTable , module . i32 ( 1 ) ) ;
459458
460459 // import and/or export table if requested (default table is named '0' by Binaryen)
461460 if ( options . importTable ) module . addTableImport ( "0" , "env" , "table" ) ;
@@ -1605,7 +1604,7 @@ export class Compiler extends DiagnosticEmitter {
16051604 return func . functionTableIndex ;
16061605 }
16071606 var functionTable = this . functionTable ;
1608- var index = functionTable . length ;
1607+ var index = 1 + functionTable . length ; // first elem is blank
16091608 if ( ! func . is ( CommonFlags . TRAMPOLINE ) && func . signature . requiredParameters < func . signature . parameterTypes . length ) {
16101609 // insert the trampoline if the function has optional parameters
16111610 func = this . ensureTrampoline ( func ) ;
0 commit comments