Skip to content

Commit dd7ad58

Browse files
committed
More defensive checking for options
1 parent b16ed8d commit dd7ad58

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

Sources/ECMASwift/API/Fetch/Fetch.swift

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public final class FetchAPI {
6161
return
6262
}
6363
// options can include body.
64-
if let options, options.hasProperty("body") {
64+
if let options, options.hasValue, options.hasProperty("body") {
6565
request.httpBody = options.forProperty("body").toString().data(using: .utf8)
6666
}
6767
guard let client = self?.client else { return }
@@ -89,11 +89,13 @@ public final class FetchAPI {
8989
return
9090
}
9191
}
92-
if let signal = options?.forProperty("signal").toType(AbortSignal.self) {
93-
signal.onAbort = {
94-
if signal.aborted {
95-
fetchTask?.cancel()
96-
reject.call(withArguments: [["name": "AbortError"]])
92+
if let options = options, options.hasValue {
93+
if let signal = options.forProperty("signal").toType(AbortSignal.self) {
94+
signal.onAbort = {
95+
if signal.aborted {
96+
fetchTask?.cancel()
97+
reject.call(withArguments: [["name": "AbortError"]])
98+
}
9799
}
98100
}
99101
}

0 commit comments

Comments
 (0)