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

node: fix the rest of test-process #16026

Draft
wants to merge 40 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
9e0adfe
fix test-process-warning.js
nektro Dec 28, 2024
d12a3d2
stub out node:test
nektro Dec 28, 2024
9b25f5a
fix test-process-umask.js
nektro Dec 28, 2024
9d3fddf
fix test-process-umask-mask.js
nektro Dec 28, 2024
8f161ea
fix test-process-uid-gid.js
nektro Dec 28, 2024
295cbc0
fix test-process-title-cli.js
nektro Dec 28, 2024
13da098
don't lowercase Error instance printing
nektro Dec 28, 2024
0b1f020
fix test-process-setgroups.js
nektro Dec 28, 2024
e4bf5e5
fix test-process-release.js
nektro Dec 28, 2024
218c673
fix test-process-really-exit.js
nektro Dec 28, 2024
ca2a61e
fix
nektro Dec 28, 2024
2ebba0a
fix test-process-no-deprecation.js
nektro Dec 28, 2024
908287f
fix test-process-kill-pid.js
nektro Dec 28, 2024
24609c2
fix test-process-hrtime.js
nektro Dec 28, 2024
7f0adc1
tidy
nektro Dec 28, 2024
9227ca6
fix test-process-get-builtin.mjs
nektro Dec 31, 2024
e8e9e37
fix test-process-exit-code-validation.js
nektro Dec 31, 2024
1be1f0c
fix test-process-exception-capture-errors.js
nektro Dec 31, 2024
3f8a948
fix test-process-euid-egid.js
nektro Dec 31, 2024
c9fc1ed
fix test-process-emitwarning.js
nektro Dec 31, 2024
4d3d51e
fix test-process-dlopen-error-message-crash.js
nektro Dec 31, 2024
297091a
fix test-process-cpuUsage.js
nektro Dec 31, 2024
e7ab2d0
fix test-process-constrained-memory.js
nektro Dec 31, 2024
863c03e
fix test-process-config.js
nektro Dec 31, 2024
652e8d4
fix test-process-chdir.js
nektro Dec 31, 2024
0fa6ab4
add code missing from 24609c27cb
nektro Dec 31, 2024
5e834d1
zig: make FileSystem.top_level_dir nul-terminated
nektro Dec 31, 2024
6a51431
fix test-process-chdir-errormessage.js
nektro Dec 31, 2024
bee3360
fill in some errnoSys variants
nektro Jan 1, 2025
19febc6
fix test-process-binding-util.js
nektro Jan 1, 2025
2f66a40
fix test-process-beforeexit-throw-exit.js
nektro Jan 1, 2025
b84078f
fix test-process-available-memory.js
nektro Jan 1, 2025
fe3a953
make process constructor callable
nektro Jan 1, 2025
77ad70f
fix test-process-assert.js
nektro Jan 1, 2025
d098c67
fix test-child-process-stdio.js
nektro Jan 1, 2025
b2e5ac7
fix test-process-beforeexit.js
nektro Jan 1, 2025
4a93608
Merge remote-tracking branch 'origin/main' into nektro-patch-18634
nektro Jan 1, 2025
96c1339
fixes
nektro Jan 1, 2025
0a97612
lower flaky test retry count
nektro Jan 1, 2025
8da2df3
fixes
nektro Jan 1, 2025
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
2 changes: 1 addition & 1 deletion scripts/runner.node.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ const { values: options, positionals: filters } = parseArgs({
},
["retries"]: {
type: "string",
default: isCI ? "4" : "0", // N retries = N+1 attempts
default: isCI ? "2" : "0", // N retries = N+1 attempts
},
},
});
Expand Down
2 changes: 1 addition & 1 deletion src/api/schema.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1631,7 +1631,7 @@ pub const Api = struct {
origin: ?[]const u8 = null,

/// absolute_working_dir
absolute_working_dir: ?[]const u8 = null,
absolute_working_dir: ?[:0]const u8 = null,

/// define
define: ?StringMap = null,
Expand Down
2 changes: 1 addition & 1 deletion src/bake/DevServer.zig
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub const igLog = bun.Output.scoped(.IncrementalGraph, false);
pub const Options = struct {
/// Arena must live until DevServer.deinit()
arena: Allocator,
root: []const u8,
root: [:0]const u8,
vm: *VirtualMachine,
framework: bake.Framework,
bundler_options: bake.SplitBundlerOptions,
Expand Down
6 changes: 3 additions & 3 deletions src/bake/bake.zig
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub const UserOptions = struct {
arena: std.heap.ArenaAllocator,
allocations: StringRefList,

root: []const u8,
root: [:0]const u8,
framework: Framework,
bundler_options: SplitBundlerOptions,

Expand Down Expand Up @@ -78,9 +78,9 @@ pub const UserOptions = struct {
const StringRefList = struct {
strings: std.ArrayListUnmanaged(ZigString.Slice),

pub fn track(al: *StringRefList, str: ZigString.Slice) []const u8 {
pub fn track(al: *StringRefList, str: ZigString.Slice) [:0]const u8 {
al.strings.append(bun.default_allocator, str) catch bun.outOfMemory();
return str.slice();
return str.sliceZ();
}

pub fn free(al: *StringRefList) void {
Expand Down
741 changes: 532 additions & 209 deletions src/bun.js/bindings/BunProcess.cpp

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/bun.js/bindings/BunProcess.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class Process : public WebCore::JSEventEmitter {
}

DECLARE_EXPORT_INFO;
bool m_reportOnUncaughtException;

static void destroy(JSC::JSCell* cell)
{
Expand Down
51 changes: 46 additions & 5 deletions src/bun.js/bindings/ErrorCode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ WTF::String determineSpecificType(JSC::JSGlobalObject* globalObject, JSValue val
if (!name.isNull() && name.length() > 0) {
return makeString("function "_s, name);
}
return String("function"_s);
return String("function "_s);
}
if (cell->isString()) {
auto str = value.toString(globalObject)->getString(globalObject);
Expand Down Expand Up @@ -405,7 +405,7 @@ namespace ERR {

JSC::EncodedJSValue INVALID_ARG_TYPE(JSC::ThrowScope& throwScope, JSC::JSGlobalObject* globalObject, const WTF::String& arg_name, const WTF::String& expected_type, JSC::JSValue val_actual_value)
{
auto arg_kind = arg_name.startsWith("options."_s) ? "property"_s : "argument"_s;
auto arg_kind = arg_name.contains("."_s) ? "property"_s : "argument"_s;
auto ty_first_char = expected_type[0];
auto ty_kind = ty_first_char >= 'A' && ty_first_char <= 'Z' ? "an instance of"_s : "of type"_s;

Expand All @@ -420,7 +420,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 = arg_name.startsWith("options."_s) ? "property"_s : "argument"_s;
auto arg_kind = arg_name.contains("."_s) ? "property"_s : "argument"_s;

auto ty_first_char = expected_type[0];
auto ty_kind = ty_first_char >= 'A' && ty_first_char <= 'Z' ? "an instance of"_s : "of type"_s;
Expand Down Expand Up @@ -500,7 +500,7 @@ JSC::EncodedJSValue OUT_OF_RANGE(JSC::ThrowScope& throwScope, JSC::JSGlobalObjec

JSC::EncodedJSValue INVALID_ARG_VALUE(JSC::ThrowScope& throwScope, JSC::JSGlobalObject* globalObject, WTF::ASCIILiteral name, JSC::JSValue value, const WTF::String& reason)
{
ASCIILiteral type = String(name).find('.') != notFound ? "property"_s : "argument"_s;
ASCIILiteral type = String(name).contains("."_s) ? "property"_s : "argument"_s;

auto value_string = JSValueToStringSafe(globalObject, value);
RETURN_IF_EXCEPTION(throwScope, {});
Expand All @@ -509,6 +509,20 @@ JSC::EncodedJSValue INVALID_ARG_VALUE(JSC::ThrowScope& throwScope, JSC::JSGlobal
throwScope.throwException(globalObject, createError(globalObject, ErrorCode::ERR_INVALID_ARG_VALUE, message));
return {};
}
JSC::EncodedJSValue INVALID_ARG_VALUE_RangeError(JSC::ThrowScope& throwScope, JSC::JSGlobalObject* globalObject, WTF::ASCIILiteral name, JSC::JSValue value, const WTF::String& reason)
{
ASCIILiteral type = String(name).contains("."_s) ? "property"_s : "argument"_s;

auto value_string = JSValueToStringSafe(globalObject, value);
RETURN_IF_EXCEPTION(throwScope, {});

auto& vm = globalObject->vm();
auto message = makeString("The "_s, type, " '"_s, name, "' "_s, reason, ". Received "_s, value_string);
auto* structure = createErrorStructure(vm, globalObject, ErrorType::RangeError, "RangeError"_s, "ERR_INVALID_ARG_VALUE"_s);
auto error = JSC::ErrorInstance::create(vm, structure, message, jsUndefined(), nullptr, JSC::RuntimeType::TypeNothing, ErrorType::RangeError, true);
throwScope.throwException(globalObject, error);
return {};
}
JSC::EncodedJSValue INVALID_ARG_VALUE(JSC::ThrowScope& throwScope, JSC::JSGlobalObject* globalObject, JSC::JSValue name, JSC::JSValue value, const WTF::String& reason)
{
auto name_string = JSValueToStringSafe(globalObject, name);
Expand Down Expand Up @@ -551,7 +565,7 @@ JSC::EncodedJSValue BUFFER_OUT_OF_BOUNDS(JSC::ThrowScope& throwScope, JSC::JSGlo

JSC::EncodedJSValue UNKNOWN_SIGNAL(JSC::ThrowScope& throwScope, JSC::JSGlobalObject* globalObject, JSC::JSValue signal, bool triedUppercase)
{
auto signal_string = JSValueToStringSafe(globalObject, signal);
auto signal_string = signal.toWTFString(globalObject);
RETURN_IF_EXCEPTION(throwScope, {});

auto message_extra = triedUppercase ? " (signals must use all capital letters)"_s : ""_s;
Expand All @@ -574,6 +588,28 @@ JSC::EncodedJSValue SOCKET_BAD_PORT(JSC::ThrowScope& throwScope, JSC::JSGlobalOb
return {};
}

JSC::EncodedJSValue UNCAUGHT_EXCEPTION_CAPTURE_ALREADY_SET(JSC::ThrowScope& throwScope, JSC::JSGlobalObject* globalObject)
{
auto message = makeString("`process.setupUncaughtExceptionCapture()` was called while a capture callback was already active"_s);
throwScope.throwException(globalObject, createError(globalObject, ErrorCode::ERR_UNCAUGHT_EXCEPTION_CAPTURE_ALREADY_SET, message));
return {};
}

JSC::EncodedJSValue ASSERTION(JSC::ThrowScope& throwScope, JSC::JSGlobalObject* globalObject, JSC::JSValue msg)
{
auto msg_string = msg.toWTFString(globalObject);
RETURN_IF_EXCEPTION(throwScope, {});
auto message = msg_string;
throwScope.throwException(globalObject, createError(globalObject, ErrorCode::ERR_ASSERTION, message));
return {};
}
JSC::EncodedJSValue ASSERTION(JSC::ThrowScope& throwScope, JSC::JSGlobalObject* globalObject, ASCIILiteral msg)
{
auto message = msg;
throwScope.throwException(globalObject, createError(globalObject, ErrorCode::ERR_ASSERTION, message));
return {};
}

}

static JSC::JSValue ERR_INVALID_ARG_TYPE(JSC::ThrowScope& scope, JSC::JSGlobalObject* globalObject, JSValue arg0, JSValue arg1, JSValue arg2)
Expand Down Expand Up @@ -725,6 +761,11 @@ JSC_DEFINE_HOST_FUNCTION(jsFunction_ERR_UNHANDLED_ERROR, (JSC::JSGlobalObject *
return JSC::JSValue::encode(createError(globalObject, ErrorCode::ERR_UNHANDLED_ERROR, makeString("Unhandled error. ("_s, err_str, ")"_s)));
}

JSC_DEFINE_HOST_FUNCTION(jsFunction_ERR_IPC_ONE_PIPE, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* 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
5 changes: 5 additions & 0 deletions src/bun.js/bindings/ErrorCode.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ 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_UNHANDLED_ERROR);
JSC_DECLARE_HOST_FUNCTION(jsFunction_ERR_IPC_ONE_PIPE);

enum Bound {
LOWER,
Expand All @@ -84,13 +85,17 @@ JSC::EncodedJSValue OUT_OF_RANGE(JSC::ThrowScope& throwScope, JSC::JSGlobalObjec
JSC::EncodedJSValue OUT_OF_RANGE(JSC::ThrowScope& throwScope, JSC::JSGlobalObject* globalObject, JSC::JSValue arg_name_val, const WTF::String& msg, JSC::JSValue actual);
JSC::EncodedJSValue OUT_OF_RANGE(JSC::ThrowScope& throwScope, JSC::JSGlobalObject* globalObject, const WTF::String& arg_name_val, const WTF::String& msg, JSC::JSValue actual);
JSC::EncodedJSValue INVALID_ARG_VALUE(JSC::ThrowScope& throwScope, JSC::JSGlobalObject* globalObject, WTF::ASCIILiteral name, JSC::JSValue value, const WTF::String& reason = "is invalid"_s);
JSC::EncodedJSValue INVALID_ARG_VALUE_RangeError(JSC::ThrowScope& throwScope, JSC::JSGlobalObject* globalObject, WTF::ASCIILiteral name, JSC::JSValue value, const WTF::String& reason = "is invalid"_s);
JSC::EncodedJSValue INVALID_ARG_VALUE(JSC::ThrowScope& throwScope, JSC::JSGlobalObject* globalObject, JSC::JSValue name, JSC::JSValue value, const WTF::String& reason = "is invalid"_s);
JSC::EncodedJSValue UNKNOWN_ENCODING(JSC::ThrowScope& throwScope, JSC::JSGlobalObject* globalObject, const WTF::StringView encoding);
JSC::EncodedJSValue INVALID_STATE(JSC::ThrowScope& throwScope, JSC::JSGlobalObject* globalObject, const WTF::String& statemsg);
JSC::EncodedJSValue STRING_TOO_LONG(JSC::ThrowScope& throwScope, JSC::JSGlobalObject* globalObject);
JSC::EncodedJSValue BUFFER_OUT_OF_BOUNDS(JSC::ThrowScope& throwScope, JSC::JSGlobalObject* globalObject);
JSC::EncodedJSValue UNKNOWN_SIGNAL(JSC::ThrowScope& throwScope, JSC::JSGlobalObject* globalObject, JSC::JSValue signal, bool triedUppercase = false);
JSC::EncodedJSValue SOCKET_BAD_PORT(JSC::ThrowScope& throwScope, JSC::JSGlobalObject* globalObject, JSC::JSValue name, JSC::JSValue port, bool allowZero);
JSC::EncodedJSValue UNCAUGHT_EXCEPTION_CAPTURE_ALREADY_SET(JSC::ThrowScope& throwScope, JSC::JSGlobalObject* globalObject);
JSC::EncodedJSValue ASSERTION(JSC::ThrowScope& throwScope, JSC::JSGlobalObject* globalObject, JSC::JSValue msg);
JSC::EncodedJSValue ASSERTION(JSC::ThrowScope& throwScope, JSC::JSGlobalObject* globalObject, ASCIILiteral msg);

}

Expand Down
5 changes: 5 additions & 0 deletions src/bun.js/bindings/ErrorCode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ export default [
["ERR_SCRIPT_EXECUTION_TIMEOUT", Error, "Error"],
["ERR_SCRIPT_EXECUTION_INTERRUPTED", Error, "Error"],
["ERR_UNHANDLED_ERROR", Error],
["ERR_UNKNOWN_CREDENTIAL", Error],
["ERR_UNCAUGHT_EXCEPTION_CAPTURE_ALREADY_SET", Error],
["ERR_DLOPEN_FAILED", Error],
["ERR_ASSERTION", Error],
["ERR_IPC_ONE_PIPE", Error],

// Bun-specific
["ERR_FORMDATA_PARSE_ERROR", TypeError],
Expand Down
65 changes: 65 additions & 0 deletions src/bun.js/bindings/NodeValidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "JSBufferEncodingType.h"
#include "BunProcess.h"
#include "ErrorCode.h"
#include "wtf/text/ASCIILiteral.h"
#include "NodeValidator.h"

namespace Bun {
Expand Down Expand Up @@ -51,6 +52,24 @@ JSC::EncodedJSValue V::validateInteger(JSC::ThrowScope& scope, JSC::JSGlobalObje

return JSValue::encode(jsUndefined());
}
JSC::EncodedJSValue V::validateInteger(JSC::ThrowScope& scope, JSC::JSGlobalObject* globalObject, JSC::JSValue value, ASCIILiteral name, JSC::JSValue min, JSC::JSValue max)
{
if (!value.isNumber()) return Bun::ERR::INVALID_ARG_TYPE(scope, globalObject, name, "number"_s, value);
if (min.isUndefined()) min = jsDoubleNumber(JSC::minSafeInteger());
if (max.isUndefined()) max = jsDoubleNumber(JSC::maxSafeInteger());

auto value_num = value.asNumber();
auto min_num = min.toNumber(globalObject);
RETURN_IF_EXCEPTION(scope, {});
auto max_num = max.toNumber(globalObject);
RETURN_IF_EXCEPTION(scope, {});
max_num = std::max(min_num, max_num);

if (std::fmod(value_num, 1.0) != 0) return Bun::ERR::OUT_OF_RANGE(scope, globalObject, name, "an integer"_s, value);
if (value_num < min_num || value_num > max_num) return Bun::ERR::OUT_OF_RANGE(scope, globalObject, name, min_num, max_num, value);

return JSValue::encode(jsUndefined());
}

JSC_DEFINE_HOST_FUNCTION(jsFunction_validateNumber, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame))
{
Expand Down Expand Up @@ -85,6 +104,28 @@ JSC::EncodedJSValue V::validateNumber(JSC::ThrowScope& scope, JSC::JSGlobalObjec

return JSValue::encode(jsUndefined());
}
JSC::EncodedJSValue V::validateNumber(JSC::ThrowScope& scope, JSC::JSGlobalObject* globalObject, JSValue value, ASCIILiteral name, JSValue min, JSValue max)
{
if (!value.isNumber()) return Bun::ERR::INVALID_ARG_TYPE(scope, globalObject, name, "number"_s, value);

auto value_num = value.asNumber();
auto min_num = min.toNumber(globalObject);
RETURN_IF_EXCEPTION(scope, {});
auto max_num = max.toNumber(globalObject);
RETURN_IF_EXCEPTION(scope, {});

auto min_isnonnull = !min.isUndefinedOrNull();
auto max_isnonnull = !max.isUndefinedOrNull();

if ((min_isnonnull && value_num < min_num) || (max_isnonnull && value_num > max_num) || ((min_isnonnull || max_isnonnull) && std::isnan(value_num))) {
if (min_isnonnull && max_isnonnull) return Bun::ERR::OUT_OF_RANGE(scope, globalObject, name, min_num, max_num, value);
if (min_isnonnull) return Bun::ERR::OUT_OF_RANGE(scope, globalObject, name, min_num, Bun::LOWER, value);
if (max_isnonnull) return Bun::ERR::OUT_OF_RANGE(scope, globalObject, name, max_num, Bun::UPPER, value);
return Bun::ERR::OUT_OF_RANGE(scope, globalObject, name, ""_s, value);
}

return JSValue::encode(jsUndefined());
}

JSC_DEFINE_HOST_FUNCTION(jsFunction_validateString, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame))
{
Expand Down Expand Up @@ -297,6 +338,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 @@ -348,7 +394,26 @@ 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);

auto value_num = value.asNumber();
if (std::fmod(value_num, 1.0) != 0) return Bun::ERR::OUT_OF_RANGE(scope, globalObject, name, "an integer"_s, value);

auto positive_b = positive.toBoolean(globalObject);
RETURN_IF_EXCEPTION(scope, {});
auto min = positive_b ? 1 : 0;
auto max = std::numeric_limits<uint32_t>().max();
if (value_num < min || value_num > max) return Bun::ERR::OUT_OF_RANGE(scope, globalObject, name, min, max, value);

return JSValue::encode(jsUndefined());
}
JSC::EncodedJSValue V::validateUint32(JSC::ThrowScope& scope, JSC::JSGlobalObject* globalObject, JSValue value, ASCIILiteral 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
6 changes: 6 additions & 0 deletions src/bun.js/bindings/NodeValidator.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "ZigGlobalObject.h"
#include "ErrorCode.h"
#include "JavaScriptCore/JSCJSValue.h"
#include "wtf/text/ASCIILiteral.h"

namespace Bun {

Expand All @@ -27,10 +28,15 @@ JSC_DEFINE_HOST_FUNCTION(jsFunction_validateBuffer, (JSC::JSGlobalObject * globa
namespace V {

JSC::EncodedJSValue validateInteger(JSC::ThrowScope& scope, JSC::JSGlobalObject* globalObject, JSC::JSValue value, JSC::JSValue name, JSC::JSValue min, JSC::JSValue max);
JSC::EncodedJSValue validateInteger(JSC::ThrowScope& scope, JSC::JSGlobalObject* globalObject, JSC::JSValue value, ASCIILiteral name, JSC::JSValue min, JSC::JSValue max);
JSC::EncodedJSValue validateNumber(JSC::ThrowScope& scope, JSC::JSGlobalObject* globalObject, JSC::JSValue value, JSC::JSValue name, JSC::JSValue min, JSC::JSValue max);
JSC::EncodedJSValue validateNumber(JSC::ThrowScope& scope, JSC::JSGlobalObject* globalObject, JSValue value, ASCIILiteral name, JSValue min, 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 validateString(JSC::ThrowScope& scope, JSC::JSGlobalObject* globalObject, JSValue value, ASCIILiteral 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);
JSC::EncodedJSValue validateUint32(JSC::ThrowScope& scope, JSC::JSGlobalObject* globalObject, JSValue value, ASCIILiteral 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
23 changes: 10 additions & 13 deletions src/bun.js/bindings/bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1947,26 +1947,23 @@ JSC__JSValue SystemError__toErrorInstance(const SystemError* arg0,

JSC::JSValue options = JSC::jsUndefined();

JSC::JSObject* result = JSC::ErrorInstance::create(globalObject, globalObject->errorStructureWithErrorType<JSC::ErrorType::Error>(), message, options);
JSC::JSObject* result = JSC::ErrorInstance::create(globalObject, JSC::ErrorInstance::createStructure(vm, globalObject, globalObject->errorPrototype()), message, options);

auto clientData = WebCore::clientData(vm);

if (err.code.tag != BunStringTag::Empty) {
JSC::JSValue code = Bun::toJS(globalObject, err.code);
result->putDirect(vm, names.codePublicName(), code,
JSC::PropertyAttribute::DontDelete | 0);

result->putDirect(vm, vm.propertyNames->name, code, JSC::PropertyAttribute::DontEnum | 0);
} else {
auto* domGlobalObject = defaultGlobalObject(globalObject);
result->putDirect(
vm, vm.propertyNames->name,
JSC::JSValue(domGlobalObject->commonStrings().SystemErrorString(domGlobalObject)),
JSC::PropertyAttribute::DontEnum | 0);
result->putDirect(vm, clientData->builtinNames().codePublicName(), code, JSC::PropertyAttribute::DontDelete | 0);
}

if (err.path.tag != BunStringTag::Empty) {
JSC::JSValue path = Bun::toJS(globalObject, err.path);
result->putDirect(vm, names.pathPublicName(), path,
JSC::PropertyAttribute::DontDelete | 0);
result->putDirect(vm, clientData->builtinNames().pathPublicName(), path, JSC::PropertyAttribute::DontDelete | 0);
}

if (err.dest.tag != BunStringTag::Empty) {
JSC::JSValue dest = Bun::toJS(globalObject, err.dest);
result->putDirect(vm, clientData->builtinNames().destPublicName(), dest, JSC::PropertyAttribute::DontDelete | 0);
}

if (err.fd != -1) {
Expand Down
Loading
Loading