@@ -245,7 +245,7 @@ public struct BridgeJSLink {
245245 " let \( JSGlueVariableScope . reservedStorageToReturnOptionalFloat) ; " ,
246246 " let \( JSGlueVariableScope . reservedStorageToReturnOptionalDouble) ; " ,
247247 " let \( JSGlueVariableScope . reservedStorageToReturnOptionalHeapObject) ; " ,
248- " let \( JSGlueVariableScope . reservedTmpRetTag) ; " ,
248+ " let \( JSGlueVariableScope . reservedTmpRetTag) = [] ;" ,
249249 " let \( JSGlueVariableScope . reservedTmpRetStrings) = []; " ,
250250 " let \( JSGlueVariableScope . reservedTmpRetInts) = []; " ,
251251 " let \( JSGlueVariableScope . reservedTmpRetF32s) = []; " ,
@@ -387,7 +387,7 @@ public struct BridgeJSLink {
387387 printer. write ( " } " )
388388 printer. write ( " bjs[ \" swift_js_push_tag \" ] = function(tag) { " )
389389 printer. indent {
390- printer. write ( " \( JSGlueVariableScope . reservedTmpRetTag) = tag;" )
390+ printer. write ( " \( JSGlueVariableScope . reservedTmpRetTag) .push( tag) ;" )
391391 }
392392 printer. write ( " } " )
393393 printer. write ( " bjs[ \" swift_js_push_i32 \" ] = function(v) { " )
@@ -1051,6 +1051,18 @@ public struct BridgeJSLink {
10511051 _ = fragment. printCode ( [ structDef. name] , structScope, structPrinter, structCleanup)
10521052 printer. write ( lines: structPrinter. lines)
10531053 }
1054+
1055+ let allAssocEnums = exportedSkeletons. flatMap {
1056+ $0. enums. filter { $0. enumType == . associatedValue }
1057+ }
1058+ for enumDef in allAssocEnums {
1059+ let enumPrinter = CodeFragmentPrinter ( )
1060+ let enumScope = JSGlueVariableScope ( )
1061+ let enumCleanup = CodeFragmentPrinter ( )
1062+ let fragment = IntrinsicJSFragment . associatedValueEnumHelperFactory ( enumDefinition: enumDef)
1063+ _ = fragment. printCode ( [ enumDef. valuesName] , enumScope, enumPrinter, enumCleanup)
1064+ printer. write ( lines: enumPrinter. lines)
1065+ }
10541066 printer. nextLine ( )
10551067 printer. write ( contentsOf: generateAddImports ( needsImportsObject: data. needsImportsObject) )
10561068 }
@@ -1079,8 +1091,6 @@ public struct BridgeJSLink {
10791091 " \( JSGlueVariableScope . reservedMemory) = \( JSGlueVariableScope . reservedInstance) .exports.memory; " ,
10801092 ] )
10811093 printer. nextLine ( )
1082- // Enum helpers section
1083- printer. write ( contentsOf: enumHelperAssignments ( ) )
10841094 // Error handling
10851095 printer. write ( " \( JSGlueVariableScope . reservedSetException) = (error) => { " )
10861096 printer. indent {
@@ -1104,8 +1114,9 @@ public struct BridgeJSLink {
11041114
11051115 printer. write ( lines: data. classLines)
11061116
1107- // Struct helpers must be initialized AFTER classes are defined (to allow _exports access)
1117+ // Struct and enum helpers must be initialized AFTER classes are defined (to allow _exports access)
11081118 printer. write ( contentsOf: structHelperAssignments ( ) )
1119+ printer. write ( contentsOf: enumHelperAssignments ( ) )
11091120 let namespaceInitCode = namespaceBuilder. buildNamespaceInitialization (
11101121 exportedSkeletons: exportedSkeletons
11111122 )
@@ -1140,7 +1151,7 @@ public struct BridgeJSLink {
11401151 for skeleton in skeletons. compactMap ( \. exported) {
11411152 for enumDef in skeleton. enums where enumDef. enumType == . associatedValue {
11421153 printer. write (
1143- " const \( enumDef. name) Helpers = __bjs_create \( enumDef. valuesName) Helpers()( \( JSGlueVariableScope . reservedTmpParamInts) , \( JSGlueVariableScope . reservedTmpParamF32s) , \( JSGlueVariableScope . reservedTmpParamF64s) , \( JSGlueVariableScope . reservedTextEncoder) , \( JSGlueVariableScope . reservedSwift) ); "
1154+ " 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 ) ); "
11441155 )
11451156 printer. write ( " \( JSGlueVariableScope . reservedEnumHelpers) . \( enumDef. name) = \( enumDef. name) Helpers; " )
11461157 printer. nextLine ( )
@@ -1601,7 +1612,7 @@ public struct BridgeJSLink {
16011612 _ = fragment. printCode ( [ enumValuesName] , scope, printer, cleanup)
16021613 jsTopLevelLines. append ( contentsOf: printer. lines)
16031614 case . associatedValue:
1604- let fragment = IntrinsicJSFragment . associatedValueEnumHelper ( enumDefinition: enumDefinition)
1615+ let fragment = IntrinsicJSFragment . associatedValueEnumValues ( enumDefinition: enumDefinition)
16051616 _ = fragment. printCode ( [ enumValuesName] , scope, printer, cleanup)
16061617 jsTopLevelLines. append ( contentsOf: printer. lines)
16071618 case . namespace:
0 commit comments