Skip to content

Commit

Permalink
More defensive checking for options
Browse files Browse the repository at this point in the history
  • Loading branch information
theolampert committed Jul 3, 2024
1 parent b16ed8d commit dd7ad58
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions Sources/ECMASwift/API/Fetch/Fetch.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public final class FetchAPI {
return
}
// options can include body.
if let options, options.hasProperty("body") {
if let options, options.hasValue, options.hasProperty("body") {
request.httpBody = options.forProperty("body").toString().data(using: .utf8)
}
guard let client = self?.client else { return }
Expand Down Expand Up @@ -89,11 +89,13 @@ public final class FetchAPI {
return
}
}
if let signal = options?.forProperty("signal").toType(AbortSignal.self) {
signal.onAbort = {
if signal.aborted {
fetchTask?.cancel()
reject.call(withArguments: [["name": "AbortError"]])
if let options = options, options.hasValue {
if let signal = options.forProperty("signal").toType(AbortSignal.self) {
signal.onAbort = {
if signal.aborted {
fetchTask?.cancel()
reject.call(withArguments: [["name": "AbortError"]])
}
}
}
}
Expand Down

0 comments on commit dd7ad58

Please sign in to comment.