Skip to content

Commit

Permalink
fix: If request does not have a static backend defined, return `undef…
Browse files Browse the repository at this point in the history
…ined` for the Request.prototype.backend getter

This fixes #716
  • Loading branch information
JakeChampion committed Jan 25, 2024
1 parent 17fbdf5 commit c38e288
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
9 changes: 3 additions & 6 deletions runtime/js-compute-runtime/builtins/request-response.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1263,11 +1263,7 @@ bool Request::bodyAll(JSContext *cx, unsigned argc, JS::Value *vp) {
bool Request::backend_get(JSContext *cx, unsigned argc, JS::Value *vp) {
METHOD_HEADER(0)
JS::RootedValue backend(cx, JS::GetReservedSlot(self, static_cast<uint32_t>(Slots::Backend)));
if (backend.isNullOrUndefined()) {
args.rval().setString(JS_GetEmptyString(cx));
} else {
args.rval().set(backend);
}
args.rval().set(backend);

return true;
}
Expand Down Expand Up @@ -1990,7 +1986,8 @@ JSObject *Request::create(JSContext *cx, JS::HandleObject requestInstance, JS::H
// (implicit)

// Apply the Fastly Compute-proprietary `backend` property.
if (!backend_val.isUndefined()) {
if (!backend_val.isNullOrUndefined()) {
dump_value(cx, backend_val, stdout);
JS::RootedString backend(cx, JS::ToString(cx, backend_val));
if (!backend) {
return nullptr;
Expand Down
2 changes: 1 addition & 1 deletion types/globals.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1084,7 +1084,7 @@ interface Request extends Body {
clone(): Request;

// Fastly extensions
backend: string;
backend?: string;
setCacheOverride(override: import('fastly:cache-override').CacheOverride): void;
setCacheKey(key: string): void;
setManualFramingHeaders(manual: boolean): void;
Expand Down

0 comments on commit c38e288

Please sign in to comment.