Skip to content

Commit 797225c

Browse files
Restricting throwable exception type to JSException for closures
1 parent 132233b commit 797225c

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

Sources/JavaScriptKit/BasicObjects/JSPromise.swift

+12-12
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,10 @@ public final class JSPromise: JSBridgedClass {
9898
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
9999
@discardableResult
100100
public func then(
101-
success: sending @escaping (sending JSValue) async throws -> JSValue
101+
success: sending @escaping (sending JSValue) async throws(JSException) -> JSValue
102102
) -> JSPromise {
103-
let closure = JSOneshotClosure.async {
104-
try await success($0[0]).jsValue
103+
let closure = JSOneshotClosure.async { arguments throws(JSException) -> JSValue in
104+
return try await success(arguments[0])
105105
}
106106
return JSPromise(unsafelyWrapping: jsObject.then!(closure).object!)
107107
}
@@ -127,14 +127,14 @@ public final class JSPromise: JSBridgedClass {
127127
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
128128
@discardableResult
129129
public func then(
130-
success: sending @escaping (sending JSValue) async throws -> JSValue,
131-
failure: sending @escaping (sending JSValue) async throws -> JSValue
130+
success: sending @escaping (sending JSValue) async throws(JSException) -> JSValue,
131+
failure: sending @escaping (sending JSValue) async throws(JSException) -> JSValue
132132
) -> JSPromise {
133-
let successClosure = JSOneshotClosure.async {
134-
try await success($0[0]).jsValue
133+
let successClosure = JSOneshotClosure.async { arguments throws(JSException) -> JSValue in
134+
try await success(arguments[0]).jsValue
135135
}
136-
let failureClosure = JSOneshotClosure.async {
137-
try await failure($0[0]).jsValue
136+
let failureClosure = JSOneshotClosure.async { arguments throws(JSException) -> JSValue in
137+
try await failure(arguments[0]).jsValue
138138
}
139139
return JSPromise(unsafelyWrapping: jsObject.then!(successClosure, failureClosure).object!)
140140
}
@@ -158,10 +158,10 @@ public final class JSPromise: JSBridgedClass {
158158
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
159159
@discardableResult
160160
public func `catch`(
161-
failure: sending @escaping (sending JSValue) async throws -> JSValue
161+
failure: sending @escaping (sending JSValue) async throws(JSException) -> JSValue
162162
) -> JSPromise {
163-
let closure = JSOneshotClosure.async {
164-
try await failure($0[0]).jsValue
163+
let closure = JSOneshotClosure.async { arguments throws(JSException) -> JSValue in
164+
try await failure(arguments[0]).jsValue
165165
}
166166
return .init(unsafelyWrapping: jsObject.catch!(closure).object!)
167167
}

Sources/JavaScriptKit/FundamentalObjects/JSClosure.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public class JSOneshotClosure: JSObject, JSClosureProtocol {
4545

4646
#if compiler(>=5.5) && (!hasFeature(Embedded) || os(WASI))
4747
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
48-
public static func async(_ body: sending @escaping (sending [JSValue]) async throws -> JSValue) -> JSOneshotClosure
48+
public static func async(_ body: sending @escaping (sending [JSValue]) async throws(JSException) -> JSValue) -> JSOneshotClosure
4949
{
5050
JSOneshotClosure(makeAsyncClosure(body))
5151
}
@@ -137,7 +137,7 @@ public class JSClosure: JSFunction, JSClosureProtocol {
137137

138138
#if compiler(>=5.5) && (!hasFeature(Embedded) || os(WASI))
139139
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
140-
public static func async(_ body: @Sendable @escaping (sending [JSValue]) async throws -> JSValue) -> JSClosure {
140+
public static func async(_ body: @Sendable @escaping (sending [JSValue]) async throws(JSException) -> JSValue) -> JSClosure {
141141
JSClosure(makeAsyncClosure(body))
142142
}
143143
#endif
@@ -154,7 +154,7 @@ public class JSClosure: JSFunction, JSClosureProtocol {
154154
#if compiler(>=5.5) && (!hasFeature(Embedded) || os(WASI))
155155
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
156156
private func makeAsyncClosure(
157-
_ body: sending @escaping (sending [JSValue]) async throws -> JSValue
157+
_ body: sending @escaping (sending [JSValue]) async throws(JSException) -> JSValue
158158
) -> ((sending [JSValue]) -> JSValue) {
159159
{ arguments in
160160
JSPromise { resolver in

0 commit comments

Comments
 (0)