Skip to content

Commit

Permalink
Rewriting Response::clone using `RequestOrResponse::headers_handle_…
Browse files Browse the repository at this point in the history
…clone` in order to properly clone headers rather than make a reference to existing headers.
  • Loading branch information
zerotri committed Dec 2, 2024
1 parent 3ba47dd commit a783a52
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions builtins/web/fetch/request-response.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2290,13 +2290,20 @@ bool Response::clone(JSContext *cx, unsigned argc, JS::Value *vp) {
init_slots(new_response);

// 2. Let newResponse be a copy of response, except for its body.
RootedValue cloned_headers_val(cx, JS::NullValue());
auto handle = RequestOrResponse::headers_handle_clone(cx, self);

auto headers_guard = RequestOrResponse::is_incoming(self) ? Headers::HeadersGuard::Immutable
: Headers::HeadersGuard::Response;
JSObject *cloned_headers = Headers::create(cx, handle.release(), headers_guard);

RootedObject cloned_headers(cx, RequestOrResponse::headers(cx, self));
if (!cloned_headers) {
return false;
}

SetReservedSlot(new_response, static_cast<uint32_t>(Slots::Headers), ObjectValue(*cloned_headers));
cloned_headers_val.set(ObjectValue(*cloned_headers));

SetReservedSlot(new_response, static_cast<uint32_t>(Slots::Headers), cloned_headers_val);

Value status_val = GetReservedSlot(self, static_cast<uint32_t>(Slots::Status));
Value status_message_val = GetReservedSlot(self, static_cast<uint32_t>(Slots::StatusMessage));
Expand Down

0 comments on commit a783a52

Please sign in to comment.