@@ -488,19 +488,23 @@ struct BridgeJSLink {
488
488
dtsExportEntryLines. append ( " \( klass. name) : { " )
489
489
jsLines. append ( " class \( klass. name) extends SwiftHeapObject { " )
490
490
491
+ // Always add __construct and constructor methods for all classes
492
+ var constructorLines : [ String ] = [ ]
493
+ constructorLines. append ( " static __construct(ptr) { " )
494
+ constructorLines. append ( " return new \( klass. name) (ptr, instance.exports.bjs_ \( klass. name) _deinit); " . indent ( count: 4 ) )
495
+ constructorLines. append ( " } " )
496
+ constructorLines. append ( " " )
497
+ constructorLines. append ( " constructor(pointer, deinit) { " )
498
+ constructorLines. append ( " super(pointer, deinit); " . indent ( count: 4 ) )
499
+ constructorLines. append ( " } " )
500
+ jsLines. append ( contentsOf: constructorLines. map { $0. indent ( count: 4 ) } )
501
+
491
502
if let constructor: ExportedConstructor = klass. constructor {
492
503
let thunkBuilder = ExportedThunkBuilder ( effects: constructor. effects)
493
504
for param in constructor. parameters {
494
505
thunkBuilder. lowerParameter ( param: param)
495
506
}
496
507
var funcLines : [ String ] = [ ]
497
- funcLines. append ( " static __construct(ptr) { " )
498
- funcLines. append ( " return new \( klass. name) (ptr, instance.exports.bjs_ \( klass. name) _deinit); " . indent ( count: 4 ) )
499
- funcLines. append ( " } " )
500
- funcLines. append ( " " )
501
- funcLines. append ( " constructor(pointer, deinit) { " )
502
- funcLines. append ( " super(pointer, deinit); " . indent ( count: 4 ) )
503
- funcLines. append ( " } " )
504
508
funcLines. append ( " " )
505
509
funcLines. append ( " static init( \( constructor. parameters. map { $0. name } . joined ( separator: " , " ) ) ) { " )
506
510
let returnExpr = thunkBuilder. callConstructor ( abiName: constructor. abiName)
0 commit comments