@@ -44,12 +44,13 @@ var LibraryEmbind = {
44
44
} ,
45
45
$FunctionDefinition__deps : [ '$createJsInvoker' , '$createJsInvokerSignature' , '$emittedFunctions' ] ,
46
46
$FunctionDefinition : class {
47
- constructor ( name , returnType , argumentTypes , functionIndex , thisType = null , isAsync = false ) {
47
+ constructor ( name , returnType , argumentTypes , functionIndex , thisType = null , isConstructor = false , isAsync = false ) {
48
48
this . name = name ;
49
49
this . returnType = returnType ;
50
50
this . argumentTypes = argumentTypes ;
51
51
this . functionIndex = functionIndex ;
52
52
this . thisType = thisType ;
53
+ this . isConstructor = isConstructor ;
53
54
this . isAsync = isAsync ;
54
55
}
55
56
@@ -75,7 +76,14 @@ var LibraryEmbind = {
75
76
}
76
77
77
78
out . push ( argOut . join ( ', ' ) ) ;
78
- out . push ( `): ${ nameMap ( this . returnType , true ) } ` ) ;
79
+ let returnType = this . returnType ;
80
+ // Constructors can return a pointer, but it will be a non-null pointer.
81
+ // Change the return type to the class type so the TS output doesn't
82
+ // have `| null`.
83
+ if ( this . isConstructor && this . returnType instanceof PointerDefinition ) {
84
+ returnType = this . returnType . classType ;
85
+ }
86
+ out . push ( `): ${ nameMap ( returnType , true ) } ` ) ;
79
87
}
80
88
81
89
printFunction ( nameMap , out ) {
@@ -183,7 +191,7 @@ var LibraryEmbind = {
183
191
printModuleEntry ( nameMap , out ) {
184
192
out . push ( ` ${ this . name } : {` ) ;
185
193
const entries = [ ] ;
186
- for ( const construct of this . constructors ) {
194
+ for ( const construct of this . constructors ) {
187
195
const entry = [ ] ;
188
196
entry . push ( 'new' ) ;
189
197
construct . printSignature ( nameMap , entry ) ;
@@ -368,7 +376,7 @@ var LibraryEmbind = {
368
376
return tsName ;
369
377
}
370
378
if ( type instanceof PointerDefinition ) {
371
- return this . typeToJsName ( type . classType ) ;
379
+ return ` ${ this . typeToJsName ( type . classType ) } | null` ;
372
380
}
373
381
if ( type instanceof OptionalType ) {
374
382
return `${ this . typeToJsName ( type . type ) } | undefined` ;
@@ -432,7 +440,7 @@ var LibraryEmbind = {
432
440
registerType ( id , new IntegerType ( id ) ) ;
433
441
} ,
434
442
$createFunctionDefinition__deps : [ '$FunctionDefinition' , '$heap32VectorToArray' , '$readLatin1String' , '$Argument' , '$whenDependentTypesAreResolved' , '$getFunctionName' , '$getFunctionArgsName' , '$PointerDefinition' , '$ClassDefinition' ] ,
435
- $createFunctionDefinition : ( name , argCount , rawArgTypesAddr , functionIndex , hasThis , isAsync , cb ) => {
443
+ $createFunctionDefinition : ( name , argCount , rawArgTypesAddr , functionIndex , hasThis , isConstructor , isAsync , cb ) => {
436
444
const argTypes = heap32VectorToArray ( argCount , rawArgTypesAddr ) ;
437
445
name = typeof name === 'string' ? name : readLatin1String ( name ) ;
438
446
@@ -462,7 +470,7 @@ var LibraryEmbind = {
462
470
args . push ( new Argument ( `_${ i - argStart } ` , argTypes [ i ] ) ) ;
463
471
}
464
472
}
465
- const funcDef = new FunctionDefinition ( name , returnType , args , functionIndex , thisType , isAsync ) ;
473
+ const funcDef = new FunctionDefinition ( name , returnType , args , functionIndex , thisType , isConstructor , isAsync ) ;
466
474
cb ( funcDef ) ;
467
475
return [ ] ;
468
476
} ) ;
@@ -514,7 +522,7 @@ var LibraryEmbind = {
514
522
} ,
515
523
_embind_register_function__deps : [ '$moduleDefinitions' , '$createFunctionDefinition' ] ,
516
524
_embind_register_function : ( name , argCount , rawArgTypesAddr , signature , rawInvoker , fn , isAsync ) => {
517
- createFunctionDefinition ( name , argCount , rawArgTypesAddr , fn , false , isAsync , ( funcDef ) => {
525
+ createFunctionDefinition ( name , argCount , rawArgTypesAddr , fn , false , false , isAsync , ( funcDef ) => {
518
526
moduleDefinitions . push ( funcDef ) ;
519
527
} ) ;
520
528
} ,
@@ -559,7 +567,7 @@ var LibraryEmbind = {
559
567
) {
560
568
whenDependentTypesAreResolved ( [ ] , [ rawClassType ] , function ( classType ) {
561
569
classType = classType [ 0 ] ;
562
- createFunctionDefinition ( `constructor ${ classType . name } ` , argCount , rawArgTypesAddr , rawConstructor , false , false , ( funcDef ) => {
570
+ createFunctionDefinition ( `constructor ${ classType . name } ` , argCount , rawArgTypesAddr , rawConstructor , false , true , false , ( funcDef ) => {
563
571
classType . constructors . push ( funcDef ) ;
564
572
} ) ;
565
573
return [ ] ;
@@ -575,7 +583,7 @@ var LibraryEmbind = {
575
583
context ,
576
584
isPureVirtual ,
577
585
isAsync ) {
578
- createFunctionDefinition ( methodName , argCount , rawArgTypesAddr , context , true , isAsync , ( funcDef ) => {
586
+ createFunctionDefinition ( methodName , argCount , rawArgTypesAddr , context , true , false , isAsync , ( funcDef ) => {
579
587
const classDef = funcDef . thisType ;
580
588
classDef . methods . push ( funcDef ) ;
581
589
} ) ;
@@ -616,7 +624,7 @@ var LibraryEmbind = {
616
624
isAsync ) {
617
625
whenDependentTypesAreResolved ( [ ] , [ rawClassType ] , function ( classType ) {
618
626
classType = classType [ 0 ] ;
619
- createFunctionDefinition ( methodName , argCount , rawArgTypesAddr , fn , false , isAsync , ( funcDef ) => {
627
+ createFunctionDefinition ( methodName , argCount , rawArgTypesAddr , fn , false , false , isAsync , ( funcDef ) => {
620
628
classType . staticMethods . push ( funcDef ) ;
621
629
} ) ;
622
630
return [ ] ;
0 commit comments