aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2023-08-08 01:18:36 -0700
committerGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2023-08-08 01:18:36 -0700
commit38df5b146fab5e8b7d8d52e81ce1d385c3590f3d (patch)
treeab64e0548c483ab89ecf59c6a04d7d45b29b0b28
parent25c91aecab8aae72f030843abfcdeee2595fc9d1 (diff)
downloadbun-38df5b146fab5e8b7d8d52e81ce1d385c3590f3d.tar.gz
bun-38df5b146fab5e8b7d8d52e81ce1d385c3590f3d.tar.zst
bun-38df5b146fab5e8b7d8d52e81ce1d385c3590f3d.zip
Enable `Headers.prototype.getSetCookie`
Fixes #4057
-rw-r--r--src/bun.js/bindings/webcore/JSFetchHeaders.cpp33
-rw-r--r--test/js/web/fetch/headers.test.ts3
2 files changed, 11 insertions, 25 deletions
diff --git a/src/bun.js/bindings/webcore/JSFetchHeaders.cpp b/src/bun.js/bindings/webcore/JSFetchHeaders.cpp
index c604ea112..08b5d8ee6 100644
--- a/src/bun.js/bindings/webcore/JSFetchHeaders.cpp
+++ b/src/bun.js/bindings/webcore/JSFetchHeaders.cpp
@@ -258,28 +258,15 @@ JSC_DEFINE_HOST_FUNCTION(jsFetchHeadersPrototypeFunction_getSetCookie, (JSGlobal
return JSValue::encode(JSC::constructEmptyArray(lexicalGlobalObject, nullptr, 0));
}
- JSC::JSArray* array = nullptr;
- GCDeferralContext deferralContext(lexicalGlobalObject->vm());
- JSC::ObjectInitializationScope initializationScope(lexicalGlobalObject->vm());
- if ((array = JSC::JSArray::tryCreateUninitializedRestricted(
- initializationScope, &deferralContext,
- lexicalGlobalObject->arrayStructureForIndexingTypeDuringAllocation(JSC::ArrayWithContiguous),
- count))) {
- for (unsigned i = 0; i < count; ++i) {
- array->initializeIndex(initializationScope, i, jsString(vm, values[i]));
- RETURN_IF_EXCEPTION(scope, JSValue::encode(jsUndefined()));
- }
- } else {
- array = constructEmptyArray(lexicalGlobalObject, nullptr, count);
- RETURN_IF_EXCEPTION(scope, JSValue::encode(jsUndefined()));
- if (!array) {
- throwOutOfMemoryError(lexicalGlobalObject, scope);
- return JSValue::encode(jsUndefined());
- }
- for (unsigned i = 0; i < count; ++i) {
- array->putDirectIndex(lexicalGlobalObject, i, jsString(vm, values[i]));
- RETURN_IF_EXCEPTION(scope, JSValue::encode(jsUndefined()));
- }
+ JSC::JSArray* array = constructEmptyArray(lexicalGlobalObject, nullptr, count);
+ RETURN_IF_EXCEPTION(scope, JSValue::encode(jsUndefined()));
+ if (UNLIKELY(!array)) {
+ throwOutOfMemoryError(lexicalGlobalObject, scope);
+ return JSValue::encode(jsUndefined());
+ }
+
+ for (unsigned i = 0; i < count; ++i) {
+ array->putDirectIndex(lexicalGlobalObject, i, jsString(vm, values[i]));
RETURN_IF_EXCEPTION(scope, JSValue::encode(jsUndefined()));
}
@@ -302,7 +289,7 @@ static const HashTableValue JSFetchHeadersPrototypeTableValues[] = {
{ "forEach"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, jsFetchHeadersPrototypeFunction_forEach, 1 } },
{ "toJSON"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, jsFetchHeadersPrototypeFunction_toJSON, 0 } },
{ "count"_s, static_cast<unsigned>(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::GetterSetterType, jsFetchHeadersGetterCount, 0 } },
- // { "getSetCookie"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, jsFetchHeadersPrototypeFunction_getSetCookie, 0 } },
+ { "getSetCookie"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, jsFetchHeadersPrototypeFunction_getSetCookie, 0 } },
};
const ClassInfo JSFetchHeadersPrototype::s_info = { "Headers"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSFetchHeadersPrototype) };
diff --git a/test/js/web/fetch/headers.test.ts b/test/js/web/fetch/headers.test.ts
index 8ae17c11e..6ac1b0671 100644
--- a/test/js/web/fetch/headers.test.ts
+++ b/test/js/web/fetch/headers.test.ts
@@ -251,8 +251,7 @@ describe("Headers", () => {
// @ts-expect-error
expect(() => cookies.getAll("not-set-cookie")).toThrow(TypeError);
});
- const it1 = "getSetCookie" in cookies ? test : test.skip;
- it1("can get header with set-cookie using getSetCookie()", () => {
+ test("can get header with set-cookie using getSetCookie()", () => {
// @ts-expect-error
expect(cookies.getSetCookie()).toEqual([
"__Secure-ID=123; Secure; Domain=example.com",