Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Plugins/BridgeJS/Sources/BridgeJSCore/ExportSwift.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1346,7 +1346,7 @@ struct ProtocolCodegen {
let builder = ImportTS.CallJSEmission(
moduleName: moduleName,
abiName: "_extern_\(method.name)",
context: .exportSwiftProtocol
context: .exportSwift
)
try builder.lowerParameter(param: Parameter(label: nil, name: "jsObject", type: .jsObject(nil)))
for param in method.parameters {
Expand All @@ -1359,7 +1359,7 @@ struct ProtocolCodegen {
let signature = SwiftSignatureBuilder.buildFunctionSignature(
parameters: method.parameters,
returnType: method.returnType,
effects: method.effects
effects: nil
)

// Build extern declaration using helper function
Expand Down
32 changes: 16 additions & 16 deletions Plugins/BridgeJS/Sources/BridgeJSCore/ImportTS.swift
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,8 @@ public struct ImportTS {
body.append("let ret = \(raw: callExpr)")
}

// Add exception check for contexts that call INTO JavaScript
if context == .importTS || context == .exportSwiftProtocol {
// Add exception check for ImportTS context
if context == .importTS {
body.append("if let error = _swift_js_take_exception() { throw error }")
}
}
Expand Down Expand Up @@ -887,7 +887,7 @@ extension BridgeType {
Swift classes can only be used in @JS protocols where Swift owns the instance.
"""
)
case .exportSwift, .exportSwiftProtocol:
case .exportSwift:
return LoweringParameterInfo(loweredParameters: [("pointer", .pointer)])
}
case .swiftProtocol:
Expand All @@ -896,30 +896,30 @@ extension BridgeType {
switch context {
case .importTS:
throw BridgeJSCoreError("Enum types are not yet supported in TypeScript imports")
case .exportSwift, .exportSwiftProtocol:
case .exportSwift:
return LoweringParameterInfo(loweredParameters: [("value", .i32)])
}
case .rawValueEnum(_, let rawType):
switch context {
case .importTS:
return LoweringParameterInfo(loweredParameters: [("value", rawType.wasmCoreType ?? .i32)])
case .exportSwift, .exportSwiftProtocol:
case .exportSwift:
// For protocol export we return .i32 for String raw value type instead of nil
return LoweringParameterInfo(loweredParameters: [("value", rawType.wasmCoreType ?? .i32)])
}
case .associatedValueEnum:
switch context {
case .importTS:
throw BridgeJSCoreError("Enum types are not yet supported in TypeScript imports")
case .exportSwift, .exportSwiftProtocol:
case .exportSwift:
return LoweringParameterInfo(loweredParameters: [("caseId", .i32)])
}
case .swiftStruct:
switch context {
case .importTS:
// Swift structs are bridged as JS objects (object IDs) in imported signatures.
return LoweringParameterInfo(loweredParameters: [("objectId", .i32)])
case .exportSwift, .exportSwiftProtocol:
case .exportSwift:
return LoweringParameterInfo(loweredParameters: [])
}
case .namespaceEnum:
Expand All @@ -928,7 +928,7 @@ extension BridgeType {
switch context {
case .importTS:
throw BridgeJSCoreError("Optional types are not yet supported in TypeScript imports")
case .exportSwift, .exportSwiftProtocol:
case .exportSwift:
let wrappedInfo = try wrappedType.loweringParameterInfo(context: context)
var params = [("isSome", WasmCoreType.i32)]
params.append(contentsOf: wrappedInfo.loweredParameters)
Expand All @@ -938,7 +938,7 @@ extension BridgeType {
switch context {
case .importTS:
throw BridgeJSCoreError("Array types are not yet supported in TypeScript imports")
case .exportSwift, .exportSwiftProtocol:
case .exportSwift:
return LoweringParameterInfo(loweredParameters: [])
}
}
Expand Down Expand Up @@ -981,7 +981,7 @@ extension BridgeType {
JavaScript cannot create Swift heap objects.
"""
)
case .exportSwift, .exportSwiftProtocol:
case .exportSwift:
return LiftingReturnInfo(valueToLift: .pointer)
}
case .swiftProtocol:
Expand All @@ -990,30 +990,30 @@ extension BridgeType {
switch context {
case .importTS:
throw BridgeJSCoreError("Enum types are not yet supported in TypeScript imports")
case .exportSwift, .exportSwiftProtocol:
case .exportSwift:
return LiftingReturnInfo(valueToLift: .i32)
}
case .rawValueEnum(_, let rawType):
switch context {
case .importTS:
return LiftingReturnInfo(valueToLift: rawType.wasmCoreType ?? .i32)
case .exportSwift, .exportSwiftProtocol:
case .exportSwift:
// For protocol export we return .i32 for String raw value type instead of nil
return LiftingReturnInfo(valueToLift: rawType.wasmCoreType ?? .i32)
}
case .associatedValueEnum:
switch context {
case .importTS:
throw BridgeJSCoreError("Enum types are not yet supported in TypeScript imports")
case .exportSwift, .exportSwiftProtocol:
case .exportSwift:
return LiftingReturnInfo(valueToLift: .i32)
}
case .swiftStruct:
switch context {
case .importTS:
// Swift structs are bridged as JS objects (object IDs) in imported signatures.
return LiftingReturnInfo(valueToLift: .i32)
case .exportSwift, .exportSwiftProtocol:
case .exportSwift:
return LiftingReturnInfo(valueToLift: nil)
}
case .namespaceEnum:
Expand All @@ -1022,15 +1022,15 @@ extension BridgeType {
switch context {
case .importTS:
throw BridgeJSCoreError("Optional types are not yet supported in TypeScript imports")
case .exportSwift, .exportSwiftProtocol:
case .exportSwift:
let wrappedInfo = try wrappedType.liftingReturnInfo(context: context)
return LiftingReturnInfo(valueToLift: wrappedInfo.valueToLift)
}
case .array:
switch context {
case .importTS:
throw BridgeJSCoreError("Array types are not yet supported in TypeScript imports")
case .exportSwift, .exportSwiftProtocol:
case .exportSwift:
return LiftingReturnInfo(valueToLift: nil)
}
}
Expand Down
9 changes: 0 additions & 9 deletions Plugins/BridgeJS/Sources/BridgeJSCore/SwiftToSkeleton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1608,15 +1608,6 @@ private final class ExportSwiftAPICollector: SyntaxAnyVisitor {
return nil
}

guard effects.isThrows else {
diagnose(
node: node,
message: "@JS protocol methods must be throws.",
hint: "Declare the method as 'throws(JSException)'."
)
return nil
}

return ExportedFunction(
name: name,
abiName: abiName,
Expand Down
20 changes: 10 additions & 10 deletions Plugins/BridgeJS/Sources/BridgeJSLink/JSGlueGen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1477,7 +1477,7 @@ struct IntrinsicJSFragment: Sendable {
throw BridgeJSLinkError(
message: "swiftHeapObject '\(name)' can only be used in protocol exports, not in \(context)"
)
case .exportSwift, .exportSwiftProtocol:
case .exportSwift:
return .swiftHeapObjectLiftParameter(name)
}
case .swiftProtocol: return .jsObjectLiftParameter
Expand All @@ -1491,7 +1491,7 @@ struct IntrinsicJSFragment: Sendable {
throw BridgeJSLinkError(
message: "Optional types are not supported for imported JS functions: \(wrappedType)"
)
case .exportSwift, .exportSwiftProtocol:
case .exportSwift:
return try .optionalLiftParameter(wrappedType: wrappedType)
}
case .caseEnum: return .identity
Expand All @@ -1508,7 +1508,7 @@ struct IntrinsicJSFragment: Sendable {
message:
"Associated value enums are not supported to be passed as parameters to imported JS functions: \(fullName)"
)
case .exportSwift, .exportSwiftProtocol:
case .exportSwift:
let base = fullName.components(separatedBy: ".").last ?? fullName
return IntrinsicJSFragment(
parameters: ["caseId"],
Expand All @@ -1526,7 +1526,7 @@ struct IntrinsicJSFragment: Sendable {
switch context {
case .importTS:
return .jsObjectLiftRetainedObjectId
case .exportSwift, .exportSwiftProtocol:
case .exportSwift:
let base = fullName.components(separatedBy: ".").last ?? fullName
return IntrinsicJSFragment(
parameters: [],
Expand Down Expand Up @@ -1558,7 +1558,7 @@ struct IntrinsicJSFragment: Sendable {
throw BridgeJSLinkError(
message: "Arrays are not yet supported to be passed as parameters to imported JS functions"
)
case .exportSwift, .exportSwiftProtocol:
case .exportSwift:
return try arrayLift(elementType: elementType)
}
}
Expand All @@ -1578,7 +1578,7 @@ struct IntrinsicJSFragment: Sendable {
throw BridgeJSLinkError(
message: "swiftHeapObject '\(name)' can only be used in protocol exports, not in \(context)"
)
case .exportSwift, .exportSwiftProtocol:
case .exportSwift:
return .swiftHeapObjectLowerReturn
}
case .swiftProtocol: return .jsObjectLowerReturn
Expand All @@ -1589,7 +1589,7 @@ struct IntrinsicJSFragment: Sendable {
throw BridgeJSLinkError(
message: "Optional types are not supported for imported JS functions: \(wrappedType)"
)
case .exportSwift, .exportSwiftProtocol:
case .exportSwift:
return try .optionalLowerReturn(wrappedType: wrappedType)
}
case .caseEnum: return .identity
Expand All @@ -1606,15 +1606,15 @@ struct IntrinsicJSFragment: Sendable {
message:
"Associated value enums are not supported to be returned from imported JS functions: \(fullName)"
)
case .exportSwift, .exportSwiftProtocol:
case .exportSwift:
return associatedValueLowerReturn(fullName: fullName)
}
case .swiftStruct(let fullName):
switch context {
case .importTS:
// ImportTS expects Swift structs to come back as a retained JS object ID.
return .jsObjectLowerReturn
case .exportSwift, .exportSwiftProtocol:
case .exportSwift:
return swiftStructLowerReturn(fullName: fullName)
}
case .closure:
Expand All @@ -1640,7 +1640,7 @@ struct IntrinsicJSFragment: Sendable {
throw BridgeJSLinkError(
message: "Arrays are not yet supported to be returned from imported JS functions"
)
case .exportSwift, .exportSwiftProtocol:
case .exportSwift:
return try arrayLower(elementType: elementType)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ public struct ABINameGenerator {
public enum BridgeContext: Sendable {
case importTS
case exportSwift
case exportSwiftProtocol
}

public struct ClosureSignature: Codable, Equatable, Hashable, Sendable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,18 @@ import JavaScriptKit
var directionOptional: Direction? { get set }
var priority: Priority { get set }
var priorityOptional: Priority? { get set }
func onSomethingHappened() throws(JSException)
func onValueChanged(_ value: String) throws(JSException)
func onCountUpdated(count: Int) throws(JSException) -> Bool
func onLabelUpdated(_ prefix: String, _ suffix: String) throws(JSException)
func isCountEven() throws(JSException) -> Bool
func onHelperUpdated(_ helper: Helper) throws(JSException)
func createHelper() throws(JSException) -> Helper
func onOptionalHelperUpdated(_ helper: Helper?) throws(JSException)
func createOptionalHelper() throws(JSException) -> Helper?
func createEnum() throws(JSException) -> ExampleEnum
func handleResult(_ result: Result) throws(JSException)
func getResult() throws(JSException) -> Result
func onSomethingHappened()
func onValueChanged(_ value: String)
func onCountUpdated(count: Int) -> Bool
func onLabelUpdated(_ prefix: String, _ suffix: String)
func isCountEven() -> Bool
func onHelperUpdated(_ helper: Helper)
func createHelper() -> Helper
func onOptionalHelperUpdated(_ helper: Helper?)
func createOptionalHelper() -> Helper?
func createEnum() -> ExampleEnum
func handleResult(_ result: Result)
func getResult() -> Result
}

@JS class MyViewController {
Expand Down
Loading