diff options
author | 2023-06-17 19:18:02 -0700 | |
---|---|---|
committer | 2023-06-17 19:18:02 -0700 | |
commit | 65f1e426849aa705c0fd7578134b8287f10d0176 (patch) | |
tree | 134aed84da5b4bf2310a2c8dd6a9f411e9572ba4 /src/bun.js/api | |
parent | b0e8f596a2a3a5bd3f70d6d03de35c290d34d35c (diff) | |
parent | 065713aeca2ae3013bdf5b3d2f04263459631598 (diff) | |
download | bun-jarred/simplify.tar.gz bun-jarred/simplify.tar.zst bun-jarred/simplify.zip |
Merge branch 'main' into jarred/simplifyjarred/simplify
Diffstat (limited to 'src/bun.js/api')
-rw-r--r-- | src/bun.js/api/bun.zig | 17 | ||||
-rw-r--r-- | src/bun.js/api/bun/socket.zig | 16 | ||||
-rw-r--r-- | src/bun.js/api/server.zig | 10 |
3 files changed, 19 insertions, 24 deletions
diff --git a/src/bun.js/api/bun.zig b/src/bun.js/api/bun.zig index d3ef6919a..5580e8840 100644 --- a/src/bun.js/api/bun.zig +++ b/src/bun.js/api/bun.zig @@ -440,7 +440,7 @@ pub fn getAssetPrefix( _: js.JSStringRef, _: js.ExceptionRef, ) js.JSValueRef { - return ZigString.init(VirtualMachine.get().bundler.options.routes.asset_prefix_path).toValue(ctx.ptr()).asRef(); + return ZigString.init(VirtualMachine.get().bundler.options.routes.asset_prefix_path).toValueGC(ctx.ptr()).asRef(); } pub fn getArgv( @@ -450,19 +450,8 @@ pub fn getArgv( _: js.JSStringRef, _: js.ExceptionRef, ) js.JSValueRef { - if (comptime Environment.isWindows) { - @compileError("argv not supported on windows"); - } - - var argv_list = std.heap.stackFallback(128, getAllocator(ctx)); - var allocator = argv_list.get(); - var argv = allocator.alloc(ZigString, std.os.argv.len) catch unreachable; - defer if (argv.len > 128) allocator.free(argv); - for (std.os.argv, 0..) |arg, i| { - argv[i] = ZigString.init(std.mem.span(arg)); - } - - return JSValue.createStringArray(ctx.ptr(), argv.ptr, argv.len, true).asObjectRef(); + // TODO: cache this + return JSC.Node.Process.getArgv(ctx).asObjectRef(); } pub fn getRoutesDir( diff --git a/src/bun.js/api/bun/socket.zig b/src/bun.js/api/bun/socket.zig index 780bfcb14..48bfe4218 100644 --- a/src/bun.js/api/bun/socket.zig +++ b/src/bun.js/api/bun/socket.zig @@ -254,19 +254,17 @@ pub const SocketConfig = struct { var ssl: ?JSC.API.ServerConfig.SSLConfig = null; var default_data = JSValue.zero; - if (opts.getTruthy(globalObject, "tls")) |tls| outer: { + if (opts.getTruthy(globalObject, "tls")) |tls| { if (tls.isBoolean()) { if (tls.toBoolean()) { ssl = JSC.API.ServerConfig.SSLConfig.zero; } - - break :outer; - } - - if (JSC.API.ServerConfig.SSLConfig.inJS(globalObject, tls, exception)) |ssl_config| { - ssl = ssl_config; - } else if (exception.* != null) { - return null; + } else { + if (JSC.API.ServerConfig.SSLConfig.inJS(globalObject, tls, exception)) |ssl_config| { + ssl = ssl_config; + } else if (exception.* != null) { + return null; + } } } 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) { |