Skip to content

Commit 552102a

Browse files
BridgeJS: Add support for JSValue
1 parent 89ed56e commit 552102a

File tree

21 files changed

+2284
-49
lines changed

21 files changed

+2284
-49
lines changed

Plugins/BridgeJS/Sources/BridgeJSCore/ExportSwift.swift

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,7 @@ struct StackCodegen {
794794
func liftExpression(for type: BridgeType) -> ExprSyntax {
795795
switch type {
796796
case .string, .int, .uint, .bool, .float, .double,
797-
.jsObject(nil), .swiftStruct, .swiftHeapObject:
797+
.jsObject(nil), .jsValue, .swiftStruct, .swiftHeapObject:
798798
return "\(raw: type.swiftType).bridgeJSLiftParameter()"
799799
case .jsObject(let className?):
800800
return "\(raw: className)(unsafelyWrapping: JSObject.bridgeJSLiftParameter())"
@@ -831,7 +831,7 @@ struct StackCodegen {
831831

832832
func liftArrayExpression(elementType: BridgeType) -> ExprSyntax {
833833
switch elementType {
834-
case .int, .uint, .float, .double, .string, .bool,
834+
case .int, .uint, .float, .double, .string, .bool, .jsValue,
835835
.jsObject(nil), .swiftStruct, .caseEnum, .swiftHeapObject,
836836
.unsafePointer, .rawValueEnum, .associatedValueEnum:
837837
return "[\(raw: elementType.swiftType)].bridgeJSLiftParameter()"
@@ -865,7 +865,7 @@ struct StackCodegen {
865865

866866
private func liftOptionalExpression(wrappedType: BridgeType) -> ExprSyntax {
867867
switch wrappedType {
868-
case .string, .int, .uint, .bool, .float, .double, .jsObject(nil),
868+
case .string, .int, .uint, .bool, .float, .double, .jsObject(nil), .jsValue,
869869
.swiftStruct, .swiftHeapObject, .caseEnum, .associatedValueEnum, .rawValueEnum:
870870
return "Optional<\(raw: wrappedType.swiftType)>.bridgeJSLiftParameter()"
871871
case .jsObject(let className?):
@@ -900,7 +900,7 @@ struct StackCodegen {
900900
varPrefix: String
901901
) -> [CodeBlockItemSyntax] {
902902
switch type {
903-
case .string, .int, .uint, .bool, .float, .double:
903+
case .string, .int, .uint, .bool, .float, .double, .jsValue:
904904
return ["\(raw: accessor).bridgeJSLowerStackReturn()"]
905905
case .jsObject(nil):
906906
return ["\(raw: accessor).bridgeJSLowerStackReturn()"]
@@ -930,7 +930,7 @@ struct StackCodegen {
930930
varPrefix: String
931931
) -> [CodeBlockItemSyntax] {
932932
switch elementType {
933-
case .int, .uint, .float, .double, .string, .bool,
933+
case .int, .uint, .float, .double, .string, .bool, .jsValue,
934934
.jsObject(nil), .swiftStruct, .caseEnum, .swiftHeapObject,
935935
.unsafePointer, .rawValueEnum, .associatedValueEnum:
936936
return ["\(raw: accessor).bridgeJSLowerReturn()"]
@@ -1001,7 +1001,7 @@ struct StackCodegen {
10011001
varPrefix: String
10021002
) -> [CodeBlockItemSyntax] {
10031003
switch wrappedType {
1004-
case .string, .int, .uint, .bool, .float, .double:
1004+
case .string, .int, .uint, .bool, .float, .double, .jsValue:
10051005
return ["\(raw: unwrappedVar).bridgeJSLowerStackReturn()"]
10061006
case .caseEnum, .rawValueEnum:
10071007
// Enums conform to _BridgedSwiftStackType
@@ -1590,6 +1590,7 @@ extension BridgeType {
15901590
case .float: return "Float"
15911591
case .double: return "Double"
15921592
case .string: return "String"
1593+
case .jsValue: return "JSValue"
15931594
case .jsObject(nil): return "JSObject"
15941595
case .jsObject(let name?): return name
15951596
case .swiftHeapObject(let name): return name
@@ -1619,6 +1620,7 @@ extension BridgeType {
16191620
static let double = LiftingIntrinsicInfo(parameters: [("value", .f64)])
16201621
static let string = LiftingIntrinsicInfo(parameters: [("bytes", .i32), ("length", .i32)])
16211622
static let jsObject = LiftingIntrinsicInfo(parameters: [("value", .i32)])
1623+
static let jsValue = LiftingIntrinsicInfo(parameters: [("kind", .i32), ("payload1", .i32), ("payload2", .f64)])
16221624
static let swiftHeapObject = LiftingIntrinsicInfo(parameters: [("value", .pointer)])
16231625
static let unsafePointer = LiftingIntrinsicInfo(parameters: [("pointer", .pointer)])
16241626
static let void = LiftingIntrinsicInfo(parameters: [])
@@ -1636,6 +1638,7 @@ extension BridgeType {
16361638
case .double: return .double
16371639
case .string: return .string
16381640
case .jsObject: return .jsObject
1641+
case .jsValue: return .jsValue
16391642
case .swiftHeapObject: return .swiftHeapObject
16401643
case .unsafePointer: return .unsafePointer
16411644
case .swiftProtocol: return .jsObject
@@ -1669,6 +1672,7 @@ extension BridgeType {
16691672
static let double = LoweringIntrinsicInfo(returnType: .f64)
16701673
static let string = LoweringIntrinsicInfo(returnType: nil)
16711674
static let jsObject = LoweringIntrinsicInfo(returnType: .i32)
1675+
static let jsValue = LoweringIntrinsicInfo(returnType: nil)
16721676
static let swiftHeapObject = LoweringIntrinsicInfo(returnType: .pointer)
16731677
static let unsafePointer = LoweringIntrinsicInfo(returnType: .pointer)
16741678
static let void = LoweringIntrinsicInfo(returnType: nil)
@@ -1688,6 +1692,7 @@ extension BridgeType {
16881692
case .double: return .double
16891693
case .string: return .string
16901694
case .jsObject: return .jsObject
1695+
case .jsValue: return .jsValue
16911696
case .swiftHeapObject: return .swiftHeapObject
16921697
case .unsafePointer: return .unsafePointer
16931698
case .swiftProtocol: return .jsObject

Plugins/BridgeJS/Sources/BridgeJSCore/ImportTS.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -861,6 +861,11 @@ extension BridgeType {
861861
static let double = LoweringParameterInfo(loweredParameters: [("value", .f64)])
862862
static let string = LoweringParameterInfo(loweredParameters: [("value", .i32)])
863863
static let jsObject = LoweringParameterInfo(loweredParameters: [("value", .i32)])
864+
static let jsValue = LoweringParameterInfo(loweredParameters: [
865+
("kind", .i32),
866+
("payload1", .i32),
867+
("payload2", .f64),
868+
])
864869
static let void = LoweringParameterInfo(loweredParameters: [])
865870
}
866871

@@ -872,6 +877,7 @@ extension BridgeType {
872877
case .double: return .double
873878
case .string: return .string
874879
case .jsObject: return .jsObject
880+
case .jsValue: return .jsValue
875881
case .void: return .void
876882
case .closure:
877883
// Swift closure is boxed and passed to JS as a pointer.
@@ -953,6 +959,7 @@ extension BridgeType {
953959
static let double = LiftingReturnInfo(valueToLift: .f64)
954960
static let string = LiftingReturnInfo(valueToLift: .i32)
955961
static let jsObject = LiftingReturnInfo(valueToLift: .i32)
962+
static let jsValue = LiftingReturnInfo(valueToLift: nil)
956963
static let void = LiftingReturnInfo(valueToLift: nil)
957964
}
958965

@@ -966,6 +973,7 @@ extension BridgeType {
966973
case .double: return .double
967974
case .string: return .string
968975
case .jsObject: return .jsObject
976+
case .jsValue: return .jsValue
969977
case .void: return .void
970978
case .closure:
971979
// JS returns a callback ID for closures, which Swift lifts to a typed closure.

Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3399,6 +3399,8 @@ extension BridgeType {
33993399
return "boolean"
34003400
case .jsObject(let name):
34013401
return name ?? "any"
3402+
case .jsValue:
3403+
return "any"
34023404
case .swiftHeapObject(let name):
34033405
return name
34043406
case .unsafePointer:

0 commit comments

Comments
 (0)