@@ -77,21 +77,16 @@ addToLibrary({
7777 return code ;
7878 } ) ) ,
7979
80+ #if ! WASM2JS || WASM = = 2
8081 // Wraps a JS function as a wasm function with a given signature.
81- #if ! WASM2JS
8282 $convertJsFunctionToWasm__deps : [
8383 '$uleb128EncodeWithLen' ,
8484#if WASM_JS_TYPES
8585 '$sigToWasmTypes' ,
8686#endif
8787 '$generateTypePack'
8888 ] ,
89- #endif
9089 $convertJsFunctionToWasm : ( func , sig ) => {
91- #if WASM2JS
92- // return func;
93- #else // WASM2JS
94-
9590#if ASSERTIONS && ! WASM_BIGINT
9691 assert ( ! sig . includes ( 'j' ) , 'i64 not permitted in function signatures when WASM_BIGINT is disabled' ) ;
9792#endif
@@ -135,8 +130,8 @@ addToLibrary({
135130 var instance = new WebAssembly . Instance ( module , { 'e' : { 'f' : func } } ) ;
136131 var wrappedFunc = instance . exports [ 'f' ] ;
137132 return wrappedFunc ;
138- #endif // WASM2JS
139133 } ,
134+ #endif // !WASM2JS && WASM != 2
140135
141136 $freeTableIndexes : [ ] ,
142137
@@ -192,18 +187,21 @@ addToLibrary({
192187 * 'sig' parameter is required if the function being added is a JS function.
193188 */
194189 $addFunction__docs : '/** @param {string=} sig */' ,
195- $addFunction__deps : [ '$convertJsFunctionToWasm' , '$ getFunctionAddress',
190+ $addFunction__deps : [ '$getFunctionAddress' ,
196191 '$functionsInTableMap' , '$getEmptyTableSlot' ,
197192 '$setWasmTableEntry' ,
193+ #if ! WASM2JS || WASM == 2
194+ '$convertJsFunctionToWasm' ,
195+ #endif
198196#if ASSERTIONS >= 2
199197 '$getWasmTableEntry' , '$wasmTable' ,
200198#endif
201199 ] ,
202200
203201 $addFunction : ( func , sig ) => {
204- #if ASSERTIONS
202+ #if ASSERTIONS
205203 assert ( typeof func != 'undefined' ) ;
206- #endif // ASSERTIONS
204+ #endif // ASSERTIONS
207205 // Check if the function is already in the table, to ensure each function
208206 // gets a unique index.
209207 var rtn = getFunctionAddress ( func ) ;
@@ -213,17 +211,20 @@ addToLibrary({
213211
214212 // It's not in the table, add it now.
215213
216- #if ASSERTIONS >= 2
214+ #if ASSERTIONS >= 2
217215 // Make sure functionsInTableMap is actually up to date, that is, that this
218216 // function is not actually in the wasm Table despite not being tracked in
219217 // functionsInTableMap.
220218 for ( var i = 0 ; i < wasmTable . length ; i ++ ) {
221219 assert ( getWasmTableEntry ( i ) != func , 'function in Table but not functionsInTableMap' ) ;
222220 }
223- #endif
221+ #endif
224222
225223 var ret = getEmptyTableSlot ( ) ;
226224
225+ #if WASM2JS && WASM != 2
226+ setWasmTableEntry ( ret , func ) ;
227+ #else
227228 // Set the new value.
228229 try {
229230 // Attempting to call this with JS function will cause of table.set() to fail
@@ -232,12 +233,13 @@ addToLibrary({
232233 if ( ! ( err instanceof TypeError ) ) {
233234 throw err ;
234235 }
235- #if ASSERTIONS
236+ #if ASSERTIONS
236237 assert ( typeof sig != 'undefined' , 'Missing signature argument to addFunction: ' + func ) ;
237- #endif
238+ #endif
238239 var wrapped = convertJsFunctionToWasm ( func , sig ) ;
239240 setWasmTableEntry ( ret , wrapped ) ;
240241 }
242+ #endif
241243
242244 functionsInTableMap . set ( func , ret ) ;
243245
0 commit comments