diff --git a/src/bun.js/bindings/webcore/JSFetchHeaders.cpp b/src/bun.js/bindings/webcore/JSFetchHeaders.cpp index f80dc5776c..888a247e0a 100644 --- a/src/bun.js/bindings/webcore/JSFetchHeaders.cpp +++ b/src/bun.js/bindings/webcore/JSFetchHeaders.cpp @@ -71,7 +71,6 @@ static JSC_DECLARE_HOST_FUNCTION(jsFetchHeadersPrototypeFunction_has); static JSC_DECLARE_HOST_FUNCTION(jsFetchHeadersPrototypeFunction_set); static JSC_DECLARE_HOST_FUNCTION(jsFetchHeadersPrototypeFunction_entries); static JSC_DECLARE_HOST_FUNCTION(jsFetchHeadersPrototypeFunction_keys); -static JSC_DECLARE_HOST_FUNCTION(jsFetchHeadersPrototypeFunction_rawKeys); static JSC_DECLARE_HOST_FUNCTION(jsFetchHeadersPrototypeFunction_values); static JSC_DECLARE_HOST_FUNCTION(jsFetchHeadersPrototypeFunction_forEach); @@ -219,6 +218,7 @@ JSC_DEFINE_HOST_FUNCTION(jsFetchHeadersPrototypeFunction_getAll, (JSGlobalObject auto& impl = castedThis->wrapped(); if (name->length() != "set-cookie"_s.length() || name->convertToASCIILowercase() != "set-cookie"_s) { throwTypeError(lexicalGlobalObject, scope, "Only \"set-cookie\" is supported."_s); + return {}; } auto values = impl.getSetCookieHeaders(); @@ -311,7 +311,6 @@ static const HashTableValue JSFetchHeadersPrototypeTableValues[] = { { "set"_s, static_cast(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, jsFetchHeadersPrototypeFunction_set, 2 } }, { "entries"_s, static_cast(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, jsFetchHeadersPrototypeFunction_entries, 0 } }, { "keys"_s, static_cast(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, jsFetchHeadersPrototypeFunction_keys, 0 } }, - { "rawKeys"_s, static_cast(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, jsFetchHeadersPrototypeFunction_rawKeys, 0 } }, { "values"_s, static_cast(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, jsFetchHeadersPrototypeFunction_values, 0 } }, { "forEach"_s, static_cast(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, jsFetchHeadersPrototypeFunction_forEach, 1 } }, { "toJSON"_s, static_cast(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, jsFetchHeadersPrototypeFunction_toJSON, 0 } }, @@ -585,11 +584,18 @@ JSC_DEFINE_HOST_FUNCTION(jsFetchHeadersPrototypeFunction_keys, (JSC::JSGlobalObj return IDLOperation::call(*lexicalGlobalObject, *callFrame, "keys"); } -JSC_DEFINE_HOST_FUNCTION(jsFetchHeadersPrototypeFunction_rawKeys, (JSC::JSGlobalObject * lexicalGlobalObject, JSC::CallFrame* callFrame)) +JSC_DEFINE_HOST_FUNCTION(jsFetchHeaders_getRawKeys, (JSC::JSGlobalObject * lexicalGlobalObject, JSC::CallFrame* callFrame)) { VM& vm = lexicalGlobalObject->vm(); + auto scope = DECLARE_THROW_SCOPE(vm); + auto* thisObject = castThisValue(*lexicalGlobalObject, callFrame->thisValue()); + if (!thisObject) { + throwTypeError(lexicalGlobalObject, scope, "\"this\" must be an instance of Headers"_s); + return {}; + } + FetchHeaders& headers = thisObject->wrapped(); JSArray* outArray = JSC::JSArray::create(vm, lexicalGlobalObject->arrayStructureForIndexingTypeDuringAllocation(JSC::ArrayWithContiguous), headers.size()); diff --git a/src/bun.js/bindings/webcore/JSFetchHeaders.h b/src/bun.js/bindings/webcore/JSFetchHeaders.h index d555b12914..8d69079f9c 100644 --- a/src/bun.js/bindings/webcore/JSFetchHeaders.h +++ b/src/bun.js/bindings/webcore/JSFetchHeaders.h @@ -100,4 +100,6 @@ template<> struct JSDOMWrapperConverterTraits { JSC::EncodedJSValue fetchHeadersGetSetCookie(JSC::JSGlobalObject* lexicalGlobalObject, VM& vm, WebCore::FetchHeaders* impl); +JSC_DEFINE_HOST_FUNCTION(jsFetchHeaders_getRawKeys, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame)); + } // namespace WebCore diff --git a/src/js/node/http.ts b/src/js/node/http.ts index b52ddf3934..ccc9f05029 100644 --- a/src/js/node/http.ts +++ b/src/js/node/http.ts @@ -109,6 +109,7 @@ const { let cluster; const sendHelper = $newZigFunction("node_cluster_binding.zig", "sendHelperChild", 3); const getBunServerAllClosedPromise = $newZigFunction("node_http_binding.zig", "getBunServerAllClosedPromise", 1); +const getRawKeys = $newCppFunction("JSFetchHeaders.cpp", "jsFetchHeaders_getRawKeys", 0); // TODO: make this more robust. function isAbortError(err) { @@ -1609,7 +1610,7 @@ const OutgoingMessagePrototype = { getRawHeaderNames() { var headers = this[headersSymbol]; if (!headers) return []; - return headers.rawKeys(); + return getRawKeys.$call(headers); }, getHeaders() {