mirror of
https://github.com/oven-sh/bun
synced 2026-02-15 13:22:07 +00:00
node:https: provide proper Agent definition (#11826)
Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
This commit is contained in:
@@ -69,6 +69,15 @@ extern "C" JSC::EncodedJSValue Bun__ERR_IPC_CHANNEL_CLOSED(JSC::JSGlobalObject*
|
||||
|
||||
// clang-format on
|
||||
|
||||
#define EXPECT_ARG_COUNT(count__) \
|
||||
do { \
|
||||
auto argCount = callFrame->argumentCount(); \
|
||||
if (argCount < count__) { \
|
||||
JSC::throwTypeError(globalObject, scope, "requires " #count__ " arguments"_s); \
|
||||
return {}; \
|
||||
} \
|
||||
} while (false)
|
||||
|
||||
namespace Bun {
|
||||
|
||||
using namespace JSC;
|
||||
@@ -196,11 +205,8 @@ JSC_DEFINE_HOST_FUNCTION(jsFunction_ERR_INVALID_ARG_TYPE, (JSC::JSGlobalObject *
|
||||
JSC::VM& vm = globalObject->vm();
|
||||
auto scope = DECLARE_THROW_SCOPE(vm);
|
||||
|
||||
auto argCount = callFrame->argumentCount();
|
||||
if (argCount < 3) {
|
||||
JSC::throwTypeError(globalObject, scope, "requires 3 arguments"_s);
|
||||
return {};
|
||||
}
|
||||
EXPECT_ARG_COUNT(3);
|
||||
|
||||
auto arg_name = callFrame->argument(0);
|
||||
auto expected_type = callFrame->argument(1);
|
||||
auto actual_value = callFrame->argument(2);
|
||||
@@ -246,11 +252,7 @@ JSC_DEFINE_HOST_FUNCTION(jsFunction_ERR_OUT_OF_RANGE, (JSC::JSGlobalObject * glo
|
||||
JSC::VM& vm = globalObject->vm();
|
||||
auto scope = DECLARE_THROW_SCOPE(vm);
|
||||
|
||||
auto argCount = callFrame->argumentCount();
|
||||
if (argCount < 3) {
|
||||
JSC::throwTypeError(globalObject, scope, "requires 3 arguments"_s);
|
||||
return {};
|
||||
}
|
||||
EXPECT_ARG_COUNT(3);
|
||||
|
||||
auto arg_name = callFrame->argument(0).toWTFString(globalObject);
|
||||
RETURN_IF_EXCEPTION(scope, {});
|
||||
@@ -320,7 +322,7 @@ extern "C" JSC::EncodedJSValue Bun__ERR_MISSING_ARGS_static(JSC::JSGlobalObject*
|
||||
JSC::VM& vm = globalObject->vm();
|
||||
auto scope = DECLARE_THROW_SCOPE(vm);
|
||||
|
||||
if (arg1 == 0) {
|
||||
if (arg1 == nullptr) {
|
||||
JSC::throwTypeError(globalObject, scope, "requires at least 1 argument"_s);
|
||||
return {};
|
||||
}
|
||||
@@ -365,6 +367,23 @@ JSC_DEFINE_HOST_FUNCTION(jsFunction_ERR_SOCKET_BAD_TYPE, (JSC::JSGlobalObject *
|
||||
return JSC::JSValue::encode(createError(globalObject, ErrorCode::ERR_SOCKET_BAD_TYPE, "Bad socket type specified. Valid types are: udp4, udp6"_s));
|
||||
}
|
||||
|
||||
JSC_DEFINE_HOST_FUNCTION(jsFunction_ERR_INVALID_PROTOCOL, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame))
|
||||
{
|
||||
JSC::VM& vm = globalObject->vm();
|
||||
auto scope = DECLARE_THROW_SCOPE(vm);
|
||||
|
||||
EXPECT_ARG_COUNT(2);
|
||||
|
||||
auto actual = callFrame->argument(0).toWTFString(globalObject);
|
||||
RETURN_IF_EXCEPTION(scope, {});
|
||||
|
||||
auto expected = callFrame->argument(1).toWTFString(globalObject);
|
||||
RETURN_IF_EXCEPTION(scope, {});
|
||||
|
||||
auto message = makeString("Protocol \""_s, actual, "\" not supported. Expected \""_s, expected, "\""_s);
|
||||
return JSC::JSValue::encode(createError(globalObject, ErrorCode::ERR_INVALID_PROTOCOL, message));
|
||||
}
|
||||
|
||||
} // namespace Bun
|
||||
|
||||
JSC::JSValue WebCore::toJS(JSC::JSGlobalObject* globalObject, CommonAbortReason abortReason)
|
||||
|
||||
Reference in New Issue
Block a user