aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/bun.js/bindings/ZigGlobalObject.cpp18
-rw-r--r--src/bun.js/bindings/bindings.zig26
-rw-r--r--src/bun.js/javascript_core_c_api.zig3
-rw-r--r--src/bun_js.zig2
-rw-r--r--src/cli/test_command.zig2
-rw-r--r--src/http.zig4
6 files changed, 47 insertions, 8 deletions
diff --git a/src/bun.js/bindings/ZigGlobalObject.cpp b/src/bun.js/bindings/ZigGlobalObject.cpp
index c4b63869e..7878b96a7 100644
--- a/src/bun.js/bindings/ZigGlobalObject.cpp
+++ b/src/bun.js/bindings/ZigGlobalObject.cpp
@@ -181,7 +181,7 @@ constexpr size_t DEFAULT_ERROR_STACK_TRACE_LIMIT = 10;
// #include <iostream>
static bool has_loaded_jsc = false;
-extern "C" void JSCInitialize()
+extern "C" void JSCInitialize(const char* envp[], size_t envc, void (*onCrash)(const char* ptr, size_t length))
{
if (has_loaded_jsc)
return;
@@ -208,6 +208,22 @@ extern "C" void JSCInitialize()
JSC::Options::useResizableArrayBuffer() = true;
JSC::Options::showPrivateScriptsInStackTraces() = true;
JSC::Options::useSetMethods() = true;
+
+ if (LIKELY(envc > 0)) {
+ while (envc--) {
+ const char* env = (const char*)envp[envc];
+ // need to check for \0 so we might as well make this single pass
+ // strlen would check the end of the string
+ if (LIKELY(!(env[0] == 'B' && env[1] == 'U' && env[2] == 'N' && env[3] == '_' && env[4] == 'J' && env[5] == 'S' && env[6] == 'C' && env[7] == '_'))) {
+ continue;
+ }
+
+ if (UNLIKELY(!JSC::Options::setOption(env + 8))) {
+ onCrash(env, strlen(env));
+ }
+ }
+ }
+
JSC::Options::assertOptionsAreCoherent();
}
}
diff --git a/src/bun.js/bindings/bindings.zig b/src/bun.js/bindings/bindings.zig
index 1479ef977..5529db27d 100644
--- a/src/bun.js/bindings/bindings.zig
+++ b/src/bun.js/bindings/bindings.zig
@@ -4720,3 +4720,29 @@ pub const DOMCalls = .{
@import("../api/bun.zig").FFI.Reader,
@import("../webcore.zig").Crypto,
};
+
+extern "c" fn JSCInitialize(env: [*]const [*:0]u8, count: usize, cb: *const fn ([*]const u8, len: usize) callconv(.C) void) void;
+pub fn initialize() void {
+ JSCInitialize(
+ std.os.environ.ptr,
+ std.os.environ.len,
+ struct {
+ pub fn callback(name: [*]const u8, len: usize) callconv(.C) void {
+ Output.prettyErrorln(
+ \\<r><red>error<r><d>:<r> invalid JSC environment variable
+ \\
+ \\ <b>{s}<r>
+ \\
+ \\For a list of options, see this file:
+ \\
+ \\ https://github.com/oven-sh/webkit/blob/main/Source/JavaScriptCore/runtime/OptionsList.h
+ \\
+ \\Environment variables must be prefixed with "BUN_JSC_". This code runs before .env files are loaded, so those won't work here.
+ \\
+ \\Warning: options change between releases of Bun and WebKit without notice. This is not a stable API, you should not rely on it beyond debugging something, and it may be removed entirely in a future version of Bun.
+ , .{name[0..len]});
+ bun.Global.exit(1);
+ }
+ }.callback,
+ );
+}
diff --git a/src/bun.js/javascript_core_c_api.zig b/src/bun.js/javascript_core_c_api.zig
index a0c9fc29e..32414829b 100644
--- a/src/bun.js/javascript_core_c_api.zig
+++ b/src/bun.js/javascript_core_c_api.zig
@@ -515,7 +515,4 @@ const JSStringIterator_ = extern struct {
write16: JStringIteratorWriteCallback,
};
-// not official api functions
-pub extern "c" fn JSCInitialize() void;
-
pub extern "c" fn JSObjectGetProxyTarget(JSObjectRef) JSObjectRef;
diff --git a/src/bun_js.zig b/src/bun_js.zig
index 30ed20a26..f13568390 100644
--- a/src/bun_js.zig
+++ b/src/bun_js.zig
@@ -47,7 +47,7 @@ pub const Run = struct {
pub fn boot(ctx_: Command.Context, file: std.fs.File, entry_path: string) !void {
var ctx = ctx_;
JSC.markBinding(@src());
- @import("bun.js/javascript_core_c_api.zig").JSCInitialize();
+ bun.JSC.initialize();
js_ast.Expr.Data.Store.create(default_allocator);
js_ast.Stmt.Data.Store.create(default_allocator);
diff --git a/src/cli/test_command.zig b/src/cli/test_command.zig
index a7b7b237c..445398fea 100644
--- a/src/cli/test_command.zig
+++ b/src/cli/test_command.zig
@@ -362,7 +362,7 @@ pub const TestCommand = struct {
loader.* = DotEnv.Loader.init(map, ctx.allocator);
break :brk loader;
};
- JSC.C.JSCInitialize();
+ bun.JSC.initialize();
HTTPThread.init() catch {};
var reporter = try ctx.allocator.create(CommandLineReporter);
diff --git a/src/http.zig b/src/http.zig
index 746e843b9..6b34adac4 100644
--- a/src/http.zig
+++ b/src/http.zig
@@ -1461,7 +1461,7 @@ pub const RequestContext = struct {
handler.start_timer = std.time.Timer.start() catch unreachable;
Output.Source.configureThread();
- @import("bun.js/javascript_core_c_api.zig").JSCInitialize();
+ bun.JSC.initialize();
js_ast.Stmt.Data.Store.create(bun.default_allocator);
js_ast.Expr.Data.Store.create(bun.default_allocator);
@@ -3506,7 +3506,7 @@ pub const Server = struct {
const addr = listener.listen_address;
if (server.bundler.options.origin.getPort() != addr.getPort()) {
- server.bundler.options.origin = ZigURL.parse(try std.fmt.allocPrint(server.allocator, "{s}://{s}:{d}", .{server.bundler.options.origin.displayProtocol(), server.bundler.options.origin.displayHostname(), addr.getPort()}));
+ server.bundler.options.origin = ZigURL.parse(try std.fmt.allocPrint(server.allocator, "{s}://{s}:{d}", .{ server.bundler.options.origin.displayProtocol(), server.bundler.options.origin.displayHostname(), addr.getPort() }));
}
const start_time = Global.getStartTime();