aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2023-07-13 01:41:56 -0700
committerGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2023-07-17 20:27:54 -0700
commit802f9ccb5864e9e1cfee7c0aa5abffbb69d53fdc (patch)
tree21c7ce86cb2f8732140e38cf69c7e511450d776f /src
parentc676a64ce4f2ab3262ac0c3013403e34d1b24a52 (diff)
downloadbun-802f9ccb5864e9e1cfee7c0aa5abffbb69d53fdc.tar.gz
bun-802f9ccb5864e9e1cfee7c0aa5abffbb69d53fdc.tar.zst
bun-802f9ccb5864e9e1cfee7c0aa5abffbb69d53fdc.zip
wip!
Diffstat (limited to 'src')
-rw-r--r--src/bun.js/api/js_brotli.zig4
-rw-r--r--src/bun.js/bindings/JSMockFunction.cpp17
-rw-r--r--src/bun.js/bindings/JSSink.cpp1002
-rw-r--r--src/bun.js/bindings/JSSink.h296
-rw-r--r--src/bun.js/bindings/JSSinkLookupTable.h162
-rw-r--r--src/bun.js/bindings/ModuleLoader.cpp27
-rw-r--r--src/bun.js/bindings/Sink.h4
-rw-r--r--src/bun.js/bindings/ZigGlobalObject.cpp37
-rw-r--r--src/bun.js/bindings/ZigGlobalObject.h14
-rw-r--r--src/bun.js/bindings/exports.zig4
-rw-r--r--src/bun.js/bindings/headers-cpp.h6
-rw-r--r--src/bun.js/bindings/headers.zig12
-rw-r--r--src/bun.js/scripts/generate-jssink.js10
-rw-r--r--src/bun.js/webcore/streams.zig332
-rw-r--r--src/deps/brotli.zig104
15 files changed, 1933 insertions, 98 deletions
diff --git a/src/bun.js/api/js_brotli.zig b/src/bun.js/api/js_brotli.zig
index 12669ab44..41b8070ce 100644
--- a/src/bun.js/api/js_brotli.zig
+++ b/src/bun.js/api/js_brotli.zig
@@ -65,6 +65,10 @@ pub const Brotli = struct {
}
// chunkSize <integer> Default: 16 * 1024
+ var chunkSize_value = 16 * 1024;
+ if (try value.getOptional(globalObject, "chunkSize", u32)) |chunkSizey| {
+ chunkSize_value = chunkSizey;
+ }
// params <Object> Key-value object containing indexed Brotli parameters.
diff --git a/src/bun.js/bindings/JSMockFunction.cpp b/src/bun.js/bindings/JSMockFunction.cpp
index 3a84f0139..a8824725e 100644
--- a/src/bun.js/bindings/JSMockFunction.cpp
+++ b/src/bun.js/bindings/JSMockFunction.cpp
@@ -20,6 +20,7 @@
#include <JavaScriptCore/WeakMapImplInlines.h>
#include <JavaScriptCore/FunctionPrototype.h>
#include <JavaScriptCore/DateInstance.h>
+#include <JavaScriptCore/JSInternalFieldObjectImplInlines.h>
namespace Bun {
@@ -1437,19 +1438,3 @@ JSC_DEFINE_HOST_FUNCTION(jsMockFunctionWithImplementation, (JSC::JSGlobalObject
return JSC::JSValue::encode(jsUndefined());
}
} // namespace Bun
-
-namespace JSC {
-
-template<unsigned passedNumberOfInternalFields>
-template<typename Visitor>
-void JSInternalFieldObjectImpl<passedNumberOfInternalFields>::visitChildrenImpl(JSCell* cell, Visitor& visitor)
-{
- auto* thisObject = jsCast<JSInternalFieldObjectImpl*>(cell);
- ASSERT_GC_OBJECT_INHERITS(thisObject, info());
- Base::visitChildren(thisObject, visitor);
- visitor.appendValues(thisObject->m_internalFields, numberOfInternalFields);
-}
-
-DEFINE_VISIT_CHILDREN_WITH_MODIFIER(template<unsigned passedNumberOfInternalFields>, JSInternalFieldObjectImpl<passedNumberOfInternalFields>);
-
-} // namespace JSC
diff --git a/src/bun.js/bindings/JSSink.cpp b/src/bun.js/bindings/JSSink.cpp
index 8be4fe95b..b360d429b 100644
--- a/src/bun.js/bindings/JSSink.cpp
+++ b/src/bun.js/bindings/JSSink.cpp
@@ -1,6 +1,6 @@
// AUTO-GENERATED FILE. DO NOT EDIT.
-// Generated by 'make generate-sink' at 2023-07-09T17:58:51.559Z
+// Generated by 'make generate-sink' at 2023-07-18T03:21:16.951Z
// To regenerate this file, run:
//
// make generate-sink
@@ -120,6 +120,24 @@ JSC_DEFINE_HOST_FUNCTION(functionStartDirectStream, (JSC::JSGlobalObject * lexic
HTTPSResponseSinkController->start(globalObject, readableStream, onPullFunction, onCloseFunction);
}
+ else if (WebCore::JSReadableBrotliDecompressorSinkController* BrotliDecompressorSinkController = JSC::jsDynamicCast<WebCore::JSReadableBrotliDecompressorSinkController*>(callFrame->thisValue())) {
+ if (BrotliDecompressorSinkController->wrapped() == nullptr) {
+ scope.throwException(globalObject, JSC::createTypeError(globalObject, "Cannot start stream with closed controller"_s));
+ return JSC::JSValue::encode(JSC::jsUndefined());
+ }
+
+ BrotliDecompressorSinkController->start(globalObject, readableStream, onPullFunction, onCloseFunction);
+ }
+
+ else if (WebCore::JSReadableBrotliCompressorSinkController* BrotliCompressorSinkController = JSC::jsDynamicCast<WebCore::JSReadableBrotliCompressorSinkController*>(callFrame->thisValue())) {
+ if (BrotliCompressorSinkController->wrapped() == nullptr) {
+ scope.throwException(globalObject, JSC::createTypeError(globalObject, "Cannot start stream with closed controller"_s));
+ return JSC::JSValue::encode(JSC::jsUndefined());
+ }
+
+ BrotliCompressorSinkController->start(globalObject, readableStream, onPullFunction, onCloseFunction);
+ }
+
else {
scope.throwException(globalObject, JSC::createTypeError(globalObject, "Unknown direct controller. This is a bug in Bun."_s));
return JSC::JSValue::encode(JSC::jsUndefined());
@@ -600,6 +618,242 @@ JSC_DEFINE_HOST_FUNCTION(HTTPSResponseSink__doClose, (JSC::JSGlobalObject * lexi
return JSC::JSValue::encode(JSC::jsUndefined());
}
+void JSBrotliDecompressorSink::ref()
+{
+ if (!m_sinkPtr)
+ return;
+
+ m_refCount++;
+ if (m_refCount == 1) {
+ BrotliDecompressorSink__updateRef(m_sinkPtr, true);
+ }
+}
+
+void JSBrotliDecompressorSink::unref()
+{
+ if (!m_sinkPtr)
+ return;
+
+ m_refCount = std::max(0, m_refCount - 1);
+ if (!m_refCount) {
+ BrotliDecompressorSink__updateRef(m_sinkPtr, false);
+ }
+}
+
+JSC_DEFINE_HOST_FUNCTION(BrotliDecompressorSink__ref, (JSC::JSGlobalObject * lexicalGlobalObject, JSC::CallFrame* callFrame))
+{
+ auto& vm = lexicalGlobalObject->vm();
+ auto* sink = jsDynamicCast<WebCore::JSBrotliDecompressorSink*>(callFrame->thisValue());
+ if (LIKELY(sink)) {
+ sink->ref();
+ }
+ return JSC::JSValue::encode(JSC::jsUndefined());
+}
+
+JSC_DEFINE_HOST_FUNCTION(BrotliDecompressorSink__unref, (JSC::JSGlobalObject * lexicalGlobalObject, JSC::CallFrame* callFrame))
+{
+ auto& vm = lexicalGlobalObject->vm();
+ auto* sink = jsDynamicCast<WebCore::JSBrotliDecompressorSink*>(callFrame->thisValue());
+ if (LIKELY(sink)) {
+ sink->unref();
+ }
+ return JSC::JSValue::encode(JSC::jsUndefined());
+}
+
+JSC_DEFINE_CUSTOM_GETTER(functionBrotliDecompressorSink__getter, (JSC::JSGlobalObject * lexicalGlobalObject, JSC::EncodedJSValue thisValue, JSC::PropertyName))
+{
+ auto& vm = lexicalGlobalObject->vm();
+ Zig::GlobalObject* globalObject = reinterpret_cast<Zig::GlobalObject*>(lexicalGlobalObject);
+
+ return JSC::JSValue::encode(globalObject->BrotliDecompressorSink());
+}
+
+JSC_DECLARE_HOST_FUNCTION(JSReadableBrotliDecompressorSinkController__close);
+JSC_DEFINE_HOST_FUNCTION(JSReadableBrotliDecompressorSinkController__close, (JSC::JSGlobalObject * lexicalGlobalObject, JSC::CallFrame* callFrame))
+{
+
+ auto& vm = lexicalGlobalObject->vm();
+ auto scope = DECLARE_THROW_SCOPE(vm);
+ Zig::GlobalObject* globalObject = reinterpret_cast<Zig::GlobalObject*>(lexicalGlobalObject);
+ WebCore::JSReadableBrotliDecompressorSinkController* controller = JSC::jsDynamicCast<WebCore::JSReadableBrotliDecompressorSinkController*>(callFrame->thisValue());
+ if (!controller) {
+ scope.throwException(globalObject, JSC::createTypeError(globalObject, "Expected JSReadableBrotliDecompressorSinkController"_s));
+ return JSC::JSValue::encode(JSC::jsUndefined());
+ }
+
+ void* ptr = controller->wrapped();
+ if (ptr == nullptr) {
+ return JSC::JSValue::encode(JSC::jsUndefined());
+ }
+
+ controller->detach();
+ BrotliDecompressorSink__close(lexicalGlobalObject, ptr);
+ return JSC::JSValue::encode(JSC::jsUndefined());
+}
+
+JSC_DECLARE_HOST_FUNCTION(JSReadableBrotliDecompressorSinkController__end);
+JSC_DEFINE_HOST_FUNCTION(JSReadableBrotliDecompressorSinkController__end, (JSC::JSGlobalObject * lexicalGlobalObject, JSC::CallFrame* callFrame))
+{
+
+ auto& vm = lexicalGlobalObject->vm();
+ auto scope = DECLARE_THROW_SCOPE(vm);
+ Zig::GlobalObject* globalObject = reinterpret_cast<Zig::GlobalObject*>(lexicalGlobalObject);
+ WebCore::JSReadableBrotliDecompressorSinkController* controller = JSC::jsDynamicCast<WebCore::JSReadableBrotliDecompressorSinkController*>(callFrame->thisValue());
+ if (!controller) {
+ scope.throwException(globalObject, JSC::createTypeError(globalObject, "Expected JSReadableBrotliDecompressorSinkController"_s));
+ return JSC::JSValue::encode(JSC::jsUndefined());
+ }
+
+ void* ptr = controller->wrapped();
+ if (ptr == nullptr) {
+ return JSC::JSValue::encode(JSC::jsUndefined());
+ }
+
+ controller->detach();
+ return BrotliDecompressorSink__endWithSink(ptr, lexicalGlobalObject);
+}
+
+JSC_DECLARE_HOST_FUNCTION(BrotliDecompressorSink__doClose);
+JSC_DEFINE_HOST_FUNCTION(BrotliDecompressorSink__doClose, (JSC::JSGlobalObject * lexicalGlobalObject, JSC::CallFrame* callFrame))
+{
+
+ auto& vm = lexicalGlobalObject->vm();
+ auto scope = DECLARE_THROW_SCOPE(vm);
+ Zig::GlobalObject* globalObject = reinterpret_cast<Zig::GlobalObject*>(lexicalGlobalObject);
+ WebCore::JSBrotliDecompressorSink* sink = JSC::jsDynamicCast<WebCore::JSBrotliDecompressorSink*>(callFrame->thisValue());
+ if (!sink) {
+ scope.throwException(globalObject, JSC::createTypeError(globalObject, "Expected BrotliDecompressorSink"_s));
+ return JSC::JSValue::encode(JSC::jsUndefined());
+ }
+
+ void* ptr = sink->wrapped();
+ if (ptr == nullptr) {
+ return JSC::JSValue::encode(JSC::jsUndefined());
+ }
+
+ sink->detach();
+ BrotliDecompressorSink__close(lexicalGlobalObject, ptr);
+ return JSC::JSValue::encode(JSC::jsUndefined());
+}
+
+void JSBrotliCompressorSink::ref()
+{
+ if (!m_sinkPtr)
+ return;
+
+ m_refCount++;
+ if (m_refCount == 1) {
+ BrotliCompressorSink__updateRef(m_sinkPtr, true);
+ }
+}
+
+void JSBrotliCompressorSink::unref()
+{
+ if (!m_sinkPtr)
+ return;
+
+ m_refCount = std::max(0, m_refCount - 1);
+ if (!m_refCount) {
+ BrotliCompressorSink__updateRef(m_sinkPtr, false);
+ }
+}
+
+JSC_DEFINE_HOST_FUNCTION(BrotliCompressorSink__ref, (JSC::JSGlobalObject * lexicalGlobalObject, JSC::CallFrame* callFrame))
+{
+ auto& vm = lexicalGlobalObject->vm();
+ auto* sink = jsDynamicCast<WebCore::JSBrotliCompressorSink*>(callFrame->thisValue());
+ if (LIKELY(sink)) {
+ sink->ref();
+ }
+ return JSC::JSValue::encode(JSC::jsUndefined());
+}
+
+JSC_DEFINE_HOST_FUNCTION(BrotliCompressorSink__unref, (JSC::JSGlobalObject * lexicalGlobalObject, JSC::CallFrame* callFrame))
+{
+ auto& vm = lexicalGlobalObject->vm();
+ auto* sink = jsDynamicCast<WebCore::JSBrotliCompressorSink*>(callFrame->thisValue());
+ if (LIKELY(sink)) {
+ sink->unref();
+ }
+ return JSC::JSValue::encode(JSC::jsUndefined());
+}
+
+JSC_DEFINE_CUSTOM_GETTER(functionBrotliCompressorSink__getter, (JSC::JSGlobalObject * lexicalGlobalObject, JSC::EncodedJSValue thisValue, JSC::PropertyName))
+{
+ auto& vm = lexicalGlobalObject->vm();
+ Zig::GlobalObject* globalObject = reinterpret_cast<Zig::GlobalObject*>(lexicalGlobalObject);
+
+ return JSC::JSValue::encode(globalObject->BrotliCompressorSink());
+}
+
+JSC_DECLARE_HOST_FUNCTION(JSReadableBrotliCompressorSinkController__close);
+JSC_DEFINE_HOST_FUNCTION(JSReadableBrotliCompressorSinkController__close, (JSC::JSGlobalObject * lexicalGlobalObject, JSC::CallFrame* callFrame))
+{
+
+ auto& vm = lexicalGlobalObject->vm();
+ auto scope = DECLARE_THROW_SCOPE(vm);
+ Zig::GlobalObject* globalObject = reinterpret_cast<Zig::GlobalObject*>(lexicalGlobalObject);
+ WebCore::JSReadableBrotliCompressorSinkController* controller = JSC::jsDynamicCast<WebCore::JSReadableBrotliCompressorSinkController*>(callFrame->thisValue());
+ if (!controller) {
+ scope.throwException(globalObject, JSC::createTypeError(globalObject, "Expected JSReadableBrotliCompressorSinkController"_s));
+ return JSC::JSValue::encode(JSC::jsUndefined());
+ }
+
+ void* ptr = controller->wrapped();
+ if (ptr == nullptr) {
+ return JSC::JSValue::encode(JSC::jsUndefined());
+ }
+
+ controller->detach();
+ BrotliCompressorSink__close(lexicalGlobalObject, ptr);
+ return JSC::JSValue::encode(JSC::jsUndefined());
+}
+
+JSC_DECLARE_HOST_FUNCTION(JSReadableBrotliCompressorSinkController__end);
+JSC_DEFINE_HOST_FUNCTION(JSReadableBrotliCompressorSinkController__end, (JSC::JSGlobalObject * lexicalGlobalObject, JSC::CallFrame* callFrame))
+{
+
+ auto& vm = lexicalGlobalObject->vm();
+ auto scope = DECLARE_THROW_SCOPE(vm);
+ Zig::GlobalObject* globalObject = reinterpret_cast<Zig::GlobalObject*>(lexicalGlobalObject);
+ WebCore::JSReadableBrotliCompressorSinkController* controller = JSC::jsDynamicCast<WebCore::JSReadableBrotliCompressorSinkController*>(callFrame->thisValue());
+ if (!controller) {
+ scope.throwException(globalObject, JSC::createTypeError(globalObject, "Expected JSReadableBrotliCompressorSinkController"_s));
+ return JSC::JSValue::encode(JSC::jsUndefined());
+ }
+
+ void* ptr = controller->wrapped();
+ if (ptr == nullptr) {
+ return JSC::JSValue::encode(JSC::jsUndefined());
+ }
+
+ controller->detach();
+ return BrotliCompressorSink__endWithSink(ptr, lexicalGlobalObject);
+}
+
+JSC_DECLARE_HOST_FUNCTION(BrotliCompressorSink__doClose);
+JSC_DEFINE_HOST_FUNCTION(BrotliCompressorSink__doClose, (JSC::JSGlobalObject * lexicalGlobalObject, JSC::CallFrame* callFrame))
+{
+
+ auto& vm = lexicalGlobalObject->vm();
+ auto scope = DECLARE_THROW_SCOPE(vm);
+ Zig::GlobalObject* globalObject = reinterpret_cast<Zig::GlobalObject*>(lexicalGlobalObject);
+ WebCore::JSBrotliCompressorSink* sink = JSC::jsDynamicCast<WebCore::JSBrotliCompressorSink*>(callFrame->thisValue());
+ if (!sink) {
+ scope.throwException(globalObject, JSC::createTypeError(globalObject, "Expected BrotliCompressorSink"_s));
+ return JSC::JSValue::encode(JSC::jsUndefined());
+ }
+
+ void* ptr = sink->wrapped();
+ if (ptr == nullptr) {
+ return JSC::JSValue::encode(JSC::jsUndefined());
+ }
+
+ sink->detach();
+ BrotliCompressorSink__close(lexicalGlobalObject, ptr);
+ return JSC::JSValue::encode(JSC::jsUndefined());
+}
+
#include "JSSinkLookupTable.h"
/* Source for JSArrayBufferSinkPrototypeTableValues.lut.h
@@ -690,6 +944,50 @@ JSC_DEFINE_HOST_FUNCTION(HTTPSResponseSink__doClose, (JSC::JSGlobalObject * lexi
@end
*/
+/* Source for JSBrotliDecompressorSinkPrototypeTableValues.lut.h
+@begin JSBrotliDecompressorSinkPrototypeTable
+ close BrotliDecompressorSink__doClose ReadOnly|DontDelete|Function 0
+ flush BrotliDecompressorSink__flush ReadOnly|DontDelete|Function 1
+ end BrotliDecompressorSink__end ReadOnly|DontDelete|Function 0
+ start BrotliDecompressorSink__start ReadOnly|DontDelete|Function 1
+ write BrotliDecompressorSink__write ReadOnly|DontDelete|Function 1
+ ref BrotliDecompressorSink__ref ReadOnly|DontDelete|Function 0
+ unref BrotliDecompressorSink__unref ReadOnly|DontDelete|Function 0
+@end
+*/
+
+/* Source for JSReadableBrotliDecompressorSinkControllerPrototypeTableValues.lut.h
+@begin JSReadableBrotliDecompressorSinkControllerPrototypeTable
+ close JSReadableBrotliDecompressorSinkController__close ReadOnly|DontDelete|Function 0
+ flush BrotliDecompressorSink__flush ReadOnly|DontDelete|Function 1
+ end JSReadableBrotliDecompressorSinkController__end ReadOnly|DontDelete|Function 0
+ start BrotliDecompressorSink__start ReadOnly|DontDelete|Function 1
+ write BrotliDecompressorSink__write ReadOnly|DontDelete|Function 1
+@end
+*/
+
+/* Source for JSBrotliCompressorSinkPrototypeTableValues.lut.h
+@begin JSBrotliCompressorSinkPrototypeTable
+ close BrotliCompressorSink__doClose ReadOnly|DontDelete|Function 0
+ flush BrotliCompressorSink__flush ReadOnly|DontDelete|Function 1
+ end BrotliCompressorSink__end ReadOnly|DontDelete|Function 0
+ start BrotliCompressorSink__start ReadOnly|DontDelete|Function 1
+ write BrotliCompressorSink__write ReadOnly|DontDelete|Function 1
+ ref BrotliCompressorSink__ref ReadOnly|DontDelete|Function 0
+ unref BrotliCompressorSink__unref ReadOnly|DontDelete|Function 0
+@end
+*/
+
+/* Source for JSReadableBrotliCompressorSinkControllerPrototypeTableValues.lut.h
+@begin JSReadableBrotliCompressorSinkControllerPrototypeTable
+ close JSReadableBrotliCompressorSinkController__close ReadOnly|DontDelete|Function 0
+ flush BrotliCompressorSink__flush ReadOnly|DontDelete|Function 1
+ end JSReadableBrotliCompressorSinkController__end ReadOnly|DontDelete|Function 0
+ start BrotliCompressorSink__start ReadOnly|DontDelete|Function 1
+ write BrotliCompressorSink__write ReadOnly|DontDelete|Function 1
+@end
+*/
+
#pragma mark - ArrayBufferSink
class JSArrayBufferSinkPrototype final : public JSC::JSNonFinalObject {
@@ -1706,6 +2004,514 @@ void JSReadableHTTPSResponseSinkController::destroy(JSCell* cell)
static_cast<JSReadableHTTPSResponseSinkController*>(cell)->JSReadableHTTPSResponseSinkController::~JSReadableHTTPSResponseSinkController();
}
+#pragma mark - BrotliDecompressorSink
+
+class JSBrotliDecompressorSinkPrototype final : public JSC::JSNonFinalObject {
+public:
+ using Base = JSC::JSNonFinalObject;
+
+ static JSBrotliDecompressorSinkPrototype* create(JSC::VM& vm, JSGlobalObject* globalObject, JSC::Structure* structure)
+ {
+ JSBrotliDecompressorSinkPrototype* ptr = new (NotNull, JSC::allocateCell<JSBrotliDecompressorSinkPrototype>(vm)) JSBrotliDecompressorSinkPrototype(vm, globalObject, structure);
+ ptr->finishCreation(vm, globalObject);
+ return ptr;
+ }
+
+ DECLARE_INFO;
+ template<typename CellType, JSC::SubspaceAccess>
+ static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm)
+ {
+ return &vm.plainObjectSpace();
+ }
+ static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
+ {
+ return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info());
+ }
+
+private:
+ JSBrotliDecompressorSinkPrototype(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure)
+ : Base(vm, structure)
+ {
+ }
+
+ void finishCreation(JSC::VM&, JSC::JSGlobalObject*);
+};
+STATIC_ASSERT_ISO_SUBSPACE_SHARABLE(JSBrotliDecompressorSinkPrototype, JSBrotliDecompressorSinkPrototype::Base);
+
+class JSReadableBrotliDecompressorSinkControllerPrototype final : public JSC::JSNonFinalObject {
+public:
+ using Base = JSC::JSNonFinalObject;
+
+ static JSReadableBrotliDecompressorSinkControllerPrototype* create(JSC::VM& vm, JSGlobalObject* globalObject, JSC::Structure* structure)
+ {
+ JSReadableBrotliDecompressorSinkControllerPrototype* ptr = new (NotNull, JSC::allocateCell<JSReadableBrotliDecompressorSinkControllerPrototype>(vm)) JSReadableBrotliDecompressorSinkControllerPrototype(vm, globalObject, structure);
+ ptr->finishCreation(vm, globalObject);
+ return ptr;
+ }
+
+ DECLARE_INFO;
+ template<typename CellType, JSC::SubspaceAccess>
+ static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm)
+ {
+ return &vm.plainObjectSpace();
+ }
+ static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
+ {
+ return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info());
+ }
+
+private:
+ JSReadableBrotliDecompressorSinkControllerPrototype(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure)
+ : Base(vm, structure)
+ {
+ }
+
+ void finishCreation(JSC::VM&, JSC::JSGlobalObject*);
+};
+STATIC_ASSERT_ISO_SUBSPACE_SHARABLE(JSReadableBrotliDecompressorSinkControllerPrototype, JSReadableBrotliDecompressorSinkControllerPrototype::Base);
+
+const ClassInfo JSBrotliDecompressorSinkPrototype::s_info = { "BrotliDecompressorSink"_s, &Base::s_info, &JSBrotliDecompressorSinkPrototypeTable, nullptr, CREATE_METHOD_TABLE(JSBrotliDecompressorSinkPrototype) };
+const ClassInfo JSBrotliDecompressorSink::s_info = { "BrotliDecompressorSink"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSBrotliDecompressorSink) };
+const ClassInfo JSBrotliDecompressorSinkConstructor::s_info = { "BrotliDecompressorSink"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSBrotliDecompressorSinkConstructor) };
+
+const ClassInfo JSReadableBrotliDecompressorSinkControllerPrototype::s_info = { "ReadableBrotliDecompressorSinkController"_s, &Base::s_info, &JSReadableBrotliDecompressorSinkControllerPrototypeTable, nullptr, CREATE_METHOD_TABLE(JSReadableBrotliDecompressorSinkControllerPrototype) };
+const ClassInfo JSReadableBrotliDecompressorSinkController::s_info = { "ReadableBrotliDecompressorSinkController"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSReadableBrotliDecompressorSinkController) };
+
+JSBrotliDecompressorSink::~JSBrotliDecompressorSink()
+{
+ if (m_sinkPtr) {
+ BrotliDecompressorSink__finalize(m_sinkPtr);
+ }
+}
+
+JSReadableBrotliDecompressorSinkController::~JSReadableBrotliDecompressorSinkController()
+{
+ if (m_sinkPtr) {
+ BrotliDecompressorSink__finalize(m_sinkPtr);
+ }
+}
+
+JSObject* JSBrotliDecompressorSink::createPrototype(VM& vm, JSDOMGlobalObject& globalObject)
+{
+ return JSBrotliDecompressorSinkPrototype::create(vm, &globalObject, JSBrotliDecompressorSinkPrototype::createStructure(vm, &globalObject, globalObject.objectPrototype()));
+}
+
+JSObject* JSReadableBrotliDecompressorSinkController::createPrototype(VM& vm, JSDOMGlobalObject& globalObject)
+{
+ return JSReadableBrotliDecompressorSinkControllerPrototype::create(vm, &globalObject, JSReadableBrotliDecompressorSinkControllerPrototype::createStructure(vm, &globalObject, globalObject.objectPrototype()));
+}
+
+void JSReadableBrotliDecompressorSinkController::detach()
+{
+ m_sinkPtr = nullptr;
+ m_onPull.clear();
+
+ auto readableStream = m_weakReadableStream.get();
+ auto onClose = m_onClose.get();
+ m_onClose.clear();
+
+ if (readableStream && onClose) {
+ JSC::JSGlobalObject* globalObject = this->globalObject();
+ auto callData = JSC::getCallData(onClose);
+ JSC::MarkedArgumentBuffer arguments;
+ arguments.append(readableStream);
+ arguments.append(jsUndefined());
+ JSC::call(globalObject, onClose, callData, JSC::jsUndefined(), arguments);
+ }
+
+ m_weakReadableStream.clear();
+}
+
+JSBrotliDecompressorSinkConstructor* JSBrotliDecompressorSinkConstructor::create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure, JSObject* prototype)
+{
+ JSBrotliDecompressorSinkConstructor* ptr = new (NotNull, JSC::allocateCell<JSBrotliDecompressorSinkConstructor>(vm)) JSBrotliDecompressorSinkConstructor(vm, structure, BrotliDecompressorSink__construct);
+ ptr->finishCreation(vm, globalObject, prototype);
+ return ptr;
+}
+
+JSBrotliDecompressorSink* JSBrotliDecompressorSink::create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure, void* sinkPtr)
+{
+ JSBrotliDecompressorSink* ptr = new (NotNull, JSC::allocateCell<JSBrotliDecompressorSink>(vm)) JSBrotliDecompressorSink(vm, structure, sinkPtr);
+ ptr->finishCreation(vm);
+ return ptr;
+}
+
+JSReadableBrotliDecompressorSinkController* JSReadableBrotliDecompressorSinkController::create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure, void* sinkPtr)
+{
+ JSReadableBrotliDecompressorSinkController* ptr = new (NotNull, JSC::allocateCell<JSReadableBrotliDecompressorSinkController>(vm)) JSReadableBrotliDecompressorSinkController(vm, structure, sinkPtr);
+ ptr->finishCreation(vm);
+ return ptr;
+}
+
+void JSBrotliDecompressorSinkConstructor::finishCreation(VM& vm, JSC::JSGlobalObject* globalObject, JSObject* prototype)
+{
+ Base::finishCreation(vm);
+ ASSERT(inherits(info()));
+ initializeProperties(vm, globalObject, prototype);
+}
+
+JSC::EncodedJSValue JSC_HOST_CALL_ATTRIBUTES JSBrotliDecompressorSinkConstructor::construct(JSC::JSGlobalObject* globalObject, JSC::CallFrame* callFrame)
+{
+ return BrotliDecompressorSink__construct(globalObject, callFrame);
+}
+
+void JSBrotliDecompressorSinkConstructor::initializeProperties(VM& vm, JSC::JSGlobalObject* globalObject, JSObject* prototype)
+{
+ putDirect(vm, vm.propertyNames->length, jsNumber(0), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
+ JSString* nameString = jsNontrivialString(vm, "BrotliDecompressorSink"_s);
+ m_originalName.set(vm, this, nameString);
+ putDirect(vm, vm.propertyNames->name, nameString, JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
+}
+
+void JSBrotliDecompressorSinkPrototype::finishCreation(JSC::VM& vm, JSC::JSGlobalObject* globalObject)
+{
+ Base::finishCreation(vm);
+ reifyStaticProperties(vm, JSBrotliDecompressorSink::info(), JSBrotliDecompressorSinkPrototypeTableValues, *this);
+ putDirect(vm, JSC::Identifier::fromString(vm, "sinkId"_s), JSC::jsNumber(JSBrotliDecompressorSink::Sink), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
+ JSC_TO_STRING_TAG_WITHOUT_TRANSITION();
+}
+
+void JSReadableBrotliDecompressorSinkControllerPrototype::finishCreation(JSC::VM& vm, JSC::JSGlobalObject* globalObject)
+{
+ Base::finishCreation(vm);
+ reifyStaticProperties(vm, JSReadableBrotliDecompressorSinkController::info(), JSReadableBrotliDecompressorSinkControllerPrototypeTableValues, *this);
+ putDirect(vm, JSC::Identifier::fromString(vm, "sinkId"_s), JSC::jsNumber(JSBrotliDecompressorSink::Sink), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
+ JSC_TO_STRING_TAG_WITHOUT_TRANSITION();
+}
+
+void JSBrotliDecompressorSink::finishCreation(VM& vm)
+{
+ Base::finishCreation(vm);
+ ASSERT(inherits(info()));
+}
+
+void JSReadableBrotliDecompressorSinkController::finishCreation(VM& vm)
+{
+ Base::finishCreation(vm);
+ ASSERT(inherits(info()));
+}
+
+void JSBrotliDecompressorSink::analyzeHeap(JSCell* cell, HeapAnalyzer& analyzer)
+{
+ auto* thisObject = jsCast<JSBrotliDecompressorSink*>(cell);
+ if (void* wrapped = thisObject->wrapped()) {
+ analyzer.setWrappedObjectForCell(cell, wrapped);
+ // if (thisObject->scriptExecutionContext())
+ // analyzer.setLabelForCell(cell, "url " + thisObject->scriptExecutionContext()->url().string());
+ }
+ Base::analyzeHeap(cell, analyzer);
+}
+
+void JSReadableBrotliDecompressorSinkController::analyzeHeap(JSCell* cell, HeapAnalyzer& analyzer)
+{
+ auto* thisObject = jsCast<JSReadableBrotliDecompressorSinkController*>(cell);
+ if (void* wrapped = thisObject->wrapped()) {
+ analyzer.setWrappedObjectForCell(cell, wrapped);
+ // if (thisObject->scriptExecutionContext())
+ // analyzer.setLabelForCell(cell, "url " + thisObject->scriptExecutionContext()->url().string());
+ }
+ Base::analyzeHeap(cell, analyzer);
+}
+
+template<typename Visitor>
+void JSReadableBrotliDecompressorSinkController::visitChildrenImpl(JSCell* cell, Visitor& visitor)
+{
+ JSReadableBrotliDecompressorSinkController* thisObject = jsCast<JSReadableBrotliDecompressorSinkController*>(cell);
+ ASSERT_GC_OBJECT_INHERITS(thisObject, info());
+ Base::visitChildren(thisObject, visitor);
+ visitor.append(thisObject->m_onPull);
+ visitor.append(thisObject->m_onClose);
+ void* ptr = thisObject->m_sinkPtr;
+ if (ptr)
+ visitor.addOpaqueRoot(ptr);
+}
+
+DEFINE_VISIT_CHILDREN(JSReadableBrotliDecompressorSinkController);
+
+template<typename Visitor>
+void JSBrotliDecompressorSink::visitChildrenImpl(JSCell* cell, Visitor& visitor)
+{
+ JSBrotliDecompressorSink* thisObject = jsCast<JSBrotliDecompressorSink*>(cell);
+ ASSERT_GC_OBJECT_INHERITS(thisObject, info());
+ Base::visitChildren(thisObject, visitor);
+ void* ptr = thisObject->m_sinkPtr;
+ if (ptr)
+ visitor.addOpaqueRoot(ptr);
+}
+
+DEFINE_VISIT_CHILDREN(JSBrotliDecompressorSink);
+
+void JSReadableBrotliDecompressorSinkController::start(JSC::JSGlobalObject* globalObject, JSC::JSValue readableStream, JSC::JSFunction* onPull, JSC::JSFunction* onClose)
+{
+ this->m_weakReadableStream = JSC::Weak<JSC::JSObject>(readableStream.getObject());
+ this->m_onPull.set(globalObject->vm(), this, onPull);
+ this->m_onClose.set(globalObject->vm(), this, onClose);
+}
+
+void JSBrotliDecompressorSink::destroy(JSCell* cell)
+{
+ static_cast<JSBrotliDecompressorSink*>(cell)->JSBrotliDecompressorSink::~JSBrotliDecompressorSink();
+}
+
+void JSReadableBrotliDecompressorSinkController::destroy(JSCell* cell)
+{
+ static_cast<JSReadableBrotliDecompressorSinkController*>(cell)->JSReadableBrotliDecompressorSinkController::~JSReadableBrotliDecompressorSinkController();
+}
+
+#pragma mark - BrotliCompressorSink
+
+class JSBrotliCompressorSinkPrototype final : public JSC::JSNonFinalObject {
+public:
+ using Base = JSC::JSNonFinalObject;
+
+ static JSBrotliCompressorSinkPrototype* create(JSC::VM& vm, JSGlobalObject* globalObject, JSC::Structure* structure)
+ {
+ JSBrotliCompressorSinkPrototype* ptr = new (NotNull, JSC::allocateCell<JSBrotliCompressorSinkPrototype>(vm)) JSBrotliCompressorSinkPrototype(vm, globalObject, structure);
+ ptr->finishCreation(vm, globalObject);
+ return ptr;
+ }
+
+ DECLARE_INFO;
+ template<typename CellType, JSC::SubspaceAccess>
+ static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm)
+ {
+ return &vm.plainObjectSpace();
+ }
+ static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
+ {
+ return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info());
+ }
+
+private:
+ JSBrotliCompressorSinkPrototype(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure)
+ : Base(vm, structure)
+ {
+ }
+
+ void finishCreation(JSC::VM&, JSC::JSGlobalObject*);
+};
+STATIC_ASSERT_ISO_SUBSPACE_SHARABLE(JSBrotliCompressorSinkPrototype, JSBrotliCompressorSinkPrototype::Base);
+
+class JSReadableBrotliCompressorSinkControllerPrototype final : public JSC::JSNonFinalObject {
+public:
+ using Base = JSC::JSNonFinalObject;
+
+ static JSReadableBrotliCompressorSinkControllerPrototype* create(JSC::VM& vm, JSGlobalObject* globalObject, JSC::Structure* structure)
+ {
+ JSReadableBrotliCompressorSinkControllerPrototype* ptr = new (NotNull, JSC::allocateCell<JSReadableBrotliCompressorSinkControllerPrototype>(vm)) JSReadableBrotliCompressorSinkControllerPrototype(vm, globalObject, structure);
+ ptr->finishCreation(vm, globalObject);
+ return ptr;
+ }
+
+ DECLARE_INFO;
+ template<typename CellType, JSC::SubspaceAccess>
+ static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm)
+ {
+ return &vm.plainObjectSpace();
+ }
+ static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
+ {
+ return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info());
+ }
+
+private:
+ JSReadableBrotliCompressorSinkControllerPrototype(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure)
+ : Base(vm, structure)
+ {
+ }
+
+ void finishCreation(JSC::VM&, JSC::JSGlobalObject*);
+};
+STATIC_ASSERT_ISO_SUBSPACE_SHARABLE(JSReadableBrotliCompressorSinkControllerPrototype, JSReadableBrotliCompressorSinkControllerPrototype::Base);
+
+const ClassInfo JSBrotliCompressorSinkPrototype::s_info = { "BrotliCompressorSink"_s, &Base::s_info, &JSBrotliCompressorSinkPrototypeTable, nullptr, CREATE_METHOD_TABLE(JSBrotliCompressorSinkPrototype) };
+const ClassInfo JSBrotliCompressorSink::s_info = { "BrotliCompressorSink"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSBrotliCompressorSink) };
+const ClassInfo JSBrotliCompressorSinkConstructor::s_info = { "BrotliCompressorSink"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSBrotliCompressorSinkConstructor) };
+
+const ClassInfo JSReadableBrotliCompressorSinkControllerPrototype::s_info = { "ReadableBrotliCompressorSinkController"_s, &Base::s_info, &JSReadableBrotliCompressorSinkControllerPrototypeTable, nullptr, CREATE_METHOD_TABLE(JSReadableBrotliCompressorSinkControllerPrototype) };
+const ClassInfo JSReadableBrotliCompressorSinkController::s_info = { "ReadableBrotliCompressorSinkController"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSReadableBrotliCompressorSinkController) };
+
+JSBrotliCompressorSink::~JSBrotliCompressorSink()
+{
+ if (m_sinkPtr) {
+ BrotliCompressorSink__finalize(m_sinkPtr);
+ }
+}
+
+JSReadableBrotliCompressorSinkController::~JSReadableBrotliCompressorSinkController()
+{
+ if (m_sinkPtr) {
+ BrotliCompressorSink__finalize(m_sinkPtr);
+ }
+}
+
+JSObject* JSBrotliCompressorSink::createPrototype(VM& vm, JSDOMGlobalObject& globalObject)
+{
+ return JSBrotliCompressorSinkPrototype::create(vm, &globalObject, JSBrotliCompressorSinkPrototype::createStructure(vm, &globalObject, globalObject.objectPrototype()));
+}
+
+JSObject* JSReadableBrotliCompressorSinkController::createPrototype(VM& vm, JSDOMGlobalObject& globalObject)
+{
+ return JSReadableBrotliCompressorSinkControllerPrototype::create(vm, &globalObject, JSReadableBrotliCompressorSinkControllerPrototype::createStructure(vm, &globalObject, globalObject.objectPrototype()));
+}
+
+void JSReadableBrotliCompressorSinkController::detach()
+{
+ m_sinkPtr = nullptr;
+ m_onPull.clear();
+
+ auto readableStream = m_weakReadableStream.get();
+ auto onClose = m_onClose.get();
+ m_onClose.clear();
+
+ if (readableStream && onClose) {
+ JSC::JSGlobalObject* globalObject = this->globalObject();
+ auto callData = JSC::getCallData(onClose);
+ JSC::MarkedArgumentBuffer arguments;
+ arguments.append(readableStream);
+ arguments.append(jsUndefined());
+ JSC::call(globalObject, onClose, callData, JSC::jsUndefined(), arguments);
+ }
+
+ m_weakReadableStream.clear();
+}
+
+JSBrotliCompressorSinkConstructor* JSBrotliCompressorSinkConstructor::create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure, JSObject* prototype)
+{
+ JSBrotliCompressorSinkConstructor* ptr = new (NotNull, JSC::allocateCell<JSBrotliCompressorSinkConstructor>(vm)) JSBrotliCompressorSinkConstructor(vm, structure, BrotliCompressorSink__construct);
+ ptr->finishCreation(vm, globalObject, prototype);
+ return ptr;
+}
+
+JSBrotliCompressorSink* JSBrotliCompressorSink::create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure, void* sinkPtr)
+{
+ JSBrotliCompressorSink* ptr = new (NotNull, JSC::allocateCell<JSBrotliCompressorSink>(vm)) JSBrotliCompressorSink(vm, structure, sinkPtr);
+ ptr->finishCreation(vm);
+ return ptr;
+}
+
+JSReadableBrotliCompressorSinkController* JSReadableBrotliCompressorSinkController::create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure, void* sinkPtr)
+{
+ JSReadableBrotliCompressorSinkController* ptr = new (NotNull, JSC::allocateCell<JSReadableBrotliCompressorSinkController>(vm)) JSReadableBrotliCompressorSinkController(vm, structure, sinkPtr);
+ ptr->finishCreation(vm);
+ return ptr;
+}
+
+void JSBrotliCompressorSinkConstructor::finishCreation(VM& vm, JSC::JSGlobalObject* globalObject, JSObject* prototype)
+{
+ Base::finishCreation(vm);
+ ASSERT(inherits(info()));
+ initializeProperties(vm, globalObject, prototype);
+}
+
+JSC::EncodedJSValue JSC_HOST_CALL_ATTRIBUTES JSBrotliCompressorSinkConstructor::construct(JSC::JSGlobalObject* globalObject, JSC::CallFrame* callFrame)
+{
+ return BrotliCompressorSink__construct(globalObject, callFrame);
+}
+
+void JSBrotliCompressorSinkConstructor::initializeProperties(VM& vm, JSC::JSGlobalObject* globalObject, JSObject* prototype)
+{
+ putDirect(vm, vm.propertyNames->length, jsNumber(0), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
+ JSString* nameString = jsNontrivialString(vm, "BrotliCompressorSink"_s);
+ m_originalName.set(vm, this, nameString);
+ putDirect(vm, vm.propertyNames->name, nameString, JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
+}
+
+void JSBrotliCompressorSinkPrototype::finishCreation(JSC::VM& vm, JSC::JSGlobalObject* globalObject)
+{
+ Base::finishCreation(vm);
+ reifyStaticProperties(vm, JSBrotliCompressorSink::info(), JSBrotliCompressorSinkPrototypeTableValues, *this);
+ putDirect(vm, JSC::Identifier::fromString(vm, "sinkId"_s), JSC::jsNumber(JSBrotliCompressorSink::Sink), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
+ JSC_TO_STRING_TAG_WITHOUT_TRANSITION();
+}
+
+void JSReadableBrotliCompressorSinkControllerPrototype::finishCreation(JSC::VM& vm, JSC::JSGlobalObject* globalObject)
+{
+ Base::finishCreation(vm);
+ reifyStaticProperties(vm, JSReadableBrotliCompressorSinkController::info(), JSReadableBrotliCompressorSinkControllerPrototypeTableValues, *this);
+ putDirect(vm, JSC::Identifier::fromString(vm, "sinkId"_s), JSC::jsNumber(JSBrotliCompressorSink::Sink), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
+ JSC_TO_STRING_TAG_WITHOUT_TRANSITION();
+}
+
+void JSBrotliCompressorSink::finishCreation(VM& vm)
+{
+ Base::finishCreation(vm);
+ ASSERT(inherits(info()));
+}
+
+void JSReadableBrotliCompressorSinkController::finishCreation(VM& vm)
+{
+ Base::finishCreation(vm);
+ ASSERT(inherits(info()));
+}
+
+void JSBrotliCompressorSink::analyzeHeap(JSCell* cell, HeapAnalyzer& analyzer)
+{
+ auto* thisObject = jsCast<JSBrotliCompressorSink*>(cell);
+ if (void* wrapped = thisObject->wrapped()) {
+ analyzer.setWrappedObjectForCell(cell, wrapped);
+ // if (thisObject->scriptExecutionContext())
+ // analyzer.setLabelForCell(cell, "url " + thisObject->scriptExecutionContext()->url().string());
+ }
+ Base::analyzeHeap(cell, analyzer);
+}
+
+void JSReadableBrotliCompressorSinkController::analyzeHeap(JSCell* cell, HeapAnalyzer& analyzer)
+{
+ auto* thisObject = jsCast<JSReadableBrotliCompressorSinkController*>(cell);
+ if (void* wrapped = thisObject->wrapped()) {
+ analyzer.setWrappedObjectForCell(cell, wrapped);
+ // if (thisObject->scriptExecutionContext())
+ // analyzer.setLabelForCell(cell, "url " + thisObject->scriptExecutionContext()->url().string());
+ }
+ Base::analyzeHeap(cell, analyzer);
+}
+
+template<typename Visitor>
+void JSReadableBrotliCompressorSinkController::visitChildrenImpl(JSCell* cell, Visitor& visitor)
+{
+ JSReadableBrotliCompressorSinkController* thisObject = jsCast<JSReadableBrotliCompressorSinkController*>(cell);
+ ASSERT_GC_OBJECT_INHERITS(thisObject, info());
+ Base::visitChildren(thisObject, visitor);
+ visitor.append(thisObject->m_onPull);
+ visitor.append(thisObject->m_onClose);
+ void* ptr = thisObject->m_sinkPtr;
+ if (ptr)
+ visitor.addOpaqueRoot(ptr);
+}
+
+DEFINE_VISIT_CHILDREN(JSReadableBrotliCompressorSinkController);
+
+template<typename Visitor>
+void JSBrotliCompressorSink::visitChildrenImpl(JSCell* cell, Visitor& visitor)
+{
+ JSBrotliCompressorSink* thisObject = jsCast<JSBrotliCompressorSink*>(cell);
+ ASSERT_GC_OBJECT_INHERITS(thisObject, info());
+ Base::visitChildren(thisObject, visitor);
+ void* ptr = thisObject->m_sinkPtr;
+ if (ptr)
+ visitor.addOpaqueRoot(ptr);
+}
+
+DEFINE_VISIT_CHILDREN(JSBrotliCompressorSink);
+
+void JSReadableBrotliCompressorSinkController::start(JSC::JSGlobalObject* globalObject, JSC::JSValue readableStream, JSC::JSFunction* onPull, JSC::JSFunction* onClose)
+{
+ this->m_weakReadableStream = JSC::Weak<JSC::JSObject>(readableStream.getObject());
+ this->m_onPull.set(globalObject->vm(), this, onPull);
+ this->m_onClose.set(globalObject->vm(), this, onClose);
+}
+
+void JSBrotliCompressorSink::destroy(JSCell* cell)
+{
+ static_cast<JSBrotliCompressorSink*>(cell)->JSBrotliCompressorSink::~JSBrotliCompressorSink();
+}
+
+void JSReadableBrotliCompressorSinkController::destroy(JSCell* cell)
+{
+ static_cast<JSReadableBrotliCompressorSinkController*>(cell)->JSReadableBrotliCompressorSinkController::~JSReadableBrotliCompressorSinkController();
+}
+
JSObject* createJSSinkPrototype(JSC::VM& vm, JSC::JSGlobalObject* globalObject, SinkID sinkID)
{
switch (sinkID) {
@@ -1722,6 +2528,12 @@ JSObject* createJSSinkPrototype(JSC::VM& vm, JSC::JSGlobalObject* globalObject,
case HTTPSResponseSink:
return JSHTTPSResponseSinkPrototype::create(vm, globalObject, JSHTTPSResponseSinkPrototype::createStructure(vm, globalObject, globalObject->objectPrototype()));
+ case BrotliDecompressorSink:
+ return JSBrotliDecompressorSinkPrototype::create(vm, globalObject, JSBrotliDecompressorSinkPrototype::createStructure(vm, globalObject, globalObject->objectPrototype()));
+
+ case BrotliCompressorSink:
+ return JSBrotliCompressorSinkPrototype::create(vm, globalObject, JSBrotliCompressorSinkPrototype::createStructure(vm, globalObject, globalObject->objectPrototype()));
+
default:
RELEASE_ASSERT_NOT_REACHED();
}
@@ -1742,6 +2554,12 @@ JSObject* createJSSinkControllerPrototype(JSC::VM& vm, JSC::JSGlobalObject* glob
case HTTPSResponseSink:
return JSReadableHTTPSResponseSinkControllerPrototype::create(vm, globalObject, JSReadableHTTPSResponseSinkControllerPrototype::createStructure(vm, globalObject, globalObject->objectPrototype()));
+ case BrotliDecompressorSink:
+ return JSReadableBrotliDecompressorSinkControllerPrototype::create(vm, globalObject, JSReadableBrotliDecompressorSinkControllerPrototype::createStructure(vm, globalObject, globalObject->objectPrototype()));
+
+ case BrotliCompressorSink:
+ return JSReadableBrotliCompressorSinkControllerPrototype::create(vm, globalObject, JSReadableBrotliCompressorSinkControllerPrototype::createStructure(vm, globalObject, globalObject->objectPrototype()));
+
default:
RELEASE_ASSERT_NOT_REACHED();
}
@@ -1770,6 +2588,16 @@ Structure* createJSSinkControllerStructure(JSC::VM& vm, JSC::JSGlobalObject* glo
return JSReadableHTTPSResponseSinkController::createStructure(vm, globalObject, prototype);
}
+ case BrotliDecompressorSink: {
+ auto* prototype = createJSSinkControllerPrototype(vm, globalObject, sinkID);
+ return JSReadableBrotliDecompressorSinkController::createStructure(vm, globalObject, prototype);
+ }
+
+ case BrotliCompressorSink: {
+ auto* prototype = createJSSinkControllerPrototype(vm, globalObject, sinkID);
+ return JSReadableBrotliCompressorSinkController::createStructure(vm, globalObject, prototype);
+ }
+
default:
RELEASE_ASSERT_NOT_REACHED();
}
@@ -2119,3 +2947,175 @@ extern "C" void HTTPSResponseSink__onClose(JSC__JSValue controllerValue, JSC__JS
arguments.append(JSC::JSValue::decode(reason));
JSC::call(globalObject, function, callData, JSC::jsUndefined(), arguments);
}
+
+extern "C" JSC__JSValue BrotliDecompressorSink__createObject(JSC__JSGlobalObject* arg0, void* sinkPtr)
+{
+ auto& vm = arg0->vm();
+ Zig::GlobalObject* globalObject = reinterpret_cast<Zig::GlobalObject*>(arg0);
+ JSC::Structure* structure = globalObject->BrotliDecompressorSinkStructure();
+ return JSC::JSValue::encode(WebCore::JSBrotliDecompressorSink::create(vm, globalObject, structure, sinkPtr));
+}
+
+extern "C" void* BrotliDecompressorSink__fromJS(JSC__JSGlobalObject* arg0, JSC__JSValue JSValue1)
+{
+ JSC::VM& vm = WebCore::getVM(arg0);
+ if (auto* sink = JSC::jsDynamicCast<WebCore::JSBrotliDecompressorSink*>(JSC::JSValue::decode(JSValue1)))
+ return sink->wrapped();
+
+ if (auto* controller = JSC::jsDynamicCast<WebCore::JSReadableBrotliDecompressorSinkController*>(JSC::JSValue::decode(JSValue1)))
+ return controller->wrapped();
+
+ return nullptr;
+}
+
+extern "C" void BrotliDecompressorSink__detachPtr(JSC__JSValue JSValue0)
+{
+ if (auto* sink = JSC::jsDynamicCast<WebCore::JSBrotliDecompressorSink*>(JSC::JSValue::decode(JSValue0))) {
+ sink->detach();
+ return;
+ }
+
+ if (auto* controller = JSC::jsDynamicCast<WebCore::JSReadableBrotliDecompressorSinkController*>(JSC::JSValue::decode(JSValue0))) {
+ controller->detach();
+ return;
+ }
+}
+
+extern "C" JSC__JSValue BrotliDecompressorSink__assignToStream(JSC__JSGlobalObject* arg0, JSC__JSValue stream, void* sinkPtr, void** controllerValue)
+{
+ auto& vm = arg0->vm();
+ Zig::GlobalObject* globalObject = reinterpret_cast<Zig::GlobalObject*>(arg0);
+
+ JSC::Structure* structure = WebCore::getDOMStructure<WebCore::JSReadableBrotliDecompressorSinkController>(vm, *globalObject);
+ WebCore::JSReadableBrotliDecompressorSinkController* controller = WebCore::JSReadableBrotliDecompressorSinkController::create(vm, globalObject, structure, sinkPtr);
+ *controllerValue = reinterpret_cast<void*>(JSC::JSValue::encode(controller));
+ return globalObject->assignToStream(JSC::JSValue::decode(stream), controller);
+}
+
+extern "C" void BrotliDecompressorSink__onReady(JSC__JSValue controllerValue, JSC__JSValue amt, JSC__JSValue offset)
+{
+ WebCore::JSReadableBrotliDecompressorSinkController* controller = JSC::jsCast<WebCore::JSReadableBrotliDecompressorSinkController*>(JSC::JSValue::decode(controllerValue).getObject());
+
+ JSC::JSFunction* function = controller->m_onPull.get();
+ if (function == nullptr)
+ return;
+ JSC::JSGlobalObject* globalObject = controller->globalObject();
+
+ auto callData = JSC::getCallData(function);
+ JSC::MarkedArgumentBuffer arguments;
+ arguments.append(controller);
+ arguments.append(JSC::JSValue::decode(amt));
+ arguments.append(JSC::JSValue::decode(offset));
+
+ JSC::call(globalObject, function, callData, JSC::jsUndefined(), arguments);
+}
+
+extern "C" void BrotliDecompressorSink__onStart(JSC__JSValue controllerValue)
+{
+}
+
+extern "C" void BrotliDecompressorSink__onClose(JSC__JSValue controllerValue, JSC__JSValue reason)
+{
+ WebCore::JSReadableBrotliDecompressorSinkController* controller = JSC::jsCast<WebCore::JSReadableBrotliDecompressorSinkController*>(JSC::JSValue::decode(controllerValue).getObject());
+
+ JSC::JSFunction* function = controller->m_onClose.get();
+ if (function == nullptr)
+ return;
+ // only call close once
+ controller->m_onClose.clear();
+ JSC::JSGlobalObject* globalObject = controller->globalObject();
+
+ auto callData = JSC::getCallData(function);
+ JSC::MarkedArgumentBuffer arguments;
+ auto readableStream = controller->m_weakReadableStream.get();
+ arguments.append(readableStream ? readableStream : JSC::jsUndefined());
+
+ arguments.append(JSC::JSValue::decode(reason));
+ JSC::call(globalObject, function, callData, JSC::jsUndefined(), arguments);
+}
+
+extern "C" JSC__JSValue BrotliCompressorSink__createObject(JSC__JSGlobalObject* arg0, void* sinkPtr)
+{
+ auto& vm = arg0->vm();
+ Zig::GlobalObject* globalObject = reinterpret_cast<Zig::GlobalObject*>(arg0);
+ JSC::Structure* structure = globalObject->BrotliCompressorSinkStructure();
+ return JSC::JSValue::encode(WebCore::JSBrotliCompressorSink::create(vm, globalObject, structure, sinkPtr));
+}
+
+extern "C" void* BrotliCompressorSink__fromJS(JSC__JSGlobalObject* arg0, JSC__JSValue JSValue1)
+{
+ JSC::VM& vm = WebCore::getVM(arg0);
+ if (auto* sink = JSC::jsDynamicCast<WebCore::JSBrotliCompressorSink*>(JSC::JSValue::decode(JSValue1)))
+ return sink->wrapped();
+
+ if (auto* controller = JSC::jsDynamicCast<WebCore::JSReadableBrotliCompressorSinkController*>(JSC::JSValue::decode(JSValue1)))
+ return controller->wrapped();
+
+ return nullptr;
+}
+
+extern "C" void BrotliCompressorSink__detachPtr(JSC__JSValue JSValue0)
+{
+ if (auto* sink = JSC::jsDynamicCast<WebCore::JSBrotliCompressorSink*>(JSC::JSValue::decode(JSValue0))) {
+ sink->detach();
+ return;
+ }
+
+ if (auto* controller = JSC::jsDynamicCast<WebCore::JSReadableBrotliCompressorSinkController*>(JSC::JSValue::decode(JSValue0))) {
+ controller->detach();
+ return;
+ }
+}
+
+extern "C" JSC__JSValue BrotliCompressorSink__assignToStream(JSC__JSGlobalObject* arg0, JSC__JSValue stream, void* sinkPtr, void** controllerValue)
+{
+ auto& vm = arg0->vm();
+ Zig::GlobalObject* globalObject = reinterpret_cast<Zig::GlobalObject*>(arg0);
+
+ JSC::Structure* structure = WebCore::getDOMStructure<WebCore::JSReadableBrotliCompressorSinkController>(vm, *globalObject);
+ WebCore::JSReadableBrotliCompressorSinkController* controller = WebCore::JSReadableBrotliCompressorSinkController::create(vm, globalObject, structure, sinkPtr);
+ *controllerValue = reinterpret_cast<void*>(JSC::JSValue::encode(controller));
+ return globalObject->assignToStream(JSC::JSValue::decode(stream), controller);
+}
+
+extern "C" void BrotliCompressorSink__onReady(JSC__JSValue controllerValue, JSC__JSValue amt, JSC__JSValue offset)
+{
+ WebCore::JSReadableBrotliCompressorSinkController* controller = JSC::jsCast<WebCore::JSReadableBrotliCompressorSinkController*>(JSC::JSValue::decode(controllerValue).getObject());
+
+ JSC::JSFunction* function = controller->m_onPull.get();
+ if (function == nullptr)
+ return;
+ JSC::JSGlobalObject* globalObject = controller->globalObject();
+
+ auto callData = JSC::getCallData(function);
+ JSC::MarkedArgumentBuffer arguments;
+ arguments.append(controller);
+ arguments.append(JSC::JSValue::decode(amt));
+ arguments.append(JSC::JSValue::decode(offset));
+
+ JSC::call(globalObject, function, callData, JSC::jsUndefined(), arguments);
+}
+
+extern "C" void BrotliCompressorSink__onStart(JSC__JSValue controllerValue)
+{
+}
+
+extern "C" void BrotliCompressorSink__onClose(JSC__JSValue controllerValue, JSC__JSValue reason)
+{
+ WebCore::JSReadableBrotliCompressorSinkController* controller = JSC::jsCast<WebCore::JSReadableBrotliCompressorSinkController*>(JSC::JSValue::decode(controllerValue).getObject());
+
+ JSC::JSFunction* function = controller->m_onClose.get();
+ if (function == nullptr)
+ return;
+ // only call close once
+ controller->m_onClose.clear();
+ JSC::JSGlobalObject* globalObject = controller->globalObject();
+
+ auto callData = JSC::getCallData(function);
+ JSC::MarkedArgumentBuffer arguments;
+ auto readableStream = controller->m_weakReadableStream.get();
+ arguments.append(readableStream ? readableStream : JSC::jsUndefined());
+
+ arguments.append(JSC::JSValue::decode(reason));
+ JSC::call(globalObject, function, callData, JSC::jsUndefined(), arguments);
+}
diff --git a/src/bun.js/bindings/JSSink.h b/src/bun.js/bindings/JSSink.h
index 3826ef696..09cea950c 100644
--- a/src/bun.js/bindings/JSSink.h
+++ b/src/bun.js/bindings/JSSink.h
@@ -1,6 +1,6 @@
// AUTO-GENERATED FILE. DO NOT EDIT.
-// Generated by 'make generate-sink' at 2023-07-09T17:58:51.558Z
+// Generated by 'make generate-sink' at 2023-07-18T03:21:16.950Z
//
#pragma once
@@ -605,6 +605,300 @@ public:
JSC_DECLARE_CUSTOM_GETTER(functionHTTPSResponseSink__getter);
+class JSBrotliDecompressorSinkConstructor final : public JSC::InternalFunction {
+public:
+ using Base = JSC::InternalFunction;
+ static JSBrotliDecompressorSinkConstructor* create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure, JSC::JSObject* prototype);
+ static constexpr SinkID Sink = SinkID::BrotliDecompressorSink;
+
+ static constexpr unsigned StructureFlags = Base::StructureFlags;
+ static constexpr bool needsDestruction = false;
+
+ DECLARE_EXPORT_INFO;
+ template<typename, JSC::SubspaceAccess mode> static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm)
+ {
+ if constexpr (mode == JSC::SubspaceAccess::Concurrently)
+ return nullptr;
+ return WebCore::subspaceForImpl<JSBrotliDecompressorSinkConstructor, WebCore::UseCustomHeapCellType::No>(
+ vm,
+ [](auto& spaces) { return spaces.m_clientSubspaceForJSSinkConstructor.get(); },
+ [](auto& spaces, auto&& space) { spaces.m_clientSubspaceForJSSinkConstructor = std::forward<decltype(space)>(space); },
+ [](auto& spaces) { return spaces.m_subspaceForJSSinkConstructor.get(); },
+ [](auto& spaces, auto&& space) { spaces.m_subspaceForJSSinkConstructor = std::forward<decltype(space)>(space); });
+ }
+
+ static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
+ {
+ return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::InternalFunctionType, StructureFlags), info());
+ }
+ void initializeProperties(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSObject* prototype);
+
+ // Must be defined for each specialization class.
+ static JSC::EncodedJSValue JSC_HOST_CALL_ATTRIBUTES construct(JSC::JSGlobalObject*, JSC::CallFrame*);
+
+private:
+ JSBrotliDecompressorSinkConstructor(JSC::VM& vm, JSC::Structure* structure, JSC::NativeFunction nativeFunction)
+ : Base(vm, structure, nativeFunction, nativeFunction)
+
+ {
+ }
+
+ void finishCreation(JSC::VM&, JSC::JSGlobalObject* globalObject, JSC::JSObject* prototype);
+};
+
+class JSBrotliDecompressorSink final : public JSC::JSDestructibleObject {
+public:
+ using Base = JSC::JSDestructibleObject;
+ static JSBrotliDecompressorSink* create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure, void* sinkPtr);
+ static constexpr SinkID Sink = SinkID::BrotliDecompressorSink;
+
+ DECLARE_EXPORT_INFO;
+ template<typename, JSC::SubspaceAccess mode> static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm)
+ {
+ if constexpr (mode == JSC::SubspaceAccess::Concurrently)
+ return nullptr;
+ return WebCore::subspaceForImpl<JSBrotliDecompressorSink, WebCore::UseCustomHeapCellType::No>(
+ vm,
+ [](auto& spaces) { return spaces.m_clientSubspaceForJSSink.get(); },
+ [](auto& spaces, auto&& space) { spaces.m_clientSubspaceForJSSink = std::forward<decltype(space)>(space); },
+ [](auto& spaces) { return spaces.m_subspaceForJSSink.get(); },
+ [](auto& spaces, auto&& space) { spaces.m_subspaceForJSSink = std::forward<decltype(space)>(space); });
+ }
+
+ static void destroy(JSC::JSCell*);
+ static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
+ {
+ return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info());
+ }
+
+ static JSObject* createPrototype(VM& vm, JSDOMGlobalObject& globalObject);
+
+ ~JSBrotliDecompressorSink();
+
+ void* wrapped() const { return m_sinkPtr; }
+ DECLARE_VISIT_CHILDREN;
+
+ void detach()
+ {
+ m_sinkPtr = nullptr;
+ }
+
+ static void analyzeHeap(JSCell*, JSC::HeapAnalyzer&);
+
+ void ref();
+ void unref();
+
+ void* m_sinkPtr;
+ int m_refCount { 1 };
+
+ JSBrotliDecompressorSink(JSC::VM& vm, JSC::Structure* structure, void* sinkPtr)
+ : Base(vm, structure)
+ {
+ m_sinkPtr = sinkPtr;
+ }
+
+ void finishCreation(JSC::VM&);
+};
+
+class JSReadableBrotliDecompressorSinkController final : public JSC::JSDestructibleObject {
+public:
+ using Base = JSC::JSDestructibleObject;
+ static JSReadableBrotliDecompressorSinkController* create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure, void* sinkPtr);
+ static constexpr SinkID Sink = SinkID::BrotliDecompressorSink;
+
+ DECLARE_EXPORT_INFO;
+ template<typename, JSC::SubspaceAccess mode> static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm)
+ {
+ if constexpr (mode == JSC::SubspaceAccess::Concurrently)
+ return nullptr;
+ return WebCore::subspaceForImpl<JSReadableBrotliDecompressorSinkController, WebCore::UseCustomHeapCellType::No>(
+ vm,
+ [](auto& spaces) { return spaces.m_clientSubspaceForJSSinkController.get(); },
+ [](auto& spaces, auto&& space) { spaces.m_clientSubspaceForJSSinkController = std::forward<decltype(space)>(space); },
+ [](auto& spaces) { return spaces.m_subspaceForJSSinkController.get(); },
+ [](auto& spaces, auto&& space) { spaces.m_subspaceForJSSinkController = std::forward<decltype(space)>(space); });
+ }
+
+ static void destroy(JSC::JSCell*);
+ static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
+ {
+ return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info());
+ }
+ static JSObject* createPrototype(VM& vm, JSDOMGlobalObject& globalObject);
+
+ ~JSReadableBrotliDecompressorSinkController();
+
+ void* wrapped() const { return m_sinkPtr; }
+ void detach();
+
+ void start(JSC::JSGlobalObject* globalObject, JSC::JSValue readableStream, JSC::JSFunction* onPull, JSC::JSFunction* onClose);
+ DECLARE_VISIT_CHILDREN;
+
+ static void analyzeHeap(JSCell*, JSC::HeapAnalyzer&);
+
+ void* m_sinkPtr;
+ mutable WriteBarrier<JSC::JSFunction> m_onPull;
+ mutable WriteBarrier<JSC::JSFunction> m_onClose;
+ mutable JSC::Weak<JSObject> m_weakReadableStream;
+
+ JSReadableBrotliDecompressorSinkController(JSC::VM& vm, JSC::Structure* structure, void* sinkPtr)
+ : Base(vm, structure)
+ {
+ m_sinkPtr = sinkPtr;
+ }
+
+ void finishCreation(JSC::VM&);
+};
+
+JSC_DECLARE_CUSTOM_GETTER(functionBrotliDecompressorSink__getter);
+
+class JSBrotliCompressorSinkConstructor final : public JSC::InternalFunction {
+public:
+ using Base = JSC::InternalFunction;
+ static JSBrotliCompressorSinkConstructor* create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure, JSC::JSObject* prototype);
+ static constexpr SinkID Sink = SinkID::BrotliCompressorSink;
+
+ static constexpr unsigned StructureFlags = Base::StructureFlags;
+ static constexpr bool needsDestruction = false;
+
+ DECLARE_EXPORT_INFO;
+ template<typename, JSC::SubspaceAccess mode> static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm)
+ {
+ if constexpr (mode == JSC::SubspaceAccess::Concurrently)
+ return nullptr;
+ return WebCore::subspaceForImpl<JSBrotliCompressorSinkConstructor, WebCore::UseCustomHeapCellType::No>(
+ vm,
+ [](auto& spaces) { return spaces.m_clientSubspaceForJSSinkConstructor.get(); },
+ [](auto& spaces, auto&& space) { spaces.m_clientSubspaceForJSSinkConstructor = std::forward<decltype(space)>(space); },
+ [](auto& spaces) { return spaces.m_subspaceForJSSinkConstructor.get(); },
+ [](auto& spaces, auto&& space) { spaces.m_subspaceForJSSinkConstructor = std::forward<decltype(space)>(space); });
+ }
+
+ static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
+ {
+ return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::InternalFunctionType, StructureFlags), info());
+ }
+ void initializeProperties(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSObject* prototype);
+
+ // Must be defined for each specialization class.
+ static JSC::EncodedJSValue JSC_HOST_CALL_ATTRIBUTES construct(JSC::JSGlobalObject*, JSC::CallFrame*);
+
+private:
+ JSBrotliCompressorSinkConstructor(JSC::VM& vm, JSC::Structure* structure, JSC::NativeFunction nativeFunction)
+ : Base(vm, structure, nativeFunction, nativeFunction)
+
+ {
+ }
+
+ void finishCreation(JSC::VM&, JSC::JSGlobalObject* globalObject, JSC::JSObject* prototype);
+};
+
+class JSBrotliCompressorSink final : public JSC::JSDestructibleObject {
+public:
+ using Base = JSC::JSDestructibleObject;
+ static JSBrotliCompressorSink* create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure, void* sinkPtr);
+ static constexpr SinkID Sink = SinkID::BrotliCompressorSink;
+
+ DECLARE_EXPORT_INFO;
+ template<typename, JSC::SubspaceAccess mode> static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm)
+ {
+ if constexpr (mode == JSC::SubspaceAccess::Concurrently)
+ return nullptr;
+ return WebCore::subspaceForImpl<JSBrotliCompressorSink, WebCore::UseCustomHeapCellType::No>(
+ vm,
+ [](auto& spaces) { return spaces.m_clientSubspaceForJSSink.get(); },
+ [](auto& spaces, auto&& space) { spaces.m_clientSubspaceForJSSink = std::forward<decltype(space)>(space); },
+ [](auto& spaces) { return spaces.m_subspaceForJSSink.get(); },
+ [](auto& spaces, auto&& space) { spaces.m_subspaceForJSSink = std::forward<decltype(space)>(space); });
+ }
+
+ static void destroy(JSC::JSCell*);
+ static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
+ {
+ return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info());
+ }
+
+ static JSObject* createPrototype(VM& vm, JSDOMGlobalObject& globalObject);
+
+ ~JSBrotliCompressorSink();
+
+ void* wrapped() const { return m_sinkPtr; }
+ DECLARE_VISIT_CHILDREN;
+
+ void detach()
+ {
+ m_sinkPtr = nullptr;
+ }
+
+ static void analyzeHeap(JSCell*, JSC::HeapAnalyzer&);
+
+ void ref();
+ void unref();
+
+ void* m_sinkPtr;
+ int m_refCount { 1 };
+
+ JSBrotliCompressorSink(JSC::VM& vm, JSC::Structure* structure, void* sinkPtr)
+ : Base(vm, structure)
+ {
+ m_sinkPtr = sinkPtr;
+ }
+
+ void finishCreation(JSC::VM&);
+};
+
+class JSReadableBrotliCompressorSinkController final : public JSC::JSDestructibleObject {
+public:
+ using Base = JSC::JSDestructibleObject;
+ static JSReadableBrotliCompressorSinkController* create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure, void* sinkPtr);
+ static constexpr SinkID Sink = SinkID::BrotliCompressorSink;
+
+ DECLARE_EXPORT_INFO;
+ template<typename, JSC::SubspaceAccess mode> static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm)
+ {
+ if constexpr (mode == JSC::SubspaceAccess::Concurrently)
+ return nullptr;
+ return WebCore::subspaceForImpl<JSReadableBrotliCompressorSinkController, WebCore::UseCustomHeapCellType::No>(
+ vm,
+ [](auto& spaces) { return spaces.m_clientSubspaceForJSSinkController.get(); },
+ [](auto& spaces, auto&& space) { spaces.m_clientSubspaceForJSSinkController = std::forward<decltype(space)>(space); },
+ [](auto& spaces) { return spaces.m_subspaceForJSSinkController.get(); },
+ [](auto& spaces, auto&& space) { spaces.m_subspaceForJSSinkController = std::forward<decltype(space)>(space); });
+ }
+
+ static void destroy(JSC::JSCell*);
+ static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
+ {
+ return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info());
+ }
+ static JSObject* createPrototype(VM& vm, JSDOMGlobalObject& globalObject);
+
+ ~JSReadableBrotliCompressorSinkController();
+
+ void* wrapped() const { return m_sinkPtr; }
+ void detach();
+
+ void start(JSC::JSGlobalObject* globalObject, JSC::JSValue readableStream, JSC::JSFunction* onPull, JSC::JSFunction* onClose);
+ DECLARE_VISIT_CHILDREN;
+
+ static void analyzeHeap(JSCell*, JSC::HeapAnalyzer&);
+
+ void* m_sinkPtr;
+ mutable WriteBarrier<JSC::JSFunction> m_onPull;
+ mutable WriteBarrier<JSC::JSFunction> m_onClose;
+ mutable JSC::Weak<JSObject> m_weakReadableStream;
+
+ JSReadableBrotliCompressorSinkController(JSC::VM& vm, JSC::Structure* structure, void* sinkPtr)
+ : Base(vm, structure)
+ {
+ m_sinkPtr = sinkPtr;
+ }
+
+ void finishCreation(JSC::VM&);
+};
+
+JSC_DECLARE_CUSTOM_GETTER(functionBrotliCompressorSink__getter);
+
JSObject* createJSSinkPrototype(JSC::VM& vm, JSC::JSGlobalObject* globalObject, WebCore::SinkID sinkID);
JSObject* createJSSinkControllerPrototype(JSC::VM& vm, JSC::JSGlobalObject* globalObject, WebCore::SinkID sinkID);
Structure* createJSSinkControllerStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, WebCore::SinkID sinkID);
diff --git a/src/bun.js/bindings/JSSinkLookupTable.h b/src/bun.js/bindings/JSSinkLookupTable.h
index 7ff4c3f9c..e67c2b37f 100644
--- a/src/bun.js/bindings/JSSinkLookupTable.h
+++ b/src/bun.js/bindings/JSSinkLookupTable.h
@@ -1,4 +1,4 @@
-// Automatically generated from src/bun.js/bindings/JSSink.cpp using /Users/ashcon/Desktop/code/bun/src/bun.js/WebKit/Source/JavaScriptCore/create_hash_table. DO NOT EDIT!
+// Automatically generated from src/bun.js/bindings/JSSink.cpp using /Users/jarred/Code/bun/src/bun.js/WebKit/Source/JavaScriptCore/create_hash_table. DO NOT EDIT!
@@ -319,3 +319,163 @@ static const struct HashTable JSReadableHTTPSResponseSinkControllerPrototypeTabl
{ 5, 15, false, nullptr, JSReadableHTTPSResponseSinkControllerPrototypeTableValues, JSReadableHTTPSResponseSinkControllerPrototypeTableIndex };
+
+
+
+
+
+static const struct CompactHashIndex JSBrotliDecompressorSinkPrototypeTableIndex[19] = {
+ { -1, -1 },
+ { -1, -1 },
+ { -1, -1 },
+ { -1, -1 },
+ { -1, -1 },
+ { 6, -1 },
+ { -1, -1 },
+ { -1, -1 },
+ { -1, -1 },
+ { -1, -1 },
+ { 0, 16 },
+ { -1, -1 },
+ { -1, -1 },
+ { -1, -1 },
+ { 5, -1 },
+ { 4, -1 },
+ { 1, 17 },
+ { 2, 18 },
+ { 3, -1 },
+};
+
+static const struct HashTableValue JSBrotliDecompressorSinkPrototypeTableValues[7] = {
+ { "close"_s, static_cast<unsigned>(PropertyAttribute::ReadOnly|PropertyAttribute::DontDelete|PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, BrotliDecompressorSink__doClose, 0 } },
+ { "flush"_s, static_cast<unsigned>(PropertyAttribute::ReadOnly|PropertyAttribute::DontDelete|PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, BrotliDecompressorSink__flush, 1 } },
+ { "end"_s, static_cast<unsigned>(PropertyAttribute::ReadOnly|PropertyAttribute::DontDelete|PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, BrotliDecompressorSink__end, 0 } },
+ { "start"_s, static_cast<unsigned>(PropertyAttribute::ReadOnly|PropertyAttribute::DontDelete|PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, BrotliDecompressorSink__start, 1 } },
+ { "write"_s, static_cast<unsigned>(PropertyAttribute::ReadOnly|PropertyAttribute::DontDelete|PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, BrotliDecompressorSink__write, 1 } },
+ { "ref"_s, static_cast<unsigned>(PropertyAttribute::ReadOnly|PropertyAttribute::DontDelete|PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, BrotliDecompressorSink__ref, 0 } },
+ { "unref"_s, static_cast<unsigned>(PropertyAttribute::ReadOnly|PropertyAttribute::DontDelete|PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, BrotliDecompressorSink__unref, 0 } },
+};
+
+static const struct HashTable JSBrotliDecompressorSinkPrototypeTable =
+ { 7, 15, false, nullptr, JSBrotliDecompressorSinkPrototypeTableValues, JSBrotliDecompressorSinkPrototypeTableIndex };
+
+
+
+
+
+
+
+static const struct CompactHashIndex JSReadableBrotliDecompressorSinkControllerPrototypeTableIndex[19] = {
+ { -1, -1 },
+ { -1, -1 },
+ { -1, -1 },
+ { -1, -1 },
+ { -1, -1 },
+ { -1, -1 },
+ { -1, -1 },
+ { -1, -1 },
+ { -1, -1 },
+ { -1, -1 },
+ { 0, 16 },
+ { -1, -1 },
+ { -1, -1 },
+ { -1, -1 },
+ { -1, -1 },
+ { 4, -1 },
+ { 1, 17 },
+ { 2, 18 },
+ { 3, -1 },
+};
+
+static const struct HashTableValue JSReadableBrotliDecompressorSinkControllerPrototypeTableValues[5] = {
+ { "close"_s, static_cast<unsigned>(PropertyAttribute::ReadOnly|PropertyAttribute::DontDelete|PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, JSReadableBrotliDecompressorSinkController__close, 0 } },
+ { "flush"_s, static_cast<unsigned>(PropertyAttribute::ReadOnly|PropertyAttribute::DontDelete|PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, BrotliDecompressorSink__flush, 1 } },
+ { "end"_s, static_cast<unsigned>(PropertyAttribute::ReadOnly|PropertyAttribute::DontDelete|PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, JSReadableBrotliDecompressorSinkController__end, 0 } },
+ { "start"_s, static_cast<unsigned>(PropertyAttribute::ReadOnly|PropertyAttribute::DontDelete|PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, BrotliDecompressorSink__start, 1 } },
+ { "write"_s, static_cast<unsigned>(PropertyAttribute::ReadOnly|PropertyAttribute::DontDelete|PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, BrotliDecompressorSink__write, 1 } },
+};
+
+static const struct HashTable JSReadableBrotliDecompressorSinkControllerPrototypeTable =
+ { 5, 15, false, nullptr, JSReadableBrotliDecompressorSinkControllerPrototypeTableValues, JSReadableBrotliDecompressorSinkControllerPrototypeTableIndex };
+
+
+
+
+
+
+
+static const struct CompactHashIndex JSBrotliCompressorSinkPrototypeTableIndex[19] = {
+ { -1, -1 },
+ { -1, -1 },
+ { -1, -1 },
+ { -1, -1 },
+ { -1, -1 },
+ { 6, -1 },
+ { -1, -1 },
+ { -1, -1 },
+ { -1, -1 },
+ { -1, -1 },
+ { 0, 16 },
+ { -1, -1 },
+ { -1, -1 },
+ { -1, -1 },
+ { 5, -1 },
+ { 4, -1 },
+ { 1, 17 },
+ { 2, 18 },
+ { 3, -1 },
+};
+
+static const struct HashTableValue JSBrotliCompressorSinkPrototypeTableValues[7] = {
+ { "close"_s, static_cast<unsigned>(PropertyAttribute::ReadOnly|PropertyAttribute::DontDelete|PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, BrotliCompressorSink__doClose, 0 } },
+ { "flush"_s, static_cast<unsigned>(PropertyAttribute::ReadOnly|PropertyAttribute::DontDelete|PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, BrotliCompressorSink__flush, 1 } },
+ { "end"_s, static_cast<unsigned>(PropertyAttribute::ReadOnly|PropertyAttribute::DontDelete|PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, BrotliCompressorSink__end, 0 } },
+ { "start"_s, static_cast<unsigned>(PropertyAttribute::ReadOnly|PropertyAttribute::DontDelete|PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, BrotliCompressorSink__start, 1 } },
+ { "write"_s, static_cast<unsigned>(PropertyAttribute::ReadOnly|PropertyAttribute::DontDelete|PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, BrotliCompressorSink__write, 1 } },
+ { "ref"_s, static_cast<unsigned>(PropertyAttribute::ReadOnly|PropertyAttribute::DontDelete|PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, BrotliCompressorSink__ref, 0 } },
+ { "unref"_s, static_cast<unsigned>(PropertyAttribute::ReadOnly|PropertyAttribute::DontDelete|PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, BrotliCompressorSink__unref, 0 } },
+};
+
+static const struct HashTable JSBrotliCompressorSinkPrototypeTable =
+ { 7, 15, false, nullptr, JSBrotliCompressorSinkPrototypeTableValues, JSBrotliCompressorSinkPrototypeTableIndex };
+
+
+
+
+
+
+
+static const struct CompactHashIndex JSReadableBrotliCompressorSinkControllerPrototypeTableIndex[19] = {
+ { -1, -1 },
+ { -1, -1 },
+ { -1, -1 },
+ { -1, -1 },
+ { -1, -1 },
+ { -1, -1 },
+ { -1, -1 },
+ { -1, -1 },
+ { -1, -1 },
+ { -1, -1 },
+ { 0, 16 },
+ { -1, -1 },
+ { -1, -1 },
+ { -1, -1 },
+ { -1, -1 },
+ { 4, -1 },
+ { 1, 17 },
+ { 2, 18 },
+ { 3, -1 },
+};
+
+static const struct HashTableValue JSReadableBrotliCompressorSinkControllerPrototypeTableValues[5] = {
+ { "close"_s, static_cast<unsigned>(PropertyAttribute::ReadOnly|PropertyAttribute::DontDelete|PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, JSReadableBrotliCompressorSinkController__close, 0 } },
+ { "flush"_s, static_cast<unsigned>(PropertyAttribute::ReadOnly|PropertyAttribute::DontDelete|PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, BrotliCompressorSink__flush, 1 } },
+ { "end"_s, static_cast<unsigned>(PropertyAttribute::ReadOnly|PropertyAttribute::DontDelete|PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, JSReadableBrotliCompressorSinkController__end, 0 } },
+ { "start"_s, static_cast<unsigned>(PropertyAttribute::ReadOnly|PropertyAttribute::DontDelete|PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, BrotliCompressorSink__start, 1 } },
+ { "write"_s, static_cast<unsigned>(PropertyAttribute::ReadOnly|PropertyAttribute::DontDelete|PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, BrotliCompressorSink__write, 1 } },
+};
+
+static const struct HashTable JSReadableBrotliCompressorSinkControllerPrototypeTable =
+ { 5, 15, false, nullptr, JSReadableBrotliCompressorSinkControllerPrototypeTableValues, JSReadableBrotliCompressorSinkControllerPrototypeTableIndex };
+
+
diff --git a/src/bun.js/bindings/ModuleLoader.cpp b/src/bun.js/bindings/ModuleLoader.cpp
index 0ccbb7dbb..46365a5fe 100644
--- a/src/bun.js/bindings/ModuleLoader.cpp
+++ b/src/bun.js/bindings/ModuleLoader.cpp
@@ -8,7 +8,6 @@
#include "JavaScriptCore/JSNativeStdFunction.h"
#include "JavaScriptCore/JSCJSValueInlines.h"
#include "JavaScriptCore/JSInternalPromise.h"
-#include "JavaScriptCore/JSInternalFieldObjectImpl.h"
#include "ZigSourceProvider.h"
@@ -36,11 +35,12 @@
#include "../modules/TTYModule.h"
#include "node_util_types.h"
#include "CommonJSModuleRecord.h"
-#include <JavaScriptCore/JSModuleLoader.h>
-#include <JavaScriptCore/Completion.h>
-#include <JavaScriptCore/JSModuleNamespaceObject.h>
-#include <JavaScriptCore/JSMap.h>
-#include <JavaScriptCore/JSMapInlines.h>
+#include "JavaScriptCore/JSModuleLoader.h"
+#include "JavaScriptCore/Completion.h"
+#include "JavaScriptCore/JSModuleNamespaceObject.h"
+#include "JavaScriptCore/JSMap.h"
+#include "JavaScriptCore/JSMapInlines.h"
+#include "JavaScriptCore/JSInternalFieldObjectImplInlines.h"
namespace Bun {
using namespace Zig;
@@ -690,18 +690,3 @@ JSValue fetchSourceCodeAsync(
return fetchSourceCode<true>(globalObject, res, specifier, referrer);
}
}
-namespace JSC {
-
-template<unsigned passedNumberOfInternalFields>
-template<typename Visitor>
-void JSInternalFieldObjectImpl<passedNumberOfInternalFields>::visitChildrenImpl(JSCell* cell, Visitor& visitor)
-{
- auto* thisObject = jsCast<JSInternalFieldObjectImpl*>(cell);
- ASSERT_GC_OBJECT_INHERITS(thisObject, info());
- Base::visitChildren(thisObject, visitor);
- visitor.appendValues(thisObject->m_internalFields, numberOfInternalFields);
-}
-
-DEFINE_VISIT_CHILDREN_WITH_MODIFIER(template<unsigned passedNumberOfInternalFields>, JSInternalFieldObjectImpl<passedNumberOfInternalFields>);
-
-} // namespace JSC
diff --git a/src/bun.js/bindings/Sink.h b/src/bun.js/bindings/Sink.h
index 711c3acf9..fcd234a84 100644
--- a/src/bun.js/bindings/Sink.h
+++ b/src/bun.js/bindings/Sink.h
@@ -9,9 +9,11 @@ enum SinkID : uint8_t {
HTMLRewriterSink = 3,
HTTPResponseSink = 4,
HTTPSResponseSink = 5,
+ BrotliDecompressorSink = 6,
+ BrotliCompressorSink = 7,
};
static constexpr unsigned numberOfSinkIDs
- = 6;
+ = 8;
} \ No newline at end of file
diff --git a/src/bun.js/bindings/ZigGlobalObject.cpp b/src/bun.js/bindings/ZigGlobalObject.cpp
index a5c96ee08..923dc0010 100644
--- a/src/bun.js/bindings/ZigGlobalObject.cpp
+++ b/src/bun.js/bindings/ZigGlobalObject.cpp
@@ -3292,6 +3292,26 @@ void GlobalObject::finishCreation(VM& vm)
init.setConstructor(constructor);
});
+ m_JSBrotliDecompressorSinkClassStructure.initLater(
+ [](LazyClassStructure::Initializer& init) {
+ auto* prototype = createJSSinkPrototype(init.vm, init.global, WebCore::SinkID::BrotliDecompressorSink);
+ auto* structure = JSBrotliDecompressorSink::createStructure(init.vm, init.global, prototype);
+ auto* constructor = JSBrotliDecompressorSinkConstructor::create(init.vm, init.global, JSBrotliDecompressorSinkConstructor::createStructure(init.vm, init.global, init.global->functionPrototype()), jsCast<JSObject*>(prototype));
+ init.setPrototype(prototype);
+ init.setStructure(structure);
+ init.setConstructor(constructor);
+ });
+
+ m_JSBrotliCompressorSinkClassStructure.initLater(
+ [](LazyClassStructure::Initializer& init) {
+ auto* prototype = createJSSinkPrototype(init.vm, init.global, WebCore::SinkID::BrotliCompressorSink);
+ auto* structure = JSBrotliCompressorSink::createStructure(init.vm, init.global, prototype);
+ auto* constructor = JSBrotliCompressorSinkConstructor::create(init.vm, init.global, JSBrotliCompressorSinkConstructor::createStructure(init.vm, init.global, init.global->functionPrototype()), jsCast<JSObject*>(prototype));
+ init.setPrototype(prototype);
+ init.setStructure(structure);
+ init.setConstructor(constructor);
+ });
+
m_JSArrayBufferSinkClassStructure.initLater(
[](LazyClassStructure::Initializer& init) {
auto* prototype = createJSSinkPrototype(init.vm, init.global, WebCore::SinkID::ArrayBufferSink);
@@ -4216,6 +4236,19 @@ void GlobalObject::installAPIGlobals(JSClassRef* globals, int count, JSC::VM& vm
}
{
+ JSC::Identifier identifier = JSC::Identifier::fromString(vm, "BrotliDecompressorSink"_s);
+ object->putDirectCustomAccessor(vm, identifier, JSC::CustomGetterSetter::create(vm, functionBrotliDecompressorSink__getter, nullptr),
+ JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly);
+ }
+
+
+ {
+ JSC::Identifier identifier = JSC::Identifier::fromString(vm, "BrotliCompressorSink"_s);
+ object->putDirectCustomAccessor(vm, identifier, JSC::CustomGetterSetter::create(vm, functionBrotliCompressorSink__getter, nullptr),
+ JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly);
+ }
+
+ {
JSC::Identifier identifier = JSC::Identifier::fromString(vm, "nanoseconds"_s);
object->putDirectNativeFunction(vm, this, identifier, 1, functionBunNanoseconds, ImplementationVisibility::Public, NoIntrinsic,
JSC::PropertyAttribute::Function | JSC::PropertyAttribute::DontDelete | 0);
@@ -4415,6 +4448,8 @@ void GlobalObject::visitChildrenImpl(JSCell* cell, Visitor& visitor)
thisObject->m_JSFileSinkClassStructure.visit(visitor);
thisObject->m_JSHTTPResponseSinkClassStructure.visit(visitor);
thisObject->m_JSHTTPSResponseSinkClassStructure.visit(visitor);
+ thisObject->m_JSBrotliDecompressorSinkClassStructure.visit(visitor);
+ thisObject->m_JSBrotliCompressorSinkClassStructure.visit(visitor);
thisObject->m_JSReadableStateClassStructure.visit(visitor);
thisObject->m_JSStringDecoderClassStructure.visit(visitor);
thisObject->m_NapiClassStructure.visit(visitor);
@@ -4430,6 +4465,8 @@ void GlobalObject::visitChildrenImpl(JSCell* cell, Visitor& visitor)
thisObject->m_JSArrayBufferControllerPrototype.visit(visitor);
thisObject->m_JSFileSinkControllerPrototype.visit(visitor);
thisObject->m_JSHTTPSResponseControllerPrototype.visit(visitor);
+ thisObject->m_JSBrotliDecompressorSinkControllerPrototype.visit(visitor);
+ thisObject->m_JSBrotliCompressorSinkControllerPrototype.visit(visitor);
thisObject->m_navigatorObject.visit(visitor);
thisObject->m_nativeMicrotaskTrampoline.visit(visitor);
thisObject->m_performanceObject.visit(visitor);
diff --git a/src/bun.js/bindings/ZigGlobalObject.h b/src/bun.js/bindings/ZigGlobalObject.h
index c98e499b0..9e1fb0c02 100644
--- a/src/bun.js/bindings/ZigGlobalObject.h
+++ b/src/bun.js/bindings/ZigGlobalObject.h
@@ -205,6 +205,16 @@ public:
JSC::Structure* FFIFunctionStructure() { return m_JSFFIFunctionStructure.getInitializedOnMainThread(this); }
JSC::Structure* NapiClassStructure() { return m_NapiClassStructure.getInitializedOnMainThread(this); }
+ JSC::Structure* BrotliDecompressorSinkStructure() { return m_JSBrotliDecompressorSinkClassStructure.getInitializedOnMainThread(this); }
+ JSC::JSObject* BrotliDecompressorSink() { return m_JSBrotliDecompressorSinkClassStructure.constructorInitializedOnMainThread(this); }
+ JSC::JSValue BrotliDecompressorSinkPrototype() { return m_JSBrotliDecompressorSinkClassStructure.prototypeInitializedOnMainThread(this); }
+ JSC::JSValue JSReadableBrotliDecompressorSinkControllerPrototype() { return m_JSBrotliDecompressorSinkControllerPrototype.getInitializedOnMainThread(this); }
+
+ JSC::Structure* BrotliCompressorSinkStructure() { return m_JSBrotliCompressorSinkClassStructure.getInitializedOnMainThread(this); }
+ JSC::JSObject* BrotliCompressorSink() { return m_JSBrotliCompressorSinkClassStructure.constructorInitializedOnMainThread(this); }
+ JSC::JSValue BrotliCompressorSinkPrototype() { return m_JSBrotliCompressorSinkClassStructure.prototypeInitializedOnMainThread(this); }
+ JSC::JSValue JSReadableBrotliCompressorSinkControllerPrototype() { return m_JSBrotliCompressorSinkControllerPrototype.getInitializedOnMainThread(this); }
+
JSC::Structure* FileSinkStructure() { return m_JSFileSinkClassStructure.getInitializedOnMainThread(this); }
JSC::JSObject* FileSink() { return m_JSFileSinkClassStructure.constructorInitializedOnMainThread(this); }
JSC::JSValue FileSinkPrototype() { return m_JSFileSinkClassStructure.prototypeInitializedOnMainThread(this); }
@@ -470,6 +480,8 @@ private:
LazyClassStructure m_JSFileSinkClassStructure;
LazyClassStructure m_JSHTTPResponseSinkClassStructure;
LazyClassStructure m_JSHTTPSResponseSinkClassStructure;
+ LazyClassStructure m_JSBrotliDecompressorSinkClassStructure;
+ LazyClassStructure m_JSBrotliCompressorSinkClassStructure;
LazyClassStructure m_JSReadableStateClassStructure;
LazyClassStructure m_JSStringDecoderClassStructure;
LazyClassStructure m_NapiClassStructure;
@@ -498,6 +510,8 @@ private:
LazyProperty<JSGlobalObject, JSObject> m_JSArrayBufferControllerPrototype;
LazyProperty<JSGlobalObject, JSObject> m_JSFileSinkControllerPrototype;
LazyProperty<JSGlobalObject, JSObject> m_JSHTTPSResponseControllerPrototype;
+ LazyProperty<JSGlobalObject, JSObject> m_JSBrotliCompressorSinkControllerPrototype;
+ LazyProperty<JSGlobalObject, JSObject> m_JSBrotliDecompressorSinkControllerPrototype;
LazyProperty<JSGlobalObject, JSObject> m_navigatorObject;
LazyProperty<JSGlobalObject, JSObject> m_performanceObject;
LazyProperty<JSGlobalObject, JSObject> m_primordialsObject;
diff --git a/src/bun.js/bindings/exports.zig b/src/bun.js/bindings/exports.zig
index 8fed85c4a..40ee4ff57 100644
--- a/src/bun.js/bindings/exports.zig
+++ b/src/bun.js/bindings/exports.zig
@@ -163,6 +163,8 @@ pub const JSArrayBufferSink = JSC.WebCore.ArrayBufferSink.JSSink;
pub const JSHTTPSResponseSink = JSC.WebCore.HTTPSResponseSink.JSSink;
pub const JSHTTPResponseSink = JSC.WebCore.HTTPResponseSink.JSSink;
pub const JSFileSink = JSC.WebCore.FileSink.JSSink;
+pub const JSBrotliDecompressorSink = JSC.WebCore.BrotliDecompressorSink.JSSink;
+pub const JSBrotliCompressorSink = JSC.WebCore.BrotliCompressorSink.JSSink;
// WebSocket
pub const WebSocketHTTPClient = @import("../../http/websocket_http_client.zig").WebSocketHTTPClient;
@@ -3404,6 +3406,8 @@ comptime {
JSReadableStreamBlob.shim.ref();
JSArrayBufferSink.shim.ref();
JSHTTPResponseSink.shim.ref();
+ JSBrotliDecompressorSink.shim.ref();
+ JSBrotliCompressorSink.shim.ref();
JSHTTPSResponseSink.shim.ref();
JSFileSink.shim.ref();
JSReadableStreamBytes.shim.ref();
diff --git a/src/bun.js/bindings/headers-cpp.h b/src/bun.js/bindings/headers-cpp.h
index 0ccc2fa8c..ea8b579c7 100644
--- a/src/bun.js/bindings/headers-cpp.h
+++ b/src/bun.js/bindings/headers-cpp.h
@@ -182,8 +182,8 @@ extern "C" const size_t Zig__ConsoleClient_object_align_ = alignof(Zig::ConsoleC
extern "C" const size_t Bun__Timer_object_size_ = sizeof(Bun__Timer);
extern "C" const size_t Bun__Timer_object_align_ = alignof(Bun__Timer);
-const size_t sizes[41] = {sizeof(JSC::JSObject), sizeof(WebCore::DOMURL), sizeof(WebCore::DOMFormData), sizeof(WebCore::FetchHeaders), sizeof(SystemError), sizeof(JSC::JSCell), sizeof(JSC::JSString), sizeof(JSC::JSModuleLoader), sizeof(WebCore::AbortSignal), sizeof(JSC::JSPromise), sizeof(JSC::JSInternalPromise), sizeof(JSC::JSFunction), sizeof(JSC::JSGlobalObject), sizeof(JSC::JSMap), sizeof(JSC::JSValue), sizeof(JSC::Exception), sizeof(JSC::VM), sizeof(JSC::ThrowScope), sizeof(JSC::CatchScope), sizeof(FFI__ptr), sizeof(Reader__u8), sizeof(Reader__u16), sizeof(Reader__u32), sizeof(Reader__ptr), sizeof(Reader__i8), sizeof(Reader__i16), sizeof(Reader__i32), sizeof(Reader__f32), sizeof(Reader__f64), sizeof(Reader__i64), sizeof(Reader__u64), sizeof(Reader__intptr), sizeof(Crypto__getRandomValues), sizeof(Crypto__randomUUID), sizeof(Crypto__timingSafeEqual), sizeof(Zig::GlobalObject), sizeof(Bun__Path), sizeof(ArrayBufferSink), sizeof(HTTPSResponseSink), sizeof(HTTPResponseSink), sizeof(FileSink)};
+const size_t sizes[43] = {sizeof(JSC::JSObject), sizeof(WebCore::DOMURL), sizeof(WebCore::DOMFormData), sizeof(WebCore::FetchHeaders), sizeof(SystemError), sizeof(JSC::JSCell), sizeof(JSC::JSString), sizeof(JSC::JSModuleLoader), sizeof(WebCore::AbortSignal), sizeof(JSC::JSPromise), sizeof(JSC::JSInternalPromise), sizeof(JSC::JSFunction), sizeof(JSC::JSGlobalObject), sizeof(JSC::JSMap), sizeof(JSC::JSValue), sizeof(JSC::Exception), sizeof(JSC::VM), sizeof(JSC::ThrowScope), sizeof(JSC::CatchScope), sizeof(FFI__ptr), sizeof(Reader__u8), sizeof(Reader__u16), sizeof(Reader__u32), sizeof(Reader__ptr), sizeof(Reader__i8), sizeof(Reader__i16), sizeof(Reader__i32), sizeof(Reader__f32), sizeof(Reader__f64), sizeof(Reader__i64), sizeof(Reader__u64), sizeof(Reader__intptr), sizeof(Crypto__getRandomValues), sizeof(Crypto__randomUUID), sizeof(Crypto__timingSafeEqual), sizeof(Zig::GlobalObject), sizeof(Bun__Path), sizeof(ArrayBufferSink), sizeof(HTTPSResponseSink), sizeof(HTTPResponseSink), sizeof(FileSink), sizeof(BrotliDecompressorSink), sizeof(BrotliCompressorSink)};
-const char* names[41] = {"JSC__JSObject", "WebCore__DOMURL", "WebCore__DOMFormData", "WebCore__FetchHeaders", "SystemError", "JSC__JSCell", "JSC__JSString", "JSC__JSModuleLoader", "WebCore__AbortSignal", "JSC__JSPromise", "JSC__JSInternalPromise", "JSC__JSFunction", "JSC__JSGlobalObject", "JSC__JSMap", "JSC__JSValue", "JSC__Exception", "JSC__VM", "JSC__ThrowScope", "JSC__CatchScope", "FFI__ptr", "Reader__u8", "Reader__u16", "Reader__u32", "Reader__ptr", "Reader__i8", "Reader__i16", "Reader__i32", "Reader__f32", "Reader__f64", "Reader__i64", "Reader__u64", "Reader__intptr", "Crypto__getRandomValues", "Crypto__randomUUID", "Crypto__timingSafeEqual", "Zig__GlobalObject", "Bun__Path", "ArrayBufferSink", "HTTPSResponseSink", "HTTPResponseSink", "FileSink"};
+const char* names[43] = {"JSC__JSObject", "WebCore__DOMURL", "WebCore__DOMFormData", "WebCore__FetchHeaders", "SystemError", "JSC__JSCell", "JSC__JSString", "JSC__JSModuleLoader", "WebCore__AbortSignal", "JSC__JSPromise", "JSC__JSInternalPromise", "JSC__JSFunction", "JSC__JSGlobalObject", "JSC__JSMap", "JSC__JSValue", "JSC__Exception", "JSC__VM", "JSC__ThrowScope", "JSC__CatchScope", "FFI__ptr", "Reader__u8", "Reader__u16", "Reader__u32", "Reader__ptr", "Reader__i8", "Reader__i16", "Reader__i32", "Reader__f32", "Reader__f64", "Reader__i64", "Reader__u64", "Reader__intptr", "Crypto__getRandomValues", "Crypto__randomUUID", "Crypto__timingSafeEqual", "Zig__GlobalObject", "Bun__Path", "ArrayBufferSink", "HTTPSResponseSink", "HTTPResponseSink", "FileSink", "BrotliDecompressorSink", "BrotliCompressorSink"};
-const size_t aligns[41] = {alignof(JSC::JSObject), alignof(WebCore::DOMURL), alignof(WebCore::DOMFormData), alignof(WebCore::FetchHeaders), alignof(SystemError), alignof(JSC::JSCell), alignof(JSC::JSString), alignof(JSC::JSModuleLoader), alignof(WebCore::AbortSignal), alignof(JSC::JSPromise), alignof(JSC::JSInternalPromise), alignof(JSC::JSFunction), alignof(JSC::JSGlobalObject), alignof(JSC::JSMap), alignof(JSC::JSValue), alignof(JSC::Exception), alignof(JSC::VM), alignof(JSC::ThrowScope), alignof(JSC::CatchScope), alignof(FFI__ptr), alignof(Reader__u8), alignof(Reader__u16), alignof(Reader__u32), alignof(Reader__ptr), alignof(Reader__i8), alignof(Reader__i16), alignof(Reader__i32), alignof(Reader__f32), alignof(Reader__f64), alignof(Reader__i64), alignof(Reader__u64), alignof(Reader__intptr), alignof(Crypto__getRandomValues), alignof(Crypto__randomUUID), alignof(Crypto__timingSafeEqual), alignof(Zig::GlobalObject), alignof(Bun__Path), alignof(ArrayBufferSink), alignof(HTTPSResponseSink), alignof(HTTPResponseSink), alignof(FileSink)};
+const size_t aligns[43] = {alignof(JSC::JSObject), alignof(WebCore::DOMURL), alignof(WebCore::DOMFormData), alignof(WebCore::FetchHeaders), alignof(SystemError), alignof(JSC::JSCell), alignof(JSC::JSString), alignof(JSC::JSModuleLoader), alignof(WebCore::AbortSignal), alignof(JSC::JSPromise), alignof(JSC::JSInternalPromise), alignof(JSC::JSFunction), alignof(JSC::JSGlobalObject), alignof(JSC::JSMap), alignof(JSC::JSValue), alignof(JSC::Exception), alignof(JSC::VM), alignof(JSC::ThrowScope), alignof(JSC::CatchScope), alignof(FFI__ptr), alignof(Reader__u8), alignof(Reader__u16), alignof(Reader__u32), alignof(Reader__ptr), alignof(Reader__i8), alignof(Reader__i16), alignof(Reader__i32), alignof(Reader__f32), alignof(Reader__f64), alignof(Reader__i64), alignof(Reader__u64), alignof(Reader__intptr), alignof(Crypto__getRandomValues), alignof(Crypto__randomUUID), alignof(Crypto__timingSafeEqual), alignof(Zig::GlobalObject), alignof(Bun__Path), alignof(ArrayBufferSink), alignof(HTTPSResponseSink), alignof(HTTPResponseSink), alignof(FileSink), alignof(BrotliDecompressorSink), alignof(BrotliCompressorSink)};
diff --git a/src/bun.js/bindings/headers.zig b/src/bun.js/bindings/headers.zig
index 155b7cce4..0b71d6918 100644
--- a/src/bun.js/bindings/headers.zig
+++ b/src/bun.js/bindings/headers.zig
@@ -378,4 +378,16 @@ pub extern fn FileSink__detachPtr(JSValue0: JSC__JSValue) void;
pub extern fn FileSink__fromJS(arg0: *bindings.JSGlobalObject, JSValue1: JSC__JSValue) ?*anyopaque;
pub extern fn FileSink__onClose(JSValue0: JSC__JSValue, JSValue1: JSC__JSValue) void;
pub extern fn FileSink__onReady(JSValue0: JSC__JSValue, JSValue1: JSC__JSValue, JSValue2: JSC__JSValue) void;
+pub extern fn BrotliDecompressorSink__assignToStream(arg0: *bindings.JSGlobalObject, JSValue1: JSC__JSValue, arg2: ?*anyopaque, arg3: [*c]*anyopaque) JSC__JSValue;
+pub extern fn BrotliDecompressorSink__createObject(arg0: *bindings.JSGlobalObject, arg1: ?*anyopaque) JSC__JSValue;
+pub extern fn BrotliDecompressorSink__detachPtr(JSValue0: JSC__JSValue) void;
+pub extern fn BrotliDecompressorSink__fromJS(arg0: *bindings.JSGlobalObject, JSValue1: JSC__JSValue) ?*anyopaque;
+pub extern fn BrotliDecompressorSink__onClose(JSValue0: JSC__JSValue, JSValue1: JSC__JSValue) void;
+pub extern fn BrotliDecompressorSink__onReady(JSValue0: JSC__JSValue, JSValue1: JSC__JSValue, JSValue2: JSC__JSValue) void;
+pub extern fn BrotliCompressorSink__assignToStream(arg0: *bindings.JSGlobalObject, JSValue1: JSC__JSValue, arg2: ?*anyopaque, arg3: [*c]*anyopaque) JSC__JSValue;
+pub extern fn BrotliCompressorSink__createObject(arg0: *bindings.JSGlobalObject, arg1: ?*anyopaque) JSC__JSValue;
+pub extern fn BrotliCompressorSink__detachPtr(JSValue0: JSC__JSValue) void;
+pub extern fn BrotliCompressorSink__fromJS(arg0: *bindings.JSGlobalObject, JSValue1: JSC__JSValue) ?*anyopaque;
+pub extern fn BrotliCompressorSink__onClose(JSValue0: JSC__JSValue, JSValue1: JSC__JSValue) void;
+pub extern fn BrotliCompressorSink__onReady(JSValue0: JSC__JSValue, JSValue1: JSC__JSValue, JSValue2: JSC__JSValue) void;
pub extern fn ZigException__fromException(arg0: [*c]bindings.Exception) ZigException;
diff --git a/src/bun.js/scripts/generate-jssink.js b/src/bun.js/scripts/generate-jssink.js
index 715df1f82..d9d045a40 100644
--- a/src/bun.js/scripts/generate-jssink.js
+++ b/src/bun.js/scripts/generate-jssink.js
@@ -1,7 +1,13 @@
import { resolve } from "path";
-const classes = ["ArrayBufferSink", "FileSink", "HTTPResponseSink", "HTTPSResponseSink"];
-const SINK_COUNT = 5;
+const classes = [
+ "ArrayBufferSink",
+ "FileSink",
+ "HTTPResponseSink",
+ "HTTPSResponseSink",
+ "BrotliDecompressorSink",
+ "BrotliCompressorSink",
+];
function names(name) {
return {
diff --git a/src/bun.js/webcore/streams.zig b/src/bun.js/webcore/streams.zig
index 9b8f5dd6f..ff4712041 100644
--- a/src/bun.js/webcore/streams.zig
+++ b/src/bun.js/webcore/streams.zig
@@ -1896,12 +1896,222 @@ pub const ArrayBufferSink = struct {
pub const JSSink = NewJSSink(@This(), "ArrayBufferSink");
};
+pub const BrotliCompressorSink = struct {
+ state: ?*bun.brotli.BrotliEncoderState = null,
+ allocator: std.mem.Allocator,
+ done: bool = false,
+ signal: Signal = .{},
+ next: ?Sink = null,
+ output_buffer: bun.ByteList = bun.ByteList{},
+ chunk_size: u32 = 16 * 1024,
+
+ pub fn connect(this: *BrotliCompressorSink, signal: Signal) void {
+ std.debug.assert(this.reader == null);
+ this.signal = signal;
+ }
+
+ pub fn start(this: *BrotliCompressorSink, _: StreamStart) JSC.Node.Maybe(void) {
+ this.output_buffer.len = 0;
+
+ if (this.state == null) {
+ this.state = bun.brotli.BrotliEncoderState.init();
+ }
+
+ // switch (stream_start) {
+ // .BrotliCompressorSink => |config| {
+ // if (config.chunk_size > 0) {
+ // list.ensureTotalCapacityPrecise(config.chunk_size) catch return .{ .err = Syscall.Error.oom };
+ // this.bytes.update(list);
+ // }
+
+ // this.as_uint8array = config.as_uint8array;
+ // this.streaming = config.stream;
+ // },
+ // else => {},
+ // }
+
+ this.done = false;
+
+ this.signal.start();
+ return .{ .result = {} };
+ }
+
+ pub fn flush(this: *BrotliCompressorSink) JSC.Node.Maybe(void) {
+ _ = this;
+ return .{ .result = {} };
+ }
+
+ pub fn flushFromJS(this: *BrotliCompressorSink, globalThis: *JSGlobalObject, wait: bool) JSC.Node.Maybe(JSValue) {
+ _ = wait;
+
+ if (this.output_buffer.len > 0) {
+ if (this.next) |*next| {
+ var list = this.output_buffer;
+ this.output_buffer = bun.ByteList.init("");
+ return .{ .result = next.writeBytes(.{ .owned = list }).toJS(globalThis) };
+ }
+
+ return .{ .result = JSC.JSValue.jsNumber(this.output_buffer.len) };
+ }
+
+ return .{ .result = JSC.JSValue.jsNumber(0) };
+ }
+
+ pub fn finalize(this: *BrotliCompressorSink) void {
+ if (this.state) |state| {
+ state.deinit();
+ }
+ this.output_buffer.deinitWithAllocator(bun.default_allocator);
+ this.allocator.destroy(this);
+ }
+
+ pub fn init(allocator: std.mem.Allocator, next: ?Sink) !*BrotliCompressorSink {
+ var this = try allocator.create(BrotliCompressorSink);
+ this.* = BrotliCompressorSink{
+ .bytes = bun.ByteList.init(&.{}),
+ .allocator = allocator,
+ .next = next,
+ };
+ return this;
+ }
+
+ pub fn construct(
+ this: *BrotliCompressorSink,
+ allocator: std.mem.Allocator,
+ ) void {
+ this.* = BrotliCompressorSink{
+ .allocator = allocator,
+ .next = null,
+ .state = null,
+ };
+ }
+
+ pub fn write(this: *@This(), data: StreamResult) StreamResult.Writable {
+ var state = this.state orelse return .{ .done = {} };
+ var initial_slice = data.slice();
+ var slice = initial_slice;
+ if (this.output_buffer.cap == 0) {
+ this.output_buffer.ensureUnusedCapacity(bun.default_allocator, this.chunk_size) catch {
+ return .{ .err = Syscall.Error.oom };
+ };
+ }
+ var output_slice = this.output_buffer.ptr[this.output_buffer.len..this.output_buffer.cap];
+
+ while (slice.len > 0) {
+ if (this.output_buffer.cap - this.output_buffer.len < 512) {
+ this.output_buffer.ensureUnusedCapacity(bun.default_allocator, this.chunk_size) catch {
+ return .{ .err = Syscall.Error.oom };
+ };
+ output_slice = this.output_buffer.ptr[this.output_buffer.len..this.output_buffer.cap];
+ }
+ const max = output_slice.len;
+ const res = state.write(&slice, &output_slice);
+ this.output_buffer.len += @truncate(u32, max - output_slice.len);
+
+ if (res) {
+ if (this.output_buffer.len > 0) {
+ if (this.next) |*next| {
+ var output_buffer = this.output_buffer;
+
+ if (data.isDone()) {
+ this.output_buffer = .{};
+ return next.writeBytes(.{ .owned_and_done = output_buffer });
+ }
+ }
+
+ if (data.isDone()) {
+ return .{ .owned_and_done = @truncate(Blob.SizeType, initial_slice.len - slice.len) };
+ }
+ }
+ } else {
+ @panic("Unhandled brotli error");
+ }
+ }
+
+ return .{ .owned = @truncate(Blob.SizeType, initial_slice.len - slice.len) };
+ }
+ pub const writeBytes = write;
+ pub fn writeLatin1(this: *@This(), data: StreamResult) StreamResult.Writable {
+ if (strings.isAllASCII(data.slice())) {
+ return this.write(data);
+ }
+
+ var allocated = strings.allocateLatin1IntoUTF8(bun.default_allocator, []const u8, data.slice()) catch {
+ return .{ .err = Syscall.Error.oom };
+ };
+ defer bun.default_allocator.free(allocated);
+ return this.write(.{ .temporary = bun.ByteList.init(allocated) });
+ }
+ pub fn writeUTF16(this: *@This(), data: StreamResult) StreamResult.Writable {
+ if (this.next) |*next| {
+ return next.writeUTF16(data);
+ }
+ var bytes = strings.toUTF8Alloc(bun.default_allocator, @ptrCast([*]const u16, @alignCast(@alignOf(u16), data.slice().ptr))[0..std.mem.bytesAsSlice(u16, data.slice()).len]) catch {
+ return .{ .err = Syscall.Error.oom };
+ };
+ defer bun.default_allocator.free(bytes);
+ return this.write(.{ .temporary = bun.ByteList.init(bytes) });
+ }
+
+ pub fn end(this: *BrotliCompressorSink, err: ?Syscall.Error) JSC.Node.Maybe(void) {
+ if (this.next) |*next| {
+ return next.end(err);
+ }
+ this.signal.close(err);
+ return .{ .result = {} };
+ }
+
+ pub fn toJS(this: *BrotliCompressorSink, globalThis: *JSGlobalObject) JSValue {
+ return JSSink.createObject(globalThis, this);
+ }
+
+ pub fn endFromJS(this: *@This(), globalThis: *JSGlobalObject) JSC.Node.Maybe(JSValue) {
+ var state = this.state orelse return .{ .result = JSC.JSValue.jsUndefined() };
+ var input: []const u8 = "";
+ if (this.output_buffer.cap == 0) {
+ this.output_buffer.ensureUnusedCapacity(bun.default_allocator, this.chunk_size) catch {
+ return .{ .err = Syscall.Error.oom };
+ };
+ }
+
+ while (state.hasMoreOutput()) : (this.output_buffer.ensureUnusedCapacity(bun.default_allocator, this.chunk_size) catch @panic("OOM")) {
+ var output_slice = this.output_buffer.ptr[this.output_buffer.len..this.output_buffer.cap];
+ const initial_len = output_slice.len;
+
+ if (!state.finish(&input, &output_slice)) {
+ @panic("Unhandled brotli error");
+ }
+
+ this.output_buffer.len += @truncate(u32, initial_len - output_slice.len);
+ }
+
+ state.deinit();
+ this.state = null;
+
+ std.debug.assert(this.next == null);
+ var list = this.output_buffer.listManaged(this.allocator);
+ this.output_buffer = bun.ByteList.init("");
+ this.done = true;
+ this.signal.close(null);
+ return .{ .result = JSC.JSValue.createBuffer(globalThis, list.items, bun.default_allocator) };
+ }
+
+ pub fn sink(this: *BrotliCompressorSink) Sink {
+ return Sink.init(this);
+ }
+
+ pub const JSSink = NewJSSink(@This(), "BrotliCompressorSink");
+};
+
pub const BrotliDecompressorSink = struct {
state: ?*bun.brotli.BrotliDecoderState = null,
allocator: std.mem.Allocator,
done: bool = false,
signal: Signal = .{},
streaming: bool = false,
+ next: ?Sink = null,
+ output_buffer: bun.ByteList = bun.ByteList{},
+ chunk_size: u32 = 16 * 1024,
pub fn connect(this: *BrotliDecompressorSink, signal: Signal) void {
std.debug.assert(this.reader == null);
@@ -1909,7 +2119,7 @@ pub const BrotliDecompressorSink = struct {
}
pub fn start(this: *BrotliDecompressorSink, _: StreamStart) JSC.Node.Maybe(void) {
- this.bytes.len = 0;
+ this.output_buffer.len = 0;
if (this.state) |existing| {
if (existing.isUsed()) {
@@ -1948,16 +2158,25 @@ pub const BrotliDecompressorSink = struct {
pub fn flushFromJS(this: *BrotliDecompressorSink, globalThis: *JSGlobalObject, wait: bool) JSC.Node.Maybe(JSValue) {
_ = wait;
- _ = globalThis;
- _ = this;
- return .{ .result = JSValue.jsNumber(0) };
+ if (this.output_buffer.len > 0) {
+ if (this.next) |*next| {
+ var list = this.output_buffer;
+ this.output_buffer = bun.ByteList.init("");
+ return .{ .result = next.writeBytes(.{ .owned = list }).toJS(globalThis) };
+ }
+
+ return .{ .result = JSC.JSValue.jsNumber(this.output_buffer.len) };
+ }
+
+ return .{ .result = JSC.JSValue.jsNumber(0) };
}
pub fn finalize(this: *BrotliDecompressorSink) void {
if (this.state) |state| {
state.deinit();
}
+ this.output_buffer.deinitWithAllocator(bun.default_allocator);
this.allocator.destroy(this);
}
@@ -1984,30 +2203,75 @@ pub const BrotliDecompressorSink = struct {
pub fn write(this: *@This(), data: StreamResult) StreamResult.Writable {
var state = this.state orelse return .{ .done = {} };
- const initial_slice = data.slice();
+ var initial_slice = data.slice();
var slice = initial_slice;
- state.write(&slice);
+ if (this.output_buffer.cap == 0) {
+ this.output_buffer.ensureUnusedCapacity(bun.default_allocator, this.chunk_size) catch {
+ return .{ .err = Syscall.Error.oom };
+ };
+ }
+ var output_slice = this.output_buffer.ptr[this.output_buffer.len..this.output_buffer.cap];
+
+ while (true) {
+ if (this.output_buffer.cap - this.output_buffer.len < 512) {
+ this.output_buffer.ensureUnusedCapacity(bun.default_allocator, this.chunk_size) catch {
+ return .{ .err = Syscall.Error.oom };
+ };
+ output_slice = this.output_buffer.ptr[this.output_buffer.len..this.output_buffer.cap];
+ }
+ const max = output_slice.len;
+ const res = state.write(&slice, &output_slice);
+ this.output_buffer.len += @truncate(u32, max - output_slice.len);
+
+ switch (res) {
+ .success => {
+ if (this.next) |*next| {
+ var output_buffer = this.output_buffer;
+ this.output_buffer = .{};
+ return next.writeBytes(.{ .owned_and_done = output_buffer });
+ }
+ this.signal.ready(null, null);
+ return .{ .owned_and_done = @truncate(Blob.SizeType, initial_slice.len - slice.len) };
+ },
+ .@"error" => {
+ return .{ .err = Syscall.Error.oom };
+ },
+ .needs_more_input => {
+ this.signal.ready(null, null);
+ return .{ .owned = @truncate(Blob.SizeType, initial_slice.len - slice.len) };
+ },
+
+ .needs_more_output => {
+ if (this.next) |*next| {
+ var output_buffer = this.output_buffer;
+ this.output_buffer = .{};
+ return next.writeBytes(.{ .owned = output_buffer });
+ }
+ },
+ }
+ }
}
pub const writeBytes = write;
pub fn writeLatin1(this: *@This(), data: StreamResult) StreamResult.Writable {
- if (this.next) |*next| {
- return next.writeLatin1(data);
+ if (strings.isAllASCII(data.slice())) {
+ return this.write(data);
}
- const len = this.bytes.writeLatin1(this.allocator, data.slice()) catch {
+
+ var allocated = strings.allocateLatin1IntoUTF8(bun.default_allocator, []const u8, data.slice()) catch {
return .{ .err = Syscall.Error.oom };
};
- this.signal.ready(null, null);
- return .{ .owned = len };
+ defer bun.default_allocator.free(allocated);
+ return this.write(.{ .temporary = bun.ByteList.init(allocated) });
}
pub fn writeUTF16(this: *@This(), data: StreamResult) StreamResult.Writable {
if (this.next) |*next| {
return next.writeUTF16(data);
}
- const len = this.bytes.writeUTF16(this.allocator, @ptrCast([*]const u16, @alignCast(@alignOf(u16), data.slice().ptr))[0..std.mem.bytesAsSlice(u16, data.slice()).len]) catch {
+ var bytes = strings.toUTF8Alloc(bun.default_allocator, @ptrCast([*]const u16, @alignCast(@alignOf(u16), data.slice().ptr))[0..std.mem.bytesAsSlice(u16, data.slice()).len]) catch {
return .{ .err = Syscall.Error.oom };
};
- this.signal.ready(null, null);
- return .{ .owned = len };
+ defer bun.default_allocator.free(bytes);
+ return this.write(.{ .temporary = bun.ByteList.init(bytes) });
}
pub fn end(this: *BrotliDecompressorSink, err: ?Syscall.Error) JSC.Node.Maybe(void) {
@@ -2018,44 +2282,22 @@ pub const BrotliDecompressorSink = struct {
return .{ .result = {} };
}
- pub fn toJS(this: *BrotliDecompressorSink, globalThis: *JSGlobalObject, as_uint8array: bool) JSValue {
- if (this.streaming) {
- const value: JSValue = switch (as_uint8array) {
- true => JSC.ArrayBuffer.create(globalThis, this.bytes.slice(), .Uint8Array),
- false => JSC.ArrayBuffer.create(globalThis, this.bytes.slice(), .ArrayBuffer),
- };
- this.bytes.len = 0;
- return value;
- }
-
- var list = this.bytes.listManaged(this.allocator);
- this.bytes = bun.ByteList.init("");
- return ArrayBuffer.fromBytes(
- try list.toOwnedSlice(),
- if (as_uint8array)
- .Uint8Array
- else
- .ArrayBuffer,
- ).toJS(globalThis, null);
+ pub fn toJS(this: *BrotliDecompressorSink, globalThis: *JSGlobalObject) JSValue {
+ return JSSink.createObject(globalThis, this);
}
- pub fn endFromJS(this: *BrotliDecompressorSink, _: *JSGlobalObject) JSC.Node.Maybe(ArrayBuffer) {
- if (this.done) {
- return .{ .result = ArrayBuffer.fromBytes(&[_]u8{}, .ArrayBuffer) };
+ pub fn endFromJS(this: *@This(), globalThis: *JSGlobalObject) JSC.Node.Maybe(JSValue) {
+ if (this.state) |state| {
+ state.deinit();
+ this.state = null;
}
std.debug.assert(this.next == null);
- var list = this.bytes.listManaged(this.allocator);
- this.bytes = bun.ByteList.init("");
+ var list = this.output_buffer.listManaged(this.allocator);
+ this.output_buffer = bun.ByteList.init("");
this.done = true;
this.signal.close(null);
- return .{ .result = ArrayBuffer.fromBytes(
- list.toOwnedSlice() catch @panic("TODO"),
- if (this.as_uint8array)
- .Uint8Array
- else
- .ArrayBuffer,
- ) };
+ return .{ .result = JSC.JSValue.createBuffer(globalThis, list.items, bun.default_allocator) };
}
pub fn sink(this: *BrotliDecompressorSink) Sink {
diff --git a/src/deps/brotli.zig b/src/deps/brotli.zig
index 0e4b687f3..b79f878a6 100644
--- a/src/deps/brotli.zig
+++ b/src/deps/brotli.zig
@@ -54,6 +54,98 @@ pub const BrotliDecoderState = opaque {
return BrotliDecoderGetErrorCode(self);
}
};
+
+pub const BrotliEncoderState = opaque {
+ pub fn init() *BrotliEncoderState {
+ return BrotliEncoderCreateInstance(default_brotli_alloc_fn, default_brotli_free_fn, null);
+ }
+
+ pub fn deinit(self: *BrotliEncoderState) void {
+ BrotliEncoderDestroyInstance(self);
+ }
+
+ pub fn setParameter(self: *BrotliEncoderState, param: BrotliEncoderParameter, value: u32) bool {
+ return BrotliEncoderSetParameter(self, param, value) == BROTLI_TRUE;
+ }
+
+ pub fn isFinished(self: *BrotliEncoderState) bool {
+ return BrotliEncoderIsFinished(self) == BROTLI_TRUE;
+ }
+
+ pub fn hasMoreOutput(self: *BrotliEncoderState) bool {
+ return BrotliEncoderHasMoreOutput(self) == BROTLI_TRUE;
+ }
+
+ /// Compresses input stream to output stream.
+ ///
+ /// The values *available_in and *available_out must specify the number of
+ /// bytes addressable at *next_in and *next_out respectively. When
+ /// *available_out is 0, next_out is allowed to be NULL.
+ ///
+ /// After each call, *available_in will be decremented by the amount of
+ /// input bytes consumed, and the *next_in pointer will be incremented by that
+ /// amount. Similarly, *available_out will be decremented by the amount of
+ /// output bytes written, and the *next_out pointer will be incremented by
+ /// that amount.
+ ///
+ /// total_out, if it is not a null-pointer, will be set to the number of
+ /// bytes decompressed since the last state initialization.
+ ///
+ /// Internally workflow consists of 3 tasks:
+ ///
+ /// (optionally) copy input data to internal buffer / actually compress data
+ /// and (optionally) store it to internal buffer / (optionally) copy
+ /// compressed bytes from internal buffer to output stream / Whenever all 3
+ /// tasks can't move forward anymore, or error occurs, this method returns the
+ /// control flow to caller.
+ ///
+ /// op is used to perform flush, finish the stream, or inject metadata
+ /// block. See BrotliEncoderOperation for more information.
+ ///
+ /// Flushing the stream means forcing encoding of all input passed to /
+ /// encoder and completing the current output block, so it could be fully /
+ /// decoded by stream decoder. To perform flush set op to /
+ /// BROTLI_OPERATION_FLUSH. Under some circumstances (e.g. lack of output /
+ /// stream capacity) this operation would require several calls to /
+ /// BrotliEncoderCompressStream. The method must be called again until both /
+ /// input stream is depleted and encoder has no more output (see /
+ /// BrotliEncoderHasMoreOutput) after the method is called.
+ ///
+ /// Finishing the stream means encoding of all input passed to encoder and /
+ /// adding specific "final" marks, so stream decoder could determine that /
+ /// stream is complete. To perform finish set op to BROTLI_OPERATION_FINISH. /
+ /// Under some circumstances (e.g. lack of output stream capacity) this /
+ /// operation would require several calls to BrotliEncoderCompressStream. The
+ /// method must be called again until both input stream is depleted and /
+ /// encoder has no more output (see BrotliEncoderHasMoreOutput) after the /
+ /// method is called.
+ ///
+ /// Warning
+ /// When flushing and finishing, op should not change until operation is complete; input stream should not be swapped, reduced or extended as well.
+ pub fn compress(self: *BrotliEncoderState, op: BrotliEncoderOperation, input: *[]const u8, output: *[]u8, encoded_size: ?*usize) bool {
+ var out: ?[*]u8 = output.ptr;
+ var len = output.len;
+ defer {
+ output.len = len;
+ if (out != null)
+ output.ptr = out.?;
+ }
+ return BrotliEncoderCompressStream(self, op, &input.len, &input.ptr, &len, &out, encoded_size) == BROTLI_TRUE;
+ }
+
+ pub fn write(self: *BrotliEncoderState, input: *[]const u8, output: *[]u8) bool {
+ return compress(self, .process, input, output, null);
+ }
+
+ pub fn flush(self: *BrotliEncoderState, input: *[]const u8, output: *[]u8) bool {
+ return compress(self, .flush, input, output, null);
+ }
+
+ pub fn finish(self: *BrotliEncoderState, input: *[]const u8, output: *[]u8) bool {
+ return compress(self, .finish, input, output, null);
+ }
+};
+
pub const BROTLI_DECODER_RESULT_ERROR: u32 = 0;
pub const BROTLI_DECODER_RESULT_SUCCESS: u32 = 1;
pub const BROTLI_DECODER_RESULT_NEEDS_MORE_INPUT: u32 = 2;
@@ -134,7 +226,7 @@ pub const BrotliDecoderParameter = enum(u32) {
};
pub extern fn BrotliDecoderSetParameter(state: ?*BrotliDecoderState, param: BrotliEncoderParameter, value: u32) c_int;
pub extern fn BrotliDecoderAttachDictionary(state: ?*BrotliDecoderState, @"type": BrotliSharedDictionaryType, data_size: usize, data: [*c]const u8) c_int;
-pub extern fn BrotliDecoderCreateInstance(alloc_func: brotli_alloc_func, free_func: brotli_free_func, @"opaque": ?*anyopaque) ?*BrotliDecoderState;
+pub extern fn BrotliDecoderCreateInstance(alloc_func: brotli_alloc_func, free_func: brotli_free_func, @"opaque": ?*anyopaque) *BrotliDecoderState;
pub extern fn BrotliDecoderDestroyInstance(state: ?*BrotliDecoderState) void;
pub extern fn BrotliDecoderDecompress(encoded_size: usize, encoded_buffer: [*]const u8, decoded_size: *usize, decoded_buffer: [*]u8) BrotliDecoderResult;
pub extern fn BrotliDecoderDecompressStream(state: *BrotliDecoderState, available_in: *usize, next_in: *[*]const u8, available_out: *usize, next_out: *[*]u8, total_out: ?*usize) BrotliDecoderResult;
@@ -202,10 +294,9 @@ pub const BrotliEncoderParameter = enum(u32) {
stream_offset = BROTLI_PARAM_STREAM_OFFSET,
_,
};
-pub const struct_BrotliEncoderStateStruct = opaque {};
-pub const BrotliEncoderState = struct_BrotliEncoderStateStruct;
+
pub extern fn BrotliEncoderSetParameter(state: ?*BrotliEncoderState, param: BrotliEncoderParameter, value: u32) c_int;
-pub extern fn BrotliEncoderCreateInstance(alloc_func: brotli_alloc_func, free_func: brotli_free_func, ctx: ?*anyopaque) ?*BrotliEncoderState;
+pub extern fn BrotliEncoderCreateInstance(alloc_func: brotli_alloc_func, free_func: brotli_free_func, ctx: ?*anyopaque) *BrotliEncoderState;
pub extern fn BrotliEncoderDestroyInstance(state: ?*BrotliEncoderState) void;
pub const struct_BrotliEncoderPreparedDictionaryStruct = opaque {};
pub const BrotliEncoderPreparedDictionary = struct_BrotliEncoderPreparedDictionaryStruct;
@@ -214,10 +305,10 @@ pub extern fn BrotliEncoderDestroyPreparedDictionary(dictionary: ?*BrotliEncoder
pub extern fn BrotliEncoderAttachPreparedDictionary(state: ?*BrotliEncoderState, dictionary: ?*const BrotliEncoderPreparedDictionary) c_int;
pub extern fn BrotliEncoderMaxCompressedSize(input_size: usize) usize;
pub extern fn BrotliEncoderCompress(quality: c_int, lgwin: c_int, mode: BrotliEncoderMode, input_size: usize, input_buffer: [*]const u8, encoded_size: *usize, encoded_buffer: [*]u8) c_int;
-pub extern fn BrotliEncoderCompressStream(state: *BrotliEncoderState, op: BrotliEncoderOperation, available_in: *usize, next_in: *[*]const u8, available_out: *usize, next_out: *?[*]u8, total_out: *usize) c_int;
+pub extern fn BrotliEncoderCompressStream(state: *BrotliEncoderState, op: BrotliEncoderOperation, available_in: *usize, next_in: *[*]const u8, available_out: *usize, next_out: *?[*]u8, total_out: ?*usize) c_int;
pub extern fn BrotliEncoderIsFinished(state: *BrotliEncoderState) c_int;
pub extern fn BrotliEncoderHasMoreOutput(state: *BrotliEncoderState) c_int;
-pub extern fn BrotliEncoderTakeOutput(state: *BrotliEncoderState, size: [*c]usize) [*c]const u8;
+pub extern fn BrotliEncoderTakeOutput(state: *BrotliEncoderState, size: *usize) ?[*]const u8;
pub extern fn BrotliEncoderEstimatePeakMemoryUsage(quality: c_int, lgwin: c_int, input_size: usize) usize;
pub extern fn BrotliEncoderGetPreparedDictionarySize(dictionary: ?*const BrotliEncoderPreparedDictionary) usize;
pub extern fn BrotliEncoderVersion() u32;
@@ -232,5 +323,4 @@ pub const BROTLI_MAX_QUALITY = @as(c_int, 11);
pub const BROTLI_DEFAULT_QUALITY = @as(c_int, 11);
pub const BROTLI_DEFAULT_WINDOW = @as(c_int, 22);
pub const BROTLI_DEFAULT_MODE = BROTLI_MODE_GENERIC;
-pub const BrotliEncoderStateStruct = struct_BrotliEncoderStateStruct;
pub const BrotliEncoderPreparedDictionaryStruct = struct_BrotliEncoderPreparedDictionaryStruct;