diff options
Diffstat (limited to 'src/bun.js')
-rw-r--r-- | src/bun.js/javascript.zig | 10 | ||||
-rw-r--r-- | src/bun.js/webcore/streams.zig | 29 |
2 files changed, 30 insertions, 9 deletions
diff --git a/src/bun.js/javascript.zig b/src/bun.js/javascript.zig index 38677c03d..d9cfcaac3 100644 --- a/src/bun.js/javascript.zig +++ b/src/bun.js/javascript.zig @@ -1848,8 +1848,11 @@ pub const VirtualMachine = struct { const message = exception.message; var did_print_name = false; - if (source_lines.next()) |source| { - if (source.text.len > 0 and exception.stack.frames()[0].position.isInvalid()) { + if (source_lines.next()) |source| brk: { + if (source.text.len == 0) break :brk; + + const top_frame = if (exception.stack.frames_len > 0) exception.stack.frames()[0] else null; + if (top_frame == null or top_frame.?.position.isInvalid()) { defer did_print_name = true; var text = std.mem.trim(u8, source.text, "\n"); @@ -1864,12 +1867,11 @@ pub const VirtualMachine = struct { ); try this.printErrorNameAndMessage(name, message, Writer, writer, allow_ansi_color); - } else if (source.text.len > 0) { + } else if (top_frame) |top| { defer did_print_name = true; const int_size = std.fmt.count("{d}", .{source.line}); const pad = max_line_number_pad - int_size; try writer.writeByteNTimes(' ', pad); - const top = exception.stack.frames()[0]; var remainder = std.mem.trim(u8, source.text, "\n"); try writer.print( diff --git a/src/bun.js/webcore/streams.zig b/src/bun.js/webcore/streams.zig index ab859c31c..8fc6a29f7 100644 --- a/src/bun.js/webcore/streams.zig +++ b/src/bun.js/webcore/streams.zig @@ -2028,14 +2028,13 @@ pub fn NewJSSink(comptime SinkType: type, comptime name_: []const u8) type { const args_list = callframe.arguments(4); const args = args_list.ptr[0..args_list.len]; - if (args.len == 0 or args[0].isEmptyOrUndefinedOrNull() or args[0].isNumber()) { - const err = JSC.toTypeError( - if (args.len == 0) JSC.Node.ErrorCode.ERR_MISSING_ARGS else JSC.Node.ErrorCode.ERR_INVALID_ARG_TYPE, + if (args.len == 0) { + globalThis.vm().throwError(globalThis, JSC.toTypeError( + JSC.Node.ErrorCode.ERR_MISSING_ARGS, "write() expects a string, ArrayBufferView, or ArrayBuffer", .{}, globalThis, - ); - globalThis.vm().throwError(globalThis, err); + )); return JSC.JSValue.jsUndefined(); } @@ -2043,6 +2042,16 @@ pub fn NewJSSink(comptime SinkType: type, comptime name_: []const u8) type { arg.ensureStillAlive(); defer arg.ensureStillAlive(); + if (arg.isEmptyOrUndefinedOrNull()) { + globalThis.vm().throwError(globalThis, JSC.toTypeError( + JSC.Node.ErrorCode.ERR_STREAM_NULL_VALUES, + "write() expects a string, ArrayBufferView, or ArrayBuffer", + .{}, + globalThis, + )); + return JSC.JSValue.jsUndefined(); + } + if (arg.asArrayBuffer(globalThis)) |buffer| { const slice = buffer.slice(); if (slice.len == 0) { @@ -2052,6 +2061,16 @@ pub fn NewJSSink(comptime SinkType: type, comptime name_: []const u8) type { return this.sink.writeBytes(.{ .temporary = bun.ByteList.init(slice) }).toJS(globalThis); } + if (!arg.isString()) { + globalThis.vm().throwError(globalThis, JSC.toTypeError( + JSC.Node.ErrorCode.ERR_INVALID_ARG_TYPE, + "write() expects a string, ArrayBufferView, or ArrayBuffer", + .{}, + globalThis, + )); + return JSC.JSValue.jsUndefined(); + } + const str = arg.getZigString(globalThis); if (str.len == 0) { return JSC.JSValue.jsNumber(0); |