mirror of
https://github.com/oven-sh/bun
synced 2026-02-10 19:08:50 +00:00
[bun.js] 1/? Implement Response.file
This commit is contained in:
@@ -297,12 +297,14 @@ pub fn IOTask(comptime Context: type) type {
|
||||
|
||||
const AsyncTransformTask = @import("./api/transpiler.zig").TransformTask.AsyncTransformTask;
|
||||
const BunTimerTimeoutTask = Bun.Timer.Timeout.TimeoutTask;
|
||||
const ReadFileTask = WebCore.Blob.Store.ReadFile.ReadFileTask;
|
||||
// const PromiseTask = JSInternalPromise.Completion.PromiseTask;
|
||||
pub const Task = TaggedPointerUnion(.{
|
||||
FetchTasklet,
|
||||
Microtask,
|
||||
AsyncTransformTask,
|
||||
BunTimerTimeoutTask,
|
||||
ReadFileTask,
|
||||
// PromiseTask,
|
||||
// TimeoutTasklet,
|
||||
});
|
||||
@@ -478,6 +480,7 @@ pub const VirtualMachine = struct {
|
||||
event_loop: *EventLoop = undefined,
|
||||
|
||||
ref_strings: JSC.RefString.Map = undefined,
|
||||
file_blobs: JSC.WebCore.Blob.Store.Map,
|
||||
|
||||
source_mappings: SavedSourceMap = undefined,
|
||||
response_objects_pool: ?*Response.Pool = null,
|
||||
@@ -525,6 +528,11 @@ pub const VirtualMachine = struct {
|
||||
transform_task.*.runFromJS();
|
||||
finished += 1;
|
||||
},
|
||||
@field(Task.Tag, @typeName(ReadFileTask)) => {
|
||||
var transform_task: *ReadFileTask = task.get(ReadFileTask).?;
|
||||
transform_task.*.runFromJS();
|
||||
finished += 1;
|
||||
},
|
||||
else => unreachable,
|
||||
}
|
||||
}
|
||||
@@ -732,6 +740,7 @@ pub const VirtualMachine = struct {
|
||||
.macro_entry_points = @TypeOf(VirtualMachine.vm.macro_entry_points).init(allocator),
|
||||
.origin_timer = std.time.Timer.start() catch @panic("Please don't mess with timers."),
|
||||
.ref_strings = JSC.RefString.Map.init(allocator),
|
||||
.file_blobs = JSC.WebCore.Blob.Store.Map.init(allocator),
|
||||
};
|
||||
VirtualMachine.vm.regular_event_loop.tasks = EventLoop.Queue.init(
|
||||
default_allocator,
|
||||
@@ -784,6 +793,21 @@ pub const VirtualMachine = struct {
|
||||
_ = VirtualMachine.vm.ref_strings.remove(ref_string.hash);
|
||||
}
|
||||
|
||||
pub fn getFileBlob(this: *VirtualMachine, pathlike: JSC.Node.PathOrFileDescriptor) ?*JSC.WebCore.Blob.Store {
|
||||
const hash = pathlike.hash();
|
||||
return this.file_blobs.get(hash);
|
||||
}
|
||||
|
||||
pub fn putFileBlob(this: *VirtualMachine, pathlike: JSC.Node.PathOrFileDescriptor, store: *JSC.WebCore.Blob.Store) !void {
|
||||
const hash = pathlike.hash();
|
||||
try this.file_blobs.put(hash, store);
|
||||
}
|
||||
|
||||
pub fn removeFileBlob(this: *VirtualMachine, pathlike: JSC.Node.PathOrFileDescriptor) void {
|
||||
const hash = pathlike.hash();
|
||||
_ = this.file_blobs.remove(hash);
|
||||
}
|
||||
|
||||
pub fn refCountedResolvedSource(this: *VirtualMachine, code: []const u8, specifier: []const u8, source_url: []const u8, hash_: ?u32) ResolvedSource {
|
||||
var source = this.refCountedString(code, hash_, true);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user