diff --git a/src/bun.js/api/server.zig b/src/bun.js/api/server.zig index 6e46728936..c9ecf0b5d8 100644 --- a/src/bun.js/api/server.zig +++ b/src/bun.js/api/server.zig @@ -861,28 +861,6 @@ pub const ServerConfig = struct { } } - if (arg.getTruthy(global, "tls")) |tls| { - if (SSLConfig.inJS(global, tls, exception)) |ssl_config| { - args.ssl_config = ssl_config; - } - - if (exception.* != null) { - return args; - } - } - - // @compatibility Bun v0.x - v0.2.1 - // this used to be top-level, now it's "tls" object - if (args.ssl_config == null) { - if (SSLConfig.inJS(global, arg, exception)) |ssl_config| { - args.ssl_config = ssl_config; - } - - if (exception.* != null) { - return args; - } - } - if (arg.getTruthy(global, "maxRequestBodySize")) |max_request_body_size| { if (max_request_body_size.isNumber()) { args.max_request_body_size = @as(u64, @intCast(@max(0, max_request_body_size.toInt64()))); @@ -917,6 +895,36 @@ pub const ServerConfig = struct { } return args; } + + if (arg.getTruthy(global, "tls")) |tls| { + if (SSLConfig.inJS(global, tls, exception)) |ssl_config| { + args.ssl_config = ssl_config; + } + + if (exception.* != null) { + return args; + } + + if (global.hasException()) { + return args; + } + } + + // @compatibility Bun v0.x - v0.2.1 + // this used to be top-level, now it's "tls" object + if (args.ssl_config == null) { + if (SSLConfig.inJS(global, arg, exception)) |ssl_config| { + args.ssl_config = ssl_config; + } + + if (exception.* != null) { + return args; + } + + if (global.hasException()) { + return args; + } + } } else { JSC.throwInvalidArguments("Bun.serve expects an object", .{}, global, exception); return args; diff --git a/src/bun.js/bindings/bindings.cpp b/src/bun.js/bindings/bindings.cpp index 369b84c3a4..fd7d8ae4c3 100644 --- a/src/bun.js/bindings/bindings.cpp +++ b/src/bun.js/bindings/bindings.cpp @@ -5351,3 +5351,8 @@ extern "C" EncodedJSValue ExpectStatic__getPrototype(JSC::JSGlobalObject* global { return JSValue::encode(reinterpret_cast(globalObject)->JSExpectStaticPrototype()); } + +extern "C" bool JSGlobalObject__hasException(JSC::JSGlobalObject* globalObject) +{ + return DECLARE_CATCH_SCOPE(globalObject->vm()).exception() != 0; +} diff --git a/src/bun.js/bindings/bindings.zig b/src/bun.js/bindings/bindings.zig index 969dcdf150..a47ebaa7ab 100644 --- a/src/bun.js/bindings/bindings.zig +++ b/src/bun.js/bindings/bindings.zig @@ -2922,6 +2922,11 @@ pub const JSGlobalObject = extern struct { return cppFn("getCachedObject", .{ this, key }); } + extern fn JSGlobalObject__hasException(*JSGlobalObject) bool; + pub fn hasException(this: *JSGlobalObject) bool { + return JSGlobalObject__hasException(this); + } + pub fn vm(this: *JSGlobalObject) *VM { return cppFn("vm", .{this}); }