mirror of
https://github.com/oven-sh/bun
synced 2026-02-10 02:48:50 +00:00
Handle integer sizes greater than i32
This commit is contained in:
@@ -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 });
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//-- AUTOGENERATED FILE -- 1647847672
|
||||
//-- AUTOGENERATED FILE -- 1647946969
|
||||
// clang-format off
|
||||
#pragma once
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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")) {
|
||||
|
||||
@@ -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_ };
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user