Skip to content

Commit 9c750e5

Browse files
Jake ChampionJakeChampion
authored andcommitted
fix: add a getter on Request to return the name of the backend assigned to the request
1 parent c52d193 commit 9c750e5

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

runtime/js-compute-runtime/builtins/request-response.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1259,6 +1259,19 @@ bool Request::bodyAll(JSContext *cx, unsigned argc, JS::Value *vp) {
12591259
return RequestOrResponse::bodyAll<result_type>(cx, args, self);
12601260
}
12611261

1262+
bool Request::backend_get(JSContext *cx, unsigned argc, JS::Value *vp) {
1263+
METHOD_HEADER(0)
1264+
JS::RootedValue backend(
1265+
cx, JS::GetReservedSlot(self, static_cast<uint32_t>(Slots::Backend)));
1266+
if (backend.isNullOrUndefined()) {
1267+
args.rval().setString(JS_GetEmptyString(cx));
1268+
} else {
1269+
args.rval().set(backend);
1270+
}
1271+
1272+
return true;
1273+
}
1274+
12621275
bool Request::body_get(JSContext *cx, unsigned argc, JS::Value *vp) {
12631276
METHOD_HEADER(0)
12641277
return RequestOrResponse::body_get(cx, args, self, is_downstream(self));
@@ -1313,6 +1326,12 @@ bool Request::clone(JSContext *cx, unsigned argc, JS::Value *vp) {
13131326
JS::SetReservedSlot(requestInstance, static_cast<uint32_t>(Slots::IsDownstream),
13141327
JS::GetReservedSlot(self, static_cast<uint32_t>(Slots::IsDownstream)));
13151328

1329+
JS::RootedValue backend(
1330+
cx, JS::GetReservedSlot(self, static_cast<uint32_t>(Slots::Backend)));
1331+
if (!backend.isNullOrUndefined()) {
1332+
JS::SetReservedSlot(requestInstance, static_cast<uint32_t>(Slots::Backend), backend);
1333+
}
1334+
13161335
auto hasBody = RequestOrResponse::has_body(self);
13171336

13181337
JS::SetReservedSlot(requestInstance, static_cast<uint32_t>(Slots::HasBody),
@@ -1451,6 +1470,7 @@ const JSPropertySpec Request::properties[] = {
14511470
JS_PSG("url", Request::url_get, JSPROP_ENUMERATE),
14521471
JS_PSG("version", Request::version_get, JSPROP_ENUMERATE),
14531472
JS_PSG("headers", Request::headers_get, JSPROP_ENUMERATE),
1473+
JS_PSG("backend", Request::backend_get, JSPROP_ENUMERATE),
14541474
JS_PSG("body", Request::body_get, JSPROP_ENUMERATE),
14551475
JS_PSG("bodyUsed", Request::bodyUsed_get, JSPROP_ENUMERATE),
14561476
JS_STRING_SYM_PS(toStringTag, "Request", JSPROP_READONLY),

runtime/js-compute-runtime/builtins/request-response.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ class Request final : public BuiltinImpl<Request> {
106106
template <RequestOrResponse::BodyReadResult result_type>
107107
static bool bodyAll(JSContext *cx, unsigned argc, JS::Value *vp);
108108

109+
static bool backend_get(JSContext *cx, unsigned argc, JS::Value *vp);
110+
109111
static bool body_get(JSContext *cx, unsigned argc, JS::Value *vp);
110112
static bool bodyUsed_get(JSContext *cx, unsigned argc, JS::Value *vp);
111113

0 commit comments

Comments
 (0)