diff options
Diffstat (limited to 'src/bun.js')
-rw-r--r-- | src/bun.js/api/js_brotli.zig | 79 | ||||
-rw-r--r-- | src/bun.js/base.zig | 10 | ||||
-rw-r--r-- | src/bun.js/bindings/JSMockFunction.cpp | 17 | ||||
-rw-r--r-- | src/bun.js/bindings/JSSink.cpp | 1002 | ||||
-rw-r--r-- | src/bun.js/bindings/JSSink.h | 296 | ||||
-rw-r--r-- | src/bun.js/bindings/JSSinkLookupTable.h | 162 | ||||
-rw-r--r-- | src/bun.js/bindings/ModuleLoader.cpp | 27 | ||||
-rw-r--r-- | src/bun.js/bindings/Sink.h | 4 | ||||
-rw-r--r-- | src/bun.js/bindings/ZigGlobalObject.cpp | 40 | ||||
-rw-r--r-- | src/bun.js/bindings/ZigGlobalObject.h | 14 | ||||
-rw-r--r-- | src/bun.js/bindings/bindings.zig | 8 | ||||
-rw-r--r-- | src/bun.js/bindings/exports.zig | 4 | ||||
-rw-r--r-- | src/bun.js/bindings/headers-cpp.h | 6 | ||||
-rw-r--r-- | src/bun.js/bindings/headers.h | 40 | ||||
-rw-r--r-- | src/bun.js/bindings/headers.zig | 12 | ||||
-rw-r--r-- | src/bun.js/scripts/generate-jssink.js | 10 | ||||
-rw-r--r-- | src/bun.js/webcore/streams.zig | 401 |
17 files changed, 2084 insertions, 48 deletions
diff --git a/src/bun.js/api/js_brotli.zig b/src/bun.js/api/js_brotli.zig new file mode 100644 index 000000000..41b8070ce --- /dev/null +++ b/src/bun.js/api/js_brotli.zig @@ -0,0 +1,79 @@ +const Bun = @This(); +const default_allocator = @import("root").bun.default_allocator; +const bun = @import("root").bun; +const JSC = bun.JSC; +const Environment = bun.Environment; +const NetworkThread = @import("root").bun.HTTP.NetworkThread; +const Global = bun.Global; +const strings = bun.strings; +const string = bun.string; +const Output = @import("root").bun.Output; +const MutableString = @import("root").bun.MutableString; +const std = @import("std"); +const Allocator = std.mem.Allocator; +const brotli = bun.brotli; + +pub const Brotli = struct { + fn brotli_alloc_func(ctx: ?*anyopaque, size: usize) callconv(.C) ?*anyopaque { + _ = ctx; + return bun.Mimalloc.mi_malloc(size); + } + fn brotli_free_func(ctx: ?*anyopaque, ptr: ?*anyopaque) callconv(.C) void { + _ = ctx; + return bun.Mimalloc.mi_free(ptr); + } + + pub const Options = struct { + pub fn fromJS(globalObject: *JSC.JSGlobalObject, value: JSC.JSValue, comptime StateType: type) !*StateType { + if (!value.isObject()) { + globalObject.throwInvalidArguments("Expected options to be an object", .{}); + return error.JSError; + } + var state = if (comptime StateType == brotli.BrotliDecoderState) brotli.BrotliDecoderCreateInstance(brotli_alloc_func, brotli_free_func, null) else brotli.BrotliEncoderCreateInstance(brotli_alloc_func, brotli_free_func, null); + errdefer { + if (comptime StateType == brotli.BrotliDecoderState) { + brotli.BrotliDecoderDestroyInstance(state); + } else { + brotli.BrotliEncoderDestroyInstance(state); + } + } + const setParamter = if (comptime StateType == brotli.BrotliDecoderState) + brotli.BrotliDecoderSetParameter + else + brotli.BrotliEncoderSetParameter; + + // flush <integer> Default: zlib.constants.BROTLI_OPERATION_PROCESS + var flush_value = brotli.BROTLI_OPERATION_PROCESS; + if (try value.getOptional(globalObject, "flush", u32)) |flushy| { + flush_value = flushy; + } + + if (setParamter(state, .flush, flush_value) == 0) { + globalObject.throwInvalidArguments("Invalid flush value", .{}); + return error.JSError; + } + + // finishFlush <integer> Default: zlib.constants.BROTLI_OPERATION_FINISH + var finishFlush_value = brotli.BROTLI_OPERATION_FINISH; + if (try value.getOptional(globalObject, "finishFlush", u32)) |finishFlushy| { + finishFlush_value = finishFlushy; + } + + if (setParamter(state, .finishFlush, flush_value) == 0) { + globalObject.throwInvalidArguments("Invalid finishFlush value", .{}); + return error.JSError; + } + + // 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. + + // maxOutputLength <integer> Limits output size when using convenience methods. Default: buffer.kMaxLength + + } + }; +}; diff --git a/src/bun.js/base.zig b/src/bun.js/base.zig index f7b2eb343..b6623af88 100644 --- a/src/bun.js/base.zig +++ b/src/bun.js/base.zig @@ -1784,6 +1784,16 @@ pub const ArrayBuffer = extern struct { }; } + pub fn createFromLength(globalThis: *JSC.JSGlobalObject, len: usize, comptime kind: BinaryType) JSValue { + JSC.markBinding(@src()); + return switch (comptime kind) { + .Uint8Array => Bun__createUint8ArrayForCopy(globalThis, null, len, false), + .Buffer => Bun__createUint8ArrayForCopy(globalThis, null, len, true), + .ArrayBuffer => Bun__createArrayBufferForCopy(globalThis, null, len), + else => @compileError("Not implemented yet"), + }; + } + pub fn createEmpty(globalThis: *JSC.JSGlobalObject, comptime kind: JSC.JSValue.JSType) JSValue { JSC.markBinding(@src()); 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 09a5a396c..6da2cbdd2 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-17T20:32:20.223Z +// Generated by 'make generate-sink' at 2023-07-18T09:07:30.319Z // 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 46111a0a2..7e95b886a 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-17T20:32:20.222Z +// Generated by 'make generate-sink' at 2023-07-18T09:07:30.318Z // #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 e4ed81629..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 /home/cirospaciari/Repos/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..12840aceb 100644 --- a/src/bun.js/bindings/ZigGlobalObject.cpp +++ b/src/bun.js/bindings/ZigGlobalObject.cpp @@ -1390,7 +1390,7 @@ extern "C" JSC__JSValue Bun__createArrayBufferForCopy(JSC::JSGlobalObject* globa return JSC::JSValue::encode(JSC::JSValue {}); } - if (len > 0) + if (len > 0 && ptr) memcpy(arrayBuffer->data(), ptr, len); RELEASE_AND_RETURN(scope, JSValue::encode(JSC::JSArrayBuffer::create(globalObject->vm(), globalObject->arrayBufferStructure(JSC::ArrayBufferSharingMode::Default), WTFMove(arrayBuffer)))); @@ -1409,7 +1409,7 @@ extern "C" JSC__JSValue Bun__createUint8ArrayForCopy(JSC::JSGlobalObject* global return JSC::JSValue::encode(JSC::JSValue {}); } - if (len > 0) + if (len > 0 && ptr) memcpy(array->vector(), ptr, len); RELEASE_AND_RETURN(scope, JSValue::encode(array)); @@ -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,18 @@ 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 +4447,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 +4464,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/bindings.zig b/src/bun.js/bindings/bindings.zig index 46f76d21d..3386de9b2 100644 --- a/src/bun.js/bindings/bindings.zig +++ b/src/bun.js/bindings/bindings.zig @@ -4430,6 +4430,14 @@ pub const JSValue = enum(JSValueReprInt) { globalThis.throwInvalidArguments(property_name ++ " must be a boolean", .{}); return error.JSError; }, + u32 => { + if (prop.isNumber()) { + return prop.to(u32); + } + + globalThis.throwInvalidArguments(property_name ++ " must be a number", .{}); + return error.JSError; + }, ZigString.Slice => { if (prop.isString()) { if (return prop.toSliceOrNull(globalThis)) |str| { diff --git a/src/bun.js/bindings/exports.zig b/src/bun.js/bindings/exports.zig index 6ec8ff2b9..b569fe68c 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.h b/src/bun.js/bindings/headers.h index 9bc8cd793..c03b621c1 100644 --- a/src/bun.js/bindings/headers.h +++ b/src/bun.js/bindings/headers.h @@ -716,6 +716,46 @@ ZIG_DECL void FileSink__updateRef(void* arg0, bool arg1); ZIG_DECL JSC__JSValue FileSink__write(JSC__JSGlobalObject* arg0, JSC__CallFrame* arg1); #endif +CPP_DECL JSC__JSValue BrotliDecompressorSink__assignToStream(JSC__JSGlobalObject* arg0, JSC__JSValue JSValue1, void* arg2, void** arg3); +CPP_DECL JSC__JSValue BrotliDecompressorSink__createObject(JSC__JSGlobalObject* arg0, void* arg1); +CPP_DECL void BrotliDecompressorSink__detachPtr(JSC__JSValue JSValue0); +CPP_DECL void* BrotliDecompressorSink__fromJS(JSC__JSGlobalObject* arg0, JSC__JSValue JSValue1); +CPP_DECL void BrotliDecompressorSink__onClose(JSC__JSValue JSValue0, JSC__JSValue JSValue1); +CPP_DECL void BrotliDecompressorSink__onReady(JSC__JSValue JSValue0, JSC__JSValue JSValue1, JSC__JSValue JSValue2); + +#ifdef __cplusplus + +ZIG_DECL JSC__JSValue BrotliDecompressorSink__close(JSC__JSGlobalObject* arg0, void* arg1); +ZIG_DECL JSC__JSValue BrotliDecompressorSink__construct(JSC__JSGlobalObject* arg0, JSC__CallFrame* arg1); +ZIG_DECL JSC__JSValue BrotliDecompressorSink__end(JSC__JSGlobalObject* arg0, JSC__CallFrame* arg1); +ZIG_DECL JSC__JSValue BrotliDecompressorSink__endWithSink(void* arg0, JSC__JSGlobalObject* arg1); +ZIG_DECL void BrotliDecompressorSink__finalize(void* arg0); +ZIG_DECL JSC__JSValue BrotliDecompressorSink__flush(JSC__JSGlobalObject* arg0, JSC__CallFrame* arg1); +ZIG_DECL JSC__JSValue BrotliDecompressorSink__start(JSC__JSGlobalObject* arg0, JSC__CallFrame* arg1); +ZIG_DECL void BrotliDecompressorSink__updateRef(void* arg0, bool arg1); +ZIG_DECL JSC__JSValue BrotliDecompressorSink__write(JSC__JSGlobalObject* arg0, JSC__CallFrame* arg1); + +#endif +CPP_DECL JSC__JSValue BrotliCompressorSink__assignToStream(JSC__JSGlobalObject* arg0, JSC__JSValue JSValue1, void* arg2, void** arg3); +CPP_DECL JSC__JSValue BrotliCompressorSink__createObject(JSC__JSGlobalObject* arg0, void* arg1); +CPP_DECL void BrotliCompressorSink__detachPtr(JSC__JSValue JSValue0); +CPP_DECL void* BrotliCompressorSink__fromJS(JSC__JSGlobalObject* arg0, JSC__JSValue JSValue1); +CPP_DECL void BrotliCompressorSink__onClose(JSC__JSValue JSValue0, JSC__JSValue JSValue1); +CPP_DECL void BrotliCompressorSink__onReady(JSC__JSValue JSValue0, JSC__JSValue JSValue1, JSC__JSValue JSValue2); + +#ifdef __cplusplus + +ZIG_DECL JSC__JSValue BrotliCompressorSink__close(JSC__JSGlobalObject* arg0, void* arg1); +ZIG_DECL JSC__JSValue BrotliCompressorSink__construct(JSC__JSGlobalObject* arg0, JSC__CallFrame* arg1); +ZIG_DECL JSC__JSValue BrotliCompressorSink__end(JSC__JSGlobalObject* arg0, JSC__CallFrame* arg1); +ZIG_DECL JSC__JSValue BrotliCompressorSink__endWithSink(void* arg0, JSC__JSGlobalObject* arg1); +ZIG_DECL void BrotliCompressorSink__finalize(void* arg0); +ZIG_DECL JSC__JSValue BrotliCompressorSink__flush(JSC__JSGlobalObject* arg0, JSC__CallFrame* arg1); +ZIG_DECL JSC__JSValue BrotliCompressorSink__start(JSC__JSGlobalObject* arg0, JSC__CallFrame* arg1); +ZIG_DECL void BrotliCompressorSink__updateRef(void* arg0, bool arg1); +ZIG_DECL JSC__JSValue BrotliCompressorSink__write(JSC__JSGlobalObject* arg0, JSC__CallFrame* arg1); + +#endif #ifdef __cplusplus diff --git a/src/bun.js/bindings/headers.zig b/src/bun.js/bindings/headers.zig index dade6c8ae..b1e19557c 100644 --- a/src/bun.js/bindings/headers.zig +++ b/src/bun.js/bindings/headers.zig @@ -379,4 +379,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 0e14fedee..32aa67a28 100644 --- a/src/bun.js/webcore/streams.zig +++ b/src/bun.js/webcore/streams.zig @@ -518,6 +518,20 @@ pub const DrainResult = union(enum) { aborted: void, }; +pub const ErrorMessage = struct { + message: bun.String = bun.String.empty, + code: bun.String = bun.String.empty, + + pub fn toJS(this: *const @This(), globalObject: *JSC.JSGlobalObject) JSValue { + defer this.message.deref(); + defer this.code.deref(); + return (JSC.SystemError{ + .message = this.message, + .code = this.code, + }).toErrorInstance(globalObject); + } +}; + pub const StreamResult = union(Tag) { owned: bun.ByteList, owned_and_done: bun.ByteList, @@ -528,6 +542,7 @@ pub const StreamResult = union(Tag) { pending: *Pending, err: Syscall.Error, done: void, + error_message: ErrorMessage, pub const Tag = enum { owned, @@ -539,6 +554,7 @@ pub const StreamResult = union(Tag) { pending, err, done, + error_message, }; pub fn slice(this: *const StreamResult) []const u8 { @@ -555,6 +571,7 @@ pub const StreamResult = union(Tag) { pending: *Writable.Pending, err: Syscall.Error, + error_message: ErrorMessage, done: void, owned: Blob.SizeType, @@ -664,6 +681,11 @@ pub const StreamResult = union(Tag) { promise_value.protect(); break :brk promise_value; }, + + .error_message => brk: { + globalThis.throwValue(this.error_message.toJS(globalThis)); + break :brk JSC.JSValue.jsUndefined(); + }, }; } }; @@ -806,6 +828,9 @@ pub const StreamResult = union(Tag) { .err => |err| { return JSC.JSPromise.rejectedPromise(globalThis, JSValue.c(err.toJS(globalThis))).asValue(globalThis); }, + .error_message => { + return JSC.JSPromise.rejectedPromise(globalThis, this.error_message.toJS(globalThis)).asValue(globalThis); + }, // false == controller.close() // undefined == noop, but we probably won't send it @@ -1896,6 +1921,382 @@ 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, + total_size: usize = 0, + + 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) { + _ = globalThis; + _ = wait; + + if (this.state) |state| { + var output_slice = this.output_buffer.ptr[0..this.output_buffer.cap]; + std.debug.assert(state.flush(&output_slice, &output_slice, &this.total_size)); + } + + 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; + while (slice.len > 0) { + this.output_buffer.ensureUnusedCapacity( + bun.default_allocator, + bun.brotli.BrotliEncoderMaxCompressedSize(slice.len), + ) catch { + return .{ .err = Syscall.Error.oom }; + }; + + var output_slice = this.output_buffer.ptr[0..this.output_buffer.cap]; + std.debug.assert(state.write(&slice, &output_slice, &this.total_size)); + slice = initial_slice; + std.debug.assert(state.flush(&slice, &output_slice, &this.total_size)); + + this.output_buffer.len = @truncate(u32, this.total_size); + } + + 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 finishing_byte_slice = this.output_buffer.ptr[0..this.output_buffer.cap]; + var finish2 = finishing_byte_slice; + finish2 = finishing_byte_slice; + _ = state.finish(null, &finishing_byte_slice, &this.total_size); + var bytes = this.output_buffer.ptr[0..this.total_size]; + state.deinit(); + this.state = null; + + this.output_buffer = .{}; + std.debug.assert(this.next == null); + this.done = true; + this.signal.close(null); + return .{ .result = JSC.ArrayBuffer.fromBytes(bytes, .ArrayBuffer).toJS(globalThis, null) }; + } + + 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, + total_size: usize = 0, + + pub fn connect(this: *BrotliDecompressorSink, signal: Signal) void { + std.debug.assert(this.reader == null); + this.signal = signal; + } + + pub fn start(this: *BrotliDecompressorSink, _: StreamStart) JSC.Node.Maybe(void) { + this.output_buffer.len = 0; + + if (this.state) |existing| { + if (existing.isUsed()) { + existing.deinit(); + this.state = null; + } + } + + if (this.state == null) { + this.state = bun.brotli.BrotliDecoderState.init(); + } + + // switch (stream_start) { + // .BrotliDecompressorSink => |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: *BrotliDecompressorSink) JSC.Node.Maybe(void) { + _ = this; + return .{ .result = {} }; + } + + pub fn flushFromJS(this: *BrotliDecompressorSink, 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: *BrotliDecompressorSink) 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) !*BrotliDecompressorSink { + var this = try allocator.create(BrotliDecompressorSink); + this.* = BrotliDecompressorSink{ + .bytes = bun.ByteList.init(&.{}), + .allocator = allocator, + .next = next, + }; + return this; + } + + pub fn construct( + this: *BrotliDecompressorSink, + allocator: std.mem.Allocator, + ) void { + this.* = BrotliDecompressorSink{ + .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; + + while (true) { + if (this.output_buffer.cap - this.output_buffer.len < this.chunk_size) { + 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]; + const res = state.write(&slice, &output_slice, &this.total_size); + this.output_buffer.len += @truncate(u32, this.total_size); + + 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" => { + const code = state.getErrorCode(); + return .{ + .error_message = .{ + .code = bun.String.static(code.code()), + .message = bun.String.static(code.message()), + }, + }; + }, + .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 }); + } + + this.output_buffer.ensureUnusedCapacity(bun.default_allocator, this.chunk_size) catch { + return .{ .err = Syscall.Error.oom }; + }; + }, + } + } + } + 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: *BrotliDecompressorSink, 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: *BrotliDecompressorSink, globalThis: *JSGlobalObject) JSValue { + return JSSink.createObject(globalThis, this); + } + + 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.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: *BrotliDecompressorSink) Sink { + return Sink.init(this); + } + + pub const JSSink = NewJSSink(@This(), "BrotliDecompressorSink"); +}; + pub fn NewJSSink(comptime SinkType: type, comptime name_: []const u8) type { return struct { sink: SinkType, |