From 251c037f424ace09e87ec0a47d7579d7b90626a1 Mon Sep 17 00:00:00 2001 From: Jake Champion Date: Thu, 25 Jan 2024 19:56:20 +0000 Subject: [PATCH] fix: If request does not have a static backend defined, return `undefined` for the Request.prototype.backend getter (#722) --- runtime/js-compute-runtime/builtins/request-response.cpp | 6 +----- types/globals.d.ts | 2 +- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/runtime/js-compute-runtime/builtins/request-response.cpp b/runtime/js-compute-runtime/builtins/request-response.cpp index 56e8afb4fa..e035920b8c 100644 --- a/runtime/js-compute-runtime/builtins/request-response.cpp +++ b/runtime/js-compute-runtime/builtins/request-response.cpp @@ -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(Slots::Backend))); - if (backend.isNullOrUndefined()) { - args.rval().setString(JS_GetEmptyString(cx)); - } else { - args.rval().set(backend); - } + args.rval().set(backend); return true; } diff --git a/types/globals.d.ts b/types/globals.d.ts index c88cbb5ca0..42a53b6fb4 100644 --- a/types/globals.d.ts +++ b/types/globals.d.ts @@ -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;