@@ -149,6 +149,15 @@ struct IntrinsicJSFragment: Sendable {
149149 }
150150 )
151151
152+ /// Convert signed Int32 to unsigned for UInt values
153+ static let uintLiftReturn = IntrinsicJSFragment (
154+ parameters: [ " value " ] ,
155+ printCode: { arguments, scope, printer, cleanupCode in
156+ return [ " \( arguments [ 0 ] ) >>> 0 " ]
157+ }
158+ )
159+ static let uintLiftParameter = uintLiftReturn
160+
152161 static let stringLowerParameter = IntrinsicJSFragment (
153162 parameters: [ " value " ] ,
154163 printCode: { arguments, scope, printer, cleanupCode in
@@ -519,7 +528,7 @@ struct IntrinsicJSFragment: Sendable {
519528 case . bool:
520529 printer. write ( " const \( resultVar) = \( JSGlueVariableScope . reservedStorageToReturnOptionalBool) ; " )
521530 printer. write ( " \( JSGlueVariableScope . reservedStorageToReturnOptionalBool) = undefined; " )
522- case . int:
531+ case . int, . uint :
523532 printer. write ( " const \( resultVar) = \( JSGlueVariableScope . reservedStorageToReturnOptionalInt) ; " )
524533 printer. write ( " \( JSGlueVariableScope . reservedStorageToReturnOptionalInt) = undefined; " )
525534 case . float:
@@ -651,7 +660,7 @@ struct IntrinsicJSFragment: Sendable {
651660 printer. write (
652661 " bjs[ \" swift_js_return_optional_bool \" ]( \( isSomeVar) ? 1 : 0, \( isSomeVar) ? ( \( value) ? 1 : 0) : 0); "
653662 )
654- case . int:
663+ case . int, . uint :
655664 printer. write (
656665 " bjs[ \" swift_js_return_optional_int \" ]( \( isSomeVar) ? 1 : 0, \( isSomeVar) ? ( \( value) | 0) : 0); "
657666 )
@@ -937,7 +946,7 @@ struct IntrinsicJSFragment: Sendable {
937946 )
938947 printer. write ( " \( JSGlueVariableScope . reservedSwift) .memory.release( \( value) ); " )
939948 printer. write ( " \( targetVar) = String( \( objectLabel) ); " )
940- case . int:
949+ case . int, . uint :
941950 printer. write ( " \( targetVar) = \( value) | 0; " )
942951 case . bool:
943952 printer. write ( " \( targetVar) = \( value) !== 0; " )
@@ -1121,7 +1130,7 @@ struct IntrinsicJSFragment: Sendable {
11211130 case . string:
11221131 printer. write ( " \( JSGlueVariableScope . reservedStorageToReturnString) = \( result) ; " )
11231132 printer. write ( " return; " )
1124- case . int:
1133+ case . int, . uint :
11251134 printer. write ( " \( JSGlueVariableScope . reservedStorageToReturnOptionalInt) = \( result) ; " )
11261135 printer. write ( " return; " )
11271136 case . bool:
@@ -1370,7 +1379,7 @@ struct IntrinsicJSFragment: Sendable {
13701379 /// Returns a fragment that lowers a JS value to Wasm core values for parameters
13711380 static func lowerParameter( type: BridgeType ) throws -> IntrinsicJSFragment {
13721381 switch type {
1373- case . int, . float, . double, . bool, . unsafePointer: return . identity
1382+ case . int, . uint , . float, . double, . bool, . unsafePointer: return . identity
13741383 case . string: return . stringLowerParameter
13751384 case . jsObject: return . jsObjectLowerParameter
13761385 case . swiftHeapObject:
@@ -1414,6 +1423,7 @@ struct IntrinsicJSFragment: Sendable {
14141423 static func liftReturn( type: BridgeType ) throws -> IntrinsicJSFragment {
14151424 switch type {
14161425 case . int, . float, . double: return . identity
1426+ case . uint: return . uintLiftReturn
14171427 case . bool: return . boolLiftReturn
14181428 case . string: return . stringLiftReturn
14191429 case . jsObject: return . jsObjectLiftReturn
@@ -1460,6 +1470,7 @@ struct IntrinsicJSFragment: Sendable {
14601470 static func liftParameter( type: BridgeType , context: BridgeContext = . importTS) throws -> IntrinsicJSFragment {
14611471 switch type {
14621472 case . int, . float, . double: return . identity
1473+ case . uint: return . uintLiftParameter
14631474 case . bool: return . boolLiftParameter
14641475 case . string: return . stringLiftParameter
14651476 case . jsObject: return . jsObjectLiftParameter
@@ -1560,7 +1571,7 @@ struct IntrinsicJSFragment: Sendable {
15601571 /// Returns a fragment that lowers a JS value to Wasm core values for return values
15611572 static func lowerReturn( type: BridgeType , context: BridgeContext = . importTS) throws -> IntrinsicJSFragment {
15621573 switch type {
1563- case . int, . float, . double: return . identity
1574+ case . int, . uint , . float, . double: return . identity
15641575 case . bool: return . boolLowerReturn
15651576 case . string: return . stringLowerReturn
15661577 case . jsObject: return . jsObjectLowerReturn
@@ -1909,7 +1920,7 @@ struct IntrinsicJSFragment: Sendable {
19091920 return [ ]
19101921 }
19111922 )
1912- case . int:
1923+ case . int, . uint :
19131924 return IntrinsicJSFragment (
19141925 parameters: [ " value " ] ,
19151926 printCode: { arguments, scope, printer, cleanup in
@@ -1967,7 +1978,7 @@ struct IntrinsicJSFragment: Sendable {
19671978 cleanup. write ( " \( JSGlueVariableScope . reservedSwift) .memory.release( \( idVar) ); " )
19681979 }
19691980 cleanup. write ( " } " )
1970- case . int:
1981+ case . int, . uint :
19711982 printer. write (
19721983 " \( JSGlueVariableScope . reservedTmpParamInts) .push( \( isSomeVar) ? ( \( value) | 0) : 0); "
19731984 )
@@ -2024,7 +2035,7 @@ struct IntrinsicJSFragment: Sendable {
20242035 return [ bVar]
20252036 }
20262037 )
2027- case . int:
2038+ case . int, . uint :
20282039 return IntrinsicJSFragment (
20292040 parameters: [ ] ,
20302041 printCode: { arguments, scope, printer, cleanup in
@@ -2214,7 +2225,7 @@ struct IntrinsicJSFragment: Sendable {
22142225 return [ bVar]
22152226 }
22162227 )
2217- case . int:
2228+ case . int, . uint :
22182229 return IntrinsicJSFragment (
22192230 parameters: [ ] ,
22202231 printCode: { arguments, scope, printer, cleanup in
@@ -2363,7 +2374,7 @@ struct IntrinsicJSFragment: Sendable {
23632374 return [ ]
23642375 }
23652376 )
2366- case . int:
2377+ case . int, . uint :
23672378 return IntrinsicJSFragment (
23682379 parameters: [ " value " ] ,
23692380 printCode: { arguments, scope, printer, cleanup in
@@ -2779,7 +2790,7 @@ struct IntrinsicJSFragment: Sendable {
27792790 return [ ]
27802791 }
27812792 )
2782- case . int:
2793+ case . int, . uint :
27832794 return IntrinsicJSFragment (
27842795 parameters: [ " value " ] ,
27852796 printCode: { arguments, scope, printer, cleanup in
@@ -3009,7 +3020,7 @@ struct IntrinsicJSFragment: Sendable {
30093020 } else {
30103021 // Handle optional primitive types using helper
30113022 switch wrappedType {
3012- case . int:
3023+ case . int, . uint :
30133024 pushOptionalPrimitive (
30143025 value: value,
30153026 isSomeVar: isSomeVar,
@@ -3260,7 +3271,7 @@ struct IntrinsicJSFragment: Sendable {
32603271 return [ bVar]
32613272 }
32623273 )
3263- case . int:
3274+ case . int, . uint :
32643275 return IntrinsicJSFragment (
32653276 parameters: [ ] ,
32663277 printCode: { arguments, scope, printer, cleanup in
0 commit comments