Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

misc node:process fixes #14621

Open
wants to merge 26 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
f34bf7b
add tests already passing
nektro Oct 15, 2024
c154559
fix child-process-stdio.test.js
nektro Oct 15, 2024
b6cd955
add definition for process.availableMemory()
nektro Oct 15, 2024
3271b2b
fix process-chdir.test.js
nektro Oct 15, 2024
aa4244b
fix process-constrained-memory.test.js
nektro Oct 15, 2024
358eb10
fix process-cpuusage.test.js
nektro Oct 16, 2024
fbe9b91
fix process-hrtime.test.js
nektro Oct 16, 2024
15ddb36
fix process-really-exit.test.js
nektro Oct 16, 2024
2d49f62
fix process-release.test.js
nektro Oct 16, 2024
76147da
fix process-uid-gid.test.js
nektro Oct 16, 2024
842c713
fix process-setgroups.test.js
nektro Oct 16, 2024
54e6744
fix regressions
nektro Oct 16, 2024
eb293d5
fix child-process-windows-hide.test.js running in ci
nektro Oct 16, 2024
d4828a1
limit gid_t and uid_t parsing to 2**31-1
nektro Oct 17, 2024
a985b07
another one without asterisks
nektro Oct 17, 2024
77e8a35
change these to 32
nektro Oct 17, 2024
c69815c
add these exception checks just in case
nektro Oct 17, 2024
b4b82b8
reorder test to separate cases
nektro Oct 17, 2024
c588751
dont overflow array access
nektro Oct 17, 2024
de82b4a
rework id validation
nektro Oct 17, 2024
bc4a0e4
this test is supposed to be allowed to fail with either message
nektro Oct 17, 2024
0c59cb4
fix child-process-stdio.test.js on windows
nektro Oct 17, 2024
fdcf59d
add constrainedMemory impl
nektro Oct 18, 2024
63780d5
add availableMemory impl
nektro Oct 18, 2024
234ba97
uv_get_available_memory is a c decl
nektro Oct 18, 2024
5ea9de6
Merge branch 'main' into nektro-patch-63596
nektro Oct 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
322 changes: 239 additions & 83 deletions src/bun.js/bindings/BunProcess.cpp

Large diffs are not rendered by default.

22 changes: 13 additions & 9 deletions src/bun.js/bindings/ErrorCode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ JSC::EncodedJSValue INVALID_ARG_TYPE(JSC::ThrowScope& throwScope, JSC::JSGlobalO
auto arg_name = val_arg_name.span8();
ASSERT(WTF::charactersAreAllASCII(arg_name));

auto arg_kind = String(arg_name).startsWith("options."_s) ? "property"_s : "argument"_s;
auto arg_kind = String(arg_name).contains("."_s) ? "property"_s : "argument"_s;

auto expected_type = val_expected_type.span8();
ASSERT(WTF::charactersAreAllASCII(expected_type));
Expand All @@ -324,7 +324,7 @@ JSC::EncodedJSValue INVALID_ARG_TYPE(JSC::ThrowScope& throwScope, JSC::JSGlobalO
auto arg_name = val_arg_name.toWTFString(globalObject);
RETURN_IF_EXCEPTION(throwScope, {});

auto arg_kind = String(arg_name).startsWith("options."_s) ? "property"_s : "argument"_s;
auto arg_kind = String(arg_name).contains("."_s) ? "property"_s : "argument"_s;

auto expected_type = val_expected_type.span8();
ASSERT(WTF::charactersAreAllASCII(expected_type));
Expand Down Expand Up @@ -360,6 +360,11 @@ JSC::EncodedJSValue OUT_OF_RANGE(JSC::ThrowScope& throwScope, JSC::JSGlobalObjec
auto actual_value = JSValueToStringSafe(globalObject, actual);
RETURN_IF_EXCEPTION(throwScope, {});

if (lower == upper) {
auto message = makeString("The value of \""_s, arg_name, "\" is out of range. It must be "_s, lowerStr, ". Received "_s, actual_value);
throwScope.throwException(globalObject, createError(globalObject, ErrorCode::ERR_OUT_OF_RANGE, message));
return {};
}
auto message = makeString("The value of \""_s, arg_name, "\" is out of range. It must be >= "_s, lowerStr, " and <= "_s, upperStr, ". Received "_s, actual_value);
throwScope.throwException(globalObject, createError(globalObject, ErrorCode::ERR_OUT_OF_RANGE, message));
return {};
Expand Down Expand Up @@ -407,13 +412,7 @@ JSC::EncodedJSValue OUT_OF_RANGE(JSC::ThrowScope& throwScope, JSC::JSGlobalObjec

JSC::EncodedJSValue INVALID_ARG_VALUE(JSC::ThrowScope& throwScope, JSC::JSGlobalObject* globalObject, const WTF::String& name, JSC::JSValue value, const WTF::String& reason)
{
ASCIILiteral type;
{
auto sp = name.span8();
auto str = std::string_view((const char*)(sp.data()), sp.size());
auto has = str.find('.') == std::string::npos;
type = has ? "property"_s : "argument"_s;
}
auto type = name.contains("."_s) ? "property"_s : "argument"_s;

auto value_string = JSValueToStringSafe(globalObject, value);
RETURN_IF_EXCEPTION(throwScope, {});
Expand Down Expand Up @@ -614,6 +613,11 @@ JSC_DEFINE_HOST_FUNCTION(jsFunction_ERR_BUFFER_OUT_OF_BOUNDS, (JSC::JSGlobalObje
return JSC::JSValue::encode(createError(globalObject, ErrorCode::ERR_BUFFER_OUT_OF_BOUNDS, "Attempt to access memory outside buffer bounds"_s));
}

JSC_DEFINE_HOST_FUNCTION(jsFunction_ERR_IPC_ONE_PIPE, (JSC::JSGlobalObject * globalObject, JSC::CallFrame*))
{
return JSC::JSValue::encode(createError(globalObject, ErrorCode::ERR_IPC_ONE_PIPE, "Child process can have only one IPC pipe"_s));
}

} // namespace Bun

JSC::JSValue WebCore::toJS(JSC::JSGlobalObject* globalObject, CommonAbortReason abortReason)
Expand Down
1 change: 1 addition & 0 deletions src/bun.js/bindings/ErrorCode.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ JSC_DECLARE_HOST_FUNCTION(jsFunction_ERR_BROTLI_INVALID_PARAM);
JSC_DECLARE_HOST_FUNCTION(jsFunction_ERR_BUFFER_TOO_LARGE);
JSC_DECLARE_HOST_FUNCTION(jsFunction_ERR_ZLIB_INITIALIZATION_FAILED);
JSC_DECLARE_HOST_FUNCTION(jsFunction_ERR_BUFFER_OUT_OF_BOUNDS);
JSC_DECLARE_HOST_FUNCTION(jsFunction_ERR_IPC_ONE_PIPE);

enum Bound {
LOWER,
Expand Down
2 changes: 2 additions & 0 deletions src/bun.js/bindings/ErrorCode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ export default [
["ERR_BUFFER_OUT_OF_BOUNDS", RangeError, "RangeError"],
["ERR_UNKNOWN_SIGNAL", TypeError, "TypeError"],
["ERR_SOCKET_BAD_PORT", RangeError, "RangeError"],
["ERR_IPC_ONE_PIPE", Error, "Error"],
["ERR_UNKNOWN_CREDENTIAL", Error, "Error"],

// Bun-specific
["ERR_FORMDATA_PARSE_ERROR", TypeError, "TypeError"],
Expand Down
10 changes: 9 additions & 1 deletion src/bun.js/bindings/NodeValidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,11 @@ JSC_DEFINE_HOST_FUNCTION(jsFunction_validateArray, (JSC::JSGlobalObject * global
auto value = callFrame->argument(0);
auto name = callFrame->argument(1);
auto minLength = callFrame->argument(2);
return V::validateArray(scope, globalObject, value, name, minLength);
}
JSC::EncodedJSValue V::validateArray(JSC::ThrowScope& scope, JSC::JSGlobalObject* globalObject, JSValue value, JSValue name, JSValue minLength)
{
JSC::VM& vm = globalObject->vm();

if (minLength.isUndefined()) minLength = jsNumber(0);

Expand Down Expand Up @@ -335,7 +340,10 @@ JSC_DEFINE_HOST_FUNCTION(jsFunction_validateUint32, (JSC::JSGlobalObject * globa
auto value = callFrame->argument(0);
auto name = callFrame->argument(1);
auto positive = callFrame->argument(2);

return V::validateUint32(scope, globalObject, value, name, positive);
}
JSC::EncodedJSValue V::validateUint32(JSC::ThrowScope& scope, JSC::JSGlobalObject* globalObject, JSValue value, JSValue name, JSValue positive)
{
if (!value.isNumber()) return Bun::ERR::INVALID_ARG_TYPE(scope, globalObject, name, "number"_s, value);
if (positive.isUndefined()) positive = jsBoolean(false);

Expand Down
2 changes: 2 additions & 0 deletions src/bun.js/bindings/NodeValidator.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ JSC::EncodedJSValue validateInteger(JSC::ThrowScope& scope, JSC::JSGlobalObject*
JSC::EncodedJSValue validateNumber(JSC::ThrowScope& scope, JSC::JSGlobalObject* globalObject, JSC::JSValue value, JSC::JSValue name, JSC::JSValue min, JSC::JSValue max);
JSC::EncodedJSValue validateFiniteNumber(JSC::ThrowScope& scope, JSC::JSGlobalObject* globalObject, JSC::JSValue number, JSC::JSValue name);
JSC::EncodedJSValue validateString(JSC::ThrowScope& scope, JSC::JSGlobalObject* globalObject, JSValue value, JSValue name);
JSC::EncodedJSValue validateArray(JSC::ThrowScope& scope, JSC::JSGlobalObject* globalObject, JSValue value, JSValue name, JSValue minLength);
JSC::EncodedJSValue validateUint32(JSC::ThrowScope& scope, JSC::JSGlobalObject* globalObject, JSValue value, JSValue name, JSValue positive);

}

Expand Down
27 changes: 23 additions & 4 deletions src/bun.js/bindings/OsBinding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,31 @@ extern "C" uint64_t Bun__Os__getFreeMemory(void)
vm_statistics_data_t info;
mach_msg_type_number_t count = sizeof(info) / sizeof(integer_t);

if (host_statistics(mach_host_self(), HOST_VM_INFO,
(host_info_t)&info, &count)
!= KERN_SUCCESS) {
if (host_statistics(mach_host_self(), HOST_VM_INFO, (host_info_t)&info, &count) != KERN_SUCCESS) {
return 0;
}

return (uint64_t)info.free_count * sysconf(_SC_PAGESIZE);
}
#endif

#if OS(LINUX)
#include <sys/sysinfo.h>

extern "C" uint64_t Bun__Os__getFreeMemory(void)
{
struct sysinfo info;
if (sysinfo(&info) == 0) {
return info.freeram * info.mem_unit;
}
return 0;
}
#endif

#if OS(WINDOWS)
extern "C" uint64_t uv_get_available_memory(void);

extern "C" uint64_t Bun__Os__getFreeMemory(void)
{
return uv_get_available_memory();
}
#endif
Loading