Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
11 changes: 10 additions & 1 deletion src/js/node/os.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,16 @@ function bound(binding) {
: $bundleError("TODO: type");
},
uptime: binding.uptime,
userInfo: binding.userInfo,
userInfo: function userInfo(options) {
// node ignores a non-object `options` and a non-string `options.encoding`
// (lib/os.js + node_os.cc `GetUserInfo`).
let encoding;
if (typeof options === "object" && options !== null) {
const value = options.encoding;
if (typeof value === "string") encoding = value;
}
return binding.userInfo(encoding);
},
version: binding.version,
machine: function () {
// TODO: linux arm64 should also return "aarch64" (Node/uname compat) —
Expand Down
2 changes: 1 addition & 1 deletion src/libuv_sys/libuv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3168,7 +3168,7 @@ unsafe extern "C" {
pub fn uv_getrusage(rusage: *mut uv_rusage_t) -> c_int;
pub fn uv_os_homedir(buffer: *mut u8, size: *mut usize) -> ReturnCode;
pub fn uv_os_tmpdir(buffer: *mut u8, size: *mut usize) -> c_int;
pub fn uv_os_get_passwd(pwd: *mut uv_passwd_t) -> c_int;
pub fn uv_os_get_passwd(pwd: *mut uv_passwd_t) -> ReturnCode;
pub fn uv_os_free_passwd(pwd: *mut uv_passwd_t);
pub fn uv_os_get_passwd2(pwd: *mut uv_passwd_t, uid: uv_uid_t) -> c_int;
pub fn uv_os_get_group(grp: *mut uv_group_t, gid: uv_uid_t) -> c_int;
Expand Down
12 changes: 6 additions & 6 deletions src/runtime/hw_exports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -632,18 +632,18 @@ pub fn bindgen_node_os_dispatch_uptime(global: &JSGlobalObject, out: *mut f64) -
}

/// # Safety
/// `arg_options` must be a valid C++ stack local.
/// `arg_encoding` must be a valid C++ stack local.
// HOST_EXPORT(bindgen_Node_os_dispatchUserInfo1, c)
// Called only from the generated `extern "C"` thunk; C++ guarantees non-null stack locals.
#[allow(clippy::not_unsafe_ptr_arg_deref)]
pub fn bindgen_node_os_dispatch_user_info(
global: &JSGlobalObject,
arg_options: *const crate::node::os::gen_::UserInfoOptions,
arg_encoding: *const bun_core::String,
) -> JSValue {
// SAFETY: `arg_options` is a valid C++ stack local; `UserInfoOptions` is
// `#[repr(C)]` matching the bindgen `extern struct`.
let options = unsafe { core::ptr::read(arg_options) };
bun_jsc::host_fn::to_js_host_call(global, || node_os::user_info(global, &options))
// SAFETY: `arg_encoding` is a valid C++ stack local, borrowed (not owned)
// for the duration of the call.
let encoding = unsafe { &*arg_encoding };
bun_jsc::host_fn::to_js_host_call(global, || node_os::user_info(global, encoding))
}

// HOST_EXPORT(bindgen_Node_os_dispatchVersion1, c)
Expand Down
8 changes: 4 additions & 4 deletions src/runtime/node/node_os.bind.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ export const uptime = fn({
},
ret: t.f64,
});
export const UserInfoOptions = t.dictionary({
encoding: t.DOMString.default(""),
});
// The `options` object itself is unwrapped in `src/js/node/os.ts`, matching
// node's `lib/os.js` + `GetUserInfo`: non-object options and non-string
// `encoding` values are ignored rather than rejected.
export const userInfo = fn({
args: {
global: t.globalObject,
options: UserInfoOptions.default({}),
encoding: t.DOMString.default(""),
},
ret: t.any,
});
Expand Down
Loading
Loading