Skip to content
Merged
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
10 changes: 3 additions & 7 deletions Sources/JavaScriptKit/FundamentalObjects/JSClosure.swift
Original file line number Diff line number Diff line change
Expand Up @@ -167,19 +167,15 @@ private func makeAsyncClosure(
struct Context: @unchecked Sendable {
let resolver: (JSPromise.Result) -> Void
let arguments: [JSValue]
let body: (sending [JSValue]) async throws -> JSValue
let body: (sending [JSValue]) async throws(JSException) -> JSValue
}
let context = Context(resolver: resolver, arguments: arguments, body: body)
Task {
do {
do throws(JSException) {
let result = try await context.body(context.arguments)
context.resolver(.success(result))
} catch {
if let jsError = error as? JSException {
context.resolver(.failure(jsError.thrownValue))
} else {
context.resolver(.failure(JSError(message: String(describing: error)).jsValue))
}
context.resolver(.failure(error.thrownValue))
}
}
}.jsValue()
Expand Down