@@ -77,21 +77,16 @@ addToLibrary({
77
77
return code ;
78
78
} ) ) ,
79
79
80
+ #if ! WASM2JS || WASM = = 2
80
81
// Wraps a JS function as a wasm function with a given signature.
81
- #if ! WASM2JS
82
82
$convertJsFunctionToWasm__deps : [
83
83
'$uleb128EncodeWithLen' ,
84
84
#if WASM_JS_TYPES
85
85
'$sigToWasmTypes' ,
86
86
#endif
87
87
'$generateTypePack'
88
88
] ,
89
- #endif
90
89
$convertJsFunctionToWasm : ( func , sig ) => {
91
- #if WASM2JS
92
- // return func;
93
- #else // WASM2JS
94
-
95
90
#if ASSERTIONS && ! WASM_BIGINT
96
91
assert ( ! sig . includes ( 'j' ) , 'i64 not permitted in function signatures when WASM_BIGINT is disabled' ) ;
97
92
#endif
@@ -135,8 +130,8 @@ addToLibrary({
135
130
var instance = new WebAssembly . Instance ( module , { 'e' : { 'f' : func } } ) ;
136
131
var wrappedFunc = instance . exports [ 'f' ] ;
137
132
return wrappedFunc ;
138
- #endif // WASM2JS
139
133
} ,
134
+ #endif // !WASM2JS && WASM != 2
140
135
141
136
$freeTableIndexes : [ ] ,
142
137
@@ -192,18 +187,21 @@ addToLibrary({
192
187
* 'sig' parameter is required if the function being added is a JS function.
193
188
*/
194
189
$addFunction__docs : '/** @param {string=} sig */' ,
195
- $addFunction__deps : [ '$convertJsFunctionToWasm' , '$ getFunctionAddress',
190
+ $addFunction__deps : [ '$getFunctionAddress' ,
196
191
'$functionsInTableMap' , '$getEmptyTableSlot' ,
197
192
'$setWasmTableEntry' ,
193
+ #if ! WASM2JS || WASM == 2
194
+ '$convertJsFunctionToWasm' ,
195
+ #endif
198
196
#if ASSERTIONS >= 2
199
197
'$getWasmTableEntry' , '$wasmTable' ,
200
198
#endif
201
199
] ,
202
200
203
201
$addFunction : ( func , sig ) => {
204
- #if ASSERTIONS
202
+ #if ASSERTIONS
205
203
assert ( typeof func != 'undefined' ) ;
206
- #endif // ASSERTIONS
204
+ #endif // ASSERTIONS
207
205
// Check if the function is already in the table, to ensure each function
208
206
// gets a unique index.
209
207
var rtn = getFunctionAddress ( func ) ;
@@ -213,17 +211,20 @@ addToLibrary({
213
211
214
212
// It's not in the table, add it now.
215
213
216
- #if ASSERTIONS >= 2
214
+ #if ASSERTIONS >= 2
217
215
// Make sure functionsInTableMap is actually up to date, that is, that this
218
216
// function is not actually in the wasm Table despite not being tracked in
219
217
// functionsInTableMap.
220
218
for ( var i = 0 ; i < wasmTable . length ; i ++ ) {
221
219
assert ( getWasmTableEntry ( i ) != func , 'function in Table but not functionsInTableMap' ) ;
222
220
}
223
- #endif
221
+ #endif
224
222
225
223
var ret = getEmptyTableSlot ( ) ;
226
224
225
+ #if WASM2JS && WASM != 2
226
+ setWasmTableEntry ( ret , func ) ;
227
+ #else
227
228
// Set the new value.
228
229
try {
229
230
// Attempting to call this with JS function will cause of table.set() to fail
@@ -232,12 +233,13 @@ addToLibrary({
232
233
if ( ! ( err instanceof TypeError ) ) {
233
234
throw err ;
234
235
}
235
- #if ASSERTIONS
236
+ #if ASSERTIONS
236
237
assert ( typeof sig != 'undefined' , 'Missing signature argument to addFunction: ' + func ) ;
237
- #endif
238
+ #endif
238
239
var wrapped = convertJsFunctionToWasm ( func , sig ) ;
239
240
setWasmTableEntry ( ret , wrapped ) ;
240
241
}
242
+ #endif
241
243
242
244
functionsInTableMap . set ( func , ret ) ;
243
245
0 commit comments