mirror of
https://github.com/oven-sh/bun
synced 2026-02-13 12:29:07 +00:00
WASM
This commit is contained in:
@@ -7,7 +7,7 @@ const QueryStringMap = @import("../../../query_string_map.zig").QueryStringMap;
|
||||
const CombinedScanner = @import("../../../query_string_map.zig").CombinedScanner;
|
||||
const _global = @import("../../../global.zig");
|
||||
const string = _global.string;
|
||||
const JSC = @import("javascript_core");
|
||||
const JSC = @import("../../../jsc.zig");
|
||||
const js = JSC.C;
|
||||
const WebCore = @import("../webcore/response.zig");
|
||||
const Router = @This();
|
||||
@@ -360,7 +360,7 @@ pub fn createQueryObject(ctx: js.JSContextRef, map: *QueryStringMap, _: js.Excep
|
||||
return value.asRef();
|
||||
}
|
||||
|
||||
threadlocal var entry_point_tempbuf: [std.fs.MAX_PATH_BYTES]u8 = undefined;
|
||||
threadlocal var entry_point_tempbuf: [_global.MAX_PATH_BYTES]u8 = undefined;
|
||||
pub fn getScriptSrcString(
|
||||
comptime Writer: type,
|
||||
writer: Writer,
|
||||
|
||||
@@ -7,7 +7,7 @@ const QueryStringMap = @import("../../../query_string_map.zig").QueryStringMap;
|
||||
const CombinedScanner = @import("../../../query_string_map.zig").CombinedScanner;
|
||||
const _global = @import("../../../global.zig");
|
||||
const string = _global.string;
|
||||
const JSC = @import("javascript_core");
|
||||
const JSC = @import("../../../jsc.zig");
|
||||
const js = JSC.C;
|
||||
const WebCore = @import("../webcore/response.zig");
|
||||
const Bundler = @import("../../../bundler.zig");
|
||||
|
||||
@@ -247,7 +247,7 @@ pub const ZigString = extern struct {
|
||||
};
|
||||
}
|
||||
|
||||
pub fn sliceZBuf(this: ZigString, buf: *[std.fs.MAX_PATH_BYTES]u8) ![:0]const u8 {
|
||||
pub fn sliceZBuf(this: ZigString, buf: *[_global.MAX_PATH_BYTES]u8) ![:0]const u8 {
|
||||
return try std.fmt.bufPrintZ(buf, "{}", .{this});
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
const JSC = @import("../../../jsc.zig");
|
||||
const Fs = @import("../../../fs.zig");
|
||||
const CAPI = @import("../../../jsc.zig").C;
|
||||
const CAPI = JSC.C;
|
||||
const JS = @import("../javascript.zig");
|
||||
const JSBase = @import("../base.zig");
|
||||
const ZigURL = @import("../../../query_string_map.zig").URL;
|
||||
|
||||
@@ -586,7 +586,7 @@ pub const Bun = struct {
|
||||
arguments: []const js.JSValueRef,
|
||||
exception: js.ExceptionRef,
|
||||
) js.JSValueRef {
|
||||
var buf: [std.fs.MAX_PATH_BYTES]u8 = undefined;
|
||||
var buf: [_global.MAX_PATH_BYTES]u8 = undefined;
|
||||
const path = getFilePath(ctx, arguments, &buf, exception) orelse return null;
|
||||
buf[path.len] = 0;
|
||||
|
||||
@@ -603,7 +603,7 @@ pub const Bun = struct {
|
||||
arguments: []const js.JSValueRef,
|
||||
exception: js.ExceptionRef,
|
||||
) js.JSValueRef {
|
||||
var buf: [std.fs.MAX_PATH_BYTES]u8 = undefined;
|
||||
var buf: [_global.MAX_PATH_BYTES]u8 = undefined;
|
||||
const path = getFilePath(ctx, arguments, &buf, exception) orelse return null;
|
||||
buf[path.len] = 0;
|
||||
|
||||
@@ -728,7 +728,7 @@ pub const Bun = struct {
|
||||
return out.toValueGC(ctx.ptr()).asObjectRef();
|
||||
}
|
||||
|
||||
var public_path_temp_str: [std.fs.MAX_PATH_BYTES]u8 = undefined;
|
||||
var public_path_temp_str: [_global.MAX_PATH_BYTES]u8 = undefined;
|
||||
|
||||
pub fn getPublicPathJS(
|
||||
_: void,
|
||||
@@ -760,7 +760,7 @@ pub const Bun = struct {
|
||||
// if (arguments.len == 0) return ZigString.Empty.toValue(ctx.ptr()).asObjectRef();
|
||||
// var zig_str: ZigString = ZigString.Empty;
|
||||
// JSValue.toZigString(JSValue.fromRef(arguments[0]), &zig_str, ctx.ptr());
|
||||
// var buf: [std.fs.MAX_PATH_BYTES]u8 = undefined;
|
||||
// var buf: [_global.MAX_PATH_BYTES]u8 = undefined;
|
||||
// var stack = std.heap.stackFallback(32 * @sizeOf(string), VirtualMachine.vm.allocator);
|
||||
// var allocator = stack.get();
|
||||
// var parts = allocator.alloc(string, arguments.len) catch {};
|
||||
|
||||
@@ -2417,7 +2417,7 @@ pub const NodeFS = struct {
|
||||
/// We want to avoid allocating a new path buffer for every error message so that JSC can clone + GC it.
|
||||
/// That means a stack-allocated buffer won't suffice. Instead, we re-use
|
||||
/// the heap allocated buffer on the NodefS struct
|
||||
sync_error_buf: [std.fs.MAX_PATH_BYTES]u8 = undefined,
|
||||
sync_error_buf: [_global.MAX_PATH_BYTES]u8 = undefined,
|
||||
|
||||
pub const ReturnType = Return;
|
||||
|
||||
@@ -2506,8 +2506,8 @@ pub const NodeFS = struct {
|
||||
|
||||
switch (comptime flavor) {
|
||||
.sync => {
|
||||
var src_buf: [std.fs.MAX_PATH_BYTES]u8 = undefined;
|
||||
var dest_buf: [std.fs.MAX_PATH_BYTES]u8 = undefined;
|
||||
var src_buf: [_global.MAX_PATH_BYTES]u8 = undefined;
|
||||
var dest_buf: [_global.MAX_PATH_BYTES]u8 = undefined;
|
||||
var src = args.src.sliceZ(&src_buf);
|
||||
var dest = args.dest.sliceZ(&dest_buf);
|
||||
|
||||
@@ -2776,7 +2776,7 @@ pub const NodeFS = struct {
|
||||
return Maybe(Return.Lchown).todo;
|
||||
}
|
||||
pub fn link(this: *NodeFS, args: Arguments.Link, comptime flavor: Flavor) Maybe(Return.Link) {
|
||||
var new_path_buf: [std.fs.MAX_PATH_BYTES]u8 = undefined;
|
||||
var new_path_buf: [_global.MAX_PATH_BYTES]u8 = undefined;
|
||||
const from = args.old_path.sliceZ(&this.sync_error_buf);
|
||||
const to = args.new_path.sliceZ(&new_path_buf);
|
||||
|
||||
@@ -2846,7 +2846,7 @@ pub const NodeFS = struct {
|
||||
switch (comptime flavor) {
|
||||
// The sync version does no allocation except when returning the path
|
||||
.sync => {
|
||||
var buf: [std.fs.MAX_PATH_BYTES]u8 = undefined;
|
||||
var buf: [_global.MAX_PATH_BYTES]u8 = undefined;
|
||||
const path = args.path.sliceZWithForceCopy(&buf, true);
|
||||
const len = @truncate(u16, path.len);
|
||||
|
||||
@@ -3393,7 +3393,7 @@ pub const NodeFS = struct {
|
||||
}
|
||||
|
||||
pub fn readlink(this: *NodeFS, args: Arguments.Readlink, comptime flavor: Flavor) Maybe(Return.Readlink) {
|
||||
var outbuf: [std.fs.MAX_PATH_BYTES]u8 = undefined;
|
||||
var outbuf: [_global.MAX_PATH_BYTES]u8 = undefined;
|
||||
var inbuf = &this.sync_error_buf;
|
||||
switch (comptime flavor) {
|
||||
.sync => {
|
||||
@@ -3426,7 +3426,7 @@ pub const NodeFS = struct {
|
||||
return Maybe(Return.Readlink).todo;
|
||||
}
|
||||
pub fn realpath(this: *NodeFS, args: Arguments.Realpath, comptime flavor: Flavor) Maybe(Return.Realpath) {
|
||||
var outbuf: [std.fs.MAX_PATH_BYTES]u8 = undefined;
|
||||
var outbuf: [_global.MAX_PATH_BYTES]u8 = undefined;
|
||||
var inbuf = &this.sync_error_buf;
|
||||
if (comptime Environment.allow_assert) std.debug.assert(FileSystem.instance_loaded);
|
||||
|
||||
@@ -3491,7 +3491,7 @@ pub const NodeFS = struct {
|
||||
// }
|
||||
pub fn rename(this: *NodeFS, args: Arguments.Rename, comptime flavor: Flavor) Maybe(Return.Rename) {
|
||||
var from_buf = &this.sync_error_buf;
|
||||
var to_buf: [std.fs.MAX_PATH_BYTES]u8 = undefined;
|
||||
var to_buf: [_global.MAX_PATH_BYTES]u8 = undefined;
|
||||
|
||||
switch (comptime flavor) {
|
||||
.sync => {
|
||||
@@ -3550,7 +3550,7 @@ pub const NodeFS = struct {
|
||||
}
|
||||
|
||||
pub fn symlink(this: *NodeFS, args: Arguments.Symlink, comptime flavor: Flavor) Maybe(Return.Symlink) {
|
||||
var to_buf: [std.fs.MAX_PATH_BYTES]u8 = undefined;
|
||||
var to_buf: [_global.MAX_PATH_BYTES]u8 = undefined;
|
||||
|
||||
switch (comptime flavor) {
|
||||
.sync => {
|
||||
|
||||
@@ -10,8 +10,9 @@ const default_allocator = @import("../../../global.zig").default_allocator;
|
||||
const JSC = @import("../../../jsc.zig");
|
||||
const SystemError = JSC.SystemError;
|
||||
const darwin = os.darwin;
|
||||
const MAX_PATH_BYTES = std.fs.MAX_PATH_BYTES;
|
||||
const fd_t = std.os.fd_t;
|
||||
const _global = @import("../../../global.zig");
|
||||
const MAX_PATH_BYTES = _global.MAX_PATH_BYTES;
|
||||
const fd_t = _global.FileDescriptorType;
|
||||
const C = @import("../../../global.zig").C;
|
||||
const linux = os.linux;
|
||||
const Maybe = JSC.Node.Maybe;
|
||||
@@ -77,12 +78,12 @@ else
|
||||
|
||||
const mem = std.mem;
|
||||
|
||||
pub fn getcwd(buf: *[std.fs.MAX_PATH_BYTES]u8) Maybe([]const u8) {
|
||||
pub fn getcwd(buf: *[_global.MAX_PATH_BYTES]u8) Maybe([]const u8) {
|
||||
const Result = Maybe([]const u8);
|
||||
buf[0] = 0;
|
||||
const rc = std.c.getcwd(buf, std.fs.MAX_PATH_BYTES);
|
||||
const rc = std.c.getcwd(buf, _global.MAX_PATH_BYTES);
|
||||
return if (rc != null)
|
||||
Result{ .result = std.mem.sliceTo(rc.?[0..std.fs.MAX_PATH_BYTES], 0) }
|
||||
Result{ .result = std.mem.sliceTo(rc.?[0.._global.MAX_PATH_BYTES], 0) }
|
||||
else
|
||||
Result.errnoSys(0, .getcwd).?;
|
||||
}
|
||||
|
||||
@@ -250,7 +250,7 @@ pub const PathLike = union(Tag) {
|
||||
};
|
||||
}
|
||||
|
||||
pub fn sliceZWithForceCopy(this: PathLike, buf: *[std.fs.MAX_PATH_BYTES]u8, comptime force: bool) [:0]const u8 {
|
||||
pub fn sliceZWithForceCopy(this: PathLike, buf: *[_global.MAX_PATH_BYTES]u8, comptime force: bool) [:0]const u8 {
|
||||
var sliced = this.slice();
|
||||
|
||||
if (sliced.len == 0) return "";
|
||||
@@ -267,7 +267,7 @@ pub const PathLike = union(Tag) {
|
||||
return buf[0..sliced.len :0];
|
||||
}
|
||||
|
||||
pub inline fn sliceZ(this: PathLike, buf: *[std.fs.MAX_PATH_BYTES]u8) [:0]const u8 {
|
||||
pub inline fn sliceZ(this: PathLike, buf: *[_global.MAX_PATH_BYTES]u8) [:0]const u8 {
|
||||
return sliceZWithForceCopy(this, buf, false);
|
||||
}
|
||||
|
||||
@@ -345,11 +345,11 @@ pub const Valid = struct {
|
||||
JSC.throwInvalidArguments("Invalid path string: can't be empty", .{}, ctx, exception);
|
||||
return false;
|
||||
},
|
||||
1...std.fs.MAX_PATH_BYTES => return true,
|
||||
1..._global.MAX_PATH_BYTES => return true,
|
||||
else => {
|
||||
// TODO: should this be an EINVAL?
|
||||
JSC.throwInvalidArguments(
|
||||
comptime std.fmt.comptimePrint("Invalid path string: path is too long (max: {d})", .{std.fs.MAX_PATH_BYTES}),
|
||||
comptime std.fmt.comptimePrint("Invalid path string: path is too long (max: {d})", .{_global.MAX_PATH_BYTES}),
|
||||
.{},
|
||||
ctx,
|
||||
exception,
|
||||
@@ -373,14 +373,14 @@ pub const Valid = struct {
|
||||
|
||||
// TODO: should this be an EINVAL?
|
||||
JSC.throwInvalidArguments(
|
||||
comptime std.fmt.comptimePrint("Invalid path buffer: path is too long (max: {d})", .{std.fs.MAX_PATH_BYTES}),
|
||||
comptime std.fmt.comptimePrint("Invalid path buffer: path is too long (max: {d})", .{_global.MAX_PATH_BYTES}),
|
||||
.{},
|
||||
ctx,
|
||||
exception,
|
||||
);
|
||||
return false;
|
||||
},
|
||||
1...std.fs.MAX_PATH_BYTES => return true,
|
||||
1..._global.MAX_PATH_BYTES => return true,
|
||||
}
|
||||
|
||||
unreachable;
|
||||
@@ -2198,7 +2198,7 @@ pub const Path = struct {
|
||||
var arena = std.heap.ArenaAllocator.init(heap_allocator);
|
||||
var arena_allocator = arena.allocator();
|
||||
defer arena.deinit();
|
||||
var buf: [std.fs.MAX_PATH_BYTES]u8 = undefined;
|
||||
var buf: [_global.MAX_PATH_BYTES]u8 = undefined;
|
||||
var to_join = allocator.alloc(string, args_len) catch unreachable;
|
||||
var possibly_utf16 = false;
|
||||
for (args_ptr[0..args_len]) |arg, i| {
|
||||
@@ -2231,7 +2231,7 @@ pub const Path = struct {
|
||||
var zig_str: JSC.ZigString = args_ptr[0].getZigString(globalThis);
|
||||
if (zig_str.len == 0) return JSC.ZigString.init("").toValue(globalThis);
|
||||
|
||||
var buf: [std.fs.MAX_PATH_BYTES]u8 = undefined;
|
||||
var buf: [_global.MAX_PATH_BYTES]u8 = undefined;
|
||||
var str_slice = zig_str.toSlice(heap_allocator);
|
||||
defer str_slice.deinit();
|
||||
var str = str_slice.slice();
|
||||
@@ -2322,7 +2322,7 @@ pub const Path = struct {
|
||||
heap_allocator,
|
||||
);
|
||||
var allocator = stack_fallback_allocator.get();
|
||||
var out_buf: [std.fs.MAX_PATH_BYTES * 2]u8 = undefined;
|
||||
var out_buf: [_global.MAX_PATH_BYTES * 2]u8 = undefined;
|
||||
|
||||
var parts = allocator.alloc(string, args_len) catch unreachable;
|
||||
defer allocator.free(parts);
|
||||
@@ -2447,7 +2447,7 @@ pub const Process = struct {
|
||||
}
|
||||
|
||||
pub fn getCwd(globalObject: *JSC.JSGlobalObject) callconv(.C) JSC.JSValue {
|
||||
var buffer: [std.fs.MAX_PATH_BYTES]u8 = undefined;
|
||||
var buffer: [_global.MAX_PATH_BYTES]u8 = undefined;
|
||||
switch (Syscall.getcwd(&buffer)) {
|
||||
.err => |err| {
|
||||
return err.toJSC(globalObject);
|
||||
@@ -2467,7 +2467,7 @@ pub const Process = struct {
|
||||
return JSC.toInvalidArguments("path is required", .{}, globalObject.ref());
|
||||
}
|
||||
|
||||
var buf: [std.fs.MAX_PATH_BYTES]u8 = undefined;
|
||||
var buf: [_global.MAX_PATH_BYTES]u8 = undefined;
|
||||
const slice = to.sliceZBuf(&buf) catch {
|
||||
return JSC.toInvalidArguments("Invalid path", .{}, globalObject.ref());
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user