aboutsummaryrefslogtreecommitdiff
path: root/src/bun.js/bindings/ZigGlobalObject.cpp
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2022-09-28 00:11:15 -0700
committerGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2022-09-28 00:11:15 -0700
commit71ea4a2c9bf38f1ac3e6351c3f863b6698513b82 (patch)
tree1aa534d170c2f3cca4654199b6c3d2bc6ba7b318 /src/bun.js/bindings/ZigGlobalObject.cpp
parenta8ab18bd50b3a98c65c6ce96bd75d87d7893df12 (diff)
downloadbun-71ea4a2c9bf38f1ac3e6351c3f863b6698513b82.tar.gz
bun-71ea4a2c9bf38f1ac3e6351c3f863b6698513b82.tar.zst
bun-71ea4a2c9bf38f1ac3e6351c3f863b6698513b82.zip
Fix several bugs with Request body streaming + store small response bodies without an extra memory allocation
Diffstat (limited to 'src/bun.js/bindings/ZigGlobalObject.cpp')
-rw-r--r--src/bun.js/bindings/ZigGlobalObject.cpp37
1 files changed, 33 insertions, 4 deletions
diff --git a/src/bun.js/bindings/ZigGlobalObject.cpp b/src/bun.js/bindings/ZigGlobalObject.cpp
index 33828f7ee..f14352230 100644
--- a/src/bun.js/bindings/ZigGlobalObject.cpp
+++ b/src/bun.js/bindings/ZigGlobalObject.cpp
@@ -1,4 +1,3 @@
-
#include "root.h"
#include "ZigGlobalObject.h"
@@ -115,7 +114,8 @@
#include "JavaScriptCore/RemoteInspectorServer.h"
#endif
-using JSGlobalObject = JSC::JSGlobalObject;
+using JSGlobalObject
+ = JSC::JSGlobalObject;
using Exception = JSC::Exception;
using JSValue = JSC::JSValue;
using JSString = JSC::JSString;
@@ -979,6 +979,30 @@ JSC_DEFINE_CUSTOM_SETTER(noop_setter,
static NeverDestroyed<const String> pathToFileURLString(MAKE_STATIC_STRING_IMPL("pathToFileURL"));
static NeverDestroyed<const String> fileURLToPathString(MAKE_STATIC_STRING_IMPL("fileURLToPath"));
+enum ReadableStreamTag : int32_t {
+ Invalid = -1,
+
+ /// ReadableStreamDefaultController or ReadableByteStreamController
+ JavaScript = 0,
+
+ /// ReadableByteStreamController
+ /// but with a BlobLoader
+ /// we can skip the BlobLoader and just use the underlying Blob
+ Blob = 1,
+
+ /// ReadableByteStreamController
+ /// but with a FileLoader
+ /// we can skip the FileLoader and just use the underlying File
+ File = 2,
+
+ /// This is a direct readable stream
+ /// That means we can turn it into whatever we want
+ Direct = 3,
+
+ // This is an ambiguous stream of bytes
+ Bytes = 4,
+};
+
// we're trying out a new way to do this lazy loading
static JSC_DECLARE_HOST_FUNCTION(functionLazyLoad);
static JSC_DEFINE_HOST_FUNCTION(functionLazyLoad,
@@ -1010,12 +1034,16 @@ JSC:
return JSC::JSValue::encode(JSC::JSValue {});
}
- case 1: {
+ case ReadableStreamTag::Blob: {
return ByteBlob__JSReadableStreamSource__load(globalObject);
}
- case 2: {
+ case ReadableStreamTag::File: {
return FileBlobLoader__JSReadableStreamSource__load(globalObject);
}
+ case ReadableStreamTag::Bytes: {
+ return ByteStream__JSReadableStreamSource__load(globalObject);
+ }
+
default: {
auto scope = DECLARE_THROW_SCOPE(globalObject->vm());
JSC::throwTypeError(globalObject, scope, "lazyLoad expects a string"_s);
@@ -1352,6 +1380,7 @@ extern "C" void ReadableStream__cancel(JSC__JSValue possibleReadableStream, Zig:
WebCore::Exception exception { AbortError };
ReadableStream(*globalObject, *readableStream).cancel(exception);
}
+
extern "C" void ReadableStream__detach(JSC__JSValue possibleReadableStream, Zig::GlobalObject* globalObject);
extern "C" void ReadableStream__detach(JSC__JSValue possibleReadableStream, Zig::GlobalObject* globalObject)
{