mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 18:38:55 +00:00
88 lines
3.7 KiB
Zig
88 lines
3.7 KiB
Zig
const std = @import("std");
|
|
const bun = @import("root").bun;
|
|
const C = bun.c;
|
|
const Environment = bun.Environment;
|
|
const JSC = bun.JSC;
|
|
const string = bun.string;
|
|
const Output = bun.Output;
|
|
const ZigString = JSC.ZigString;
|
|
|
|
//
|
|
//
|
|
|
|
pub var autoSelectFamilyDefault: bool = true;
|
|
|
|
pub fn getDefaultAutoSelectFamily(global: *JSC.JSGlobalObject) JSC.JSValue {
|
|
return JSC.JSFunction.create(global, "getDefaultAutoSelectFamily", (struct {
|
|
fn getter(globalThis: *JSC.JSGlobalObject, callframe: *JSC.CallFrame) bun.JSError!JSC.JSValue {
|
|
_ = globalThis;
|
|
_ = callframe;
|
|
return JSC.jsBoolean(autoSelectFamilyDefault);
|
|
}
|
|
}).getter, 0, .{});
|
|
}
|
|
|
|
pub fn setDefaultAutoSelectFamily(global: *JSC.JSGlobalObject) JSC.JSValue {
|
|
return JSC.JSFunction.create(global, "setDefaultAutoSelectFamily", (struct {
|
|
fn setter(globalThis: *JSC.JSGlobalObject, callframe: *JSC.CallFrame) bun.JSError!JSC.JSValue {
|
|
const arguments = callframe.arguments_old(1);
|
|
if (arguments.len < 1) {
|
|
return globalThis.throw("missing argument", .{});
|
|
}
|
|
const arg = arguments.slice()[0];
|
|
if (!arg.isBoolean()) {
|
|
return globalThis.throwInvalidArguments("autoSelectFamilyDefault", .{});
|
|
}
|
|
const value = arg.toBoolean();
|
|
autoSelectFamilyDefault = value;
|
|
return JSC.jsBoolean(value);
|
|
}
|
|
}).setter, 1, .{});
|
|
}
|
|
|
|
/// This is only used to provide the getDefaultAutoSelectFamilyAttemptTimeout and
|
|
/// setDefaultAutoSelectFamilyAttemptTimeout functions, not currently read by any other code. It's
|
|
/// `threadlocal` because Node.js expects each Worker to have its own copy of this, and currently
|
|
/// it can only be accessed by accessor functions which run on each Worker's main JavaScript thread.
|
|
///
|
|
/// If this becomes used in more places, and especially if it can be read by other threads, we may
|
|
/// need to store it as a field in the VirtualMachine instead of in a `threadlocal`.
|
|
pub threadlocal var autoSelectFamilyAttemptTimeoutDefault: u32 = 250;
|
|
|
|
pub fn getDefaultAutoSelectFamilyAttemptTimeout(global: *JSC.JSGlobalObject) JSC.JSValue {
|
|
return JSC.JSFunction.create(global, "getDefaultAutoSelectFamilyAttemptTimeout", (struct {
|
|
fn getter(globalThis: *JSC.JSGlobalObject, callframe: *JSC.CallFrame) bun.JSError!JSC.JSValue {
|
|
_ = globalThis;
|
|
_ = callframe;
|
|
return JSC.jsNumber(autoSelectFamilyAttemptTimeoutDefault);
|
|
}
|
|
}).getter, 0, .{});
|
|
}
|
|
|
|
pub fn setDefaultAutoSelectFamilyAttemptTimeout(global: *JSC.JSGlobalObject) JSC.JSValue {
|
|
return JSC.JSFunction.create(global, "setDefaultAutoSelectFamilyAttemptTimeout", (struct {
|
|
fn setter(globalThis: *JSC.JSGlobalObject, callframe: *JSC.CallFrame) bun.JSError!JSC.JSValue {
|
|
const arguments = callframe.arguments_old(1);
|
|
if (arguments.len < 1) {
|
|
return globalThis.throw("missing argument", .{});
|
|
}
|
|
const arg = arguments.slice()[0];
|
|
if (!arg.isInt32AsAnyInt()) {
|
|
return globalThis.throwInvalidArguments("autoSelectFamilyAttemptTimeoutDefault", .{});
|
|
}
|
|
const value: u32 = @max(10, arg.coerceToInt32(globalThis));
|
|
autoSelectFamilyAttemptTimeoutDefault = value;
|
|
return JSC.jsNumber(value);
|
|
}
|
|
}).setter, 1, .{});
|
|
}
|
|
|
|
pub fn createBinding(global: *JSC.JSGlobalObject) JSC.JSValue {
|
|
const SocketAddress = bun.JSC.GeneratedClassesList.SocketAddress;
|
|
const net = JSC.JSValue.createEmptyObjectWithNullPrototype(global);
|
|
|
|
net.put(global, "SocketAddress", SocketAddress.getConstructor(global));
|
|
|
|
return net;
|
|
}
|