@@ -53,7 +53,7 @@ var LibraryEmbind = {
53
53
argOut . push ( `${ arg . name } : ${ nameMap ( arg . type ) } ` ) ;
54
54
}
55
55
out . push ( argOut . join ( ', ' ) ) ;
56
- out . push ( `): ${ nameMap ( this . returnType ) } ` ) ;
56
+ out . push ( `): ${ nameMap ( this . returnType , true ) } ` ) ;
57
57
}
58
58
59
59
printFunction ( nameMap , out ) {
@@ -298,37 +298,40 @@ var LibraryEmbind = {
298
298
constructor ( definitions ) {
299
299
this . definitions = definitions ;
300
300
const jsString = 'ArrayBuffer|Uint8Array|Uint8ClampedArray|Int8Array|string' ;
301
+ // The mapping is in the format of '<c++ name>' => ['toWireType', 'fromWireType']
302
+ // or if the to/from wire types are the same use a single element.
301
303
this . builtInToJsName = new Map ( [
302
- [ 'bool' , 'boolean' ] ,
303
- [ 'float' , 'number' ] ,
304
- [ 'double' , 'number' ] ,
304
+ [ 'bool' , [ 'boolean' ] ] ,
305
+ [ 'float' , [ 'number' ] ] ,
306
+ [ 'double' , [ 'number' ] ] ,
305
307
#if MEMORY64
306
- [ 'long' , 'bigint' ] ,
307
- [ 'unsigned long' , 'bigint' ] ,
308
+ [ 'long' , [ 'bigint' ] ] ,
309
+ [ 'unsigned long' , [ 'bigint' ] ] ,
308
310
#endif
309
311
#if WASM_BIGINT
310
- [ 'int64_t' , 'bigint' ] ,
311
- [ 'uint64_t' , 'bigint' ] ,
312
+ [ 'int64_t' , [ 'bigint' ] ] ,
313
+ [ 'uint64_t' , [ 'bigint' ] ] ,
312
314
#endif
313
- [ 'void' , 'void' ] ,
314
- [ 'std::string' , jsString ] ,
315
- [ 'std::basic_string<unsigned char>' , jsString ] ,
316
- [ 'std::wstring' , jsString ] ,
317
- [ 'std::u16string' , jsString ] ,
318
- [ 'std::u32string' , jsString ] ,
319
- [ 'emscripten::val' , 'any' ] ,
315
+ [ 'void' , [ 'void' ] ] ,
316
+ [ 'std::string' , [ jsString , 'string' ] ] ,
317
+ [ 'std::basic_string<unsigned char>' , [ jsString , 'string' ] ] ,
318
+ [ 'std::wstring' , [ 'string' ] ] ,
319
+ [ 'std::u16string' , [ 'string' ] ] ,
320
+ [ 'std::u32string' , [ 'string' ] ] ,
321
+ [ 'emscripten::val' , [ 'any' ] ] ,
320
322
] ) ;
321
323
}
322
324
323
- typeToJsName ( type ) {
325
+ typeToJsName ( type , isFromWireType = false ) {
324
326
if ( type instanceof IntegerType ) {
325
327
return 'number' ;
326
328
}
327
329
if ( type instanceof PrimitiveType ) {
328
330
if ( ! this . builtInToJsName . has ( type . name ) ) {
329
331
throw new Error ( `Missing primitive type to TS type for '${ type . name } '` ) ;
330
332
}
331
- return this . builtInToJsName . get ( type . name )
333
+ const [ toWireType , fromWireType = toWireType ] = this . builtInToJsName . get ( type . name ) ;
334
+ return isFromWireType ? fromWireType : toWireType ;
332
335
}
333
336
if ( type instanceof PointerDefinition ) {
334
337
return this . typeToJsName ( type . classType ) ;
0 commit comments