@@ -246,7 +246,7 @@ public struct BridgeJSLink {
246246 " let \( JSGlueVariableScope . reservedStorageToReturnOptionalFloat) ; " ,
247247 " let \( JSGlueVariableScope . reservedStorageToReturnOptionalDouble) ; " ,
248248 " let \( JSGlueVariableScope . reservedStorageToReturnOptionalHeapObject) ; " ,
249- " let \( JSGlueVariableScope . reservedTmpRetTag) ; " ,
249+ " let \( JSGlueVariableScope . reservedTmpRetTag) = [] ;" ,
250250 " let \( JSGlueVariableScope . reservedTmpRetStrings) = []; " ,
251251 " let \( JSGlueVariableScope . reservedTmpRetInts) = []; " ,
252252 " let \( JSGlueVariableScope . reservedTmpRetF32s) = []; " ,
@@ -388,7 +388,7 @@ public struct BridgeJSLink {
388388 printer. write ( " } " )
389389 printer. write ( " bjs[ \" swift_js_push_tag \" ] = function(tag) { " )
390390 printer. indent {
391- printer. write ( " \( JSGlueVariableScope . reservedTmpRetTag) = tag;" )
391+ printer. write ( " \( JSGlueVariableScope . reservedTmpRetTag) .push( tag) ;" )
392392 }
393393 printer. write ( " } " )
394394 printer. write ( " bjs[ \" swift_js_push_i32 \" ] = function(v) { " )
@@ -1059,6 +1059,18 @@ public struct BridgeJSLink {
10591059 _ = fragment. printCode ( [ structDef. name] , structScope, structPrinter, structCleanup)
10601060 bodyPrinter. write ( lines: structPrinter. lines)
10611061 }
1062+
1063+ let allAssocEnums = exportedSkeletons. flatMap {
1064+ $0. enums. filter { $0. enumType == . associatedValue }
1065+ }
1066+ for enumDef in allAssocEnums {
1067+ let enumPrinter = CodeFragmentPrinter ( )
1068+ let enumScope = JSGlueVariableScope ( )
1069+ let enumCleanup = CodeFragmentPrinter ( )
1070+ let fragment = IntrinsicJSFragment . associatedValueEnumHelperFactory ( enumDefinition: enumDef)
1071+ _ = fragment. printCode ( [ enumDef. valuesName] , enumScope, enumPrinter, enumCleanup)
1072+ bodyPrinter. write ( lines: enumPrinter. lines)
1073+ }
10621074 bodyPrinter. nextLine ( )
10631075 bodyPrinter. write ( contentsOf: generateAddImports ( needsImportsObject: data. needsImportsObject) )
10641076
@@ -1094,8 +1106,6 @@ public struct BridgeJSLink {
10941106 " \( JSGlueVariableScope . reservedMemory) = \( JSGlueVariableScope . reservedInstance) .exports.memory; " ,
10951107 ] )
10961108 printer. nextLine ( )
1097- // Enum helpers section
1098- printer. write ( contentsOf: enumHelperAssignments ( ) )
10991109 // Error handling
11001110 printer. write ( " \( JSGlueVariableScope . reservedSetException) = (error) => { " )
11011111 printer. indent {
@@ -1109,18 +1119,19 @@ public struct BridgeJSLink {
11091119 }
11101120
11111121 // createExports method
1112- try printer. indent {
1122+ printer. indent {
11131123 printer. write ( lines: [
11141124 " /** @param {WebAssembly.Instance} instance */" ,
11151125 " createExports: (instance) => { " ,
11161126 ] )
1117- try printer. indent {
1127+ printer. indent {
11181128 printer. write ( " const js = \( JSGlueVariableScope . reservedSwift) .memory.heap; " )
11191129
11201130 printer. write ( lines: data. classLines)
11211131
1122- // Struct helpers must be initialized AFTER classes are defined (to allow _exports access)
1132+ // Struct and enum helpers must be initialized AFTER classes are defined (to allow _exports access)
11231133 printer. write ( contentsOf: structHelperAssignments ( ) )
1134+ printer. write ( contentsOf: enumHelperAssignments ( ) )
11241135 let namespaceInitCode = namespaceBuilder. buildNamespaceInitialization (
11251136 exportedSkeletons: exportedSkeletons
11261137 )
@@ -1151,7 +1162,7 @@ public struct BridgeJSLink {
11511162 for skeleton in skeletons. compactMap ( \. exported) {
11521163 for enumDef in skeleton. enums where enumDef. enumType == . associatedValue {
11531164 printer. write (
1154- " const \( enumDef. name) Helpers = __bjs_create \( enumDef. valuesName) Helpers()( \( JSGlueVariableScope . reservedTmpParamInts) , \( JSGlueVariableScope . reservedTmpParamF32s) , \( JSGlueVariableScope . reservedTmpParamF64s) , \( JSGlueVariableScope . reservedTextEncoder) , \( JSGlueVariableScope . reservedSwift) ); "
1165+ " const \( enumDef. name) Helpers = __bjs_create \( enumDef. valuesName) Helpers()( \( JSGlueVariableScope . reservedTmpParamInts) , \( JSGlueVariableScope . reservedTmpParamF32s) , \( JSGlueVariableScope . reservedTmpParamF64s) , \( JSGlueVariableScope . reservedTmpParamPointers ) , \( JSGlueVariableScope . reservedTmpRetPointers ) , \( JSGlueVariableScope . reservedTextEncoder) , \( JSGlueVariableScope . reservedSwift) , \( JSGlueVariableScope . reservedStructHelpers ) , \( JSGlueVariableScope . reservedEnumHelpers ) ); "
11551166 )
11561167 printer. write ( " \( JSGlueVariableScope . reservedEnumHelpers) . \( enumDef. name) = \( enumDef. name) Helpers; " )
11571168 printer. nextLine ( )
@@ -1616,7 +1627,7 @@ public struct BridgeJSLink {
16161627 _ = fragment. printCode ( [ enumValuesName] , scope, printer, cleanup)
16171628 jsTopLevelLines. append ( contentsOf: printer. lines)
16181629 case . associatedValue:
1619- let fragment = IntrinsicJSFragment . associatedValueEnumHelper ( enumDefinition: enumDefinition)
1630+ let fragment = IntrinsicJSFragment . associatedValueEnumValues ( enumDefinition: enumDefinition)
16201631 _ = fragment. printCode ( [ enumValuesName] , scope, printer, cleanup)
16211632 jsTopLevelLines. append ( contentsOf: printer. lines)
16221633 case . namespace:
0 commit comments