@@ -251,7 +251,6 @@ public struct BridgeJSLink {
251251 " let \( JSGlueVariableScope . reservedF32Stack) = []; " ,
252252 " let \( JSGlueVariableScope . reservedF64Stack) = []; " ,
253253 " let \( JSGlueVariableScope . reservedPointerStack) = []; " ,
254- " let \( JSGlueVariableScope . reservedTmpStructCleanups) = []; " ,
255254 " const \( JSGlueVariableScope . reservedEnumHelpers) = {}; " ,
256255 " const \( JSGlueVariableScope . reservedStructHelpers) = {}; " ,
257256 " " ,
@@ -297,6 +296,9 @@ public struct BridgeJSLink {
297296 printer. write (
298297 " const source = \( JSGlueVariableScope . reservedSwift) . \( JSGlueVariableScope . reservedMemory) .getObject(sourceId); "
299298 )
299+ printer. write (
300+ " \( JSGlueVariableScope . reservedSwift) . \( JSGlueVariableScope . reservedMemory) .release(sourceId); "
301+ )
300302 printer. write (
301303 " const bytes = new Uint8Array( \( JSGlueVariableScope . reservedMemory) .buffer, bytesPtr); "
302304 )
@@ -390,38 +392,13 @@ public struct BridgeJSLink {
390392 printer. write ( " return \( JSGlueVariableScope . reservedPointerStack) .pop(); " )
391393 }
392394 printer. write ( " } " )
393- printer. write ( " bjs[ \" swift_js_struct_cleanup \" ] = function(cleanupId) { " )
394- printer. indent {
395- printer. write ( " if (cleanupId === 0) { return; } " )
396- printer. write ( " const index = (cleanupId | 0) - 1; " )
397- printer. write ( " const cleanup = \( JSGlueVariableScope . reservedTmpStructCleanups) [index]; " )
398- printer. write ( " \( JSGlueVariableScope . reservedTmpStructCleanups) [index] = null; " )
399- printer. write ( " if (cleanup) { cleanup(); } " )
400- printer. write (
401- " while ( \( JSGlueVariableScope . reservedTmpStructCleanups) .length > 0 && \( JSGlueVariableScope . reservedTmpStructCleanups) [ \( JSGlueVariableScope . reservedTmpStructCleanups) .length - 1] == null) { "
402- )
403- printer. indent {
404- printer. write ( " \( JSGlueVariableScope . reservedTmpStructCleanups) .pop(); " )
405- }
406- printer. write ( " } " )
407- }
408- printer. write ( " } " )
409-
410395 if !allStructs. isEmpty {
411396 for structDef in allStructs {
412397 printer. write ( " bjs[ \" swift_js_struct_lower_ \( structDef. name) \" ] = function(objectId) { " )
413398 printer. indent {
414399 printer. write (
415- " const { cleanup: cleanup } = \( JSGlueVariableScope . reservedStructHelpers) . \( structDef. name) .lower( \( JSGlueVariableScope . reservedSwift) .memory.getObject(objectId)); "
400+ " \( JSGlueVariableScope . reservedStructHelpers) . \( structDef. name) .lower( \( JSGlueVariableScope . reservedSwift) .memory.getObject(objectId)); "
416401 )
417- printer. write ( " if (cleanup) { " )
418- printer. indent {
419- printer. write (
420- " return \( JSGlueVariableScope . reservedTmpStructCleanups) .push(cleanup); "
421- )
422- }
423- printer. write ( " } " )
424- printer. write ( " return 0; " )
425402 }
426403 printer. write ( " } " )
427404
@@ -943,14 +920,12 @@ public struct BridgeJSLink {
943920 for structDef in allStructs {
944921 let structPrinter = CodeFragmentPrinter ( )
945922 let structScope = JSGlueVariableScope ( intrinsicRegistry: intrinsicRegistry)
946- let structCleanup = CodeFragmentPrinter ( )
947923 let fragment = IntrinsicJSFragment . structHelper ( structDefinition: structDef, allStructs: allStructs)
948924 _ = try fragment. printCode (
949925 [ structDef. name] ,
950926 IntrinsicJSFragment . PrintCodeContext (
951927 scope: structScope,
952- printer: structPrinter,
953- cleanupCode: structCleanup
928+ printer: structPrinter
954929 )
955930 )
956931 bodyPrinter. write ( lines: structPrinter. lines)
@@ -962,14 +937,12 @@ public struct BridgeJSLink {
962937 for enumDef in allAssocEnums {
963938 let enumPrinter = CodeFragmentPrinter ( )
964939 let enumScope = JSGlueVariableScope ( intrinsicRegistry: intrinsicRegistry)
965- let enumCleanup = CodeFragmentPrinter ( )
966940 let fragment = IntrinsicJSFragment . associatedValueEnumHelperFactory ( enumDefinition: enumDef)
967941 _ = try fragment. printCode (
968942 [ enumDef. valuesName] ,
969943 IntrinsicJSFragment . PrintCodeContext (
970944 scope: enumScope,
971- printer: enumPrinter,
972- cleanupCode: enumCleanup
945+ printer: enumPrinter
973946 )
974947 )
975948 bodyPrinter. write ( lines: enumPrinter. lines)
@@ -1214,7 +1187,6 @@ public struct BridgeJSLink {
12141187
12151188 class ExportedThunkBuilder {
12161189 var body : CodeFragmentPrinter
1217- var cleanupCode : CodeFragmentPrinter
12181190 var parameterForwardings : [ String ] = [ ]
12191191 let effects : Effects
12201192 let scope : JSGlueVariableScope
@@ -1224,11 +1196,9 @@ public struct BridgeJSLink {
12241196 self . effects = effects
12251197 self . scope = JSGlueVariableScope ( intrinsicRegistry: intrinsicRegistry)
12261198 self . body = CodeFragmentPrinter ( )
1227- self . cleanupCode = CodeFragmentPrinter ( )
12281199 self . context = IntrinsicJSFragment . PrintCodeContext (
12291200 scope: scope,
12301201 printer: body,
1231- cleanupCode: cleanupCode,
12321202 hasDirectAccessToSwiftClass: hasDirectAccessToSwiftClass
12331203 )
12341204 }
@@ -1302,7 +1272,6 @@ public struct BridgeJSLink {
13021272 /// Renders the thunk body (body code, cleanup, exception handling, and optional return) into a printer.
13031273 func renderFunctionBody( into printer: CodeFragmentPrinter , returnExpr: String ? ) {
13041274 printer. write ( contentsOf: body)
1305- printer. write ( contentsOf: cleanupCode)
13061275 printer. write ( lines: checkExceptionLines ( ) )
13071276 if let returnExpr = returnExpr {
13081277 printer. write ( " return \( returnExpr) ; " )
@@ -1528,8 +1497,7 @@ public struct BridgeJSLink {
15281497 let printer = CodeFragmentPrinter ( )
15291498 let context = IntrinsicJSFragment . PrintCodeContext (
15301499 scope: scope,
1531- printer: printer,
1532- cleanupCode: CodeFragmentPrinter ( )
1500+ printer: printer
15331501 )
15341502 let enumValuesName = enumDefinition. valuesName
15351503
@@ -2114,7 +2082,6 @@ extension BridgeJSLink {
21142082 class ImportedThunkBuilder {
21152083 let body : CodeFragmentPrinter
21162084 let scope : JSGlueVariableScope
2117- let cleanupCode : CodeFragmentPrinter
21182085 let context : BridgeContext
21192086 var parameterNames : [ String ] = [ ]
21202087 var parameterForwardings : [ String ] = [ ]
@@ -2123,12 +2090,10 @@ extension BridgeJSLink {
21232090 init ( context: BridgeContext = . importTS, intrinsicRegistry: JSIntrinsicRegistry ) {
21242091 self . body = CodeFragmentPrinter ( )
21252092 self . scope = JSGlueVariableScope ( intrinsicRegistry: intrinsicRegistry)
2126- self . cleanupCode = CodeFragmentPrinter ( )
21272093 self . context = context
21282094 self . printContext = IntrinsicJSFragment . PrintCodeContext (
21292095 scope: scope,
2130- printer: body,
2131- cleanupCode: cleanupCode
2096+ printer: body
21322097 )
21332098 }
21342099
@@ -2667,7 +2632,6 @@ extension BridgeJSLink {
26672632 getterPrinter. write ( " get \( property. name) () { " )
26682633 getterPrinter. indent {
26692634 getterPrinter. write ( contentsOf: getterThunkBuilder. body)
2670- getterPrinter. write ( contentsOf: getterThunkBuilder. cleanupCode)
26712635 getterPrinter. write ( lines: getterThunkBuilder. checkExceptionLines ( ) )
26722636 if let returnExpr = getterReturnExpr {
26732637 getterPrinter. write ( " return \( returnExpr) ; " )
@@ -2695,7 +2659,6 @@ extension BridgeJSLink {
26952659 setterPrinter. write ( " set \( property. name) (value) { " )
26962660 setterPrinter. indent {
26972661 setterPrinter. write ( contentsOf: setterThunkBuilder. body)
2698- setterPrinter. write ( contentsOf: setterThunkBuilder. cleanupCode)
26992662 setterPrinter. write ( lines: setterThunkBuilder. checkExceptionLines ( ) )
27002663 }
27012664 setterPrinter. write ( " }, " )
0 commit comments