Skip to content

Commit 8133508

Browse files
author
Jake Champion
committed
simplify the branching for when no backend is set
1 parent f1a4e70 commit 8133508

File tree

1 file changed

+23
-23
lines changed

1 file changed

+23
-23
lines changed

c-dependencies/js-compute-runtime/js-compute-builtins.cpp

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4039,30 +4039,30 @@ bool fetch(JSContext *cx, unsigned argc, Value *vp) {
40394039
}
40404040

40414041
RootedString backend(cx, Request::backend(request));
4042-
if (!backend && builtins::Fastly::allowDynamicBackends == false) {
4043-
backend = builtins::Fastly::defaultBackend;
4044-
}
4045-
if (!backend && builtins::Fastly::allowDynamicBackends == false) {
4046-
size_t bytes_read;
4047-
RequestHandle handle = Request::request_handle(request);
4048-
UniqueChars buf(
4049-
read_from_handle_all<xqd_req_uri_get, RequestHandle>(cx, handle, &bytes_read, false));
4050-
if (buf) {
4051-
JS_ReportErrorUTF8(cx,
4052-
"No backend specified for request with url %s. "
4053-
"Must provide a `backend` property on the `init` object "
4054-
"passed to either `new Request()` or `fetch`",
4055-
buf.get());
4056-
}
4057-
return ReturnPromiseRejectedWithPendingError(cx, args);
4058-
}
4059-
4060-
if (!backend && builtins::Fastly::allowDynamicBackends) {
4061-
JS::RootedObject dynamicBackend(cx, builtins::Backend::create(cx, request));
4062-
if (!dynamicBackend) {
4063-
return false;
4042+
if (!backend) {
4043+
if (builtins::Fastly::allowDynamicBackends) {
4044+
JS::RootedObject dynamicBackend(cx, builtins::Backend::create(cx, request));
4045+
if (!dynamicBackend) {
4046+
return false;
4047+
}
4048+
backend.set(builtins::Backend::name(cx, dynamicBackend));
4049+
} else {
4050+
backend = builtins::Fastly::defaultBackend;
4051+
if (!backend) {
4052+
size_t bytes_read;
4053+
RequestHandle handle = Request::request_handle(request);
4054+
UniqueChars buf(
4055+
read_from_handle_all<xqd_req_uri_get, RequestHandle>(cx, handle, &bytes_read, false));
4056+
if (buf) {
4057+
JS_ReportErrorUTF8(cx,
4058+
"No backend specified for request with url %s. "
4059+
"Must provide a `backend` property on the `init` object "
4060+
"passed to either `new Request()` or `fetch`",
4061+
buf.get());
4062+
}
4063+
return ReturnPromiseRejectedWithPendingError(cx, args);
4064+
}
40644065
}
4065-
backend.set(builtins::Backend::name(cx, dynamicBackend));
40664066
}
40674067

40684068
size_t backend_len;

0 commit comments

Comments
 (0)