diff options
author | 2022-06-07 22:42:47 -0700 | |
---|---|---|
committer | 2022-06-07 22:42:47 -0700 | |
commit | 609edc368f896063b2b81f483533a757a8be68ff (patch) | |
tree | 260651d970b59c5cafa3bc268d33bc36843a77ef | |
parent | 5b4dcb8d169f0463df83624a25b004636f3516d9 (diff) | |
download | bun-609edc368f896063b2b81f483533a757a8be68ff.tar.gz bun-609edc368f896063b2b81f483533a757a8be68ff.tar.zst bun-609edc368f896063b2b81f483533a757a8be68ff.zip |
wip ReadableStream <> zig
-rw-r--r-- | src/javascript/jsc/webcore/streams.zig | 65 |
1 files changed, 58 insertions, 7 deletions
diff --git a/src/javascript/jsc/webcore/streams.zig b/src/javascript/jsc/webcore/streams.zig index 13829cd91..fea962e1e 100644 --- a/src/javascript/jsc/webcore/streams.zig +++ b/src/javascript/jsc/webcore/streams.zig @@ -48,12 +48,70 @@ const Response = JSC.WebCore.Response; const Request = JSC.WebCore.Request; pub const ReadableStream = struct { + value: JSValue, + ptr: Handle, + pub const Tag = enum(i32) { + Invalid = -1, + + JavaScript = 0, Blob = 1, File = 2, HTTPRequest = 3, HTTPSRequest = 4, }; + pub const Handle = union(Tag) { + Invalid: void, + JavaScript: void, + Blob: *ByteBlobLoader, + File: *FileBlobLoader, + HTTPRequest: void, + HTTPSRequest: void, + }; + + extern fn ReadableStreamTag__tagged(globalObject: *JSGlobalObject, possibleReadableStream: JSValue, ptr: *JSValue) Tag; + extern fn ReadableStream__isDisturbed(possibleReadableStream: JSValue, globalObject: *JSGlobalObject) bool; + extern fn ReadableStream__isLocked(possibleReadableStream: JSValue, globalObject: *JSGlobalObject) bool; + extern fn ReadableStream__empty(*JSGlobalObject) JSC.JSValue; + extern fn ReadableStream__fromBlob( + *JSGlobalObject, + store: *anyopaque, + offset: usize, + length: usize, + ) JSC.JSValue; + + pub fn isDisturbed(this: *const ReadableStream, globalObject: *JSGlobalObject) bool { + return ReadableStream__isDisturbed(this.value, globalObject); + } + + pub fn isLocked(this: *const ReadableStream, globalObject: *JSGlobalObject) bool { + return ReadableStream__isLocked(this.value, globalObject); + } + + pub fn fromJS(value: JSValue, globalThis: *JSGlobalObject) ?ReadableStream { + var ptr = JSValue.zero; + return switch (ReadableStreamTag__tagged(globalThis, value, &ptr)) { + .JavaScript => ReadableStream{ + .value = value, + .ptr = .{ + .JavaScript = {}, + }, + }, + .Blob => ReadableStream{ + .value = value, + .ptr = .{ + .Blob = ptr.asPtr(ByteBlobLoader), + }, + }, + .File => ReadableStream{ + .value = value, + .ptr = .{ + .File = ptr.asPtr(FileBlobLoader), + }, + }, + else => null, + }; + } extern fn ZigGlobalObject__createNativeReadableStream(*JSGlobalObject, nativePtr: JSValue, nativeType: JSValue) JSValue; @@ -93,13 +151,6 @@ pub const ReadableStream = struct { return ReadableStream__empty(globalThis); } - extern fn ReadableStream__empty(*JSGlobalObject) JSC.JSValue; - extern fn ReadableStream__fromBlob( - *JSGlobalObject, - store: *anyopaque, - offset: usize, - length: usize, - ) JSC.JSValue; const Base = @import("../../../ast/base.zig"); pub const StreamTag = enum(usize) { invalid = 0, |