aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Jarred SUmner <jarred@jarredsumner.com> 2022-03-22 04:44:39 -0700
committerGravatar Jarred SUmner <jarred@jarredsumner.com> 2022-03-22 04:44:39 -0700
commit9974142eef9909866128951f64f4beb8a9617db7 (patch)
treefe1f5a698ec0d2a55ebe55e86105017274d5b163
parent6e9be9f1cc4cc91dd0ac7b7c4ea1efd9f17b8ea3 (diff)
downloadbun-9974142eef9909866128951f64f4beb8a9617db7.tar.gz
bun-9974142eef9909866128951f64f4beb8a9617db7.tar.zst
bun-9974142eef9909866128951f64f4beb8a9617db7.zip
Handle integer sizes greater than i32
-rw-r--r--src/deps/uws.zig2
-rw-r--r--src/javascript/jsc/api/bun.zig18
-rw-r--r--src/javascript/jsc/api/html_rewriter.zig2
-rw-r--r--src/javascript/jsc/api/server.zig37
-rw-r--r--src/javascript/jsc/base.zig17
-rw-r--r--src/javascript/jsc/bindings/bindings.cpp19
-rw-r--r--src/javascript/jsc/bindings/bindings.zig6
-rw-r--r--src/javascript/jsc/bindings/exports.zig4
-rw-r--r--src/javascript/jsc/bindings/headers-cpp.h2
-rw-r--r--src/javascript/jsc/bindings/headers.h3
-rw-r--r--src/javascript/jsc/bindings/headers.zig10
-rw-r--r--src/javascript/jsc/javascript.zig2
-rw-r--r--src/javascript/jsc/node/syscall.zig8
-rw-r--r--src/javascript/jsc/webcore/response.zig86
14 files changed, 142 insertions, 74 deletions
diff --git a/src/deps/uws.zig b/src/deps/uws.zig
index 2f444e4ab..a9753406e 100644
--- a/src/deps/uws.zig
+++ b/src/deps/uws.zig
@@ -474,6 +474,8 @@ pub fn NewApp(comptime ssl: bool) type {
}
};
uws_res_on_writable(ssl_flag, res.downcast(), Wrapper.handle, user_data);
+ }
+ pub inline fn markNeedsMore(res: *Response) void {
if (!ssl) {
us_socket_mark_needs_more_not_ssl(res.downcast());
}
diff --git a/src/javascript/jsc/api/bun.zig b/src/javascript/jsc/api/bun.zig
index 9974bb108..844c04f09 100644
--- a/src/javascript/jsc/api/bun.zig
+++ b/src/javascript/jsc/api/bun.zig
@@ -1358,6 +1358,9 @@ pub const Timer = struct {
}
pub fn then(this: *Timeout, global: *JSGlobalObject) void {
+ if (comptime JSC.is_bindgen)
+ unreachable;
+
if (!this.cancelled) {
if (this.repeat) {
this.io_task.?.deinit();
@@ -1376,6 +1379,9 @@ pub const Timer = struct {
}
pub fn clear(this: *Timeout, global: *JSGlobalObject) void {
+ if (comptime JSC.is_bindgen)
+ unreachable;
+
this.cancelled = true;
JSC.C.JSValueUnprotect(global.ref(), this.callback.asObjectRef());
_ = VirtualMachine.vm.timer.timeouts.swapRemove(this.id);
@@ -1474,11 +1480,13 @@ pub const Timer = struct {
});
comptime {
- @export(setTimeout, .{ .name = Export[0].symbol_name });
- @export(setInterval, .{ .name = Export[1].symbol_name });
- @export(clearTimeout, .{ .name = Export[2].symbol_name });
- @export(clearInterval, .{ .name = Export[3].symbol_name });
- @export(getNextID, .{ .name = Export[4].symbol_name });
+ if (!JSC.is_bindgen) {
+ @export(setTimeout, .{ .name = Export[0].symbol_name });
+ @export(setInterval, .{ .name = Export[1].symbol_name });
+ @export(clearTimeout, .{ .name = Export[2].symbol_name });
+ @export(clearInterval, .{ .name = Export[3].symbol_name });
+ @export(getNextID, .{ .name = Export[4].symbol_name });
+ }
}
};
diff --git a/src/javascript/jsc/api/html_rewriter.zig b/src/javascript/jsc/api/html_rewriter.zig
index 3814c7f8d..a85a62ac8 100644
--- a/src/javascript/jsc/api/html_rewriter.zig
+++ b/src/javascript/jsc/api/html_rewriter.zig
@@ -533,6 +533,8 @@ fn HandlerCallback(
) (fn (*HandlerType, *LOLHTMLType) bool) {
return struct {
pub fn callback(this: *HandlerType, value: *LOLHTMLType) bool {
+ if (comptime JSC.is_bindgen)
+ unreachable;
var zig_element = bun.default_allocator.create(ZigType) catch unreachable;
@field(zig_element, field_name) = value;
// At the end of this scope, the value is no longer valid
diff --git a/src/javascript/jsc/api/server.zig b/src/javascript/jsc/api/server.zig
index cb128284f..62eb0b735 100644
--- a/src/javascript/jsc/api/server.zig
+++ b/src/javascript/jsc/api/server.zig
@@ -78,13 +78,14 @@ const VirtualMachine = @import("../javascript.zig").VirtualMachine;
const IOTask = JSC.IOTask;
const is_bindgen = JSC.is_bindgen;
const uws = @import("uws");
-
+const Blob = JSC.WebCore.Blob;
const SendfileContext = struct {
fd: i32,
socket_fd: i32 = 0,
- remain: u32 = 0,
- offset: i64 = 0,
+ remain: Blob.SizeType = 0,
+ offset: Blob.SizeType = 0,
has_listener: bool = false,
+ has_set_on_writable: bool = false,
};
pub fn NewServer(comptime ssl_enabled: bool) type {
@@ -259,6 +260,7 @@ pub fn NewServer(comptime ssl_enabled: bool) type {
}
fn cleanupAfterSendfile(this: *RequestContext) void {
+ this.resp.setWriteOffset(this.sendfile.offset);
this.resp.endWithoutBody();
std.os.close(this.sendfile.fd);
this.sendfile = undefined;
@@ -271,20 +273,20 @@ pub fn NewServer(comptime ssl_enabled: bool) type {
}};
pub fn onSendfile(this: *RequestContext) bool {
- const adjusted_count_temporary = @minimum(@as(u63, this.sendfile.remain), @as(u63, std.math.maxInt(i32)));
+ const adjusted_count_temporary = @minimum(@truncate(u64, this.sendfile.remain), @as(u63, std.math.maxInt(u63)));
// TODO we should not need this int cast; improve the return type of `@minimum`
const adjusted_count = @intCast(u63, adjusted_count_temporary);
- var sbytes: std.os.off_t = adjusted_count;
- const signed_offset = @bitCast(i64, this.sendfile.offset);
if (Environment.isLinux) {
+ var signed_offset = @intCast(i64, this.sendfile.offset);
const start = this.sendfile.offset;
const val =
- std.os.linux.sendfile(this.sendfile.socket_fd, this.sendfile.fd, &this.sendfile.offset, this.sendfile.remain);
+ std.os.linux.sendfile(this.sendfile.socket_fd, this.sendfile.fd, &signed_offset, this.sendfile.remain);
+ this.sendfile.offset = @intCast(Blob.SizeType, signed_offset);
const errcode = std.os.linux.getErrno(val);
- this.sendfile.remain -= @intCast(u32, this.sendfile.offset - start);
+ this.sendfile.remain -= @intCast(Blob.SizeType, this.sendfile.offset - start);
if (errcode != .SUCCESS or this.aborted or this.sendfile.remain == 0 or val == 0) {
if (errcode != .SUCCESS) {
@@ -295,6 +297,9 @@ pub fn NewServer(comptime ssl_enabled: bool) type {
return errcode != .SUCCESS;
}
} else {
+ var sbytes: std.os.off_t = adjusted_count;
+ const signed_offset = @bitCast(i64, this.sendfile.offset);
+
// var sf_hdr_trailer: std.os.darwin.sf_hdtr = .{
// .headers = &separator_iovec,
// .hdr_cnt = 1,
@@ -317,7 +322,7 @@ pub fn NewServer(comptime ssl_enabled: bool) type {
));
this.sendfile.offset += sbytes;
- this.sendfile.remain -= @intCast(u32, sbytes);
+ this.sendfile.remain -= @intCast(JSC.WebCore.Blob.SizeType, sbytes);
if (errcode != .AGAIN or this.aborted or this.sendfile.remain == 0 or sbytes == 0) {
if (errcode != .AGAIN and errcode != .SUCCESS) {
Output.prettyErrorln("Error: {s}", .{@tagName(errcode)});
@@ -328,8 +333,12 @@ pub fn NewServer(comptime ssl_enabled: bool) type {
}
}
- this.resp.setWriteOffset(this.sendfile.offset);
- this.resp.onWritable(*RequestContext, onWritableSendfile, this);
+ if (!this.sendfile.has_set_on_writable) {
+ this.sendfile.has_set_on_writable = true;
+ this.resp.onWritable(*RequestContext, onWritableSendfile, this);
+ }
+ if (comptime !ssl_enabled)
+ this.resp.markNeedsMore();
return true;
}
@@ -343,11 +352,11 @@ pub fn NewServer(comptime ssl_enabled: bool) type {
return true;
}
- pub fn onPrepareSendfileWrap(this: *anyopaque, fd: i32, size: anyerror!u32, _: *JSGlobalObject) void {
+ pub fn onPrepareSendfileWrap(this: *anyopaque, fd: i32, size: anyerror!Blob.SizeType, _: *JSGlobalObject) void {
onPrepareSendfile(bun.cast(*RequestContext, this), fd, size);
}
- fn onPrepareSendfile(this: *RequestContext, fd: i32, size: anyerror!u32) void {
+ fn onPrepareSendfile(this: *RequestContext, fd: i32, size: anyerror!Blob.SizeType) void {
this.setAbortHandler();
if (this.aborted) return;
const size_ = size catch {
@@ -381,7 +390,6 @@ pub fn NewServer(comptime ssl_enabled: bool) type {
return;
}
-
_ = std.os.write(this.sendfile.socket_fd, "\r\n") catch 0;
_ = this.onSendfile();
@@ -390,6 +398,7 @@ pub fn NewServer(comptime ssl_enabled: bool) type {
pub fn renderSendFile(this: *RequestContext, blob: JSC.WebCore.Blob) void {
if (this.has_sendfile_ctx) return;
this.has_sendfile_ctx = true;
+ this.setAbortHandler();
JSC.WebCore.Blob.doOpenAndStatFile(
&this.blob,
diff --git a/src/javascript/jsc/base.zig b/src/javascript/jsc/base.zig
index 183a0c908..0763b5b6d 100644
--- a/src/javascript/jsc/base.zig
+++ b/src/javascript/jsc/base.zig
@@ -943,6 +943,9 @@ pub fn NewClassWithInstanceType(
const class_definition_ptr = &complete_definition;
pub fn get() callconv(.C) [*c]js.JSClassRef {
+ if (comptime JSC.is_bindgen)
+ unreachable;
+
var lazy = lazy_ref;
if (!lazy.loaded) {
@@ -974,6 +977,9 @@ pub fn NewClassWithInstanceType(
}
pub fn make(ctx: js.JSContextRef, ptr: *ZigType) js.JSObjectRef {
+ if (comptime JSC.is_bindgen)
+ unreachable;
+
var real_ptr = JSPrivateDataPtr.init(ptr).ptr();
if (comptime Environment.allow_assert) {
std.debug.assert(JSPrivateDataPtr.isValidPtr(real_ptr));
@@ -1024,6 +1030,9 @@ pub fn NewClassWithInstanceType(
prop: js.JSStringRef,
exception: js.ExceptionRef,
) callconv(.C) js.JSValueRef {
+ if (comptime JSC.is_bindgen)
+ unreachable;
+
var this: ObjectPtrType(ZigType) = if (comptime ZigType == void) void{} else GetJSPrivateData(ZigType, obj) orelse return js.JSValueMakeUndefined(ctx);
const Field = @TypeOf(@field(
@@ -1095,6 +1104,9 @@ pub fn NewClassWithInstanceType(
value: js.JSValueRef,
exception: js.ExceptionRef,
) callconv(.C) bool {
+ if (comptime JSC.is_bindgen)
+ unreachable;
+
var this = GetJSPrivateData(ZigType, obj) orelse return false;
switch (comptime @typeInfo(@TypeOf(@field(
@@ -1313,6 +1325,8 @@ pub fn NewClassWithInstanceType(
_: js.JSObjectRef,
props: js.JSPropertyNameAccumulatorRef,
) callconv(.C) void {
+ if (comptime JSC.is_bindgen)
+ unreachable;
if (comptime property_name_refs.len > 0) {
comptime var i: usize = 0;
if (!property_name_refs_set) {
@@ -1695,6 +1709,9 @@ pub fn JSError(
ctx: js.JSContextRef,
exception: ExceptionValueRef,
) void {
+ if (comptime JSC.is_bindgen)
+ unreachable;
+
var error_args: [1]js.JSValueRef = undefined;
@setCold(true);
diff --git a/src/javascript/jsc/bindings/bindings.cpp b/src/javascript/jsc/bindings/bindings.cpp
index 84d57a83c..9f12ee44d 100644
--- a/src/javascript/jsc/bindings/bindings.cpp
+++ b/src/javascript/jsc/bindings/bindings.cpp
@@ -1607,6 +1607,25 @@ JSC__JSValue JSC__JSValue__jsNumberFromUint64(uint64_t arg0)
return JSC::JSValue::encode(JSC::jsNumber(arg0));
};
+int64_t JSC__JSValue__toInt64(JSC__JSValue val)
+{
+ JSC::JSValue _val = JSC::JSValue::decode(val);
+
+ int64_t result = JSC::tryConvertToInt52(_val.asDouble());
+ if (result != JSC::JSValue::notInt52) {
+ return result;
+ }
+
+ if (auto* heapBigInt = _val.asHeapBigInt()) {
+ return heapBigInt->toBigInt64(heapBigInt);
+ }
+
+
+
+ return _val.asAnyInt();
+}
+
+
JSC__JSValue JSC__JSValue__createObject2(JSC__JSGlobalObject* globalObject, const ZigString* arg1,
const ZigString* arg2, JSC__JSValue JSValue3,
JSC__JSValue JSValue4)
diff --git a/src/javascript/jsc/bindings/bindings.zig b/src/javascript/jsc/bindings/bindings.zig
index 8e0f6cfcd..009bf20fc 100644
--- a/src/javascript/jsc/bindings/bindings.zig
+++ b/src/javascript/jsc/bindings/bindings.zig
@@ -2005,6 +2005,10 @@ pub const JSValue = enum(u64) {
return cppFn("jsNumberFromUint64", .{i});
}
+ pub fn toInt64(this: JSValue) i64 {
+ return cppFn("toInt64", .{this});
+ }
+
pub fn isUndefined(this: JSValue) bool {
return @enumToInt(this) == 0xa;
}
@@ -2366,7 +2370,7 @@ pub const JSValue = enum(u64) {
return @intToPtr(*anyopaque, @enumToInt(this));
}
- pub const Extern = [_][]const u8{ "_then", "put", "makeWithNameAndPrototype", "parseJSON", "symbolKeyFor", "symbolFor", "getSymbolDescription", "createInternalPromise", "asInternalPromise", "asArrayBuffer_", "getReadableStreamState", "getWritableStreamState", "fromEntries", "createTypeError", "createRangeError", "createObject2", "getIfPropertyExistsImpl", "jsType", "jsonStringify", "kind_", "isTerminationException", "isSameValue", "getLengthOfArray", "toZigString", "createStringArray", "createEmptyObject", "putRecord", "asPromise", "isClass", "getNameProperty", "getClassName", "getErrorsProperty", "toInt32", "toBoolean", "isInt32", "isIterable", "forEach", "isAggregateError", "toZigException", "isException", "toWTFString", "hasProperty", "getPropertyNames", "getDirect", "putDirect", "getIfExists", "asString", "asObject", "asNumber", "isError", "jsNull", "jsUndefined", "jsTDZValue", "jsBoolean", "jsDoubleNumber", "jsNumberFromDouble", "jsNumberFromChar", "jsNumberFromU16", "jsNumberFromInt32", "jsNumberFromInt64", "jsNumberFromUint64", "isBoolean", "isAnyInt", "isUInt32AsAnyInt", "isInt32AsAnyInt", "isNumber", "isString", "isBigInt", "isHeapBigInt", "isBigInt32", "isSymbol", "isPrimitive", "isGetterSetter", "isCustomGetterSetter", "isObject", "isCell", "asCell", "toString", "toStringOrNull", "toPropertyKey", "toPropertyKeyValue", "toObject", "toString", "getPrototype", "getPropertyByPropertyName", "eqlValue", "eqlCell", "isCallable" };
+ pub const Extern = [_][]const u8{ "toInt64", "_then", "put", "makeWithNameAndPrototype", "parseJSON", "symbolKeyFor", "symbolFor", "getSymbolDescription", "createInternalPromise", "asInternalPromise", "asArrayBuffer_", "getReadableStreamState", "getWritableStreamState", "fromEntries", "createTypeError", "createRangeError", "createObject2", "getIfPropertyExistsImpl", "jsType", "jsonStringify", "kind_", "isTerminationException", "isSameValue", "getLengthOfArray", "toZigString", "createStringArray", "createEmptyObject", "putRecord", "asPromise", "isClass", "getNameProperty", "getClassName", "getErrorsProperty", "toInt32", "toBoolean", "isInt32", "isIterable", "forEach", "isAggregateError", "toZigException", "isException", "toWTFString", "hasProperty", "getPropertyNames", "getDirect", "putDirect", "getIfExists", "asString", "asObject", "asNumber", "isError", "jsNull", "jsUndefined", "jsTDZValue", "jsBoolean", "jsDoubleNumber", "jsNumberFromDouble", "jsNumberFromChar", "jsNumberFromU16", "jsNumberFromInt32", "jsNumberFromInt64", "jsNumberFromUint64", "isBoolean", "isAnyInt", "isUInt32AsAnyInt", "isInt32AsAnyInt", "isNumber", "isString", "isBigInt", "isHeapBigInt", "isBigInt32", "isSymbol", "isPrimitive", "isGetterSetter", "isCustomGetterSetter", "isObject", "isCell", "asCell", "toString", "toStringOrNull", "toPropertyKey", "toPropertyKeyValue", "toObject", "toString", "getPrototype", "getPropertyByPropertyName", "eqlValue", "eqlCell", "isCallable" };
};
extern "c" fn Microtask__run(*Microtask, *JSGlobalObject) void;
diff --git a/src/javascript/jsc/bindings/exports.zig b/src/javascript/jsc/bindings/exports.zig
index 10c3674ac..4715b95f0 100644
--- a/src/javascript/jsc/bindings/exports.zig
+++ b/src/javascript/jsc/bindings/exports.zig
@@ -408,7 +408,7 @@ pub const ZigStackTrace = extern struct {
root_path: string,
origin: ?*const ZigURL,
) !Api.StackTrace {
- var stack_trace: Api.StackTrace = std.mem.zeroes(Api.StackTrace);
+ var stack_trace: Api.StackTrace = comptime std.mem.zeroes(Api.StackTrace);
{
var source_lines_iter = this.sourceLineIterator();
@@ -506,7 +506,7 @@ pub const ZigStackFrame = extern struct {
remapped: bool = false,
pub fn toAPI(this: *const ZigStackFrame, root_path: string, origin: ?*const ZigURL, allocator: std.mem.Allocator) !Api.StackFrame {
- var frame: Api.StackFrame = std.mem.zeroes(Api.StackFrame);
+ var frame: Api.StackFrame = comptime std.mem.zeroes(Api.StackFrame);
if (this.function_name.len > 0) {
frame.function_name = try allocator.dupe(u8, this.function_name.slice());
}
diff --git a/src/javascript/jsc/bindings/headers-cpp.h b/src/javascript/jsc/bindings/headers-cpp.h
index 495e3cdb6..bac4b0abf 100644
--- a/src/javascript/jsc/bindings/headers-cpp.h
+++ b/src/javascript/jsc/bindings/headers-cpp.h
@@ -1,4 +1,4 @@
-//-- AUTOGENERATED FILE -- 1647847672
+//-- AUTOGENERATED FILE -- 1647946969
// clang-format off
#pragma once
diff --git a/src/javascript/jsc/bindings/headers.h b/src/javascript/jsc/bindings/headers.h
index 55e560ac7..4580be974 100644
--- a/src/javascript/jsc/bindings/headers.h
+++ b/src/javascript/jsc/bindings/headers.h
@@ -1,5 +1,5 @@
// clang-format: off
-//-- AUTOGENERATED FILE -- 1647847672
+//-- AUTOGENERATED FILE -- 1647946969
#pragma once
#include <stddef.h>
@@ -499,6 +499,7 @@ CPP_DECL JSC__JSValue JSC__JSValue__symbolFor(JSC__JSGlobalObject* arg0, ZigStri
CPP_DECL bool JSC__JSValue__symbolKeyFor(JSC__JSValue JSValue0, JSC__JSGlobalObject* arg1, ZigString* arg2);
CPP_DECL bool JSC__JSValue__toBoolean(JSC__JSValue JSValue0);
CPP_DECL int32_t JSC__JSValue__toInt32(JSC__JSValue JSValue0);
+CPP_DECL int64_t JSC__JSValue__toInt64(JSC__JSValue JSValue0);
CPP_DECL JSC__JSObject* JSC__JSValue__toObject(JSC__JSValue JSValue0, JSC__JSGlobalObject* arg1);
CPP_DECL bJSC__Identifier JSC__JSValue__toPropertyKey(JSC__JSValue JSValue0, JSC__JSGlobalObject* arg1);
CPP_DECL JSC__JSValue JSC__JSValue__toPropertyKeyValue(JSC__JSValue JSValue0, JSC__JSGlobalObject* arg1);
diff --git a/src/javascript/jsc/bindings/headers.zig b/src/javascript/jsc/bindings/headers.zig
index bf8ab5d75..a82822ed9 100644
--- a/src/javascript/jsc/bindings/headers.zig
+++ b/src/javascript/jsc/bindings/headers.zig
@@ -63,15 +63,6 @@ pub const Bun__ArrayBuffer = bindings.ArrayBuffer;
pub const ptrdiff_t = c_long;
pub const wchar_t = c_int;
-pub const __uint16_t = c_ushort;
-pub const __int32_t = c_int;
-pub const __uint32_t = c_uint;
-pub const __int64_t = c_longlong;
-pub const __uint64_t = c_ulonglong;
-pub const __mbstate_t = extern union {
- __mbstate8: [128]u8,
- _mbstateL: c_longlong,
-};
pub const JSC__GeneratorPrototype = struct_JSC__GeneratorPrototype;
@@ -347,6 +338,7 @@ pub extern fn JSC__JSValue__symbolFor(arg0: [*c]JSC__JSGlobalObject, arg1: [*c]Z
pub extern fn JSC__JSValue__symbolKeyFor(JSValue0: JSC__JSValue, arg1: [*c]JSC__JSGlobalObject, arg2: [*c]ZigString) bool;
pub extern fn JSC__JSValue__toBoolean(JSValue0: JSC__JSValue) bool;
pub extern fn JSC__JSValue__toInt32(JSValue0: JSC__JSValue) i32;
+pub extern fn JSC__JSValue__toInt64(JSValue0: JSC__JSValue) i64;
pub extern fn JSC__JSValue__toObject(JSValue0: JSC__JSValue, arg1: [*c]JSC__JSGlobalObject) [*c]JSC__JSObject;
pub extern fn JSC__JSValue__toPropertyKey(JSValue0: JSC__JSValue, arg1: [*c]JSC__JSGlobalObject) bJSC__Identifier;
pub extern fn JSC__JSValue__toPropertyKeyValue(JSValue0: JSC__JSValue, arg1: [*c]JSC__JSGlobalObject) JSC__JSValue;
diff --git a/src/javascript/jsc/javascript.zig b/src/javascript/jsc/javascript.zig
index d2ba2490a..90cb8341f 100644
--- a/src/javascript/jsc/javascript.zig
+++ b/src/javascript/jsc/javascript.zig
@@ -161,6 +161,8 @@ pub fn ConcurrentPromiseTask(comptime Context: type) type {
}
pub fn runFromJS(this: This) void {
+ if (comptime JSC.is_bindgen)
+ unreachable;
var promise_value = this.promise;
var promise = promise_value.asInternalPromise() orelse {
if (comptime @hasDecl(Context, "deinit")) {
diff --git a/src/javascript/jsc/node/syscall.zig b/src/javascript/jsc/node/syscall.zig
index c355fe5cc..c702f8ad6 100644
--- a/src/javascript/jsc/node/syscall.zig
+++ b/src/javascript/jsc/node/syscall.zig
@@ -71,7 +71,7 @@ const mode_t = os.mode_t;
const open_sym = system.open;
-const fstat_sym = if (builtin.os.tag == .linux and builtin.link_libc)
+const fstat_sym = if (builtin.os.tag == .linux)
libc.fstat64
else
libc.fstat;
@@ -99,19 +99,19 @@ pub fn chdir(destination: [:0]const u8) Maybe(void) {
}
pub fn stat(path: [:0]const u8) Maybe(os.Stat) {
- var stat_ = mem.zeroes(os.Stat);
+ var stat_ = comptime mem.zeroes(os.Stat);
if (Maybe(os.Stat).errnoSys(libc.stat(path, &stat_), .stat)) |err| return err;
return Maybe(os.Stat){ .result = stat_ };
}
pub fn lstat(path: [:0]const u8) Maybe(os.Stat) {
- var stat_ = mem.zeroes(os.Stat);
+ var stat_ = comptime mem.zeroes(os.Stat);
if (Maybe(os.Stat).errnoSys(C.lstat(path, &stat_), .lstat)) |err| return err;
return Maybe(os.Stat){ .result = stat_ };
}
pub fn fstat(fd: JSC.Node.FileDescriptor) Maybe(os.Stat) {
- var stat_ = mem.zeroes(os.Stat);
+ var stat_ = comptime mem.zeroes(os.Stat);
if (Maybe(os.Stat).errnoSys(fstat_sym(fd, &stat_), .fstat)) |err| return err;
return Maybe(os.Stat){ .result = stat_ };
}
diff --git a/src/javascript/jsc/webcore/response.zig b/src/javascript/jsc/webcore/response.zig
index 3ff67f79d..22e492a9a 100644
--- a/src/javascript/jsc/webcore/response.zig
+++ b/src/javascript/jsc/webcore/response.zig
@@ -48,6 +48,8 @@ pub const Response = struct {
response_objects_used: u8 = 0,
pub fn get(this: *Pool, ptr: *Response) ?JSC.C.JSObjectRef {
+ if (comptime JSC.is_bindgen)
+ unreachable;
if (this.response_objects_used > 0) {
var result = this.response_objects_pool[this.response_objects_used - 1];
this.response_objects_used -= 1;
@@ -303,6 +305,8 @@ pub const Response = struct {
}
pub fn makeMaybePooled(ctx: js.JSContextRef, ptr: *Response) JSC.C.JSObjectRef {
+ if (comptime JSC.is_bindgen)
+ unreachable;
if (JSC.VirtualMachine.vm.response_objects_pool) |pool| {
if (pool.get(ptr)) |object| {
JSC.C.JSValueUnprotect(ctx, object);
@@ -689,6 +693,8 @@ pub const Fetch = struct {
};
pub fn onDone(this: *FetchTasklet) void {
+ if (comptime JSC.is_bindgen)
+ unreachable;
var args = [1]js.JSValueRef{undefined};
var callback_object = switch (this.http.state.load(.Monotonic)) {
@@ -1652,8 +1658,8 @@ pub const Headers = struct {
};
pub const Blob = struct {
- size: u32 = 0,
- offset: u32 = 0,
+ size: SizeType = 0,
+ offset: SizeType = 0,
allocator: ?std.mem.Allocator = null,
store: ?*Store = null,
content_type: string = "",
@@ -1665,6 +1671,8 @@ pub const Blob = struct {
globalThis: *JSGlobalObject = undefined,
+ pub const SizeType = u64;
+
pub fn constructFile(
_: void,
ctx: js.JSContextRef,
@@ -1709,7 +1717,7 @@ pub const Blob = struct {
is_all_ascii: ?bool = null,
allocator: std.mem.Allocator,
- pub fn size(this: *const Store) u32 {
+ pub fn size(this: *const Store) SizeType {
return switch (this.data) {
.bytes => this.data.bytes.len,
.file => std.math.maxInt(i32),
@@ -1899,7 +1907,7 @@ pub const Blob = struct {
errno: ?anyerror = null,
open_completion: HTTPClient.NetworkThread.Completion = undefined,
opened_fd: JSC.Node.FileDescriptor = 0,
- size: u32 = 0,
+ size: SizeType = 0,
store: *Store = undefined,
file_store: FileStore,
@@ -1913,7 +1921,7 @@ pub const Blob = struct {
pub const OnCompleteCallback = fn (
ctx: *anyopaque,
fd: JSC.Node.FileDescriptor,
- size: anyerror!u32,
+ size: anyerror!SizeType,
global: *JSGlobalObject,
) void;
@@ -1985,7 +1993,7 @@ pub const Blob = struct {
return;
}
- this.size = @truncate(u32, @intCast(u64, @maximum(@intCast(i64, stat.size), 0)));
+ this.size = @truncate(SizeType, @intCast(u64, @maximum(@intCast(i64, stat.size), 0)));
}
};
@@ -1997,8 +2005,8 @@ pub const Blob = struct {
file_store: FileStore,
byte_store: ByteStore = ByteStore{ .allocator = bun.default_allocator },
store: ?*Store = null,
- offset: u32 = 0,
- max_length: u32 = std.math.maxInt(u32),
+ offset: SizeType = 0,
+ max_length: SizeType = std.math.maxInt(SizeType),
open_frame: OpenFrameType = undefined,
read_frame: @Frame(ReadFile.doRead) = undefined,
close_frame: @Frame(ReadFile.doClose) = undefined,
@@ -2006,9 +2014,9 @@ pub const Blob = struct {
open_completion: HTTPClient.NetworkThread.Completion = undefined,
opened_fd: JSC.Node.FileDescriptor = 0,
read_completion: HTTPClient.NetworkThread.Completion = undefined,
- read_len: u32 = 0,
- read_off: u32 = 0,
- size: u32 = 0,
+ read_len: SizeType = 0,
+ read_off: SizeType = 0,
+ size: SizeType = 0,
buffer: []u8 = undefined,
runAsyncFrame: @Frame(ReadFile.runAsync) = undefined,
close_completion: HTTPClient.NetworkThread.Completion = undefined,
@@ -2027,8 +2035,8 @@ pub const Blob = struct {
store: *Store,
onReadFileContext: *anyopaque,
onCompleteCallback: OnReadFileCallback,
- off: u32,
- max_len: u32,
+ off: SizeType,
+ max_len: SizeType,
) !*ReadFile {
var read_file = try allocator.create(ReadFile);
read_file.* = ReadFile{
@@ -2046,8 +2054,8 @@ pub const Blob = struct {
pub fn create(
allocator: std.mem.Allocator,
store: *Store,
- off: u32,
- max_len: u32,
+ off: SizeType,
+ max_len: SizeType,
comptime Context: type,
context: Context,
comptime callback: fn (ctx: Context, bytes: anyerror![]u8) void,
@@ -2061,7 +2069,7 @@ pub const Blob = struct {
return try ReadFile.createWithCtx(allocator, store, @ptrCast(*anyopaque, context), Handler.run, off, max_len);
}
- pub fn doRead(this: *ReadFile) AsyncIO.ReadError!u32 {
+ pub fn doRead(this: *ReadFile) AsyncIO.ReadError!SizeType {
var aio = &AsyncIO.global;
var remaining = this.buffer[this.read_off..];
@@ -2133,7 +2141,7 @@ pub const Blob = struct {
}
pub fn onRead(this: *ReadFile, _: *HTTPClient.NetworkThread.Completion, result: AsyncIO.ReadError!usize) void {
- this.read_len = @truncate(u32, result catch |err| {
+ this.read_len = @truncate(SizeType, result catch |err| {
this.errno = err;
this.read_len = 0;
resume this.read_frame;
@@ -2164,7 +2172,7 @@ pub const Blob = struct {
}
this.size = @minimum(
- @truncate(u32, @intCast(u64, @maximum(@intCast(i64, stat.size), 0))),
+ @truncate(SizeType, @intCast(SizeType, @maximum(@intCast(i64, stat.size), 0))),
this.max_length,
);
if (this.size == 0) {
@@ -2216,15 +2224,15 @@ pub const Blob = struct {
pub const ByteStore = struct {
ptr: [*]u8 = undefined,
- len: u32 = 0,
- cap: u32 = 0,
+ len: SizeType = 0,
+ cap: SizeType = 0,
allocator: std.mem.Allocator,
pub fn init(bytes: []u8, allocator: std.mem.Allocator) ByteStore {
return .{
.ptr = bytes.ptr,
- .len = @truncate(u32, bytes.len),
- .cap = @truncate(u32, bytes.len),
+ .len = @truncate(SizeType, bytes.len),
+ .cap = @truncate(SizeType, bytes.len),
.allocator = allocator,
};
}
@@ -2369,32 +2377,32 @@ pub const Blob = struct {
return constructor(ctx, null, &[_]js.JSValueRef{}, exception);
}
// If the optional start parameter is not used as a parameter when making this call, let relativeStart be 0.
- var relativeStart: i32 = 0;
+ var relativeStart: i64 = 0;
// If the optional end parameter is not used as a parameter when making this call, let relativeEnd be size.
- var relativeEnd: i32 = @intCast(i32, this.size);
+ var relativeEnd: i64 = @intCast(i64, this.size);
var args_iter = JSC.Node.ArgumentsSlice.from(args);
if (args_iter.nextEat()) |start_| {
- const start = start_.toInt32();
+ const start = start_.toInt64();
if (start < 0) {
// If the optional start parameter is negative, let relativeStart be start + size.
- relativeStart = @intCast(i32, @maximum(start + @intCast(i32, this.size), 0));
+ relativeStart = @intCast(i64, @maximum(start + @intCast(i64, this.size), 0));
} else {
// Otherwise, let relativeStart be start.
- relativeStart = @minimum(@intCast(i32, start), @intCast(i32, this.size));
+ relativeStart = @minimum(@intCast(i64, start), @intCast(i64, this.size));
}
}
if (args_iter.nextEat()) |end_| {
- const end = end_.toInt32();
+ const end = end_.toInt64();
// If end is negative, let relativeEnd be max((size + end), 0).
if (end < 0) {
// If the optional start parameter is negative, let relativeStart be start + size.
- relativeEnd = @intCast(i32, @maximum(end + @intCast(i32, this.size), 0));
+ relativeEnd = @intCast(i64, @maximum(end + @intCast(i64, this.size), 0));
} else {
// Otherwise, let relativeStart be start.
- relativeEnd = @minimum(@intCast(i32, end), @intCast(i32, this.size));
+ relativeEnd = @minimum(@intCast(i64, end), @intCast(i64, this.size));
}
}
@@ -2410,12 +2418,12 @@ pub const Blob = struct {
}
}
- const len = @intCast(u32, @maximum(relativeEnd - relativeStart, 0));
+ const len = @intCast(SizeType, @maximum(relativeEnd - relativeStart, 0));
// This copies over the is_all_ascii flag
// which is okay because this will only be a <= slice
var blob = this.dupe();
- blob.offset = @intCast(u32, relativeStart);
+ blob.offset = @intCast(SizeType, relativeStart);
blob.size = len;
blob.content_type = content_type;
blob.content_type_allocated = content_type.len > 0;
@@ -2470,14 +2478,18 @@ pub const Blob = struct {
_: js.JSStringRef,
_: js.ExceptionRef,
) js.JSValueRef {
- if (this.size == std.math.maxInt(i32)) {
+ if (this.size == std.math.maxInt(SizeType)) {
this.resolveSize();
- if (this.size == std.math.maxInt(i32) and this.store != null) {
- return JSValue.jsNumber(@as(u32, 0)).asRef();
+ if (this.size == std.math.maxInt(SizeType) and this.store != null) {
+ return JSValue.jsNumber(@as(SizeType, 0)).asRef();
}
}
- return JSValue.jsNumber(@truncate(u32, this.size)).asRef();
+ if (this.size < std.math.maxInt(i32)) {
+ return JSValue.jsNumber(this.size).asRef();
+ }
+
+ return JSC.JSValue.jsNumberFromUint64(this.size).asRef();
}
pub fn resolveSize(this: *Blob) void {
@@ -2485,7 +2497,7 @@ pub const Blob = struct {
if (store.data == .bytes) {
const offset = this.offset;
const store_size = store.size();
- if (store_size != std.math.maxInt(i32)) {
+ if (store_size != std.math.maxInt(SizeType)) {
this.offset = @minimum(store_size, offset);
this.size = store_size - offset;
}