Skip to content
Merged
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
13 changes: 13 additions & 0 deletions src/bun.js/node/node_os.zig
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pub const Os = struct {
module.put(globalObject, JSC.ZigString.static("homedir"), JSC.NewFunction(globalObject, JSC.ZigString.static("homedir"), 0, homedir, true));
module.put(globalObject, JSC.ZigString.static("hostname"), JSC.NewFunction(globalObject, JSC.ZigString.static("hostname"), 0, hostname, true));
module.put(globalObject, JSC.ZigString.static("loadavg"), JSC.NewFunction(globalObject, JSC.ZigString.static("loadavg"), 0, loadavg, true));
module.put(globalObject, JSC.ZigString.static("machine"), JSC.NewFunction(globalObject, JSC.ZigString.static("machine"), 0, machine, true));
module.put(globalObject, JSC.ZigString.static("networkInterfaces"), JSC.NewFunction(globalObject, JSC.ZigString.static("networkInterfaces"), 0, networkInterfaces, true));
module.put(globalObject, JSC.ZigString.static("platform"), JSC.NewFunction(globalObject, JSC.ZigString.static("platform"), 0, platform, true));
module.put(globalObject, JSC.ZigString.static("release"), JSC.NewFunction(globalObject, JSC.ZigString.static("release"), 0, release, true));
Expand Down Expand Up @@ -289,6 +290,18 @@ pub const Os = struct {
});
}

pub fn machine(globalThis: *JSC.JSGlobalObject, _: *JSC.CallFrame) callconv(.C) JSC.JSValue {
JSC.markBinding(@src());

const machine_name = if (comptime Environment.isLinux) b: {
const uts = std.os.uname();
break :b std.mem.span(&uts.machine);
}
else "unknown";

return JSC.ZigString.init(machine_name).withEncoding().toValueGC(globalThis);
}

pub fn networkInterfaces(globalThis: *JSC.JSGlobalObject, _: *JSC.CallFrame) callconv(.C) JSC.JSValue {
JSC.markBinding(@src());

Expand Down
2 changes: 2 additions & 0 deletions src/bun.js/os.exports.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ function bound(obj) {
homedir: obj.homedir.bind(obj),
hostname: obj.hostname.bind(obj),
loadavg: obj.loadavg.bind(obj),
machine: obj.machine.bind(obj),
networkInterfaces: obj.networkInterfaces.bind(obj),
platform: obj.platform.bind(obj),
release: obj.release.bind(obj),
Expand Down Expand Up @@ -35,6 +36,7 @@ export var {
homedir,
hostname,
loadavg,
machine,
networkInterfaces,
platform,
release,
Expand Down
4 changes: 4 additions & 0 deletions test/bun.js/os.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ it("networkInterfaces", () => {
}
});

it("machine", () => {
expect(os.machine().length > 1).toBe(true);
});

it("EOL", () => {
if (process.platform === "win32") expect(os.EOL).toBe("\\r\\n");
else expect(os.EOL).toBe("\n");
Expand Down