@@ -643,10 +643,7 @@ struct IntrinsicJSFragment: Sendable {
643643 )
644644 }
645645
646- static func optionalLowerReturn(
647- wrappedType: BridgeType ,
648- presenceCheck: ( @Sendable ( String ) -> String ) ? = nil
649- ) throws -> IntrinsicJSFragment {
646+ static func optionalLowerReturn( wrappedType: BridgeType , kind: JSOptionalKind ) throws -> IntrinsicJSFragment {
650647 switch wrappedType {
651648 case . void, . nullable, . namespaceEnum, . closure:
652649 throw BridgeJSLinkError ( message: " Unsupported optional wrapped type for protocol export: \( wrappedType) " )
@@ -658,7 +655,7 @@ struct IntrinsicJSFragment: Sendable {
658655 printCode: { arguments, scope, printer, cleanupCode in
659656 let value = arguments [ 0 ]
660657 let isSomeVar = scope. variable ( " isSome " )
661- let presenceExpr = presenceCheck ? ( value) ?? " \( value) != null "
658+ let presenceExpr = kind . presenceCheck ( value: value)
662659 printer. write ( " const \( isSomeVar) = \( presenceExpr) ; " )
663660
664661 switch wrappedType {
@@ -1599,10 +1596,7 @@ struct IntrinsicJSFragment: Sendable {
15991596 case . swiftProtocol: return . jsObjectLowerReturn
16001597 case . void: return . void
16011598 case . nullable( let wrappedType, let kind) :
1602- return try . optionalLowerReturn(
1603- wrappedType: wrappedType,
1604- presenceCheck: { value in kind. presenceCheck ( value: value) }
1605- )
1599+ return try . optionalLowerReturn( wrappedType: wrappedType, kind: kind)
16061600 case . caseEnum: return . identity
16071601 case . rawValueEnum( _, let rawType) :
16081602 switch rawType {
@@ -2493,7 +2487,7 @@ struct IntrinsicJSFragment: Sendable {
24932487 case . nullable( let wrappedType, let kind) :
24942488 return try optionalElementLowerFragment (
24952489 wrappedType: wrappedType,
2496- presenceCheck : { kind. presenceCheck ( value : $0 ) }
2490+ kind: kind
24972491 )
24982492 case . swiftProtocol:
24992493 // Same as jsObject but no cleanup — Swift's AnyProtocol wrapper releases via deinit
@@ -2556,15 +2550,15 @@ struct IntrinsicJSFragment: Sendable {
25562550
25572551 private static func optionalElementLowerFragment(
25582552 wrappedType: BridgeType ,
2559- presenceCheck : ( @ Sendable ( String ) -> String ) ? = nil
2553+ kind : JSOptionalKind
25602554 ) throws -> IntrinsicJSFragment {
25612555 return IntrinsicJSFragment (
25622556 parameters: [ " value " ] ,
25632557 printCode: { arguments, scope, printer, cleanup in
25642558 let value = arguments [ 0 ]
25652559 let isSomeVar = scope. variable ( " isSome " )
25662560
2567- let presenceExpr = presenceCheck ? ( value) ?? " \( value) != null "
2561+ let presenceExpr = kind . presenceCheck ( value: value)
25682562 printer. write ( " const \( isSomeVar) = \( presenceExpr) ? 1 : 0; " )
25692563 // Cleanup is written inside the if block so retained id is in scope
25702564 let localCleanupWriter = CodeFragmentPrinter ( )
0 commit comments