aboutsummaryrefslogtreecommitdiff
path: root/src/bun.js/api/server.zig
diff options
context:
space:
mode:
authorGravatar Ciro Spaciari <ciro.spaciari@gmail.com> 2023-06-14 23:29:36 -0300
committerGravatar GitHub <noreply@github.com> 2023-06-14 19:29:36 -0700
commite6d4b3a89ac6631f54276a21d82d41f91fd41c76 (patch)
tree17308fa0b27544c5590d111ceea7b46d79803681 /src/bun.js/api/server.zig
parent0f131a976e637669ab3ac44f53af6227a24f6900 (diff)
downloadbun-e6d4b3a89ac6631f54276a21d82d41f91fd41c76.tar.gz
bun-e6d4b3a89ac6631f54276a21d82d41f91fd41c76.tar.zst
bun-e6d4b3a89ac6631f54276a21d82d41f91fd41c76.zip
[Bun.serve] fix `Bun.serve` argument check (#3314)
* fixup checks * throw when tls is not a object also fix socket * fix error message * null or undefined on tls option in Bun.serve or sockets should not throw * add tests * fix tests and socket validation * remove unnecessary check * add listen tests
Diffstat (limited to 'src/bun.js/api/server.zig')
-rw-r--r--src/bun.js/api/server.zig10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/bun.js/api/server.zig b/src/bun.js/api/server.zig
index 8fd9acde7..37bc601a5 100644
--- a/src/bun.js/api/server.zig
+++ b/src/bun.js/api/server.zig
@@ -270,6 +270,11 @@ pub const ServerConfig = struct {
pub fn inJS(global: *JSC.JSGlobalObject, obj: JSC.JSValue, exception: JSC.C.ExceptionRef) ?SSLConfig {
var result = zero;
+ if (!obj.isObject()) {
+ JSC.throwInvalidArguments("tls option expects an object", .{}, global, exception);
+ return null;
+ }
+
var any = false;
// Required
@@ -688,7 +693,7 @@ pub const ServerConfig = struct {
}
if (arguments.next()) |arg| {
- if (arg.isUndefinedOrNull() or !arg.isObject()) {
+ if (!arg.isObject()) {
JSC.throwInvalidArguments("Bun.serve expects an object", .{}, global, exception);
return args;
}
@@ -812,6 +817,9 @@ pub const ServerConfig = struct {
}
return args;
}
+ } else {
+ JSC.throwInvalidArguments("Bun.serve expects an object", .{}, global, exception);
+ return args;
}
if (args.base_uri.len > 0) {