aboutsummaryrefslogtreecommitdiff
path: root/src/bun.js/builtins
diff options
context:
space:
mode:
Diffstat (limited to 'src/bun.js/builtins')
-rw-r--r--src/bun.js/builtins/BunBuiltinNames.h261
-rw-r--r--src/bun.js/builtins/README.md30
-rw-r--r--src/bun.js/builtins/WebCoreJSBuiltinInternals.cpp114
-rw-r--r--src/bun.js/builtins/WebCoreJSBuiltins.cpp55
-rw-r--r--src/bun.js/builtins/cpp/ByteLengthQueuingStrategyBuiltins.cpp104
-rw-r--r--src/bun.js/builtins/cpp/ByteLengthQueuingStrategyBuiltins.h143
-rw-r--r--src/bun.js/builtins/cpp/CountQueuingStrategyBuiltins.cpp104
-rw-r--r--src/bun.js/builtins/cpp/CountQueuingStrategyBuiltins.h143
-rw-r--r--src/bun.js/builtins/cpp/JSBufferConstructorBuiltins.cpp105
-rw-r--r--src/bun.js/builtins/cpp/JSBufferConstructorBuiltins.h127
-rw-r--r--src/bun.js/builtins/cpp/JSBufferPrototypeBuiltins.cpp717
-rw-r--r--src/bun.js/builtins/cpp/JSBufferPrototypeBuiltins.h575
-rw-r--r--src/bun.js/builtins/cpp/JSZigGlobalObjectBuiltins.cpp105
-rw-r--r--src/bun.js/builtins/cpp/JSZigGlobalObjectBuiltins.h127
-rw-r--r--src/bun.js/builtins/cpp/ReadableByteStreamControllerBuiltins.cpp188
-rw-r--r--src/bun.js/builtins/cpp/ReadableByteStreamControllerBuiltins.h167
-rw-r--r--src/bun.js/builtins/cpp/ReadableByteStreamInternalsBuiltins.cpp958
-rw-r--r--src/bun.js/builtins/cpp/ReadableByteStreamInternalsBuiltins.h444
-rw-r--r--src/bun.js/builtins/cpp/ReadableStreamBYOBReaderBuiltins.cpp169
-rw-r--r--src/bun.js/builtins/cpp/ReadableStreamBYOBReaderBuiltins.h159
-rw-r--r--src/bun.js/builtins/cpp/ReadableStreamBYOBRequestBuiltins.cpp137
-rw-r--r--src/bun.js/builtins/cpp/ReadableStreamBYOBRequestBuiltins.h151
-rw-r--r--src/bun.js/builtins/cpp/ReadableStreamBuiltins.cpp620
-rw-r--r--src/bun.js/builtins/cpp/ReadableStreamBuiltins.h239
-rw-r--r--src/bun.js/builtins/cpp/ReadableStreamDefaultControllerBuiltins.cpp147
-rw-r--r--src/bun.js/builtins/cpp/ReadableStreamDefaultControllerBuiltins.h159
-rw-r--r--src/bun.js/builtins/cpp/ReadableStreamDefaultReaderBuiltins.cpp254
-rw-r--r--src/bun.js/builtins/cpp/ReadableStreamDefaultReaderBuiltins.h167
-rw-r--r--src/bun.js/builtins/cpp/ReadableStreamInternalsBuiltins.cpp1594
-rw-r--r--src/bun.js/builtins/cpp/ReadableStreamInternalsBuiltins.h580
-rw-r--r--src/bun.js/builtins/cpp/StreamInternalsBuiltins.cpp464
-rw-r--r--src/bun.js/builtins/cpp/StreamInternalsBuiltins.h308
-rw-r--r--src/bun.js/builtins/cpp/TransformStreamBuiltins.cpp170
-rw-r--r--src/bun.js/builtins/cpp/TransformStreamBuiltins.h143
-rw-r--r--src/bun.js/builtins/cpp/TransformStreamDefaultControllerBuiltins.cpp142
-rw-r--r--src/bun.js/builtins/cpp/TransformStreamDefaultControllerBuiltins.h159
-rw-r--r--src/bun.js/builtins/cpp/TransformStreamInternalsBuiltins.cpp492
-rw-r--r--src/bun.js/builtins/cpp/TransformStreamInternalsBuiltins.h300
-rw-r--r--src/bun.js/builtins/cpp/WebCoreJSBuiltinInternals.h74
-rw-r--r--src/bun.js/builtins/cpp/WebCoreJSBuiltins.h139
-rw-r--r--src/bun.js/builtins/cpp/WritableStreamDefaultControllerBuiltins.cpp104
-rw-r--r--src/bun.js/builtins/cpp/WritableStreamDefaultControllerBuiltins.h135
-rw-r--r--src/bun.js/builtins/cpp/WritableStreamDefaultWriterBuiltins.cpp217
-rw-r--r--src/bun.js/builtins/cpp/WritableStreamDefaultWriterBuiltins.h183
-rw-r--r--src/bun.js/builtins/cpp/WritableStreamInternalsBuiltins.cpp1183
-rw-r--r--src/bun.js/builtins/cpp/WritableStreamInternalsBuiltins.h548
-rw-r--r--src/bun.js/builtins/js/ByteLengthQueuingStrategy.js51
-rw-r--r--src/bun.js/builtins/js/CountQueuingStrategy.js50
-rw-r--r--src/bun.js/builtins/js/JSBufferConstructor.js65
-rw-r--r--src/bun.js/builtins/js/JSBufferPrototype.js303
-rw-r--r--src/bun.js/builtins/js/JSZigGlobalObject.js62
-rw-r--r--src/bun.js/builtins/js/ReadableByteStreamController.js117
-rw-r--r--src/bun.js/builtins/js/ReadableByteStreamInternals.js712
-rw-r--r--src/bun.js/builtins/js/ReadableStream.js506
-rw-r--r--src/bun.js/builtins/js/ReadableStreamBYOBReader.js102
-rw-r--r--src/bun.js/builtins/js/ReadableStreamBYOBRequest.js77
-rw-r--r--src/bun.js/builtins/js/ReadableStreamDefaultController.js82
-rw-r--r--src/bun.js/builtins/js/ReadableStreamDefaultReader.js182
-rw-r--r--src/bun.js/builtins/js/ReadableStreamInternals.js1255
-rw-r--r--src/bun.js/builtins/js/StreamInternals.js317
-rw-r--r--src/bun.js/builtins/js/TransformStream.js116
-rw-r--r--src/bun.js/builtins/js/TransformStreamDefaultController.js76
-rw-r--r--src/bun.js/builtins/js/TransformStreamInternals.js350
-rw-r--r--src/bun.js/builtins/js/WritableStreamDefaultController.js56
-rw-r--r--src/bun.js/builtins/js/WritableStreamDefaultWriter.js135
-rw-r--r--src/bun.js/builtins/js/WritableStreamInternals.js856
66 files changed, 19074 insertions, 0 deletions
diff --git a/src/bun.js/builtins/BunBuiltinNames.h b/src/bun.js/builtins/BunBuiltinNames.h
new file mode 100644
index 000000000..1b49338c0
--- /dev/null
+++ b/src/bun.js/builtins/BunBuiltinNames.h
@@ -0,0 +1,261 @@
+// clang-format off
+
+#pragma once
+
+#include "root.h"
+
+
+#include "helpers.h"
+
+#include "JavaScriptCore/BuiltinUtils.h"
+
+
+namespace WebCore {
+
+using namespace JSC;
+
+
+#if !defined(BUN_ADDITIONAL_PRIVATE_IDENTIFIERS)
+#define BUN_ADDITIONAL_PRIVATE_IDENTIFIERS(macro)
+#endif
+
+
+
+
+#define BUN_COMMON_PRIVATE_IDENTIFIERS_EACH_PROPERTY_NAME(macro) \
+ macro(AbortSignal) \
+ macro(ReadableByteStreamController) \
+ macro(ReadableStream) \
+ macro(ReadableStreamBYOBReader) \
+ macro(ReadableStreamBYOBRequest) \
+ macro(ReadableStreamDefaultController) \
+ macro(ReadableStreamDefaultReader) \
+ macro(TransformStream) \
+ macro(TransformStreamDefaultController) \
+ macro(WritableStream) \
+ macro(WritableStreamDefaultController) \
+ macro(WritableStreamDefaultWriter) \
+ macro(abortAlgorithm) \
+ macro(abortSteps) \
+ macro(addEventListener) \
+ macro(appendFromJS) \
+ macro(argv) \
+ macro(assignDirectStream) \
+ macro(associatedReadableByteStreamController) \
+ macro(autoAllocateChunkSize) \
+ macro(backpressure) \
+ macro(backpressureChangePromise) \
+ macro(basename) \
+ macro(body) \
+ macro(bunNativePtr) \
+ macro(bunNativeType) \
+ macro(byobRequest) \
+ macro(cancel) \
+ macro(cancelAlgorithm) \
+ macro(chdir) \
+ macro(cloneArrayBuffer) \
+ macro(close) \
+ macro(closeAlgorithm) \
+ macro(closeRequest) \
+ macro(closeRequested) \
+ macro(closed) \
+ macro(closedPromise) \
+ macro(closedPromiseCapability) \
+ macro(code) \
+ macro(connect) \
+ macro(consumeReadableStream) \
+ macro(controlledReadableStream) \
+ macro(controller) \
+ macro(cork) \
+ macro(createEmptyReadableStream) \
+ macro(createFIFO) \
+ macro(createNativeReadableStream) \
+ macro(createReadableStream) \
+ macro(createUninitializedArrayBuffer) \
+ macro(createWritableStreamFromInternal) \
+ macro(cwd) \
+ macro(dataView) \
+ macro(decode) \
+ macro(delimiter) \
+ macro(destroy) \
+ macro(dir) \
+ macro(direct) \
+ macro(dirname) \
+ macro(disturbed) \
+ macro(document) \
+ macro(encode) \
+ macro(encoding) \
+ macro(end) \
+ macro(errno) \
+ macro(errorSteps) \
+ macro(execArgv) \
+ macro(extname) \
+ macro(failureKind) \
+ macro(fatal) \
+ macro(fetch) \
+ macro(fetchRequest) \
+ macro(file) \
+ macro(filePath) \
+ macro(fillFromJS) \
+ macro(finishConsumingStream) \
+ macro(flush) \
+ macro(flushAlgorithm) \
+ macro(format) \
+ macro(get) \
+ macro(getInternalWritableStream) \
+ macro(handleEvent) \
+ macro(hash) \
+ macro(header) \
+ macro(highWaterMark) \
+ macro(host) \
+ macro(hostname) \
+ macro(href) \
+ macro(ignoreBOM) \
+ macro(inFlightCloseRequest) \
+ macro(inFlightWriteRequest) \
+ macro(initializeWith) \
+ macro(internalStream) \
+ macro(internalWritable) \
+ macro(isAbortSignal) \
+ macro(isAbsolute) \
+ macro(isDisturbed) \
+ macro(isPaused) \
+ macro(isSecureContext) \
+ macro(isWindows) \
+ macro(join) \
+ macro(kind) \
+ macro(lazy) \
+ macro(lazyStreamPrototypeMap) \
+ macro(lazyLoad) \
+ macro(localStreams) \
+ macro(makeDOMException) \
+ macro(makeGetterTypeError) \
+ macro(makeThisTypeError) \
+ macro(map) \
+ macro(nextTick) \
+ macro(normalize) \
+ macro(on) \
+ macro(once) \
+ macro(options) \
+ macro(origin) \
+ macro(ownerReadableStream) \
+ macro(parse) \
+ macro(password) \
+ macro(patch) \
+ macro(path) \
+ macro(pathname) \
+ macro(pause) \
+ macro(pendingAbortRequest) \
+ macro(pendingPullIntos) \
+ macro(pid) \
+ macro(pipe) \
+ macro(port) \
+ macro(post) \
+ macro(ppid) \
+ macro(prependEventListener) \
+ macro(process) \
+ macro(protocol) \
+ macro(pull) \
+ macro(pullAgain) \
+ macro(pullAlgorithm) \
+ macro(pulling) \
+ macro(put) \
+ macro(queue) \
+ macro(read) \
+ macro(readIntoRequests) \
+ macro(readRequests) \
+ macro(readable) \
+ macro(readableStreamController) \
+ macro(readableStreamToArray) \
+ macro(reader) \
+ macro(readyPromise) \
+ macro(readyPromiseCapability) \
+ macro(relative) \
+ macro(releaseLock) \
+ macro(removeEventListener) \
+ macro(require) \
+ macro(resolve) \
+ macro(resolveSync) \
+ macro(resume) \
+ macro(search) \
+ macro(searchParams) \
+ macro(self) \
+ macro(sep) \
+ macro(setBody) \
+ macro(setStatus) \
+ macro(sink) \
+ macro(size) \
+ macro(start) \
+ macro(startAlgorithm) \
+ macro(startConsumingStream) \
+ macro(startDirectStream) \
+ macro(started) \
+ macro(startedPromise) \
+ macro(state) \
+ macro(storedError) \
+ macro(strategy) \
+ macro(strategyHWM) \
+ macro(strategySizeAlgorithm) \
+ macro(stream) \
+ macro(streamClosed) \
+ macro(streamClosing) \
+ macro(streamErrored) \
+ macro(streamReadable) \
+ macro(streamWaiting) \
+ macro(streamWritable) \
+ macro(structuredCloneForStream) \
+ macro(syscall) \
+ macro(textDecoderStreamDecoder) \
+ macro(textDecoderStreamTransform) \
+ macro(textEncoderStreamEncoder) \
+ macro(textEncoderStreamTransform) \
+ macro(toNamespacedPath) \
+ macro(trace) \
+ macro(transformAlgorithm) \
+ macro(uncork) \
+ macro(underlyingByteSource) \
+ macro(underlyingSink) \
+ macro(underlyingSource) \
+ macro(unpipe) \
+ macro(unshift) \
+ macro(url) \
+ macro(username) \
+ macro(version) \
+ macro(versions) \
+ macro(view) \
+ macro(whenSignalAborted) \
+ macro(writable) \
+ macro(write) \
+ macro(writeAlgorithm) \
+ macro(writeRequests) \
+ macro(writer) \
+ macro(writing) \
+ BUN_ADDITIONAL_PRIVATE_IDENTIFIERS(macro) \
+
+class BunBuiltinNames {
+public:
+ // FIXME: Remove the __attribute__((nodebug)) when <rdar://68246686> is fixed.
+#if COMPILER(CLANG)
+ __attribute__((nodebug))
+#endif
+ explicit BunBuiltinNames(JSC::VM& vm)
+ : m_vm(vm)
+ BUN_COMMON_PRIVATE_IDENTIFIERS_EACH_PROPERTY_NAME(INITIALIZE_BUILTIN_NAMES)
+ {
+#define EXPORT_NAME(name) m_vm.propertyNames->appendExternalName(name##PublicName(), name##PrivateName());
+ BUN_COMMON_PRIVATE_IDENTIFIERS_EACH_PROPERTY_NAME(EXPORT_NAME)
+#undef EXPORT_NAME
+ }
+
+
+ BUN_COMMON_PRIVATE_IDENTIFIERS_EACH_PROPERTY_NAME(DECLARE_BUILTIN_IDENTIFIER_ACCESSOR)
+
+private:
+ JSC::VM& m_vm;
+ BUN_COMMON_PRIVATE_IDENTIFIERS_EACH_PROPERTY_NAME(DECLARE_BUILTIN_NAMES)
+};
+
+
+
+} // namespace WebCore
+
diff --git a/src/bun.js/builtins/README.md b/src/bun.js/builtins/README.md
new file mode 100644
index 000000000..8ec32e8b5
--- /dev/null
+++ b/src/bun.js/builtins/README.md
@@ -0,0 +1,30 @@
+# JavaScript Builtins
+
+JavaScript files in [./js](./js) use JavaScriptCore's builtins syntax
+
+```js
+@getter
+function foo() {
+ return @getByIdDirectPrivate(this, "superSecret");
+}
+```
+
+It looks kind of like decorators but they're not. They let you directly call engine intrinsics and help with avoiding prototype pollution issues.
+
+V8 has a [similar feature](https://v8.dev/blog/embedded-builtins) (they use `%` instead of `@`)
+
+They usually are accompanied by a C++ file.
+
+The `js` directory is necessary for the bindings generator to work.
+
+To regenerate the builtins, run this from Bun's project root (where the `Makefile` is)
+
+```bash
+make generate-builtins
+```
+
+You'll want to also rebuild all the C++ bindings or you will get strange crashes on start
+
+```bash
+make clean-bindings
+```
diff --git a/src/bun.js/builtins/WebCoreJSBuiltinInternals.cpp b/src/bun.js/builtins/WebCoreJSBuiltinInternals.cpp
new file mode 100644
index 000000000..159e2f45b
--- /dev/null
+++ b/src/bun.js/builtins/WebCoreJSBuiltinInternals.cpp
@@ -0,0 +1,114 @@
+/*
+ * Copyright (c) 2015 Igalia
+ * Copyright (c) 2015 Igalia S.L.
+ * Copyright (c) 2015 Igalia.
+ * Copyright (c) 2015, 2016 Canon Inc. All rights reserved.
+ * Copyright (c) 2015, 2016, 2017 Canon Inc.
+ * Copyright (c) 2016, 2020 Apple Inc. All rights reserved.
+ * Copyright (c) 2022 Codeblog Corp. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+// DO NOT EDIT THIS FILE. It is automatically generated from JavaScript files for
+// builtins by the script: Source/JavaScriptCore/Scripts/generate-js-builtins.py
+
+#include "config.h"
+#include "WebCoreJSBuiltinInternals.h"
+
+#include "JSDOMGlobalObject.h"
+#include "WebCoreJSClientData.h"
+#include <JavaScriptCore/HeapInlines.h>
+#include <JavaScriptCore/JSCJSValueInlines.h>
+#include <JavaScriptCore/SlotVisitorInlines.h>
+#include <JavaScriptCore/StructureInlines.h>
+
+namespace WebCore {
+
+JSBuiltinInternalFunctions::JSBuiltinInternalFunctions(JSC::VM& vm)
+ : m_vm(vm)
+ , m_readableByteStreamInternals(m_vm)
+ , m_readableStreamInternals(m_vm)
+ , m_streamInternals(m_vm)
+ , m_transformStreamInternals(m_vm)
+ , m_writableStreamInternals(m_vm)
+{
+ UNUSED_PARAM(vm);
+}
+
+template<typename Visitor>
+void JSBuiltinInternalFunctions::visit(Visitor& visitor)
+{
+ m_readableByteStreamInternals.visit(visitor);
+ m_readableStreamInternals.visit(visitor);
+ m_streamInternals.visit(visitor);
+ m_transformStreamInternals.visit(visitor);
+ m_writableStreamInternals.visit(visitor);
+ UNUSED_PARAM(visitor);
+}
+
+template void JSBuiltinInternalFunctions::visit(AbstractSlotVisitor&);
+template void JSBuiltinInternalFunctions::visit(SlotVisitor&);
+
+SUPPRESS_ASAN void JSBuiltinInternalFunctions::initialize(JSDOMGlobalObject& globalObject)
+{
+ UNUSED_PARAM(globalObject);
+ m_readableByteStreamInternals.init(globalObject);
+ m_readableStreamInternals.init(globalObject);
+ m_streamInternals.init(globalObject);
+ m_transformStreamInternals.init(globalObject);
+ m_writableStreamInternals.init(globalObject);
+
+ JSVMClientData& clientData = *static_cast<JSVMClientData*>(m_vm.clientData);
+ JSDOMGlobalObject::GlobalPropertyInfo staticGlobals[] = {
+#define DECLARE_GLOBAL_STATIC(name) \
+ JSDOMGlobalObject::GlobalPropertyInfo( \
+ clientData.builtinFunctions().readableByteStreamInternalsBuiltins().name##PrivateName(), readableByteStreamInternals().m_##name##Function.get() , JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly),
+ WEBCORE_FOREACH_READABLEBYTESTREAMINTERNALS_BUILTIN_FUNCTION_NAME(DECLARE_GLOBAL_STATIC)
+#undef DECLARE_GLOBAL_STATIC
+#define DECLARE_GLOBAL_STATIC(name) \
+ JSDOMGlobalObject::GlobalPropertyInfo( \
+ clientData.builtinFunctions().readableStreamInternalsBuiltins().name##PrivateName(), readableStreamInternals().m_##name##Function.get() , JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly),
+ WEBCORE_FOREACH_READABLESTREAMINTERNALS_BUILTIN_FUNCTION_NAME(DECLARE_GLOBAL_STATIC)
+#undef DECLARE_GLOBAL_STATIC
+#define DECLARE_GLOBAL_STATIC(name) \
+ JSDOMGlobalObject::GlobalPropertyInfo( \
+ clientData.builtinFunctions().streamInternalsBuiltins().name##PrivateName(), streamInternals().m_##name##Function.get() , JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly),
+ WEBCORE_FOREACH_STREAMINTERNALS_BUILTIN_FUNCTION_NAME(DECLARE_GLOBAL_STATIC)
+#undef DECLARE_GLOBAL_STATIC
+#define DECLARE_GLOBAL_STATIC(name) \
+ JSDOMGlobalObject::GlobalPropertyInfo( \
+ clientData.builtinFunctions().transformStreamInternalsBuiltins().name##PrivateName(), transformStreamInternals().m_##name##Function.get() , JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly),
+ WEBCORE_FOREACH_TRANSFORMSTREAMINTERNALS_BUILTIN_FUNCTION_NAME(DECLARE_GLOBAL_STATIC)
+#undef DECLARE_GLOBAL_STATIC
+#define DECLARE_GLOBAL_STATIC(name) \
+ JSDOMGlobalObject::GlobalPropertyInfo( \
+ clientData.builtinFunctions().writableStreamInternalsBuiltins().name##PrivateName(), writableStreamInternals().m_##name##Function.get() , JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly),
+ WEBCORE_FOREACH_WRITABLESTREAMINTERNALS_BUILTIN_FUNCTION_NAME(DECLARE_GLOBAL_STATIC)
+#undef DECLARE_GLOBAL_STATIC
+ };
+ globalObject.addStaticGlobals(staticGlobals, WTF_ARRAY_LENGTH(staticGlobals));
+ UNUSED_PARAM(clientData);
+}
+
+} // namespace WebCore
diff --git a/src/bun.js/builtins/WebCoreJSBuiltins.cpp b/src/bun.js/builtins/WebCoreJSBuiltins.cpp
new file mode 100644
index 000000000..00cde9f54
--- /dev/null
+++ b/src/bun.js/builtins/WebCoreJSBuiltins.cpp
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 2015 Igalia
+ * Copyright (c) 2015 Igalia S.L.
+ * Copyright (c) 2015 Igalia.
+ * Copyright (c) 2015, 2016 Canon Inc. All rights reserved.
+ * Copyright (c) 2015, 2016, 2017 Canon Inc.
+ * Copyright (c) 2016, 2020 Apple Inc. All rights reserved.
+ * Copyright (c) 2022 Codeblog Corp. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+// DO NOT EDIT THIS FILE. It is automatically generated from JavaScript files for
+// builtins by the script: Source/JavaScriptCore/Scripts/generate-js-builtins.py
+
+#include "ByteLengthQueuingStrategyBuiltins.cpp"
+#include "CountQueuingStrategyBuiltins.cpp"
+#include "JSBufferConstructorBuiltins.cpp"
+#include "JSBufferPrototypeBuiltins.cpp"
+#include "JSZigGlobalObjectBuiltins.cpp"
+#include "ReadableByteStreamControllerBuiltins.cpp"
+#include "ReadableByteStreamInternalsBuiltins.cpp"
+#include "ReadableStreamBYOBReaderBuiltins.cpp"
+#include "ReadableStreamBYOBRequestBuiltins.cpp"
+#include "ReadableStreamBuiltins.cpp"
+#include "ReadableStreamDefaultControllerBuiltins.cpp"
+#include "ReadableStreamDefaultReaderBuiltins.cpp"
+#include "ReadableStreamInternalsBuiltins.cpp"
+#include "StreamInternalsBuiltins.cpp"
+#include "TransformStreamBuiltins.cpp"
+#include "TransformStreamDefaultControllerBuiltins.cpp"
+#include "TransformStreamInternalsBuiltins.cpp"
+#include "WritableStreamDefaultControllerBuiltins.cpp"
+#include "WritableStreamDefaultWriterBuiltins.cpp"
+#include "WritableStreamInternalsBuiltins.cpp"
diff --git a/src/bun.js/builtins/cpp/ByteLengthQueuingStrategyBuiltins.cpp b/src/bun.js/builtins/cpp/ByteLengthQueuingStrategyBuiltins.cpp
new file mode 100644
index 000000000..320cba7da
--- /dev/null
+++ b/src/bun.js/builtins/cpp/ByteLengthQueuingStrategyBuiltins.cpp
@@ -0,0 +1,104 @@
+/*
+ * Copyright (c) 2015 Igalia
+ * Copyright (c) 2015 Igalia S.L.
+ * Copyright (c) 2015 Igalia.
+ * Copyright (c) 2015, 2016 Canon Inc. All rights reserved.
+ * Copyright (c) 2015, 2016, 2017 Canon Inc.
+ * Copyright (c) 2016, 2020 Apple Inc. All rights reserved.
+ * Copyright (c) 2022 Codeblog Corp. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+// DO NOT EDIT THIS FILE. It is automatically generated from JavaScript files for
+// builtins by the script: Source/JavaScriptCore/Scripts/generate-js-builtins.py
+
+#include "config.h"
+#include "ByteLengthQueuingStrategyBuiltins.h"
+
+#include "WebCoreJSClientData.h"
+#include <JavaScriptCore/HeapInlines.h>
+#include <JavaScriptCore/IdentifierInlines.h>
+#include <JavaScriptCore/Intrinsic.h>
+#include <JavaScriptCore/JSCJSValueInlines.h>
+#include <JavaScriptCore/JSCellInlines.h>
+#include <JavaScriptCore/StructureInlines.h>
+#include <JavaScriptCore/VM.h>
+
+namespace WebCore {
+
+const JSC::ConstructAbility s_byteLengthQueuingStrategyHighWaterMarkCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_byteLengthQueuingStrategyHighWaterMarkCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_byteLengthQueuingStrategyHighWaterMarkCodeLength = 286;
+static const JSC::Intrinsic s_byteLengthQueuingStrategyHighWaterMarkCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_byteLengthQueuingStrategyHighWaterMarkCode =
+ "(function ()\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " const highWaterMark = @getByIdDirectPrivate(this, \"highWaterMark\");\n" \
+ " if (highWaterMark === @undefined)\n" \
+ " @throwTypeError(\"ByteLengthQueuingStrategy.highWaterMark getter called on incompatible |this| value.\");\n" \
+ "\n" \
+ " return highWaterMark;\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_byteLengthQueuingStrategySizeCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_byteLengthQueuingStrategySizeCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_byteLengthQueuingStrategySizeCodeLength = 71;
+static const JSC::Intrinsic s_byteLengthQueuingStrategySizeCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_byteLengthQueuingStrategySizeCode =
+ "(function (chunk)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " return chunk.byteLength;\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_byteLengthQueuingStrategyInitializeByteLengthQueuingStrategyCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_byteLengthQueuingStrategyInitializeByteLengthQueuingStrategyCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_byteLengthQueuingStrategyInitializeByteLengthQueuingStrategyCodeLength = 155;
+static const JSC::Intrinsic s_byteLengthQueuingStrategyInitializeByteLengthQueuingStrategyCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_byteLengthQueuingStrategyInitializeByteLengthQueuingStrategyCode =
+ "(function (parameters)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " @putByIdDirectPrivate(this, \"highWaterMark\", @extractHighWaterMarkFromQueuingStrategyInit(parameters));\n" \
+ "})\n" \
+;
+
+
+#define DEFINE_BUILTIN_GENERATOR(codeName, functionName, overriddenName, argumentCount) \
+JSC::FunctionExecutable* codeName##Generator(JSC::VM& vm) \
+{\
+ JSVMClientData* clientData = static_cast<JSVMClientData*>(vm.clientData); \
+ return clientData->builtinFunctions().byteLengthQueuingStrategyBuiltins().codeName##Executable()->link(vm, nullptr, clientData->builtinFunctions().byteLengthQueuingStrategyBuiltins().codeName##Source(), std::nullopt, s_##codeName##Intrinsic); \
+}
+WEBCORE_FOREACH_BYTELENGTHQUEUINGSTRATEGY_BUILTIN_CODE(DEFINE_BUILTIN_GENERATOR)
+#undef DEFINE_BUILTIN_GENERATOR
+
+
+} // namespace WebCore
diff --git a/src/bun.js/builtins/cpp/ByteLengthQueuingStrategyBuiltins.h b/src/bun.js/builtins/cpp/ByteLengthQueuingStrategyBuiltins.h
new file mode 100644
index 000000000..964ce15af
--- /dev/null
+++ b/src/bun.js/builtins/cpp/ByteLengthQueuingStrategyBuiltins.h
@@ -0,0 +1,143 @@
+/*
+ * Copyright (c) 2015 Igalia
+ * Copyright (c) 2015 Igalia S.L.
+ * Copyright (c) 2015 Igalia.
+ * Copyright (c) 2015, 2016 Canon Inc. All rights reserved.
+ * Copyright (c) 2015, 2016, 2017 Canon Inc.
+ * Copyright (c) 2016, 2020 Apple Inc. All rights reserved.
+ * Copyright (c) 2022 Codeblog Corp. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+// DO NOT EDIT THIS FILE. It is automatically generated from JavaScript files for
+// builtins by the script: Source/JavaScriptCore/Scripts/generate-js-builtins.py
+
+#pragma once
+
+#include <JavaScriptCore/BuiltinUtils.h>
+#include <JavaScriptCore/Identifier.h>
+#include <JavaScriptCore/JSFunction.h>
+#include <JavaScriptCore/UnlinkedFunctionExecutable.h>
+
+namespace JSC {
+class FunctionExecutable;
+}
+
+namespace WebCore {
+
+/* ByteLengthQueuingStrategy */
+extern const char* const s_byteLengthQueuingStrategyHighWaterMarkCode;
+extern const int s_byteLengthQueuingStrategyHighWaterMarkCodeLength;
+extern const JSC::ConstructAbility s_byteLengthQueuingStrategyHighWaterMarkCodeConstructAbility;
+extern const JSC::ConstructorKind s_byteLengthQueuingStrategyHighWaterMarkCodeConstructorKind;
+extern const char* const s_byteLengthQueuingStrategySizeCode;
+extern const int s_byteLengthQueuingStrategySizeCodeLength;
+extern const JSC::ConstructAbility s_byteLengthQueuingStrategySizeCodeConstructAbility;
+extern const JSC::ConstructorKind s_byteLengthQueuingStrategySizeCodeConstructorKind;
+extern const char* const s_byteLengthQueuingStrategyInitializeByteLengthQueuingStrategyCode;
+extern const int s_byteLengthQueuingStrategyInitializeByteLengthQueuingStrategyCodeLength;
+extern const JSC::ConstructAbility s_byteLengthQueuingStrategyInitializeByteLengthQueuingStrategyCodeConstructAbility;
+extern const JSC::ConstructorKind s_byteLengthQueuingStrategyInitializeByteLengthQueuingStrategyCodeConstructorKind;
+
+#define WEBCORE_FOREACH_BYTELENGTHQUEUINGSTRATEGY_BUILTIN_DATA(macro) \
+ macro(highWaterMark, byteLengthQueuingStrategyHighWaterMark, 0) \
+ macro(size, byteLengthQueuingStrategySize, 1) \
+ macro(initializeByteLengthQueuingStrategy, byteLengthQueuingStrategyInitializeByteLengthQueuingStrategy, 1) \
+
+#define WEBCORE_BUILTIN_BYTELENGTHQUEUINGSTRATEGY_HIGHWATERMARK 1
+#define WEBCORE_BUILTIN_BYTELENGTHQUEUINGSTRATEGY_SIZE 1
+#define WEBCORE_BUILTIN_BYTELENGTHQUEUINGSTRATEGY_INITIALIZEBYTELENGTHQUEUINGSTRATEGY 1
+
+#define WEBCORE_FOREACH_BYTELENGTHQUEUINGSTRATEGY_BUILTIN_CODE(macro) \
+ macro(byteLengthQueuingStrategyHighWaterMarkCode, highWaterMark, "get highWaterMark"_s, s_byteLengthQueuingStrategyHighWaterMarkCodeLength) \
+ macro(byteLengthQueuingStrategySizeCode, size, ASCIILiteral(), s_byteLengthQueuingStrategySizeCodeLength) \
+ macro(byteLengthQueuingStrategyInitializeByteLengthQueuingStrategyCode, initializeByteLengthQueuingStrategy, ASCIILiteral(), s_byteLengthQueuingStrategyInitializeByteLengthQueuingStrategyCodeLength) \
+
+#define WEBCORE_FOREACH_BYTELENGTHQUEUINGSTRATEGY_BUILTIN_FUNCTION_NAME(macro) \
+ macro(highWaterMark) \
+ macro(initializeByteLengthQueuingStrategy) \
+ macro(size) \
+
+#define DECLARE_BUILTIN_GENERATOR(codeName, functionName, overriddenName, argumentCount) \
+ JSC::FunctionExecutable* codeName##Generator(JSC::VM&);
+
+WEBCORE_FOREACH_BYTELENGTHQUEUINGSTRATEGY_BUILTIN_CODE(DECLARE_BUILTIN_GENERATOR)
+#undef DECLARE_BUILTIN_GENERATOR
+
+class ByteLengthQueuingStrategyBuiltinsWrapper : private JSC::WeakHandleOwner {
+public:
+ explicit ByteLengthQueuingStrategyBuiltinsWrapper(JSC::VM& vm)
+ : m_vm(vm)
+ WEBCORE_FOREACH_BYTELENGTHQUEUINGSTRATEGY_BUILTIN_FUNCTION_NAME(INITIALIZE_BUILTIN_NAMES)
+#define INITIALIZE_BUILTIN_SOURCE_MEMBERS(name, functionName, overriddenName, length) , m_##name##Source(JSC::makeSource(StringImpl::createWithoutCopying(s_##name, length), { }))
+ WEBCORE_FOREACH_BYTELENGTHQUEUINGSTRATEGY_BUILTIN_CODE(INITIALIZE_BUILTIN_SOURCE_MEMBERS)
+#undef INITIALIZE_BUILTIN_SOURCE_MEMBERS
+ {
+ }
+
+#define EXPOSE_BUILTIN_EXECUTABLES(name, functionName, overriddenName, length) \
+ JSC::UnlinkedFunctionExecutable* name##Executable(); \
+ const JSC::SourceCode& name##Source() const { return m_##name##Source; }
+ WEBCORE_FOREACH_BYTELENGTHQUEUINGSTRATEGY_BUILTIN_CODE(EXPOSE_BUILTIN_EXECUTABLES)
+#undef EXPOSE_BUILTIN_EXECUTABLES
+
+ WEBCORE_FOREACH_BYTELENGTHQUEUINGSTRATEGY_BUILTIN_FUNCTION_NAME(DECLARE_BUILTIN_IDENTIFIER_ACCESSOR)
+
+ void exportNames();
+
+private:
+ JSC::VM& m_vm;
+
+ WEBCORE_FOREACH_BYTELENGTHQUEUINGSTRATEGY_BUILTIN_FUNCTION_NAME(DECLARE_BUILTIN_NAMES)
+
+#define DECLARE_BUILTIN_SOURCE_MEMBERS(name, functionName, overriddenName, length) \
+ JSC::SourceCode m_##name##Source;\
+ JSC::Weak<JSC::UnlinkedFunctionExecutable> m_##name##Executable;
+ WEBCORE_FOREACH_BYTELENGTHQUEUINGSTRATEGY_BUILTIN_CODE(DECLARE_BUILTIN_SOURCE_MEMBERS)
+#undef DECLARE_BUILTIN_SOURCE_MEMBERS
+
+};
+
+#define DEFINE_BUILTIN_EXECUTABLES(name, functionName, overriddenName, length) \
+inline JSC::UnlinkedFunctionExecutable* ByteLengthQueuingStrategyBuiltinsWrapper::name##Executable() \
+{\
+ if (!m_##name##Executable) {\
+ JSC::Identifier executableName = functionName##PublicName();\
+ if (overriddenName)\
+ executableName = JSC::Identifier::fromString(m_vm, overriddenName);\
+ m_##name##Executable = JSC::Weak<JSC::UnlinkedFunctionExecutable>(JSC::createBuiltinExecutable(m_vm, m_##name##Source, executableName, s_##name##ConstructorKind, s_##name##ConstructAbility), this, &m_##name##Executable);\
+ }\
+ return m_##name##Executable.get();\
+}
+WEBCORE_FOREACH_BYTELENGTHQUEUINGSTRATEGY_BUILTIN_CODE(DEFINE_BUILTIN_EXECUTABLES)
+#undef DEFINE_BUILTIN_EXECUTABLES
+
+inline void ByteLengthQueuingStrategyBuiltinsWrapper::exportNames()
+{
+#define EXPORT_FUNCTION_NAME(name) m_vm.propertyNames->appendExternalName(name##PublicName(), name##PrivateName());
+ WEBCORE_FOREACH_BYTELENGTHQUEUINGSTRATEGY_BUILTIN_FUNCTION_NAME(EXPORT_FUNCTION_NAME)
+#undef EXPORT_FUNCTION_NAME
+}
+
+} // namespace WebCore
diff --git a/src/bun.js/builtins/cpp/CountQueuingStrategyBuiltins.cpp b/src/bun.js/builtins/cpp/CountQueuingStrategyBuiltins.cpp
new file mode 100644
index 000000000..1a7100f00
--- /dev/null
+++ b/src/bun.js/builtins/cpp/CountQueuingStrategyBuiltins.cpp
@@ -0,0 +1,104 @@
+/*
+ * Copyright (c) 2015 Igalia
+ * Copyright (c) 2015 Igalia S.L.
+ * Copyright (c) 2015 Igalia.
+ * Copyright (c) 2015, 2016 Canon Inc. All rights reserved.
+ * Copyright (c) 2015, 2016, 2017 Canon Inc.
+ * Copyright (c) 2016, 2020 Apple Inc. All rights reserved.
+ * Copyright (c) 2022 Codeblog Corp. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+// DO NOT EDIT THIS FILE. It is automatically generated from JavaScript files for
+// builtins by the script: Source/JavaScriptCore/Scripts/generate-js-builtins.py
+
+#include "config.h"
+#include "CountQueuingStrategyBuiltins.h"
+
+#include "WebCoreJSClientData.h"
+#include <JavaScriptCore/HeapInlines.h>
+#include <JavaScriptCore/IdentifierInlines.h>
+#include <JavaScriptCore/Intrinsic.h>
+#include <JavaScriptCore/JSCJSValueInlines.h>
+#include <JavaScriptCore/JSCellInlines.h>
+#include <JavaScriptCore/StructureInlines.h>
+#include <JavaScriptCore/VM.h>
+
+namespace WebCore {
+
+const JSC::ConstructAbility s_countQueuingStrategyHighWaterMarkCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_countQueuingStrategyHighWaterMarkCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_countQueuingStrategyHighWaterMarkCodeLength = 281;
+static const JSC::Intrinsic s_countQueuingStrategyHighWaterMarkCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_countQueuingStrategyHighWaterMarkCode =
+ "(function ()\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " const highWaterMark = @getByIdDirectPrivate(this, \"highWaterMark\");\n" \
+ " if (highWaterMark === @undefined)\n" \
+ " @throwTypeError(\"CountQueuingStrategy.highWaterMark getter called on incompatible |this| value.\");\n" \
+ "\n" \
+ " return highWaterMark;\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_countQueuingStrategySizeCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_countQueuingStrategySizeCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_countQueuingStrategySizeCodeLength = 51;
+static const JSC::Intrinsic s_countQueuingStrategySizeCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_countQueuingStrategySizeCode =
+ "(function ()\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " return 1;\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_countQueuingStrategyInitializeCountQueuingStrategyCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_countQueuingStrategyInitializeCountQueuingStrategyCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_countQueuingStrategyInitializeCountQueuingStrategyCodeLength = 155;
+static const JSC::Intrinsic s_countQueuingStrategyInitializeCountQueuingStrategyCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_countQueuingStrategyInitializeCountQueuingStrategyCode =
+ "(function (parameters)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " @putByIdDirectPrivate(this, \"highWaterMark\", @extractHighWaterMarkFromQueuingStrategyInit(parameters));\n" \
+ "})\n" \
+;
+
+
+#define DEFINE_BUILTIN_GENERATOR(codeName, functionName, overriddenName, argumentCount) \
+JSC::FunctionExecutable* codeName##Generator(JSC::VM& vm) \
+{\
+ JSVMClientData* clientData = static_cast<JSVMClientData*>(vm.clientData); \
+ return clientData->builtinFunctions().countQueuingStrategyBuiltins().codeName##Executable()->link(vm, nullptr, clientData->builtinFunctions().countQueuingStrategyBuiltins().codeName##Source(), std::nullopt, s_##codeName##Intrinsic); \
+}
+WEBCORE_FOREACH_COUNTQUEUINGSTRATEGY_BUILTIN_CODE(DEFINE_BUILTIN_GENERATOR)
+#undef DEFINE_BUILTIN_GENERATOR
+
+
+} // namespace WebCore
diff --git a/src/bun.js/builtins/cpp/CountQueuingStrategyBuiltins.h b/src/bun.js/builtins/cpp/CountQueuingStrategyBuiltins.h
new file mode 100644
index 000000000..3805d0873
--- /dev/null
+++ b/src/bun.js/builtins/cpp/CountQueuingStrategyBuiltins.h
@@ -0,0 +1,143 @@
+/*
+ * Copyright (c) 2015 Igalia
+ * Copyright (c) 2015 Igalia S.L.
+ * Copyright (c) 2015 Igalia.
+ * Copyright (c) 2015, 2016 Canon Inc. All rights reserved.
+ * Copyright (c) 2015, 2016, 2017 Canon Inc.
+ * Copyright (c) 2016, 2020 Apple Inc. All rights reserved.
+ * Copyright (c) 2022 Codeblog Corp. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+// DO NOT EDIT THIS FILE. It is automatically generated from JavaScript files for
+// builtins by the script: Source/JavaScriptCore/Scripts/generate-js-builtins.py
+
+#pragma once
+
+#include <JavaScriptCore/BuiltinUtils.h>
+#include <JavaScriptCore/Identifier.h>
+#include <JavaScriptCore/JSFunction.h>
+#include <JavaScriptCore/UnlinkedFunctionExecutable.h>
+
+namespace JSC {
+class FunctionExecutable;
+}
+
+namespace WebCore {
+
+/* CountQueuingStrategy */
+extern const char* const s_countQueuingStrategyHighWaterMarkCode;
+extern const int s_countQueuingStrategyHighWaterMarkCodeLength;
+extern const JSC::ConstructAbility s_countQueuingStrategyHighWaterMarkCodeConstructAbility;
+extern const JSC::ConstructorKind s_countQueuingStrategyHighWaterMarkCodeConstructorKind;
+extern const char* const s_countQueuingStrategySizeCode;
+extern const int s_countQueuingStrategySizeCodeLength;
+extern const JSC::ConstructAbility s_countQueuingStrategySizeCodeConstructAbility;
+extern const JSC::ConstructorKind s_countQueuingStrategySizeCodeConstructorKind;
+extern const char* const s_countQueuingStrategyInitializeCountQueuingStrategyCode;
+extern const int s_countQueuingStrategyInitializeCountQueuingStrategyCodeLength;
+extern const JSC::ConstructAbility s_countQueuingStrategyInitializeCountQueuingStrategyCodeConstructAbility;
+extern const JSC::ConstructorKind s_countQueuingStrategyInitializeCountQueuingStrategyCodeConstructorKind;
+
+#define WEBCORE_FOREACH_COUNTQUEUINGSTRATEGY_BUILTIN_DATA(macro) \
+ macro(highWaterMark, countQueuingStrategyHighWaterMark, 0) \
+ macro(size, countQueuingStrategySize, 0) \
+ macro(initializeCountQueuingStrategy, countQueuingStrategyInitializeCountQueuingStrategy, 1) \
+
+#define WEBCORE_BUILTIN_COUNTQUEUINGSTRATEGY_HIGHWATERMARK 1
+#define WEBCORE_BUILTIN_COUNTQUEUINGSTRATEGY_SIZE 1
+#define WEBCORE_BUILTIN_COUNTQUEUINGSTRATEGY_INITIALIZECOUNTQUEUINGSTRATEGY 1
+
+#define WEBCORE_FOREACH_COUNTQUEUINGSTRATEGY_BUILTIN_CODE(macro) \
+ macro(countQueuingStrategyHighWaterMarkCode, highWaterMark, "get highWaterMark"_s, s_countQueuingStrategyHighWaterMarkCodeLength) \
+ macro(countQueuingStrategySizeCode, size, ASCIILiteral(), s_countQueuingStrategySizeCodeLength) \
+ macro(countQueuingStrategyInitializeCountQueuingStrategyCode, initializeCountQueuingStrategy, ASCIILiteral(), s_countQueuingStrategyInitializeCountQueuingStrategyCodeLength) \
+
+#define WEBCORE_FOREACH_COUNTQUEUINGSTRATEGY_BUILTIN_FUNCTION_NAME(macro) \
+ macro(highWaterMark) \
+ macro(initializeCountQueuingStrategy) \
+ macro(size) \
+
+#define DECLARE_BUILTIN_GENERATOR(codeName, functionName, overriddenName, argumentCount) \
+ JSC::FunctionExecutable* codeName##Generator(JSC::VM&);
+
+WEBCORE_FOREACH_COUNTQUEUINGSTRATEGY_BUILTIN_CODE(DECLARE_BUILTIN_GENERATOR)
+#undef DECLARE_BUILTIN_GENERATOR
+
+class CountQueuingStrategyBuiltinsWrapper : private JSC::WeakHandleOwner {
+public:
+ explicit CountQueuingStrategyBuiltinsWrapper(JSC::VM& vm)
+ : m_vm(vm)
+ WEBCORE_FOREACH_COUNTQUEUINGSTRATEGY_BUILTIN_FUNCTION_NAME(INITIALIZE_BUILTIN_NAMES)
+#define INITIALIZE_BUILTIN_SOURCE_MEMBERS(name, functionName, overriddenName, length) , m_##name##Source(JSC::makeSource(StringImpl::createWithoutCopying(s_##name, length), { }))
+ WEBCORE_FOREACH_COUNTQUEUINGSTRATEGY_BUILTIN_CODE(INITIALIZE_BUILTIN_SOURCE_MEMBERS)
+#undef INITIALIZE_BUILTIN_SOURCE_MEMBERS
+ {
+ }
+
+#define EXPOSE_BUILTIN_EXECUTABLES(name, functionName, overriddenName, length) \
+ JSC::UnlinkedFunctionExecutable* name##Executable(); \
+ const JSC::SourceCode& name##Source() const { return m_##name##Source; }
+ WEBCORE_FOREACH_COUNTQUEUINGSTRATEGY_BUILTIN_CODE(EXPOSE_BUILTIN_EXECUTABLES)
+#undef EXPOSE_BUILTIN_EXECUTABLES
+
+ WEBCORE_FOREACH_COUNTQUEUINGSTRATEGY_BUILTIN_FUNCTION_NAME(DECLARE_BUILTIN_IDENTIFIER_ACCESSOR)
+
+ void exportNames();
+
+private:
+ JSC::VM& m_vm;
+
+ WEBCORE_FOREACH_COUNTQUEUINGSTRATEGY_BUILTIN_FUNCTION_NAME(DECLARE_BUILTIN_NAMES)
+
+#define DECLARE_BUILTIN_SOURCE_MEMBERS(name, functionName, overriddenName, length) \
+ JSC::SourceCode m_##name##Source;\
+ JSC::Weak<JSC::UnlinkedFunctionExecutable> m_##name##Executable;
+ WEBCORE_FOREACH_COUNTQUEUINGSTRATEGY_BUILTIN_CODE(DECLARE_BUILTIN_SOURCE_MEMBERS)
+#undef DECLARE_BUILTIN_SOURCE_MEMBERS
+
+};
+
+#define DEFINE_BUILTIN_EXECUTABLES(name, functionName, overriddenName, length) \
+inline JSC::UnlinkedFunctionExecutable* CountQueuingStrategyBuiltinsWrapper::name##Executable() \
+{\
+ if (!m_##name##Executable) {\
+ JSC::Identifier executableName = functionName##PublicName();\
+ if (overriddenName)\
+ executableName = JSC::Identifier::fromString(m_vm, overriddenName);\
+ m_##name##Executable = JSC::Weak<JSC::UnlinkedFunctionExecutable>(JSC::createBuiltinExecutable(m_vm, m_##name##Source, executableName, s_##name##ConstructorKind, s_##name##ConstructAbility), this, &m_##name##Executable);\
+ }\
+ return m_##name##Executable.get();\
+}
+WEBCORE_FOREACH_COUNTQUEUINGSTRATEGY_BUILTIN_CODE(DEFINE_BUILTIN_EXECUTABLES)
+#undef DEFINE_BUILTIN_EXECUTABLES
+
+inline void CountQueuingStrategyBuiltinsWrapper::exportNames()
+{
+#define EXPORT_FUNCTION_NAME(name) m_vm.propertyNames->appendExternalName(name##PublicName(), name##PrivateName());
+ WEBCORE_FOREACH_COUNTQUEUINGSTRATEGY_BUILTIN_FUNCTION_NAME(EXPORT_FUNCTION_NAME)
+#undef EXPORT_FUNCTION_NAME
+}
+
+} // namespace WebCore
diff --git a/src/bun.js/builtins/cpp/JSBufferConstructorBuiltins.cpp b/src/bun.js/builtins/cpp/JSBufferConstructorBuiltins.cpp
new file mode 100644
index 000000000..d605d5b1b
--- /dev/null
+++ b/src/bun.js/builtins/cpp/JSBufferConstructorBuiltins.cpp
@@ -0,0 +1,105 @@
+/*
+ * Copyright (c) 2015 Igalia
+ * Copyright (c) 2015 Igalia S.L.
+ * Copyright (c) 2015 Igalia.
+ * Copyright (c) 2015, 2016 Canon Inc. All rights reserved.
+ * Copyright (c) 2015, 2016, 2017 Canon Inc.
+ * Copyright (c) 2016, 2020 Apple Inc. All rights reserved.
+ * Copyright (c) 2022 Codeblog Corp. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+// DO NOT EDIT THIS FILE. It is automatically generated from JavaScript files for
+// builtins by the script: Source/JavaScriptCore/Scripts/generate-js-builtins.py
+
+#include "config.h"
+#include "JSBufferConstructorBuiltins.h"
+
+#include "WebCoreJSClientData.h"
+#include <JavaScriptCore/HeapInlines.h>
+#include <JavaScriptCore/IdentifierInlines.h>
+#include <JavaScriptCore/Intrinsic.h>
+#include <JavaScriptCore/JSCJSValueInlines.h>
+#include <JavaScriptCore/JSCellInlines.h>
+#include <JavaScriptCore/StructureInlines.h>
+#include <JavaScriptCore/VM.h>
+
+namespace WebCore {
+
+const JSC::ConstructAbility s_jsBufferConstructorFromCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_jsBufferConstructorFromCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_jsBufferConstructorFromCodeLength = 1019;
+static const JSC::Intrinsic s_jsBufferConstructorFromCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_jsBufferConstructorFromCode =
+ "(function (items) {\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " if (!@isConstructor(this))\n" \
+ " @throwTypeError(\"Buffer.from requires |this| to be a constructor\");\n" \
+ "\n" \
+ "\n" \
+ " //\n" \
+ " if (typeof items === 'string' || (typeof items === 'object' && items && (items instanceof ArrayBuffer || items instanceof SharedArrayBuffer))) {\n" \
+ " switch (@argumentCount()) {\n" \
+ " case 1: {\n" \
+ " return new this(items);\n" \
+ " }\n" \
+ " case 2: {\n" \
+ " return new this(items, @argument(1));\n" \
+ " }\n" \
+ " default: {\n" \
+ " return new this(items, @argument(1), @argument(2));\n" \
+ " }\n" \
+ " }\n" \
+ " }\n" \
+ "\n" \
+ "\n" \
+ " var arrayLike = @toObject(items, \"Buffer.from requires an array-like object - not null or undefined\");\n" \
+ "\n" \
+ " //\n" \
+ " //\n" \
+ " //\n" \
+ " if (@isTypedArrayView(arrayLike)) {\n" \
+ " var length = @typedArrayLength(arrayLike);\n" \
+ " var result = this.allocUnsafe(length);\n" \
+ " result.set(arrayLike);\n" \
+ " return result;\n" \
+ " } \n" \
+ "\n" \
+ " return @tailCallForwardArguments(@Uint8Array.from, this);\n" \
+ "})\n" \
+;
+
+
+#define DEFINE_BUILTIN_GENERATOR(codeName, functionName, overriddenName, argumentCount) \
+JSC::FunctionExecutable* codeName##Generator(JSC::VM& vm) \
+{\
+ JSVMClientData* clientData = static_cast<JSVMClientData*>(vm.clientData); \
+ return clientData->builtinFunctions().jsBufferConstructorBuiltins().codeName##Executable()->link(vm, nullptr, clientData->builtinFunctions().jsBufferConstructorBuiltins().codeName##Source(), std::nullopt, s_##codeName##Intrinsic); \
+}
+WEBCORE_FOREACH_JSBUFFERCONSTRUCTOR_BUILTIN_CODE(DEFINE_BUILTIN_GENERATOR)
+#undef DEFINE_BUILTIN_GENERATOR
+
+
+} // namespace WebCore
diff --git a/src/bun.js/builtins/cpp/JSBufferConstructorBuiltins.h b/src/bun.js/builtins/cpp/JSBufferConstructorBuiltins.h
new file mode 100644
index 000000000..1495b852d
--- /dev/null
+++ b/src/bun.js/builtins/cpp/JSBufferConstructorBuiltins.h
@@ -0,0 +1,127 @@
+/*
+ * Copyright (c) 2015 Igalia
+ * Copyright (c) 2015 Igalia S.L.
+ * Copyright (c) 2015 Igalia.
+ * Copyright (c) 2015, 2016 Canon Inc. All rights reserved.
+ * Copyright (c) 2015, 2016, 2017 Canon Inc.
+ * Copyright (c) 2016, 2020 Apple Inc. All rights reserved.
+ * Copyright (c) 2022 Codeblog Corp. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+// DO NOT EDIT THIS FILE. It is automatically generated from JavaScript files for
+// builtins by the script: Source/JavaScriptCore/Scripts/generate-js-builtins.py
+
+#pragma once
+
+#include <JavaScriptCore/BuiltinUtils.h>
+#include <JavaScriptCore/Identifier.h>
+#include <JavaScriptCore/JSFunction.h>
+#include <JavaScriptCore/UnlinkedFunctionExecutable.h>
+
+namespace JSC {
+class FunctionExecutable;
+}
+
+namespace WebCore {
+
+/* JSBufferConstructor */
+extern const char* const s_jsBufferConstructorFromCode;
+extern const int s_jsBufferConstructorFromCodeLength;
+extern const JSC::ConstructAbility s_jsBufferConstructorFromCodeConstructAbility;
+extern const JSC::ConstructorKind s_jsBufferConstructorFromCodeConstructorKind;
+
+#define WEBCORE_FOREACH_JSBUFFERCONSTRUCTOR_BUILTIN_DATA(macro) \
+ macro(from, jsBufferConstructorFrom, 1) \
+
+#define WEBCORE_BUILTIN_JSBUFFERCONSTRUCTOR_FROM 1
+
+#define WEBCORE_FOREACH_JSBUFFERCONSTRUCTOR_BUILTIN_CODE(macro) \
+ macro(jsBufferConstructorFromCode, from, ASCIILiteral(), s_jsBufferConstructorFromCodeLength) \
+
+#define WEBCORE_FOREACH_JSBUFFERCONSTRUCTOR_BUILTIN_FUNCTION_NAME(macro) \
+ macro(from) \
+
+#define DECLARE_BUILTIN_GENERATOR(codeName, functionName, overriddenName, argumentCount) \
+ JSC::FunctionExecutable* codeName##Generator(JSC::VM&);
+
+WEBCORE_FOREACH_JSBUFFERCONSTRUCTOR_BUILTIN_CODE(DECLARE_BUILTIN_GENERATOR)
+#undef DECLARE_BUILTIN_GENERATOR
+
+class JSBufferConstructorBuiltinsWrapper : private JSC::WeakHandleOwner {
+public:
+ explicit JSBufferConstructorBuiltinsWrapper(JSC::VM& vm)
+ : m_vm(vm)
+ WEBCORE_FOREACH_JSBUFFERCONSTRUCTOR_BUILTIN_FUNCTION_NAME(INITIALIZE_BUILTIN_NAMES)
+#define INITIALIZE_BUILTIN_SOURCE_MEMBERS(name, functionName, overriddenName, length) , m_##name##Source(JSC::makeSource(StringImpl::createWithoutCopying(s_##name, length), { }))
+ WEBCORE_FOREACH_JSBUFFERCONSTRUCTOR_BUILTIN_CODE(INITIALIZE_BUILTIN_SOURCE_MEMBERS)
+#undef INITIALIZE_BUILTIN_SOURCE_MEMBERS
+ {
+ }
+
+#define EXPOSE_BUILTIN_EXECUTABLES(name, functionName, overriddenName, length) \
+ JSC::UnlinkedFunctionExecutable* name##Executable(); \
+ const JSC::SourceCode& name##Source() const { return m_##name##Source; }
+ WEBCORE_FOREACH_JSBUFFERCONSTRUCTOR_BUILTIN_CODE(EXPOSE_BUILTIN_EXECUTABLES)
+#undef EXPOSE_BUILTIN_EXECUTABLES
+
+ WEBCORE_FOREACH_JSBUFFERCONSTRUCTOR_BUILTIN_FUNCTION_NAME(DECLARE_BUILTIN_IDENTIFIER_ACCESSOR)
+
+ void exportNames();
+
+private:
+ JSC::VM& m_vm;
+
+ WEBCORE_FOREACH_JSBUFFERCONSTRUCTOR_BUILTIN_FUNCTION_NAME(DECLARE_BUILTIN_NAMES)
+
+#define DECLARE_BUILTIN_SOURCE_MEMBERS(name, functionName, overriddenName, length) \
+ JSC::SourceCode m_##name##Source;\
+ JSC::Weak<JSC::UnlinkedFunctionExecutable> m_##name##Executable;
+ WEBCORE_FOREACH_JSBUFFERCONSTRUCTOR_BUILTIN_CODE(DECLARE_BUILTIN_SOURCE_MEMBERS)
+#undef DECLARE_BUILTIN_SOURCE_MEMBERS
+
+};
+
+#define DEFINE_BUILTIN_EXECUTABLES(name, functionName, overriddenName, length) \
+inline JSC::UnlinkedFunctionExecutable* JSBufferConstructorBuiltinsWrapper::name##Executable() \
+{\
+ if (!m_##name##Executable) {\
+ JSC::Identifier executableName = functionName##PublicName();\
+ if (overriddenName)\
+ executableName = JSC::Identifier::fromString(m_vm, overriddenName);\
+ m_##name##Executable = JSC::Weak<JSC::UnlinkedFunctionExecutable>(JSC::createBuiltinExecutable(m_vm, m_##name##Source, executableName, s_##name##ConstructorKind, s_##name##ConstructAbility), this, &m_##name##Executable);\
+ }\
+ return m_##name##Executable.get();\
+}
+WEBCORE_FOREACH_JSBUFFERCONSTRUCTOR_BUILTIN_CODE(DEFINE_BUILTIN_EXECUTABLES)
+#undef DEFINE_BUILTIN_EXECUTABLES
+
+inline void JSBufferConstructorBuiltinsWrapper::exportNames()
+{
+#define EXPORT_FUNCTION_NAME(name) m_vm.propertyNames->appendExternalName(name##PublicName(), name##PrivateName());
+ WEBCORE_FOREACH_JSBUFFERCONSTRUCTOR_BUILTIN_FUNCTION_NAME(EXPORT_FUNCTION_NAME)
+#undef EXPORT_FUNCTION_NAME
+}
+
+} // namespace WebCore
diff --git a/src/bun.js/builtins/cpp/JSBufferPrototypeBuiltins.cpp b/src/bun.js/builtins/cpp/JSBufferPrototypeBuiltins.cpp
new file mode 100644
index 000000000..3925e54f7
--- /dev/null
+++ b/src/bun.js/builtins/cpp/JSBufferPrototypeBuiltins.cpp
@@ -0,0 +1,717 @@
+/*
+ * Copyright (c) 2015 Igalia
+ * Copyright (c) 2015 Igalia S.L.
+ * Copyright (c) 2015 Igalia.
+ * Copyright (c) 2015, 2016 Canon Inc. All rights reserved.
+ * Copyright (c) 2015, 2016, 2017 Canon Inc.
+ * Copyright (c) 2016, 2020 Apple Inc. All rights reserved.
+ * Copyright (c) 2022 Codeblog Corp. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+// DO NOT EDIT THIS FILE. It is automatically generated from JavaScript files for
+// builtins by the script: Source/JavaScriptCore/Scripts/generate-js-builtins.py
+
+#include "config.h"
+#include "JSBufferPrototypeBuiltins.h"
+
+#include "WebCoreJSClientData.h"
+#include <JavaScriptCore/HeapInlines.h>
+#include <JavaScriptCore/IdentifierInlines.h>
+#include <JavaScriptCore/Intrinsic.h>
+#include <JavaScriptCore/JSCJSValueInlines.h>
+#include <JavaScriptCore/JSCellInlines.h>
+#include <JavaScriptCore/StructureInlines.h>
+#include <JavaScriptCore/VM.h>
+
+namespace WebCore {
+
+const JSC::ConstructAbility s_jsBufferPrototypeSetBigUint64CodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_jsBufferPrototypeSetBigUint64CodeConstructorKind = JSC::ConstructorKind::None;
+const int s_jsBufferPrototypeSetBigUint64CodeLength = 107;
+static const JSC::Intrinsic s_jsBufferPrototypeSetBigUint64CodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_jsBufferPrototypeSetBigUint64Code =
+ "(function (offset, value, le) {\n" \
+ " \"use strict\";\n" \
+ " return this.dataView.setBigUint64(offset, value, le);\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_jsBufferPrototypeReadInt8CodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_jsBufferPrototypeReadInt8CodeConstructorKind = JSC::ConstructorKind::None;
+const int s_jsBufferPrototypeReadInt8CodeLength = 80;
+static const JSC::Intrinsic s_jsBufferPrototypeReadInt8CodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_jsBufferPrototypeReadInt8Code =
+ "(function (offset) {\n" \
+ " \"use strict\";\n" \
+ " return this.dataView.getInt8(offset);\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_jsBufferPrototypeReadUInt8CodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_jsBufferPrototypeReadUInt8CodeConstructorKind = JSC::ConstructorKind::None;
+const int s_jsBufferPrototypeReadUInt8CodeLength = 81;
+static const JSC::Intrinsic s_jsBufferPrototypeReadUInt8CodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_jsBufferPrototypeReadUInt8Code =
+ "(function (offset) {\n" \
+ " \"use strict\";\n" \
+ " return this.dataView.getUint8(offset);\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_jsBufferPrototypeReadInt16LECodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_jsBufferPrototypeReadInt16LECodeConstructorKind = JSC::ConstructorKind::None;
+const int s_jsBufferPrototypeReadInt16LECodeLength = 87;
+static const JSC::Intrinsic s_jsBufferPrototypeReadInt16LECodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_jsBufferPrototypeReadInt16LECode =
+ "(function (offset) {\n" \
+ " \"use strict\";\n" \
+ " return this.dataView.getInt16(offset, true);\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_jsBufferPrototypeReadInt16BECodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_jsBufferPrototypeReadInt16BECodeConstructorKind = JSC::ConstructorKind::None;
+const int s_jsBufferPrototypeReadInt16BECodeLength = 88;
+static const JSC::Intrinsic s_jsBufferPrototypeReadInt16BECodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_jsBufferPrototypeReadInt16BECode =
+ "(function (offset) {\n" \
+ " \"use strict\";\n" \
+ " return this.dataView.getInt16(offset, false);\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_jsBufferPrototypeReadUInt16LECodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_jsBufferPrototypeReadUInt16LECodeConstructorKind = JSC::ConstructorKind::None;
+const int s_jsBufferPrototypeReadUInt16LECodeLength = 88;
+static const JSC::Intrinsic s_jsBufferPrototypeReadUInt16LECodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_jsBufferPrototypeReadUInt16LECode =
+ "(function (offset) {\n" \
+ " \"use strict\";\n" \
+ " return this.dataView.getUint16(offset, true);\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_jsBufferPrototypeReadUInt16BECodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_jsBufferPrototypeReadUInt16BECodeConstructorKind = JSC::ConstructorKind::None;
+const int s_jsBufferPrototypeReadUInt16BECodeLength = 89;
+static const JSC::Intrinsic s_jsBufferPrototypeReadUInt16BECodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_jsBufferPrototypeReadUInt16BECode =
+ "(function (offset) {\n" \
+ " \"use strict\";\n" \
+ " return this.dataView.getUint16(offset, false);\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_jsBufferPrototypeReadInt32LECodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_jsBufferPrototypeReadInt32LECodeConstructorKind = JSC::ConstructorKind::None;
+const int s_jsBufferPrototypeReadInt32LECodeLength = 87;
+static const JSC::Intrinsic s_jsBufferPrototypeReadInt32LECodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_jsBufferPrototypeReadInt32LECode =
+ "(function (offset) {\n" \
+ " \"use strict\";\n" \
+ " return this.dataView.getInt32(offset, true);\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_jsBufferPrototypeReadInt32BECodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_jsBufferPrototypeReadInt32BECodeConstructorKind = JSC::ConstructorKind::None;
+const int s_jsBufferPrototypeReadInt32BECodeLength = 88;
+static const JSC::Intrinsic s_jsBufferPrototypeReadInt32BECodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_jsBufferPrototypeReadInt32BECode =
+ "(function (offset) {\n" \
+ " \"use strict\";\n" \
+ " return this.dataView.getInt32(offset, false);\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_jsBufferPrototypeReadUInt32LECodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_jsBufferPrototypeReadUInt32LECodeConstructorKind = JSC::ConstructorKind::None;
+const int s_jsBufferPrototypeReadUInt32LECodeLength = 88;
+static const JSC::Intrinsic s_jsBufferPrototypeReadUInt32LECodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_jsBufferPrototypeReadUInt32LECode =
+ "(function (offset) {\n" \
+ " \"use strict\";\n" \
+ " return this.dataView.getUint32(offset, true);\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_jsBufferPrototypeReadUInt32BECodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_jsBufferPrototypeReadUInt32BECodeConstructorKind = JSC::ConstructorKind::None;
+const int s_jsBufferPrototypeReadUInt32BECodeLength = 89;
+static const JSC::Intrinsic s_jsBufferPrototypeReadUInt32BECodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_jsBufferPrototypeReadUInt32BECode =
+ "(function (offset) {\n" \
+ " \"use strict\";\n" \
+ " return this.dataView.getUint32(offset, false);\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_jsBufferPrototypeReadFloatLECodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_jsBufferPrototypeReadFloatLECodeConstructorKind = JSC::ConstructorKind::None;
+const int s_jsBufferPrototypeReadFloatLECodeLength = 89;
+static const JSC::Intrinsic s_jsBufferPrototypeReadFloatLECodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_jsBufferPrototypeReadFloatLECode =
+ "(function (offset) {\n" \
+ " \"use strict\";\n" \
+ " return this.dataView.getFloat32(offset, true);\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_jsBufferPrototypeReadFloatBECodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_jsBufferPrototypeReadFloatBECodeConstructorKind = JSC::ConstructorKind::None;
+const int s_jsBufferPrototypeReadFloatBECodeLength = 90;
+static const JSC::Intrinsic s_jsBufferPrototypeReadFloatBECodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_jsBufferPrototypeReadFloatBECode =
+ "(function (offset) {\n" \
+ " \"use strict\";\n" \
+ " return this.dataView.getFloat32(offset, false);\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_jsBufferPrototypeReadDoubleLECodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_jsBufferPrototypeReadDoubleLECodeConstructorKind = JSC::ConstructorKind::None;
+const int s_jsBufferPrototypeReadDoubleLECodeLength = 89;
+static const JSC::Intrinsic s_jsBufferPrototypeReadDoubleLECodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_jsBufferPrototypeReadDoubleLECode =
+ "(function (offset) {\n" \
+ " \"use strict\";\n" \
+ " return this.dataView.getFloat64(offset, true);\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_jsBufferPrototypeReadDoubleBECodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_jsBufferPrototypeReadDoubleBECodeConstructorKind = JSC::ConstructorKind::None;
+const int s_jsBufferPrototypeReadDoubleBECodeLength = 90;
+static const JSC::Intrinsic s_jsBufferPrototypeReadDoubleBECodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_jsBufferPrototypeReadDoubleBECode =
+ "(function (offset) {\n" \
+ " \"use strict\";\n" \
+ " return this.dataView.getFloat64(offset, false);\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_jsBufferPrototypeReadBigInt64LECodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_jsBufferPrototypeReadBigInt64LECodeConstructorKind = JSC::ConstructorKind::None;
+const int s_jsBufferPrototypeReadBigInt64LECodeLength = 90;
+static const JSC::Intrinsic s_jsBufferPrototypeReadBigInt64LECodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_jsBufferPrototypeReadBigInt64LECode =
+ "(function (offset) {\n" \
+ " \"use strict\";\n" \
+ " return this.dataView.getBigInt64(offset, true);\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_jsBufferPrototypeReadBigInt64BECodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_jsBufferPrototypeReadBigInt64BECodeConstructorKind = JSC::ConstructorKind::None;
+const int s_jsBufferPrototypeReadBigInt64BECodeLength = 91;
+static const JSC::Intrinsic s_jsBufferPrototypeReadBigInt64BECodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_jsBufferPrototypeReadBigInt64BECode =
+ "(function (offset) {\n" \
+ " \"use strict\";\n" \
+ " return this.dataView.getBigInt64(offset, false);\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_jsBufferPrototypeReadBigUInt64LECodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_jsBufferPrototypeReadBigUInt64LECodeConstructorKind = JSC::ConstructorKind::None;
+const int s_jsBufferPrototypeReadBigUInt64LECodeLength = 91;
+static const JSC::Intrinsic s_jsBufferPrototypeReadBigUInt64LECodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_jsBufferPrototypeReadBigUInt64LECode =
+ "(function (offset) {\n" \
+ " \"use strict\";\n" \
+ " return this.dataView.getBigUint64(offset, true);\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_jsBufferPrototypeReadBigUInt64BECodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_jsBufferPrototypeReadBigUInt64BECodeConstructorKind = JSC::ConstructorKind::None;
+const int s_jsBufferPrototypeReadBigUInt64BECodeLength = 92;
+static const JSC::Intrinsic s_jsBufferPrototypeReadBigUInt64BECodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_jsBufferPrototypeReadBigUInt64BECode =
+ "(function (offset) {\n" \
+ " \"use strict\";\n" \
+ " return this.dataView.getBigUint64(offset, false);\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_jsBufferPrototypeWriteInt8CodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_jsBufferPrototypeWriteInt8CodeConstructorKind = JSC::ConstructorKind::None;
+const int s_jsBufferPrototypeWriteInt8CodeLength = 108;
+static const JSC::Intrinsic s_jsBufferPrototypeWriteInt8CodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_jsBufferPrototypeWriteInt8Code =
+ "(function (value, offset) {\n" \
+ " \"use strict\";\n" \
+ " this.dataView.setInt8(offset, value);\n" \
+ " return offset + 1;\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_jsBufferPrototypeWriteUInt8CodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_jsBufferPrototypeWriteUInt8CodeConstructorKind = JSC::ConstructorKind::None;
+const int s_jsBufferPrototypeWriteUInt8CodeLength = 109;
+static const JSC::Intrinsic s_jsBufferPrototypeWriteUInt8CodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_jsBufferPrototypeWriteUInt8Code =
+ "(function (value, offset) {\n" \
+ " \"use strict\";\n" \
+ " this.dataView.setUint8(offset, value);\n" \
+ " return offset + 1;\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_jsBufferPrototypeWriteInt16LECodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_jsBufferPrototypeWriteInt16LECodeConstructorKind = JSC::ConstructorKind::None;
+const int s_jsBufferPrototypeWriteInt16LECodeLength = 115;
+static const JSC::Intrinsic s_jsBufferPrototypeWriteInt16LECodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_jsBufferPrototypeWriteInt16LECode =
+ "(function (value, offset) {\n" \
+ " \"use strict\";\n" \
+ " this.dataView.setInt16(offset, value, true);\n" \
+ " return offset + 2;\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_jsBufferPrototypeWriteInt16BECodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_jsBufferPrototypeWriteInt16BECodeConstructorKind = JSC::ConstructorKind::None;
+const int s_jsBufferPrototypeWriteInt16BECodeLength = 116;
+static const JSC::Intrinsic s_jsBufferPrototypeWriteInt16BECodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_jsBufferPrototypeWriteInt16BECode =
+ "(function (value, offset) {\n" \
+ " \"use strict\";\n" \
+ " this.dataView.setInt16(offset, value, false);\n" \
+ " return offset + 2;\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_jsBufferPrototypeWriteUInt16LECodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_jsBufferPrototypeWriteUInt16LECodeConstructorKind = JSC::ConstructorKind::None;
+const int s_jsBufferPrototypeWriteUInt16LECodeLength = 116;
+static const JSC::Intrinsic s_jsBufferPrototypeWriteUInt16LECodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_jsBufferPrototypeWriteUInt16LECode =
+ "(function (value, offset) {\n" \
+ " \"use strict\";\n" \
+ " this.dataView.setUint16(offset, value, true);\n" \
+ " return offset + 2;\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_jsBufferPrototypeWriteUInt16BECodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_jsBufferPrototypeWriteUInt16BECodeConstructorKind = JSC::ConstructorKind::None;
+const int s_jsBufferPrototypeWriteUInt16BECodeLength = 117;
+static const JSC::Intrinsic s_jsBufferPrototypeWriteUInt16BECodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_jsBufferPrototypeWriteUInt16BECode =
+ "(function (value, offset) {\n" \
+ " \"use strict\";\n" \
+ " this.dataView.setUint16(offset, value, false);\n" \
+ " return offset + 2;\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_jsBufferPrototypeWriteInt32LECodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_jsBufferPrototypeWriteInt32LECodeConstructorKind = JSC::ConstructorKind::None;
+const int s_jsBufferPrototypeWriteInt32LECodeLength = 115;
+static const JSC::Intrinsic s_jsBufferPrototypeWriteInt32LECodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_jsBufferPrototypeWriteInt32LECode =
+ "(function (value, offset) {\n" \
+ " \"use strict\";\n" \
+ " this.dataView.setInt32(offset, value, true);\n" \
+ " return offset + 4;\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_jsBufferPrototypeWriteInt32BECodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_jsBufferPrototypeWriteInt32BECodeConstructorKind = JSC::ConstructorKind::None;
+const int s_jsBufferPrototypeWriteInt32BECodeLength = 116;
+static const JSC::Intrinsic s_jsBufferPrototypeWriteInt32BECodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_jsBufferPrototypeWriteInt32BECode =
+ "(function (value, offset) {\n" \
+ " \"use strict\";\n" \
+ " this.dataView.setInt32(offset, value, false);\n" \
+ " return offset + 4;\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_jsBufferPrototypeWriteUInt32LECodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_jsBufferPrototypeWriteUInt32LECodeConstructorKind = JSC::ConstructorKind::None;
+const int s_jsBufferPrototypeWriteUInt32LECodeLength = 116;
+static const JSC::Intrinsic s_jsBufferPrototypeWriteUInt32LECodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_jsBufferPrototypeWriteUInt32LECode =
+ "(function (value, offset) {\n" \
+ " \"use strict\";\n" \
+ " this.dataView.setUint32(offset, value, true);\n" \
+ " return offset + 4;\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_jsBufferPrototypeWriteUInt32BECodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_jsBufferPrototypeWriteUInt32BECodeConstructorKind = JSC::ConstructorKind::None;
+const int s_jsBufferPrototypeWriteUInt32BECodeLength = 117;
+static const JSC::Intrinsic s_jsBufferPrototypeWriteUInt32BECodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_jsBufferPrototypeWriteUInt32BECode =
+ "(function (value, offset) {\n" \
+ " \"use strict\";\n" \
+ " this.dataView.setUint32(offset, value, false);\n" \
+ " return offset + 4;\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_jsBufferPrototypeWriteFloatLECodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_jsBufferPrototypeWriteFloatLECodeConstructorKind = JSC::ConstructorKind::None;
+const int s_jsBufferPrototypeWriteFloatLECodeLength = 117;
+static const JSC::Intrinsic s_jsBufferPrototypeWriteFloatLECodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_jsBufferPrototypeWriteFloatLECode =
+ "(function (value, offset) {\n" \
+ " \"use strict\";\n" \
+ " this.dataView.setFloat32(offset, value, true);\n" \
+ " return offset + 4;\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_jsBufferPrototypeWriteFloatBECodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_jsBufferPrototypeWriteFloatBECodeConstructorKind = JSC::ConstructorKind::None;
+const int s_jsBufferPrototypeWriteFloatBECodeLength = 118;
+static const JSC::Intrinsic s_jsBufferPrototypeWriteFloatBECodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_jsBufferPrototypeWriteFloatBECode =
+ "(function (value, offset) {\n" \
+ " \"use strict\";\n" \
+ " this.dataView.setFloat32(offset, value, false);\n" \
+ " return offset + 4;\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_jsBufferPrototypeWriteDoubleLECodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_jsBufferPrototypeWriteDoubleLECodeConstructorKind = JSC::ConstructorKind::None;
+const int s_jsBufferPrototypeWriteDoubleLECodeLength = 117;
+static const JSC::Intrinsic s_jsBufferPrototypeWriteDoubleLECodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_jsBufferPrototypeWriteDoubleLECode =
+ "(function (value, offset) {\n" \
+ " \"use strict\";\n" \
+ " this.dataView.setFloat64(offset, value, true);\n" \
+ " return offset + 8;\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_jsBufferPrototypeWriteDoubleBECodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_jsBufferPrototypeWriteDoubleBECodeConstructorKind = JSC::ConstructorKind::None;
+const int s_jsBufferPrototypeWriteDoubleBECodeLength = 118;
+static const JSC::Intrinsic s_jsBufferPrototypeWriteDoubleBECodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_jsBufferPrototypeWriteDoubleBECode =
+ "(function (value, offset) {\n" \
+ " \"use strict\";\n" \
+ " this.dataView.setFloat64(offset, value, false);\n" \
+ " return offset + 8;\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_jsBufferPrototypeWriteBigInt64LECodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_jsBufferPrototypeWriteBigInt64LECodeConstructorKind = JSC::ConstructorKind::None;
+const int s_jsBufferPrototypeWriteBigInt64LECodeLength = 118;
+static const JSC::Intrinsic s_jsBufferPrototypeWriteBigInt64LECodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_jsBufferPrototypeWriteBigInt64LECode =
+ "(function (value, offset) {\n" \
+ " \"use strict\";\n" \
+ " this.dataView.setBigInt64(offset, value, true);\n" \
+ " return offset + 8;\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_jsBufferPrototypeWriteBigInt64BECodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_jsBufferPrototypeWriteBigInt64BECodeConstructorKind = JSC::ConstructorKind::None;
+const int s_jsBufferPrototypeWriteBigInt64BECodeLength = 119;
+static const JSC::Intrinsic s_jsBufferPrototypeWriteBigInt64BECodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_jsBufferPrototypeWriteBigInt64BECode =
+ "(function (value, offset) {\n" \
+ " \"use strict\";\n" \
+ " this.dataView.setBigInt64(offset, value, false);\n" \
+ " return offset + 8;\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_jsBufferPrototypeWriteBigUInt64LECodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_jsBufferPrototypeWriteBigUInt64LECodeConstructorKind = JSC::ConstructorKind::None;
+const int s_jsBufferPrototypeWriteBigUInt64LECodeLength = 119;
+static const JSC::Intrinsic s_jsBufferPrototypeWriteBigUInt64LECodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_jsBufferPrototypeWriteBigUInt64LECode =
+ "(function (value, offset) {\n" \
+ " \"use strict\";\n" \
+ " this.dataView.setBigUint64(offset, value, true);\n" \
+ " return offset + 8;\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_jsBufferPrototypeWriteBigUInt64BECodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_jsBufferPrototypeWriteBigUInt64BECodeConstructorKind = JSC::ConstructorKind::None;
+const int s_jsBufferPrototypeWriteBigUInt64BECodeLength = 120;
+static const JSC::Intrinsic s_jsBufferPrototypeWriteBigUInt64BECodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_jsBufferPrototypeWriteBigUInt64BECode =
+ "(function (value, offset) {\n" \
+ " \"use strict\";\n" \
+ " this.dataView.setBigUint64(offset, value, false);\n" \
+ " return offset + 8;\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_jsBufferPrototypeSliceCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_jsBufferPrototypeSliceCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_jsBufferPrototypeSliceCodeLength = 262;
+static const JSC::Intrinsic s_jsBufferPrototypeSliceCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_jsBufferPrototypeSliceCode =
+ "(function (start, end) {\n" \
+ " \"use strict\";\n" \
+ " if (start === undefined && end === undefined) {\n" \
+ " return this;\n" \
+ " }\n" \
+ "\n" \
+ " Buffer[Symbol.species] ||= Buffer;\n" \
+ "\n" \
+ " return new Buffer(this.buffer, this.byteOffset + (start || 0), (end || this.byteLength) - (start || 0));\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_jsBufferPrototypeUtf8WriteCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_jsBufferPrototypeUtf8WriteCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_jsBufferPrototypeUtf8WriteCodeLength = 105;
+static const JSC::Intrinsic s_jsBufferPrototypeUtf8WriteCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_jsBufferPrototypeUtf8WriteCode =
+ "(function (text, offset, length) {\n" \
+ " \"use strict\";\n" \
+ " return this.write(text, offset, length, \"utf8\");\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_jsBufferPrototypeUcs2WriteCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_jsBufferPrototypeUcs2WriteCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_jsBufferPrototypeUcs2WriteCodeLength = 105;
+static const JSC::Intrinsic s_jsBufferPrototypeUcs2WriteCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_jsBufferPrototypeUcs2WriteCode =
+ "(function (text, offset, length) {\n" \
+ " \"use strict\";\n" \
+ " return this.write(text, offset, length, \"ucs2\");\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_jsBufferPrototypeUtf16leWriteCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_jsBufferPrototypeUtf16leWriteCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_jsBufferPrototypeUtf16leWriteCodeLength = 108;
+static const JSC::Intrinsic s_jsBufferPrototypeUtf16leWriteCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_jsBufferPrototypeUtf16leWriteCode =
+ "(function (text, offset, length) {\n" \
+ " \"use strict\";\n" \
+ " return this.write(text, offset, length, \"utf16le\");\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_jsBufferPrototypeLatin1WriteCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_jsBufferPrototypeLatin1WriteCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_jsBufferPrototypeLatin1WriteCodeLength = 107;
+static const JSC::Intrinsic s_jsBufferPrototypeLatin1WriteCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_jsBufferPrototypeLatin1WriteCode =
+ "(function (text, offset, length) {\n" \
+ " \"use strict\";\n" \
+ " return this.write(text, offset, length, \"latin1\");\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_jsBufferPrototypeAsciiWriteCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_jsBufferPrototypeAsciiWriteCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_jsBufferPrototypeAsciiWriteCodeLength = 106;
+static const JSC::Intrinsic s_jsBufferPrototypeAsciiWriteCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_jsBufferPrototypeAsciiWriteCode =
+ "(function (text, offset, length) {\n" \
+ " \"use strict\";\n" \
+ " return this.write(text, offset, length, \"ascii\");\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_jsBufferPrototypeBase64WriteCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_jsBufferPrototypeBase64WriteCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_jsBufferPrototypeBase64WriteCodeLength = 107;
+static const JSC::Intrinsic s_jsBufferPrototypeBase64WriteCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_jsBufferPrototypeBase64WriteCode =
+ "(function (text, offset, length) {\n" \
+ " \"use strict\";\n" \
+ " return this.write(text, offset, length, \"base64\");\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_jsBufferPrototypeBase64urlWriteCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_jsBufferPrototypeBase64urlWriteCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_jsBufferPrototypeBase64urlWriteCodeLength = 110;
+static const JSC::Intrinsic s_jsBufferPrototypeBase64urlWriteCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_jsBufferPrototypeBase64urlWriteCode =
+ "(function (text, offset, length) {\n" \
+ " \"use strict\";\n" \
+ " return this.write(text, offset, length, \"base64url\");\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_jsBufferPrototypeHexWriteCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_jsBufferPrototypeHexWriteCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_jsBufferPrototypeHexWriteCodeLength = 104;
+static const JSC::Intrinsic s_jsBufferPrototypeHexWriteCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_jsBufferPrototypeHexWriteCode =
+ "(function (text, offset, length) {\n" \
+ " \"use strict\";\n" \
+ " return this.write(text, offset, length, \"hex\");\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_jsBufferPrototypeUtf8SliceCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_jsBufferPrototypeUtf8SliceCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_jsBufferPrototypeUtf8SliceCodeLength = 96;
+static const JSC::Intrinsic s_jsBufferPrototypeUtf8SliceCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_jsBufferPrototypeUtf8SliceCode =
+ "(function (offset, length) {\n" \
+ " \"use strict\";\n" \
+ " return this.toString(offset, length, \"utf8\");\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_jsBufferPrototypeUcs2SliceCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_jsBufferPrototypeUcs2SliceCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_jsBufferPrototypeUcs2SliceCodeLength = 96;
+static const JSC::Intrinsic s_jsBufferPrototypeUcs2SliceCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_jsBufferPrototypeUcs2SliceCode =
+ "(function (offset, length) {\n" \
+ " \"use strict\";\n" \
+ " return this.toString(offset, length, \"ucs2\");\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_jsBufferPrototypeUtf16leSliceCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_jsBufferPrototypeUtf16leSliceCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_jsBufferPrototypeUtf16leSliceCodeLength = 99;
+static const JSC::Intrinsic s_jsBufferPrototypeUtf16leSliceCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_jsBufferPrototypeUtf16leSliceCode =
+ "(function (offset, length) {\n" \
+ " \"use strict\";\n" \
+ " return this.toString(offset, length, \"utf16le\");\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_jsBufferPrototypeLatin1SliceCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_jsBufferPrototypeLatin1SliceCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_jsBufferPrototypeLatin1SliceCodeLength = 98;
+static const JSC::Intrinsic s_jsBufferPrototypeLatin1SliceCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_jsBufferPrototypeLatin1SliceCode =
+ "(function (offset, length) {\n" \
+ " \"use strict\";\n" \
+ " return this.toString(offset, length, \"latin1\");\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_jsBufferPrototypeAsciiSliceCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_jsBufferPrototypeAsciiSliceCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_jsBufferPrototypeAsciiSliceCodeLength = 97;
+static const JSC::Intrinsic s_jsBufferPrototypeAsciiSliceCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_jsBufferPrototypeAsciiSliceCode =
+ "(function (offset, length) {\n" \
+ " \"use strict\";\n" \
+ " return this.toString(offset, length, \"ascii\");\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_jsBufferPrototypeBase64SliceCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_jsBufferPrototypeBase64SliceCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_jsBufferPrototypeBase64SliceCodeLength = 98;
+static const JSC::Intrinsic s_jsBufferPrototypeBase64SliceCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_jsBufferPrototypeBase64SliceCode =
+ "(function (offset, length) {\n" \
+ " \"use strict\";\n" \
+ " return this.toString(offset, length, \"base64\");\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_jsBufferPrototypeBase64urlSliceCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_jsBufferPrototypeBase64urlSliceCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_jsBufferPrototypeBase64urlSliceCodeLength = 101;
+static const JSC::Intrinsic s_jsBufferPrototypeBase64urlSliceCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_jsBufferPrototypeBase64urlSliceCode =
+ "(function (offset, length) {\n" \
+ " \"use strict\";\n" \
+ " return this.toString(offset, length, \"base64url\");\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_jsBufferPrototypeHexSliceCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_jsBufferPrototypeHexSliceCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_jsBufferPrototypeHexSliceCodeLength = 95;
+static const JSC::Intrinsic s_jsBufferPrototypeHexSliceCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_jsBufferPrototypeHexSliceCode =
+ "(function (offset, length) {\n" \
+ " \"use strict\";\n" \
+ " return this.toString(offset, length, \"hex\");\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_jsBufferPrototypeToJSONCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_jsBufferPrototypeToJSONCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_jsBufferPrototypeToJSONCodeLength = 118;
+static const JSC::Intrinsic s_jsBufferPrototypeToJSONCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_jsBufferPrototypeToJSONCode =
+ "(function () {\n" \
+ " \"use strict\";\n" \
+ " const type = \"Buffer\";\n" \
+ " const data = @Array.from(this);\n" \
+ " return { type, data };\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_jsBufferPrototypeSubarrayCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_jsBufferPrototypeSubarrayCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_jsBufferPrototypeSubarrayCodeLength = 196;
+static const JSC::Intrinsic s_jsBufferPrototypeSubarrayCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_jsBufferPrototypeSubarrayCode =
+ "(function (start, end) {\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " Buffer[Symbol.species] ??= Buffer;\n" \
+ " return new Buffer(this.buffer, this.byteOffset + (start || 0), (end || this.byteLength) - (start || 0));\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_jsBufferPrototypeInitializeBunBufferCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_jsBufferPrototypeInitializeBunBufferCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_jsBufferPrototypeInitializeBunBufferCodeLength = 45;
+static const JSC::Intrinsic s_jsBufferPrototypeInitializeBunBufferCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_jsBufferPrototypeInitializeBunBufferCode =
+ "(function (parameters)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ "})\n" \
+;
+
+
+#define DEFINE_BUILTIN_GENERATOR(codeName, functionName, overriddenName, argumentCount) \
+JSC::FunctionExecutable* codeName##Generator(JSC::VM& vm) \
+{\
+ JSVMClientData* clientData = static_cast<JSVMClientData*>(vm.clientData); \
+ return clientData->builtinFunctions().jsBufferPrototypeBuiltins().codeName##Executable()->link(vm, nullptr, clientData->builtinFunctions().jsBufferPrototypeBuiltins().codeName##Source(), std::nullopt, s_##codeName##Intrinsic); \
+}
+WEBCORE_FOREACH_JSBUFFERPROTOTYPE_BUILTIN_CODE(DEFINE_BUILTIN_GENERATOR)
+#undef DEFINE_BUILTIN_GENERATOR
+
+
+} // namespace WebCore
diff --git a/src/bun.js/builtins/cpp/JSBufferPrototypeBuiltins.h b/src/bun.js/builtins/cpp/JSBufferPrototypeBuiltins.h
new file mode 100644
index 000000000..5fc08789e
--- /dev/null
+++ b/src/bun.js/builtins/cpp/JSBufferPrototypeBuiltins.h
@@ -0,0 +1,575 @@
+/*
+ * Copyright (c) 2015 Igalia
+ * Copyright (c) 2015 Igalia S.L.
+ * Copyright (c) 2015 Igalia.
+ * Copyright (c) 2015, 2016 Canon Inc. All rights reserved.
+ * Copyright (c) 2015, 2016, 2017 Canon Inc.
+ * Copyright (c) 2016, 2020 Apple Inc. All rights reserved.
+ * Copyright (c) 2022 Codeblog Corp. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+// DO NOT EDIT THIS FILE. It is automatically generated from JavaScript files for
+// builtins by the script: Source/JavaScriptCore/Scripts/generate-js-builtins.py
+
+#pragma once
+
+#include <JavaScriptCore/BuiltinUtils.h>
+#include <JavaScriptCore/Identifier.h>
+#include <JavaScriptCore/JSFunction.h>
+#include <JavaScriptCore/UnlinkedFunctionExecutable.h>
+
+namespace JSC {
+class FunctionExecutable;
+}
+
+namespace WebCore {
+
+/* JSBufferPrototype */
+extern const char* const s_jsBufferPrototypeSetBigUint64Code;
+extern const int s_jsBufferPrototypeSetBigUint64CodeLength;
+extern const JSC::ConstructAbility s_jsBufferPrototypeSetBigUint64CodeConstructAbility;
+extern const JSC::ConstructorKind s_jsBufferPrototypeSetBigUint64CodeConstructorKind;
+extern const char* const s_jsBufferPrototypeReadInt8Code;
+extern const int s_jsBufferPrototypeReadInt8CodeLength;
+extern const JSC::ConstructAbility s_jsBufferPrototypeReadInt8CodeConstructAbility;
+extern const JSC::ConstructorKind s_jsBufferPrototypeReadInt8CodeConstructorKind;
+extern const char* const s_jsBufferPrototypeReadUInt8Code;
+extern const int s_jsBufferPrototypeReadUInt8CodeLength;
+extern const JSC::ConstructAbility s_jsBufferPrototypeReadUInt8CodeConstructAbility;
+extern const JSC::ConstructorKind s_jsBufferPrototypeReadUInt8CodeConstructorKind;
+extern const char* const s_jsBufferPrototypeReadInt16LECode;
+extern const int s_jsBufferPrototypeReadInt16LECodeLength;
+extern const JSC::ConstructAbility s_jsBufferPrototypeReadInt16LECodeConstructAbility;
+extern const JSC::ConstructorKind s_jsBufferPrototypeReadInt16LECodeConstructorKind;
+extern const char* const s_jsBufferPrototypeReadInt16BECode;
+extern const int s_jsBufferPrototypeReadInt16BECodeLength;
+extern const JSC::ConstructAbility s_jsBufferPrototypeReadInt16BECodeConstructAbility;
+extern const JSC::ConstructorKind s_jsBufferPrototypeReadInt16BECodeConstructorKind;
+extern const char* const s_jsBufferPrototypeReadUInt16LECode;
+extern const int s_jsBufferPrototypeReadUInt16LECodeLength;
+extern const JSC::ConstructAbility s_jsBufferPrototypeReadUInt16LECodeConstructAbility;
+extern const JSC::ConstructorKind s_jsBufferPrototypeReadUInt16LECodeConstructorKind;
+extern const char* const s_jsBufferPrototypeReadUInt16BECode;
+extern const int s_jsBufferPrototypeReadUInt16BECodeLength;
+extern const JSC::ConstructAbility s_jsBufferPrototypeReadUInt16BECodeConstructAbility;
+extern const JSC::ConstructorKind s_jsBufferPrototypeReadUInt16BECodeConstructorKind;
+extern const char* const s_jsBufferPrototypeReadInt32LECode;
+extern const int s_jsBufferPrototypeReadInt32LECodeLength;
+extern const JSC::ConstructAbility s_jsBufferPrototypeReadInt32LECodeConstructAbility;
+extern const JSC::ConstructorKind s_jsBufferPrototypeReadInt32LECodeConstructorKind;
+extern const char* const s_jsBufferPrototypeReadInt32BECode;
+extern const int s_jsBufferPrototypeReadInt32BECodeLength;
+extern const JSC::ConstructAbility s_jsBufferPrototypeReadInt32BECodeConstructAbility;
+extern const JSC::ConstructorKind s_jsBufferPrototypeReadInt32BECodeConstructorKind;
+extern const char* const s_jsBufferPrototypeReadUInt32LECode;
+extern const int s_jsBufferPrototypeReadUInt32LECodeLength;
+extern const JSC::ConstructAbility s_jsBufferPrototypeReadUInt32LECodeConstructAbility;
+extern const JSC::ConstructorKind s_jsBufferPrototypeReadUInt32LECodeConstructorKind;
+extern const char* const s_jsBufferPrototypeReadUInt32BECode;
+extern const int s_jsBufferPrototypeReadUInt32BECodeLength;
+extern const JSC::ConstructAbility s_jsBufferPrototypeReadUInt32BECodeConstructAbility;
+extern const JSC::ConstructorKind s_jsBufferPrototypeReadUInt32BECodeConstructorKind;
+extern const char* const s_jsBufferPrototypeReadFloatLECode;
+extern const int s_jsBufferPrototypeReadFloatLECodeLength;
+extern const JSC::ConstructAbility s_jsBufferPrototypeReadFloatLECodeConstructAbility;
+extern const JSC::ConstructorKind s_jsBufferPrototypeReadFloatLECodeConstructorKind;
+extern const char* const s_jsBufferPrototypeReadFloatBECode;
+extern const int s_jsBufferPrototypeReadFloatBECodeLength;
+extern const JSC::ConstructAbility s_jsBufferPrototypeReadFloatBECodeConstructAbility;
+extern const JSC::ConstructorKind s_jsBufferPrototypeReadFloatBECodeConstructorKind;
+extern const char* const s_jsBufferPrototypeReadDoubleLECode;
+extern const int s_jsBufferPrototypeReadDoubleLECodeLength;
+extern const JSC::ConstructAbility s_jsBufferPrototypeReadDoubleLECodeConstructAbility;
+extern const JSC::ConstructorKind s_jsBufferPrototypeReadDoubleLECodeConstructorKind;
+extern const char* const s_jsBufferPrototypeReadDoubleBECode;
+extern const int s_jsBufferPrototypeReadDoubleBECodeLength;
+extern const JSC::ConstructAbility s_jsBufferPrototypeReadDoubleBECodeConstructAbility;
+extern const JSC::ConstructorKind s_jsBufferPrototypeReadDoubleBECodeConstructorKind;
+extern const char* const s_jsBufferPrototypeReadBigInt64LECode;
+extern const int s_jsBufferPrototypeReadBigInt64LECodeLength;
+extern const JSC::ConstructAbility s_jsBufferPrototypeReadBigInt64LECodeConstructAbility;
+extern const JSC::ConstructorKind s_jsBufferPrototypeReadBigInt64LECodeConstructorKind;
+extern const char* const s_jsBufferPrototypeReadBigInt64BECode;
+extern const int s_jsBufferPrototypeReadBigInt64BECodeLength;
+extern const JSC::ConstructAbility s_jsBufferPrototypeReadBigInt64BECodeConstructAbility;
+extern const JSC::ConstructorKind s_jsBufferPrototypeReadBigInt64BECodeConstructorKind;
+extern const char* const s_jsBufferPrototypeReadBigUInt64LECode;
+extern const int s_jsBufferPrototypeReadBigUInt64LECodeLength;
+extern const JSC::ConstructAbility s_jsBufferPrototypeReadBigUInt64LECodeConstructAbility;
+extern const JSC::ConstructorKind s_jsBufferPrototypeReadBigUInt64LECodeConstructorKind;
+extern const char* const s_jsBufferPrototypeReadBigUInt64BECode;
+extern const int s_jsBufferPrototypeReadBigUInt64BECodeLength;
+extern const JSC::ConstructAbility s_jsBufferPrototypeReadBigUInt64BECodeConstructAbility;
+extern const JSC::ConstructorKind s_jsBufferPrototypeReadBigUInt64BECodeConstructorKind;
+extern const char* const s_jsBufferPrototypeWriteInt8Code;
+extern const int s_jsBufferPrototypeWriteInt8CodeLength;
+extern const JSC::ConstructAbility s_jsBufferPrototypeWriteInt8CodeConstructAbility;
+extern const JSC::ConstructorKind s_jsBufferPrototypeWriteInt8CodeConstructorKind;
+extern const char* const s_jsBufferPrototypeWriteUInt8Code;
+extern const int s_jsBufferPrototypeWriteUInt8CodeLength;
+extern const JSC::ConstructAbility s_jsBufferPrototypeWriteUInt8CodeConstructAbility;
+extern const JSC::ConstructorKind s_jsBufferPrototypeWriteUInt8CodeConstructorKind;
+extern const char* const s_jsBufferPrototypeWriteInt16LECode;
+extern const int s_jsBufferPrototypeWriteInt16LECodeLength;
+extern const JSC::ConstructAbility s_jsBufferPrototypeWriteInt16LECodeConstructAbility;
+extern const JSC::ConstructorKind s_jsBufferPrototypeWriteInt16LECodeConstructorKind;
+extern const char* const s_jsBufferPrototypeWriteInt16BECode;
+extern const int s_jsBufferPrototypeWriteInt16BECodeLength;
+extern const JSC::ConstructAbility s_jsBufferPrototypeWriteInt16BECodeConstructAbility;
+extern const JSC::ConstructorKind s_jsBufferPrototypeWriteInt16BECodeConstructorKind;
+extern const char* const s_jsBufferPrototypeWriteUInt16LECode;
+extern const int s_jsBufferPrototypeWriteUInt16LECodeLength;
+extern const JSC::ConstructAbility s_jsBufferPrototypeWriteUInt16LECodeConstructAbility;
+extern const JSC::ConstructorKind s_jsBufferPrototypeWriteUInt16LECodeConstructorKind;
+extern const char* const s_jsBufferPrototypeWriteUInt16BECode;
+extern const int s_jsBufferPrototypeWriteUInt16BECodeLength;
+extern const JSC::ConstructAbility s_jsBufferPrototypeWriteUInt16BECodeConstructAbility;
+extern const JSC::ConstructorKind s_jsBufferPrototypeWriteUInt16BECodeConstructorKind;
+extern const char* const s_jsBufferPrototypeWriteInt32LECode;
+extern const int s_jsBufferPrototypeWriteInt32LECodeLength;
+extern const JSC::ConstructAbility s_jsBufferPrototypeWriteInt32LECodeConstructAbility;
+extern const JSC::ConstructorKind s_jsBufferPrototypeWriteInt32LECodeConstructorKind;
+extern const char* const s_jsBufferPrototypeWriteInt32BECode;
+extern const int s_jsBufferPrototypeWriteInt32BECodeLength;
+extern const JSC::ConstructAbility s_jsBufferPrototypeWriteInt32BECodeConstructAbility;
+extern const JSC::ConstructorKind s_jsBufferPrototypeWriteInt32BECodeConstructorKind;
+extern const char* const s_jsBufferPrototypeWriteUInt32LECode;
+extern const int s_jsBufferPrototypeWriteUInt32LECodeLength;
+extern const JSC::ConstructAbility s_jsBufferPrototypeWriteUInt32LECodeConstructAbility;
+extern const JSC::ConstructorKind s_jsBufferPrototypeWriteUInt32LECodeConstructorKind;
+extern const char* const s_jsBufferPrototypeWriteUInt32BECode;
+extern const int s_jsBufferPrototypeWriteUInt32BECodeLength;
+extern const JSC::ConstructAbility s_jsBufferPrototypeWriteUInt32BECodeConstructAbility;
+extern const JSC::ConstructorKind s_jsBufferPrototypeWriteUInt32BECodeConstructorKind;
+extern const char* const s_jsBufferPrototypeWriteFloatLECode;
+extern const int s_jsBufferPrototypeWriteFloatLECodeLength;
+extern const JSC::ConstructAbility s_jsBufferPrototypeWriteFloatLECodeConstructAbility;
+extern const JSC::ConstructorKind s_jsBufferPrototypeWriteFloatLECodeConstructorKind;
+extern const char* const s_jsBufferPrototypeWriteFloatBECode;
+extern const int s_jsBufferPrototypeWriteFloatBECodeLength;
+extern const JSC::ConstructAbility s_jsBufferPrototypeWriteFloatBECodeConstructAbility;
+extern const JSC::ConstructorKind s_jsBufferPrototypeWriteFloatBECodeConstructorKind;
+extern const char* const s_jsBufferPrototypeWriteDoubleLECode;
+extern const int s_jsBufferPrototypeWriteDoubleLECodeLength;
+extern const JSC::ConstructAbility s_jsBufferPrototypeWriteDoubleLECodeConstructAbility;
+extern const JSC::ConstructorKind s_jsBufferPrototypeWriteDoubleLECodeConstructorKind;
+extern const char* const s_jsBufferPrototypeWriteDoubleBECode;
+extern const int s_jsBufferPrototypeWriteDoubleBECodeLength;
+extern const JSC::ConstructAbility s_jsBufferPrototypeWriteDoubleBECodeConstructAbility;
+extern const JSC::ConstructorKind s_jsBufferPrototypeWriteDoubleBECodeConstructorKind;
+extern const char* const s_jsBufferPrototypeWriteBigInt64LECode;
+extern const int s_jsBufferPrototypeWriteBigInt64LECodeLength;
+extern const JSC::ConstructAbility s_jsBufferPrototypeWriteBigInt64LECodeConstructAbility;
+extern const JSC::ConstructorKind s_jsBufferPrototypeWriteBigInt64LECodeConstructorKind;
+extern const char* const s_jsBufferPrototypeWriteBigInt64BECode;
+extern const int s_jsBufferPrototypeWriteBigInt64BECodeLength;
+extern const JSC::ConstructAbility s_jsBufferPrototypeWriteBigInt64BECodeConstructAbility;
+extern const JSC::ConstructorKind s_jsBufferPrototypeWriteBigInt64BECodeConstructorKind;
+extern const char* const s_jsBufferPrototypeWriteBigUInt64LECode;
+extern const int s_jsBufferPrototypeWriteBigUInt64LECodeLength;
+extern const JSC::ConstructAbility s_jsBufferPrototypeWriteBigUInt64LECodeConstructAbility;
+extern const JSC::ConstructorKind s_jsBufferPrototypeWriteBigUInt64LECodeConstructorKind;
+extern const char* const s_jsBufferPrototypeWriteBigUInt64BECode;
+extern const int s_jsBufferPrototypeWriteBigUInt64BECodeLength;
+extern const JSC::ConstructAbility s_jsBufferPrototypeWriteBigUInt64BECodeConstructAbility;
+extern const JSC::ConstructorKind s_jsBufferPrototypeWriteBigUInt64BECodeConstructorKind;
+extern const char* const s_jsBufferPrototypeSliceCode;
+extern const int s_jsBufferPrototypeSliceCodeLength;
+extern const JSC::ConstructAbility s_jsBufferPrototypeSliceCodeConstructAbility;
+extern const JSC::ConstructorKind s_jsBufferPrototypeSliceCodeConstructorKind;
+extern const char* const s_jsBufferPrototypeUtf8WriteCode;
+extern const int s_jsBufferPrototypeUtf8WriteCodeLength;
+extern const JSC::ConstructAbility s_jsBufferPrototypeUtf8WriteCodeConstructAbility;
+extern const JSC::ConstructorKind s_jsBufferPrototypeUtf8WriteCodeConstructorKind;
+extern const char* const s_jsBufferPrototypeUcs2WriteCode;
+extern const int s_jsBufferPrototypeUcs2WriteCodeLength;
+extern const JSC::ConstructAbility s_jsBufferPrototypeUcs2WriteCodeConstructAbility;
+extern const JSC::ConstructorKind s_jsBufferPrototypeUcs2WriteCodeConstructorKind;
+extern const char* const s_jsBufferPrototypeUtf16leWriteCode;
+extern const int s_jsBufferPrototypeUtf16leWriteCodeLength;
+extern const JSC::ConstructAbility s_jsBufferPrototypeUtf16leWriteCodeConstructAbility;
+extern const JSC::ConstructorKind s_jsBufferPrototypeUtf16leWriteCodeConstructorKind;
+extern const char* const s_jsBufferPrototypeLatin1WriteCode;
+extern const int s_jsBufferPrototypeLatin1WriteCodeLength;
+extern const JSC::ConstructAbility s_jsBufferPrototypeLatin1WriteCodeConstructAbility;
+extern const JSC::ConstructorKind s_jsBufferPrototypeLatin1WriteCodeConstructorKind;
+extern const char* const s_jsBufferPrototypeAsciiWriteCode;
+extern const int s_jsBufferPrototypeAsciiWriteCodeLength;
+extern const JSC::ConstructAbility s_jsBufferPrototypeAsciiWriteCodeConstructAbility;
+extern const JSC::ConstructorKind s_jsBufferPrototypeAsciiWriteCodeConstructorKind;
+extern const char* const s_jsBufferPrototypeBase64WriteCode;
+extern const int s_jsBufferPrototypeBase64WriteCodeLength;
+extern const JSC::ConstructAbility s_jsBufferPrototypeBase64WriteCodeConstructAbility;
+extern const JSC::ConstructorKind s_jsBufferPrototypeBase64WriteCodeConstructorKind;
+extern const char* const s_jsBufferPrototypeBase64urlWriteCode;
+extern const int s_jsBufferPrototypeBase64urlWriteCodeLength;
+extern const JSC::ConstructAbility s_jsBufferPrototypeBase64urlWriteCodeConstructAbility;
+extern const JSC::ConstructorKind s_jsBufferPrototypeBase64urlWriteCodeConstructorKind;
+extern const char* const s_jsBufferPrototypeHexWriteCode;
+extern const int s_jsBufferPrototypeHexWriteCodeLength;
+extern const JSC::ConstructAbility s_jsBufferPrototypeHexWriteCodeConstructAbility;
+extern const JSC::ConstructorKind s_jsBufferPrototypeHexWriteCodeConstructorKind;
+extern const char* const s_jsBufferPrototypeUtf8SliceCode;
+extern const int s_jsBufferPrototypeUtf8SliceCodeLength;
+extern const JSC::ConstructAbility s_jsBufferPrototypeUtf8SliceCodeConstructAbility;
+extern const JSC::ConstructorKind s_jsBufferPrototypeUtf8SliceCodeConstructorKind;
+extern const char* const s_jsBufferPrototypeUcs2SliceCode;
+extern const int s_jsBufferPrototypeUcs2SliceCodeLength;
+extern const JSC::ConstructAbility s_jsBufferPrototypeUcs2SliceCodeConstructAbility;
+extern const JSC::ConstructorKind s_jsBufferPrototypeUcs2SliceCodeConstructorKind;
+extern const char* const s_jsBufferPrototypeUtf16leSliceCode;
+extern const int s_jsBufferPrototypeUtf16leSliceCodeLength;
+extern const JSC::ConstructAbility s_jsBufferPrototypeUtf16leSliceCodeConstructAbility;
+extern const JSC::ConstructorKind s_jsBufferPrototypeUtf16leSliceCodeConstructorKind;
+extern const char* const s_jsBufferPrototypeLatin1SliceCode;
+extern const int s_jsBufferPrototypeLatin1SliceCodeLength;
+extern const JSC::ConstructAbility s_jsBufferPrototypeLatin1SliceCodeConstructAbility;
+extern const JSC::ConstructorKind s_jsBufferPrototypeLatin1SliceCodeConstructorKind;
+extern const char* const s_jsBufferPrototypeAsciiSliceCode;
+extern const int s_jsBufferPrototypeAsciiSliceCodeLength;
+extern const JSC::ConstructAbility s_jsBufferPrototypeAsciiSliceCodeConstructAbility;
+extern const JSC::ConstructorKind s_jsBufferPrototypeAsciiSliceCodeConstructorKind;
+extern const char* const s_jsBufferPrototypeBase64SliceCode;
+extern const int s_jsBufferPrototypeBase64SliceCodeLength;
+extern const JSC::ConstructAbility s_jsBufferPrototypeBase64SliceCodeConstructAbility;
+extern const JSC::ConstructorKind s_jsBufferPrototypeBase64SliceCodeConstructorKind;
+extern const char* const s_jsBufferPrototypeBase64urlSliceCode;
+extern const int s_jsBufferPrototypeBase64urlSliceCodeLength;
+extern const JSC::ConstructAbility s_jsBufferPrototypeBase64urlSliceCodeConstructAbility;
+extern const JSC::ConstructorKind s_jsBufferPrototypeBase64urlSliceCodeConstructorKind;
+extern const char* const s_jsBufferPrototypeHexSliceCode;
+extern const int s_jsBufferPrototypeHexSliceCodeLength;
+extern const JSC::ConstructAbility s_jsBufferPrototypeHexSliceCodeConstructAbility;
+extern const JSC::ConstructorKind s_jsBufferPrototypeHexSliceCodeConstructorKind;
+extern const char* const s_jsBufferPrototypeToJSONCode;
+extern const int s_jsBufferPrototypeToJSONCodeLength;
+extern const JSC::ConstructAbility s_jsBufferPrototypeToJSONCodeConstructAbility;
+extern const JSC::ConstructorKind s_jsBufferPrototypeToJSONCodeConstructorKind;
+extern const char* const s_jsBufferPrototypeSubarrayCode;
+extern const int s_jsBufferPrototypeSubarrayCodeLength;
+extern const JSC::ConstructAbility s_jsBufferPrototypeSubarrayCodeConstructAbility;
+extern const JSC::ConstructorKind s_jsBufferPrototypeSubarrayCodeConstructorKind;
+extern const char* const s_jsBufferPrototypeInitializeBunBufferCode;
+extern const int s_jsBufferPrototypeInitializeBunBufferCodeLength;
+extern const JSC::ConstructAbility s_jsBufferPrototypeInitializeBunBufferCodeConstructAbility;
+extern const JSC::ConstructorKind s_jsBufferPrototypeInitializeBunBufferCodeConstructorKind;
+
+#define WEBCORE_FOREACH_JSBUFFERPROTOTYPE_BUILTIN_DATA(macro) \
+ macro(setBigUint64, jsBufferPrototypeSetBigUint64, 3) \
+ macro(readInt8, jsBufferPrototypeReadInt8, 1) \
+ macro(readUInt8, jsBufferPrototypeReadUInt8, 1) \
+ macro(readInt16LE, jsBufferPrototypeReadInt16LE, 1) \
+ macro(readInt16BE, jsBufferPrototypeReadInt16BE, 1) \
+ macro(readUInt16LE, jsBufferPrototypeReadUInt16LE, 1) \
+ macro(readUInt16BE, jsBufferPrototypeReadUInt16BE, 1) \
+ macro(readInt32LE, jsBufferPrototypeReadInt32LE, 1) \
+ macro(readInt32BE, jsBufferPrototypeReadInt32BE, 1) \
+ macro(readUInt32LE, jsBufferPrototypeReadUInt32LE, 1) \
+ macro(readUInt32BE, jsBufferPrototypeReadUInt32BE, 1) \
+ macro(readFloatLE, jsBufferPrototypeReadFloatLE, 1) \
+ macro(readFloatBE, jsBufferPrototypeReadFloatBE, 1) \
+ macro(readDoubleLE, jsBufferPrototypeReadDoubleLE, 1) \
+ macro(readDoubleBE, jsBufferPrototypeReadDoubleBE, 1) \
+ macro(readBigInt64LE, jsBufferPrototypeReadBigInt64LE, 1) \
+ macro(readBigInt64BE, jsBufferPrototypeReadBigInt64BE, 1) \
+ macro(readBigUInt64LE, jsBufferPrototypeReadBigUInt64LE, 1) \
+ macro(readBigUInt64BE, jsBufferPrototypeReadBigUInt64BE, 1) \
+ macro(writeInt8, jsBufferPrototypeWriteInt8, 2) \
+ macro(writeUInt8, jsBufferPrototypeWriteUInt8, 2) \
+ macro(writeInt16LE, jsBufferPrototypeWriteInt16LE, 2) \
+ macro(writeInt16BE, jsBufferPrototypeWriteInt16BE, 2) \
+ macro(writeUInt16LE, jsBufferPrototypeWriteUInt16LE, 2) \
+ macro(writeUInt16BE, jsBufferPrototypeWriteUInt16BE, 2) \
+ macro(writeInt32LE, jsBufferPrototypeWriteInt32LE, 2) \
+ macro(writeInt32BE, jsBufferPrototypeWriteInt32BE, 2) \
+ macro(writeUInt32LE, jsBufferPrototypeWriteUInt32LE, 2) \
+ macro(writeUInt32BE, jsBufferPrototypeWriteUInt32BE, 2) \
+ macro(writeFloatLE, jsBufferPrototypeWriteFloatLE, 2) \
+ macro(writeFloatBE, jsBufferPrototypeWriteFloatBE, 2) \
+ macro(writeDoubleLE, jsBufferPrototypeWriteDoubleLE, 2) \
+ macro(writeDoubleBE, jsBufferPrototypeWriteDoubleBE, 2) \
+ macro(writeBigInt64LE, jsBufferPrototypeWriteBigInt64LE, 2) \
+ macro(writeBigInt64BE, jsBufferPrototypeWriteBigInt64BE, 2) \
+ macro(writeBigUInt64LE, jsBufferPrototypeWriteBigUInt64LE, 2) \
+ macro(writeBigUInt64BE, jsBufferPrototypeWriteBigUInt64BE, 2) \
+ macro(slice, jsBufferPrototypeSlice, 2) \
+ macro(utf8Write, jsBufferPrototypeUtf8Write, 3) \
+ macro(ucs2Write, jsBufferPrototypeUcs2Write, 3) \
+ macro(utf16leWrite, jsBufferPrototypeUtf16leWrite, 3) \
+ macro(latin1Write, jsBufferPrototypeLatin1Write, 3) \
+ macro(asciiWrite, jsBufferPrototypeAsciiWrite, 3) \
+ macro(base64Write, jsBufferPrototypeBase64Write, 3) \
+ macro(base64urlWrite, jsBufferPrototypeBase64urlWrite, 3) \
+ macro(hexWrite, jsBufferPrototypeHexWrite, 3) \
+ macro(utf8Slice, jsBufferPrototypeUtf8Slice, 2) \
+ macro(ucs2Slice, jsBufferPrototypeUcs2Slice, 2) \
+ macro(utf16leSlice, jsBufferPrototypeUtf16leSlice, 2) \
+ macro(latin1Slice, jsBufferPrototypeLatin1Slice, 2) \
+ macro(asciiSlice, jsBufferPrototypeAsciiSlice, 2) \
+ macro(base64Slice, jsBufferPrototypeBase64Slice, 2) \
+ macro(base64urlSlice, jsBufferPrototypeBase64urlSlice, 2) \
+ macro(hexSlice, jsBufferPrototypeHexSlice, 2) \
+ macro(toJSON, jsBufferPrototypeToJSON, 0) \
+ macro(subarray, jsBufferPrototypeSubarray, 2) \
+ macro(initializeBunBuffer, jsBufferPrototypeInitializeBunBuffer, 1) \
+
+#define WEBCORE_BUILTIN_JSBUFFERPROTOTYPE_SETBIGUINT64 1
+#define WEBCORE_BUILTIN_JSBUFFERPROTOTYPE_READINT8 1
+#define WEBCORE_BUILTIN_JSBUFFERPROTOTYPE_READUINT8 1
+#define WEBCORE_BUILTIN_JSBUFFERPROTOTYPE_READINT16LE 1
+#define WEBCORE_BUILTIN_JSBUFFERPROTOTYPE_READINT16BE 1
+#define WEBCORE_BUILTIN_JSBUFFERPROTOTYPE_READUINT16LE 1
+#define WEBCORE_BUILTIN_JSBUFFERPROTOTYPE_READUINT16BE 1
+#define WEBCORE_BUILTIN_JSBUFFERPROTOTYPE_READINT32LE 1
+#define WEBCORE_BUILTIN_JSBUFFERPROTOTYPE_READINT32BE 1
+#define WEBCORE_BUILTIN_JSBUFFERPROTOTYPE_READUINT32LE 1
+#define WEBCORE_BUILTIN_JSBUFFERPROTOTYPE_READUINT32BE 1
+#define WEBCORE_BUILTIN_JSBUFFERPROTOTYPE_READFLOATLE 1
+#define WEBCORE_BUILTIN_JSBUFFERPROTOTYPE_READFLOATBE 1
+#define WEBCORE_BUILTIN_JSBUFFERPROTOTYPE_READDOUBLELE 1
+#define WEBCORE_BUILTIN_JSBUFFERPROTOTYPE_READDOUBLEBE 1
+#define WEBCORE_BUILTIN_JSBUFFERPROTOTYPE_READBIGINT64LE 1
+#define WEBCORE_BUILTIN_JSBUFFERPROTOTYPE_READBIGINT64BE 1
+#define WEBCORE_BUILTIN_JSBUFFERPROTOTYPE_READBIGUINT64LE 1
+#define WEBCORE_BUILTIN_JSBUFFERPROTOTYPE_READBIGUINT64BE 1
+#define WEBCORE_BUILTIN_JSBUFFERPROTOTYPE_WRITEINT8 1
+#define WEBCORE_BUILTIN_JSBUFFERPROTOTYPE_WRITEUINT8 1
+#define WEBCORE_BUILTIN_JSBUFFERPROTOTYPE_WRITEINT16LE 1
+#define WEBCORE_BUILTIN_JSBUFFERPROTOTYPE_WRITEINT16BE 1
+#define WEBCORE_BUILTIN_JSBUFFERPROTOTYPE_WRITEUINT16LE 1
+#define WEBCORE_BUILTIN_JSBUFFERPROTOTYPE_WRITEUINT16BE 1
+#define WEBCORE_BUILTIN_JSBUFFERPROTOTYPE_WRITEINT32LE 1
+#define WEBCORE_BUILTIN_JSBUFFERPROTOTYPE_WRITEINT32BE 1
+#define WEBCORE_BUILTIN_JSBUFFERPROTOTYPE_WRITEUINT32LE 1
+#define WEBCORE_BUILTIN_JSBUFFERPROTOTYPE_WRITEUINT32BE 1
+#define WEBCORE_BUILTIN_JSBUFFERPROTOTYPE_WRITEFLOATLE 1
+#define WEBCORE_BUILTIN_JSBUFFERPROTOTYPE_WRITEFLOATBE 1
+#define WEBCORE_BUILTIN_JSBUFFERPROTOTYPE_WRITEDOUBLELE 1
+#define WEBCORE_BUILTIN_JSBUFFERPROTOTYPE_WRITEDOUBLEBE 1
+#define WEBCORE_BUILTIN_JSBUFFERPROTOTYPE_WRITEBIGINT64LE 1
+#define WEBCORE_BUILTIN_JSBUFFERPROTOTYPE_WRITEBIGINT64BE 1
+#define WEBCORE_BUILTIN_JSBUFFERPROTOTYPE_WRITEBIGUINT64LE 1
+#define WEBCORE_BUILTIN_JSBUFFERPROTOTYPE_WRITEBIGUINT64BE 1
+#define WEBCORE_BUILTIN_JSBUFFERPROTOTYPE_SLICE 1
+#define WEBCORE_BUILTIN_JSBUFFERPROTOTYPE_UTF8WRITE 1
+#define WEBCORE_BUILTIN_JSBUFFERPROTOTYPE_UCS2WRITE 1
+#define WEBCORE_BUILTIN_JSBUFFERPROTOTYPE_UTF16LEWRITE 1
+#define WEBCORE_BUILTIN_JSBUFFERPROTOTYPE_LATIN1WRITE 1
+#define WEBCORE_BUILTIN_JSBUFFERPROTOTYPE_ASCIIWRITE 1
+#define WEBCORE_BUILTIN_JSBUFFERPROTOTYPE_BASE64WRITE 1
+#define WEBCORE_BUILTIN_JSBUFFERPROTOTYPE_BASE64URLWRITE 1
+#define WEBCORE_BUILTIN_JSBUFFERPROTOTYPE_HEXWRITE 1
+#define WEBCORE_BUILTIN_JSBUFFERPROTOTYPE_UTF8SLICE 1
+#define WEBCORE_BUILTIN_JSBUFFERPROTOTYPE_UCS2SLICE 1
+#define WEBCORE_BUILTIN_JSBUFFERPROTOTYPE_UTF16LESLICE 1
+#define WEBCORE_BUILTIN_JSBUFFERPROTOTYPE_LATIN1SLICE 1
+#define WEBCORE_BUILTIN_JSBUFFERPROTOTYPE_ASCIISLICE 1
+#define WEBCORE_BUILTIN_JSBUFFERPROTOTYPE_BASE64SLICE 1
+#define WEBCORE_BUILTIN_JSBUFFERPROTOTYPE_BASE64URLSLICE 1
+#define WEBCORE_BUILTIN_JSBUFFERPROTOTYPE_HEXSLICE 1
+#define WEBCORE_BUILTIN_JSBUFFERPROTOTYPE_TOJSON 1
+#define WEBCORE_BUILTIN_JSBUFFERPROTOTYPE_SUBARRAY 1
+#define WEBCORE_BUILTIN_JSBUFFERPROTOTYPE_INITIALIZEBUNBUFFER 1
+
+#define WEBCORE_FOREACH_JSBUFFERPROTOTYPE_BUILTIN_CODE(macro) \
+ macro(jsBufferPrototypeSetBigUint64Code, setBigUint64, ASCIILiteral(), s_jsBufferPrototypeSetBigUint64CodeLength) \
+ macro(jsBufferPrototypeReadInt8Code, readInt8, ASCIILiteral(), s_jsBufferPrototypeReadInt8CodeLength) \
+ macro(jsBufferPrototypeReadUInt8Code, readUInt8, ASCIILiteral(), s_jsBufferPrototypeReadUInt8CodeLength) \
+ macro(jsBufferPrototypeReadInt16LECode, readInt16LE, ASCIILiteral(), s_jsBufferPrototypeReadInt16LECodeLength) \
+ macro(jsBufferPrototypeReadInt16BECode, readInt16BE, ASCIILiteral(), s_jsBufferPrototypeReadInt16BECodeLength) \
+ macro(jsBufferPrototypeReadUInt16LECode, readUInt16LE, ASCIILiteral(), s_jsBufferPrototypeReadUInt16LECodeLength) \
+ macro(jsBufferPrototypeReadUInt16BECode, readUInt16BE, ASCIILiteral(), s_jsBufferPrototypeReadUInt16BECodeLength) \
+ macro(jsBufferPrototypeReadInt32LECode, readInt32LE, ASCIILiteral(), s_jsBufferPrototypeReadInt32LECodeLength) \
+ macro(jsBufferPrototypeReadInt32BECode, readInt32BE, ASCIILiteral(), s_jsBufferPrototypeReadInt32BECodeLength) \
+ macro(jsBufferPrototypeReadUInt32LECode, readUInt32LE, ASCIILiteral(), s_jsBufferPrototypeReadUInt32LECodeLength) \
+ macro(jsBufferPrototypeReadUInt32BECode, readUInt32BE, ASCIILiteral(), s_jsBufferPrototypeReadUInt32BECodeLength) \
+ macro(jsBufferPrototypeReadFloatLECode, readFloatLE, ASCIILiteral(), s_jsBufferPrototypeReadFloatLECodeLength) \
+ macro(jsBufferPrototypeReadFloatBECode, readFloatBE, ASCIILiteral(), s_jsBufferPrototypeReadFloatBECodeLength) \
+ macro(jsBufferPrototypeReadDoubleLECode, readDoubleLE, ASCIILiteral(), s_jsBufferPrototypeReadDoubleLECodeLength) \
+ macro(jsBufferPrototypeReadDoubleBECode, readDoubleBE, ASCIILiteral(), s_jsBufferPrototypeReadDoubleBECodeLength) \
+ macro(jsBufferPrototypeReadBigInt64LECode, readBigInt64LE, ASCIILiteral(), s_jsBufferPrototypeReadBigInt64LECodeLength) \
+ macro(jsBufferPrototypeReadBigInt64BECode, readBigInt64BE, ASCIILiteral(), s_jsBufferPrototypeReadBigInt64BECodeLength) \
+ macro(jsBufferPrototypeReadBigUInt64LECode, readBigUInt64LE, ASCIILiteral(), s_jsBufferPrototypeReadBigUInt64LECodeLength) \
+ macro(jsBufferPrototypeReadBigUInt64BECode, readBigUInt64BE, ASCIILiteral(), s_jsBufferPrototypeReadBigUInt64BECodeLength) \
+ macro(jsBufferPrototypeWriteInt8Code, writeInt8, ASCIILiteral(), s_jsBufferPrototypeWriteInt8CodeLength) \
+ macro(jsBufferPrototypeWriteUInt8Code, writeUInt8, ASCIILiteral(), s_jsBufferPrototypeWriteUInt8CodeLength) \
+ macro(jsBufferPrototypeWriteInt16LECode, writeInt16LE, ASCIILiteral(), s_jsBufferPrototypeWriteInt16LECodeLength) \
+ macro(jsBufferPrototypeWriteInt16BECode, writeInt16BE, ASCIILiteral(), s_jsBufferPrototypeWriteInt16BECodeLength) \
+ macro(jsBufferPrototypeWriteUInt16LECode, writeUInt16LE, ASCIILiteral(), s_jsBufferPrototypeWriteUInt16LECodeLength) \
+ macro(jsBufferPrototypeWriteUInt16BECode, writeUInt16BE, ASCIILiteral(), s_jsBufferPrototypeWriteUInt16BECodeLength) \
+ macro(jsBufferPrototypeWriteInt32LECode, writeInt32LE, ASCIILiteral(), s_jsBufferPrototypeWriteInt32LECodeLength) \
+ macro(jsBufferPrototypeWriteInt32BECode, writeInt32BE, ASCIILiteral(), s_jsBufferPrototypeWriteInt32BECodeLength) \
+ macro(jsBufferPrototypeWriteUInt32LECode, writeUInt32LE, ASCIILiteral(), s_jsBufferPrototypeWriteUInt32LECodeLength) \
+ macro(jsBufferPrototypeWriteUInt32BECode, writeUInt32BE, ASCIILiteral(), s_jsBufferPrototypeWriteUInt32BECodeLength) \
+ macro(jsBufferPrototypeWriteFloatLECode, writeFloatLE, ASCIILiteral(), s_jsBufferPrototypeWriteFloatLECodeLength) \
+ macro(jsBufferPrototypeWriteFloatBECode, writeFloatBE, ASCIILiteral(), s_jsBufferPrototypeWriteFloatBECodeLength) \
+ macro(jsBufferPrototypeWriteDoubleLECode, writeDoubleLE, ASCIILiteral(), s_jsBufferPrototypeWriteDoubleLECodeLength) \
+ macro(jsBufferPrototypeWriteDoubleBECode, writeDoubleBE, ASCIILiteral(), s_jsBufferPrototypeWriteDoubleBECodeLength) \
+ macro(jsBufferPrototypeWriteBigInt64LECode, writeBigInt64LE, ASCIILiteral(), s_jsBufferPrototypeWriteBigInt64LECodeLength) \
+ macro(jsBufferPrototypeWriteBigInt64BECode, writeBigInt64BE, ASCIILiteral(), s_jsBufferPrototypeWriteBigInt64BECodeLength) \
+ macro(jsBufferPrototypeWriteBigUInt64LECode, writeBigUInt64LE, ASCIILiteral(), s_jsBufferPrototypeWriteBigUInt64LECodeLength) \
+ macro(jsBufferPrototypeWriteBigUInt64BECode, writeBigUInt64BE, ASCIILiteral(), s_jsBufferPrototypeWriteBigUInt64BECodeLength) \
+ macro(jsBufferPrototypeSliceCode, slice, ASCIILiteral(), s_jsBufferPrototypeSliceCodeLength) \
+ macro(jsBufferPrototypeUtf8WriteCode, utf8Write, ASCIILiteral(), s_jsBufferPrototypeUtf8WriteCodeLength) \
+ macro(jsBufferPrototypeUcs2WriteCode, ucs2Write, ASCIILiteral(), s_jsBufferPrototypeUcs2WriteCodeLength) \
+ macro(jsBufferPrototypeUtf16leWriteCode, utf16leWrite, ASCIILiteral(), s_jsBufferPrototypeUtf16leWriteCodeLength) \
+ macro(jsBufferPrototypeLatin1WriteCode, latin1Write, ASCIILiteral(), s_jsBufferPrototypeLatin1WriteCodeLength) \
+ macro(jsBufferPrototypeAsciiWriteCode, asciiWrite, ASCIILiteral(), s_jsBufferPrototypeAsciiWriteCodeLength) \
+ macro(jsBufferPrototypeBase64WriteCode, base64Write, ASCIILiteral(), s_jsBufferPrototypeBase64WriteCodeLength) \
+ macro(jsBufferPrototypeBase64urlWriteCode, base64urlWrite, ASCIILiteral(), s_jsBufferPrototypeBase64urlWriteCodeLength) \
+ macro(jsBufferPrototypeHexWriteCode, hexWrite, ASCIILiteral(), s_jsBufferPrototypeHexWriteCodeLength) \
+ macro(jsBufferPrototypeUtf8SliceCode, utf8Slice, ASCIILiteral(), s_jsBufferPrototypeUtf8SliceCodeLength) \
+ macro(jsBufferPrototypeUcs2SliceCode, ucs2Slice, ASCIILiteral(), s_jsBufferPrototypeUcs2SliceCodeLength) \
+ macro(jsBufferPrototypeUtf16leSliceCode, utf16leSlice, ASCIILiteral(), s_jsBufferPrototypeUtf16leSliceCodeLength) \
+ macro(jsBufferPrototypeLatin1SliceCode, latin1Slice, ASCIILiteral(), s_jsBufferPrototypeLatin1SliceCodeLength) \
+ macro(jsBufferPrototypeAsciiSliceCode, asciiSlice, ASCIILiteral(), s_jsBufferPrototypeAsciiSliceCodeLength) \
+ macro(jsBufferPrototypeBase64SliceCode, base64Slice, ASCIILiteral(), s_jsBufferPrototypeBase64SliceCodeLength) \
+ macro(jsBufferPrototypeBase64urlSliceCode, base64urlSlice, ASCIILiteral(), s_jsBufferPrototypeBase64urlSliceCodeLength) \
+ macro(jsBufferPrototypeHexSliceCode, hexSlice, ASCIILiteral(), s_jsBufferPrototypeHexSliceCodeLength) \
+ macro(jsBufferPrototypeToJSONCode, toJSON, ASCIILiteral(), s_jsBufferPrototypeToJSONCodeLength) \
+ macro(jsBufferPrototypeSubarrayCode, subarray, ASCIILiteral(), s_jsBufferPrototypeSubarrayCodeLength) \
+ macro(jsBufferPrototypeInitializeBunBufferCode, initializeBunBuffer, ASCIILiteral(), s_jsBufferPrototypeInitializeBunBufferCodeLength) \
+
+#define WEBCORE_FOREACH_JSBUFFERPROTOTYPE_BUILTIN_FUNCTION_NAME(macro) \
+ macro(asciiSlice) \
+ macro(asciiWrite) \
+ macro(base64Slice) \
+ macro(base64Write) \
+ macro(base64urlSlice) \
+ macro(base64urlWrite) \
+ macro(hexSlice) \
+ macro(hexWrite) \
+ macro(initializeBunBuffer) \
+ macro(latin1Slice) \
+ macro(latin1Write) \
+ macro(readBigInt64BE) \
+ macro(readBigInt64LE) \
+ macro(readBigUInt64BE) \
+ macro(readBigUInt64LE) \
+ macro(readDoubleBE) \
+ macro(readDoubleLE) \
+ macro(readFloatBE) \
+ macro(readFloatLE) \
+ macro(readInt16BE) \
+ macro(readInt16LE) \
+ macro(readInt32BE) \
+ macro(readInt32LE) \
+ macro(readInt8) \
+ macro(readUInt16BE) \
+ macro(readUInt16LE) \
+ macro(readUInt32BE) \
+ macro(readUInt32LE) \
+ macro(readUInt8) \
+ macro(setBigUint64) \
+ macro(slice) \
+ macro(subarray) \
+ macro(toJSON) \
+ macro(ucs2Slice) \
+ macro(ucs2Write) \
+ macro(utf16leSlice) \
+ macro(utf16leWrite) \
+ macro(utf8Slice) \
+ macro(utf8Write) \
+ macro(writeBigInt64BE) \
+ macro(writeBigInt64LE) \
+ macro(writeBigUInt64BE) \
+ macro(writeBigUInt64LE) \
+ macro(writeDoubleBE) \
+ macro(writeDoubleLE) \
+ macro(writeFloatBE) \
+ macro(writeFloatLE) \
+ macro(writeInt16BE) \
+ macro(writeInt16LE) \
+ macro(writeInt32BE) \
+ macro(writeInt32LE) \
+ macro(writeInt8) \
+ macro(writeUInt16BE) \
+ macro(writeUInt16LE) \
+ macro(writeUInt32BE) \
+ macro(writeUInt32LE) \
+ macro(writeUInt8) \
+
+#define DECLARE_BUILTIN_GENERATOR(codeName, functionName, overriddenName, argumentCount) \
+ JSC::FunctionExecutable* codeName##Generator(JSC::VM&);
+
+WEBCORE_FOREACH_JSBUFFERPROTOTYPE_BUILTIN_CODE(DECLARE_BUILTIN_GENERATOR)
+#undef DECLARE_BUILTIN_GENERATOR
+
+class JSBufferPrototypeBuiltinsWrapper : private JSC::WeakHandleOwner {
+public:
+ explicit JSBufferPrototypeBuiltinsWrapper(JSC::VM& vm)
+ : m_vm(vm)
+ WEBCORE_FOREACH_JSBUFFERPROTOTYPE_BUILTIN_FUNCTION_NAME(INITIALIZE_BUILTIN_NAMES)
+#define INITIALIZE_BUILTIN_SOURCE_MEMBERS(name, functionName, overriddenName, length) , m_##name##Source(JSC::makeSource(StringImpl::createWithoutCopying(s_##name, length), { }))
+ WEBCORE_FOREACH_JSBUFFERPROTOTYPE_BUILTIN_CODE(INITIALIZE_BUILTIN_SOURCE_MEMBERS)
+#undef INITIALIZE_BUILTIN_SOURCE_MEMBERS
+ {
+ }
+
+#define EXPOSE_BUILTIN_EXECUTABLES(name, functionName, overriddenName, length) \
+ JSC::UnlinkedFunctionExecutable* name##Executable(); \
+ const JSC::SourceCode& name##Source() const { return m_##name##Source; }
+ WEBCORE_FOREACH_JSBUFFERPROTOTYPE_BUILTIN_CODE(EXPOSE_BUILTIN_EXECUTABLES)
+#undef EXPOSE_BUILTIN_EXECUTABLES
+
+ WEBCORE_FOREACH_JSBUFFERPROTOTYPE_BUILTIN_FUNCTION_NAME(DECLARE_BUILTIN_IDENTIFIER_ACCESSOR)
+
+ void exportNames();
+
+private:
+ JSC::VM& m_vm;
+
+ WEBCORE_FOREACH_JSBUFFERPROTOTYPE_BUILTIN_FUNCTION_NAME(DECLARE_BUILTIN_NAMES)
+
+#define DECLARE_BUILTIN_SOURCE_MEMBERS(name, functionName, overriddenName, length) \
+ JSC::SourceCode m_##name##Source;\
+ JSC::Weak<JSC::UnlinkedFunctionExecutable> m_##name##Executable;
+ WEBCORE_FOREACH_JSBUFFERPROTOTYPE_BUILTIN_CODE(DECLARE_BUILTIN_SOURCE_MEMBERS)
+#undef DECLARE_BUILTIN_SOURCE_MEMBERS
+
+};
+
+#define DEFINE_BUILTIN_EXECUTABLES(name, functionName, overriddenName, length) \
+inline JSC::UnlinkedFunctionExecutable* JSBufferPrototypeBuiltinsWrapper::name##Executable() \
+{\
+ if (!m_##name##Executable) {\
+ JSC::Identifier executableName = functionName##PublicName();\
+ if (overriddenName)\
+ executableName = JSC::Identifier::fromString(m_vm, overriddenName);\
+ m_##name##Executable = JSC::Weak<JSC::UnlinkedFunctionExecutable>(JSC::createBuiltinExecutable(m_vm, m_##name##Source, executableName, s_##name##ConstructorKind, s_##name##ConstructAbility), this, &m_##name##Executable);\
+ }\
+ return m_##name##Executable.get();\
+}
+WEBCORE_FOREACH_JSBUFFERPROTOTYPE_BUILTIN_CODE(DEFINE_BUILTIN_EXECUTABLES)
+#undef DEFINE_BUILTIN_EXECUTABLES
+
+inline void JSBufferPrototypeBuiltinsWrapper::exportNames()
+{
+#define EXPORT_FUNCTION_NAME(name) m_vm.propertyNames->appendExternalName(name##PublicName(), name##PrivateName());
+ WEBCORE_FOREACH_JSBUFFERPROTOTYPE_BUILTIN_FUNCTION_NAME(EXPORT_FUNCTION_NAME)
+#undef EXPORT_FUNCTION_NAME
+}
+
+} // namespace WebCore
diff --git a/src/bun.js/builtins/cpp/JSZigGlobalObjectBuiltins.cpp b/src/bun.js/builtins/cpp/JSZigGlobalObjectBuiltins.cpp
new file mode 100644
index 000000000..05863cc27
--- /dev/null
+++ b/src/bun.js/builtins/cpp/JSZigGlobalObjectBuiltins.cpp
@@ -0,0 +1,105 @@
+/*
+ * Copyright (c) 2015 Igalia
+ * Copyright (c) 2015 Igalia S.L.
+ * Copyright (c) 2015 Igalia.
+ * Copyright (c) 2015, 2016 Canon Inc. All rights reserved.
+ * Copyright (c) 2015, 2016, 2017 Canon Inc.
+ * Copyright (c) 2016, 2020 Apple Inc. All rights reserved.
+ * Copyright (c) 2022 Codeblog Corp. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+// DO NOT EDIT THIS FILE. It is automatically generated from JavaScript files for
+// builtins by the script: Source/JavaScriptCore/Scripts/generate-js-builtins.py
+
+#include "config.h"
+#include "JSZigGlobalObjectBuiltins.h"
+
+#include "WebCoreJSClientData.h"
+#include <JavaScriptCore/HeapInlines.h>
+#include <JavaScriptCore/IdentifierInlines.h>
+#include <JavaScriptCore/Intrinsic.h>
+#include <JavaScriptCore/JSCJSValueInlines.h>
+#include <JavaScriptCore/JSCellInlines.h>
+#include <JavaScriptCore/StructureInlines.h>
+#include <JavaScriptCore/VM.h>
+
+namespace WebCore {
+
+const JSC::ConstructAbility s_jsZigGlobalObjectRequireCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_jsZigGlobalObjectRequireCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_jsZigGlobalObjectRequireCodeLength = 1225;
+static const JSC::Intrinsic s_jsZigGlobalObjectRequireCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_jsZigGlobalObjectRequireCode =
+ "(function (name) {\n" \
+ " \"use strict\";\n" \
+ " if (typeof name !== \"string\") {\n" \
+ " @throwTypeError(\"require() expects a string as its argument\");\n" \
+ " }\n" \
+ "\n" \
+ " const resolved = this.resolveSync(name, this.path);\n" \
+ " var requireCache = (globalThis[Symbol.for(\"_requireCache\")] ||= new @Map);\n" \
+ " var cached = requireCache.@get(resolved);\n" \
+ " if (cached) {\n" \
+ " if (resolved.endsWith(\".node\")) {\n" \
+ " return cached.exports;\n" \
+ " }\n" \
+ "\n" \
+ " return cached;\n" \
+ " }\n" \
+ "\n" \
+ " //\n" \
+ " if (resolved.endsWith(\".json\")) {\n" \
+ " var fs = (globalThis[Symbol.for(\"_fs\")] ||= Bun.fs());\n" \
+ " var exports = JSON.parse(fs.readFileSync(resolved, \"utf8\"));\n" \
+ " requireCache.@set(resolved, exports);\n" \
+ " return exports;\n" \
+ " } else if (resolved.endsWith(\".node\")) {\n" \
+ " var module = { exports: {} };\n" \
+ " globalThis.process.dlopen(module, resolved);\n" \
+ " requireCache.@set(resolved, module);\n" \
+ " return module.exports;\n" \
+ " } else if (resolved.endsWith(\".toml\")) {\n" \
+ " var fs = (globalThis[Symbol.for(\"_fs\")] ||= Bun.fs());\n" \
+ " var exports = Bun.TOML.parse(fs.readFileSync(resolved, \"utf8\"));\n" \
+ " requireCache.@set(resolved, exports);\n" \
+ " return exports;\n" \
+ " }\n" \
+ "\n" \
+ " @throwTypeError(`Dynamic require isn't supported for file type: ${resolved.subsring(resolved.lastIndexOf(\".\") + 1) || resolved}`);\n" \
+ "})\n" \
+;
+
+
+#define DEFINE_BUILTIN_GENERATOR(codeName, functionName, overriddenName, argumentCount) \
+JSC::FunctionExecutable* codeName##Generator(JSC::VM& vm) \
+{\
+ JSVMClientData* clientData = static_cast<JSVMClientData*>(vm.clientData); \
+ return clientData->builtinFunctions().jsZigGlobalObjectBuiltins().codeName##Executable()->link(vm, nullptr, clientData->builtinFunctions().jsZigGlobalObjectBuiltins().codeName##Source(), std::nullopt, s_##codeName##Intrinsic); \
+}
+WEBCORE_FOREACH_JSZIGGLOBALOBJECT_BUILTIN_CODE(DEFINE_BUILTIN_GENERATOR)
+#undef DEFINE_BUILTIN_GENERATOR
+
+
+} // namespace WebCore
diff --git a/src/bun.js/builtins/cpp/JSZigGlobalObjectBuiltins.h b/src/bun.js/builtins/cpp/JSZigGlobalObjectBuiltins.h
new file mode 100644
index 000000000..f02eec836
--- /dev/null
+++ b/src/bun.js/builtins/cpp/JSZigGlobalObjectBuiltins.h
@@ -0,0 +1,127 @@
+/*
+ * Copyright (c) 2015 Igalia
+ * Copyright (c) 2015 Igalia S.L.
+ * Copyright (c) 2015 Igalia.
+ * Copyright (c) 2015, 2016 Canon Inc. All rights reserved.
+ * Copyright (c) 2015, 2016, 2017 Canon Inc.
+ * Copyright (c) 2016, 2020 Apple Inc. All rights reserved.
+ * Copyright (c) 2022 Codeblog Corp. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+// DO NOT EDIT THIS FILE. It is automatically generated from JavaScript files for
+// builtins by the script: Source/JavaScriptCore/Scripts/generate-js-builtins.py
+
+#pragma once
+
+#include <JavaScriptCore/BuiltinUtils.h>
+#include <JavaScriptCore/Identifier.h>
+#include <JavaScriptCore/JSFunction.h>
+#include <JavaScriptCore/UnlinkedFunctionExecutable.h>
+
+namespace JSC {
+class FunctionExecutable;
+}
+
+namespace WebCore {
+
+/* JSZigGlobalObject */
+extern const char* const s_jsZigGlobalObjectRequireCode;
+extern const int s_jsZigGlobalObjectRequireCodeLength;
+extern const JSC::ConstructAbility s_jsZigGlobalObjectRequireCodeConstructAbility;
+extern const JSC::ConstructorKind s_jsZigGlobalObjectRequireCodeConstructorKind;
+
+#define WEBCORE_FOREACH_JSZIGGLOBALOBJECT_BUILTIN_DATA(macro) \
+ macro(require, jsZigGlobalObjectRequire, 1) \
+
+#define WEBCORE_BUILTIN_JSZIGGLOBALOBJECT_REQUIRE 1
+
+#define WEBCORE_FOREACH_JSZIGGLOBALOBJECT_BUILTIN_CODE(macro) \
+ macro(jsZigGlobalObjectRequireCode, require, ASCIILiteral(), s_jsZigGlobalObjectRequireCodeLength) \
+
+#define WEBCORE_FOREACH_JSZIGGLOBALOBJECT_BUILTIN_FUNCTION_NAME(macro) \
+ macro(require) \
+
+#define DECLARE_BUILTIN_GENERATOR(codeName, functionName, overriddenName, argumentCount) \
+ JSC::FunctionExecutable* codeName##Generator(JSC::VM&);
+
+WEBCORE_FOREACH_JSZIGGLOBALOBJECT_BUILTIN_CODE(DECLARE_BUILTIN_GENERATOR)
+#undef DECLARE_BUILTIN_GENERATOR
+
+class JSZigGlobalObjectBuiltinsWrapper : private JSC::WeakHandleOwner {
+public:
+ explicit JSZigGlobalObjectBuiltinsWrapper(JSC::VM& vm)
+ : m_vm(vm)
+ WEBCORE_FOREACH_JSZIGGLOBALOBJECT_BUILTIN_FUNCTION_NAME(INITIALIZE_BUILTIN_NAMES)
+#define INITIALIZE_BUILTIN_SOURCE_MEMBERS(name, functionName, overriddenName, length) , m_##name##Source(JSC::makeSource(StringImpl::createWithoutCopying(s_##name, length), { }))
+ WEBCORE_FOREACH_JSZIGGLOBALOBJECT_BUILTIN_CODE(INITIALIZE_BUILTIN_SOURCE_MEMBERS)
+#undef INITIALIZE_BUILTIN_SOURCE_MEMBERS
+ {
+ }
+
+#define EXPOSE_BUILTIN_EXECUTABLES(name, functionName, overriddenName, length) \
+ JSC::UnlinkedFunctionExecutable* name##Executable(); \
+ const JSC::SourceCode& name##Source() const { return m_##name##Source; }
+ WEBCORE_FOREACH_JSZIGGLOBALOBJECT_BUILTIN_CODE(EXPOSE_BUILTIN_EXECUTABLES)
+#undef EXPOSE_BUILTIN_EXECUTABLES
+
+ WEBCORE_FOREACH_JSZIGGLOBALOBJECT_BUILTIN_FUNCTION_NAME(DECLARE_BUILTIN_IDENTIFIER_ACCESSOR)
+
+ void exportNames();
+
+private:
+ JSC::VM& m_vm;
+
+ WEBCORE_FOREACH_JSZIGGLOBALOBJECT_BUILTIN_FUNCTION_NAME(DECLARE_BUILTIN_NAMES)
+
+#define DECLARE_BUILTIN_SOURCE_MEMBERS(name, functionName, overriddenName, length) \
+ JSC::SourceCode m_##name##Source;\
+ JSC::Weak<JSC::UnlinkedFunctionExecutable> m_##name##Executable;
+ WEBCORE_FOREACH_JSZIGGLOBALOBJECT_BUILTIN_CODE(DECLARE_BUILTIN_SOURCE_MEMBERS)
+#undef DECLARE_BUILTIN_SOURCE_MEMBERS
+
+};
+
+#define DEFINE_BUILTIN_EXECUTABLES(name, functionName, overriddenName, length) \
+inline JSC::UnlinkedFunctionExecutable* JSZigGlobalObjectBuiltinsWrapper::name##Executable() \
+{\
+ if (!m_##name##Executable) {\
+ JSC::Identifier executableName = functionName##PublicName();\
+ if (overriddenName)\
+ executableName = JSC::Identifier::fromString(m_vm, overriddenName);\
+ m_##name##Executable = JSC::Weak<JSC::UnlinkedFunctionExecutable>(JSC::createBuiltinExecutable(m_vm, m_##name##Source, executableName, s_##name##ConstructorKind, s_##name##ConstructAbility), this, &m_##name##Executable);\
+ }\
+ return m_##name##Executable.get();\
+}
+WEBCORE_FOREACH_JSZIGGLOBALOBJECT_BUILTIN_CODE(DEFINE_BUILTIN_EXECUTABLES)
+#undef DEFINE_BUILTIN_EXECUTABLES
+
+inline void JSZigGlobalObjectBuiltinsWrapper::exportNames()
+{
+#define EXPORT_FUNCTION_NAME(name) m_vm.propertyNames->appendExternalName(name##PublicName(), name##PrivateName());
+ WEBCORE_FOREACH_JSZIGGLOBALOBJECT_BUILTIN_FUNCTION_NAME(EXPORT_FUNCTION_NAME)
+#undef EXPORT_FUNCTION_NAME
+}
+
+} // namespace WebCore
diff --git a/src/bun.js/builtins/cpp/ReadableByteStreamControllerBuiltins.cpp b/src/bun.js/builtins/cpp/ReadableByteStreamControllerBuiltins.cpp
new file mode 100644
index 000000000..b09754494
--- /dev/null
+++ b/src/bun.js/builtins/cpp/ReadableByteStreamControllerBuiltins.cpp
@@ -0,0 +1,188 @@
+/*
+ * Copyright (c) 2015 Igalia
+ * Copyright (c) 2015 Igalia S.L.
+ * Copyright (c) 2015 Igalia.
+ * Copyright (c) 2015, 2016 Canon Inc. All rights reserved.
+ * Copyright (c) 2015, 2016, 2017 Canon Inc.
+ * Copyright (c) 2016, 2020 Apple Inc. All rights reserved.
+ * Copyright (c) 2022 Codeblog Corp. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+// DO NOT EDIT THIS FILE. It is automatically generated from JavaScript files for
+// builtins by the script: Source/JavaScriptCore/Scripts/generate-js-builtins.py
+
+#include "config.h"
+#include "ReadableByteStreamControllerBuiltins.h"
+
+#include "WebCoreJSClientData.h"
+#include <JavaScriptCore/HeapInlines.h>
+#include <JavaScriptCore/IdentifierInlines.h>
+#include <JavaScriptCore/Intrinsic.h>
+#include <JavaScriptCore/JSCJSValueInlines.h>
+#include <JavaScriptCore/JSCellInlines.h>
+#include <JavaScriptCore/StructureInlines.h>
+#include <JavaScriptCore/VM.h>
+
+namespace WebCore {
+
+const JSC::ConstructAbility s_readableByteStreamControllerInitializeReadableByteStreamControllerCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableByteStreamControllerInitializeReadableByteStreamControllerCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableByteStreamControllerInitializeReadableByteStreamControllerCodeLength = 366;
+static const JSC::Intrinsic s_readableByteStreamControllerInitializeReadableByteStreamControllerCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableByteStreamControllerInitializeReadableByteStreamControllerCode =
+ "(function (stream, underlyingByteSource, highWaterMark)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " if (arguments.length !== 4 && arguments[3] !== @isReadableStream)\n" \
+ " @throwTypeError(\"ReadableByteStreamController constructor should not be called directly\");\n" \
+ "\n" \
+ " return @privateInitializeReadableByteStreamController.@call(this, stream, underlyingByteSource, highWaterMark);\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableByteStreamControllerEnqueueCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableByteStreamControllerEnqueueCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableByteStreamControllerEnqueueCodeLength = 665;
+static const JSC::Intrinsic s_readableByteStreamControllerEnqueueCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableByteStreamControllerEnqueueCode =
+ "(function (chunk)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " if (!@isReadableByteStreamController(this))\n" \
+ " throw @makeThisTypeError(\"ReadableByteStreamController\", \"enqueue\");\n" \
+ "\n" \
+ " if (@getByIdDirectPrivate(this, \"closeRequested\"))\n" \
+ " @throwTypeError(\"ReadableByteStreamController is requested to close\");\n" \
+ "\n" \
+ " if (@getByIdDirectPrivate(@getByIdDirectPrivate(this, \"controlledReadableStream\"), \"state\") !== @streamReadable)\n" \
+ " @throwTypeError(\"ReadableStream is not readable\");\n" \
+ "\n" \
+ " if (!@isObject(chunk) || !@ArrayBuffer.@isView(chunk))\n" \
+ " @throwTypeError(\"Provided chunk is not a TypedArray\");\n" \
+ "\n" \
+ " return @readableByteStreamControllerEnqueue(this, chunk);\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableByteStreamControllerErrorCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableByteStreamControllerErrorCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableByteStreamControllerErrorCodeLength = 396;
+static const JSC::Intrinsic s_readableByteStreamControllerErrorCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableByteStreamControllerErrorCode =
+ "(function (error)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " if (!@isReadableByteStreamController(this))\n" \
+ " throw @makeThisTypeError(\"ReadableByteStreamController\", \"error\");\n" \
+ "\n" \
+ " if (@getByIdDirectPrivate(@getByIdDirectPrivate(this, \"controlledReadableStream\"), \"state\") !== @streamReadable)\n" \
+ " @throwTypeError(\"ReadableStream is not readable\");\n" \
+ "\n" \
+ " @readableByteStreamControllerError(this, error);\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableByteStreamControllerCloseCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableByteStreamControllerCloseCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableByteStreamControllerCloseCodeLength = 501;
+static const JSC::Intrinsic s_readableByteStreamControllerCloseCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableByteStreamControllerCloseCode =
+ "(function ()\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " if (!@isReadableByteStreamController(this))\n" \
+ " throw @makeThisTypeError(\"ReadableByteStreamController\", \"close\");\n" \
+ "\n" \
+ " if (@getByIdDirectPrivate(this, \"closeRequested\"))\n" \
+ " @throwTypeError(\"Close has already been requested\");\n" \
+ "\n" \
+ " if (@getByIdDirectPrivate(@getByIdDirectPrivate(this, \"controlledReadableStream\"), \"state\") !== @streamReadable)\n" \
+ " @throwTypeError(\"ReadableStream is not readable\");\n" \
+ "\n" \
+ " @readableByteStreamControllerClose(this);\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableByteStreamControllerByobRequestCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableByteStreamControllerByobRequestCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableByteStreamControllerByobRequestCodeLength = 817;
+static const JSC::Intrinsic s_readableByteStreamControllerByobRequestCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableByteStreamControllerByobRequestCode =
+ "(function ()\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " if (!@isReadableByteStreamController(this))\n" \
+ " throw @makeGetterTypeError(\"ReadableByteStreamController\", \"byobRequest\");\n" \
+ "\n" \
+ " \n" \
+ " var request = @getByIdDirectPrivate(this, \"byobRequest\");\n" \
+ " if (request === @undefined) {\n" \
+ " var pending = @getByIdDirectPrivate(this, \"pendingPullIntos\");\n" \
+ " const firstDescriptor = pending.peek();\n" \
+ " if (firstDescriptor) {\n" \
+ " const view = new @Uint8Array(firstDescriptor.buffer,\n" \
+ " firstDescriptor.byteOffset + firstDescriptor.bytesFilled,\n" \
+ " firstDescriptor.byteLength - firstDescriptor.bytesFilled);\n" \
+ " @putByIdDirectPrivate(this, \"byobRequest\", new @ReadableStreamBYOBRequest(this, view, @isReadableStream));\n" \
+ " }\n" \
+ " }\n" \
+ "\n" \
+ " return @getByIdDirectPrivate(this, \"byobRequest\");\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableByteStreamControllerDesiredSizeCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableByteStreamControllerDesiredSizeCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableByteStreamControllerDesiredSizeCodeLength = 231;
+static const JSC::Intrinsic s_readableByteStreamControllerDesiredSizeCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableByteStreamControllerDesiredSizeCode =
+ "(function ()\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " if (!@isReadableByteStreamController(this))\n" \
+ " throw @makeGetterTypeError(\"ReadableByteStreamController\", \"desiredSize\");\n" \
+ "\n" \
+ " return @readableByteStreamControllerGetDesiredSize(this);\n" \
+ "})\n" \
+;
+
+
+#define DEFINE_BUILTIN_GENERATOR(codeName, functionName, overriddenName, argumentCount) \
+JSC::FunctionExecutable* codeName##Generator(JSC::VM& vm) \
+{\
+ JSVMClientData* clientData = static_cast<JSVMClientData*>(vm.clientData); \
+ return clientData->builtinFunctions().readableByteStreamControllerBuiltins().codeName##Executable()->link(vm, nullptr, clientData->builtinFunctions().readableByteStreamControllerBuiltins().codeName##Source(), std::nullopt, s_##codeName##Intrinsic); \
+}
+WEBCORE_FOREACH_READABLEBYTESTREAMCONTROLLER_BUILTIN_CODE(DEFINE_BUILTIN_GENERATOR)
+#undef DEFINE_BUILTIN_GENERATOR
+
+
+} // namespace WebCore
diff --git a/src/bun.js/builtins/cpp/ReadableByteStreamControllerBuiltins.h b/src/bun.js/builtins/cpp/ReadableByteStreamControllerBuiltins.h
new file mode 100644
index 000000000..5513883db
--- /dev/null
+++ b/src/bun.js/builtins/cpp/ReadableByteStreamControllerBuiltins.h
@@ -0,0 +1,167 @@
+/*
+ * Copyright (c) 2015 Igalia
+ * Copyright (c) 2015 Igalia S.L.
+ * Copyright (c) 2015 Igalia.
+ * Copyright (c) 2015, 2016 Canon Inc. All rights reserved.
+ * Copyright (c) 2015, 2016, 2017 Canon Inc.
+ * Copyright (c) 2016, 2020 Apple Inc. All rights reserved.
+ * Copyright (c) 2022 Codeblog Corp. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+// DO NOT EDIT THIS FILE. It is automatically generated from JavaScript files for
+// builtins by the script: Source/JavaScriptCore/Scripts/generate-js-builtins.py
+
+#pragma once
+
+#include <JavaScriptCore/BuiltinUtils.h>
+#include <JavaScriptCore/Identifier.h>
+#include <JavaScriptCore/JSFunction.h>
+#include <JavaScriptCore/UnlinkedFunctionExecutable.h>
+
+namespace JSC {
+class FunctionExecutable;
+}
+
+namespace WebCore {
+
+/* ReadableByteStreamController */
+extern const char* const s_readableByteStreamControllerInitializeReadableByteStreamControllerCode;
+extern const int s_readableByteStreamControllerInitializeReadableByteStreamControllerCodeLength;
+extern const JSC::ConstructAbility s_readableByteStreamControllerInitializeReadableByteStreamControllerCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableByteStreamControllerInitializeReadableByteStreamControllerCodeConstructorKind;
+extern const char* const s_readableByteStreamControllerEnqueueCode;
+extern const int s_readableByteStreamControllerEnqueueCodeLength;
+extern const JSC::ConstructAbility s_readableByteStreamControllerEnqueueCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableByteStreamControllerEnqueueCodeConstructorKind;
+extern const char* const s_readableByteStreamControllerErrorCode;
+extern const int s_readableByteStreamControllerErrorCodeLength;
+extern const JSC::ConstructAbility s_readableByteStreamControllerErrorCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableByteStreamControllerErrorCodeConstructorKind;
+extern const char* const s_readableByteStreamControllerCloseCode;
+extern const int s_readableByteStreamControllerCloseCodeLength;
+extern const JSC::ConstructAbility s_readableByteStreamControllerCloseCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableByteStreamControllerCloseCodeConstructorKind;
+extern const char* const s_readableByteStreamControllerByobRequestCode;
+extern const int s_readableByteStreamControllerByobRequestCodeLength;
+extern const JSC::ConstructAbility s_readableByteStreamControllerByobRequestCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableByteStreamControllerByobRequestCodeConstructorKind;
+extern const char* const s_readableByteStreamControllerDesiredSizeCode;
+extern const int s_readableByteStreamControllerDesiredSizeCodeLength;
+extern const JSC::ConstructAbility s_readableByteStreamControllerDesiredSizeCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableByteStreamControllerDesiredSizeCodeConstructorKind;
+
+#define WEBCORE_FOREACH_READABLEBYTESTREAMCONTROLLER_BUILTIN_DATA(macro) \
+ macro(initializeReadableByteStreamController, readableByteStreamControllerInitializeReadableByteStreamController, 3) \
+ macro(enqueue, readableByteStreamControllerEnqueue, 1) \
+ macro(error, readableByteStreamControllerError, 1) \
+ macro(close, readableByteStreamControllerClose, 0) \
+ macro(byobRequest, readableByteStreamControllerByobRequest, 0) \
+ macro(desiredSize, readableByteStreamControllerDesiredSize, 0) \
+
+#define WEBCORE_BUILTIN_READABLEBYTESTREAMCONTROLLER_INITIALIZEREADABLEBYTESTREAMCONTROLLER 1
+#define WEBCORE_BUILTIN_READABLEBYTESTREAMCONTROLLER_ENQUEUE 1
+#define WEBCORE_BUILTIN_READABLEBYTESTREAMCONTROLLER_ERROR 1
+#define WEBCORE_BUILTIN_READABLEBYTESTREAMCONTROLLER_CLOSE 1
+#define WEBCORE_BUILTIN_READABLEBYTESTREAMCONTROLLER_BYOBREQUEST 1
+#define WEBCORE_BUILTIN_READABLEBYTESTREAMCONTROLLER_DESIREDSIZE 1
+
+#define WEBCORE_FOREACH_READABLEBYTESTREAMCONTROLLER_BUILTIN_CODE(macro) \
+ macro(readableByteStreamControllerInitializeReadableByteStreamControllerCode, initializeReadableByteStreamController, ASCIILiteral(), s_readableByteStreamControllerInitializeReadableByteStreamControllerCodeLength) \
+ macro(readableByteStreamControllerEnqueueCode, enqueue, ASCIILiteral(), s_readableByteStreamControllerEnqueueCodeLength) \
+ macro(readableByteStreamControllerErrorCode, error, ASCIILiteral(), s_readableByteStreamControllerErrorCodeLength) \
+ macro(readableByteStreamControllerCloseCode, close, ASCIILiteral(), s_readableByteStreamControllerCloseCodeLength) \
+ macro(readableByteStreamControllerByobRequestCode, byobRequest, "get byobRequest"_s, s_readableByteStreamControllerByobRequestCodeLength) \
+ macro(readableByteStreamControllerDesiredSizeCode, desiredSize, "get desiredSize"_s, s_readableByteStreamControllerDesiredSizeCodeLength) \
+
+#define WEBCORE_FOREACH_READABLEBYTESTREAMCONTROLLER_BUILTIN_FUNCTION_NAME(macro) \
+ macro(byobRequest) \
+ macro(close) \
+ macro(desiredSize) \
+ macro(enqueue) \
+ macro(error) \
+ macro(initializeReadableByteStreamController) \
+
+#define DECLARE_BUILTIN_GENERATOR(codeName, functionName, overriddenName, argumentCount) \
+ JSC::FunctionExecutable* codeName##Generator(JSC::VM&);
+
+WEBCORE_FOREACH_READABLEBYTESTREAMCONTROLLER_BUILTIN_CODE(DECLARE_BUILTIN_GENERATOR)
+#undef DECLARE_BUILTIN_GENERATOR
+
+class ReadableByteStreamControllerBuiltinsWrapper : private JSC::WeakHandleOwner {
+public:
+ explicit ReadableByteStreamControllerBuiltinsWrapper(JSC::VM& vm)
+ : m_vm(vm)
+ WEBCORE_FOREACH_READABLEBYTESTREAMCONTROLLER_BUILTIN_FUNCTION_NAME(INITIALIZE_BUILTIN_NAMES)
+#define INITIALIZE_BUILTIN_SOURCE_MEMBERS(name, functionName, overriddenName, length) , m_##name##Source(JSC::makeSource(StringImpl::createWithoutCopying(s_##name, length), { }))
+ WEBCORE_FOREACH_READABLEBYTESTREAMCONTROLLER_BUILTIN_CODE(INITIALIZE_BUILTIN_SOURCE_MEMBERS)
+#undef INITIALIZE_BUILTIN_SOURCE_MEMBERS
+ {
+ }
+
+#define EXPOSE_BUILTIN_EXECUTABLES(name, functionName, overriddenName, length) \
+ JSC::UnlinkedFunctionExecutable* name##Executable(); \
+ const JSC::SourceCode& name##Source() const { return m_##name##Source; }
+ WEBCORE_FOREACH_READABLEBYTESTREAMCONTROLLER_BUILTIN_CODE(EXPOSE_BUILTIN_EXECUTABLES)
+#undef EXPOSE_BUILTIN_EXECUTABLES
+
+ WEBCORE_FOREACH_READABLEBYTESTREAMCONTROLLER_BUILTIN_FUNCTION_NAME(DECLARE_BUILTIN_IDENTIFIER_ACCESSOR)
+
+ void exportNames();
+
+private:
+ JSC::VM& m_vm;
+
+ WEBCORE_FOREACH_READABLEBYTESTREAMCONTROLLER_BUILTIN_FUNCTION_NAME(DECLARE_BUILTIN_NAMES)
+
+#define DECLARE_BUILTIN_SOURCE_MEMBERS(name, functionName, overriddenName, length) \
+ JSC::SourceCode m_##name##Source;\
+ JSC::Weak<JSC::UnlinkedFunctionExecutable> m_##name##Executable;
+ WEBCORE_FOREACH_READABLEBYTESTREAMCONTROLLER_BUILTIN_CODE(DECLARE_BUILTIN_SOURCE_MEMBERS)
+#undef DECLARE_BUILTIN_SOURCE_MEMBERS
+
+};
+
+#define DEFINE_BUILTIN_EXECUTABLES(name, functionName, overriddenName, length) \
+inline JSC::UnlinkedFunctionExecutable* ReadableByteStreamControllerBuiltinsWrapper::name##Executable() \
+{\
+ if (!m_##name##Executable) {\
+ JSC::Identifier executableName = functionName##PublicName();\
+ if (overriddenName)\
+ executableName = JSC::Identifier::fromString(m_vm, overriddenName);\
+ m_##name##Executable = JSC::Weak<JSC::UnlinkedFunctionExecutable>(JSC::createBuiltinExecutable(m_vm, m_##name##Source, executableName, s_##name##ConstructorKind, s_##name##ConstructAbility), this, &m_##name##Executable);\
+ }\
+ return m_##name##Executable.get();\
+}
+WEBCORE_FOREACH_READABLEBYTESTREAMCONTROLLER_BUILTIN_CODE(DEFINE_BUILTIN_EXECUTABLES)
+#undef DEFINE_BUILTIN_EXECUTABLES
+
+inline void ReadableByteStreamControllerBuiltinsWrapper::exportNames()
+{
+#define EXPORT_FUNCTION_NAME(name) m_vm.propertyNames->appendExternalName(name##PublicName(), name##PrivateName());
+ WEBCORE_FOREACH_READABLEBYTESTREAMCONTROLLER_BUILTIN_FUNCTION_NAME(EXPORT_FUNCTION_NAME)
+#undef EXPORT_FUNCTION_NAME
+}
+
+} // namespace WebCore
diff --git a/src/bun.js/builtins/cpp/ReadableByteStreamInternalsBuiltins.cpp b/src/bun.js/builtins/cpp/ReadableByteStreamInternalsBuiltins.cpp
new file mode 100644
index 000000000..5f2f77b6a
--- /dev/null
+++ b/src/bun.js/builtins/cpp/ReadableByteStreamInternalsBuiltins.cpp
@@ -0,0 +1,958 @@
+/*
+ * Copyright (c) 2015 Igalia
+ * Copyright (c) 2015 Igalia S.L.
+ * Copyright (c) 2015 Igalia.
+ * Copyright (c) 2015, 2016 Canon Inc. All rights reserved.
+ * Copyright (c) 2015, 2016, 2017 Canon Inc.
+ * Copyright (c) 2016, 2020 Apple Inc. All rights reserved.
+ * Copyright (c) 2022 Codeblog Corp. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+// DO NOT EDIT THIS FILE. It is automatically generated from JavaScript files for
+// builtins by the script: Source/JavaScriptCore/Scripts/generate-js-builtins.py
+
+#include "config.h"
+#include "ReadableByteStreamInternalsBuiltins.h"
+
+#include "WebCoreJSClientData.h"
+#include <JavaScriptCore/HeapInlines.h>
+#include <JavaScriptCore/IdentifierInlines.h>
+#include <JavaScriptCore/Intrinsic.h>
+#include <JavaScriptCore/JSCJSValueInlines.h>
+#include <JavaScriptCore/JSCellInlines.h>
+#include <JavaScriptCore/StructureInlines.h>
+#include <JavaScriptCore/VM.h>
+
+namespace WebCore {
+
+const JSC::ConstructAbility s_readableByteStreamInternalsPrivateInitializeReadableByteStreamControllerCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableByteStreamInternalsPrivateInitializeReadableByteStreamControllerCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableByteStreamInternalsPrivateInitializeReadableByteStreamControllerCodeLength = 2365;
+static const JSC::Intrinsic s_readableByteStreamInternalsPrivateInitializeReadableByteStreamControllerCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableByteStreamInternalsPrivateInitializeReadableByteStreamControllerCode =
+ "(function (stream, underlyingByteSource, highWaterMark)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " if (!@isReadableStream(stream))\n" \
+ " @throwTypeError(\"ReadableByteStreamController needs a ReadableStream\");\n" \
+ "\n" \
+ " //\n" \
+ " if (@getByIdDirectPrivate(stream, \"readableStreamController\") !== null)\n" \
+ " @throwTypeError(\"ReadableStream already has a controller\");\n" \
+ "\n" \
+ " @putByIdDirectPrivate(this, \"controlledReadableStream\", stream);\n" \
+ " @putByIdDirectPrivate(this, \"underlyingByteSource\", underlyingByteSource);\n" \
+ " @putByIdDirectPrivate(this, \"pullAgain\", false);\n" \
+ " @putByIdDirectPrivate(this, \"pulling\", false);\n" \
+ " @readableByteStreamControllerClearPendingPullIntos(this);\n" \
+ " @putByIdDirectPrivate(this, \"queue\", @newQueue());\n" \
+ " @putByIdDirectPrivate(this, \"started\", 0);\n" \
+ " @putByIdDirectPrivate(this, \"closeRequested\", false);\n" \
+ "\n" \
+ " let hwm = @toNumber(highWaterMark);\n" \
+ " if (@isNaN(hwm) || hwm < 0)\n" \
+ " @throwRangeError(\"highWaterMark value is negative or not a number\");\n" \
+ " @putByIdDirectPrivate(this, \"strategyHWM\", hwm);\n" \
+ "\n" \
+ " let autoAllocateChunkSize = underlyingByteSource.autoAllocateChunkSize;\n" \
+ " if (autoAllocateChunkSize !== @undefined) {\n" \
+ " autoAllocateChunkSize = @toNumber(autoAllocateChunkSize);\n" \
+ " if (autoAllocateChunkSize <= 0 || autoAllocateChunkSize === @Infinity || autoAllocateChunkSize === -@Infinity)\n" \
+ " @throwRangeError(\"autoAllocateChunkSize value is negative or equal to positive or negative infinity\");\n" \
+ " }\n" \
+ " @putByIdDirectPrivate(this, \"autoAllocateChunkSize\", autoAllocateChunkSize);\n" \
+ " @putByIdDirectPrivate(this, \"pendingPullIntos\", @createFIFO());\n" \
+ "\n" \
+ "\n" \
+ " const controller = this;\n" \
+ " @promiseInvokeOrNoopNoCatch(@getByIdDirectPrivate(controller, \"underlyingByteSource\"), \"start\", [controller]).@then(() => {\n" \
+ " @putByIdDirectPrivate(controller, \"started\", 1);\n" \
+ " @assert(!@getByIdDirectPrivate(controller, \"pulling\"));\n" \
+ " @assert(!@getByIdDirectPrivate(controller, \"pullAgain\"));\n" \
+ " @readableByteStreamControllerCallPullIfNeeded(controller);\n" \
+ " }, (error) => {\n" \
+ " if (@getByIdDirectPrivate(stream, \"state\") === @streamReadable)\n" \
+ " @readableByteStreamControllerError(controller, error);\n" \
+ " });\n" \
+ "\n" \
+ " @putByIdDirectPrivate(this, \"cancel\", @readableByteStreamControllerCancel);\n" \
+ " @putByIdDirectPrivate(this, \"pull\", @readableByteStreamControllerPull);\n" \
+ " \n" \
+ " return this;\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableByteStreamInternalsReadableStreamByteStreamControllerStartCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableByteStreamInternalsReadableStreamByteStreamControllerStartCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableByteStreamInternalsReadableStreamByteStreamControllerStartCodeLength = 107;
+static const JSC::Intrinsic s_readableByteStreamInternalsReadableStreamByteStreamControllerStartCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableByteStreamInternalsReadableStreamByteStreamControllerStartCode =
+ "(function (controller) {\n" \
+ " \"use strict\";\n" \
+ " @putByIdDirectPrivate(controller, \"start\", @undefined);\n" \
+ "\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableByteStreamInternalsPrivateInitializeReadableStreamBYOBRequestCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableByteStreamInternalsPrivateInitializeReadableStreamBYOBRequestCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableByteStreamInternalsPrivateInitializeReadableStreamBYOBRequestCodeLength = 187;
+static const JSC::Intrinsic s_readableByteStreamInternalsPrivateInitializeReadableStreamBYOBRequestCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableByteStreamInternalsPrivateInitializeReadableStreamBYOBRequestCode =
+ "(function (controller, view)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " @putByIdDirectPrivate(this, \"associatedReadableByteStreamController\", controller);\n" \
+ " @putByIdDirectPrivate(this, \"view\", view);\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableByteStreamInternalsIsReadableByteStreamControllerCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableByteStreamInternalsIsReadableByteStreamControllerCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableByteStreamInternalsIsReadableByteStreamControllerCodeLength = 158;
+static const JSC::Intrinsic s_readableByteStreamInternalsIsReadableByteStreamControllerCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableByteStreamInternalsIsReadableByteStreamControllerCode =
+ "(function (controller)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " //\n" \
+ " //\n" \
+ " return @isObject(controller) && !!@getByIdDirectPrivate(controller, \"underlyingByteSource\");\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableByteStreamInternalsIsReadableStreamBYOBRequestCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableByteStreamInternalsIsReadableStreamBYOBRequestCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableByteStreamInternalsIsReadableStreamBYOBRequestCodeLength = 179;
+static const JSC::Intrinsic s_readableByteStreamInternalsIsReadableStreamBYOBRequestCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableByteStreamInternalsIsReadableStreamBYOBRequestCode =
+ "(function (byobRequest)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " //\n" \
+ " //\n" \
+ " return @isObject(byobRequest) && !!@getByIdDirectPrivate(byobRequest, \"associatedReadableByteStreamController\");\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableByteStreamInternalsIsReadableStreamBYOBReaderCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableByteStreamInternalsIsReadableStreamBYOBReaderCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableByteStreamInternalsIsReadableStreamBYOBReaderCodeLength = 149;
+static const JSC::Intrinsic s_readableByteStreamInternalsIsReadableStreamBYOBReaderCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableByteStreamInternalsIsReadableStreamBYOBReaderCode =
+ "(function (reader)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " //\n" \
+ " //\n" \
+ " //\n" \
+ " return @isObject(reader) && !!@getByIdDirectPrivate(reader, \"readIntoRequests\");\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableByteStreamInternalsReadableByteStreamControllerCancelCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableByteStreamInternalsReadableByteStreamControllerCancelCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableByteStreamInternalsReadableByteStreamControllerCancelCodeLength = 398;
+static const JSC::Intrinsic s_readableByteStreamInternalsReadableByteStreamControllerCancelCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableByteStreamInternalsReadableByteStreamControllerCancelCode =
+ "(function (controller, reason)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " var pendingPullIntos = @getByIdDirectPrivate(controller, \"pendingPullIntos\");\n" \
+ " var first = pendingPullIntos.peek();\n" \
+ " if (first)\n" \
+ " first.bytesFilled = 0;\n" \
+ "\n" \
+ " @putByIdDirectPrivate(controller, \"queue\", @newQueue());\n" \
+ " return @promiseInvokeOrNoop(@getByIdDirectPrivate(controller, \"underlyingByteSource\"), \"cancel\", [reason]);\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableByteStreamInternalsReadableByteStreamControllerErrorCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableByteStreamInternalsReadableByteStreamControllerErrorCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableByteStreamInternalsReadableByteStreamControllerErrorCodeLength = 399;
+static const JSC::Intrinsic s_readableByteStreamInternalsReadableByteStreamControllerErrorCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableByteStreamInternalsReadableByteStreamControllerErrorCode =
+ "(function (controller, e)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " @assert(@getByIdDirectPrivate(@getByIdDirectPrivate(controller, \"controlledReadableStream\"), \"state\") === @streamReadable);\n" \
+ " @readableByteStreamControllerClearPendingPullIntos(controller);\n" \
+ " @putByIdDirectPrivate(controller, \"queue\", @newQueue());\n" \
+ " @readableStreamError(@getByIdDirectPrivate(controller, \"controlledReadableStream\"), e);\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableByteStreamInternalsReadableByteStreamControllerCloseCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableByteStreamInternalsReadableByteStreamControllerCloseCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableByteStreamInternalsReadableByteStreamControllerCloseCodeLength = 809;
+static const JSC::Intrinsic s_readableByteStreamInternalsReadableByteStreamControllerCloseCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableByteStreamInternalsReadableByteStreamControllerCloseCode =
+ "(function (controller)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " @assert(!@getByIdDirectPrivate(controller, \"closeRequested\"));\n" \
+ " @assert(@getByIdDirectPrivate(@getByIdDirectPrivate(controller, \"controlledReadableStream\"), \"state\") === @streamReadable);\n" \
+ "\n" \
+ " if (@getByIdDirectPrivate(controller, \"queue\").size > 0) {\n" \
+ " @putByIdDirectPrivate(controller, \"closeRequested\", true);\n" \
+ " return;\n" \
+ " }\n" \
+ "\n" \
+ " var first = @getByIdDirectPrivate(controller, \"pendingPullIntos\")?.peek();\n" \
+ " if (first) {\n" \
+ " if (first.bytesFilled > 0) {\n" \
+ " const e = @makeTypeError(\"Close requested while there remain pending bytes\");\n" \
+ " @readableByteStreamControllerError(controller, e);\n" \
+ " throw e;\n" \
+ " }\n" \
+ " }\n" \
+ "\n" \
+ " @readableStreamClose(@getByIdDirectPrivate(controller, \"controlledReadableStream\"));\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableByteStreamInternalsReadableByteStreamControllerClearPendingPullIntosCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableByteStreamInternalsReadableByteStreamControllerClearPendingPullIntosCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableByteStreamInternalsReadableByteStreamControllerClearPendingPullIntosCodeLength = 347;
+static const JSC::Intrinsic s_readableByteStreamInternalsReadableByteStreamControllerClearPendingPullIntosCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableByteStreamInternalsReadableByteStreamControllerClearPendingPullIntosCode =
+ "(function (controller)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " @readableByteStreamControllerInvalidateBYOBRequest(controller);\n" \
+ " var existing = @getByIdDirectPrivate(controller, \"pendingPullIntos\");\n" \
+ " if (existing !== @undefined) {\n" \
+ " existing.clear();\n" \
+ " } else {\n" \
+ " @putByIdDirectPrivate(controller, \"pendingPullIntos\", @createFIFO());\n" \
+ " }\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableByteStreamInternalsReadableByteStreamControllerGetDesiredSizeCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableByteStreamInternalsReadableByteStreamControllerGetDesiredSizeCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableByteStreamInternalsReadableByteStreamControllerGetDesiredSizeCodeLength = 406;
+static const JSC::Intrinsic s_readableByteStreamInternalsReadableByteStreamControllerGetDesiredSizeCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableByteStreamInternalsReadableByteStreamControllerGetDesiredSizeCode =
+ "(function (controller)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " const stream = @getByIdDirectPrivate(controller, \"controlledReadableStream\");\n" \
+ " const state = @getByIdDirectPrivate(stream, \"state\");\n" \
+ "\n" \
+ " if (state === @streamErrored)\n" \
+ " return null;\n" \
+ " if (state === @streamClosed)\n" \
+ " return 0;\n" \
+ "\n" \
+ " return @getByIdDirectPrivate(controller, \"strategyHWM\") - @getByIdDirectPrivate(controller, \"queue\").size;\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableByteStreamInternalsReadableStreamHasBYOBReaderCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableByteStreamInternalsReadableStreamHasBYOBReaderCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableByteStreamInternalsReadableStreamHasBYOBReaderCodeLength = 176;
+static const JSC::Intrinsic s_readableByteStreamInternalsReadableStreamHasBYOBReaderCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableByteStreamInternalsReadableStreamHasBYOBReaderCode =
+ "(function (stream)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " const reader = @getByIdDirectPrivate(stream, \"reader\");\n" \
+ " return reader !== @undefined && @isReadableStreamBYOBReader(reader);\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableByteStreamInternalsReadableStreamHasDefaultReaderCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableByteStreamInternalsReadableStreamHasDefaultReaderCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableByteStreamInternalsReadableStreamHasDefaultReaderCodeLength = 179;
+static const JSC::Intrinsic s_readableByteStreamInternalsReadableStreamHasDefaultReaderCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableByteStreamInternalsReadableStreamHasDefaultReaderCode =
+ "(function (stream)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " const reader = @getByIdDirectPrivate(stream, \"reader\");\n" \
+ " return reader !== @undefined && @isReadableStreamDefaultReader(reader);\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableByteStreamInternalsReadableByteStreamControllerHandleQueueDrainCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableByteStreamInternalsReadableByteStreamControllerHandleQueueDrainCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableByteStreamInternalsReadableByteStreamControllerHandleQueueDrainCodeLength = 458;
+static const JSC::Intrinsic s_readableByteStreamInternalsReadableByteStreamControllerHandleQueueDrainCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableByteStreamInternalsReadableByteStreamControllerHandleQueueDrainCode =
+ "(function (controller) {\n" \
+ "\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " @assert(@getByIdDirectPrivate(@getByIdDirectPrivate(controller, \"controlledReadableStream\"), \"state\") === @streamReadable);\n" \
+ " if (!@getByIdDirectPrivate(controller, \"queue\").size && @getByIdDirectPrivate(controller, \"closeRequested\"))\n" \
+ " @readableStreamClose(@getByIdDirectPrivate(controller, \"controlledReadableStream\"));\n" \
+ " else\n" \
+ " @readableByteStreamControllerCallPullIfNeeded(controller);\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableByteStreamInternalsReadableByteStreamControllerPullCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableByteStreamInternalsReadableByteStreamControllerPullCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableByteStreamInternalsReadableByteStreamControllerPullCodeLength = 1610;
+static const JSC::Intrinsic s_readableByteStreamInternalsReadableByteStreamControllerPullCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableByteStreamInternalsReadableByteStreamControllerPullCode =
+ "(function (controller)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " const stream = @getByIdDirectPrivate(controller, \"controlledReadableStream\");\n" \
+ " @assert(@readableStreamHasDefaultReader(stream));\n" \
+ " if (@getByIdDirectPrivate(controller, \"queue\").content?.isNotEmpty()) {\n" \
+ " const entry = @getByIdDirectPrivate(controller, \"queue\").content.shift();\n" \
+ " @getByIdDirectPrivate(controller, \"queue\").size -= entry.byteLength;\n" \
+ " @readableByteStreamControllerHandleQueueDrain(controller);\n" \
+ " let view;\n" \
+ " try {\n" \
+ " view = new @Uint8Array(entry.buffer, entry.byteOffset, entry.byteLength);\n" \
+ " } catch (error) {\n" \
+ " return @Promise.@reject(error);\n" \
+ " }\n" \
+ " return @createFulfilledPromise({ value: view, done: false });\n" \
+ " }\n" \
+ "\n" \
+ " if (@getByIdDirectPrivate(controller, \"autoAllocateChunkSize\") !== @undefined) {\n" \
+ " let buffer;\n" \
+ " try {\n" \
+ " buffer = @createUninitializedArrayBuffer(@getByIdDirectPrivate(controller, \"autoAllocateChunkSize\"));\n" \
+ " } catch (error) {\n" \
+ " return @Promise.@reject(error);\n" \
+ " }\n" \
+ " const pullIntoDescriptor = {\n" \
+ " buffer,\n" \
+ " byteOffset: 0,\n" \
+ " byteLength: @getByIdDirectPrivate(controller, \"autoAllocateChunkSize\"),\n" \
+ " bytesFilled: 0,\n" \
+ " elementSize: 1,\n" \
+ " ctor: @Uint8Array,\n" \
+ " readerType: 'default'\n" \
+ " };\n" \
+ " @getByIdDirectPrivate(controller, \"pendingPullIntos\").push(pullIntoDescriptor);\n" \
+ " }\n" \
+ "\n" \
+ " const promise = @readableStreamAddReadRequest(stream);\n" \
+ " @readableByteStreamControllerCallPullIfNeeded(controller);\n" \
+ " return promise;\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableByteStreamInternalsReadableByteStreamControllerShouldCallPullCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableByteStreamInternalsReadableByteStreamControllerShouldCallPullCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableByteStreamInternalsReadableByteStreamControllerShouldCallPullCodeLength = 879;
+static const JSC::Intrinsic s_readableByteStreamInternalsReadableByteStreamControllerShouldCallPullCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableByteStreamInternalsReadableByteStreamControllerShouldCallPullCode =
+ "(function (controller)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " const stream = @getByIdDirectPrivate(controller, \"controlledReadableStream\");\n" \
+ "\n" \
+ " if (@getByIdDirectPrivate(stream, \"state\") !== @streamReadable)\n" \
+ " return false;\n" \
+ " if (@getByIdDirectPrivate(controller, \"closeRequested\"))\n" \
+ " return false;\n" \
+ " if (!(@getByIdDirectPrivate(controller, \"started\") > 0))\n" \
+ " return false;\n" \
+ " const reader = @getByIdDirectPrivate(stream, \"reader\");\n" \
+ " \n" \
+ " if (reader && (@getByIdDirectPrivate(reader, \"readRequests\")?.isNotEmpty() || !!@getByIdDirectPrivate(reader, \"bunNativePtr\")))\n" \
+ " return true;\n" \
+ " if (@readableStreamHasBYOBReader(stream) && @getByIdDirectPrivate(@getByIdDirectPrivate(stream, \"reader\"), \"readIntoRequests\")?.isNotEmpty())\n" \
+ " return true;\n" \
+ " if (@readableByteStreamControllerGetDesiredSize(controller) > 0)\n" \
+ " return true;\n" \
+ " return false;\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableByteStreamInternalsReadableByteStreamControllerCallPullIfNeededCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableByteStreamInternalsReadableByteStreamControllerCallPullIfNeededCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableByteStreamInternalsReadableByteStreamControllerCallPullIfNeededCodeLength = 1002;
+static const JSC::Intrinsic s_readableByteStreamInternalsReadableByteStreamControllerCallPullIfNeededCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableByteStreamInternalsReadableByteStreamControllerCallPullIfNeededCode =
+ "(function (controller)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " if (!@readableByteStreamControllerShouldCallPull(controller))\n" \
+ " return;\n" \
+ "\n" \
+ " if (@getByIdDirectPrivate(controller, \"pulling\")) {\n" \
+ " @putByIdDirectPrivate(controller, \"pullAgain\", true);\n" \
+ " return;\n" \
+ " }\n" \
+ "\n" \
+ " @assert(!@getByIdDirectPrivate(controller, \"pullAgain\"));\n" \
+ " @putByIdDirectPrivate(controller, \"pulling\", true);\n" \
+ " @promiseInvokeOrNoop(@getByIdDirectPrivate(controller, \"underlyingByteSource\"), \"pull\", [controller]).@then(() => {\n" \
+ " @putByIdDirectPrivate(controller, \"pulling\", false);\n" \
+ " if (@getByIdDirectPrivate(controller, \"pullAgain\")) {\n" \
+ " @putByIdDirectPrivate(controller, \"pullAgain\", false);\n" \
+ " @readableByteStreamControllerCallPullIfNeeded(controller);\n" \
+ " }\n" \
+ " }, (error) => {\n" \
+ " if (@getByIdDirectPrivate(@getByIdDirectPrivate(controller, \"controlledReadableStream\"), \"state\") === @streamReadable)\n" \
+ " @readableByteStreamControllerError(controller, error);\n" \
+ " });\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableByteStreamInternalsTransferBufferToCurrentRealmCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableByteStreamInternalsTransferBufferToCurrentRealmCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableByteStreamInternalsTransferBufferToCurrentRealmCodeLength = 90;
+static const JSC::Intrinsic s_readableByteStreamInternalsTransferBufferToCurrentRealmCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableByteStreamInternalsTransferBufferToCurrentRealmCode =
+ "(function (buffer)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " //\n" \
+ " //\n" \
+ " //\n" \
+ " //\n" \
+ " return buffer;\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableByteStreamInternalsReadableStreamReaderKindCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableByteStreamInternalsReadableStreamReaderKindCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableByteStreamInternalsReadableStreamReaderKindCodeLength = 266;
+static const JSC::Intrinsic s_readableByteStreamInternalsReadableStreamReaderKindCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableByteStreamInternalsReadableStreamReaderKindCode =
+ "(function (reader) {\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ "\n" \
+ " if (!!@getByIdDirectPrivate(reader, \"readRequests\"))\n" \
+ " return @getByIdDirectPrivate(reader, \"bunNativePtr\") ? 3 : 1;\n" \
+ "\n" \
+ " if (!!@getByIdDirectPrivate(reader, \"readIntoRequests\"))\n" \
+ " return 2;\n" \
+ "\n" \
+ " return 0;\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableByteStreamInternalsReadableByteStreamControllerEnqueueCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableByteStreamInternalsReadableByteStreamControllerEnqueueCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableByteStreamInternalsReadableByteStreamControllerEnqueueCodeLength = 1690;
+static const JSC::Intrinsic s_readableByteStreamInternalsReadableByteStreamControllerEnqueueCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableByteStreamInternalsReadableByteStreamControllerEnqueueCode =
+ "(function (controller, chunk)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " const stream = @getByIdDirectPrivate(controller, \"controlledReadableStream\");\n" \
+ " @assert(!@getByIdDirectPrivate(controller, \"closeRequested\"));\n" \
+ " @assert(@getByIdDirectPrivate(stream, \"state\") === @streamReadable);\n" \
+ "\n" \
+ "\n" \
+ " switch (@getByIdDirectPrivate(stream, \"reader\") ? @readableStreamReaderKind(@getByIdDirectPrivate(stream, \"reader\")) : 0) {\n" \
+ " \n" \
+ " case 1: {\n" \
+ " if (!@getByIdDirectPrivate(@getByIdDirectPrivate(stream, \"reader\"), \"readRequests\")?.isNotEmpty())\n" \
+ " @readableByteStreamControllerEnqueueChunk(controller, @transferBufferToCurrentRealm(chunk.buffer), chunk.byteOffset, chunk.byteLength);\n" \
+ " else {\n" \
+ " @assert(!@getByIdDirectPrivate(controller, \"queue\").content.size());\n" \
+ " const transferredView = chunk.constructor === @Uint8Array ? chunk : new @Uint8Array(chunk.buffer, chunk.byteOffset, chunk.byteLength);\n" \
+ " @readableStreamFulfillReadRequest(stream, transferredView, false);\n" \
+ " }\n" \
+ " break;\n" \
+ " }\n" \
+ "\n" \
+ " \n" \
+ " case 2: {\n" \
+ " @readableByteStreamControllerEnqueueChunk(controller, @transferBufferToCurrentRealm(chunk.buffer), chunk.byteOffset, chunk.byteLength);\n" \
+ " @readableByteStreamControllerProcessPullDescriptors(controller);\n" \
+ " break;\n" \
+ " }\n" \
+ "\n" \
+ " \n" \
+ " case 3: {\n" \
+ " //\n" \
+ "\n" \
+ " break;\n" \
+ " }\n" \
+ "\n" \
+ " default: {\n" \
+ " @assert(!@isReadableStreamLocked(stream));\n" \
+ " @readableByteStreamControllerEnqueueChunk(controller, @transferBufferToCurrentRealm(chunk.buffer), chunk.byteOffset, chunk.byteLength);\n" \
+ " break;\n" \
+ " }\n" \
+ " }\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableByteStreamInternalsReadableByteStreamControllerEnqueueChunkCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableByteStreamInternalsReadableByteStreamControllerEnqueueChunkCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableByteStreamInternalsReadableByteStreamControllerEnqueueChunkCodeLength = 303;
+static const JSC::Intrinsic s_readableByteStreamInternalsReadableByteStreamControllerEnqueueChunkCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableByteStreamInternalsReadableByteStreamControllerEnqueueChunkCode =
+ "(function (controller, buffer, byteOffset, byteLength)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " @getByIdDirectPrivate(controller, \"queue\").content.push({\n" \
+ " buffer: buffer,\n" \
+ " byteOffset: byteOffset,\n" \
+ " byteLength: byteLength\n" \
+ " });\n" \
+ " @getByIdDirectPrivate(controller, \"queue\").size += byteLength;\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableByteStreamInternalsReadableByteStreamControllerRespondWithNewViewCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableByteStreamInternalsReadableByteStreamControllerRespondWithNewViewCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableByteStreamInternalsReadableByteStreamControllerRespondWithNewViewCodeLength = 619;
+static const JSC::Intrinsic s_readableByteStreamInternalsReadableByteStreamControllerRespondWithNewViewCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableByteStreamInternalsReadableByteStreamControllerRespondWithNewViewCode =
+ "(function (controller, view)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " @assert(@getByIdDirectPrivate(controller, \"pendingPullIntos\").isNotEmpty());\n" \
+ "\n" \
+ " let firstDescriptor = @getByIdDirectPrivate(controller, \"pendingPullIntos\").peek();\n" \
+ " \n" \
+ " if (firstDescriptor.byteOffset + firstDescriptor.bytesFilled !== view.byteOffset)\n" \
+ " @throwRangeError(\"Invalid value for view.byteOffset\");\n" \
+ "\n" \
+ " if (firstDescriptor.byteLength !== view.byteLength)\n" \
+ " @throwRangeError(\"Invalid value for view.byteLength\");\n" \
+ "\n" \
+ " firstDescriptor.buffer = view.buffer;\n" \
+ " @readableByteStreamControllerRespondInternal(controller, view.byteLength);\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableByteStreamInternalsReadableByteStreamControllerRespondCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableByteStreamInternalsReadableByteStreamControllerRespondCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableByteStreamInternalsReadableByteStreamControllerRespondCodeLength = 411;
+static const JSC::Intrinsic s_readableByteStreamInternalsReadableByteStreamControllerRespondCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableByteStreamInternalsReadableByteStreamControllerRespondCode =
+ "(function (controller, bytesWritten)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " bytesWritten = @toNumber(bytesWritten);\n" \
+ "\n" \
+ " if (@isNaN(bytesWritten) || bytesWritten === @Infinity || bytesWritten < 0 )\n" \
+ " @throwRangeError(\"bytesWritten has an incorrect value\");\n" \
+ "\n" \
+ " @assert(@getByIdDirectPrivate(controller, \"pendingPullIntos\").isNotEmpty());\n" \
+ "\n" \
+ " @readableByteStreamControllerRespondInternal(controller, bytesWritten);\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableByteStreamInternalsReadableByteStreamControllerRespondInternalCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableByteStreamInternalsReadableByteStreamControllerRespondInternalCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableByteStreamInternalsReadableByteStreamControllerRespondInternalCodeLength = 712;
+static const JSC::Intrinsic s_readableByteStreamInternalsReadableByteStreamControllerRespondInternalCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableByteStreamInternalsReadableByteStreamControllerRespondInternalCode =
+ "(function (controller, bytesWritten)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " let firstDescriptor = @getByIdDirectPrivate(controller, \"pendingPullIntos\").peek();\n" \
+ " let stream = @getByIdDirectPrivate(controller, \"controlledReadableStream\");\n" \
+ "\n" \
+ " if (@getByIdDirectPrivate(stream, \"state\") === @streamClosed) {\n" \
+ " if (bytesWritten !== 0)\n" \
+ " @throwTypeError(\"bytesWritten is different from 0 even though stream is closed\");\n" \
+ " @readableByteStreamControllerRespondInClosedState(controller, firstDescriptor);\n" \
+ " } else {\n" \
+ " @assert(@getByIdDirectPrivate(stream, \"state\") === @streamReadable);\n" \
+ " @readableByteStreamControllerRespondInReadableState(controller, bytesWritten, firstDescriptor);\n" \
+ " }\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableByteStreamInternalsReadableByteStreamControllerRespondInReadableStateCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableByteStreamInternalsReadableByteStreamControllerRespondInReadableStateCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableByteStreamInternalsReadableByteStreamControllerRespondInReadableStateCodeLength = 1440;
+static const JSC::Intrinsic s_readableByteStreamInternalsReadableByteStreamControllerRespondInReadableStateCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableByteStreamInternalsReadableByteStreamControllerRespondInReadableStateCode =
+ "(function (controller, bytesWritten, pullIntoDescriptor)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " if (pullIntoDescriptor.bytesFilled + bytesWritten > pullIntoDescriptor.byteLength)\n" \
+ " @throwRangeError(\"bytesWritten value is too great\");\n" \
+ "\n" \
+ " @assert(@getByIdDirectPrivate(controller, \"pendingPullIntos\").isEmpty() || @getByIdDirectPrivate(controller, \"pendingPullIntos\").peek() === pullIntoDescriptor);\n" \
+ " @readableByteStreamControllerInvalidateBYOBRequest(controller);\n" \
+ " pullIntoDescriptor.bytesFilled += bytesWritten;\n" \
+ "\n" \
+ " if (pullIntoDescriptor.bytesFilled < pullIntoDescriptor.elementSize)\n" \
+ " return;\n" \
+ "\n" \
+ " @readableByteStreamControllerShiftPendingDescriptor(controller);\n" \
+ " const remainderSize = pullIntoDescriptor.bytesFilled % pullIntoDescriptor.elementSize;\n" \
+ "\n" \
+ " if (remainderSize > 0) {\n" \
+ " const end = pullIntoDescriptor.byteOffset + pullIntoDescriptor.bytesFilled;\n" \
+ " const remainder = @cloneArrayBuffer(pullIntoDescriptor.buffer, end - remainderSize, remainderSize);\n" \
+ " @readableByteStreamControllerEnqueueChunk(controller, remainder, 0, remainder.byteLength);\n" \
+ " }\n" \
+ "\n" \
+ " pullIntoDescriptor.buffer = @transferBufferToCurrentRealm(pullIntoDescriptor.buffer);\n" \
+ " pullIntoDescriptor.bytesFilled -= remainderSize;\n" \
+ " @readableByteStreamControllerCommitDescriptor(@getByIdDirectPrivate(controller, \"controlledReadableStream\"), pullIntoDescriptor);\n" \
+ " @readableByteStreamControllerProcessPullDescriptors(controller);\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableByteStreamInternalsReadableByteStreamControllerRespondInClosedStateCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableByteStreamInternalsReadableByteStreamControllerRespondInClosedStateCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableByteStreamInternalsReadableByteStreamControllerRespondInClosedStateCodeLength = 730;
+static const JSC::Intrinsic s_readableByteStreamInternalsReadableByteStreamControllerRespondInClosedStateCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableByteStreamInternalsReadableByteStreamControllerRespondInClosedStateCode =
+ "(function (controller, firstDescriptor)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " firstDescriptor.buffer = @transferBufferToCurrentRealm(firstDescriptor.buffer);\n" \
+ " @assert(firstDescriptor.bytesFilled === 0);\n" \
+ "\n" \
+ " if (@readableStreamHasBYOBReader(@getByIdDirectPrivate(controller, \"controlledReadableStream\"))) {\n" \
+ " while (@getByIdDirectPrivate(@getByIdDirectPrivate(@getByIdDirectPrivate(controller, \"controlledReadableStream\"), \"reader\"), \"readIntoRequests\")?.isNotEmpty()) {\n" \
+ " let pullIntoDescriptor = @readableByteStreamControllerShiftPendingDescriptor(controller);\n" \
+ " @readableByteStreamControllerCommitDescriptor(@getByIdDirectPrivate(controller, \"controlledReadableStream\"), pullIntoDescriptor);\n" \
+ " }\n" \
+ " }\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableByteStreamInternalsReadableByteStreamControllerProcessPullDescriptorsCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableByteStreamInternalsReadableByteStreamControllerProcessPullDescriptorsCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableByteStreamInternalsReadableByteStreamControllerProcessPullDescriptorsCodeLength = 712;
+static const JSC::Intrinsic s_readableByteStreamInternalsReadableByteStreamControllerProcessPullDescriptorsCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableByteStreamInternalsReadableByteStreamControllerProcessPullDescriptorsCode =
+ "(function (controller)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " @assert(!@getByIdDirectPrivate(controller, \"closeRequested\"));\n" \
+ " while (@getByIdDirectPrivate(controller, \"pendingPullIntos\").isNotEmpty()) {\n" \
+ " if (@getByIdDirectPrivate(controller, \"queue\").size === 0)\n" \
+ " return;\n" \
+ " let pullIntoDescriptor = @getByIdDirectPrivate(controller, \"pendingPullIntos\").peek();\n" \
+ " if (@readableByteStreamControllerFillDescriptorFromQueue(controller, pullIntoDescriptor)) {\n" \
+ " @readableByteStreamControllerShiftPendingDescriptor(controller);\n" \
+ " @readableByteStreamControllerCommitDescriptor(@getByIdDirectPrivate(controller, \"controlledReadableStream\"), pullIntoDescriptor);\n" \
+ " }\n" \
+ " }\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableByteStreamInternalsReadableByteStreamControllerFillDescriptorFromQueueCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableByteStreamInternalsReadableByteStreamControllerFillDescriptorFromQueueCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableByteStreamInternalsReadableByteStreamControllerFillDescriptorFromQueueCodeLength = 2359;
+static const JSC::Intrinsic s_readableByteStreamInternalsReadableByteStreamControllerFillDescriptorFromQueueCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableByteStreamInternalsReadableByteStreamControllerFillDescriptorFromQueueCode =
+ "(function (controller, pullIntoDescriptor)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " const currentAlignedBytes = pullIntoDescriptor.bytesFilled - (pullIntoDescriptor.bytesFilled % pullIntoDescriptor.elementSize);\n" \
+ " const maxBytesToCopy = @getByIdDirectPrivate(controller, \"queue\").size < pullIntoDescriptor.byteLength - pullIntoDescriptor.bytesFilled ?\n" \
+ " @getByIdDirectPrivate(controller, \"queue\").size : pullIntoDescriptor.byteLength - pullIntoDescriptor.bytesFilled;\n" \
+ " const maxBytesFilled = pullIntoDescriptor.bytesFilled + maxBytesToCopy;\n" \
+ " const maxAlignedBytes = maxBytesFilled - (maxBytesFilled % pullIntoDescriptor.elementSize);\n" \
+ " let totalBytesToCopyRemaining = maxBytesToCopy;\n" \
+ " let ready = false;\n" \
+ "\n" \
+ " if (maxAlignedBytes > currentAlignedBytes) {\n" \
+ " totalBytesToCopyRemaining = maxAlignedBytes - pullIntoDescriptor.bytesFilled;\n" \
+ " ready = true;\n" \
+ " }\n" \
+ "\n" \
+ " while (totalBytesToCopyRemaining > 0) {\n" \
+ " let headOfQueue = @getByIdDirectPrivate(controller, \"queue\").content.peek();\n" \
+ " const bytesToCopy = totalBytesToCopyRemaining < headOfQueue.byteLength ? totalBytesToCopyRemaining : headOfQueue.byteLength;\n" \
+ " //\n" \
+ " //\n" \
+ " //\n" \
+ " const destStart = pullIntoDescriptor.byteOffset + pullIntoDescriptor.bytesFilled;\n" \
+ " //\n" \
+ " //\n" \
+ " new @Uint8Array(pullIntoDescriptor.buffer).set(new @Uint8Array(headOfQueue.buffer, headOfQueue.byteOffset, bytesToCopy), destStart);\n" \
+ "\n" \
+ " if (headOfQueue.byteLength === bytesToCopy)\n" \
+ " @getByIdDirectPrivate(controller, \"queue\").content.shift();\n" \
+ " else {\n" \
+ " headOfQueue.byteOffset += bytesToCopy;\n" \
+ " headOfQueue.byteLength -= bytesToCopy;\n" \
+ " }\n" \
+ "\n" \
+ " @getByIdDirectPrivate(controller, \"queue\").size -= bytesToCopy;\n" \
+ " @assert(@getByIdDirectPrivate(controller, \"pendingPullIntos\").isEmpty() || @getByIdDirectPrivate(controller, \"pendingPullIntos\").peek() === pullIntoDescriptor);\n" \
+ " @readableByteStreamControllerInvalidateBYOBRequest(controller);\n" \
+ " pullIntoDescriptor.bytesFilled += bytesToCopy;\n" \
+ " totalBytesToCopyRemaining -= bytesToCopy;\n" \
+ " }\n" \
+ "\n" \
+ " if (!ready) {\n" \
+ " @assert(@getByIdDirectPrivate(controller, \"queue\").size === 0);\n" \
+ " @assert(pullIntoDescriptor.bytesFilled > 0);\n" \
+ " @assert(pullIntoDescriptor.bytesFilled < pullIntoDescriptor.elementSize);\n" \
+ " }\n" \
+ "\n" \
+ " return ready;\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableByteStreamInternalsReadableByteStreamControllerShiftPendingDescriptorCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableByteStreamInternalsReadableByteStreamControllerShiftPendingDescriptorCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableByteStreamInternalsReadableByteStreamControllerShiftPendingDescriptorCodeLength = 222;
+static const JSC::Intrinsic s_readableByteStreamInternalsReadableByteStreamControllerShiftPendingDescriptorCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableByteStreamInternalsReadableByteStreamControllerShiftPendingDescriptorCode =
+ "(function (controller)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " let descriptor = @getByIdDirectPrivate(controller, \"pendingPullIntos\").shift();\n" \
+ " @readableByteStreamControllerInvalidateBYOBRequest(controller);\n" \
+ " return descriptor;\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableByteStreamInternalsReadableByteStreamControllerInvalidateBYOBRequestCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableByteStreamInternalsReadableByteStreamControllerInvalidateBYOBRequestCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableByteStreamInternalsReadableByteStreamControllerInvalidateBYOBRequestCodeLength = 430;
+static const JSC::Intrinsic s_readableByteStreamInternalsReadableByteStreamControllerInvalidateBYOBRequestCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableByteStreamInternalsReadableByteStreamControllerInvalidateBYOBRequestCode =
+ "(function (controller)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " if (@getByIdDirectPrivate(controller, \"byobRequest\") === @undefined)\n" \
+ " return;\n" \
+ " const byobRequest = @getByIdDirectPrivate(controller, \"byobRequest\");\n" \
+ " @putByIdDirectPrivate(byobRequest, \"associatedReadableByteStreamController\", @undefined);\n" \
+ " @putByIdDirectPrivate(byobRequest, \"view\", @undefined);\n" \
+ " @putByIdDirectPrivate(controller, \"byobRequest\", @undefined);\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableByteStreamInternalsReadableByteStreamControllerCommitDescriptorCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableByteStreamInternalsReadableByteStreamControllerCommitDescriptorCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableByteStreamInternalsReadableByteStreamControllerCommitDescriptorCodeLength = 662;
+static const JSC::Intrinsic s_readableByteStreamInternalsReadableByteStreamControllerCommitDescriptorCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableByteStreamInternalsReadableByteStreamControllerCommitDescriptorCode =
+ "(function (stream, pullIntoDescriptor)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " @assert(@getByIdDirectPrivate(stream, \"state\") !== @streamErrored);\n" \
+ " let done = false;\n" \
+ " if (@getByIdDirectPrivate(stream, \"state\") === @streamClosed) {\n" \
+ " @assert(!pullIntoDescriptor.bytesFilled);\n" \
+ " done = true;\n" \
+ " }\n" \
+ " let filledView = @readableByteStreamControllerConvertDescriptor(pullIntoDescriptor);\n" \
+ " if (pullIntoDescriptor.readerType === \"default\")\n" \
+ " @readableStreamFulfillReadRequest(stream, filledView, done);\n" \
+ " else {\n" \
+ " @assert(pullIntoDescriptor.readerType === \"byob\");\n" \
+ " @readableStreamFulfillReadIntoRequest(stream, filledView, done);\n" \
+ " }\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableByteStreamInternalsReadableByteStreamControllerConvertDescriptorCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableByteStreamInternalsReadableByteStreamControllerConvertDescriptorCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableByteStreamInternalsReadableByteStreamControllerConvertDescriptorCodeLength = 381;
+static const JSC::Intrinsic s_readableByteStreamInternalsReadableByteStreamControllerConvertDescriptorCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableByteStreamInternalsReadableByteStreamControllerConvertDescriptorCode =
+ "(function (pullIntoDescriptor)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " @assert(pullIntoDescriptor.bytesFilled <= pullIntoDescriptor.byteLength);\n" \
+ " @assert(pullIntoDescriptor.bytesFilled % pullIntoDescriptor.elementSize === 0);\n" \
+ "\n" \
+ " return new pullIntoDescriptor.ctor(pullIntoDescriptor.buffer, pullIntoDescriptor.byteOffset, pullIntoDescriptor.bytesFilled / pullIntoDescriptor.elementSize);\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableByteStreamInternalsReadableStreamFulfillReadIntoRequestCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableByteStreamInternalsReadableStreamFulfillReadIntoRequestCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableByteStreamInternalsReadableStreamFulfillReadIntoRequestCodeLength = 243;
+static const JSC::Intrinsic s_readableByteStreamInternalsReadableStreamFulfillReadIntoRequestCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableByteStreamInternalsReadableStreamFulfillReadIntoRequestCode =
+ "(function (stream, chunk, done)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ " const readIntoRequest = @getByIdDirectPrivate(@getByIdDirectPrivate(stream, \"reader\"), \"readIntoRequests\").shift();\n" \
+ " @fulfillPromise(readIntoRequest, { value: chunk, done: done });\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableByteStreamInternalsReadableStreamBYOBReaderReadCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableByteStreamInternalsReadableStreamBYOBReaderReadCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableByteStreamInternalsReadableStreamBYOBReaderReadCodeLength = 462;
+static const JSC::Intrinsic s_readableByteStreamInternalsReadableStreamBYOBReaderReadCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableByteStreamInternalsReadableStreamBYOBReaderReadCode =
+ "(function (reader, view)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " const stream = @getByIdDirectPrivate(reader, \"ownerReadableStream\");\n" \
+ " @assert(!!stream);\n" \
+ "\n" \
+ " @putByIdDirectPrivate(stream, \"disturbed\", true);\n" \
+ " if (@getByIdDirectPrivate(stream, \"state\") === @streamErrored)\n" \
+ " return @Promise.@reject(@getByIdDirectPrivate(stream, \"storedError\"));\n" \
+ "\n" \
+ " return @readableByteStreamControllerPullInto(@getByIdDirectPrivate(stream, \"readableStreamController\"), view);\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableByteStreamInternalsReadableByteStreamControllerPullIntoCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableByteStreamInternalsReadableByteStreamControllerPullIntoCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableByteStreamInternalsReadableByteStreamControllerPullIntoCodeLength = 2190;
+static const JSC::Intrinsic s_readableByteStreamInternalsReadableByteStreamControllerPullIntoCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableByteStreamInternalsReadableByteStreamControllerPullIntoCode =
+ "(function (controller, view)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " const stream = @getByIdDirectPrivate(controller, \"controlledReadableStream\");\n" \
+ " let elementSize = 1;\n" \
+ " //\n" \
+ " //\n" \
+ " //\n" \
+ " //\n" \
+ " //\n" \
+ " //\n" \
+ " //\n" \
+ " //\n" \
+ " //\n" \
+ " //\n" \
+ " if (view.BYTES_PER_ELEMENT !== @undefined)\n" \
+ " elementSize = view.BYTES_PER_ELEMENT;\n" \
+ "\n" \
+ " //\n" \
+ " //\n" \
+ " //\n" \
+ " //\n" \
+ " //\n" \
+ " //\n" \
+ " const ctor = view.constructor;\n" \
+ "\n" \
+ " const pullIntoDescriptor = {\n" \
+ " buffer: view.buffer,\n" \
+ " byteOffset: view.byteOffset,\n" \
+ " byteLength: view.byteLength,\n" \
+ " bytesFilled: 0,\n" \
+ " elementSize,\n" \
+ " ctor,\n" \
+ " readerType: 'byob'\n" \
+ " };\n" \
+ "\n" \
+ " var pending = @getByIdDirectPrivate(controller, \"pendingPullIntos\");\n" \
+ " if (pending?.isNotEmpty()) {\n" \
+ " pullIntoDescriptor.buffer = @transferBufferToCurrentRealm(pullIntoDescriptor.buffer);\n" \
+ " pending.push(pullIntoDescriptor);\n" \
+ " return @readableStreamAddReadIntoRequest(stream);\n" \
+ " }\n" \
+ "\n" \
+ " if (@getByIdDirectPrivate(stream, \"state\") === @streamClosed) {\n" \
+ " const emptyView = new ctor(pullIntoDescriptor.buffer, pullIntoDescriptor.byteOffset, 0);\n" \
+ " return @createFulfilledPromise({ value: emptyView, done: true });\n" \
+ " }\n" \
+ "\n" \
+ " if (@getByIdDirectPrivate(controller, \"queue\").size > 0) {\n" \
+ " if (@readableByteStreamControllerFillDescriptorFromQueue(controller, pullIntoDescriptor)) {\n" \
+ " const filledView = @readableByteStreamControllerConvertDescriptor(pullIntoDescriptor);\n" \
+ " @readableByteStreamControllerHandleQueueDrain(controller);\n" \
+ " return @createFulfilledPromise({ value: filledView, done: false });\n" \
+ " }\n" \
+ " if (@getByIdDirectPrivate(controller, \"closeRequested\")) {\n" \
+ " const e = @makeTypeError(\"Closing stream has been requested\");\n" \
+ " @readableByteStreamControllerError(controller, e);\n" \
+ " return @Promise.@reject(e);\n" \
+ " }\n" \
+ " }\n" \
+ "\n" \
+ " pullIntoDescriptor.buffer = @transferBufferToCurrentRealm(pullIntoDescriptor.buffer);\n" \
+ " @getByIdDirectPrivate(controller, \"pendingPullIntos\").push(pullIntoDescriptor);\n" \
+ " const promise = @readableStreamAddReadIntoRequest(stream);\n" \
+ " @readableByteStreamControllerCallPullIfNeeded(controller);\n" \
+ " return promise;\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableByteStreamInternalsReadableStreamAddReadIntoRequestCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableByteStreamInternalsReadableStreamAddReadIntoRequestCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableByteStreamInternalsReadableStreamAddReadIntoRequestCodeLength = 430;
+static const JSC::Intrinsic s_readableByteStreamInternalsReadableStreamAddReadIntoRequestCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableByteStreamInternalsReadableStreamAddReadIntoRequestCode =
+ "(function (stream)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " @assert(@isReadableStreamBYOBReader(@getByIdDirectPrivate(stream, \"reader\")));\n" \
+ " @assert(@getByIdDirectPrivate(stream, \"state\") === @streamReadable || @getByIdDirectPrivate(stream, \"state\") === @streamClosed);\n" \
+ "\n" \
+ " const readRequest = @newPromise();\n" \
+ " @getByIdDirectPrivate(@getByIdDirectPrivate(stream, \"reader\"), \"readIntoRequests\").push(readRequest);\n" \
+ "\n" \
+ " return readRequest;\n" \
+ "})\n" \
+;
+
+
+#define DEFINE_BUILTIN_GENERATOR(codeName, functionName, overriddenName, argumentCount) \
+JSC::FunctionExecutable* codeName##Generator(JSC::VM& vm) \
+{\
+ JSVMClientData* clientData = static_cast<JSVMClientData*>(vm.clientData); \
+ return clientData->builtinFunctions().readableByteStreamInternalsBuiltins().codeName##Executable()->link(vm, nullptr, clientData->builtinFunctions().readableByteStreamInternalsBuiltins().codeName##Source(), std::nullopt, s_##codeName##Intrinsic); \
+}
+WEBCORE_FOREACH_READABLEBYTESTREAMINTERNALS_BUILTIN_CODE(DEFINE_BUILTIN_GENERATOR)
+#undef DEFINE_BUILTIN_GENERATOR
+
+
+} // namespace WebCore
diff --git a/src/bun.js/builtins/cpp/ReadableByteStreamInternalsBuiltins.h b/src/bun.js/builtins/cpp/ReadableByteStreamInternalsBuiltins.h
new file mode 100644
index 000000000..3bf0d406a
--- /dev/null
+++ b/src/bun.js/builtins/cpp/ReadableByteStreamInternalsBuiltins.h
@@ -0,0 +1,444 @@
+/*
+ * Copyright (c) 2015 Igalia
+ * Copyright (c) 2015 Igalia S.L.
+ * Copyright (c) 2015 Igalia.
+ * Copyright (c) 2015, 2016 Canon Inc. All rights reserved.
+ * Copyright (c) 2015, 2016, 2017 Canon Inc.
+ * Copyright (c) 2016, 2020 Apple Inc. All rights reserved.
+ * Copyright (c) 2022 Codeblog Corp. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+// DO NOT EDIT THIS FILE. It is automatically generated from JavaScript files for
+// builtins by the script: Source/JavaScriptCore/Scripts/generate-js-builtins.py
+
+#pragma once
+
+#include <JavaScriptCore/BuiltinUtils.h>
+#include <JavaScriptCore/Identifier.h>
+#include <JavaScriptCore/JSFunction.h>
+#include <JavaScriptCore/UnlinkedFunctionExecutable.h>
+
+namespace JSC {
+class FunctionExecutable;
+}
+
+namespace WebCore {
+
+/* ReadableByteStreamInternals */
+extern const char* const s_readableByteStreamInternalsPrivateInitializeReadableByteStreamControllerCode;
+extern const int s_readableByteStreamInternalsPrivateInitializeReadableByteStreamControllerCodeLength;
+extern const JSC::ConstructAbility s_readableByteStreamInternalsPrivateInitializeReadableByteStreamControllerCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableByteStreamInternalsPrivateInitializeReadableByteStreamControllerCodeConstructorKind;
+extern const char* const s_readableByteStreamInternalsReadableStreamByteStreamControllerStartCode;
+extern const int s_readableByteStreamInternalsReadableStreamByteStreamControllerStartCodeLength;
+extern const JSC::ConstructAbility s_readableByteStreamInternalsReadableStreamByteStreamControllerStartCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableByteStreamInternalsReadableStreamByteStreamControllerStartCodeConstructorKind;
+extern const char* const s_readableByteStreamInternalsPrivateInitializeReadableStreamBYOBRequestCode;
+extern const int s_readableByteStreamInternalsPrivateInitializeReadableStreamBYOBRequestCodeLength;
+extern const JSC::ConstructAbility s_readableByteStreamInternalsPrivateInitializeReadableStreamBYOBRequestCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableByteStreamInternalsPrivateInitializeReadableStreamBYOBRequestCodeConstructorKind;
+extern const char* const s_readableByteStreamInternalsIsReadableByteStreamControllerCode;
+extern const int s_readableByteStreamInternalsIsReadableByteStreamControllerCodeLength;
+extern const JSC::ConstructAbility s_readableByteStreamInternalsIsReadableByteStreamControllerCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableByteStreamInternalsIsReadableByteStreamControllerCodeConstructorKind;
+extern const char* const s_readableByteStreamInternalsIsReadableStreamBYOBRequestCode;
+extern const int s_readableByteStreamInternalsIsReadableStreamBYOBRequestCodeLength;
+extern const JSC::ConstructAbility s_readableByteStreamInternalsIsReadableStreamBYOBRequestCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableByteStreamInternalsIsReadableStreamBYOBRequestCodeConstructorKind;
+extern const char* const s_readableByteStreamInternalsIsReadableStreamBYOBReaderCode;
+extern const int s_readableByteStreamInternalsIsReadableStreamBYOBReaderCodeLength;
+extern const JSC::ConstructAbility s_readableByteStreamInternalsIsReadableStreamBYOBReaderCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableByteStreamInternalsIsReadableStreamBYOBReaderCodeConstructorKind;
+extern const char* const s_readableByteStreamInternalsReadableByteStreamControllerCancelCode;
+extern const int s_readableByteStreamInternalsReadableByteStreamControllerCancelCodeLength;
+extern const JSC::ConstructAbility s_readableByteStreamInternalsReadableByteStreamControllerCancelCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableByteStreamInternalsReadableByteStreamControllerCancelCodeConstructorKind;
+extern const char* const s_readableByteStreamInternalsReadableByteStreamControllerErrorCode;
+extern const int s_readableByteStreamInternalsReadableByteStreamControllerErrorCodeLength;
+extern const JSC::ConstructAbility s_readableByteStreamInternalsReadableByteStreamControllerErrorCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableByteStreamInternalsReadableByteStreamControllerErrorCodeConstructorKind;
+extern const char* const s_readableByteStreamInternalsReadableByteStreamControllerCloseCode;
+extern const int s_readableByteStreamInternalsReadableByteStreamControllerCloseCodeLength;
+extern const JSC::ConstructAbility s_readableByteStreamInternalsReadableByteStreamControllerCloseCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableByteStreamInternalsReadableByteStreamControllerCloseCodeConstructorKind;
+extern const char* const s_readableByteStreamInternalsReadableByteStreamControllerClearPendingPullIntosCode;
+extern const int s_readableByteStreamInternalsReadableByteStreamControllerClearPendingPullIntosCodeLength;
+extern const JSC::ConstructAbility s_readableByteStreamInternalsReadableByteStreamControllerClearPendingPullIntosCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableByteStreamInternalsReadableByteStreamControllerClearPendingPullIntosCodeConstructorKind;
+extern const char* const s_readableByteStreamInternalsReadableByteStreamControllerGetDesiredSizeCode;
+extern const int s_readableByteStreamInternalsReadableByteStreamControllerGetDesiredSizeCodeLength;
+extern const JSC::ConstructAbility s_readableByteStreamInternalsReadableByteStreamControllerGetDesiredSizeCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableByteStreamInternalsReadableByteStreamControllerGetDesiredSizeCodeConstructorKind;
+extern const char* const s_readableByteStreamInternalsReadableStreamHasBYOBReaderCode;
+extern const int s_readableByteStreamInternalsReadableStreamHasBYOBReaderCodeLength;
+extern const JSC::ConstructAbility s_readableByteStreamInternalsReadableStreamHasBYOBReaderCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableByteStreamInternalsReadableStreamHasBYOBReaderCodeConstructorKind;
+extern const char* const s_readableByteStreamInternalsReadableStreamHasDefaultReaderCode;
+extern const int s_readableByteStreamInternalsReadableStreamHasDefaultReaderCodeLength;
+extern const JSC::ConstructAbility s_readableByteStreamInternalsReadableStreamHasDefaultReaderCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableByteStreamInternalsReadableStreamHasDefaultReaderCodeConstructorKind;
+extern const char* const s_readableByteStreamInternalsReadableByteStreamControllerHandleQueueDrainCode;
+extern const int s_readableByteStreamInternalsReadableByteStreamControllerHandleQueueDrainCodeLength;
+extern const JSC::ConstructAbility s_readableByteStreamInternalsReadableByteStreamControllerHandleQueueDrainCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableByteStreamInternalsReadableByteStreamControllerHandleQueueDrainCodeConstructorKind;
+extern const char* const s_readableByteStreamInternalsReadableByteStreamControllerPullCode;
+extern const int s_readableByteStreamInternalsReadableByteStreamControllerPullCodeLength;
+extern const JSC::ConstructAbility s_readableByteStreamInternalsReadableByteStreamControllerPullCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableByteStreamInternalsReadableByteStreamControllerPullCodeConstructorKind;
+extern const char* const s_readableByteStreamInternalsReadableByteStreamControllerShouldCallPullCode;
+extern const int s_readableByteStreamInternalsReadableByteStreamControllerShouldCallPullCodeLength;
+extern const JSC::ConstructAbility s_readableByteStreamInternalsReadableByteStreamControllerShouldCallPullCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableByteStreamInternalsReadableByteStreamControllerShouldCallPullCodeConstructorKind;
+extern const char* const s_readableByteStreamInternalsReadableByteStreamControllerCallPullIfNeededCode;
+extern const int s_readableByteStreamInternalsReadableByteStreamControllerCallPullIfNeededCodeLength;
+extern const JSC::ConstructAbility s_readableByteStreamInternalsReadableByteStreamControllerCallPullIfNeededCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableByteStreamInternalsReadableByteStreamControllerCallPullIfNeededCodeConstructorKind;
+extern const char* const s_readableByteStreamInternalsTransferBufferToCurrentRealmCode;
+extern const int s_readableByteStreamInternalsTransferBufferToCurrentRealmCodeLength;
+extern const JSC::ConstructAbility s_readableByteStreamInternalsTransferBufferToCurrentRealmCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableByteStreamInternalsTransferBufferToCurrentRealmCodeConstructorKind;
+extern const char* const s_readableByteStreamInternalsReadableStreamReaderKindCode;
+extern const int s_readableByteStreamInternalsReadableStreamReaderKindCodeLength;
+extern const JSC::ConstructAbility s_readableByteStreamInternalsReadableStreamReaderKindCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableByteStreamInternalsReadableStreamReaderKindCodeConstructorKind;
+extern const char* const s_readableByteStreamInternalsReadableByteStreamControllerEnqueueCode;
+extern const int s_readableByteStreamInternalsReadableByteStreamControllerEnqueueCodeLength;
+extern const JSC::ConstructAbility s_readableByteStreamInternalsReadableByteStreamControllerEnqueueCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableByteStreamInternalsReadableByteStreamControllerEnqueueCodeConstructorKind;
+extern const char* const s_readableByteStreamInternalsReadableByteStreamControllerEnqueueChunkCode;
+extern const int s_readableByteStreamInternalsReadableByteStreamControllerEnqueueChunkCodeLength;
+extern const JSC::ConstructAbility s_readableByteStreamInternalsReadableByteStreamControllerEnqueueChunkCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableByteStreamInternalsReadableByteStreamControllerEnqueueChunkCodeConstructorKind;
+extern const char* const s_readableByteStreamInternalsReadableByteStreamControllerRespondWithNewViewCode;
+extern const int s_readableByteStreamInternalsReadableByteStreamControllerRespondWithNewViewCodeLength;
+extern const JSC::ConstructAbility s_readableByteStreamInternalsReadableByteStreamControllerRespondWithNewViewCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableByteStreamInternalsReadableByteStreamControllerRespondWithNewViewCodeConstructorKind;
+extern const char* const s_readableByteStreamInternalsReadableByteStreamControllerRespondCode;
+extern const int s_readableByteStreamInternalsReadableByteStreamControllerRespondCodeLength;
+extern const JSC::ConstructAbility s_readableByteStreamInternalsReadableByteStreamControllerRespondCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableByteStreamInternalsReadableByteStreamControllerRespondCodeConstructorKind;
+extern const char* const s_readableByteStreamInternalsReadableByteStreamControllerRespondInternalCode;
+extern const int s_readableByteStreamInternalsReadableByteStreamControllerRespondInternalCodeLength;
+extern const JSC::ConstructAbility s_readableByteStreamInternalsReadableByteStreamControllerRespondInternalCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableByteStreamInternalsReadableByteStreamControllerRespondInternalCodeConstructorKind;
+extern const char* const s_readableByteStreamInternalsReadableByteStreamControllerRespondInReadableStateCode;
+extern const int s_readableByteStreamInternalsReadableByteStreamControllerRespondInReadableStateCodeLength;
+extern const JSC::ConstructAbility s_readableByteStreamInternalsReadableByteStreamControllerRespondInReadableStateCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableByteStreamInternalsReadableByteStreamControllerRespondInReadableStateCodeConstructorKind;
+extern const char* const s_readableByteStreamInternalsReadableByteStreamControllerRespondInClosedStateCode;
+extern const int s_readableByteStreamInternalsReadableByteStreamControllerRespondInClosedStateCodeLength;
+extern const JSC::ConstructAbility s_readableByteStreamInternalsReadableByteStreamControllerRespondInClosedStateCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableByteStreamInternalsReadableByteStreamControllerRespondInClosedStateCodeConstructorKind;
+extern const char* const s_readableByteStreamInternalsReadableByteStreamControllerProcessPullDescriptorsCode;
+extern const int s_readableByteStreamInternalsReadableByteStreamControllerProcessPullDescriptorsCodeLength;
+extern const JSC::ConstructAbility s_readableByteStreamInternalsReadableByteStreamControllerProcessPullDescriptorsCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableByteStreamInternalsReadableByteStreamControllerProcessPullDescriptorsCodeConstructorKind;
+extern const char* const s_readableByteStreamInternalsReadableByteStreamControllerFillDescriptorFromQueueCode;
+extern const int s_readableByteStreamInternalsReadableByteStreamControllerFillDescriptorFromQueueCodeLength;
+extern const JSC::ConstructAbility s_readableByteStreamInternalsReadableByteStreamControllerFillDescriptorFromQueueCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableByteStreamInternalsReadableByteStreamControllerFillDescriptorFromQueueCodeConstructorKind;
+extern const char* const s_readableByteStreamInternalsReadableByteStreamControllerShiftPendingDescriptorCode;
+extern const int s_readableByteStreamInternalsReadableByteStreamControllerShiftPendingDescriptorCodeLength;
+extern const JSC::ConstructAbility s_readableByteStreamInternalsReadableByteStreamControllerShiftPendingDescriptorCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableByteStreamInternalsReadableByteStreamControllerShiftPendingDescriptorCodeConstructorKind;
+extern const char* const s_readableByteStreamInternalsReadableByteStreamControllerInvalidateBYOBRequestCode;
+extern const int s_readableByteStreamInternalsReadableByteStreamControllerInvalidateBYOBRequestCodeLength;
+extern const JSC::ConstructAbility s_readableByteStreamInternalsReadableByteStreamControllerInvalidateBYOBRequestCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableByteStreamInternalsReadableByteStreamControllerInvalidateBYOBRequestCodeConstructorKind;
+extern const char* const s_readableByteStreamInternalsReadableByteStreamControllerCommitDescriptorCode;
+extern const int s_readableByteStreamInternalsReadableByteStreamControllerCommitDescriptorCodeLength;
+extern const JSC::ConstructAbility s_readableByteStreamInternalsReadableByteStreamControllerCommitDescriptorCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableByteStreamInternalsReadableByteStreamControllerCommitDescriptorCodeConstructorKind;
+extern const char* const s_readableByteStreamInternalsReadableByteStreamControllerConvertDescriptorCode;
+extern const int s_readableByteStreamInternalsReadableByteStreamControllerConvertDescriptorCodeLength;
+extern const JSC::ConstructAbility s_readableByteStreamInternalsReadableByteStreamControllerConvertDescriptorCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableByteStreamInternalsReadableByteStreamControllerConvertDescriptorCodeConstructorKind;
+extern const char* const s_readableByteStreamInternalsReadableStreamFulfillReadIntoRequestCode;
+extern const int s_readableByteStreamInternalsReadableStreamFulfillReadIntoRequestCodeLength;
+extern const JSC::ConstructAbility s_readableByteStreamInternalsReadableStreamFulfillReadIntoRequestCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableByteStreamInternalsReadableStreamFulfillReadIntoRequestCodeConstructorKind;
+extern const char* const s_readableByteStreamInternalsReadableStreamBYOBReaderReadCode;
+extern const int s_readableByteStreamInternalsReadableStreamBYOBReaderReadCodeLength;
+extern const JSC::ConstructAbility s_readableByteStreamInternalsReadableStreamBYOBReaderReadCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableByteStreamInternalsReadableStreamBYOBReaderReadCodeConstructorKind;
+extern const char* const s_readableByteStreamInternalsReadableByteStreamControllerPullIntoCode;
+extern const int s_readableByteStreamInternalsReadableByteStreamControllerPullIntoCodeLength;
+extern const JSC::ConstructAbility s_readableByteStreamInternalsReadableByteStreamControllerPullIntoCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableByteStreamInternalsReadableByteStreamControllerPullIntoCodeConstructorKind;
+extern const char* const s_readableByteStreamInternalsReadableStreamAddReadIntoRequestCode;
+extern const int s_readableByteStreamInternalsReadableStreamAddReadIntoRequestCodeLength;
+extern const JSC::ConstructAbility s_readableByteStreamInternalsReadableStreamAddReadIntoRequestCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableByteStreamInternalsReadableStreamAddReadIntoRequestCodeConstructorKind;
+
+#define WEBCORE_FOREACH_READABLEBYTESTREAMINTERNALS_BUILTIN_DATA(macro) \
+ macro(privateInitializeReadableByteStreamController, readableByteStreamInternalsPrivateInitializeReadableByteStreamController, 3) \
+ macro(readableStreamByteStreamControllerStart, readableByteStreamInternalsReadableStreamByteStreamControllerStart, 1) \
+ macro(privateInitializeReadableStreamBYOBRequest, readableByteStreamInternalsPrivateInitializeReadableStreamBYOBRequest, 2) \
+ macro(isReadableByteStreamController, readableByteStreamInternalsIsReadableByteStreamController, 1) \
+ macro(isReadableStreamBYOBRequest, readableByteStreamInternalsIsReadableStreamBYOBRequest, 1) \
+ macro(isReadableStreamBYOBReader, readableByteStreamInternalsIsReadableStreamBYOBReader, 1) \
+ macro(readableByteStreamControllerCancel, readableByteStreamInternalsReadableByteStreamControllerCancel, 2) \
+ macro(readableByteStreamControllerError, readableByteStreamInternalsReadableByteStreamControllerError, 2) \
+ macro(readableByteStreamControllerClose, readableByteStreamInternalsReadableByteStreamControllerClose, 1) \
+ macro(readableByteStreamControllerClearPendingPullIntos, readableByteStreamInternalsReadableByteStreamControllerClearPendingPullIntos, 1) \
+ macro(readableByteStreamControllerGetDesiredSize, readableByteStreamInternalsReadableByteStreamControllerGetDesiredSize, 1) \
+ macro(readableStreamHasBYOBReader, readableByteStreamInternalsReadableStreamHasBYOBReader, 1) \
+ macro(readableStreamHasDefaultReader, readableByteStreamInternalsReadableStreamHasDefaultReader, 1) \
+ macro(readableByteStreamControllerHandleQueueDrain, readableByteStreamInternalsReadableByteStreamControllerHandleQueueDrain, 1) \
+ macro(readableByteStreamControllerPull, readableByteStreamInternalsReadableByteStreamControllerPull, 1) \
+ macro(readableByteStreamControllerShouldCallPull, readableByteStreamInternalsReadableByteStreamControllerShouldCallPull, 1) \
+ macro(readableByteStreamControllerCallPullIfNeeded, readableByteStreamInternalsReadableByteStreamControllerCallPullIfNeeded, 1) \
+ macro(transferBufferToCurrentRealm, readableByteStreamInternalsTransferBufferToCurrentRealm, 1) \
+ macro(readableStreamReaderKind, readableByteStreamInternalsReadableStreamReaderKind, 1) \
+ macro(readableByteStreamControllerEnqueue, readableByteStreamInternalsReadableByteStreamControllerEnqueue, 2) \
+ macro(readableByteStreamControllerEnqueueChunk, readableByteStreamInternalsReadableByteStreamControllerEnqueueChunk, 4) \
+ macro(readableByteStreamControllerRespondWithNewView, readableByteStreamInternalsReadableByteStreamControllerRespondWithNewView, 2) \
+ macro(readableByteStreamControllerRespond, readableByteStreamInternalsReadableByteStreamControllerRespond, 2) \
+ macro(readableByteStreamControllerRespondInternal, readableByteStreamInternalsReadableByteStreamControllerRespondInternal, 2) \
+ macro(readableByteStreamControllerRespondInReadableState, readableByteStreamInternalsReadableByteStreamControllerRespondInReadableState, 3) \
+ macro(readableByteStreamControllerRespondInClosedState, readableByteStreamInternalsReadableByteStreamControllerRespondInClosedState, 2) \
+ macro(readableByteStreamControllerProcessPullDescriptors, readableByteStreamInternalsReadableByteStreamControllerProcessPullDescriptors, 1) \
+ macro(readableByteStreamControllerFillDescriptorFromQueue, readableByteStreamInternalsReadableByteStreamControllerFillDescriptorFromQueue, 2) \
+ macro(readableByteStreamControllerShiftPendingDescriptor, readableByteStreamInternalsReadableByteStreamControllerShiftPendingDescriptor, 1) \
+ macro(readableByteStreamControllerInvalidateBYOBRequest, readableByteStreamInternalsReadableByteStreamControllerInvalidateBYOBRequest, 1) \
+ macro(readableByteStreamControllerCommitDescriptor, readableByteStreamInternalsReadableByteStreamControllerCommitDescriptor, 2) \
+ macro(readableByteStreamControllerConvertDescriptor, readableByteStreamInternalsReadableByteStreamControllerConvertDescriptor, 1) \
+ macro(readableStreamFulfillReadIntoRequest, readableByteStreamInternalsReadableStreamFulfillReadIntoRequest, 3) \
+ macro(readableStreamBYOBReaderRead, readableByteStreamInternalsReadableStreamBYOBReaderRead, 2) \
+ macro(readableByteStreamControllerPullInto, readableByteStreamInternalsReadableByteStreamControllerPullInto, 2) \
+ macro(readableStreamAddReadIntoRequest, readableByteStreamInternalsReadableStreamAddReadIntoRequest, 1) \
+
+#define WEBCORE_BUILTIN_READABLEBYTESTREAMINTERNALS_PRIVATEINITIALIZEREADABLEBYTESTREAMCONTROLLER 1
+#define WEBCORE_BUILTIN_READABLEBYTESTREAMINTERNALS_READABLESTREAMBYTESTREAMCONTROLLERSTART 1
+#define WEBCORE_BUILTIN_READABLEBYTESTREAMINTERNALS_PRIVATEINITIALIZEREADABLESTREAMBYOBREQUEST 1
+#define WEBCORE_BUILTIN_READABLEBYTESTREAMINTERNALS_ISREADABLEBYTESTREAMCONTROLLER 1
+#define WEBCORE_BUILTIN_READABLEBYTESTREAMINTERNALS_ISREADABLESTREAMBYOBREQUEST 1
+#define WEBCORE_BUILTIN_READABLEBYTESTREAMINTERNALS_ISREADABLESTREAMBYOBREADER 1
+#define WEBCORE_BUILTIN_READABLEBYTESTREAMINTERNALS_READABLEBYTESTREAMCONTROLLERCANCEL 1
+#define WEBCORE_BUILTIN_READABLEBYTESTREAMINTERNALS_READABLEBYTESTREAMCONTROLLERERROR 1
+#define WEBCORE_BUILTIN_READABLEBYTESTREAMINTERNALS_READABLEBYTESTREAMCONTROLLERCLOSE 1
+#define WEBCORE_BUILTIN_READABLEBYTESTREAMINTERNALS_READABLEBYTESTREAMCONTROLLERCLEARPENDINGPULLINTOS 1
+#define WEBCORE_BUILTIN_READABLEBYTESTREAMINTERNALS_READABLEBYTESTREAMCONTROLLERGETDESIREDSIZE 1
+#define WEBCORE_BUILTIN_READABLEBYTESTREAMINTERNALS_READABLESTREAMHASBYOBREADER 1
+#define WEBCORE_BUILTIN_READABLEBYTESTREAMINTERNALS_READABLESTREAMHASDEFAULTREADER 1
+#define WEBCORE_BUILTIN_READABLEBYTESTREAMINTERNALS_READABLEBYTESTREAMCONTROLLERHANDLEQUEUEDRAIN 1
+#define WEBCORE_BUILTIN_READABLEBYTESTREAMINTERNALS_READABLEBYTESTREAMCONTROLLERPULL 1
+#define WEBCORE_BUILTIN_READABLEBYTESTREAMINTERNALS_READABLEBYTESTREAMCONTROLLERSHOULDCALLPULL 1
+#define WEBCORE_BUILTIN_READABLEBYTESTREAMINTERNALS_READABLEBYTESTREAMCONTROLLERCALLPULLIFNEEDED 1
+#define WEBCORE_BUILTIN_READABLEBYTESTREAMINTERNALS_TRANSFERBUFFERTOCURRENTREALM 1
+#define WEBCORE_BUILTIN_READABLEBYTESTREAMINTERNALS_READABLESTREAMREADERKIND 1
+#define WEBCORE_BUILTIN_READABLEBYTESTREAMINTERNALS_READABLEBYTESTREAMCONTROLLERENQUEUE 1
+#define WEBCORE_BUILTIN_READABLEBYTESTREAMINTERNALS_READABLEBYTESTREAMCONTROLLERENQUEUECHUNK 1
+#define WEBCORE_BUILTIN_READABLEBYTESTREAMINTERNALS_READABLEBYTESTREAMCONTROLLERRESPONDWITHNEWVIEW 1
+#define WEBCORE_BUILTIN_READABLEBYTESTREAMINTERNALS_READABLEBYTESTREAMCONTROLLERRESPOND 1
+#define WEBCORE_BUILTIN_READABLEBYTESTREAMINTERNALS_READABLEBYTESTREAMCONTROLLERRESPONDINTERNAL 1
+#define WEBCORE_BUILTIN_READABLEBYTESTREAMINTERNALS_READABLEBYTESTREAMCONTROLLERRESPONDINREADABLESTATE 1
+#define WEBCORE_BUILTIN_READABLEBYTESTREAMINTERNALS_READABLEBYTESTREAMCONTROLLERRESPONDINCLOSEDSTATE 1
+#define WEBCORE_BUILTIN_READABLEBYTESTREAMINTERNALS_READABLEBYTESTREAMCONTROLLERPROCESSPULLDESCRIPTORS 1
+#define WEBCORE_BUILTIN_READABLEBYTESTREAMINTERNALS_READABLEBYTESTREAMCONTROLLERFILLDESCRIPTORFROMQUEUE 1
+#define WEBCORE_BUILTIN_READABLEBYTESTREAMINTERNALS_READABLEBYTESTREAMCONTROLLERSHIFTPENDINGDESCRIPTOR 1
+#define WEBCORE_BUILTIN_READABLEBYTESTREAMINTERNALS_READABLEBYTESTREAMCONTROLLERINVALIDATEBYOBREQUEST 1
+#define WEBCORE_BUILTIN_READABLEBYTESTREAMINTERNALS_READABLEBYTESTREAMCONTROLLERCOMMITDESCRIPTOR 1
+#define WEBCORE_BUILTIN_READABLEBYTESTREAMINTERNALS_READABLEBYTESTREAMCONTROLLERCONVERTDESCRIPTOR 1
+#define WEBCORE_BUILTIN_READABLEBYTESTREAMINTERNALS_READABLESTREAMFULFILLREADINTOREQUEST 1
+#define WEBCORE_BUILTIN_READABLEBYTESTREAMINTERNALS_READABLESTREAMBYOBREADERREAD 1
+#define WEBCORE_BUILTIN_READABLEBYTESTREAMINTERNALS_READABLEBYTESTREAMCONTROLLERPULLINTO 1
+#define WEBCORE_BUILTIN_READABLEBYTESTREAMINTERNALS_READABLESTREAMADDREADINTOREQUEST 1
+
+#define WEBCORE_FOREACH_READABLEBYTESTREAMINTERNALS_BUILTIN_CODE(macro) \
+ macro(readableByteStreamInternalsPrivateInitializeReadableByteStreamControllerCode, privateInitializeReadableByteStreamController, ASCIILiteral(), s_readableByteStreamInternalsPrivateInitializeReadableByteStreamControllerCodeLength) \
+ macro(readableByteStreamInternalsReadableStreamByteStreamControllerStartCode, readableStreamByteStreamControllerStart, ASCIILiteral(), s_readableByteStreamInternalsReadableStreamByteStreamControllerStartCodeLength) \
+ macro(readableByteStreamInternalsPrivateInitializeReadableStreamBYOBRequestCode, privateInitializeReadableStreamBYOBRequest, ASCIILiteral(), s_readableByteStreamInternalsPrivateInitializeReadableStreamBYOBRequestCodeLength) \
+ macro(readableByteStreamInternalsIsReadableByteStreamControllerCode, isReadableByteStreamController, ASCIILiteral(), s_readableByteStreamInternalsIsReadableByteStreamControllerCodeLength) \
+ macro(readableByteStreamInternalsIsReadableStreamBYOBRequestCode, isReadableStreamBYOBRequest, ASCIILiteral(), s_readableByteStreamInternalsIsReadableStreamBYOBRequestCodeLength) \
+ macro(readableByteStreamInternalsIsReadableStreamBYOBReaderCode, isReadableStreamBYOBReader, ASCIILiteral(), s_readableByteStreamInternalsIsReadableStreamBYOBReaderCodeLength) \
+ macro(readableByteStreamInternalsReadableByteStreamControllerCancelCode, readableByteStreamControllerCancel, ASCIILiteral(), s_readableByteStreamInternalsReadableByteStreamControllerCancelCodeLength) \
+ macro(readableByteStreamInternalsReadableByteStreamControllerErrorCode, readableByteStreamControllerError, ASCIILiteral(), s_readableByteStreamInternalsReadableByteStreamControllerErrorCodeLength) \
+ macro(readableByteStreamInternalsReadableByteStreamControllerCloseCode, readableByteStreamControllerClose, ASCIILiteral(), s_readableByteStreamInternalsReadableByteStreamControllerCloseCodeLength) \
+ macro(readableByteStreamInternalsReadableByteStreamControllerClearPendingPullIntosCode, readableByteStreamControllerClearPendingPullIntos, ASCIILiteral(), s_readableByteStreamInternalsReadableByteStreamControllerClearPendingPullIntosCodeLength) \
+ macro(readableByteStreamInternalsReadableByteStreamControllerGetDesiredSizeCode, readableByteStreamControllerGetDesiredSize, ASCIILiteral(), s_readableByteStreamInternalsReadableByteStreamControllerGetDesiredSizeCodeLength) \
+ macro(readableByteStreamInternalsReadableStreamHasBYOBReaderCode, readableStreamHasBYOBReader, ASCIILiteral(), s_readableByteStreamInternalsReadableStreamHasBYOBReaderCodeLength) \
+ macro(readableByteStreamInternalsReadableStreamHasDefaultReaderCode, readableStreamHasDefaultReader, ASCIILiteral(), s_readableByteStreamInternalsReadableStreamHasDefaultReaderCodeLength) \
+ macro(readableByteStreamInternalsReadableByteStreamControllerHandleQueueDrainCode, readableByteStreamControllerHandleQueueDrain, ASCIILiteral(), s_readableByteStreamInternalsReadableByteStreamControllerHandleQueueDrainCodeLength) \
+ macro(readableByteStreamInternalsReadableByteStreamControllerPullCode, readableByteStreamControllerPull, ASCIILiteral(), s_readableByteStreamInternalsReadableByteStreamControllerPullCodeLength) \
+ macro(readableByteStreamInternalsReadableByteStreamControllerShouldCallPullCode, readableByteStreamControllerShouldCallPull, ASCIILiteral(), s_readableByteStreamInternalsReadableByteStreamControllerShouldCallPullCodeLength) \
+ macro(readableByteStreamInternalsReadableByteStreamControllerCallPullIfNeededCode, readableByteStreamControllerCallPullIfNeeded, ASCIILiteral(), s_readableByteStreamInternalsReadableByteStreamControllerCallPullIfNeededCodeLength) \
+ macro(readableByteStreamInternalsTransferBufferToCurrentRealmCode, transferBufferToCurrentRealm, ASCIILiteral(), s_readableByteStreamInternalsTransferBufferToCurrentRealmCodeLength) \
+ macro(readableByteStreamInternalsReadableStreamReaderKindCode, readableStreamReaderKind, ASCIILiteral(), s_readableByteStreamInternalsReadableStreamReaderKindCodeLength) \
+ macro(readableByteStreamInternalsReadableByteStreamControllerEnqueueCode, readableByteStreamControllerEnqueue, ASCIILiteral(), s_readableByteStreamInternalsReadableByteStreamControllerEnqueueCodeLength) \
+ macro(readableByteStreamInternalsReadableByteStreamControllerEnqueueChunkCode, readableByteStreamControllerEnqueueChunk, ASCIILiteral(), s_readableByteStreamInternalsReadableByteStreamControllerEnqueueChunkCodeLength) \
+ macro(readableByteStreamInternalsReadableByteStreamControllerRespondWithNewViewCode, readableByteStreamControllerRespondWithNewView, ASCIILiteral(), s_readableByteStreamInternalsReadableByteStreamControllerRespondWithNewViewCodeLength) \
+ macro(readableByteStreamInternalsReadableByteStreamControllerRespondCode, readableByteStreamControllerRespond, ASCIILiteral(), s_readableByteStreamInternalsReadableByteStreamControllerRespondCodeLength) \
+ macro(readableByteStreamInternalsReadableByteStreamControllerRespondInternalCode, readableByteStreamControllerRespondInternal, ASCIILiteral(), s_readableByteStreamInternalsReadableByteStreamControllerRespondInternalCodeLength) \
+ macro(readableByteStreamInternalsReadableByteStreamControllerRespondInReadableStateCode, readableByteStreamControllerRespondInReadableState, ASCIILiteral(), s_readableByteStreamInternalsReadableByteStreamControllerRespondInReadableStateCodeLength) \
+ macro(readableByteStreamInternalsReadableByteStreamControllerRespondInClosedStateCode, readableByteStreamControllerRespondInClosedState, ASCIILiteral(), s_readableByteStreamInternalsReadableByteStreamControllerRespondInClosedStateCodeLength) \
+ macro(readableByteStreamInternalsReadableByteStreamControllerProcessPullDescriptorsCode, readableByteStreamControllerProcessPullDescriptors, ASCIILiteral(), s_readableByteStreamInternalsReadableByteStreamControllerProcessPullDescriptorsCodeLength) \
+ macro(readableByteStreamInternalsReadableByteStreamControllerFillDescriptorFromQueueCode, readableByteStreamControllerFillDescriptorFromQueue, ASCIILiteral(), s_readableByteStreamInternalsReadableByteStreamControllerFillDescriptorFromQueueCodeLength) \
+ macro(readableByteStreamInternalsReadableByteStreamControllerShiftPendingDescriptorCode, readableByteStreamControllerShiftPendingDescriptor, ASCIILiteral(), s_readableByteStreamInternalsReadableByteStreamControllerShiftPendingDescriptorCodeLength) \
+ macro(readableByteStreamInternalsReadableByteStreamControllerInvalidateBYOBRequestCode, readableByteStreamControllerInvalidateBYOBRequest, ASCIILiteral(), s_readableByteStreamInternalsReadableByteStreamControllerInvalidateBYOBRequestCodeLength) \
+ macro(readableByteStreamInternalsReadableByteStreamControllerCommitDescriptorCode, readableByteStreamControllerCommitDescriptor, ASCIILiteral(), s_readableByteStreamInternalsReadableByteStreamControllerCommitDescriptorCodeLength) \
+ macro(readableByteStreamInternalsReadableByteStreamControllerConvertDescriptorCode, readableByteStreamControllerConvertDescriptor, ASCIILiteral(), s_readableByteStreamInternalsReadableByteStreamControllerConvertDescriptorCodeLength) \
+ macro(readableByteStreamInternalsReadableStreamFulfillReadIntoRequestCode, readableStreamFulfillReadIntoRequest, ASCIILiteral(), s_readableByteStreamInternalsReadableStreamFulfillReadIntoRequestCodeLength) \
+ macro(readableByteStreamInternalsReadableStreamBYOBReaderReadCode, readableStreamBYOBReaderRead, ASCIILiteral(), s_readableByteStreamInternalsReadableStreamBYOBReaderReadCodeLength) \
+ macro(readableByteStreamInternalsReadableByteStreamControllerPullIntoCode, readableByteStreamControllerPullInto, ASCIILiteral(), s_readableByteStreamInternalsReadableByteStreamControllerPullIntoCodeLength) \
+ macro(readableByteStreamInternalsReadableStreamAddReadIntoRequestCode, readableStreamAddReadIntoRequest, ASCIILiteral(), s_readableByteStreamInternalsReadableStreamAddReadIntoRequestCodeLength) \
+
+#define WEBCORE_FOREACH_READABLEBYTESTREAMINTERNALS_BUILTIN_FUNCTION_NAME(macro) \
+ macro(isReadableByteStreamController) \
+ macro(isReadableStreamBYOBReader) \
+ macro(isReadableStreamBYOBRequest) \
+ macro(privateInitializeReadableByteStreamController) \
+ macro(privateInitializeReadableStreamBYOBRequest) \
+ macro(readableByteStreamControllerCallPullIfNeeded) \
+ macro(readableByteStreamControllerCancel) \
+ macro(readableByteStreamControllerClearPendingPullIntos) \
+ macro(readableByteStreamControllerClose) \
+ macro(readableByteStreamControllerCommitDescriptor) \
+ macro(readableByteStreamControllerConvertDescriptor) \
+ macro(readableByteStreamControllerEnqueue) \
+ macro(readableByteStreamControllerEnqueueChunk) \
+ macro(readableByteStreamControllerError) \
+ macro(readableByteStreamControllerFillDescriptorFromQueue) \
+ macro(readableByteStreamControllerGetDesiredSize) \
+ macro(readableByteStreamControllerHandleQueueDrain) \
+ macro(readableByteStreamControllerInvalidateBYOBRequest) \
+ macro(readableByteStreamControllerProcessPullDescriptors) \
+ macro(readableByteStreamControllerPull) \
+ macro(readableByteStreamControllerPullInto) \
+ macro(readableByteStreamControllerRespond) \
+ macro(readableByteStreamControllerRespondInClosedState) \
+ macro(readableByteStreamControllerRespondInReadableState) \
+ macro(readableByteStreamControllerRespondInternal) \
+ macro(readableByteStreamControllerRespondWithNewView) \
+ macro(readableByteStreamControllerShiftPendingDescriptor) \
+ macro(readableByteStreamControllerShouldCallPull) \
+ macro(readableStreamAddReadIntoRequest) \
+ macro(readableStreamBYOBReaderRead) \
+ macro(readableStreamByteStreamControllerStart) \
+ macro(readableStreamFulfillReadIntoRequest) \
+ macro(readableStreamHasBYOBReader) \
+ macro(readableStreamHasDefaultReader) \
+ macro(readableStreamReaderKind) \
+ macro(transferBufferToCurrentRealm) \
+
+#define DECLARE_BUILTIN_GENERATOR(codeName, functionName, overriddenName, argumentCount) \
+ JSC::FunctionExecutable* codeName##Generator(JSC::VM&);
+
+WEBCORE_FOREACH_READABLEBYTESTREAMINTERNALS_BUILTIN_CODE(DECLARE_BUILTIN_GENERATOR)
+#undef DECLARE_BUILTIN_GENERATOR
+
+class ReadableByteStreamInternalsBuiltinsWrapper : private JSC::WeakHandleOwner {
+public:
+ explicit ReadableByteStreamInternalsBuiltinsWrapper(JSC::VM& vm)
+ : m_vm(vm)
+ WEBCORE_FOREACH_READABLEBYTESTREAMINTERNALS_BUILTIN_FUNCTION_NAME(INITIALIZE_BUILTIN_NAMES)
+#define INITIALIZE_BUILTIN_SOURCE_MEMBERS(name, functionName, overriddenName, length) , m_##name##Source(JSC::makeSource(StringImpl::createWithoutCopying(s_##name, length), { }))
+ WEBCORE_FOREACH_READABLEBYTESTREAMINTERNALS_BUILTIN_CODE(INITIALIZE_BUILTIN_SOURCE_MEMBERS)
+#undef INITIALIZE_BUILTIN_SOURCE_MEMBERS
+ {
+ }
+
+#define EXPOSE_BUILTIN_EXECUTABLES(name, functionName, overriddenName, length) \
+ JSC::UnlinkedFunctionExecutable* name##Executable(); \
+ const JSC::SourceCode& name##Source() const { return m_##name##Source; }
+ WEBCORE_FOREACH_READABLEBYTESTREAMINTERNALS_BUILTIN_CODE(EXPOSE_BUILTIN_EXECUTABLES)
+#undef EXPOSE_BUILTIN_EXECUTABLES
+
+ WEBCORE_FOREACH_READABLEBYTESTREAMINTERNALS_BUILTIN_FUNCTION_NAME(DECLARE_BUILTIN_IDENTIFIER_ACCESSOR)
+
+ void exportNames();
+
+private:
+ JSC::VM& m_vm;
+
+ WEBCORE_FOREACH_READABLEBYTESTREAMINTERNALS_BUILTIN_FUNCTION_NAME(DECLARE_BUILTIN_NAMES)
+
+#define DECLARE_BUILTIN_SOURCE_MEMBERS(name, functionName, overriddenName, length) \
+ JSC::SourceCode m_##name##Source;\
+ JSC::Weak<JSC::UnlinkedFunctionExecutable> m_##name##Executable;
+ WEBCORE_FOREACH_READABLEBYTESTREAMINTERNALS_BUILTIN_CODE(DECLARE_BUILTIN_SOURCE_MEMBERS)
+#undef DECLARE_BUILTIN_SOURCE_MEMBERS
+
+};
+
+#define DEFINE_BUILTIN_EXECUTABLES(name, functionName, overriddenName, length) \
+inline JSC::UnlinkedFunctionExecutable* ReadableByteStreamInternalsBuiltinsWrapper::name##Executable() \
+{\
+ if (!m_##name##Executable) {\
+ JSC::Identifier executableName = functionName##PublicName();\
+ if (overriddenName)\
+ executableName = JSC::Identifier::fromString(m_vm, overriddenName);\
+ m_##name##Executable = JSC::Weak<JSC::UnlinkedFunctionExecutable>(JSC::createBuiltinExecutable(m_vm, m_##name##Source, executableName, s_##name##ConstructorKind, s_##name##ConstructAbility), this, &m_##name##Executable);\
+ }\
+ return m_##name##Executable.get();\
+}
+WEBCORE_FOREACH_READABLEBYTESTREAMINTERNALS_BUILTIN_CODE(DEFINE_BUILTIN_EXECUTABLES)
+#undef DEFINE_BUILTIN_EXECUTABLES
+
+inline void ReadableByteStreamInternalsBuiltinsWrapper::exportNames()
+{
+#define EXPORT_FUNCTION_NAME(name) m_vm.propertyNames->appendExternalName(name##PublicName(), name##PrivateName());
+ WEBCORE_FOREACH_READABLEBYTESTREAMINTERNALS_BUILTIN_FUNCTION_NAME(EXPORT_FUNCTION_NAME)
+#undef EXPORT_FUNCTION_NAME
+}
+
+class ReadableByteStreamInternalsBuiltinFunctions {
+public:
+ explicit ReadableByteStreamInternalsBuiltinFunctions(JSC::VM& vm) : m_vm(vm) { }
+
+ void init(JSC::JSGlobalObject&);
+ template<typename Visitor> void visit(Visitor&);
+
+public:
+ JSC::VM& m_vm;
+
+#define DECLARE_BUILTIN_SOURCE_MEMBERS(functionName) \
+ JSC::WriteBarrier<JSC::JSFunction> m_##functionName##Function;
+ WEBCORE_FOREACH_READABLEBYTESTREAMINTERNALS_BUILTIN_FUNCTION_NAME(DECLARE_BUILTIN_SOURCE_MEMBERS)
+#undef DECLARE_BUILTIN_SOURCE_MEMBERS
+};
+
+inline void ReadableByteStreamInternalsBuiltinFunctions::init(JSC::JSGlobalObject& globalObject)
+{
+#define EXPORT_FUNCTION(codeName, functionName, overriddenName, length)\
+ m_##functionName##Function.set(m_vm, &globalObject, JSC::JSFunction::create(m_vm, codeName##Generator(m_vm), &globalObject));
+ WEBCORE_FOREACH_READABLEBYTESTREAMINTERNALS_BUILTIN_CODE(EXPORT_FUNCTION)
+#undef EXPORT_FUNCTION
+}
+
+template<typename Visitor>
+inline void ReadableByteStreamInternalsBuiltinFunctions::visit(Visitor& visitor)
+{
+#define VISIT_FUNCTION(name) visitor.append(m_##name##Function);
+ WEBCORE_FOREACH_READABLEBYTESTREAMINTERNALS_BUILTIN_FUNCTION_NAME(VISIT_FUNCTION)
+#undef VISIT_FUNCTION
+}
+
+template void ReadableByteStreamInternalsBuiltinFunctions::visit(JSC::AbstractSlotVisitor&);
+template void ReadableByteStreamInternalsBuiltinFunctions::visit(JSC::SlotVisitor&);
+
+
+
+} // namespace WebCore
diff --git a/src/bun.js/builtins/cpp/ReadableStreamBYOBReaderBuiltins.cpp b/src/bun.js/builtins/cpp/ReadableStreamBYOBReaderBuiltins.cpp
new file mode 100644
index 000000000..81486dffe
--- /dev/null
+++ b/src/bun.js/builtins/cpp/ReadableStreamBYOBReaderBuiltins.cpp
@@ -0,0 +1,169 @@
+/*
+ * Copyright (c) 2015 Igalia
+ * Copyright (c) 2015 Igalia S.L.
+ * Copyright (c) 2015 Igalia.
+ * Copyright (c) 2015, 2016 Canon Inc. All rights reserved.
+ * Copyright (c) 2015, 2016, 2017 Canon Inc.
+ * Copyright (c) 2016, 2020 Apple Inc. All rights reserved.
+ * Copyright (c) 2022 Codeblog Corp. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+// DO NOT EDIT THIS FILE. It is automatically generated from JavaScript files for
+// builtins by the script: Source/JavaScriptCore/Scripts/generate-js-builtins.py
+
+#include "config.h"
+#include "ReadableStreamBYOBReaderBuiltins.h"
+
+#include "WebCoreJSClientData.h"
+#include <JavaScriptCore/HeapInlines.h>
+#include <JavaScriptCore/IdentifierInlines.h>
+#include <JavaScriptCore/Intrinsic.h>
+#include <JavaScriptCore/JSCJSValueInlines.h>
+#include <JavaScriptCore/JSCellInlines.h>
+#include <JavaScriptCore/StructureInlines.h>
+#include <JavaScriptCore/VM.h>
+
+namespace WebCore {
+
+const JSC::ConstructAbility s_readableStreamBYOBReaderInitializeReadableStreamBYOBReaderCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableStreamBYOBReaderInitializeReadableStreamBYOBReaderCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableStreamBYOBReaderInitializeReadableStreamBYOBReaderCodeLength = 585;
+static const JSC::Intrinsic s_readableStreamBYOBReaderInitializeReadableStreamBYOBReaderCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableStreamBYOBReaderInitializeReadableStreamBYOBReaderCode =
+ "(function (stream)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " if (!@isReadableStream(stream))\n" \
+ " @throwTypeError(\"ReadableStreamBYOBReader needs a ReadableStream\");\n" \
+ " if (!@isReadableByteStreamController(@getByIdDirectPrivate(stream, \"readableStreamController\")))\n" \
+ " @throwTypeError(\"ReadableStreamBYOBReader needs a ReadableByteStreamController\");\n" \
+ " if (@isReadableStreamLocked(stream))\n" \
+ " @throwTypeError(\"ReadableStream is locked\");\n" \
+ "\n" \
+ " @readableStreamReaderGenericInitialize(this, stream);\n" \
+ " @putByIdDirectPrivate(this, \"readIntoRequests\", @createFIFO());\n" \
+ "\n" \
+ " return this;\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableStreamBYOBReaderCancelCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableStreamBYOBReaderCancelCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableStreamBYOBReaderCancelCodeLength = 410;
+static const JSC::Intrinsic s_readableStreamBYOBReaderCancelCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableStreamBYOBReaderCancelCode =
+ "(function (reason)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " if (!@isReadableStreamBYOBReader(this))\n" \
+ " return @Promise.@reject(@makeThisTypeError(\"ReadableStreamBYOBReader\", \"cancel\"));\n" \
+ "\n" \
+ " if (!@getByIdDirectPrivate(this, \"ownerReadableStream\"))\n" \
+ " return @Promise.@reject(@makeTypeError(\"cancel() called on a reader owned by no readable stream\"));\n" \
+ "\n" \
+ " return @readableStreamReaderGenericCancel(this, reason);\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableStreamBYOBReaderReadCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableStreamBYOBReaderReadCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableStreamBYOBReaderReadCodeLength = 762;
+static const JSC::Intrinsic s_readableStreamBYOBReaderReadCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableStreamBYOBReaderReadCode =
+ "(function (view)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " if (!@isReadableStreamBYOBReader(this))\n" \
+ " return @Promise.@reject(@makeThisTypeError(\"ReadableStreamBYOBReader\", \"read\"));\n" \
+ "\n" \
+ " if (!@getByIdDirectPrivate(this, \"ownerReadableStream\"))\n" \
+ " return @Promise.@reject(@makeTypeError(\"read() called on a reader owned by no readable stream\"));\n" \
+ "\n" \
+ " if (!@isObject(view))\n" \
+ " return @Promise.@reject(@makeTypeError(\"Provided view is not an object\"));\n" \
+ "\n" \
+ " if (!@ArrayBuffer.@isView(view))\n" \
+ " return @Promise.@reject(@makeTypeError(\"Provided view is not an ArrayBufferView\"));\n" \
+ "\n" \
+ " if (view.byteLength === 0)\n" \
+ " return @Promise.@reject(@makeTypeError(\"Provided view cannot have a 0 byteLength\"));\n" \
+ "\n" \
+ " return @readableStreamBYOBReaderRead(this, view);\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableStreamBYOBReaderReleaseLockCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableStreamBYOBReaderReleaseLockCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableStreamBYOBReaderReleaseLockCodeLength = 447;
+static const JSC::Intrinsic s_readableStreamBYOBReaderReleaseLockCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableStreamBYOBReaderReleaseLockCode =
+ "(function ()\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " if (!@isReadableStreamBYOBReader(this))\n" \
+ " throw @makeThisTypeError(\"ReadableStreamBYOBReader\", \"releaseLock\");\n" \
+ "\n" \
+ " if (!@getByIdDirectPrivate(this, \"ownerReadableStream\"))\n" \
+ " return;\n" \
+ "\n" \
+ " if (@getByIdDirectPrivate(this, \"readIntoRequests\")?.isNotEmpty())\n" \
+ " @throwTypeError(\"There are still pending read requests, cannot release the lock\");\n" \
+ "\n" \
+ " @readableStreamReaderGenericRelease(this);\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableStreamBYOBReaderClosedCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableStreamBYOBReaderClosedCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableStreamBYOBReaderClosedCodeLength = 251;
+static const JSC::Intrinsic s_readableStreamBYOBReaderClosedCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableStreamBYOBReaderClosedCode =
+ "(function ()\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " if (!@isReadableStreamBYOBReader(this))\n" \
+ " return @Promise.@reject(@makeGetterTypeError(\"ReadableStreamBYOBReader\", \"closed\"));\n" \
+ "\n" \
+ " return @getByIdDirectPrivate(this, \"closedPromiseCapability\").@promise;\n" \
+ "})\n" \
+;
+
+
+#define DEFINE_BUILTIN_GENERATOR(codeName, functionName, overriddenName, argumentCount) \
+JSC::FunctionExecutable* codeName##Generator(JSC::VM& vm) \
+{\
+ JSVMClientData* clientData = static_cast<JSVMClientData*>(vm.clientData); \
+ return clientData->builtinFunctions().readableStreamBYOBReaderBuiltins().codeName##Executable()->link(vm, nullptr, clientData->builtinFunctions().readableStreamBYOBReaderBuiltins().codeName##Source(), std::nullopt, s_##codeName##Intrinsic); \
+}
+WEBCORE_FOREACH_READABLESTREAMBYOBREADER_BUILTIN_CODE(DEFINE_BUILTIN_GENERATOR)
+#undef DEFINE_BUILTIN_GENERATOR
+
+
+} // namespace WebCore
diff --git a/src/bun.js/builtins/cpp/ReadableStreamBYOBReaderBuiltins.h b/src/bun.js/builtins/cpp/ReadableStreamBYOBReaderBuiltins.h
new file mode 100644
index 000000000..0011df117
--- /dev/null
+++ b/src/bun.js/builtins/cpp/ReadableStreamBYOBReaderBuiltins.h
@@ -0,0 +1,159 @@
+/*
+ * Copyright (c) 2015 Igalia
+ * Copyright (c) 2015 Igalia S.L.
+ * Copyright (c) 2015 Igalia.
+ * Copyright (c) 2015, 2016 Canon Inc. All rights reserved.
+ * Copyright (c) 2015, 2016, 2017 Canon Inc.
+ * Copyright (c) 2016, 2020 Apple Inc. All rights reserved.
+ * Copyright (c) 2022 Codeblog Corp. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+// DO NOT EDIT THIS FILE. It is automatically generated from JavaScript files for
+// builtins by the script: Source/JavaScriptCore/Scripts/generate-js-builtins.py
+
+#pragma once
+
+#include <JavaScriptCore/BuiltinUtils.h>
+#include <JavaScriptCore/Identifier.h>
+#include <JavaScriptCore/JSFunction.h>
+#include <JavaScriptCore/UnlinkedFunctionExecutable.h>
+
+namespace JSC {
+class FunctionExecutable;
+}
+
+namespace WebCore {
+
+/* ReadableStreamBYOBReader */
+extern const char* const s_readableStreamBYOBReaderInitializeReadableStreamBYOBReaderCode;
+extern const int s_readableStreamBYOBReaderInitializeReadableStreamBYOBReaderCodeLength;
+extern const JSC::ConstructAbility s_readableStreamBYOBReaderInitializeReadableStreamBYOBReaderCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableStreamBYOBReaderInitializeReadableStreamBYOBReaderCodeConstructorKind;
+extern const char* const s_readableStreamBYOBReaderCancelCode;
+extern const int s_readableStreamBYOBReaderCancelCodeLength;
+extern const JSC::ConstructAbility s_readableStreamBYOBReaderCancelCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableStreamBYOBReaderCancelCodeConstructorKind;
+extern const char* const s_readableStreamBYOBReaderReadCode;
+extern const int s_readableStreamBYOBReaderReadCodeLength;
+extern const JSC::ConstructAbility s_readableStreamBYOBReaderReadCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableStreamBYOBReaderReadCodeConstructorKind;
+extern const char* const s_readableStreamBYOBReaderReleaseLockCode;
+extern const int s_readableStreamBYOBReaderReleaseLockCodeLength;
+extern const JSC::ConstructAbility s_readableStreamBYOBReaderReleaseLockCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableStreamBYOBReaderReleaseLockCodeConstructorKind;
+extern const char* const s_readableStreamBYOBReaderClosedCode;
+extern const int s_readableStreamBYOBReaderClosedCodeLength;
+extern const JSC::ConstructAbility s_readableStreamBYOBReaderClosedCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableStreamBYOBReaderClosedCodeConstructorKind;
+
+#define WEBCORE_FOREACH_READABLESTREAMBYOBREADER_BUILTIN_DATA(macro) \
+ macro(initializeReadableStreamBYOBReader, readableStreamBYOBReaderInitializeReadableStreamBYOBReader, 1) \
+ macro(cancel, readableStreamBYOBReaderCancel, 1) \
+ macro(read, readableStreamBYOBReaderRead, 1) \
+ macro(releaseLock, readableStreamBYOBReaderReleaseLock, 0) \
+ macro(closed, readableStreamBYOBReaderClosed, 0) \
+
+#define WEBCORE_BUILTIN_READABLESTREAMBYOBREADER_INITIALIZEREADABLESTREAMBYOBREADER 1
+#define WEBCORE_BUILTIN_READABLESTREAMBYOBREADER_CANCEL 1
+#define WEBCORE_BUILTIN_READABLESTREAMBYOBREADER_READ 1
+#define WEBCORE_BUILTIN_READABLESTREAMBYOBREADER_RELEASELOCK 1
+#define WEBCORE_BUILTIN_READABLESTREAMBYOBREADER_CLOSED 1
+
+#define WEBCORE_FOREACH_READABLESTREAMBYOBREADER_BUILTIN_CODE(macro) \
+ macro(readableStreamBYOBReaderInitializeReadableStreamBYOBReaderCode, initializeReadableStreamBYOBReader, ASCIILiteral(), s_readableStreamBYOBReaderInitializeReadableStreamBYOBReaderCodeLength) \
+ macro(readableStreamBYOBReaderCancelCode, cancel, ASCIILiteral(), s_readableStreamBYOBReaderCancelCodeLength) \
+ macro(readableStreamBYOBReaderReadCode, read, ASCIILiteral(), s_readableStreamBYOBReaderReadCodeLength) \
+ macro(readableStreamBYOBReaderReleaseLockCode, releaseLock, ASCIILiteral(), s_readableStreamBYOBReaderReleaseLockCodeLength) \
+ macro(readableStreamBYOBReaderClosedCode, closed, "get closed"_s, s_readableStreamBYOBReaderClosedCodeLength) \
+
+#define WEBCORE_FOREACH_READABLESTREAMBYOBREADER_BUILTIN_FUNCTION_NAME(macro) \
+ macro(cancel) \
+ macro(closed) \
+ macro(initializeReadableStreamBYOBReader) \
+ macro(read) \
+ macro(releaseLock) \
+
+#define DECLARE_BUILTIN_GENERATOR(codeName, functionName, overriddenName, argumentCount) \
+ JSC::FunctionExecutable* codeName##Generator(JSC::VM&);
+
+WEBCORE_FOREACH_READABLESTREAMBYOBREADER_BUILTIN_CODE(DECLARE_BUILTIN_GENERATOR)
+#undef DECLARE_BUILTIN_GENERATOR
+
+class ReadableStreamBYOBReaderBuiltinsWrapper : private JSC::WeakHandleOwner {
+public:
+ explicit ReadableStreamBYOBReaderBuiltinsWrapper(JSC::VM& vm)
+ : m_vm(vm)
+ WEBCORE_FOREACH_READABLESTREAMBYOBREADER_BUILTIN_FUNCTION_NAME(INITIALIZE_BUILTIN_NAMES)
+#define INITIALIZE_BUILTIN_SOURCE_MEMBERS(name, functionName, overriddenName, length) , m_##name##Source(JSC::makeSource(StringImpl::createWithoutCopying(s_##name, length), { }))
+ WEBCORE_FOREACH_READABLESTREAMBYOBREADER_BUILTIN_CODE(INITIALIZE_BUILTIN_SOURCE_MEMBERS)
+#undef INITIALIZE_BUILTIN_SOURCE_MEMBERS
+ {
+ }
+
+#define EXPOSE_BUILTIN_EXECUTABLES(name, functionName, overriddenName, length) \
+ JSC::UnlinkedFunctionExecutable* name##Executable(); \
+ const JSC::SourceCode& name##Source() const { return m_##name##Source; }
+ WEBCORE_FOREACH_READABLESTREAMBYOBREADER_BUILTIN_CODE(EXPOSE_BUILTIN_EXECUTABLES)
+#undef EXPOSE_BUILTIN_EXECUTABLES
+
+ WEBCORE_FOREACH_READABLESTREAMBYOBREADER_BUILTIN_FUNCTION_NAME(DECLARE_BUILTIN_IDENTIFIER_ACCESSOR)
+
+ void exportNames();
+
+private:
+ JSC::VM& m_vm;
+
+ WEBCORE_FOREACH_READABLESTREAMBYOBREADER_BUILTIN_FUNCTION_NAME(DECLARE_BUILTIN_NAMES)
+
+#define DECLARE_BUILTIN_SOURCE_MEMBERS(name, functionName, overriddenName, length) \
+ JSC::SourceCode m_##name##Source;\
+ JSC::Weak<JSC::UnlinkedFunctionExecutable> m_##name##Executable;
+ WEBCORE_FOREACH_READABLESTREAMBYOBREADER_BUILTIN_CODE(DECLARE_BUILTIN_SOURCE_MEMBERS)
+#undef DECLARE_BUILTIN_SOURCE_MEMBERS
+
+};
+
+#define DEFINE_BUILTIN_EXECUTABLES(name, functionName, overriddenName, length) \
+inline JSC::UnlinkedFunctionExecutable* ReadableStreamBYOBReaderBuiltinsWrapper::name##Executable() \
+{\
+ if (!m_##name##Executable) {\
+ JSC::Identifier executableName = functionName##PublicName();\
+ if (overriddenName)\
+ executableName = JSC::Identifier::fromString(m_vm, overriddenName);\
+ m_##name##Executable = JSC::Weak<JSC::UnlinkedFunctionExecutable>(JSC::createBuiltinExecutable(m_vm, m_##name##Source, executableName, s_##name##ConstructorKind, s_##name##ConstructAbility), this, &m_##name##Executable);\
+ }\
+ return m_##name##Executable.get();\
+}
+WEBCORE_FOREACH_READABLESTREAMBYOBREADER_BUILTIN_CODE(DEFINE_BUILTIN_EXECUTABLES)
+#undef DEFINE_BUILTIN_EXECUTABLES
+
+inline void ReadableStreamBYOBReaderBuiltinsWrapper::exportNames()
+{
+#define EXPORT_FUNCTION_NAME(name) m_vm.propertyNames->appendExternalName(name##PublicName(), name##PrivateName());
+ WEBCORE_FOREACH_READABLESTREAMBYOBREADER_BUILTIN_FUNCTION_NAME(EXPORT_FUNCTION_NAME)
+#undef EXPORT_FUNCTION_NAME
+}
+
+} // namespace WebCore
diff --git a/src/bun.js/builtins/cpp/ReadableStreamBYOBRequestBuiltins.cpp b/src/bun.js/builtins/cpp/ReadableStreamBYOBRequestBuiltins.cpp
new file mode 100644
index 000000000..1c4d9fdb3
--- /dev/null
+++ b/src/bun.js/builtins/cpp/ReadableStreamBYOBRequestBuiltins.cpp
@@ -0,0 +1,137 @@
+/*
+ * Copyright (c) 2015 Igalia
+ * Copyright (c) 2015 Igalia S.L.
+ * Copyright (c) 2015 Igalia.
+ * Copyright (c) 2015, 2016 Canon Inc. All rights reserved.
+ * Copyright (c) 2015, 2016, 2017 Canon Inc.
+ * Copyright (c) 2016, 2020 Apple Inc. All rights reserved.
+ * Copyright (c) 2022 Codeblog Corp. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+// DO NOT EDIT THIS FILE. It is automatically generated from JavaScript files for
+// builtins by the script: Source/JavaScriptCore/Scripts/generate-js-builtins.py
+
+#include "config.h"
+#include "ReadableStreamBYOBRequestBuiltins.h"
+
+#include "WebCoreJSClientData.h"
+#include <JavaScriptCore/HeapInlines.h>
+#include <JavaScriptCore/IdentifierInlines.h>
+#include <JavaScriptCore/Intrinsic.h>
+#include <JavaScriptCore/JSCJSValueInlines.h>
+#include <JavaScriptCore/JSCellInlines.h>
+#include <JavaScriptCore/StructureInlines.h>
+#include <JavaScriptCore/VM.h>
+
+namespace WebCore {
+
+const JSC::ConstructAbility s_readableStreamBYOBRequestInitializeReadableStreamBYOBRequestCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableStreamBYOBRequestInitializeReadableStreamBYOBRequestCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableStreamBYOBRequestInitializeReadableStreamBYOBRequestCodeLength = 306;
+static const JSC::Intrinsic s_readableStreamBYOBRequestInitializeReadableStreamBYOBRequestCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableStreamBYOBRequestInitializeReadableStreamBYOBRequestCode =
+ "(function (controller, view)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " if (arguments.length !== 3 && arguments[2] !== @isReadableStream)\n" \
+ " @throwTypeError(\"ReadableStreamBYOBRequest constructor should not be called directly\");\n" \
+ "\n" \
+ " return @privateInitializeReadableStreamBYOBRequest.@call(this, controller, view);\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableStreamBYOBRequestRespondCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableStreamBYOBRequestRespondCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableStreamBYOBRequestRespondCodeLength = 504;
+static const JSC::Intrinsic s_readableStreamBYOBRequestRespondCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableStreamBYOBRequestRespondCode =
+ "(function (bytesWritten)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " if (!@isReadableStreamBYOBRequest(this))\n" \
+ " throw @makeThisTypeError(\"ReadableStreamBYOBRequest\", \"respond\");\n" \
+ "\n" \
+ " if (@getByIdDirectPrivate(this, \"associatedReadableByteStreamController\") === @undefined)\n" \
+ " @throwTypeError(\"ReadableStreamBYOBRequest.associatedReadableByteStreamController is undefined\");\n" \
+ "\n" \
+ " return @readableByteStreamControllerRespond(@getByIdDirectPrivate(this, \"associatedReadableByteStreamController\"), bytesWritten);\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableStreamBYOBRequestRespondWithNewViewCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableStreamBYOBRequestRespondWithNewViewCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableStreamBYOBRequestRespondWithNewViewCodeLength = 691;
+static const JSC::Intrinsic s_readableStreamBYOBRequestRespondWithNewViewCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableStreamBYOBRequestRespondWithNewViewCode =
+ "(function (view)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " if (!@isReadableStreamBYOBRequest(this))\n" \
+ " throw @makeThisTypeError(\"ReadableStreamBYOBRequest\", \"respond\");\n" \
+ "\n" \
+ " if (@getByIdDirectPrivate(this, \"associatedReadableByteStreamController\") === @undefined)\n" \
+ " @throwTypeError(\"ReadableStreamBYOBRequest.associatedReadableByteStreamController is undefined\");\n" \
+ "\n" \
+ " if (!@isObject(view))\n" \
+ " @throwTypeError(\"Provided view is not an object\");\n" \
+ "\n" \
+ " if (!@ArrayBuffer.@isView(view))\n" \
+ " @throwTypeError(\"Provided view is not an ArrayBufferView\");\n" \
+ "\n" \
+ " return @readableByteStreamControllerRespondWithNewView(@getByIdDirectPrivate(this, \"associatedReadableByteStreamController\"), view);\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableStreamBYOBRequestViewCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableStreamBYOBRequestViewCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableStreamBYOBRequestViewCodeLength = 204;
+static const JSC::Intrinsic s_readableStreamBYOBRequestViewCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableStreamBYOBRequestViewCode =
+ "(function ()\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " if (!@isReadableStreamBYOBRequest(this))\n" \
+ " throw @makeGetterTypeError(\"ReadableStreamBYOBRequest\", \"view\");\n" \
+ "\n" \
+ " return @getByIdDirectPrivate(this, \"view\");\n" \
+ "})\n" \
+;
+
+
+#define DEFINE_BUILTIN_GENERATOR(codeName, functionName, overriddenName, argumentCount) \
+JSC::FunctionExecutable* codeName##Generator(JSC::VM& vm) \
+{\
+ JSVMClientData* clientData = static_cast<JSVMClientData*>(vm.clientData); \
+ return clientData->builtinFunctions().readableStreamBYOBRequestBuiltins().codeName##Executable()->link(vm, nullptr, clientData->builtinFunctions().readableStreamBYOBRequestBuiltins().codeName##Source(), std::nullopt, s_##codeName##Intrinsic); \
+}
+WEBCORE_FOREACH_READABLESTREAMBYOBREQUEST_BUILTIN_CODE(DEFINE_BUILTIN_GENERATOR)
+#undef DEFINE_BUILTIN_GENERATOR
+
+
+} // namespace WebCore
diff --git a/src/bun.js/builtins/cpp/ReadableStreamBYOBRequestBuiltins.h b/src/bun.js/builtins/cpp/ReadableStreamBYOBRequestBuiltins.h
new file mode 100644
index 000000000..8e8aedff3
--- /dev/null
+++ b/src/bun.js/builtins/cpp/ReadableStreamBYOBRequestBuiltins.h
@@ -0,0 +1,151 @@
+/*
+ * Copyright (c) 2015 Igalia
+ * Copyright (c) 2015 Igalia S.L.
+ * Copyright (c) 2015 Igalia.
+ * Copyright (c) 2015, 2016 Canon Inc. All rights reserved.
+ * Copyright (c) 2015, 2016, 2017 Canon Inc.
+ * Copyright (c) 2016, 2020 Apple Inc. All rights reserved.
+ * Copyright (c) 2022 Codeblog Corp. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+// DO NOT EDIT THIS FILE. It is automatically generated from JavaScript files for
+// builtins by the script: Source/JavaScriptCore/Scripts/generate-js-builtins.py
+
+#pragma once
+
+#include <JavaScriptCore/BuiltinUtils.h>
+#include <JavaScriptCore/Identifier.h>
+#include <JavaScriptCore/JSFunction.h>
+#include <JavaScriptCore/UnlinkedFunctionExecutable.h>
+
+namespace JSC {
+class FunctionExecutable;
+}
+
+namespace WebCore {
+
+/* ReadableStreamBYOBRequest */
+extern const char* const s_readableStreamBYOBRequestInitializeReadableStreamBYOBRequestCode;
+extern const int s_readableStreamBYOBRequestInitializeReadableStreamBYOBRequestCodeLength;
+extern const JSC::ConstructAbility s_readableStreamBYOBRequestInitializeReadableStreamBYOBRequestCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableStreamBYOBRequestInitializeReadableStreamBYOBRequestCodeConstructorKind;
+extern const char* const s_readableStreamBYOBRequestRespondCode;
+extern const int s_readableStreamBYOBRequestRespondCodeLength;
+extern const JSC::ConstructAbility s_readableStreamBYOBRequestRespondCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableStreamBYOBRequestRespondCodeConstructorKind;
+extern const char* const s_readableStreamBYOBRequestRespondWithNewViewCode;
+extern const int s_readableStreamBYOBRequestRespondWithNewViewCodeLength;
+extern const JSC::ConstructAbility s_readableStreamBYOBRequestRespondWithNewViewCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableStreamBYOBRequestRespondWithNewViewCodeConstructorKind;
+extern const char* const s_readableStreamBYOBRequestViewCode;
+extern const int s_readableStreamBYOBRequestViewCodeLength;
+extern const JSC::ConstructAbility s_readableStreamBYOBRequestViewCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableStreamBYOBRequestViewCodeConstructorKind;
+
+#define WEBCORE_FOREACH_READABLESTREAMBYOBREQUEST_BUILTIN_DATA(macro) \
+ macro(initializeReadableStreamBYOBRequest, readableStreamBYOBRequestInitializeReadableStreamBYOBRequest, 2) \
+ macro(respond, readableStreamBYOBRequestRespond, 1) \
+ macro(respondWithNewView, readableStreamBYOBRequestRespondWithNewView, 1) \
+ macro(view, readableStreamBYOBRequestView, 0) \
+
+#define WEBCORE_BUILTIN_READABLESTREAMBYOBREQUEST_INITIALIZEREADABLESTREAMBYOBREQUEST 1
+#define WEBCORE_BUILTIN_READABLESTREAMBYOBREQUEST_RESPOND 1
+#define WEBCORE_BUILTIN_READABLESTREAMBYOBREQUEST_RESPONDWITHNEWVIEW 1
+#define WEBCORE_BUILTIN_READABLESTREAMBYOBREQUEST_VIEW 1
+
+#define WEBCORE_FOREACH_READABLESTREAMBYOBREQUEST_BUILTIN_CODE(macro) \
+ macro(readableStreamBYOBRequestInitializeReadableStreamBYOBRequestCode, initializeReadableStreamBYOBRequest, ASCIILiteral(), s_readableStreamBYOBRequestInitializeReadableStreamBYOBRequestCodeLength) \
+ macro(readableStreamBYOBRequestRespondCode, respond, ASCIILiteral(), s_readableStreamBYOBRequestRespondCodeLength) \
+ macro(readableStreamBYOBRequestRespondWithNewViewCode, respondWithNewView, ASCIILiteral(), s_readableStreamBYOBRequestRespondWithNewViewCodeLength) \
+ macro(readableStreamBYOBRequestViewCode, view, "get view"_s, s_readableStreamBYOBRequestViewCodeLength) \
+
+#define WEBCORE_FOREACH_READABLESTREAMBYOBREQUEST_BUILTIN_FUNCTION_NAME(macro) \
+ macro(initializeReadableStreamBYOBRequest) \
+ macro(respond) \
+ macro(respondWithNewView) \
+ macro(view) \
+
+#define DECLARE_BUILTIN_GENERATOR(codeName, functionName, overriddenName, argumentCount) \
+ JSC::FunctionExecutable* codeName##Generator(JSC::VM&);
+
+WEBCORE_FOREACH_READABLESTREAMBYOBREQUEST_BUILTIN_CODE(DECLARE_BUILTIN_GENERATOR)
+#undef DECLARE_BUILTIN_GENERATOR
+
+class ReadableStreamBYOBRequestBuiltinsWrapper : private JSC::WeakHandleOwner {
+public:
+ explicit ReadableStreamBYOBRequestBuiltinsWrapper(JSC::VM& vm)
+ : m_vm(vm)
+ WEBCORE_FOREACH_READABLESTREAMBYOBREQUEST_BUILTIN_FUNCTION_NAME(INITIALIZE_BUILTIN_NAMES)
+#define INITIALIZE_BUILTIN_SOURCE_MEMBERS(name, functionName, overriddenName, length) , m_##name##Source(JSC::makeSource(StringImpl::createWithoutCopying(s_##name, length), { }))
+ WEBCORE_FOREACH_READABLESTREAMBYOBREQUEST_BUILTIN_CODE(INITIALIZE_BUILTIN_SOURCE_MEMBERS)
+#undef INITIALIZE_BUILTIN_SOURCE_MEMBERS
+ {
+ }
+
+#define EXPOSE_BUILTIN_EXECUTABLES(name, functionName, overriddenName, length) \
+ JSC::UnlinkedFunctionExecutable* name##Executable(); \
+ const JSC::SourceCode& name##Source() const { return m_##name##Source; }
+ WEBCORE_FOREACH_READABLESTREAMBYOBREQUEST_BUILTIN_CODE(EXPOSE_BUILTIN_EXECUTABLES)
+#undef EXPOSE_BUILTIN_EXECUTABLES
+
+ WEBCORE_FOREACH_READABLESTREAMBYOBREQUEST_BUILTIN_FUNCTION_NAME(DECLARE_BUILTIN_IDENTIFIER_ACCESSOR)
+
+ void exportNames();
+
+private:
+ JSC::VM& m_vm;
+
+ WEBCORE_FOREACH_READABLESTREAMBYOBREQUEST_BUILTIN_FUNCTION_NAME(DECLARE_BUILTIN_NAMES)
+
+#define DECLARE_BUILTIN_SOURCE_MEMBERS(name, functionName, overriddenName, length) \
+ JSC::SourceCode m_##name##Source;\
+ JSC::Weak<JSC::UnlinkedFunctionExecutable> m_##name##Executable;
+ WEBCORE_FOREACH_READABLESTREAMBYOBREQUEST_BUILTIN_CODE(DECLARE_BUILTIN_SOURCE_MEMBERS)
+#undef DECLARE_BUILTIN_SOURCE_MEMBERS
+
+};
+
+#define DEFINE_BUILTIN_EXECUTABLES(name, functionName, overriddenName, length) \
+inline JSC::UnlinkedFunctionExecutable* ReadableStreamBYOBRequestBuiltinsWrapper::name##Executable() \
+{\
+ if (!m_##name##Executable) {\
+ JSC::Identifier executableName = functionName##PublicName();\
+ if (overriddenName)\
+ executableName = JSC::Identifier::fromString(m_vm, overriddenName);\
+ m_##name##Executable = JSC::Weak<JSC::UnlinkedFunctionExecutable>(JSC::createBuiltinExecutable(m_vm, m_##name##Source, executableName, s_##name##ConstructorKind, s_##name##ConstructAbility), this, &m_##name##Executable);\
+ }\
+ return m_##name##Executable.get();\
+}
+WEBCORE_FOREACH_READABLESTREAMBYOBREQUEST_BUILTIN_CODE(DEFINE_BUILTIN_EXECUTABLES)
+#undef DEFINE_BUILTIN_EXECUTABLES
+
+inline void ReadableStreamBYOBRequestBuiltinsWrapper::exportNames()
+{
+#define EXPORT_FUNCTION_NAME(name) m_vm.propertyNames->appendExternalName(name##PublicName(), name##PrivateName());
+ WEBCORE_FOREACH_READABLESTREAMBYOBREQUEST_BUILTIN_FUNCTION_NAME(EXPORT_FUNCTION_NAME)
+#undef EXPORT_FUNCTION_NAME
+}
+
+} // namespace WebCore
diff --git a/src/bun.js/builtins/cpp/ReadableStreamBuiltins.cpp b/src/bun.js/builtins/cpp/ReadableStreamBuiltins.cpp
new file mode 100644
index 000000000..7ce97e7bb
--- /dev/null
+++ b/src/bun.js/builtins/cpp/ReadableStreamBuiltins.cpp
@@ -0,0 +1,620 @@
+/*
+ * Copyright (c) 2015 Igalia
+ * Copyright (c) 2015 Igalia S.L.
+ * Copyright (c) 2015 Igalia.
+ * Copyright (c) 2015, 2016 Canon Inc. All rights reserved.
+ * Copyright (c) 2015, 2016, 2017 Canon Inc.
+ * Copyright (c) 2016, 2020 Apple Inc. All rights reserved.
+ * Copyright (c) 2022 Codeblog Corp. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+// DO NOT EDIT THIS FILE. It is automatically generated from JavaScript files for
+// builtins by the script: Source/JavaScriptCore/Scripts/generate-js-builtins.py
+
+#include "config.h"
+#include "ReadableStreamBuiltins.h"
+
+#include "WebCoreJSClientData.h"
+#include <JavaScriptCore/HeapInlines.h>
+#include <JavaScriptCore/IdentifierInlines.h>
+#include <JavaScriptCore/Intrinsic.h>
+#include <JavaScriptCore/JSCJSValueInlines.h>
+#include <JavaScriptCore/JSCellInlines.h>
+#include <JavaScriptCore/StructureInlines.h>
+#include <JavaScriptCore/VM.h>
+
+namespace WebCore {
+
+const JSC::ConstructAbility s_readableStreamInitializeReadableStreamCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableStreamInitializeReadableStreamCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableStreamInitializeReadableStreamCodeLength = 2501;
+static const JSC::Intrinsic s_readableStreamInitializeReadableStreamCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableStreamInitializeReadableStreamCode =
+ "(function (underlyingSource, strategy)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " if (underlyingSource === @undefined)\n" \
+ " underlyingSource = { @bunNativeType: 0, @bunNativePtr: 0, @lazy: false };\n" \
+ " if (strategy === @undefined)\n" \
+ " strategy = { };\n" \
+ "\n" \
+ " if (!@isObject(underlyingSource))\n" \
+ " @throwTypeError(\"ReadableStream constructor takes an object as first argument\");\n" \
+ "\n" \
+ " if (strategy !== @undefined && !@isObject(strategy))\n" \
+ " @throwTypeError(\"ReadableStream constructor takes an object as second argument, if any\");\n" \
+ "\n" \
+ " @putByIdDirectPrivate(this, \"state\", @streamReadable);\n" \
+ " \n" \
+ " @putByIdDirectPrivate(this, \"reader\", @undefined);\n" \
+ " \n" \
+ " @putByIdDirectPrivate(this, \"storedError\", @undefined);\n" \
+ " \n" \
+ " @putByIdDirectPrivate(this, \"disturbed\", false);\n" \
+ " \n" \
+ " //\n" \
+ " @putByIdDirectPrivate(this, \"readableStreamController\", null);\n" \
+ " @putByIdDirectPrivate(this, \"bunNativeType\", @getByIdDirectPrivate(underlyingSource, \"bunNativeType\") ?? 0);\n" \
+ " @putByIdDirectPrivate(this, \"bunNativePtr\", @getByIdDirectPrivate(underlyingSource, \"bunNativePtr\") ?? 0);\n" \
+ "\n" \
+ " const isDirect = underlyingSource.type === \"direct\";\n" \
+ " //\n" \
+ " const isUnderlyingSourceLazy = !!underlyingSource.@lazy;\n" \
+ " const isLazy = isDirect || isUnderlyingSourceLazy;\n" \
+ " \n" \
+ " //\n" \
+ " //\n" \
+ " if (@getByIdDirectPrivate(underlyingSource, \"pull\") !== @undefined && !isLazy) {\n" \
+ " const size = @getByIdDirectPrivate(strategy, \"size\");\n" \
+ " const highWaterMark = @getByIdDirectPrivate(strategy, \"highWaterMark\");\n" \
+ " @setupReadableStreamDefaultController(this, underlyingSource, size, highWaterMark !== @undefined ? highWaterMark : 1, @getByIdDirectPrivate(underlyingSource, \"start\"), @getByIdDirectPrivate(underlyingSource, \"pull\"), @getByIdDirectPrivate(underlyingSource, \"cancel\"));\n" \
+ " \n" \
+ " return this;\n" \
+ " }\n" \
+ " if (isDirect) {\n" \
+ " @putByIdDirectPrivate(this, \"start\", () => @createReadableStreamController(this, underlyingSource, strategy));\n" \
+ " } else if (isLazy) {\n" \
+ " const autoAllocateChunkSize = underlyingSource.autoAllocateChunkSize;\n" \
+ "\n" \
+ " \n" \
+ " @putByIdDirectPrivate(this, \"start\", () => {\n" \
+ " const instance = @lazyLoadStream(this, autoAllocateChunkSize);\n" \
+ " if (instance) {\n" \
+ " @createReadableStreamController(this, instance, strategy);\n" \
+ " }\n" \
+ " });\n" \
+ " } else {\n" \
+ " @putByIdDirectPrivate(this, \"start\", @undefined);\n" \
+ " @createReadableStreamController(this, underlyingSource, strategy);\n" \
+ " }\n" \
+ " \n" \
+ "\n" \
+ " return this;\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableStreamReadableStreamToArrayCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableStreamReadableStreamToArrayCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableStreamReadableStreamToArrayCodeLength = 883;
+static const JSC::Intrinsic s_readableStreamReadableStreamToArrayCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableStreamReadableStreamToArrayCode =
+ "(function (stream) {\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " if (!stream || @getByIdDirectPrivate(stream, \"state\") === @streamClosed) {\n" \
+ " return null;\n" \
+ " }\n" \
+ " var reader = stream.getReader();\n" \
+ " var manyResult = reader.readMany();\n" \
+ " \n" \
+ " async function processManyResult(result) {\n" \
+ " \n" \
+ " if (result.done) {\n" \
+ " return null;\n" \
+ " }\n" \
+ "\n" \
+ " var chunks = result.value || [];\n" \
+ " \n" \
+ " while (true) {\n" \
+ " var thisResult = await reader.read();\n" \
+ " \n" \
+ " if (thisResult.done) {\n" \
+ " return chunks;\n" \
+ " }\n" \
+ " \n" \
+ " chunks.push(thisResult.value);\n" \
+ " }\n" \
+ "\n" \
+ " return chunks;\n" \
+ " };\n" \
+ "\n" \
+ "\n" \
+ " if (manyResult && @isPromise(manyResult)) {\n" \
+ " return manyResult.@then(processManyResult);\n" \
+ " }\n" \
+ "\n" \
+ " if (manyResult && manyResult.done) {\n" \
+ " return null;\n" \
+ " }\n" \
+ "\n" \
+ " return processManyResult(manyResult);\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableStreamReadableStreamToTextCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableStreamReadableStreamToTextCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableStreamReadableStreamToTextCodeLength = 215;
+static const JSC::Intrinsic s_readableStreamReadableStreamToTextCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableStreamReadableStreamToTextCode =
+ "(function (stream) {\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " //\n" \
+ " return globalThis.Bun.readableStreamToArrayBuffer(stream).@then(function(arrayBuffer) {\n" \
+ " return new globalThis.TextDecoder().decode(arrayBuffer);\n" \
+ " });\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableStreamReadableStreamToJSONCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableStreamReadableStreamToJSONCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableStreamReadableStreamToJSONCodeLength = 238;
+static const JSC::Intrinsic s_readableStreamReadableStreamToJSONCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableStreamReadableStreamToJSONCode =
+ "(function (stream) {\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " //\n" \
+ " return globalThis.Bun.readableStreamToArrayBuffer(stream).@then(function(arrayBuffer) {\n" \
+ " return globalThis.JSON.parse(new globalThis.TextDecoder().decode(arrayBuffer));\n" \
+ " });\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableStreamReadableStreamToBlobCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableStreamReadableStreamToBlobCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableStreamReadableStreamToBlobCodeLength = 367;
+static const JSC::Intrinsic s_readableStreamReadableStreamToBlobCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableStreamReadableStreamToBlobCode =
+ "(function (stream) {\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " \n" \
+ " const array = @readableStreamToArray(stream);\n" \
+ " if (array === null) {\n" \
+ " return new globalThis.Blob();\n" \
+ " }\n" \
+ "\n" \
+ " return array.@then(function(chunks) {\n" \
+ " if (chunks === null || chunks.length === 0) {\n" \
+ " return new globalThis.Blob();\n" \
+ " }\n" \
+ "\n" \
+ " return new globalThis.Blob(chunks);\n" \
+ " });\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableStreamReadableStreamToArrayPublicCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableStreamReadableStreamToArrayPublicCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableStreamReadableStreamToArrayPublicCodeLength = 841;
+static const JSC::Intrinsic s_readableStreamReadableStreamToArrayPublicCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableStreamReadableStreamToArrayPublicCode =
+ "(function (stream) {\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " if (@getByIdDirectPrivate(stream, \"state\") === @streamClosed) {\n" \
+ " return [];\n" \
+ " }\n" \
+ " var reader = stream.getReader();\n" \
+ "\n" \
+ " var manyResult = reader.readMany();\n" \
+ "\n" \
+ " var processManyResult = (0, (async function(result) {\n" \
+ " if (result.done) {\n" \
+ " return [];\n" \
+ " }\n" \
+ "\n" \
+ " var chunks = result.value || [];\n" \
+ " \n" \
+ " while (true) {\n" \
+ " var thisResult = await reader.read();\n" \
+ " if (thisResult.done) {\n" \
+ " return chunks;\n" \
+ " }\n" \
+ "\n" \
+ " chunks.push(thisResult.value);\n" \
+ " }\n" \
+ "\n" \
+ " return chunks;\n" \
+ " }));\n" \
+ "\n" \
+ "\n" \
+ " if (manyResult && @isPromise(manyResult)) {\n" \
+ " return manyResult.then(processManyResult);\n" \
+ " }\n" \
+ "\n" \
+ " if (manyResult && manyResult.done) {\n" \
+ " return [];\n" \
+ " }\n" \
+ "\n" \
+ " return processManyResult(manyResult);\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableStreamConsumeReadableStreamCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableStreamConsumeReadableStreamCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableStreamConsumeReadableStreamCodeLength = 3718;
+static const JSC::Intrinsic s_readableStreamConsumeReadableStreamCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableStreamConsumeReadableStreamCode =
+ "(function (nativePtr, nativeType, inputStream) {\n" \
+ " \"use strict\";\n" \
+ " const symbol = globalThis.Symbol.for(\"Bun.consumeReadableStreamPrototype\");\n" \
+ " var cached = globalThis[symbol];\n" \
+ " if (!cached) {\n" \
+ " cached = globalThis[symbol] = [];\n" \
+ " }\n" \
+ " var Prototype = cached[nativeType];\n" \
+ " if (Prototype === @undefined) {\n" \
+ " var [doRead, doError, doReadMany, doClose, onClose, deinit] = globalThis[globalThis.Symbol.for(\"Bun.lazy\")](nativeType);\n" \
+ "\n" \
+ " Prototype = class NativeReadableStreamSink {\n" \
+ " constructor(reader, ptr) {\n" \
+ " this.#ptr = ptr;\n" \
+ " this.#reader = reader;\n" \
+ " this.#didClose = false;\n" \
+ "\n" \
+ " this.handleError = this._handleError.bind(this);\n" \
+ " this.handleClosed = this._handleClosed.bind(this);\n" \
+ " this.processResult = this._processResult.bind(this);\n" \
+ "\n" \
+ " reader.closed.then(this.handleClosed, this.handleError);\n" \
+ " }\n" \
+ "\n" \
+ " handleError;\n" \
+ " handleClosed;\n" \
+ " _handleClosed() {\n" \
+ " if (this.#didClose) return;\n" \
+ " this.#didClose = true;\n" \
+ " var ptr = this.#ptr;\n" \
+ " this.#ptr = 0;\n" \
+ " doClose(ptr);\n" \
+ " deinit(ptr);\n" \
+ " }\n" \
+ "\n" \
+ " _handleError(error) {\n" \
+ " if (this.#didClose) return;\n" \
+ " this.#didClose = true;\n" \
+ " var ptr = this.#ptr;\n" \
+ " this.#ptr = 0;\n" \
+ " doError(ptr, error);\n" \
+ " deinit(ptr);\n" \
+ " }\n" \
+ "\n" \
+ " #ptr;\n" \
+ " #didClose = false;\n" \
+ " #reader;\n" \
+ "\n" \
+ " _handleReadMany({value, done, size}) {\n" \
+ " if (done) {\n" \
+ " this.handleClosed();\n" \
+ " return;\n" \
+ " }\n" \
+ "\n" \
+ " if (this.#didClose) return;\n" \
+ " \n" \
+ "\n" \
+ " doReadMany(this.#ptr, value, done, size);\n" \
+ " }\n" \
+ " \n" \
+ "\n" \
+ " read() {\n" \
+ " if (!this.#ptr) return @throwTypeError(\"ReadableStreamSink is already closed\");\n" \
+ " \n" \
+ " return this.processResult(this.#reader.read());\n" \
+ " \n" \
+ " }\n" \
+ "\n" \
+ " _processResult(result) {\n" \
+ " if (result && @isPromise(result)) {\n" \
+ " const flags = @getPromiseInternalField(result, @promiseFieldFlags);\n" \
+ " if (flags & @promiseStateFulfilled) {\n" \
+ " const fulfilledValue = @getPromiseInternalField(result, @promiseFieldReactionsOrResult);\n" \
+ " if (fulfilledValue) {\n" \
+ " result = fulfilledValue;\n" \
+ " }\n" \
+ " }\n" \
+ " }\n" \
+ "\n" \
+ " if (result && @isPromise(result)) {\n" \
+ " result.then(this.processResult, this.handleError);\n" \
+ " return null;\n" \
+ " }\n" \
+ "\n" \
+ " if (result.done) {\n" \
+ " this.handleClosed();\n" \
+ " return 0;\n" \
+ " } else if (result.value) {\n" \
+ " return result.value;\n" \
+ " } else {\n" \
+ " return -1;\n" \
+ " }\n" \
+ " }\n" \
+ "\n" \
+ " readMany() {\n" \
+ " if (!this.#ptr) return @throwTypeError(\"ReadableStreamSink is already closed\");\n" \
+ " return this.processResult(this.#reader.readMany());\n" \
+ " }\n" \
+ "\n" \
+ " \n" \
+ " };\n" \
+ "\n" \
+ " const minlength = nativeType + 1;\n" \
+ " if (cached.length < minlength) {\n" \
+ " cached.length = minlength;\n" \
+ " }\n" \
+ " @putByValDirect(cached, nativeType, Prototype);\n" \
+ " }\n" \
+ "\n" \
+ " if (@isReadableStreamLocked(inputStream)) {\n" \
+ " @throwTypeError(\"Cannot start reading from a locked stream\");\n" \
+ " }\n" \
+ "\n" \
+ " return new Prototype(inputStream.getReader(), nativePtr);\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableStreamCreateEmptyReadableStreamCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableStreamCreateEmptyReadableStreamCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableStreamCreateEmptyReadableStreamCodeLength = 156;
+static const JSC::Intrinsic s_readableStreamCreateEmptyReadableStreamCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableStreamCreateEmptyReadableStreamCode =
+ "(function () {\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " var stream = new @ReadableStream({\n" \
+ " pull() {},\n" \
+ " });\n" \
+ " @readableStreamClose(stream);\n" \
+ " return stream;\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableStreamCreateNativeReadableStreamCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableStreamCreateNativeReadableStreamCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableStreamCreateNativeReadableStreamCodeLength = 266;
+static const JSC::Intrinsic s_readableStreamCreateNativeReadableStreamCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableStreamCreateNativeReadableStreamCode =
+ "(function (nativePtr, nativeType, autoAllocateChunkSize) {\n" \
+ " \"use strict\";\n" \
+ " return new @ReadableStream({\n" \
+ " @lazy: true,\n" \
+ " @bunNativeType: nativeType,\n" \
+ " @bunNativePtr: nativePtr,\n" \
+ " autoAllocateChunkSize: autoAllocateChunkSize,\n" \
+ " });\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableStreamCancelCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableStreamCancelCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableStreamCancelCodeLength = 324;
+static const JSC::Intrinsic s_readableStreamCancelCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableStreamCancelCode =
+ "(function (reason)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " if (!@isReadableStream(this))\n" \
+ " return @Promise.@reject(@makeThisTypeError(\"ReadableStream\", \"cancel\"));\n" \
+ "\n" \
+ " if (@isReadableStreamLocked(this))\n" \
+ " return @Promise.@reject(@makeTypeError(\"ReadableStream is locked\"));\n" \
+ "\n" \
+ " return @readableStreamCancel(this, reason);\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableStreamGetReaderCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableStreamGetReaderCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableStreamGetReaderCodeLength = 680;
+static const JSC::Intrinsic s_readableStreamGetReaderCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableStreamGetReaderCode =
+ "(function (options)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " if (!@isReadableStream(this))\n" \
+ " throw @makeThisTypeError(\"ReadableStream\", \"getReader\");\n" \
+ "\n" \
+ " const mode = @toDictionary(options, { }, \"ReadableStream.getReader takes an object as first argument\").mode;\n" \
+ " if (mode === @undefined) {\n" \
+ " var start_ = @getByIdDirectPrivate(this, \"start\");\n" \
+ " if (start_) {\n" \
+ " @putByIdDirectPrivate(this, \"start\", @undefined);\n" \
+ " start_();\n" \
+ " }\n" \
+ " \n" \
+ " return new @ReadableStreamDefaultReader(this);\n" \
+ " }\n" \
+ " //\n" \
+ " if (mode == 'byob') {\n" \
+ " return new @ReadableStreamBYOBReader(this);\n" \
+ " }\n" \
+ "\n" \
+ " \n" \
+ " @throwTypeError(\"Invalid mode is specified\");\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableStreamPipeThroughCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableStreamPipeThroughCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableStreamPipeThroughCodeLength = 1485;
+static const JSC::Intrinsic s_readableStreamPipeThroughCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableStreamPipeThroughCode =
+ "(function (streams, options)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " const transforms = streams;\n" \
+ "\n" \
+ " const readable = transforms[\"readable\"];\n" \
+ " if (!@isReadableStream(readable))\n" \
+ " throw @makeTypeError(\"readable should be ReadableStream\");\n" \
+ "\n" \
+ " const writable = transforms[\"writable\"];\n" \
+ " const internalWritable = @getInternalWritableStream(writable);\n" \
+ " if (!@isWritableStream(internalWritable))\n" \
+ " throw @makeTypeError(\"writable should be WritableStream\");\n" \
+ "\n" \
+ " let preventClose = false;\n" \
+ " let preventAbort = false;\n" \
+ " let preventCancel = false;\n" \
+ " let signal;\n" \
+ " if (!@isUndefinedOrNull(options)) {\n" \
+ " if (!@isObject(options))\n" \
+ " throw @makeTypeError(\"options must be an object\");\n" \
+ "\n" \
+ " preventAbort = !!options[\"preventAbort\"];\n" \
+ " preventCancel = !!options[\"preventCancel\"];\n" \
+ " preventClose = !!options[\"preventClose\"];\n" \
+ "\n" \
+ " signal = options[\"signal\"];\n" \
+ " if (signal !== @undefined && !@isAbortSignal(signal))\n" \
+ " throw @makeTypeError(\"options.signal must be AbortSignal\");\n" \
+ " }\n" \
+ "\n" \
+ " if (!@isReadableStream(this))\n" \
+ " throw @makeThisTypeError(\"ReadableStream\", \"pipeThrough\");\n" \
+ "\n" \
+ " if (@isReadableStreamLocked(this))\n" \
+ " throw @makeTypeError(\"ReadableStream is locked\");\n" \
+ "\n" \
+ " if (@isWritableStreamLocked(internalWritable))\n" \
+ " throw @makeTypeError(\"WritableStream is locked\");\n" \
+ "\n" \
+ " @readableStreamPipeToWritableStream(this, internalWritable, preventClose, preventAbort, preventCancel, signal);\n" \
+ "\n" \
+ " return readable;\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableStreamPipeToCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableStreamPipeToCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableStreamPipeToCodeLength = 1523;
+static const JSC::Intrinsic s_readableStreamPipeToCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableStreamPipeToCode =
+ "(function (destination)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " //\n" \
+ " //\n" \
+ " let options = arguments[1];\n" \
+ "\n" \
+ " let preventClose = false;\n" \
+ " let preventAbort = false;\n" \
+ " let preventCancel = false;\n" \
+ " let signal;\n" \
+ " if (!@isUndefinedOrNull(options)) {\n" \
+ " if (!@isObject(options))\n" \
+ " return @Promise.@reject(@makeTypeError(\"options must be an object\"));\n" \
+ "\n" \
+ " try {\n" \
+ " preventAbort = !!options[\"preventAbort\"];\n" \
+ " preventCancel = !!options[\"preventCancel\"];\n" \
+ " preventClose = !!options[\"preventClose\"];\n" \
+ "\n" \
+ " signal = options[\"signal\"];\n" \
+ " } catch(e) {\n" \
+ " return @Promise.@reject(e);\n" \
+ " }\n" \
+ "\n" \
+ " if (signal !== @undefined && !@isAbortSignal(signal))\n" \
+ " return @Promise.@reject(@makeTypeError(\"options.signal must be AbortSignal\"));\n" \
+ " }\n" \
+ "\n" \
+ " const internalDestination = @getInternalWritableStream(destination);\n" \
+ " if (!@isWritableStream(internalDestination))\n" \
+ " return @Promise.@reject(@makeTypeError(\"ReadableStream pipeTo requires a WritableStream\"));\n" \
+ "\n" \
+ " if (!@isReadableStream(this))\n" \
+ " return @Promise.@reject(@makeThisTypeError(\"ReadableStream\", \"pipeTo\"));\n" \
+ "\n" \
+ " if (@isReadableStreamLocked(this))\n" \
+ " return @Promise.@reject(@makeTypeError(\"ReadableStream is locked\"));\n" \
+ "\n" \
+ " if (@isWritableStreamLocked(internalDestination))\n" \
+ " return @Promise.@reject(@makeTypeError(\"WritableStream is locked\"));\n" \
+ "\n" \
+ " return @readableStreamPipeToWritableStream(this, internalDestination, preventClose, preventAbort, preventCancel, signal);\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableStreamTeeCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableStreamTeeCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableStreamTeeCodeLength = 175;
+static const JSC::Intrinsic s_readableStreamTeeCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableStreamTeeCode =
+ "(function ()\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " if (!@isReadableStream(this))\n" \
+ " throw @makeThisTypeError(\"ReadableStream\", \"tee\");\n" \
+ "\n" \
+ " return @readableStreamTee(this, false);\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableStreamLockedCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableStreamLockedCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableStreamLockedCodeLength = 178;
+static const JSC::Intrinsic s_readableStreamLockedCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableStreamLockedCode =
+ "(function ()\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " if (!@isReadableStream(this))\n" \
+ " throw @makeGetterTypeError(\"ReadableStream\", \"locked\");\n" \
+ "\n" \
+ " return @isReadableStreamLocked(this);\n" \
+ "})\n" \
+;
+
+
+#define DEFINE_BUILTIN_GENERATOR(codeName, functionName, overriddenName, argumentCount) \
+JSC::FunctionExecutable* codeName##Generator(JSC::VM& vm) \
+{\
+ JSVMClientData* clientData = static_cast<JSVMClientData*>(vm.clientData); \
+ return clientData->builtinFunctions().readableStreamBuiltins().codeName##Executable()->link(vm, nullptr, clientData->builtinFunctions().readableStreamBuiltins().codeName##Source(), std::nullopt, s_##codeName##Intrinsic); \
+}
+WEBCORE_FOREACH_READABLESTREAM_BUILTIN_CODE(DEFINE_BUILTIN_GENERATOR)
+#undef DEFINE_BUILTIN_GENERATOR
+
+
+} // namespace WebCore
diff --git a/src/bun.js/builtins/cpp/ReadableStreamBuiltins.h b/src/bun.js/builtins/cpp/ReadableStreamBuiltins.h
new file mode 100644
index 000000000..d009f8560
--- /dev/null
+++ b/src/bun.js/builtins/cpp/ReadableStreamBuiltins.h
@@ -0,0 +1,239 @@
+/*
+ * Copyright (c) 2015 Igalia
+ * Copyright (c) 2015 Igalia S.L.
+ * Copyright (c) 2015 Igalia.
+ * Copyright (c) 2015, 2016 Canon Inc. All rights reserved.
+ * Copyright (c) 2015, 2016, 2017 Canon Inc.
+ * Copyright (c) 2016, 2020 Apple Inc. All rights reserved.
+ * Copyright (c) 2022 Codeblog Corp. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+// DO NOT EDIT THIS FILE. It is automatically generated from JavaScript files for
+// builtins by the script: Source/JavaScriptCore/Scripts/generate-js-builtins.py
+
+#pragma once
+
+#include <JavaScriptCore/BuiltinUtils.h>
+#include <JavaScriptCore/Identifier.h>
+#include <JavaScriptCore/JSFunction.h>
+#include <JavaScriptCore/UnlinkedFunctionExecutable.h>
+
+namespace JSC {
+class FunctionExecutable;
+}
+
+namespace WebCore {
+
+/* ReadableStream */
+extern const char* const s_readableStreamInitializeReadableStreamCode;
+extern const int s_readableStreamInitializeReadableStreamCodeLength;
+extern const JSC::ConstructAbility s_readableStreamInitializeReadableStreamCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableStreamInitializeReadableStreamCodeConstructorKind;
+extern const char* const s_readableStreamReadableStreamToArrayCode;
+extern const int s_readableStreamReadableStreamToArrayCodeLength;
+extern const JSC::ConstructAbility s_readableStreamReadableStreamToArrayCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableStreamReadableStreamToArrayCodeConstructorKind;
+extern const char* const s_readableStreamReadableStreamToTextCode;
+extern const int s_readableStreamReadableStreamToTextCodeLength;
+extern const JSC::ConstructAbility s_readableStreamReadableStreamToTextCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableStreamReadableStreamToTextCodeConstructorKind;
+extern const char* const s_readableStreamReadableStreamToJSONCode;
+extern const int s_readableStreamReadableStreamToJSONCodeLength;
+extern const JSC::ConstructAbility s_readableStreamReadableStreamToJSONCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableStreamReadableStreamToJSONCodeConstructorKind;
+extern const char* const s_readableStreamReadableStreamToBlobCode;
+extern const int s_readableStreamReadableStreamToBlobCodeLength;
+extern const JSC::ConstructAbility s_readableStreamReadableStreamToBlobCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableStreamReadableStreamToBlobCodeConstructorKind;
+extern const char* const s_readableStreamReadableStreamToArrayPublicCode;
+extern const int s_readableStreamReadableStreamToArrayPublicCodeLength;
+extern const JSC::ConstructAbility s_readableStreamReadableStreamToArrayPublicCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableStreamReadableStreamToArrayPublicCodeConstructorKind;
+extern const char* const s_readableStreamConsumeReadableStreamCode;
+extern const int s_readableStreamConsumeReadableStreamCodeLength;
+extern const JSC::ConstructAbility s_readableStreamConsumeReadableStreamCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableStreamConsumeReadableStreamCodeConstructorKind;
+extern const char* const s_readableStreamCreateEmptyReadableStreamCode;
+extern const int s_readableStreamCreateEmptyReadableStreamCodeLength;
+extern const JSC::ConstructAbility s_readableStreamCreateEmptyReadableStreamCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableStreamCreateEmptyReadableStreamCodeConstructorKind;
+extern const char* const s_readableStreamCreateNativeReadableStreamCode;
+extern const int s_readableStreamCreateNativeReadableStreamCodeLength;
+extern const JSC::ConstructAbility s_readableStreamCreateNativeReadableStreamCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableStreamCreateNativeReadableStreamCodeConstructorKind;
+extern const char* const s_readableStreamCancelCode;
+extern const int s_readableStreamCancelCodeLength;
+extern const JSC::ConstructAbility s_readableStreamCancelCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableStreamCancelCodeConstructorKind;
+extern const char* const s_readableStreamGetReaderCode;
+extern const int s_readableStreamGetReaderCodeLength;
+extern const JSC::ConstructAbility s_readableStreamGetReaderCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableStreamGetReaderCodeConstructorKind;
+extern const char* const s_readableStreamPipeThroughCode;
+extern const int s_readableStreamPipeThroughCodeLength;
+extern const JSC::ConstructAbility s_readableStreamPipeThroughCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableStreamPipeThroughCodeConstructorKind;
+extern const char* const s_readableStreamPipeToCode;
+extern const int s_readableStreamPipeToCodeLength;
+extern const JSC::ConstructAbility s_readableStreamPipeToCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableStreamPipeToCodeConstructorKind;
+extern const char* const s_readableStreamTeeCode;
+extern const int s_readableStreamTeeCodeLength;
+extern const JSC::ConstructAbility s_readableStreamTeeCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableStreamTeeCodeConstructorKind;
+extern const char* const s_readableStreamLockedCode;
+extern const int s_readableStreamLockedCodeLength;
+extern const JSC::ConstructAbility s_readableStreamLockedCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableStreamLockedCodeConstructorKind;
+
+#define WEBCORE_FOREACH_READABLESTREAM_BUILTIN_DATA(macro) \
+ macro(initializeReadableStream, readableStreamInitializeReadableStream, 2) \
+ macro(readableStreamToArray, readableStreamReadableStreamToArray, 1) \
+ macro(readableStreamToText, readableStreamReadableStreamToText, 1) \
+ macro(readableStreamToJSON, readableStreamReadableStreamToJSON, 1) \
+ macro(readableStreamToBlob, readableStreamReadableStreamToBlob, 1) \
+ macro(readableStreamToArrayPublic, readableStreamReadableStreamToArrayPublic, 1) \
+ macro(consumeReadableStream, readableStreamConsumeReadableStream, 3) \
+ macro(createEmptyReadableStream, readableStreamCreateEmptyReadableStream, 0) \
+ macro(createNativeReadableStream, readableStreamCreateNativeReadableStream, 3) \
+ macro(cancel, readableStreamCancel, 1) \
+ macro(getReader, readableStreamGetReader, 1) \
+ macro(pipeThrough, readableStreamPipeThrough, 2) \
+ macro(pipeTo, readableStreamPipeTo, 1) \
+ macro(tee, readableStreamTee, 0) \
+ macro(locked, readableStreamLocked, 0) \
+
+#define WEBCORE_BUILTIN_READABLESTREAM_INITIALIZEREADABLESTREAM 1
+#define WEBCORE_BUILTIN_READABLESTREAM_READABLESTREAMTOARRAY 1
+#define WEBCORE_BUILTIN_READABLESTREAM_READABLESTREAMTOTEXT 1
+#define WEBCORE_BUILTIN_READABLESTREAM_READABLESTREAMTOJSON 1
+#define WEBCORE_BUILTIN_READABLESTREAM_READABLESTREAMTOBLOB 1
+#define WEBCORE_BUILTIN_READABLESTREAM_READABLESTREAMTOARRAYPUBLIC 1
+#define WEBCORE_BUILTIN_READABLESTREAM_CONSUMEREADABLESTREAM 1
+#define WEBCORE_BUILTIN_READABLESTREAM_CREATEEMPTYREADABLESTREAM 1
+#define WEBCORE_BUILTIN_READABLESTREAM_CREATENATIVEREADABLESTREAM 1
+#define WEBCORE_BUILTIN_READABLESTREAM_CANCEL 1
+#define WEBCORE_BUILTIN_READABLESTREAM_GETREADER 1
+#define WEBCORE_BUILTIN_READABLESTREAM_PIPETHROUGH 1
+#define WEBCORE_BUILTIN_READABLESTREAM_PIPETO 1
+#define WEBCORE_BUILTIN_READABLESTREAM_TEE 1
+#define WEBCORE_BUILTIN_READABLESTREAM_LOCKED 1
+
+#define WEBCORE_FOREACH_READABLESTREAM_BUILTIN_CODE(macro) \
+ macro(readableStreamInitializeReadableStreamCode, initializeReadableStream, ASCIILiteral(), s_readableStreamInitializeReadableStreamCodeLength) \
+ macro(readableStreamReadableStreamToArrayCode, readableStreamToArray, ASCIILiteral(), s_readableStreamReadableStreamToArrayCodeLength) \
+ macro(readableStreamReadableStreamToTextCode, readableStreamToText, ASCIILiteral(), s_readableStreamReadableStreamToTextCodeLength) \
+ macro(readableStreamReadableStreamToJSONCode, readableStreamToJSON, ASCIILiteral(), s_readableStreamReadableStreamToJSONCodeLength) \
+ macro(readableStreamReadableStreamToBlobCode, readableStreamToBlob, ASCIILiteral(), s_readableStreamReadableStreamToBlobCodeLength) \
+ macro(readableStreamReadableStreamToArrayPublicCode, readableStreamToArrayPublic, ASCIILiteral(), s_readableStreamReadableStreamToArrayPublicCodeLength) \
+ macro(readableStreamConsumeReadableStreamCode, consumeReadableStream, ASCIILiteral(), s_readableStreamConsumeReadableStreamCodeLength) \
+ macro(readableStreamCreateEmptyReadableStreamCode, createEmptyReadableStream, ASCIILiteral(), s_readableStreamCreateEmptyReadableStreamCodeLength) \
+ macro(readableStreamCreateNativeReadableStreamCode, createNativeReadableStream, ASCIILiteral(), s_readableStreamCreateNativeReadableStreamCodeLength) \
+ macro(readableStreamCancelCode, cancel, ASCIILiteral(), s_readableStreamCancelCodeLength) \
+ macro(readableStreamGetReaderCode, getReader, ASCIILiteral(), s_readableStreamGetReaderCodeLength) \
+ macro(readableStreamPipeThroughCode, pipeThrough, ASCIILiteral(), s_readableStreamPipeThroughCodeLength) \
+ macro(readableStreamPipeToCode, pipeTo, ASCIILiteral(), s_readableStreamPipeToCodeLength) \
+ macro(readableStreamTeeCode, tee, ASCIILiteral(), s_readableStreamTeeCodeLength) \
+ macro(readableStreamLockedCode, locked, "get locked"_s, s_readableStreamLockedCodeLength) \
+
+#define WEBCORE_FOREACH_READABLESTREAM_BUILTIN_FUNCTION_NAME(macro) \
+ macro(cancel) \
+ macro(consumeReadableStream) \
+ macro(createEmptyReadableStream) \
+ macro(createNativeReadableStream) \
+ macro(getReader) \
+ macro(initializeReadableStream) \
+ macro(locked) \
+ macro(pipeThrough) \
+ macro(pipeTo) \
+ macro(readableStreamToArray) \
+ macro(readableStreamToArrayPublic) \
+ macro(readableStreamToBlob) \
+ macro(readableStreamToJSON) \
+ macro(readableStreamToText) \
+ macro(tee) \
+
+#define DECLARE_BUILTIN_GENERATOR(codeName, functionName, overriddenName, argumentCount) \
+ JSC::FunctionExecutable* codeName##Generator(JSC::VM&);
+
+WEBCORE_FOREACH_READABLESTREAM_BUILTIN_CODE(DECLARE_BUILTIN_GENERATOR)
+#undef DECLARE_BUILTIN_GENERATOR
+
+class ReadableStreamBuiltinsWrapper : private JSC::WeakHandleOwner {
+public:
+ explicit ReadableStreamBuiltinsWrapper(JSC::VM& vm)
+ : m_vm(vm)
+ WEBCORE_FOREACH_READABLESTREAM_BUILTIN_FUNCTION_NAME(INITIALIZE_BUILTIN_NAMES)
+#define INITIALIZE_BUILTIN_SOURCE_MEMBERS(name, functionName, overriddenName, length) , m_##name##Source(JSC::makeSource(StringImpl::createWithoutCopying(s_##name, length), { }))
+ WEBCORE_FOREACH_READABLESTREAM_BUILTIN_CODE(INITIALIZE_BUILTIN_SOURCE_MEMBERS)
+#undef INITIALIZE_BUILTIN_SOURCE_MEMBERS
+ {
+ }
+
+#define EXPOSE_BUILTIN_EXECUTABLES(name, functionName, overriddenName, length) \
+ JSC::UnlinkedFunctionExecutable* name##Executable(); \
+ const JSC::SourceCode& name##Source() const { return m_##name##Source; }
+ WEBCORE_FOREACH_READABLESTREAM_BUILTIN_CODE(EXPOSE_BUILTIN_EXECUTABLES)
+#undef EXPOSE_BUILTIN_EXECUTABLES
+
+ WEBCORE_FOREACH_READABLESTREAM_BUILTIN_FUNCTION_NAME(DECLARE_BUILTIN_IDENTIFIER_ACCESSOR)
+
+ void exportNames();
+
+private:
+ JSC::VM& m_vm;
+
+ WEBCORE_FOREACH_READABLESTREAM_BUILTIN_FUNCTION_NAME(DECLARE_BUILTIN_NAMES)
+
+#define DECLARE_BUILTIN_SOURCE_MEMBERS(name, functionName, overriddenName, length) \
+ JSC::SourceCode m_##name##Source;\
+ JSC::Weak<JSC::UnlinkedFunctionExecutable> m_##name##Executable;
+ WEBCORE_FOREACH_READABLESTREAM_BUILTIN_CODE(DECLARE_BUILTIN_SOURCE_MEMBERS)
+#undef DECLARE_BUILTIN_SOURCE_MEMBERS
+
+};
+
+#define DEFINE_BUILTIN_EXECUTABLES(name, functionName, overriddenName, length) \
+inline JSC::UnlinkedFunctionExecutable* ReadableStreamBuiltinsWrapper::name##Executable() \
+{\
+ if (!m_##name##Executable) {\
+ JSC::Identifier executableName = functionName##PublicName();\
+ if (overriddenName)\
+ executableName = JSC::Identifier::fromString(m_vm, overriddenName);\
+ m_##name##Executable = JSC::Weak<JSC::UnlinkedFunctionExecutable>(JSC::createBuiltinExecutable(m_vm, m_##name##Source, executableName, s_##name##ConstructorKind, s_##name##ConstructAbility), this, &m_##name##Executable);\
+ }\
+ return m_##name##Executable.get();\
+}
+WEBCORE_FOREACH_READABLESTREAM_BUILTIN_CODE(DEFINE_BUILTIN_EXECUTABLES)
+#undef DEFINE_BUILTIN_EXECUTABLES
+
+inline void ReadableStreamBuiltinsWrapper::exportNames()
+{
+#define EXPORT_FUNCTION_NAME(name) m_vm.propertyNames->appendExternalName(name##PublicName(), name##PrivateName());
+ WEBCORE_FOREACH_READABLESTREAM_BUILTIN_FUNCTION_NAME(EXPORT_FUNCTION_NAME)
+#undef EXPORT_FUNCTION_NAME
+}
+
+} // namespace WebCore
diff --git a/src/bun.js/builtins/cpp/ReadableStreamDefaultControllerBuiltins.cpp b/src/bun.js/builtins/cpp/ReadableStreamDefaultControllerBuiltins.cpp
new file mode 100644
index 000000000..a7be93e52
--- /dev/null
+++ b/src/bun.js/builtins/cpp/ReadableStreamDefaultControllerBuiltins.cpp
@@ -0,0 +1,147 @@
+/*
+ * Copyright (c) 2015 Igalia
+ * Copyright (c) 2015 Igalia S.L.
+ * Copyright (c) 2015 Igalia.
+ * Copyright (c) 2015, 2016 Canon Inc. All rights reserved.
+ * Copyright (c) 2015, 2016, 2017 Canon Inc.
+ * Copyright (c) 2016, 2020 Apple Inc. All rights reserved.
+ * Copyright (c) 2022 Codeblog Corp. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+// DO NOT EDIT THIS FILE. It is automatically generated from JavaScript files for
+// builtins by the script: Source/JavaScriptCore/Scripts/generate-js-builtins.py
+
+#include "config.h"
+#include "ReadableStreamDefaultControllerBuiltins.h"
+
+#include "WebCoreJSClientData.h"
+#include <JavaScriptCore/HeapInlines.h>
+#include <JavaScriptCore/IdentifierInlines.h>
+#include <JavaScriptCore/Intrinsic.h>
+#include <JavaScriptCore/JSCJSValueInlines.h>
+#include <JavaScriptCore/JSCellInlines.h>
+#include <JavaScriptCore/StructureInlines.h>
+#include <JavaScriptCore/VM.h>
+
+namespace WebCore {
+
+const JSC::ConstructAbility s_readableStreamDefaultControllerInitializeReadableStreamDefaultControllerCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableStreamDefaultControllerInitializeReadableStreamDefaultControllerCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableStreamDefaultControllerInitializeReadableStreamDefaultControllerCodeLength = 376;
+static const JSC::Intrinsic s_readableStreamDefaultControllerInitializeReadableStreamDefaultControllerCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableStreamDefaultControllerInitializeReadableStreamDefaultControllerCode =
+ "(function (stream, underlyingSource, size, highWaterMark)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " if (arguments.length !== 5 && arguments[4] !== @isReadableStream)\n" \
+ " @throwTypeError(\"ReadableStreamDefaultController constructor should not be called directly\");\n" \
+ "\n" \
+ " return @privateInitializeReadableStreamDefaultController.@call(this, stream, underlyingSource, size, highWaterMark);\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableStreamDefaultControllerEnqueueCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableStreamDefaultControllerEnqueueCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableStreamDefaultControllerEnqueueCodeLength = 412;
+static const JSC::Intrinsic s_readableStreamDefaultControllerEnqueueCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableStreamDefaultControllerEnqueueCode =
+ "(function (chunk)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " if (!@isReadableStreamDefaultController(this))\n" \
+ " throw @makeThisTypeError(\"ReadableStreamDefaultController\", \"enqueue\");\n" \
+ "\n" \
+ " if (!@readableStreamDefaultControllerCanCloseOrEnqueue(this))\n" \
+ " @throwTypeError(\"ReadableStreamDefaultController is not in a state where chunk can be enqueued\");\n" \
+ "\n" \
+ " return @readableStreamDefaultControllerEnqueue(this, chunk);\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableStreamDefaultControllerErrorCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableStreamDefaultControllerErrorCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableStreamDefaultControllerErrorCodeLength = 228;
+static const JSC::Intrinsic s_readableStreamDefaultControllerErrorCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableStreamDefaultControllerErrorCode =
+ "(function (error)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " if (!@isReadableStreamDefaultController(this))\n" \
+ " throw @makeThisTypeError(\"ReadableStreamDefaultController\", \"error\");\n" \
+ "\n" \
+ " @readableStreamDefaultControllerError(this, error);\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableStreamDefaultControllerCloseCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableStreamDefaultControllerCloseCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableStreamDefaultControllerCloseCodeLength = 384;
+static const JSC::Intrinsic s_readableStreamDefaultControllerCloseCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableStreamDefaultControllerCloseCode =
+ "(function ()\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " if (!@isReadableStreamDefaultController(this))\n" \
+ " throw @makeThisTypeError(\"ReadableStreamDefaultController\", \"close\");\n" \
+ "\n" \
+ " if (!@readableStreamDefaultControllerCanCloseOrEnqueue(this))\n" \
+ " @throwTypeError(\"ReadableStreamDefaultController is not in a state where it can be closed\");\n" \
+ "\n" \
+ " @readableStreamDefaultControllerClose(this);\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableStreamDefaultControllerDesiredSizeCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableStreamDefaultControllerDesiredSizeCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableStreamDefaultControllerDesiredSizeCodeLength = 240;
+static const JSC::Intrinsic s_readableStreamDefaultControllerDesiredSizeCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableStreamDefaultControllerDesiredSizeCode =
+ "(function ()\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " if (!@isReadableStreamDefaultController(this))\n" \
+ " throw @makeGetterTypeError(\"ReadableStreamDefaultController\", \"desiredSize\");\n" \
+ "\n" \
+ " return @readableStreamDefaultControllerGetDesiredSize(this);\n" \
+ "})\n" \
+;
+
+
+#define DEFINE_BUILTIN_GENERATOR(codeName, functionName, overriddenName, argumentCount) \
+JSC::FunctionExecutable* codeName##Generator(JSC::VM& vm) \
+{\
+ JSVMClientData* clientData = static_cast<JSVMClientData*>(vm.clientData); \
+ return clientData->builtinFunctions().readableStreamDefaultControllerBuiltins().codeName##Executable()->link(vm, nullptr, clientData->builtinFunctions().readableStreamDefaultControllerBuiltins().codeName##Source(), std::nullopt, s_##codeName##Intrinsic); \
+}
+WEBCORE_FOREACH_READABLESTREAMDEFAULTCONTROLLER_BUILTIN_CODE(DEFINE_BUILTIN_GENERATOR)
+#undef DEFINE_BUILTIN_GENERATOR
+
+
+} // namespace WebCore
diff --git a/src/bun.js/builtins/cpp/ReadableStreamDefaultControllerBuiltins.h b/src/bun.js/builtins/cpp/ReadableStreamDefaultControllerBuiltins.h
new file mode 100644
index 000000000..625da2f88
--- /dev/null
+++ b/src/bun.js/builtins/cpp/ReadableStreamDefaultControllerBuiltins.h
@@ -0,0 +1,159 @@
+/*
+ * Copyright (c) 2015 Igalia
+ * Copyright (c) 2015 Igalia S.L.
+ * Copyright (c) 2015 Igalia.
+ * Copyright (c) 2015, 2016 Canon Inc. All rights reserved.
+ * Copyright (c) 2015, 2016, 2017 Canon Inc.
+ * Copyright (c) 2016, 2020 Apple Inc. All rights reserved.
+ * Copyright (c) 2022 Codeblog Corp. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+// DO NOT EDIT THIS FILE. It is automatically generated from JavaScript files for
+// builtins by the script: Source/JavaScriptCore/Scripts/generate-js-builtins.py
+
+#pragma once
+
+#include <JavaScriptCore/BuiltinUtils.h>
+#include <JavaScriptCore/Identifier.h>
+#include <JavaScriptCore/JSFunction.h>
+#include <JavaScriptCore/UnlinkedFunctionExecutable.h>
+
+namespace JSC {
+class FunctionExecutable;
+}
+
+namespace WebCore {
+
+/* ReadableStreamDefaultController */
+extern const char* const s_readableStreamDefaultControllerInitializeReadableStreamDefaultControllerCode;
+extern const int s_readableStreamDefaultControllerInitializeReadableStreamDefaultControllerCodeLength;
+extern const JSC::ConstructAbility s_readableStreamDefaultControllerInitializeReadableStreamDefaultControllerCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableStreamDefaultControllerInitializeReadableStreamDefaultControllerCodeConstructorKind;
+extern const char* const s_readableStreamDefaultControllerEnqueueCode;
+extern const int s_readableStreamDefaultControllerEnqueueCodeLength;
+extern const JSC::ConstructAbility s_readableStreamDefaultControllerEnqueueCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableStreamDefaultControllerEnqueueCodeConstructorKind;
+extern const char* const s_readableStreamDefaultControllerErrorCode;
+extern const int s_readableStreamDefaultControllerErrorCodeLength;
+extern const JSC::ConstructAbility s_readableStreamDefaultControllerErrorCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableStreamDefaultControllerErrorCodeConstructorKind;
+extern const char* const s_readableStreamDefaultControllerCloseCode;
+extern const int s_readableStreamDefaultControllerCloseCodeLength;
+extern const JSC::ConstructAbility s_readableStreamDefaultControllerCloseCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableStreamDefaultControllerCloseCodeConstructorKind;
+extern const char* const s_readableStreamDefaultControllerDesiredSizeCode;
+extern const int s_readableStreamDefaultControllerDesiredSizeCodeLength;
+extern const JSC::ConstructAbility s_readableStreamDefaultControllerDesiredSizeCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableStreamDefaultControllerDesiredSizeCodeConstructorKind;
+
+#define WEBCORE_FOREACH_READABLESTREAMDEFAULTCONTROLLER_BUILTIN_DATA(macro) \
+ macro(initializeReadableStreamDefaultController, readableStreamDefaultControllerInitializeReadableStreamDefaultController, 4) \
+ macro(enqueue, readableStreamDefaultControllerEnqueue, 1) \
+ macro(error, readableStreamDefaultControllerError, 1) \
+ macro(close, readableStreamDefaultControllerClose, 0) \
+ macro(desiredSize, readableStreamDefaultControllerDesiredSize, 0) \
+
+#define WEBCORE_BUILTIN_READABLESTREAMDEFAULTCONTROLLER_INITIALIZEREADABLESTREAMDEFAULTCONTROLLER 1
+#define WEBCORE_BUILTIN_READABLESTREAMDEFAULTCONTROLLER_ENQUEUE 1
+#define WEBCORE_BUILTIN_READABLESTREAMDEFAULTCONTROLLER_ERROR 1
+#define WEBCORE_BUILTIN_READABLESTREAMDEFAULTCONTROLLER_CLOSE 1
+#define WEBCORE_BUILTIN_READABLESTREAMDEFAULTCONTROLLER_DESIREDSIZE 1
+
+#define WEBCORE_FOREACH_READABLESTREAMDEFAULTCONTROLLER_BUILTIN_CODE(macro) \
+ macro(readableStreamDefaultControllerInitializeReadableStreamDefaultControllerCode, initializeReadableStreamDefaultController, ASCIILiteral(), s_readableStreamDefaultControllerInitializeReadableStreamDefaultControllerCodeLength) \
+ macro(readableStreamDefaultControllerEnqueueCode, enqueue, ASCIILiteral(), s_readableStreamDefaultControllerEnqueueCodeLength) \
+ macro(readableStreamDefaultControllerErrorCode, error, ASCIILiteral(), s_readableStreamDefaultControllerErrorCodeLength) \
+ macro(readableStreamDefaultControllerCloseCode, close, ASCIILiteral(), s_readableStreamDefaultControllerCloseCodeLength) \
+ macro(readableStreamDefaultControllerDesiredSizeCode, desiredSize, "get desiredSize"_s, s_readableStreamDefaultControllerDesiredSizeCodeLength) \
+
+#define WEBCORE_FOREACH_READABLESTREAMDEFAULTCONTROLLER_BUILTIN_FUNCTION_NAME(macro) \
+ macro(close) \
+ macro(desiredSize) \
+ macro(enqueue) \
+ macro(error) \
+ macro(initializeReadableStreamDefaultController) \
+
+#define DECLARE_BUILTIN_GENERATOR(codeName, functionName, overriddenName, argumentCount) \
+ JSC::FunctionExecutable* codeName##Generator(JSC::VM&);
+
+WEBCORE_FOREACH_READABLESTREAMDEFAULTCONTROLLER_BUILTIN_CODE(DECLARE_BUILTIN_GENERATOR)
+#undef DECLARE_BUILTIN_GENERATOR
+
+class ReadableStreamDefaultControllerBuiltinsWrapper : private JSC::WeakHandleOwner {
+public:
+ explicit ReadableStreamDefaultControllerBuiltinsWrapper(JSC::VM& vm)
+ : m_vm(vm)
+ WEBCORE_FOREACH_READABLESTREAMDEFAULTCONTROLLER_BUILTIN_FUNCTION_NAME(INITIALIZE_BUILTIN_NAMES)
+#define INITIALIZE_BUILTIN_SOURCE_MEMBERS(name, functionName, overriddenName, length) , m_##name##Source(JSC::makeSource(StringImpl::createWithoutCopying(s_##name, length), { }))
+ WEBCORE_FOREACH_READABLESTREAMDEFAULTCONTROLLER_BUILTIN_CODE(INITIALIZE_BUILTIN_SOURCE_MEMBERS)
+#undef INITIALIZE_BUILTIN_SOURCE_MEMBERS
+ {
+ }
+
+#define EXPOSE_BUILTIN_EXECUTABLES(name, functionName, overriddenName, length) \
+ JSC::UnlinkedFunctionExecutable* name##Executable(); \
+ const JSC::SourceCode& name##Source() const { return m_##name##Source; }
+ WEBCORE_FOREACH_READABLESTREAMDEFAULTCONTROLLER_BUILTIN_CODE(EXPOSE_BUILTIN_EXECUTABLES)
+#undef EXPOSE_BUILTIN_EXECUTABLES
+
+ WEBCORE_FOREACH_READABLESTREAMDEFAULTCONTROLLER_BUILTIN_FUNCTION_NAME(DECLARE_BUILTIN_IDENTIFIER_ACCESSOR)
+
+ void exportNames();
+
+private:
+ JSC::VM& m_vm;
+
+ WEBCORE_FOREACH_READABLESTREAMDEFAULTCONTROLLER_BUILTIN_FUNCTION_NAME(DECLARE_BUILTIN_NAMES)
+
+#define DECLARE_BUILTIN_SOURCE_MEMBERS(name, functionName, overriddenName, length) \
+ JSC::SourceCode m_##name##Source;\
+ JSC::Weak<JSC::UnlinkedFunctionExecutable> m_##name##Executable;
+ WEBCORE_FOREACH_READABLESTREAMDEFAULTCONTROLLER_BUILTIN_CODE(DECLARE_BUILTIN_SOURCE_MEMBERS)
+#undef DECLARE_BUILTIN_SOURCE_MEMBERS
+
+};
+
+#define DEFINE_BUILTIN_EXECUTABLES(name, functionName, overriddenName, length) \
+inline JSC::UnlinkedFunctionExecutable* ReadableStreamDefaultControllerBuiltinsWrapper::name##Executable() \
+{\
+ if (!m_##name##Executable) {\
+ JSC::Identifier executableName = functionName##PublicName();\
+ if (overriddenName)\
+ executableName = JSC::Identifier::fromString(m_vm, overriddenName);\
+ m_##name##Executable = JSC::Weak<JSC::UnlinkedFunctionExecutable>(JSC::createBuiltinExecutable(m_vm, m_##name##Source, executableName, s_##name##ConstructorKind, s_##name##ConstructAbility), this, &m_##name##Executable);\
+ }\
+ return m_##name##Executable.get();\
+}
+WEBCORE_FOREACH_READABLESTREAMDEFAULTCONTROLLER_BUILTIN_CODE(DEFINE_BUILTIN_EXECUTABLES)
+#undef DEFINE_BUILTIN_EXECUTABLES
+
+inline void ReadableStreamDefaultControllerBuiltinsWrapper::exportNames()
+{
+#define EXPORT_FUNCTION_NAME(name) m_vm.propertyNames->appendExternalName(name##PublicName(), name##PrivateName());
+ WEBCORE_FOREACH_READABLESTREAMDEFAULTCONTROLLER_BUILTIN_FUNCTION_NAME(EXPORT_FUNCTION_NAME)
+#undef EXPORT_FUNCTION_NAME
+}
+
+} // namespace WebCore
diff --git a/src/bun.js/builtins/cpp/ReadableStreamDefaultReaderBuiltins.cpp b/src/bun.js/builtins/cpp/ReadableStreamDefaultReaderBuiltins.cpp
new file mode 100644
index 000000000..b1f8d4791
--- /dev/null
+++ b/src/bun.js/builtins/cpp/ReadableStreamDefaultReaderBuiltins.cpp
@@ -0,0 +1,254 @@
+/*
+ * Copyright (c) 2015 Igalia
+ * Copyright (c) 2015 Igalia S.L.
+ * Copyright (c) 2015 Igalia.
+ * Copyright (c) 2015, 2016 Canon Inc. All rights reserved.
+ * Copyright (c) 2015, 2016, 2017 Canon Inc.
+ * Copyright (c) 2016, 2020 Apple Inc. All rights reserved.
+ * Copyright (c) 2022 Codeblog Corp. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+// DO NOT EDIT THIS FILE. It is automatically generated from JavaScript files for
+// builtins by the script: Source/JavaScriptCore/Scripts/generate-js-builtins.py
+
+#include "config.h"
+#include "ReadableStreamDefaultReaderBuiltins.h"
+
+#include "WebCoreJSClientData.h"
+#include <JavaScriptCore/HeapInlines.h>
+#include <JavaScriptCore/IdentifierInlines.h>
+#include <JavaScriptCore/Intrinsic.h>
+#include <JavaScriptCore/JSCJSValueInlines.h>
+#include <JavaScriptCore/JSCellInlines.h>
+#include <JavaScriptCore/StructureInlines.h>
+#include <JavaScriptCore/VM.h>
+
+namespace WebCore {
+
+const JSC::ConstructAbility s_readableStreamDefaultReaderInitializeReadableStreamDefaultReaderCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableStreamDefaultReaderInitializeReadableStreamDefaultReaderCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableStreamDefaultReaderInitializeReadableStreamDefaultReaderCodeLength = 393;
+static const JSC::Intrinsic s_readableStreamDefaultReaderInitializeReadableStreamDefaultReaderCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableStreamDefaultReaderInitializeReadableStreamDefaultReaderCode =
+ "(function (stream)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " if (!@isReadableStream(stream))\n" \
+ " @throwTypeError(\"ReadableStreamDefaultReader needs a ReadableStream\");\n" \
+ " if (@isReadableStreamLocked(stream))\n" \
+ " @throwTypeError(\"ReadableStream is locked\");\n" \
+ "\n" \
+ " @readableStreamReaderGenericInitialize(this, stream);\n" \
+ " @putByIdDirectPrivate(this, \"readRequests\", @createFIFO());\n" \
+ "\n" \
+ " return this;\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableStreamDefaultReaderCancelCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableStreamDefaultReaderCancelCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableStreamDefaultReaderCancelCodeLength = 416;
+static const JSC::Intrinsic s_readableStreamDefaultReaderCancelCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableStreamDefaultReaderCancelCode =
+ "(function (reason)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " if (!@isReadableStreamDefaultReader(this))\n" \
+ " return @Promise.@reject(@makeThisTypeError(\"ReadableStreamDefaultReader\", \"cancel\"));\n" \
+ "\n" \
+ " if (!@getByIdDirectPrivate(this, \"ownerReadableStream\"))\n" \
+ " return @Promise.@reject(@makeTypeError(\"cancel() called on a reader owned by no readable stream\"));\n" \
+ "\n" \
+ " return @readableStreamReaderGenericCancel(this, reason);\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableStreamDefaultReaderReadManyCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableStreamDefaultReaderReadManyCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableStreamDefaultReaderReadManyCodeLength = 3414;
+static const JSC::Intrinsic s_readableStreamDefaultReaderReadManyCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableStreamDefaultReaderReadManyCode =
+ "(function ()\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " if (!@isReadableStreamDefaultReader(this))\n" \
+ " @throwTypeError(\"ReadableStreamDefaultReader.readMany() should not be called directly\");\n" \
+ "\n" \
+ " const stream = @getByIdDirectPrivate(this, \"ownerReadableStream\");\n" \
+ " if (!stream)\n" \
+ " @throwTypeError(\"readMany() called on a reader owned by no readable stream\");\n" \
+ "\n" \
+ " const state = @getByIdDirectPrivate(stream, \"state\");\n" \
+ " @putByIdDirectPrivate(stream, \"disturbed\", true);\n" \
+ " if (state === @streamClosed)\n" \
+ " return {value: [], size: 0, done: true};\n" \
+ " else if (state === @streamErrored) {\n" \
+ " throw @getByIdDirectPrivate(stream, \"storedError\");\n" \
+ " }\n" \
+ "\n" \
+ " \n" \
+ " var controller = @getByIdDirectPrivate(stream, \"readableStreamController\");\n" \
+ "\n" \
+ " const content = @getByIdDirectPrivate(controller, \"queue\").content;\n" \
+ " var size = @getByIdDirectPrivate(controller, \"queue\").size;\n" \
+ " var values = content.toArray(false);\n" \
+ " var length = values.length;\n" \
+ "\n" \
+ " if (length > 0) {\n" \
+ "\n" \
+ " if (@isReadableByteStreamController(controller)) {\n" \
+ " for (var i = 0; i < value.length; i++) {\n" \
+ " const buf = value[i];\n" \
+ " if (!(@ArrayBuffer.@isView(buf) || buf instanceof @ArrayBuffer)) {\n" \
+ " value[i] = new @Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength);\n" \
+ " }\n" \
+ " }\n" \
+ " }\n" \
+ " \n" \
+ " @resetQueue(@getByIdDirectPrivate(controller, \"queue\"));\n" \
+ "\n" \
+ " if (@getByIdDirectPrivate(controller, \"closeRequested\"))\n" \
+ " @readableStreamClose(@getByIdDirectPrivate(controller, \"controlledReadableStream\"));\n" \
+ " else if (@isReadableStreamDefaultController(controller)) \n" \
+ " @readableStreamDefaultControllerCallPullIfNeeded(controller);\n" \
+ " else if (@isReadableByteStreamController(controller))\n" \
+ " @readableByteStreamControllerCallPullIfNeeded(controller);\n" \
+ "\n" \
+ " return {value: values, size, done: false};\n" \
+ " }\n" \
+ "\n" \
+ " var onPullMany = (result) => {\n" \
+ " if (result.done) {\n" \
+ " return {value: [], size: 0, done: true};\n" \
+ " }\n" \
+ " var controller = @getByIdDirectPrivate(stream, \"readableStreamController\");\n" \
+ " \n" \
+ " var queue = @getByIdDirectPrivate(controller, \"queue\");\n" \
+ " var value = [result.value].concat(queue.content.toArray(false));\n" \
+ "\n" \
+ " if (@isReadableByteStreamController(controller)) {\n" \
+ " for (var i = 0; i < value.length; i++) {\n" \
+ " const buf = value[i];\n" \
+ " if (!(@ArrayBuffer.@isView(buf) || buf instanceof @ArrayBuffer)) {\n" \
+ " value[i] = new @Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength);\n" \
+ " }\n" \
+ " }\n" \
+ " }\n" \
+ " \n" \
+ " var size = queue.size;\n" \
+ " @resetQueue(queue);\n" \
+ "\n" \
+ " if (@getByIdDirectPrivate(controller, \"closeRequested\"))\n" \
+ " @readableStreamClose(@getByIdDirectPrivate(controller, \"controlledReadableStream\"));\n" \
+ " else if (@isReadableStreamDefaultController(controller)) \n" \
+ " @readableStreamDefaultControllerCallPullIfNeeded(controller);\n" \
+ " else if (@isReadableByteStreamController(controller))\n" \
+ " @readableByteStreamControllerCallPullIfNeeded(controller);\n" \
+ " \n" \
+ "\n" \
+ " \n" \
+ " return {value: value, size: size, done: false};\n" \
+ " };\n" \
+ " \n" \
+ " var pullResult = controller.@pull(controller);\n" \
+ " if (pullResult && @isPromise(pullResult)) {\n" \
+ " return pullResult.@then(onPullMany);\n" \
+ " }\n" \
+ "\n" \
+ " return onPullMany(pullResult);\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableStreamDefaultReaderReadCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableStreamDefaultReaderReadCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableStreamDefaultReaderReadCodeLength = 395;
+static const JSC::Intrinsic s_readableStreamDefaultReaderReadCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableStreamDefaultReaderReadCode =
+ "(function ()\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " if (!@isReadableStreamDefaultReader(this))\n" \
+ " return @Promise.@reject(@makeThisTypeError(\"ReadableStreamDefaultReader\", \"read\"));\n" \
+ " if (!@getByIdDirectPrivate(this, \"ownerReadableStream\"))\n" \
+ " return @Promise.@reject(@makeTypeError(\"read() called on a reader owned by no readable stream\"));\n" \
+ "\n" \
+ " return @readableStreamDefaultReaderRead(this);\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableStreamDefaultReaderReleaseLockCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableStreamDefaultReaderReleaseLockCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableStreamDefaultReaderReleaseLockCodeLength = 449;
+static const JSC::Intrinsic s_readableStreamDefaultReaderReleaseLockCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableStreamDefaultReaderReleaseLockCode =
+ "(function ()\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " if (!@isReadableStreamDefaultReader(this))\n" \
+ " throw @makeThisTypeError(\"ReadableStreamDefaultReader\", \"releaseLock\");\n" \
+ "\n" \
+ " if (!@getByIdDirectPrivate(this, \"ownerReadableStream\"))\n" \
+ " return;\n" \
+ "\n" \
+ " if (@getByIdDirectPrivate(this, \"readRequests\")?.isNotEmpty())\n" \
+ " @throwTypeError(\"There are still pending read requests, cannot release the lock\");\n" \
+ "\n" \
+ " @readableStreamReaderGenericRelease(this);\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableStreamDefaultReaderClosedCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableStreamDefaultReaderClosedCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableStreamDefaultReaderClosedCodeLength = 257;
+static const JSC::Intrinsic s_readableStreamDefaultReaderClosedCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableStreamDefaultReaderClosedCode =
+ "(function ()\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " if (!@isReadableStreamDefaultReader(this))\n" \
+ " return @Promise.@reject(@makeGetterTypeError(\"ReadableStreamDefaultReader\", \"closed\"));\n" \
+ "\n" \
+ " return @getByIdDirectPrivate(this, \"closedPromiseCapability\").@promise;\n" \
+ "})\n" \
+;
+
+
+#define DEFINE_BUILTIN_GENERATOR(codeName, functionName, overriddenName, argumentCount) \
+JSC::FunctionExecutable* codeName##Generator(JSC::VM& vm) \
+{\
+ JSVMClientData* clientData = static_cast<JSVMClientData*>(vm.clientData); \
+ return clientData->builtinFunctions().readableStreamDefaultReaderBuiltins().codeName##Executable()->link(vm, nullptr, clientData->builtinFunctions().readableStreamDefaultReaderBuiltins().codeName##Source(), std::nullopt, s_##codeName##Intrinsic); \
+}
+WEBCORE_FOREACH_READABLESTREAMDEFAULTREADER_BUILTIN_CODE(DEFINE_BUILTIN_GENERATOR)
+#undef DEFINE_BUILTIN_GENERATOR
+
+
+} // namespace WebCore
diff --git a/src/bun.js/builtins/cpp/ReadableStreamDefaultReaderBuiltins.h b/src/bun.js/builtins/cpp/ReadableStreamDefaultReaderBuiltins.h
new file mode 100644
index 000000000..1dc33a831
--- /dev/null
+++ b/src/bun.js/builtins/cpp/ReadableStreamDefaultReaderBuiltins.h
@@ -0,0 +1,167 @@
+/*
+ * Copyright (c) 2015 Igalia
+ * Copyright (c) 2015 Igalia S.L.
+ * Copyright (c) 2015 Igalia.
+ * Copyright (c) 2015, 2016 Canon Inc. All rights reserved.
+ * Copyright (c) 2015, 2016, 2017 Canon Inc.
+ * Copyright (c) 2016, 2020 Apple Inc. All rights reserved.
+ * Copyright (c) 2022 Codeblog Corp. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+// DO NOT EDIT THIS FILE. It is automatically generated from JavaScript files for
+// builtins by the script: Source/JavaScriptCore/Scripts/generate-js-builtins.py
+
+#pragma once
+
+#include <JavaScriptCore/BuiltinUtils.h>
+#include <JavaScriptCore/Identifier.h>
+#include <JavaScriptCore/JSFunction.h>
+#include <JavaScriptCore/UnlinkedFunctionExecutable.h>
+
+namespace JSC {
+class FunctionExecutable;
+}
+
+namespace WebCore {
+
+/* ReadableStreamDefaultReader */
+extern const char* const s_readableStreamDefaultReaderInitializeReadableStreamDefaultReaderCode;
+extern const int s_readableStreamDefaultReaderInitializeReadableStreamDefaultReaderCodeLength;
+extern const JSC::ConstructAbility s_readableStreamDefaultReaderInitializeReadableStreamDefaultReaderCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableStreamDefaultReaderInitializeReadableStreamDefaultReaderCodeConstructorKind;
+extern const char* const s_readableStreamDefaultReaderCancelCode;
+extern const int s_readableStreamDefaultReaderCancelCodeLength;
+extern const JSC::ConstructAbility s_readableStreamDefaultReaderCancelCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableStreamDefaultReaderCancelCodeConstructorKind;
+extern const char* const s_readableStreamDefaultReaderReadManyCode;
+extern const int s_readableStreamDefaultReaderReadManyCodeLength;
+extern const JSC::ConstructAbility s_readableStreamDefaultReaderReadManyCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableStreamDefaultReaderReadManyCodeConstructorKind;
+extern const char* const s_readableStreamDefaultReaderReadCode;
+extern const int s_readableStreamDefaultReaderReadCodeLength;
+extern const JSC::ConstructAbility s_readableStreamDefaultReaderReadCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableStreamDefaultReaderReadCodeConstructorKind;
+extern const char* const s_readableStreamDefaultReaderReleaseLockCode;
+extern const int s_readableStreamDefaultReaderReleaseLockCodeLength;
+extern const JSC::ConstructAbility s_readableStreamDefaultReaderReleaseLockCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableStreamDefaultReaderReleaseLockCodeConstructorKind;
+extern const char* const s_readableStreamDefaultReaderClosedCode;
+extern const int s_readableStreamDefaultReaderClosedCodeLength;
+extern const JSC::ConstructAbility s_readableStreamDefaultReaderClosedCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableStreamDefaultReaderClosedCodeConstructorKind;
+
+#define WEBCORE_FOREACH_READABLESTREAMDEFAULTREADER_BUILTIN_DATA(macro) \
+ macro(initializeReadableStreamDefaultReader, readableStreamDefaultReaderInitializeReadableStreamDefaultReader, 1) \
+ macro(cancel, readableStreamDefaultReaderCancel, 1) \
+ macro(readMany, readableStreamDefaultReaderReadMany, 0) \
+ macro(read, readableStreamDefaultReaderRead, 0) \
+ macro(releaseLock, readableStreamDefaultReaderReleaseLock, 0) \
+ macro(closed, readableStreamDefaultReaderClosed, 0) \
+
+#define WEBCORE_BUILTIN_READABLESTREAMDEFAULTREADER_INITIALIZEREADABLESTREAMDEFAULTREADER 1
+#define WEBCORE_BUILTIN_READABLESTREAMDEFAULTREADER_CANCEL 1
+#define WEBCORE_BUILTIN_READABLESTREAMDEFAULTREADER_READMANY 1
+#define WEBCORE_BUILTIN_READABLESTREAMDEFAULTREADER_READ 1
+#define WEBCORE_BUILTIN_READABLESTREAMDEFAULTREADER_RELEASELOCK 1
+#define WEBCORE_BUILTIN_READABLESTREAMDEFAULTREADER_CLOSED 1
+
+#define WEBCORE_FOREACH_READABLESTREAMDEFAULTREADER_BUILTIN_CODE(macro) \
+ macro(readableStreamDefaultReaderInitializeReadableStreamDefaultReaderCode, initializeReadableStreamDefaultReader, ASCIILiteral(), s_readableStreamDefaultReaderInitializeReadableStreamDefaultReaderCodeLength) \
+ macro(readableStreamDefaultReaderCancelCode, cancel, ASCIILiteral(), s_readableStreamDefaultReaderCancelCodeLength) \
+ macro(readableStreamDefaultReaderReadManyCode, readMany, ASCIILiteral(), s_readableStreamDefaultReaderReadManyCodeLength) \
+ macro(readableStreamDefaultReaderReadCode, read, ASCIILiteral(), s_readableStreamDefaultReaderReadCodeLength) \
+ macro(readableStreamDefaultReaderReleaseLockCode, releaseLock, ASCIILiteral(), s_readableStreamDefaultReaderReleaseLockCodeLength) \
+ macro(readableStreamDefaultReaderClosedCode, closed, "get closed"_s, s_readableStreamDefaultReaderClosedCodeLength) \
+
+#define WEBCORE_FOREACH_READABLESTREAMDEFAULTREADER_BUILTIN_FUNCTION_NAME(macro) \
+ macro(cancel) \
+ macro(closed) \
+ macro(initializeReadableStreamDefaultReader) \
+ macro(read) \
+ macro(readMany) \
+ macro(releaseLock) \
+
+#define DECLARE_BUILTIN_GENERATOR(codeName, functionName, overriddenName, argumentCount) \
+ JSC::FunctionExecutable* codeName##Generator(JSC::VM&);
+
+WEBCORE_FOREACH_READABLESTREAMDEFAULTREADER_BUILTIN_CODE(DECLARE_BUILTIN_GENERATOR)
+#undef DECLARE_BUILTIN_GENERATOR
+
+class ReadableStreamDefaultReaderBuiltinsWrapper : private JSC::WeakHandleOwner {
+public:
+ explicit ReadableStreamDefaultReaderBuiltinsWrapper(JSC::VM& vm)
+ : m_vm(vm)
+ WEBCORE_FOREACH_READABLESTREAMDEFAULTREADER_BUILTIN_FUNCTION_NAME(INITIALIZE_BUILTIN_NAMES)
+#define INITIALIZE_BUILTIN_SOURCE_MEMBERS(name, functionName, overriddenName, length) , m_##name##Source(JSC::makeSource(StringImpl::createWithoutCopying(s_##name, length), { }))
+ WEBCORE_FOREACH_READABLESTREAMDEFAULTREADER_BUILTIN_CODE(INITIALIZE_BUILTIN_SOURCE_MEMBERS)
+#undef INITIALIZE_BUILTIN_SOURCE_MEMBERS
+ {
+ }
+
+#define EXPOSE_BUILTIN_EXECUTABLES(name, functionName, overriddenName, length) \
+ JSC::UnlinkedFunctionExecutable* name##Executable(); \
+ const JSC::SourceCode& name##Source() const { return m_##name##Source; }
+ WEBCORE_FOREACH_READABLESTREAMDEFAULTREADER_BUILTIN_CODE(EXPOSE_BUILTIN_EXECUTABLES)
+#undef EXPOSE_BUILTIN_EXECUTABLES
+
+ WEBCORE_FOREACH_READABLESTREAMDEFAULTREADER_BUILTIN_FUNCTION_NAME(DECLARE_BUILTIN_IDENTIFIER_ACCESSOR)
+
+ void exportNames();
+
+private:
+ JSC::VM& m_vm;
+
+ WEBCORE_FOREACH_READABLESTREAMDEFAULTREADER_BUILTIN_FUNCTION_NAME(DECLARE_BUILTIN_NAMES)
+
+#define DECLARE_BUILTIN_SOURCE_MEMBERS(name, functionName, overriddenName, length) \
+ JSC::SourceCode m_##name##Source;\
+ JSC::Weak<JSC::UnlinkedFunctionExecutable> m_##name##Executable;
+ WEBCORE_FOREACH_READABLESTREAMDEFAULTREADER_BUILTIN_CODE(DECLARE_BUILTIN_SOURCE_MEMBERS)
+#undef DECLARE_BUILTIN_SOURCE_MEMBERS
+
+};
+
+#define DEFINE_BUILTIN_EXECUTABLES(name, functionName, overriddenName, length) \
+inline JSC::UnlinkedFunctionExecutable* ReadableStreamDefaultReaderBuiltinsWrapper::name##Executable() \
+{\
+ if (!m_##name##Executable) {\
+ JSC::Identifier executableName = functionName##PublicName();\
+ if (overriddenName)\
+ executableName = JSC::Identifier::fromString(m_vm, overriddenName);\
+ m_##name##Executable = JSC::Weak<JSC::UnlinkedFunctionExecutable>(JSC::createBuiltinExecutable(m_vm, m_##name##Source, executableName, s_##name##ConstructorKind, s_##name##ConstructAbility), this, &m_##name##Executable);\
+ }\
+ return m_##name##Executable.get();\
+}
+WEBCORE_FOREACH_READABLESTREAMDEFAULTREADER_BUILTIN_CODE(DEFINE_BUILTIN_EXECUTABLES)
+#undef DEFINE_BUILTIN_EXECUTABLES
+
+inline void ReadableStreamDefaultReaderBuiltinsWrapper::exportNames()
+{
+#define EXPORT_FUNCTION_NAME(name) m_vm.propertyNames->appendExternalName(name##PublicName(), name##PrivateName());
+ WEBCORE_FOREACH_READABLESTREAMDEFAULTREADER_BUILTIN_FUNCTION_NAME(EXPORT_FUNCTION_NAME)
+#undef EXPORT_FUNCTION_NAME
+}
+
+} // namespace WebCore
diff --git a/src/bun.js/builtins/cpp/ReadableStreamInternalsBuiltins.cpp b/src/bun.js/builtins/cpp/ReadableStreamInternalsBuiltins.cpp
new file mode 100644
index 000000000..09e96a121
--- /dev/null
+++ b/src/bun.js/builtins/cpp/ReadableStreamInternalsBuiltins.cpp
@@ -0,0 +1,1594 @@
+/*
+ * Copyright (c) 2015 Igalia
+ * Copyright (c) 2015 Igalia S.L.
+ * Copyright (c) 2015 Igalia.
+ * Copyright (c) 2015, 2016 Canon Inc. All rights reserved.
+ * Copyright (c) 2015, 2016, 2017 Canon Inc.
+ * Copyright (c) 2016, 2020 Apple Inc. All rights reserved.
+ * Copyright (c) 2022 Codeblog Corp. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+// DO NOT EDIT THIS FILE. It is automatically generated from JavaScript files for
+// builtins by the script: Source/JavaScriptCore/Scripts/generate-js-builtins.py
+
+#include "config.h"
+#include "ReadableStreamInternalsBuiltins.h"
+
+#include "WebCoreJSClientData.h"
+#include <JavaScriptCore/HeapInlines.h>
+#include <JavaScriptCore/IdentifierInlines.h>
+#include <JavaScriptCore/Intrinsic.h>
+#include <JavaScriptCore/JSCJSValueInlines.h>
+#include <JavaScriptCore/JSCellInlines.h>
+#include <JavaScriptCore/StructureInlines.h>
+#include <JavaScriptCore/VM.h>
+
+namespace WebCore {
+
+const JSC::ConstructAbility s_readableStreamInternalsReadableStreamReaderGenericInitializeCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableStreamInternalsReadableStreamReaderGenericInitializeCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableStreamInternalsReadableStreamReaderGenericInitializeCodeLength = 756;
+static const JSC::Intrinsic s_readableStreamInternalsReadableStreamReaderGenericInitializeCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableStreamInternalsReadableStreamReaderGenericInitializeCode =
+ "(function (reader, stream)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " @putByIdDirectPrivate(reader, \"ownerReadableStream\", stream);\n" \
+ " @putByIdDirectPrivate(stream, \"reader\", reader);\n" \
+ " if (@getByIdDirectPrivate(stream, \"state\") === @streamReadable)\n" \
+ " @putByIdDirectPrivate(reader, \"closedPromiseCapability\", @newPromiseCapability(@Promise));\n" \
+ " else if (@getByIdDirectPrivate(stream, \"state\") === @streamClosed)\n" \
+ " @putByIdDirectPrivate(reader, \"closedPromiseCapability\", { @promise: @Promise.@resolve() });\n" \
+ " else {\n" \
+ " @assert(@getByIdDirectPrivate(stream, \"state\") === @streamErrored);\n" \
+ " @putByIdDirectPrivate(reader, \"closedPromiseCapability\", { @promise: @newHandledRejectedPromise(@getByIdDirectPrivate(stream, \"storedError\")) });\n" \
+ " }\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableStreamInternalsPrivateInitializeReadableStreamDefaultControllerCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableStreamInternalsPrivateInitializeReadableStreamDefaultControllerCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableStreamInternalsPrivateInitializeReadableStreamDefaultControllerCodeLength = 899;
+static const JSC::Intrinsic s_readableStreamInternalsPrivateInitializeReadableStreamDefaultControllerCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableStreamInternalsPrivateInitializeReadableStreamDefaultControllerCode =
+ "(function (stream, underlyingSource, size, highWaterMark)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ " \n" \
+ " if (!@isReadableStream(stream))\n" \
+ " @throwTypeError(\"ReadableStreamDefaultController needs a ReadableStream\");\n" \
+ "\n" \
+ " //\n" \
+ " if (@getByIdDirectPrivate(stream, \"readableStreamController\") !== null)\n" \
+ " @throwTypeError(\"ReadableStream already has a controller\");\n" \
+ "\n" \
+ " \n" \
+ "\n" \
+ " @putByIdDirectPrivate(this, \"controlledReadableStream\", stream);\n" \
+ " @putByIdDirectPrivate(this, \"underlyingSource\", underlyingSource);\n" \
+ " @putByIdDirectPrivate(this, \"queue\", @newQueue());\n" \
+ " @putByIdDirectPrivate(this, \"started\", -1);\n" \
+ " @putByIdDirectPrivate(this, \"closeRequested\", false);\n" \
+ " @putByIdDirectPrivate(this, \"pullAgain\", false);\n" \
+ " @putByIdDirectPrivate(this, \"pulling\", false);\n" \
+ " @putByIdDirectPrivate(this, \"strategy\", @validateAndNormalizeQueuingStrategy(size, highWaterMark));\n" \
+ "\n" \
+ " return this;\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableStreamInternalsReadableStreamDefaultControllerErrorCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableStreamInternalsReadableStreamDefaultControllerErrorCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableStreamInternalsReadableStreamDefaultControllerErrorCodeLength = 327;
+static const JSC::Intrinsic s_readableStreamInternalsReadableStreamDefaultControllerErrorCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableStreamInternalsReadableStreamDefaultControllerErrorCode =
+ "(function (controller, error)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " const stream = @getByIdDirectPrivate(controller, \"controlledReadableStream\");\n" \
+ " if (@getByIdDirectPrivate(stream, \"state\") !== @streamReadable)\n" \
+ " return;\n" \
+ " @putByIdDirectPrivate(controller, \"queue\", @newQueue());\n" \
+ " \n" \
+ " @readableStreamError(stream, error);\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableStreamInternalsReadableStreamPipeToCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableStreamInternalsReadableStreamPipeToCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableStreamInternalsReadableStreamPipeToCodeLength = 778;
+static const JSC::Intrinsic s_readableStreamInternalsReadableStreamPipeToCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableStreamInternalsReadableStreamPipeToCode =
+ "(function (stream, sink)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ " @assert(@isReadableStream(stream));\n" \
+ "\n" \
+ " const reader = new @ReadableStreamDefaultReader(stream);\n" \
+ "\n" \
+ " @getByIdDirectPrivate(reader, \"closedPromiseCapability\").@promise.@then(() => { }, (e) => { sink.error(e); });\n" \
+ "\n" \
+ " function doPipe() {\n" \
+ " @readableStreamDefaultReaderRead(reader).@then(function(result) {\n" \
+ " if (result.done) {\n" \
+ " sink.close();\n" \
+ " return;\n" \
+ " }\n" \
+ " try {\n" \
+ " sink.enqueue(result.value);\n" \
+ " } catch (e) {\n" \
+ " sink.error(\"ReadableStream chunk enqueueing in the sink failed\");\n" \
+ " return;\n" \
+ " }\n" \
+ " doPipe();\n" \
+ " }, function(e) {\n" \
+ " sink.error(e);\n" \
+ " });\n" \
+ " }\n" \
+ " doPipe();\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableStreamInternalsAcquireReadableStreamDefaultReaderCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableStreamInternalsAcquireReadableStreamDefaultReaderCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableStreamInternalsAcquireReadableStreamDefaultReaderCodeLength = 204;
+static const JSC::Intrinsic s_readableStreamInternalsAcquireReadableStreamDefaultReaderCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableStreamInternalsAcquireReadableStreamDefaultReaderCode =
+ "(function (stream)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ " var start = @getByIdDirectPrivate(stream, \"start\");\n" \
+ " if (start) {\n" \
+ " start.@call(stream);\n" \
+ " }\n" \
+ "\n" \
+ " return new @ReadableStreamDefaultReader(stream);\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableStreamInternalsSetupReadableStreamDefaultControllerCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableStreamInternalsSetupReadableStreamDefaultControllerCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableStreamInternalsSetupReadableStreamDefaultControllerCodeLength = 931;
+static const JSC::Intrinsic s_readableStreamInternalsSetupReadableStreamDefaultControllerCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableStreamInternalsSetupReadableStreamDefaultControllerCode =
+ "(function (stream, underlyingSource, size, highWaterMark, startMethod, pullMethod, cancelMethod)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ " \n" \
+ " const controller = new @ReadableStreamDefaultController(stream, underlyingSource, size, highWaterMark, @isReadableStream);\n" \
+ " \n" \
+ " const pullAlgorithm = () => @promiseInvokeOrNoopMethod(underlyingSource, pullMethod, [controller]);\n" \
+ " const cancelAlgorithm = (reason) => @promiseInvokeOrNoopMethod(underlyingSource, cancelMethod, [reason]);\n" \
+ " \n" \
+ " @putByIdDirectPrivate(controller, \"pullAlgorithm\", pullAlgorithm);\n" \
+ " @putByIdDirectPrivate(controller, \"cancelAlgorithm\", cancelAlgorithm);\n" \
+ " @putByIdDirectPrivate(controller, \"pull\", @readableStreamDefaultControllerPull);\n" \
+ " @putByIdDirectPrivate(controller, \"cancel\", @readableStreamDefaultControllerCancel);\n" \
+ " @putByIdDirectPrivate(stream, \"readableStreamController\", controller);\n" \
+ "\n" \
+ " @readableStreamDefaultControllerStart(controller);\n" \
+ " \n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableStreamInternalsCreateReadableStreamControllerCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableStreamInternalsCreateReadableStreamControllerCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableStreamInternalsCreateReadableStreamControllerCodeLength = 1196;
+static const JSC::Intrinsic s_readableStreamInternalsCreateReadableStreamControllerCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableStreamInternalsCreateReadableStreamControllerCode =
+ "(function (stream, underlyingSource, strategy) {\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " const type = underlyingSource.type;\n" \
+ " const typeString = @toString(type);\n" \
+ "\n" \
+ " if (typeString === \"bytes\") {\n" \
+ " //\n" \
+ " //\n" \
+ "\n" \
+ " if (strategy.highWaterMark === @undefined)\n" \
+ " strategy.highWaterMark = 0;\n" \
+ " if (strategy.size !== @undefined)\n" \
+ " @throwRangeError(\"Strategy for a ReadableByteStreamController cannot have a size\");\n" \
+ "\n" \
+ " @putByIdDirectPrivate(stream, \"readableStreamController\", new @ReadableByteStreamController(stream, underlyingSource, strategy.highWaterMark, @isReadableStream));\n" \
+ " } else if (typeString === \"direct\") {\n" \
+ " var highWaterMark = strategy?.highWaterMark;\n" \
+ " @initializeArrayBufferStream.@call(stream, underlyingSource, highWaterMark); \n" \
+ " } else if (type === @undefined) {\n" \
+ " if (strategy.highWaterMark === @undefined)\n" \
+ " strategy.highWaterMark = 1;\n" \
+ " \n" \
+ " @setupReadableStreamDefaultController(stream, underlyingSource, strategy.size, strategy.highWaterMark, underlyingSource.start, underlyingSource.pull, underlyingSource.cancel);\n" \
+ " } else\n" \
+ " @throwRangeError(\"Invalid type for underlying source\");\n" \
+ "\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableStreamInternalsReadableStreamDefaultControllerStartCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableStreamInternalsReadableStreamDefaultControllerStartCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableStreamInternalsReadableStreamDefaultControllerStartCodeLength = 765;
+static const JSC::Intrinsic s_readableStreamInternalsReadableStreamDefaultControllerStartCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableStreamInternalsReadableStreamDefaultControllerStartCode =
+ "(function (controller) {\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " \n" \
+ "\n" \
+ " if (@getByIdDirectPrivate(controller, \"started\") !== -1)\n" \
+ " return;\n" \
+ "\n" \
+ " const underlyingSource = @getByIdDirectPrivate(controller, \"underlyingSource\");\n" \
+ " const startMethod = underlyingSource.start;\n" \
+ " @putByIdDirectPrivate(controller, \"started\", 0);\n" \
+ "\n" \
+ " @promiseInvokeOrNoopMethodNoCatch(underlyingSource, startMethod, [controller]).@then(() => {\n" \
+ " @putByIdDirectPrivate(controller, \"started\", 1);\n" \
+ " @assert(!@getByIdDirectPrivate(controller, \"pulling\"));\n" \
+ " @assert(!@getByIdDirectPrivate(controller, \"pullAgain\"));\n" \
+ " @readableStreamDefaultControllerCallPullIfNeeded(controller);\n" \
+ " }, (error) => {\n" \
+ " @readableStreamDefaultControllerError(controller, error);\n" \
+ " });\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableStreamInternalsReadableStreamPipeToWritableStreamCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableStreamInternalsReadableStreamPipeToWritableStreamCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableStreamInternalsReadableStreamPipeToWritableStreamCodeLength = 3232;
+static const JSC::Intrinsic s_readableStreamInternalsReadableStreamPipeToWritableStreamCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableStreamInternalsReadableStreamPipeToWritableStreamCode =
+ "(function (source, destination, preventClose, preventAbort, preventCancel, signal)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " @assert(@isReadableStream(source));\n" \
+ " @assert(@isWritableStream(destination));\n" \
+ " @assert(!@isReadableStreamLocked(source));\n" \
+ " @assert(!@isWritableStreamLocked(destination));\n" \
+ " @assert(signal === @undefined || @isAbortSignal(signal));\n" \
+ "\n" \
+ " if (@getByIdDirectPrivate(source, \"underlyingByteSource\") !== @undefined)\n" \
+ " return @Promise.@reject(\"Piping to a readable bytestream is not supported\");\n" \
+ "\n" \
+ " let pipeState = { source : source, destination : destination, preventAbort : preventAbort, preventCancel : preventCancel, preventClose : preventClose, signal : signal };\n" \
+ "\n" \
+ " pipeState.reader = @acquireReadableStreamDefaultReader(source);\n" \
+ " pipeState.writer = @acquireWritableStreamDefaultWriter(destination);\n" \
+ "\n" \
+ " @putByIdDirectPrivate(source, \"disturbed\", true);\n" \
+ "\n" \
+ " pipeState.finalized = false;\n" \
+ " pipeState.shuttingDown = false;\n" \
+ " pipeState.promiseCapability = @newPromiseCapability(@Promise);\n" \
+ " pipeState.pendingReadPromiseCapability = @newPromiseCapability(@Promise);\n" \
+ " pipeState.pendingReadPromiseCapability.@resolve.@call();\n" \
+ " pipeState.pendingWritePromise = @Promise.@resolve();\n" \
+ "\n" \
+ " if (signal !== @undefined) {\n" \
+ " const algorithm = () => {\n" \
+ " if (pipeState.finalized)\n" \
+ " return;\n" \
+ "\n" \
+ " const error = @makeDOMException(\"AbortError\", \"abort pipeTo from signal\");\n" \
+ "\n" \
+ " @pipeToShutdownWithAction(pipeState, () => {\n" \
+ " const shouldAbortDestination = !pipeState.preventAbort && @getByIdDirectPrivate(pipeState.destination, \"state\") === \"writable\";\n" \
+ " const promiseDestination = shouldAbortDestination ? @writableStreamAbort(pipeState.destination, error) : @Promise.@resolve();\n" \
+ "\n" \
+ " const shouldAbortSource = !pipeState.preventCancel && @getByIdDirectPrivate(pipeState.source, \"state\") === @streamReadable;\n" \
+ " const promiseSource = shouldAbortSource ? @readableStreamCancel(pipeState.source, error) : @Promise.@resolve();\n" \
+ "\n" \
+ " let promiseCapability = @newPromiseCapability(@Promise);\n" \
+ " let shouldWait = true;\n" \
+ " let handleResolvedPromise = () => {\n" \
+ " if (shouldWait) {\n" \
+ " shouldWait = false;\n" \
+ " return;\n" \
+ " }\n" \
+ " promiseCapability.@resolve.@call();\n" \
+ " }\n" \
+ " let handleRejectedPromise = (e) => {\n" \
+ " promiseCapability.@reject.@call(@undefined, e);\n" \
+ " }\n" \
+ " promiseDestination.@then(handleResolvedPromise, handleRejectedPromise);\n" \
+ " promiseSource.@then(handleResolvedPromise, handleRejectedPromise);\n" \
+ " return promiseCapability.@promise;\n" \
+ " }, error);\n" \
+ " };\n" \
+ " if (@whenSignalAborted(signal, algorithm))\n" \
+ " return pipeState.promiseCapability.@promise;\n" \
+ " }\n" \
+ "\n" \
+ " @pipeToErrorsMustBePropagatedForward(pipeState);\n" \
+ " @pipeToErrorsMustBePropagatedBackward(pipeState);\n" \
+ " @pipeToClosingMustBePropagatedForward(pipeState);\n" \
+ " @pipeToClosingMustBePropagatedBackward(pipeState);\n" \
+ "\n" \
+ " @pipeToLoop(pipeState);\n" \
+ "\n" \
+ " return pipeState.promiseCapability.@promise;\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableStreamInternalsPipeToLoopCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableStreamInternalsPipeToLoopCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableStreamInternalsPipeToLoopCodeLength = 212;
+static const JSC::Intrinsic s_readableStreamInternalsPipeToLoopCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableStreamInternalsPipeToLoopCode =
+ "(function (pipeState)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ " if (pipeState.shuttingDown)\n" \
+ " return;\n" \
+ "\n" \
+ " @pipeToDoReadWrite(pipeState).@then((result) => {\n" \
+ " if (result)\n" \
+ " @pipeToLoop(pipeState);\n" \
+ " });\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableStreamInternalsPipeToDoReadWriteCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableStreamInternalsPipeToDoReadWriteCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableStreamInternalsPipeToDoReadWriteCodeLength = 1126;
+static const JSC::Intrinsic s_readableStreamInternalsPipeToDoReadWriteCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableStreamInternalsPipeToDoReadWriteCode =
+ "(function (pipeState)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ " @assert(!pipeState.shuttingDown);\n" \
+ "\n" \
+ " pipeState.pendingReadPromiseCapability = @newPromiseCapability(@Promise);\n" \
+ " @getByIdDirectPrivate(pipeState.writer, \"readyPromise\").@promise.@then(() => {\n" \
+ " if (pipeState.shuttingDown) {\n" \
+ " pipeState.pendingReadPromiseCapability.@resolve.@call(@undefined, false);\n" \
+ " return;\n" \
+ " }\n" \
+ "\n" \
+ " @readableStreamDefaultReaderRead(pipeState.reader).@then((result) => {\n" \
+ " const canWrite = !result.done && @getByIdDirectPrivate(pipeState.writer, \"stream\") !== @undefined;\n" \
+ " pipeState.pendingReadPromiseCapability.@resolve.@call(@undefined, canWrite);\n" \
+ " if (!canWrite)\n" \
+ " return;\n" \
+ "\n" \
+ " pipeState.pendingWritePromise = @writableStreamDefaultWriterWrite(pipeState.writer, result.value);\n" \
+ " }, (e) => {\n" \
+ " pipeState.pendingReadPromiseCapability.@resolve.@call(@undefined, false);\n" \
+ " });\n" \
+ " }, (e) => {\n" \
+ " pipeState.pendingReadPromiseCapability.@resolve.@call(@undefined, false);\n" \
+ " });\n" \
+ " return pipeState.pendingReadPromiseCapability.@promise;\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableStreamInternalsPipeToErrorsMustBePropagatedForwardCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableStreamInternalsPipeToErrorsMustBePropagatedForwardCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableStreamInternalsPipeToErrorsMustBePropagatedForwardCodeLength = 695;
+static const JSC::Intrinsic s_readableStreamInternalsPipeToErrorsMustBePropagatedForwardCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableStreamInternalsPipeToErrorsMustBePropagatedForwardCode =
+ "(function (pipeState)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " const action = () => {\n" \
+ " pipeState.pendingReadPromiseCapability.@resolve.@call(@undefined, false);\n" \
+ " const error = @getByIdDirectPrivate(pipeState.source, \"storedError\");\n" \
+ " if (!pipeState.preventAbort) {\n" \
+ " @pipeToShutdownWithAction(pipeState, () => @writableStreamAbort(pipeState.destination, error), error);\n" \
+ " return;\n" \
+ " }\n" \
+ " @pipeToShutdown(pipeState, error);\n" \
+ " };\n" \
+ "\n" \
+ " if (@getByIdDirectPrivate(pipeState.source, \"state\") === @streamErrored) {\n" \
+ " action();\n" \
+ " return;\n" \
+ " }\n" \
+ "\n" \
+ " @getByIdDirectPrivate(pipeState.reader, \"closedPromiseCapability\").@promise.@then(@undefined, action);\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableStreamInternalsPipeToErrorsMustBePropagatedBackwardCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableStreamInternalsPipeToErrorsMustBePropagatedBackwardCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableStreamInternalsPipeToErrorsMustBePropagatedBackwardCodeLength = 602;
+static const JSC::Intrinsic s_readableStreamInternalsPipeToErrorsMustBePropagatedBackwardCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableStreamInternalsPipeToErrorsMustBePropagatedBackwardCode =
+ "(function (pipeState)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ " const action = () => {\n" \
+ " const error = @getByIdDirectPrivate(pipeState.destination, \"storedError\");\n" \
+ " if (!pipeState.preventCancel) {\n" \
+ " @pipeToShutdownWithAction(pipeState, () => @readableStreamCancel(pipeState.source, error), error);\n" \
+ " return;\n" \
+ " }\n" \
+ " @pipeToShutdown(pipeState, error);\n" \
+ " };\n" \
+ " if (@getByIdDirectPrivate(pipeState.destination, \"state\") === \"errored\") {\n" \
+ " action();\n" \
+ " return;\n" \
+ " }\n" \
+ " @getByIdDirectPrivate(pipeState.writer, \"closedPromise\").@promise.@then(@undefined, action);\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableStreamInternalsPipeToClosingMustBePropagatedForwardCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableStreamInternalsPipeToClosingMustBePropagatedForwardCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableStreamInternalsPipeToClosingMustBePropagatedForwardCodeLength = 698;
+static const JSC::Intrinsic s_readableStreamInternalsPipeToClosingMustBePropagatedForwardCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableStreamInternalsPipeToClosingMustBePropagatedForwardCode =
+ "(function (pipeState)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ " const action = () => {\n" \
+ " pipeState.pendingReadPromiseCapability.@resolve.@call(@undefined, false);\n" \
+ " const error = @getByIdDirectPrivate(pipeState.source, \"storedError\");\n" \
+ " if (!pipeState.preventClose) {\n" \
+ " @pipeToShutdownWithAction(pipeState, () => @writableStreamDefaultWriterCloseWithErrorPropagation(pipeState.writer));\n" \
+ " return;\n" \
+ " }\n" \
+ " @pipeToShutdown(pipeState);\n" \
+ " };\n" \
+ " if (@getByIdDirectPrivate(pipeState.source, \"state\") === @streamClosed) {\n" \
+ " action();\n" \
+ " return;\n" \
+ " }\n" \
+ " @getByIdDirectPrivate(pipeState.reader, \"closedPromiseCapability\").@promise.@then(action, @undefined);\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableStreamInternalsPipeToClosingMustBePropagatedBackwardCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableStreamInternalsPipeToClosingMustBePropagatedBackwardCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableStreamInternalsPipeToClosingMustBePropagatedBackwardCodeLength = 482;
+static const JSC::Intrinsic s_readableStreamInternalsPipeToClosingMustBePropagatedBackwardCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableStreamInternalsPipeToClosingMustBePropagatedBackwardCode =
+ "(function (pipeState)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ " if (!@writableStreamCloseQueuedOrInFlight(pipeState.destination) && @getByIdDirectPrivate(pipeState.destination, \"state\") !== \"closed\")\n" \
+ " return;\n" \
+ "\n" \
+ " //\n" \
+ "\n" \
+ " const error = @makeTypeError(\"closing is propagated backward\");\n" \
+ " if (!pipeState.preventCancel) {\n" \
+ " @pipeToShutdownWithAction(pipeState, () => @readableStreamCancel(pipeState.source, error), error);\n" \
+ " return;\n" \
+ " }\n" \
+ " @pipeToShutdown(pipeState, error);\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableStreamInternalsPipeToShutdownWithActionCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableStreamInternalsPipeToShutdownWithActionCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableStreamInternalsPipeToShutdownWithActionCodeLength = 901;
+static const JSC::Intrinsic s_readableStreamInternalsPipeToShutdownWithActionCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableStreamInternalsPipeToShutdownWithActionCode =
+ "(function (pipeState, action)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " if (pipeState.shuttingDown)\n" \
+ " return;\n" \
+ "\n" \
+ " pipeState.shuttingDown = true;\n" \
+ "\n" \
+ " const hasError = arguments.length > 2;\n" \
+ " const error = arguments[2];\n" \
+ " const finalize = () => {\n" \
+ " const promise = action();\n" \
+ " promise.@then(() => {\n" \
+ " if (hasError)\n" \
+ " @pipeToFinalize(pipeState, error);\n" \
+ " else\n" \
+ " @pipeToFinalize(pipeState);\n" \
+ " }, (e) => {\n" \
+ " @pipeToFinalize(pipeState, e);\n" \
+ " });\n" \
+ " };\n" \
+ "\n" \
+ " if (@getByIdDirectPrivate(pipeState.destination, \"state\") === \"writable\" && !@writableStreamCloseQueuedOrInFlight(pipeState.destination)) {\n" \
+ " pipeState.pendingReadPromiseCapability.@promise.@then(() => {\n" \
+ " pipeState.pendingWritePromise.@then(finalize, finalize);\n" \
+ " }, (e) => @pipeToFinalize(pipeState, e));\n" \
+ " return;\n" \
+ " }\n" \
+ "\n" \
+ " finalize();\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableStreamInternalsPipeToShutdownCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableStreamInternalsPipeToShutdownCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableStreamInternalsPipeToShutdownCodeLength = 740;
+static const JSC::Intrinsic s_readableStreamInternalsPipeToShutdownCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableStreamInternalsPipeToShutdownCode =
+ "(function (pipeState)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ " \n" \
+ " if (pipeState.shuttingDown)\n" \
+ " return;\n" \
+ "\n" \
+ " pipeState.shuttingDown = true;\n" \
+ "\n" \
+ " const hasError = arguments.length > 1;\n" \
+ " const error = arguments[1];\n" \
+ " const finalize = () => {\n" \
+ " if (hasError)\n" \
+ " @pipeToFinalize(pipeState, error);\n" \
+ " else\n" \
+ " @pipeToFinalize(pipeState);\n" \
+ " };\n" \
+ "\n" \
+ " if (@getByIdDirectPrivate(pipeState.destination, \"state\") === \"writable\" && !@writableStreamCloseQueuedOrInFlight(pipeState.destination)) {\n" \
+ " pipeState.pendingReadPromiseCapability.@promise.@then(() => {\n" \
+ " pipeState.pendingWritePromise.@then(finalize, finalize);\n" \
+ " }, (e) => @pipeToFinalize(pipeState, e));\n" \
+ " return;\n" \
+ " }\n" \
+ " finalize();\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableStreamInternalsPipeToFinalizeCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableStreamInternalsPipeToFinalizeCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableStreamInternalsPipeToFinalizeCodeLength = 375;
+static const JSC::Intrinsic s_readableStreamInternalsPipeToFinalizeCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableStreamInternalsPipeToFinalizeCode =
+ "(function (pipeState)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " @writableStreamDefaultWriterRelease(pipeState.writer);\n" \
+ " @readableStreamReaderGenericRelease(pipeState.reader);\n" \
+ "\n" \
+ " //\n" \
+ " pipeState.finalized = true;\n" \
+ "\n" \
+ " if (arguments.length > 1)\n" \
+ " pipeState.promiseCapability.@reject.@call(@undefined, arguments[1]);\n" \
+ " else\n" \
+ " pipeState.promiseCapability.@resolve.@call();\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableStreamInternalsReadableStreamTeeCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableStreamInternalsReadableStreamTeeCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableStreamInternalsReadableStreamTeeCodeLength = 1671;
+static const JSC::Intrinsic s_readableStreamInternalsReadableStreamTeeCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableStreamInternalsReadableStreamTeeCode =
+ "(function (stream, shouldClone)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " @assert(@isReadableStream(stream));\n" \
+ " @assert(typeof(shouldClone) === \"boolean\");\n" \
+ "\n" \
+ " const reader = new @ReadableStreamDefaultReader(stream);\n" \
+ "\n" \
+ " const teeState = {\n" \
+ " closedOrErrored: false,\n" \
+ " canceled1: false,\n" \
+ " canceled2: false,\n" \
+ " reason1: @undefined,\n" \
+ " reason2: @undefined,\n" \
+ " };\n" \
+ "\n" \
+ " teeState.cancelPromiseCapability = @newPromiseCapability(@Promise);\n" \
+ "\n" \
+ " const pullFunction = @readableStreamTeePullFunction(teeState, reader, shouldClone);\n" \
+ "\n" \
+ " const branch1Source = { };\n" \
+ " @putByIdDirectPrivate(branch1Source, \"pull\", pullFunction);\n" \
+ " @putByIdDirectPrivate(branch1Source, \"cancel\", @readableStreamTeeBranch1CancelFunction(teeState, stream));\n" \
+ "\n" \
+ " const branch2Source = { };\n" \
+ " @putByIdDirectPrivate(branch2Source, \"pull\", pullFunction);\n" \
+ " @putByIdDirectPrivate(branch2Source, \"cancel\", @readableStreamTeeBranch2CancelFunction(teeState, stream));\n" \
+ "\n" \
+ " const branch1 = new @ReadableStream(branch1Source);\n" \
+ " const branch2 = new @ReadableStream(branch2Source);\n" \
+ "\n" \
+ " @getByIdDirectPrivate(reader, \"closedPromiseCapability\").@promise.@then(@undefined, function(e) {\n" \
+ " if (teeState.closedOrErrored)\n" \
+ " return;\n" \
+ " @readableStreamDefaultControllerError(branch1.@readableStreamController, e);\n" \
+ " @readableStreamDefaultControllerError(branch2.@readableStreamController, e);\n" \
+ " teeState.closedOrErrored = true;\n" \
+ " if (!teeState.canceled1 || !teeState.canceled2)\n" \
+ " teeState.cancelPromiseCapability.@resolve.@call();\n" \
+ " });\n" \
+ "\n" \
+ " //\n" \
+ " teeState.branch1 = branch1;\n" \
+ " teeState.branch2 = branch2;\n" \
+ "\n" \
+ " return [branch1, branch2];\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableStreamInternalsReadableStreamTeePullFunctionCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableStreamInternalsReadableStreamTeePullFunctionCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableStreamInternalsReadableStreamTeePullFunctionCodeLength = 1275;
+static const JSC::Intrinsic s_readableStreamInternalsReadableStreamTeePullFunctionCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableStreamInternalsReadableStreamTeePullFunctionCode =
+ "(function (teeState, reader, shouldClone)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " return function() {\n" \
+ " @Promise.prototype.@then.@call(@readableStreamDefaultReaderRead(reader), function(result) {\n" \
+ " @assert(@isObject(result));\n" \
+ " @assert(typeof result.done === \"boolean\");\n" \
+ " if (result.done && !teeState.closedOrErrored) {\n" \
+ " if (!teeState.canceled1)\n" \
+ " @readableStreamDefaultControllerClose(teeState.branch1.@readableStreamController);\n" \
+ " if (!teeState.canceled2)\n" \
+ " @readableStreamDefaultControllerClose(teeState.branch2.@readableStreamController);\n" \
+ " teeState.closedOrErrored = true;\n" \
+ " if (!teeState.canceled1 || !teeState.canceled2)\n" \
+ " teeState.cancelPromiseCapability.@resolve.@call();\n" \
+ " }\n" \
+ " if (teeState.closedOrErrored)\n" \
+ " return;\n" \
+ " if (!teeState.canceled1)\n" \
+ " @readableStreamDefaultControllerEnqueue(teeState.branch1.@readableStreamController, result.value);\n" \
+ " if (!teeState.canceled2)\n" \
+ " @readableStreamDefaultControllerEnqueue(teeState.branch2.@readableStreamController, shouldClone ? @structuredCloneForStream(result.value) : result.value);\n" \
+ " });\n" \
+ " }\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableStreamInternalsReadableStreamTeeBranch1CancelFunctionCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableStreamInternalsReadableStreamTeeBranch1CancelFunctionCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableStreamInternalsReadableStreamTeeBranch1CancelFunctionCodeLength = 456;
+static const JSC::Intrinsic s_readableStreamInternalsReadableStreamTeeBranch1CancelFunctionCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableStreamInternalsReadableStreamTeeBranch1CancelFunctionCode =
+ "(function (teeState, stream)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " return function(r) {\n" \
+ " teeState.canceled1 = true;\n" \
+ " teeState.reason1 = r;\n" \
+ " if (teeState.canceled2) {\n" \
+ " @readableStreamCancel(stream, [teeState.reason1, teeState.reason2]).@then(\n" \
+ " teeState.cancelPromiseCapability.@resolve,\n" \
+ " teeState.cancelPromiseCapability.@reject);\n" \
+ " }\n" \
+ " return teeState.cancelPromiseCapability.@promise;\n" \
+ " }\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableStreamInternalsReadableStreamTeeBranch2CancelFunctionCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableStreamInternalsReadableStreamTeeBranch2CancelFunctionCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableStreamInternalsReadableStreamTeeBranch2CancelFunctionCodeLength = 456;
+static const JSC::Intrinsic s_readableStreamInternalsReadableStreamTeeBranch2CancelFunctionCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableStreamInternalsReadableStreamTeeBranch2CancelFunctionCode =
+ "(function (teeState, stream)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " return function(r) {\n" \
+ " teeState.canceled2 = true;\n" \
+ " teeState.reason2 = r;\n" \
+ " if (teeState.canceled1) {\n" \
+ " @readableStreamCancel(stream, [teeState.reason1, teeState.reason2]).@then(\n" \
+ " teeState.cancelPromiseCapability.@resolve,\n" \
+ " teeState.cancelPromiseCapability.@reject);\n" \
+ " }\n" \
+ " return teeState.cancelPromiseCapability.@promise;\n" \
+ " }\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableStreamInternalsIsReadableStreamCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableStreamInternalsIsReadableStreamCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableStreamInternalsIsReadableStreamCodeLength = 170;
+static const JSC::Intrinsic s_readableStreamInternalsIsReadableStreamCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableStreamInternalsIsReadableStreamCode =
+ "(function (stream)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " //\n" \
+ " //\n" \
+ " //\n" \
+ " return @isObject(stream) && @getByIdDirectPrivate(stream, \"readableStreamController\") !== @undefined;\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableStreamInternalsIsReadableStreamDefaultReaderCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableStreamInternalsIsReadableStreamDefaultReaderCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableStreamInternalsIsReadableStreamDefaultReaderCodeLength = 145;
+static const JSC::Intrinsic s_readableStreamInternalsIsReadableStreamDefaultReaderCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableStreamInternalsIsReadableStreamDefaultReaderCode =
+ "(function (reader)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " //\n" \
+ " //\n" \
+ " //\n" \
+ " return @isObject(reader) && !!@getByIdDirectPrivate(reader, \"readRequests\");\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableStreamInternalsIsReadableStreamDefaultControllerCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableStreamInternalsIsReadableStreamDefaultControllerCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableStreamInternalsIsReadableStreamDefaultControllerCodeLength = 168;
+static const JSC::Intrinsic s_readableStreamInternalsIsReadableStreamDefaultControllerCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableStreamInternalsIsReadableStreamDefaultControllerCode =
+ "(function (controller)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " //\n" \
+ " //\n" \
+ " //\n" \
+ " //\n" \
+ " return @isObject(controller) && !!@getByIdDirectPrivate(controller, \"underlyingSource\");\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableStreamInternalsAssignDirectStreamCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableStreamInternalsAssignDirectStreamCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableStreamInternalsAssignDirectStreamCodeLength = 60;
+static const JSC::Intrinsic s_readableStreamInternalsAssignDirectStreamCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableStreamInternalsAssignDirectStreamCode =
+ "(function () {\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " var stream = this;\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableStreamInternalsHandleDirectStreamErrorCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableStreamInternalsHandleDirectStreamErrorCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableStreamInternalsHandleDirectStreamErrorCodeLength = 840;
+static const JSC::Intrinsic s_readableStreamInternalsHandleDirectStreamErrorCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableStreamInternalsHandleDirectStreamErrorCode =
+ "(function (e) {\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " var controller = this;\n" \
+ " var sink = controller.@sink;\n" \
+ " if (sink) {\n" \
+ " @putByIdDirectPrivate(controller, \"sink\", @undefined);\n" \
+ " try {\n" \
+ " sink.close(e);\n" \
+ " } catch (f) {}\n" \
+ " }\n" \
+ "\n" \
+ " this.error = this.drain = this.write = this.close = this.end = @onReadableStreamDirectControllerClosed;\n" \
+ "\n" \
+ " if (typeof this.@underlyingSource.close === 'function') {\n" \
+ " try {\n" \
+ " this.@underlyingSource.close.@call(this.@underlyingSource, e);\n" \
+ " } catch (e) {\n" \
+ " }\n" \
+ " }\n" \
+ "\n" \
+ " try {\n" \
+ " var pend = controller._pendingRead;\n" \
+ " if (pend) {\n" \
+ " controller._pendingRead = @undefined;\n" \
+ " @rejectPromise(pend, e);\n" \
+ " }\n" \
+ " } catch (f) {}\n" \
+ " var stream = controller.@controlledReadableStream;\n" \
+ " if (stream) @readableStreamError(stream, e);\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableStreamInternalsHandleDirectStreamErrorRejectCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableStreamInternalsHandleDirectStreamErrorRejectCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableStreamInternalsHandleDirectStreamErrorRejectCodeLength = 96;
+static const JSC::Intrinsic s_readableStreamInternalsHandleDirectStreamErrorRejectCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableStreamInternalsHandleDirectStreamErrorRejectCode =
+ "(function (e) {\n" \
+ " @handleDirectStreamError.@call(this, e);\n" \
+ " return @Promise.@reject(e);\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableStreamInternalsOnPullDirectStreamCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableStreamInternalsOnPullDirectStreamCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableStreamInternalsOnPullDirectStreamCodeLength = 1701;
+static const JSC::Intrinsic s_readableStreamInternalsOnPullDirectStreamCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableStreamInternalsOnPullDirectStreamCode =
+ "(function (controller)\n" \
+ "{\n" \
+ " \n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " var stream = controller.@controlledReadableStream;\n" \
+ " if (!stream || @getByIdDirectPrivate(stream, \"state\") !== @streamReadable)\n" \
+ " return;\n" \
+ "\n" \
+ " //\n" \
+ " //\n" \
+ " //\n" \
+ " if (controller._deferClose === -1) {\n" \
+ " return;\n" \
+ " }\n" \
+ "\n" \
+ " \n" \
+ " controller._deferClose = -1;\n" \
+ " controller._deferDrain = -1;\n" \
+ " var deferClose;\n" \
+ " var deferDrain;\n" \
+ "\n" \
+ " //\n" \
+ " //\n" \
+ " //\n" \
+ " //\n" \
+ " //\n" \
+ " //\n" \
+ " try {\n" \
+ " var result = controller.@underlyingSource.pull(\n" \
+ " controller,\n" \
+ " );\n" \
+ "\n" \
+ " if (result && @isPromise(result)) {\n" \
+ " if (controller._handleError === @undefined) {\n" \
+ " controller._handleError = @handleDirectStreamErrorReject.bind(controller);\n" \
+ " }\n" \
+ "\n" \
+ " @Promise.prototype.catch.@call(result, controller._handleError);\n" \
+ " }\n" \
+ " } catch(e) {\n" \
+ " return @handleDirectStreamErrorReject.@call(controller, e);\n" \
+ " } finally {\n" \
+ " deferClose = controller._deferClose;\n" \
+ " deferDrain = controller._deferDrain;\n" \
+ " controller._deferDrain = controller._deferClose = 0;\n" \
+ " }\n" \
+ " \n" \
+ " \n" \
+ " var promiseToReturn;\n" \
+ " \n" \
+ "\n" \
+ " if (controller._pendingRead === @undefined) {\n" \
+ " controller._pendingRead = promiseToReturn = @newPromise();\n" \
+ " } else {\n" \
+ " promiseToReturn = @readableStreamAddReadRequest(stream);\n" \
+ " }\n" \
+ "\n" \
+ "\n" \
+ " //\n" \
+ " //\n" \
+ " if (deferClose === 1) {\n" \
+ " var reason = controller._deferCloseReason;\n" \
+ " controller._deferCloseReason = @undefined;\n" \
+ " @onCloseDirectStream.@call(controller, reason);\n" \
+ " return promiseToReturn;\n" \
+ " }\n" \
+ "\n" \
+ " //\n" \
+ " if (deferDrain === 1) {\n" \
+ " @onDrainDirectStream.@call(controller);\n" \
+ " }\n" \
+ " \n" \
+ "\n" \
+ " return promiseToReturn;\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableStreamInternalsNoopDoneFunctionCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableStreamInternalsNoopDoneFunctionCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableStreamInternalsNoopDoneFunctionCodeLength = 81;
+static const JSC::Intrinsic s_readableStreamInternalsNoopDoneFunctionCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableStreamInternalsNoopDoneFunctionCode =
+ "(function () {\n" \
+ " return @Promise.@resolve({value: @undefined, done: true});\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableStreamInternalsOnReadableStreamDirectControllerClosedCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableStreamInternalsOnReadableStreamDirectControllerClosedCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableStreamInternalsOnReadableStreamDirectControllerClosedCodeLength = 111;
+static const JSC::Intrinsic s_readableStreamInternalsOnReadableStreamDirectControllerClosedCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableStreamInternalsOnReadableStreamDirectControllerClosedCode =
+ "(function (reason)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ " @throwTypeError(\"ReadableStreamDirectController is now closed\");\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableStreamInternalsOnCloseDirectStreamCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableStreamInternalsOnCloseDirectStreamCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableStreamInternalsOnCloseDirectStreamCodeLength = 2405;
+static const JSC::Intrinsic s_readableStreamInternalsOnCloseDirectStreamCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableStreamInternalsOnCloseDirectStreamCode =
+ "(function (reason)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ " var stream = this.@controlledReadableStream;\n" \
+ " if (!stream || @getByIdDirectPrivate(stream, \"state\") !== @streamReadable)\n" \
+ " return;\n" \
+ "\n" \
+ " if (this._deferClose !== 0) {\n" \
+ " this._deferClose = 1;\n" \
+ " this._deferCloseReason = reason;\n" \
+ " return;\n" \
+ " }\n" \
+ "\n" \
+ " @putByIdDirectPrivate(stream, \"state\", @streamClosing);\n" \
+ " if (typeof this.@underlyingSource.close === 'function') {\n" \
+ " try {\n" \
+ " this.@underlyingSource.close.@call(this.@underlyingSource, reason);\n" \
+ " } catch (e) {\n" \
+ " \n" \
+ " }\n" \
+ " }\n" \
+ "\n" \
+ " var drained;\n" \
+ " try {\n" \
+ " drained = this.@sink.end();\n" \
+ " @putByIdDirectPrivate(this, \"sink\", @undefined);\n" \
+ " } catch (e) {\n" \
+ " if (this._pendingRead) {\n" \
+ " var read = this._pendingRead;\n" \
+ " this._pendingRead = @undefined;\n" \
+ " @rejectPromise(read, e);\n" \
+ " }\n" \
+ " @readableStreamError(stream, e);\n" \
+ " return;\n" \
+ " }\n" \
+ "\n" \
+ " this.error = this.drain = this.write = this.close = this.end = @onReadableStreamDirectControllerClosed;\n" \
+ "\n" \
+ " var reader = @getByIdDirectPrivate(stream, \"reader\");\n" \
+ "\n" \
+ " if (reader && @isReadableStreamDefaultReader(reader)) {\n" \
+ " var _pendingRead = this._pendingRead;\n" \
+ " if (_pendingRead && @isPromise(_pendingRead) && drained?.byteLength) {\n" \
+ " this._pendingRead = @undefined;\n" \
+ " @fulfillPromise(_pendingRead, {value: drained, done: false});\n" \
+ " @readableStreamClose(stream);\n" \
+ " return;\n" \
+ " }\n" \
+ " }\n" \
+ "\n" \
+ " if (drained?.byteLength) {\n" \
+ " var requests = @getByIdDirectPrivate(reader, \"readRequests\");\n" \
+ " if (requests?.isNotEmpty()) {\n" \
+ " @readableStreamFulfillReadRequest(stream, drained, false);\n" \
+ " @readableStreamClose(stream);\n" \
+ " return;\n" \
+ " }\n" \
+ " \n" \
+ " @putByIdDirectPrivate(stream, \"state\", @streamReadable);\n" \
+ " this.@pull = () => {\n" \
+ " var thisResult = @createFulfilledPromise({value: drained, done: false});\n" \
+ " drained = @undefined;\n" \
+ " @readableStreamClose(stream);\n" \
+ " stream = @undefined;\n" \
+ " return thisResult;\n" \
+ " };\n" \
+ " } else if (this._pendingRead) {\n" \
+ " var read = this._pendingRead;\n" \
+ " this._pendingRead = @undefined;\n" \
+ " @putByIdDirectPrivate(this, \"pull\", @noopDoneFunction);\n" \
+ " @fulfillPromise(read, {value: @undefined, done: true});\n" \
+ " }\n" \
+ "\n" \
+ " @readableStreamClose(stream);\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableStreamInternalsOnDrainDirectStreamCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableStreamInternalsOnDrainDirectStreamCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableStreamInternalsOnDrainDirectStreamCodeLength = 990;
+static const JSC::Intrinsic s_readableStreamInternalsOnDrainDirectStreamCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableStreamInternalsOnDrainDirectStreamCode =
+ "(function ()\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " var stream = this.@controlledReadableStream;\n" \
+ " var reader = @getByIdDirectPrivate(stream, \"reader\");\n" \
+ " if (!reader || !@isReadableStreamDefaultReader(reader)) {\n" \
+ " return;\n" \
+ " }\n" \
+ "\n" \
+ " var _pendingRead = this._pendingRead;\n" \
+ " this._pendingRead = @undefined;\n" \
+ " if (_pendingRead && @isPromise(_pendingRead)) {\n" \
+ " var drained = this.@sink.drain();\n" \
+ " if (drained?.byteLength) {\n" \
+ " this._pendingRead = @getByIdDirectPrivate(stream, \"readRequests\")?.shift();\n" \
+ " @fulfillPromise(_pendingRead, {value: drained, done: false});\n" \
+ " } else {\n" \
+ " this._pendingRead = _pendingRead;\n" \
+ " }\n" \
+ " } else if (@getByIdDirectPrivate(stream, \"readRequests\")?.isNotEmpty()) {\n" \
+ " var drained = this.@sink.drain();\n" \
+ " if (drained?.byteLength) {\n" \
+ " @readableStreamFulfillReadRequest(stream, drained, false);\n" \
+ " }\n" \
+ " } else if (this._deferDrain === -1) {\n" \
+ " this._deferDrain = 1;\n" \
+ " }\n" \
+ " \n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableStreamInternalsInitializeArrayBufferStreamCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableStreamInternalsInitializeArrayBufferStreamCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableStreamInternalsInitializeArrayBufferStreamCodeLength = 930;
+static const JSC::Intrinsic s_readableStreamInternalsInitializeArrayBufferStreamCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableStreamInternalsInitializeArrayBufferStreamCode =
+ "(function (underlyingSource, highWaterMark)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " //\n" \
+ " //\n" \
+ " //\n" \
+ " \n" \
+ " var opts = highWaterMark ? {highWaterMark, stream: true, asUint8Array: true} : {stream: true, asUint8Array: true};\n" \
+ " var sink = new globalThis.Bun.ArrayBufferSink();\n" \
+ " sink.start(opts);\n" \
+ "\n" \
+ " var controller = {\n" \
+ " @underlyingSource: underlyingSource,\n" \
+ " @pull: @onPullDirectStream,\n" \
+ " @controlledReadableStream: this,\n" \
+ " @sink: sink,\n" \
+ " close: @onCloseDirectStream,\n" \
+ " write: sink.write.bind(sink),\n" \
+ " error: @handleDirectStreamError,\n" \
+ " end: @onCloseDirectStream,\n" \
+ " @close: @onCloseDirectStream,\n" \
+ " drain: @onDrainDirectStream,\n" \
+ " _pendingRead: @undefined,\n" \
+ " _deferClose: 0,\n" \
+ " _deferDrain: 0,\n" \
+ " _deferCloseReason: @undefined,\n" \
+ " _handleError: @undefined,\n" \
+ " };\n" \
+ " \n" \
+ " \n" \
+ " @putByIdDirectPrivate(this, \"readableStreamController\", controller);\n" \
+ " \n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableStreamInternalsReadableStreamErrorCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableStreamInternalsReadableStreamErrorCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableStreamInternalsReadableStreamErrorCodeLength = 1266;
+static const JSC::Intrinsic s_readableStreamInternalsReadableStreamErrorCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableStreamInternalsReadableStreamErrorCode =
+ "(function (stream, error)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " @assert(@isReadableStream(stream));\n" \
+ " @assert(@getByIdDirectPrivate(stream, \"state\") === @streamReadable);\n" \
+ " @putByIdDirectPrivate(stream, \"state\", @streamErrored);\n" \
+ " @putByIdDirectPrivate(stream, \"storedError\", error);\n" \
+ "\n" \
+ " const reader = @getByIdDirectPrivate(stream, \"reader\");\n" \
+ "\n" \
+ " if (!reader)\n" \
+ " return;\n" \
+ "\n" \
+ " if (@isReadableStreamDefaultReader(reader)) {\n" \
+ " const requests = @getByIdDirectPrivate(reader, \"readRequests\");\n" \
+ " @putByIdDirectPrivate(reader, \"readRequests\", @createFIFO());\n" \
+ " for (var request = requests.shift(); request; request = requests.shift())\n" \
+ " @rejectPromise(request, error);\n" \
+ " } else {\n" \
+ " @assert(@isReadableStreamBYOBReader(reader));\n" \
+ " const requests = @getByIdDirectPrivate(reader, \"readIntoRequests\");\n" \
+ " @putByIdDirectPrivate(reader, \"readIntoRequests\", @createFIFO());\n" \
+ " for (var request = requests.shift(); request; request = requests.shift())\n" \
+ " @rejectPromise(request, error);\n" \
+ " }\n" \
+ "\n" \
+ " @getByIdDirectPrivate(reader, \"closedPromiseCapability\").@reject.@call(@undefined, error);\n" \
+ " const promise = @getByIdDirectPrivate(reader, \"closedPromiseCapability\").@promise;\n" \
+ " @markPromiseAsHandled(promise);\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableStreamInternalsReadableStreamDefaultControllerShouldCallPullCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableStreamInternalsReadableStreamDefaultControllerShouldCallPullCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableStreamInternalsReadableStreamDefaultControllerShouldCallPullCodeLength = 690;
+static const JSC::Intrinsic s_readableStreamInternalsReadableStreamDefaultControllerShouldCallPullCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableStreamInternalsReadableStreamDefaultControllerShouldCallPullCode =
+ "(function (controller)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " const stream = @getByIdDirectPrivate(controller, \"controlledReadableStream\");\n" \
+ " \n" \
+ " if (!@readableStreamDefaultControllerCanCloseOrEnqueue(controller))\n" \
+ " return false;\n" \
+ " if (!(@getByIdDirectPrivate(controller, \"started\") === 1))\n" \
+ " return false;\n" \
+ " if ((!@isReadableStreamLocked(stream) || !@getByIdDirectPrivate(@getByIdDirectPrivate(stream, \"reader\"), \"readRequests\")?.isNotEmpty()) && @readableStreamDefaultControllerGetDesiredSize(controller) <= 0)\n" \
+ " return false;\n" \
+ " const desiredSize = @readableStreamDefaultControllerGetDesiredSize(controller);\n" \
+ " @assert(desiredSize !== null);\n" \
+ " return desiredSize > 0;\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableStreamInternalsReadableStreamDefaultControllerCallPullIfNeededCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableStreamInternalsReadableStreamDefaultControllerCallPullIfNeededCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableStreamInternalsReadableStreamDefaultControllerCallPullIfNeededCodeLength = 1272;
+static const JSC::Intrinsic s_readableStreamInternalsReadableStreamDefaultControllerCallPullIfNeededCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableStreamInternalsReadableStreamDefaultControllerCallPullIfNeededCode =
+ "(function (controller)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " //\n" \
+ " const stream = @getByIdDirectPrivate(controller, \"controlledReadableStream\");\n" \
+ "\n" \
+ " if (!@readableStreamDefaultControllerCanCloseOrEnqueue(controller))\n" \
+ " return;\n" \
+ " if (!(@getByIdDirectPrivate(controller, \"started\") === 1))\n" \
+ " return;\n" \
+ " if ((!@isReadableStreamLocked(stream) || !@getByIdDirectPrivate(@getByIdDirectPrivate(stream, \"reader\"), \"readRequests\")?.isNotEmpty()) && @readableStreamDefaultControllerGetDesiredSize(controller) <= 0)\n" \
+ " return;\n" \
+ "\n" \
+ " if (@getByIdDirectPrivate(controller, \"pulling\")) {\n" \
+ " @putByIdDirectPrivate(controller, \"pullAgain\", true);\n" \
+ " return;\n" \
+ " }\n" \
+ "\n" \
+ " \n" \
+ " @assert(!@getByIdDirectPrivate(controller, \"pullAgain\"));\n" \
+ " @putByIdDirectPrivate(controller, \"pulling\", true);\n" \
+ "\n" \
+ " @getByIdDirectPrivate(controller, \"pullAlgorithm\").@call(@undefined).@then(function() {\n" \
+ " @putByIdDirectPrivate(controller, \"pulling\", false);\n" \
+ " if (@getByIdDirectPrivate(controller, \"pullAgain\")) {\n" \
+ " @putByIdDirectPrivate(controller, \"pullAgain\", false);\n" \
+ " \n" \
+ " @readableStreamDefaultControllerCallPullIfNeeded(controller);\n" \
+ " }\n" \
+ " }, function(error) {\n" \
+ " @readableStreamDefaultControllerError(controller, error);\n" \
+ " });\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableStreamInternalsIsReadableStreamLockedCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableStreamInternalsIsReadableStreamLockedCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableStreamInternalsIsReadableStreamLockedCodeLength = 136;
+static const JSC::Intrinsic s_readableStreamInternalsIsReadableStreamLockedCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableStreamInternalsIsReadableStreamLockedCode =
+ "(function (stream)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " @assert(@isReadableStream(stream));\n" \
+ " return !!@getByIdDirectPrivate(stream, \"reader\");\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableStreamInternalsReadableStreamDefaultControllerGetDesiredSizeCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableStreamInternalsReadableStreamDefaultControllerGetDesiredSizeCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableStreamInternalsReadableStreamDefaultControllerGetDesiredSizeCodeLength = 416;
+static const JSC::Intrinsic s_readableStreamInternalsReadableStreamDefaultControllerGetDesiredSizeCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableStreamInternalsReadableStreamDefaultControllerGetDesiredSizeCode =
+ "(function (controller)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " const stream = @getByIdDirectPrivate(controller, \"controlledReadableStream\");\n" \
+ " const state = @getByIdDirectPrivate(stream, \"state\");\n" \
+ "\n" \
+ " if (state === @streamErrored)\n" \
+ " return null;\n" \
+ " if (state === @streamClosed)\n" \
+ " return 0;\n" \
+ "\n" \
+ " return @getByIdDirectPrivate(controller, \"strategy\").highWaterMark - @getByIdDirectPrivate(controller, \"queue\").size;\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableStreamInternalsReadableStreamReaderGenericCancelCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableStreamInternalsReadableStreamReaderGenericCancelCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableStreamInternalsReadableStreamReaderGenericCancelCodeLength = 197;
+static const JSC::Intrinsic s_readableStreamInternalsReadableStreamReaderGenericCancelCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableStreamInternalsReadableStreamReaderGenericCancelCode =
+ "(function (reader, reason)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " const stream = @getByIdDirectPrivate(reader, \"ownerReadableStream\");\n" \
+ " @assert(!!stream);\n" \
+ " return @readableStreamCancel(stream, reason);\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableStreamInternalsReadableStreamCancelCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableStreamInternalsReadableStreamCancelCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableStreamInternalsReadableStreamCancelCodeLength = 534;
+static const JSC::Intrinsic s_readableStreamInternalsReadableStreamCancelCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableStreamInternalsReadableStreamCancelCode =
+ "(function (stream, reason)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " @putByIdDirectPrivate(stream, \"disturbed\", true);\n" \
+ " const state = @getByIdDirectPrivate(stream, \"state\");\n" \
+ " if (state === @streamClosed)\n" \
+ " return @Promise.@resolve();\n" \
+ " if (state === @streamErrored)\n" \
+ " return @Promise.@reject(@getByIdDirectPrivate(stream, \"storedError\"));\n" \
+ " @readableStreamClose(stream);\n" \
+ "\n" \
+ " var controller = @getByIdDirectPrivate(stream, \"readableStreamController\");\n" \
+ " return controller.@cancel(controller, reason).@then(function() { });\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableStreamInternalsReadableStreamDefaultControllerCancelCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableStreamInternalsReadableStreamDefaultControllerCancelCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableStreamInternalsReadableStreamDefaultControllerCancelCodeLength = 207;
+static const JSC::Intrinsic s_readableStreamInternalsReadableStreamDefaultControllerCancelCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableStreamInternalsReadableStreamDefaultControllerCancelCode =
+ "(function (controller, reason)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " @putByIdDirectPrivate(controller, \"queue\", @newQueue());\n" \
+ " return @getByIdDirectPrivate(controller, \"cancelAlgorithm\").@call(@undefined, reason);\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableStreamInternalsReadableStreamDefaultControllerPullCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableStreamInternalsReadableStreamDefaultControllerPullCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableStreamInternalsReadableStreamDefaultControllerPullCodeLength = 758;
+static const JSC::Intrinsic s_readableStreamInternalsReadableStreamDefaultControllerPullCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableStreamInternalsReadableStreamDefaultControllerPullCode =
+ "(function (controller)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " var queue = @getByIdDirectPrivate(controller, \"queue\");\n" \
+ " if (queue.content.isNotEmpty()) {\n" \
+ " const chunk = @dequeueValue(queue);\n" \
+ " if (@getByIdDirectPrivate(controller, \"closeRequested\") && queue.content.isEmpty())\n" \
+ " @readableStreamClose(@getByIdDirectPrivate(controller, \"controlledReadableStream\"));\n" \
+ " else\n" \
+ " @readableStreamDefaultControllerCallPullIfNeeded(controller);\n" \
+ "\n" \
+ " return @createFulfilledPromise({ value: chunk, done: false });\n" \
+ " }\n" \
+ " const pendingPromise = @readableStreamAddReadRequest(@getByIdDirectPrivate(controller, \"controlledReadableStream\"));\n" \
+ " @readableStreamDefaultControllerCallPullIfNeeded(controller);\n" \
+ " return pendingPromise;\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableStreamInternalsReadableStreamDefaultControllerCloseCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableStreamInternalsReadableStreamDefaultControllerCloseCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableStreamInternalsReadableStreamDefaultControllerCloseCodeLength = 351;
+static const JSC::Intrinsic s_readableStreamInternalsReadableStreamDefaultControllerCloseCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableStreamInternalsReadableStreamDefaultControllerCloseCode =
+ "(function (controller)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " @assert(@readableStreamDefaultControllerCanCloseOrEnqueue(controller));\n" \
+ " @putByIdDirectPrivate(controller, \"closeRequested\", true);\n" \
+ " if (@getByIdDirectPrivate(controller, \"queue\")?.content?.isEmpty())\n" \
+ " @readableStreamClose(@getByIdDirectPrivate(controller, \"controlledReadableStream\"));\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableStreamInternalsReadableStreamCloseCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableStreamInternalsReadableStreamCloseCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableStreamInternalsReadableStreamCloseCodeLength = 875;
+static const JSC::Intrinsic s_readableStreamInternalsReadableStreamCloseCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableStreamInternalsReadableStreamCloseCode =
+ "(function (stream)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " @assert(@getByIdDirectPrivate(stream, \"state\") === @streamReadable);\n" \
+ " @putByIdDirectPrivate(stream, \"state\", @streamClosed);\n" \
+ " if (!@getByIdDirectPrivate(stream, \"reader\"))\n" \
+ " return;\n" \
+ "\n" \
+ " if (@isReadableStreamDefaultReader(@getByIdDirectPrivate(stream, \"reader\"))) {\n" \
+ " const requests = @getByIdDirectPrivate(@getByIdDirectPrivate(stream, \"reader\"), \"readRequests\");\n" \
+ " if (requests.isNotEmpty()) {\n" \
+ " @putByIdDirectPrivate(@getByIdDirectPrivate(stream, \"reader\"), \"readRequests\", @createFIFO());\n" \
+ " \n" \
+ " for (var request = requests.shift(); request; request = requests.shift())\n" \
+ " @fulfillPromise(request, { value: @undefined, done: true });\n" \
+ " }\n" \
+ " }\n" \
+ "\n" \
+ " @getByIdDirectPrivate(@getByIdDirectPrivate(stream, \"reader\"), \"closedPromiseCapability\").@resolve.@call();\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableStreamInternalsReadableStreamFulfillReadRequestCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableStreamInternalsReadableStreamFulfillReadRequestCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableStreamInternalsReadableStreamFulfillReadRequestCodeLength = 231;
+static const JSC::Intrinsic s_readableStreamInternalsReadableStreamFulfillReadRequestCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableStreamInternalsReadableStreamFulfillReadRequestCode =
+ "(function (stream, chunk, done)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ " const readRequest = @getByIdDirectPrivate(@getByIdDirectPrivate(stream, \"reader\"), \"readRequests\").shift();\n" \
+ " @fulfillPromise(readRequest, { value: chunk, done: done });\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableStreamInternalsReadableStreamDefaultControllerEnqueueCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableStreamInternalsReadableStreamDefaultControllerEnqueueCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableStreamInternalsReadableStreamDefaultControllerEnqueueCodeLength = 993;
+static const JSC::Intrinsic s_readableStreamInternalsReadableStreamDefaultControllerEnqueueCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableStreamInternalsReadableStreamDefaultControllerEnqueueCode =
+ "(function (controller, chunk)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " const stream = @getByIdDirectPrivate(controller, \"controlledReadableStream\");\n" \
+ " //\n" \
+ " @assert(@readableStreamDefaultControllerCanCloseOrEnqueue(controller));\n" \
+ "\n" \
+ " if (@isReadableStreamLocked(stream) && @getByIdDirectPrivate(@getByIdDirectPrivate(stream, \"reader\"), \"readRequests\")?.isNotEmpty()) {\n" \
+ " @readableStreamFulfillReadRequest(stream, chunk, false);\n" \
+ " @readableStreamDefaultControllerCallPullIfNeeded(controller);\n" \
+ " return;\n" \
+ " }\n" \
+ "\n" \
+ " try {\n" \
+ " let chunkSize = 1;\n" \
+ " if (@getByIdDirectPrivate(controller, \"strategy\").size !== @undefined)\n" \
+ " chunkSize = @getByIdDirectPrivate(controller, \"strategy\").size(chunk);\n" \
+ " @enqueueValueWithSize(@getByIdDirectPrivate(controller, \"queue\"), chunk, chunkSize);\n" \
+ " }\n" \
+ " catch(error) {\n" \
+ " @readableStreamDefaultControllerError(controller, error);\n" \
+ " throw error;\n" \
+ " }\n" \
+ " @readableStreamDefaultControllerCallPullIfNeeded(controller);\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableStreamInternalsReadableStreamDefaultReaderReadCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableStreamInternalsReadableStreamDefaultReaderReadCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableStreamInternalsReadableStreamDefaultReaderReadCodeLength = 649;
+static const JSC::Intrinsic s_readableStreamInternalsReadableStreamDefaultReaderReadCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableStreamInternalsReadableStreamDefaultReaderReadCode =
+ "(function (reader)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " const stream = @getByIdDirectPrivate(reader, \"ownerReadableStream\");\n" \
+ " @assert(!!stream);\n" \
+ " const state = @getByIdDirectPrivate(stream, \"state\");\n" \
+ "\n" \
+ " @putByIdDirectPrivate(stream, \"disturbed\", true);\n" \
+ " if (state === @streamClosed)\n" \
+ " return @createFulfilledPromise({ value: @undefined, done: true });\n" \
+ " if (state === @streamErrored)\n" \
+ " return @Promise.@reject(@getByIdDirectPrivate(stream, \"storedError\"));\n" \
+ " @assert(state === @streamReadable);\n" \
+ "\n" \
+ " return @getByIdDirectPrivate(stream, \"readableStreamController\").@pull(@getByIdDirectPrivate(stream, \"readableStreamController\"));\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableStreamInternalsReadableStreamAddReadRequestCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableStreamInternalsReadableStreamAddReadRequestCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableStreamInternalsReadableStreamAddReadRequestCodeLength = 373;
+static const JSC::Intrinsic s_readableStreamInternalsReadableStreamAddReadRequestCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableStreamInternalsReadableStreamAddReadRequestCode =
+ "(function (stream)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " @assert(@isReadableStreamDefaultReader(@getByIdDirectPrivate(stream, \"reader\")));\n" \
+ " @assert(@getByIdDirectPrivate(stream, \"state\") == @streamReadable);\n" \
+ "\n" \
+ " const readRequest = @newPromise();\n" \
+ " \n" \
+ " @getByIdDirectPrivate(@getByIdDirectPrivate(stream, \"reader\"), \"readRequests\").push(readRequest);\n" \
+ "\n" \
+ " return readRequest;\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableStreamInternalsIsReadableStreamDisturbedCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableStreamInternalsIsReadableStreamDisturbedCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableStreamInternalsIsReadableStreamDisturbedCodeLength = 138;
+static const JSC::Intrinsic s_readableStreamInternalsIsReadableStreamDisturbedCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableStreamInternalsIsReadableStreamDisturbedCode =
+ "(function (stream)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " @assert(@isReadableStream(stream));\n" \
+ " return @getByIdDirectPrivate(stream, \"disturbed\");\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableStreamInternalsReadableStreamReaderGenericReleaseCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableStreamInternalsReadableStreamReaderGenericReleaseCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableStreamInternalsReadableStreamReaderGenericReleaseCodeLength = 968;
+static const JSC::Intrinsic s_readableStreamInternalsReadableStreamReaderGenericReleaseCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableStreamInternalsReadableStreamReaderGenericReleaseCode =
+ "(function (reader)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " @assert(!!@getByIdDirectPrivate(reader, \"ownerReadableStream\"));\n" \
+ " @assert(@getByIdDirectPrivate(@getByIdDirectPrivate(reader, \"ownerReadableStream\"), \"reader\") === reader);\n" \
+ "\n" \
+ " if (@getByIdDirectPrivate(@getByIdDirectPrivate(reader, \"ownerReadableStream\"), \"state\") === @streamReadable)\n" \
+ " @getByIdDirectPrivate(reader, \"closedPromiseCapability\").@reject.@call(@undefined, @makeTypeError(\"releasing lock of reader whose stream is still in readable state\"));\n" \
+ " else\n" \
+ " @putByIdDirectPrivate(reader, \"closedPromiseCapability\", { @promise: @newHandledRejectedPromise(@makeTypeError(\"reader released lock\")) });\n" \
+ "\n" \
+ " const promise = @getByIdDirectPrivate(reader, \"closedPromiseCapability\").@promise;\n" \
+ " @markPromiseAsHandled(promise);\n" \
+ " @putByIdDirectPrivate(@getByIdDirectPrivate(reader, \"ownerReadableStream\"), \"reader\", @undefined);\n" \
+ " @putByIdDirectPrivate(reader, \"ownerReadableStream\", @undefined);\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableStreamInternalsReadableStreamDefaultControllerCanCloseOrEnqueueCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableStreamInternalsReadableStreamDefaultControllerCanCloseOrEnqueueCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableStreamInternalsReadableStreamDefaultControllerCanCloseOrEnqueueCodeLength = 229;
+static const JSC::Intrinsic s_readableStreamInternalsReadableStreamDefaultControllerCanCloseOrEnqueueCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableStreamInternalsReadableStreamDefaultControllerCanCloseOrEnqueueCode =
+ "(function (controller)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " return !@getByIdDirectPrivate(controller, \"closeRequested\") && @getByIdDirectPrivate(@getByIdDirectPrivate(controller, \"controlledReadableStream\"), \"state\") === @streamReadable;\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_readableStreamInternalsLazyLoadStreamCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_readableStreamInternalsLazyLoadStreamCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_readableStreamInternalsLazyLoadStreamCodeLength = 2853;
+static const JSC::Intrinsic s_readableStreamInternalsLazyLoadStreamCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_readableStreamInternalsLazyLoadStreamCode =
+ "(function (stream, autoAllocateChunkSize) {\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " var nativeType = @getByIdDirectPrivate(stream, \"bunNativeType\");\n" \
+ " var nativePtr = @getByIdDirectPrivate(stream, \"bunNativePtr\");\n" \
+ " var cached = @lazyStreamPrototypeMap;\n" \
+ " var Prototype = cached.@get(nativeType);\n" \
+ " if (Prototype === @undefined) {\n" \
+ " var [pull, start, cancel, setClose, deinit] = @lazyLoad(nativeType);\n" \
+ " var closer = [false];\n" \
+ " var handleResult;\n" \
+ " function handleNativeReadableStreamPromiseResult(val) {\n" \
+ " \"use strict\";\n" \
+ " var {c, v} = this;\n" \
+ " this.c = @undefined;\n" \
+ " this.v = @undefined;\n" \
+ " handleResult(val, c, v);\n" \
+ " }\n" \
+ " \n" \
+ " handleResult = function handleResult(result, controller, view) {\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " if (result && @isPromise(result)) {\n" \
+ " return result.then(handleNativeReadableStreamPromiseResult.bind({c: controller, v: view}), (err) => controller.error(err));\n" \
+ " } else if (result !== false) {\n" \
+ " if (view && view.byteLength === result) {\n" \
+ " controller.byobRequest.respondWithNewView(view);\n" \
+ " } else {\n" \
+ " controller.byobRequest.respond(result);\n" \
+ " }\n" \
+ " }\n" \
+ "\n" \
+ " if (closer[0] || result === false) {\n" \
+ " @enqueueJob(() => controller.close());\n" \
+ " closer[0] = false;\n" \
+ " }\n" \
+ " };\n" \
+ "\n" \
+ " Prototype = class NativeReadableStreamSource {\n" \
+ " constructor(tag, autoAllocateChunkSize) {\n" \
+ " this.pull = this.pull_.bind(tag);\n" \
+ " this.cancel = this.cancel_.bind(tag);\n" \
+ " this.autoAllocateChunkSize = autoAllocateChunkSize;\n" \
+ " }\n" \
+ "\n" \
+ " pull;\n" \
+ " cancel;\n" \
+ "\n" \
+ " type = \"bytes\";\n" \
+ " autoAllocateChunkSize = 0;\n" \
+ "\n" \
+ " static startSync = start;\n" \
+ " \n" \
+ " pull_(controller) {\n" \
+ " closer[0] = false;\n" \
+ " var result;\n" \
+ "\n" \
+ " const view = controller.byobRequest.view;\n" \
+ " try {\n" \
+ " result = pull(this, view, closer);\n" \
+ " } catch(err) {\n" \
+ " return controller.error(err);\n" \
+ " }\n" \
+ "\n" \
+ " return handleResult(result, controller, view);\n" \
+ " }\n" \
+ "\n" \
+ " cancel_(reason) {\n" \
+ " cancel(this, reason);\n" \
+ " }\n" \
+ " static deinit = deinit;\n" \
+ " static registry = new FinalizationRegistry(deinit);\n" \
+ " }\n" \
+ " cached.@set(nativeType, Prototype);\n" \
+ " }\n" \
+ "\n" \
+ " const chunkSize = Prototype.startSync(nativePtr, autoAllocateChunkSize);\n" \
+ "\n" \
+ " //\n" \
+ " if (chunkSize === 0) {\n" \
+ " @readableStreamClose(stream);\n" \
+ " return null;\n" \
+ " }\n" \
+ " var instance = new Prototype(nativePtr, chunkSize);\n" \
+ " Prototype.registry.register(instance, nativePtr);\n" \
+ " return instance;\n" \
+ "})\n" \
+;
+
+
+#define DEFINE_BUILTIN_GENERATOR(codeName, functionName, overriddenName, argumentCount) \
+JSC::FunctionExecutable* codeName##Generator(JSC::VM& vm) \
+{\
+ JSVMClientData* clientData = static_cast<JSVMClientData*>(vm.clientData); \
+ return clientData->builtinFunctions().readableStreamInternalsBuiltins().codeName##Executable()->link(vm, nullptr, clientData->builtinFunctions().readableStreamInternalsBuiltins().codeName##Source(), std::nullopt, s_##codeName##Intrinsic); \
+}
+WEBCORE_FOREACH_READABLESTREAMINTERNALS_BUILTIN_CODE(DEFINE_BUILTIN_GENERATOR)
+#undef DEFINE_BUILTIN_GENERATOR
+
+
+} // namespace WebCore
diff --git a/src/bun.js/builtins/cpp/ReadableStreamInternalsBuiltins.h b/src/bun.js/builtins/cpp/ReadableStreamInternalsBuiltins.h
new file mode 100644
index 000000000..a17ea08bb
--- /dev/null
+++ b/src/bun.js/builtins/cpp/ReadableStreamInternalsBuiltins.h
@@ -0,0 +1,580 @@
+/*
+ * Copyright (c) 2015 Igalia
+ * Copyright (c) 2015 Igalia S.L.
+ * Copyright (c) 2015 Igalia.
+ * Copyright (c) 2015, 2016 Canon Inc. All rights reserved.
+ * Copyright (c) 2015, 2016, 2017 Canon Inc.
+ * Copyright (c) 2016, 2020 Apple Inc. All rights reserved.
+ * Copyright (c) 2022 Codeblog Corp. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+// DO NOT EDIT THIS FILE. It is automatically generated from JavaScript files for
+// builtins by the script: Source/JavaScriptCore/Scripts/generate-js-builtins.py
+
+#pragma once
+
+#include <JavaScriptCore/BuiltinUtils.h>
+#include <JavaScriptCore/Identifier.h>
+#include <JavaScriptCore/JSFunction.h>
+#include <JavaScriptCore/UnlinkedFunctionExecutable.h>
+
+namespace JSC {
+class FunctionExecutable;
+}
+
+namespace WebCore {
+
+/* ReadableStreamInternals */
+extern const char* const s_readableStreamInternalsReadableStreamReaderGenericInitializeCode;
+extern const int s_readableStreamInternalsReadableStreamReaderGenericInitializeCodeLength;
+extern const JSC::ConstructAbility s_readableStreamInternalsReadableStreamReaderGenericInitializeCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableStreamInternalsReadableStreamReaderGenericInitializeCodeConstructorKind;
+extern const char* const s_readableStreamInternalsPrivateInitializeReadableStreamDefaultControllerCode;
+extern const int s_readableStreamInternalsPrivateInitializeReadableStreamDefaultControllerCodeLength;
+extern const JSC::ConstructAbility s_readableStreamInternalsPrivateInitializeReadableStreamDefaultControllerCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableStreamInternalsPrivateInitializeReadableStreamDefaultControllerCodeConstructorKind;
+extern const char* const s_readableStreamInternalsReadableStreamDefaultControllerErrorCode;
+extern const int s_readableStreamInternalsReadableStreamDefaultControllerErrorCodeLength;
+extern const JSC::ConstructAbility s_readableStreamInternalsReadableStreamDefaultControllerErrorCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableStreamInternalsReadableStreamDefaultControllerErrorCodeConstructorKind;
+extern const char* const s_readableStreamInternalsReadableStreamPipeToCode;
+extern const int s_readableStreamInternalsReadableStreamPipeToCodeLength;
+extern const JSC::ConstructAbility s_readableStreamInternalsReadableStreamPipeToCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableStreamInternalsReadableStreamPipeToCodeConstructorKind;
+extern const char* const s_readableStreamInternalsAcquireReadableStreamDefaultReaderCode;
+extern const int s_readableStreamInternalsAcquireReadableStreamDefaultReaderCodeLength;
+extern const JSC::ConstructAbility s_readableStreamInternalsAcquireReadableStreamDefaultReaderCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableStreamInternalsAcquireReadableStreamDefaultReaderCodeConstructorKind;
+extern const char* const s_readableStreamInternalsSetupReadableStreamDefaultControllerCode;
+extern const int s_readableStreamInternalsSetupReadableStreamDefaultControllerCodeLength;
+extern const JSC::ConstructAbility s_readableStreamInternalsSetupReadableStreamDefaultControllerCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableStreamInternalsSetupReadableStreamDefaultControllerCodeConstructorKind;
+extern const char* const s_readableStreamInternalsCreateReadableStreamControllerCode;
+extern const int s_readableStreamInternalsCreateReadableStreamControllerCodeLength;
+extern const JSC::ConstructAbility s_readableStreamInternalsCreateReadableStreamControllerCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableStreamInternalsCreateReadableStreamControllerCodeConstructorKind;
+extern const char* const s_readableStreamInternalsReadableStreamDefaultControllerStartCode;
+extern const int s_readableStreamInternalsReadableStreamDefaultControllerStartCodeLength;
+extern const JSC::ConstructAbility s_readableStreamInternalsReadableStreamDefaultControllerStartCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableStreamInternalsReadableStreamDefaultControllerStartCodeConstructorKind;
+extern const char* const s_readableStreamInternalsReadableStreamPipeToWritableStreamCode;
+extern const int s_readableStreamInternalsReadableStreamPipeToWritableStreamCodeLength;
+extern const JSC::ConstructAbility s_readableStreamInternalsReadableStreamPipeToWritableStreamCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableStreamInternalsReadableStreamPipeToWritableStreamCodeConstructorKind;
+extern const char* const s_readableStreamInternalsPipeToLoopCode;
+extern const int s_readableStreamInternalsPipeToLoopCodeLength;
+extern const JSC::ConstructAbility s_readableStreamInternalsPipeToLoopCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableStreamInternalsPipeToLoopCodeConstructorKind;
+extern const char* const s_readableStreamInternalsPipeToDoReadWriteCode;
+extern const int s_readableStreamInternalsPipeToDoReadWriteCodeLength;
+extern const JSC::ConstructAbility s_readableStreamInternalsPipeToDoReadWriteCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableStreamInternalsPipeToDoReadWriteCodeConstructorKind;
+extern const char* const s_readableStreamInternalsPipeToErrorsMustBePropagatedForwardCode;
+extern const int s_readableStreamInternalsPipeToErrorsMustBePropagatedForwardCodeLength;
+extern const JSC::ConstructAbility s_readableStreamInternalsPipeToErrorsMustBePropagatedForwardCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableStreamInternalsPipeToErrorsMustBePropagatedForwardCodeConstructorKind;
+extern const char* const s_readableStreamInternalsPipeToErrorsMustBePropagatedBackwardCode;
+extern const int s_readableStreamInternalsPipeToErrorsMustBePropagatedBackwardCodeLength;
+extern const JSC::ConstructAbility s_readableStreamInternalsPipeToErrorsMustBePropagatedBackwardCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableStreamInternalsPipeToErrorsMustBePropagatedBackwardCodeConstructorKind;
+extern const char* const s_readableStreamInternalsPipeToClosingMustBePropagatedForwardCode;
+extern const int s_readableStreamInternalsPipeToClosingMustBePropagatedForwardCodeLength;
+extern const JSC::ConstructAbility s_readableStreamInternalsPipeToClosingMustBePropagatedForwardCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableStreamInternalsPipeToClosingMustBePropagatedForwardCodeConstructorKind;
+extern const char* const s_readableStreamInternalsPipeToClosingMustBePropagatedBackwardCode;
+extern const int s_readableStreamInternalsPipeToClosingMustBePropagatedBackwardCodeLength;
+extern const JSC::ConstructAbility s_readableStreamInternalsPipeToClosingMustBePropagatedBackwardCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableStreamInternalsPipeToClosingMustBePropagatedBackwardCodeConstructorKind;
+extern const char* const s_readableStreamInternalsPipeToShutdownWithActionCode;
+extern const int s_readableStreamInternalsPipeToShutdownWithActionCodeLength;
+extern const JSC::ConstructAbility s_readableStreamInternalsPipeToShutdownWithActionCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableStreamInternalsPipeToShutdownWithActionCodeConstructorKind;
+extern const char* const s_readableStreamInternalsPipeToShutdownCode;
+extern const int s_readableStreamInternalsPipeToShutdownCodeLength;
+extern const JSC::ConstructAbility s_readableStreamInternalsPipeToShutdownCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableStreamInternalsPipeToShutdownCodeConstructorKind;
+extern const char* const s_readableStreamInternalsPipeToFinalizeCode;
+extern const int s_readableStreamInternalsPipeToFinalizeCodeLength;
+extern const JSC::ConstructAbility s_readableStreamInternalsPipeToFinalizeCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableStreamInternalsPipeToFinalizeCodeConstructorKind;
+extern const char* const s_readableStreamInternalsReadableStreamTeeCode;
+extern const int s_readableStreamInternalsReadableStreamTeeCodeLength;
+extern const JSC::ConstructAbility s_readableStreamInternalsReadableStreamTeeCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableStreamInternalsReadableStreamTeeCodeConstructorKind;
+extern const char* const s_readableStreamInternalsReadableStreamTeePullFunctionCode;
+extern const int s_readableStreamInternalsReadableStreamTeePullFunctionCodeLength;
+extern const JSC::ConstructAbility s_readableStreamInternalsReadableStreamTeePullFunctionCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableStreamInternalsReadableStreamTeePullFunctionCodeConstructorKind;
+extern const char* const s_readableStreamInternalsReadableStreamTeeBranch1CancelFunctionCode;
+extern const int s_readableStreamInternalsReadableStreamTeeBranch1CancelFunctionCodeLength;
+extern const JSC::ConstructAbility s_readableStreamInternalsReadableStreamTeeBranch1CancelFunctionCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableStreamInternalsReadableStreamTeeBranch1CancelFunctionCodeConstructorKind;
+extern const char* const s_readableStreamInternalsReadableStreamTeeBranch2CancelFunctionCode;
+extern const int s_readableStreamInternalsReadableStreamTeeBranch2CancelFunctionCodeLength;
+extern const JSC::ConstructAbility s_readableStreamInternalsReadableStreamTeeBranch2CancelFunctionCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableStreamInternalsReadableStreamTeeBranch2CancelFunctionCodeConstructorKind;
+extern const char* const s_readableStreamInternalsIsReadableStreamCode;
+extern const int s_readableStreamInternalsIsReadableStreamCodeLength;
+extern const JSC::ConstructAbility s_readableStreamInternalsIsReadableStreamCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableStreamInternalsIsReadableStreamCodeConstructorKind;
+extern const char* const s_readableStreamInternalsIsReadableStreamDefaultReaderCode;
+extern const int s_readableStreamInternalsIsReadableStreamDefaultReaderCodeLength;
+extern const JSC::ConstructAbility s_readableStreamInternalsIsReadableStreamDefaultReaderCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableStreamInternalsIsReadableStreamDefaultReaderCodeConstructorKind;
+extern const char* const s_readableStreamInternalsIsReadableStreamDefaultControllerCode;
+extern const int s_readableStreamInternalsIsReadableStreamDefaultControllerCodeLength;
+extern const JSC::ConstructAbility s_readableStreamInternalsIsReadableStreamDefaultControllerCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableStreamInternalsIsReadableStreamDefaultControllerCodeConstructorKind;
+extern const char* const s_readableStreamInternalsAssignDirectStreamCode;
+extern const int s_readableStreamInternalsAssignDirectStreamCodeLength;
+extern const JSC::ConstructAbility s_readableStreamInternalsAssignDirectStreamCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableStreamInternalsAssignDirectStreamCodeConstructorKind;
+extern const char* const s_readableStreamInternalsHandleDirectStreamErrorCode;
+extern const int s_readableStreamInternalsHandleDirectStreamErrorCodeLength;
+extern const JSC::ConstructAbility s_readableStreamInternalsHandleDirectStreamErrorCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableStreamInternalsHandleDirectStreamErrorCodeConstructorKind;
+extern const char* const s_readableStreamInternalsHandleDirectStreamErrorRejectCode;
+extern const int s_readableStreamInternalsHandleDirectStreamErrorRejectCodeLength;
+extern const JSC::ConstructAbility s_readableStreamInternalsHandleDirectStreamErrorRejectCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableStreamInternalsHandleDirectStreamErrorRejectCodeConstructorKind;
+extern const char* const s_readableStreamInternalsOnPullDirectStreamCode;
+extern const int s_readableStreamInternalsOnPullDirectStreamCodeLength;
+extern const JSC::ConstructAbility s_readableStreamInternalsOnPullDirectStreamCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableStreamInternalsOnPullDirectStreamCodeConstructorKind;
+extern const char* const s_readableStreamInternalsNoopDoneFunctionCode;
+extern const int s_readableStreamInternalsNoopDoneFunctionCodeLength;
+extern const JSC::ConstructAbility s_readableStreamInternalsNoopDoneFunctionCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableStreamInternalsNoopDoneFunctionCodeConstructorKind;
+extern const char* const s_readableStreamInternalsOnReadableStreamDirectControllerClosedCode;
+extern const int s_readableStreamInternalsOnReadableStreamDirectControllerClosedCodeLength;
+extern const JSC::ConstructAbility s_readableStreamInternalsOnReadableStreamDirectControllerClosedCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableStreamInternalsOnReadableStreamDirectControllerClosedCodeConstructorKind;
+extern const char* const s_readableStreamInternalsOnCloseDirectStreamCode;
+extern const int s_readableStreamInternalsOnCloseDirectStreamCodeLength;
+extern const JSC::ConstructAbility s_readableStreamInternalsOnCloseDirectStreamCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableStreamInternalsOnCloseDirectStreamCodeConstructorKind;
+extern const char* const s_readableStreamInternalsOnDrainDirectStreamCode;
+extern const int s_readableStreamInternalsOnDrainDirectStreamCodeLength;
+extern const JSC::ConstructAbility s_readableStreamInternalsOnDrainDirectStreamCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableStreamInternalsOnDrainDirectStreamCodeConstructorKind;
+extern const char* const s_readableStreamInternalsInitializeArrayBufferStreamCode;
+extern const int s_readableStreamInternalsInitializeArrayBufferStreamCodeLength;
+extern const JSC::ConstructAbility s_readableStreamInternalsInitializeArrayBufferStreamCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableStreamInternalsInitializeArrayBufferStreamCodeConstructorKind;
+extern const char* const s_readableStreamInternalsReadableStreamErrorCode;
+extern const int s_readableStreamInternalsReadableStreamErrorCodeLength;
+extern const JSC::ConstructAbility s_readableStreamInternalsReadableStreamErrorCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableStreamInternalsReadableStreamErrorCodeConstructorKind;
+extern const char* const s_readableStreamInternalsReadableStreamDefaultControllerShouldCallPullCode;
+extern const int s_readableStreamInternalsReadableStreamDefaultControllerShouldCallPullCodeLength;
+extern const JSC::ConstructAbility s_readableStreamInternalsReadableStreamDefaultControllerShouldCallPullCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableStreamInternalsReadableStreamDefaultControllerShouldCallPullCodeConstructorKind;
+extern const char* const s_readableStreamInternalsReadableStreamDefaultControllerCallPullIfNeededCode;
+extern const int s_readableStreamInternalsReadableStreamDefaultControllerCallPullIfNeededCodeLength;
+extern const JSC::ConstructAbility s_readableStreamInternalsReadableStreamDefaultControllerCallPullIfNeededCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableStreamInternalsReadableStreamDefaultControllerCallPullIfNeededCodeConstructorKind;
+extern const char* const s_readableStreamInternalsIsReadableStreamLockedCode;
+extern const int s_readableStreamInternalsIsReadableStreamLockedCodeLength;
+extern const JSC::ConstructAbility s_readableStreamInternalsIsReadableStreamLockedCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableStreamInternalsIsReadableStreamLockedCodeConstructorKind;
+extern const char* const s_readableStreamInternalsReadableStreamDefaultControllerGetDesiredSizeCode;
+extern const int s_readableStreamInternalsReadableStreamDefaultControllerGetDesiredSizeCodeLength;
+extern const JSC::ConstructAbility s_readableStreamInternalsReadableStreamDefaultControllerGetDesiredSizeCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableStreamInternalsReadableStreamDefaultControllerGetDesiredSizeCodeConstructorKind;
+extern const char* const s_readableStreamInternalsReadableStreamReaderGenericCancelCode;
+extern const int s_readableStreamInternalsReadableStreamReaderGenericCancelCodeLength;
+extern const JSC::ConstructAbility s_readableStreamInternalsReadableStreamReaderGenericCancelCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableStreamInternalsReadableStreamReaderGenericCancelCodeConstructorKind;
+extern const char* const s_readableStreamInternalsReadableStreamCancelCode;
+extern const int s_readableStreamInternalsReadableStreamCancelCodeLength;
+extern const JSC::ConstructAbility s_readableStreamInternalsReadableStreamCancelCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableStreamInternalsReadableStreamCancelCodeConstructorKind;
+extern const char* const s_readableStreamInternalsReadableStreamDefaultControllerCancelCode;
+extern const int s_readableStreamInternalsReadableStreamDefaultControllerCancelCodeLength;
+extern const JSC::ConstructAbility s_readableStreamInternalsReadableStreamDefaultControllerCancelCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableStreamInternalsReadableStreamDefaultControllerCancelCodeConstructorKind;
+extern const char* const s_readableStreamInternalsReadableStreamDefaultControllerPullCode;
+extern const int s_readableStreamInternalsReadableStreamDefaultControllerPullCodeLength;
+extern const JSC::ConstructAbility s_readableStreamInternalsReadableStreamDefaultControllerPullCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableStreamInternalsReadableStreamDefaultControllerPullCodeConstructorKind;
+extern const char* const s_readableStreamInternalsReadableStreamDefaultControllerCloseCode;
+extern const int s_readableStreamInternalsReadableStreamDefaultControllerCloseCodeLength;
+extern const JSC::ConstructAbility s_readableStreamInternalsReadableStreamDefaultControllerCloseCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableStreamInternalsReadableStreamDefaultControllerCloseCodeConstructorKind;
+extern const char* const s_readableStreamInternalsReadableStreamCloseCode;
+extern const int s_readableStreamInternalsReadableStreamCloseCodeLength;
+extern const JSC::ConstructAbility s_readableStreamInternalsReadableStreamCloseCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableStreamInternalsReadableStreamCloseCodeConstructorKind;
+extern const char* const s_readableStreamInternalsReadableStreamFulfillReadRequestCode;
+extern const int s_readableStreamInternalsReadableStreamFulfillReadRequestCodeLength;
+extern const JSC::ConstructAbility s_readableStreamInternalsReadableStreamFulfillReadRequestCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableStreamInternalsReadableStreamFulfillReadRequestCodeConstructorKind;
+extern const char* const s_readableStreamInternalsReadableStreamDefaultControllerEnqueueCode;
+extern const int s_readableStreamInternalsReadableStreamDefaultControllerEnqueueCodeLength;
+extern const JSC::ConstructAbility s_readableStreamInternalsReadableStreamDefaultControllerEnqueueCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableStreamInternalsReadableStreamDefaultControllerEnqueueCodeConstructorKind;
+extern const char* const s_readableStreamInternalsReadableStreamDefaultReaderReadCode;
+extern const int s_readableStreamInternalsReadableStreamDefaultReaderReadCodeLength;
+extern const JSC::ConstructAbility s_readableStreamInternalsReadableStreamDefaultReaderReadCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableStreamInternalsReadableStreamDefaultReaderReadCodeConstructorKind;
+extern const char* const s_readableStreamInternalsReadableStreamAddReadRequestCode;
+extern const int s_readableStreamInternalsReadableStreamAddReadRequestCodeLength;
+extern const JSC::ConstructAbility s_readableStreamInternalsReadableStreamAddReadRequestCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableStreamInternalsReadableStreamAddReadRequestCodeConstructorKind;
+extern const char* const s_readableStreamInternalsIsReadableStreamDisturbedCode;
+extern const int s_readableStreamInternalsIsReadableStreamDisturbedCodeLength;
+extern const JSC::ConstructAbility s_readableStreamInternalsIsReadableStreamDisturbedCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableStreamInternalsIsReadableStreamDisturbedCodeConstructorKind;
+extern const char* const s_readableStreamInternalsReadableStreamReaderGenericReleaseCode;
+extern const int s_readableStreamInternalsReadableStreamReaderGenericReleaseCodeLength;
+extern const JSC::ConstructAbility s_readableStreamInternalsReadableStreamReaderGenericReleaseCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableStreamInternalsReadableStreamReaderGenericReleaseCodeConstructorKind;
+extern const char* const s_readableStreamInternalsReadableStreamDefaultControllerCanCloseOrEnqueueCode;
+extern const int s_readableStreamInternalsReadableStreamDefaultControllerCanCloseOrEnqueueCodeLength;
+extern const JSC::ConstructAbility s_readableStreamInternalsReadableStreamDefaultControllerCanCloseOrEnqueueCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableStreamInternalsReadableStreamDefaultControllerCanCloseOrEnqueueCodeConstructorKind;
+extern const char* const s_readableStreamInternalsLazyLoadStreamCode;
+extern const int s_readableStreamInternalsLazyLoadStreamCodeLength;
+extern const JSC::ConstructAbility s_readableStreamInternalsLazyLoadStreamCodeConstructAbility;
+extern const JSC::ConstructorKind s_readableStreamInternalsLazyLoadStreamCodeConstructorKind;
+
+#define WEBCORE_FOREACH_READABLESTREAMINTERNALS_BUILTIN_DATA(macro) \
+ macro(readableStreamReaderGenericInitialize, readableStreamInternalsReadableStreamReaderGenericInitialize, 2) \
+ macro(privateInitializeReadableStreamDefaultController, readableStreamInternalsPrivateInitializeReadableStreamDefaultController, 4) \
+ macro(readableStreamDefaultControllerError, readableStreamInternalsReadableStreamDefaultControllerError, 2) \
+ macro(readableStreamPipeTo, readableStreamInternalsReadableStreamPipeTo, 2) \
+ macro(acquireReadableStreamDefaultReader, readableStreamInternalsAcquireReadableStreamDefaultReader, 1) \
+ macro(setupReadableStreamDefaultController, readableStreamInternalsSetupReadableStreamDefaultController, 7) \
+ macro(createReadableStreamController, readableStreamInternalsCreateReadableStreamController, 3) \
+ macro(readableStreamDefaultControllerStart, readableStreamInternalsReadableStreamDefaultControllerStart, 1) \
+ macro(readableStreamPipeToWritableStream, readableStreamInternalsReadableStreamPipeToWritableStream, 6) \
+ macro(pipeToLoop, readableStreamInternalsPipeToLoop, 1) \
+ macro(pipeToDoReadWrite, readableStreamInternalsPipeToDoReadWrite, 1) \
+ macro(pipeToErrorsMustBePropagatedForward, readableStreamInternalsPipeToErrorsMustBePropagatedForward, 1) \
+ macro(pipeToErrorsMustBePropagatedBackward, readableStreamInternalsPipeToErrorsMustBePropagatedBackward, 1) \
+ macro(pipeToClosingMustBePropagatedForward, readableStreamInternalsPipeToClosingMustBePropagatedForward, 1) \
+ macro(pipeToClosingMustBePropagatedBackward, readableStreamInternalsPipeToClosingMustBePropagatedBackward, 1) \
+ macro(pipeToShutdownWithAction, readableStreamInternalsPipeToShutdownWithAction, 2) \
+ macro(pipeToShutdown, readableStreamInternalsPipeToShutdown, 1) \
+ macro(pipeToFinalize, readableStreamInternalsPipeToFinalize, 1) \
+ macro(readableStreamTee, readableStreamInternalsReadableStreamTee, 2) \
+ macro(readableStreamTeePullFunction, readableStreamInternalsReadableStreamTeePullFunction, 3) \
+ macro(readableStreamTeeBranch1CancelFunction, readableStreamInternalsReadableStreamTeeBranch1CancelFunction, 2) \
+ macro(readableStreamTeeBranch2CancelFunction, readableStreamInternalsReadableStreamTeeBranch2CancelFunction, 2) \
+ macro(isReadableStream, readableStreamInternalsIsReadableStream, 1) \
+ macro(isReadableStreamDefaultReader, readableStreamInternalsIsReadableStreamDefaultReader, 1) \
+ macro(isReadableStreamDefaultController, readableStreamInternalsIsReadableStreamDefaultController, 1) \
+ macro(assignDirectStream, readableStreamInternalsAssignDirectStream, 0) \
+ macro(handleDirectStreamError, readableStreamInternalsHandleDirectStreamError, 1) \
+ macro(handleDirectStreamErrorReject, readableStreamInternalsHandleDirectStreamErrorReject, 1) \
+ macro(onPullDirectStream, readableStreamInternalsOnPullDirectStream, 1) \
+ macro(noopDoneFunction, readableStreamInternalsNoopDoneFunction, 0) \
+ macro(onReadableStreamDirectControllerClosed, readableStreamInternalsOnReadableStreamDirectControllerClosed, 1) \
+ macro(onCloseDirectStream, readableStreamInternalsOnCloseDirectStream, 1) \
+ macro(onDrainDirectStream, readableStreamInternalsOnDrainDirectStream, 0) \
+ macro(initializeArrayBufferStream, readableStreamInternalsInitializeArrayBufferStream, 2) \
+ macro(readableStreamError, readableStreamInternalsReadableStreamError, 2) \
+ macro(readableStreamDefaultControllerShouldCallPull, readableStreamInternalsReadableStreamDefaultControllerShouldCallPull, 1) \
+ macro(readableStreamDefaultControllerCallPullIfNeeded, readableStreamInternalsReadableStreamDefaultControllerCallPullIfNeeded, 1) \
+ macro(isReadableStreamLocked, readableStreamInternalsIsReadableStreamLocked, 1) \
+ macro(readableStreamDefaultControllerGetDesiredSize, readableStreamInternalsReadableStreamDefaultControllerGetDesiredSize, 1) \
+ macro(readableStreamReaderGenericCancel, readableStreamInternalsReadableStreamReaderGenericCancel, 2) \
+ macro(readableStreamCancel, readableStreamInternalsReadableStreamCancel, 2) \
+ macro(readableStreamDefaultControllerCancel, readableStreamInternalsReadableStreamDefaultControllerCancel, 2) \
+ macro(readableStreamDefaultControllerPull, readableStreamInternalsReadableStreamDefaultControllerPull, 1) \
+ macro(readableStreamDefaultControllerClose, readableStreamInternalsReadableStreamDefaultControllerClose, 1) \
+ macro(readableStreamClose, readableStreamInternalsReadableStreamClose, 1) \
+ macro(readableStreamFulfillReadRequest, readableStreamInternalsReadableStreamFulfillReadRequest, 3) \
+ macro(readableStreamDefaultControllerEnqueue, readableStreamInternalsReadableStreamDefaultControllerEnqueue, 2) \
+ macro(readableStreamDefaultReaderRead, readableStreamInternalsReadableStreamDefaultReaderRead, 1) \
+ macro(readableStreamAddReadRequest, readableStreamInternalsReadableStreamAddReadRequest, 1) \
+ macro(isReadableStreamDisturbed, readableStreamInternalsIsReadableStreamDisturbed, 1) \
+ macro(readableStreamReaderGenericRelease, readableStreamInternalsReadableStreamReaderGenericRelease, 1) \
+ macro(readableStreamDefaultControllerCanCloseOrEnqueue, readableStreamInternalsReadableStreamDefaultControllerCanCloseOrEnqueue, 1) \
+ macro(lazyLoadStream, readableStreamInternalsLazyLoadStream, 2) \
+
+#define WEBCORE_BUILTIN_READABLESTREAMINTERNALS_READABLESTREAMREADERGENERICINITIALIZE 1
+#define WEBCORE_BUILTIN_READABLESTREAMINTERNALS_PRIVATEINITIALIZEREADABLESTREAMDEFAULTCONTROLLER 1
+#define WEBCORE_BUILTIN_READABLESTREAMINTERNALS_READABLESTREAMDEFAULTCONTROLLERERROR 1
+#define WEBCORE_BUILTIN_READABLESTREAMINTERNALS_READABLESTREAMPIPETO 1
+#define WEBCORE_BUILTIN_READABLESTREAMINTERNALS_ACQUIREREADABLESTREAMDEFAULTREADER 1
+#define WEBCORE_BUILTIN_READABLESTREAMINTERNALS_SETUPREADABLESTREAMDEFAULTCONTROLLER 1
+#define WEBCORE_BUILTIN_READABLESTREAMINTERNALS_CREATEREADABLESTREAMCONTROLLER 1
+#define WEBCORE_BUILTIN_READABLESTREAMINTERNALS_READABLESTREAMDEFAULTCONTROLLERSTART 1
+#define WEBCORE_BUILTIN_READABLESTREAMINTERNALS_READABLESTREAMPIPETOWRITABLESTREAM 1
+#define WEBCORE_BUILTIN_READABLESTREAMINTERNALS_PIPETOLOOP 1
+#define WEBCORE_BUILTIN_READABLESTREAMINTERNALS_PIPETODOREADWRITE 1
+#define WEBCORE_BUILTIN_READABLESTREAMINTERNALS_PIPETOERRORSMUSTBEPROPAGATEDFORWARD 1
+#define WEBCORE_BUILTIN_READABLESTREAMINTERNALS_PIPETOERRORSMUSTBEPROPAGATEDBACKWARD 1
+#define WEBCORE_BUILTIN_READABLESTREAMINTERNALS_PIPETOCLOSINGMUSTBEPROPAGATEDFORWARD 1
+#define WEBCORE_BUILTIN_READABLESTREAMINTERNALS_PIPETOCLOSINGMUSTBEPROPAGATEDBACKWARD 1
+#define WEBCORE_BUILTIN_READABLESTREAMINTERNALS_PIPETOSHUTDOWNWITHACTION 1
+#define WEBCORE_BUILTIN_READABLESTREAMINTERNALS_PIPETOSHUTDOWN 1
+#define WEBCORE_BUILTIN_READABLESTREAMINTERNALS_PIPETOFINALIZE 1
+#define WEBCORE_BUILTIN_READABLESTREAMINTERNALS_READABLESTREAMTEE 1
+#define WEBCORE_BUILTIN_READABLESTREAMINTERNALS_READABLESTREAMTEEPULLFUNCTION 1
+#define WEBCORE_BUILTIN_READABLESTREAMINTERNALS_READABLESTREAMTEEBRANCH1CANCELFUNCTION 1
+#define WEBCORE_BUILTIN_READABLESTREAMINTERNALS_READABLESTREAMTEEBRANCH2CANCELFUNCTION 1
+#define WEBCORE_BUILTIN_READABLESTREAMINTERNALS_ISREADABLESTREAM 1
+#define WEBCORE_BUILTIN_READABLESTREAMINTERNALS_ISREADABLESTREAMDEFAULTREADER 1
+#define WEBCORE_BUILTIN_READABLESTREAMINTERNALS_ISREADABLESTREAMDEFAULTCONTROLLER 1
+#define WEBCORE_BUILTIN_READABLESTREAMINTERNALS_ASSIGNDIRECTSTREAM 1
+#define WEBCORE_BUILTIN_READABLESTREAMINTERNALS_HANDLEDIRECTSTREAMERROR 1
+#define WEBCORE_BUILTIN_READABLESTREAMINTERNALS_HANDLEDIRECTSTREAMERRORREJECT 1
+#define WEBCORE_BUILTIN_READABLESTREAMINTERNALS_ONPULLDIRECTSTREAM 1
+#define WEBCORE_BUILTIN_READABLESTREAMINTERNALS_NOOPDONEFUNCTION 1
+#define WEBCORE_BUILTIN_READABLESTREAMINTERNALS_ONREADABLESTREAMDIRECTCONTROLLERCLOSED 1
+#define WEBCORE_BUILTIN_READABLESTREAMINTERNALS_ONCLOSEDIRECTSTREAM 1
+#define WEBCORE_BUILTIN_READABLESTREAMINTERNALS_ONDRAINDIRECTSTREAM 1
+#define WEBCORE_BUILTIN_READABLESTREAMINTERNALS_INITIALIZEARRAYBUFFERSTREAM 1
+#define WEBCORE_BUILTIN_READABLESTREAMINTERNALS_READABLESTREAMERROR 1
+#define WEBCORE_BUILTIN_READABLESTREAMINTERNALS_READABLESTREAMDEFAULTCONTROLLERSHOULDCALLPULL 1
+#define WEBCORE_BUILTIN_READABLESTREAMINTERNALS_READABLESTREAMDEFAULTCONTROLLERCALLPULLIFNEEDED 1
+#define WEBCORE_BUILTIN_READABLESTREAMINTERNALS_ISREADABLESTREAMLOCKED 1
+#define WEBCORE_BUILTIN_READABLESTREAMINTERNALS_READABLESTREAMDEFAULTCONTROLLERGETDESIREDSIZE 1
+#define WEBCORE_BUILTIN_READABLESTREAMINTERNALS_READABLESTREAMREADERGENERICCANCEL 1
+#define WEBCORE_BUILTIN_READABLESTREAMINTERNALS_READABLESTREAMCANCEL 1
+#define WEBCORE_BUILTIN_READABLESTREAMINTERNALS_READABLESTREAMDEFAULTCONTROLLERCANCEL 1
+#define WEBCORE_BUILTIN_READABLESTREAMINTERNALS_READABLESTREAMDEFAULTCONTROLLERPULL 1
+#define WEBCORE_BUILTIN_READABLESTREAMINTERNALS_READABLESTREAMDEFAULTCONTROLLERCLOSE 1
+#define WEBCORE_BUILTIN_READABLESTREAMINTERNALS_READABLESTREAMCLOSE 1
+#define WEBCORE_BUILTIN_READABLESTREAMINTERNALS_READABLESTREAMFULFILLREADREQUEST 1
+#define WEBCORE_BUILTIN_READABLESTREAMINTERNALS_READABLESTREAMDEFAULTCONTROLLERENQUEUE 1
+#define WEBCORE_BUILTIN_READABLESTREAMINTERNALS_READABLESTREAMDEFAULTREADERREAD 1
+#define WEBCORE_BUILTIN_READABLESTREAMINTERNALS_READABLESTREAMADDREADREQUEST 1
+#define WEBCORE_BUILTIN_READABLESTREAMINTERNALS_ISREADABLESTREAMDISTURBED 1
+#define WEBCORE_BUILTIN_READABLESTREAMINTERNALS_READABLESTREAMREADERGENERICRELEASE 1
+#define WEBCORE_BUILTIN_READABLESTREAMINTERNALS_READABLESTREAMDEFAULTCONTROLLERCANCLOSEORENQUEUE 1
+#define WEBCORE_BUILTIN_READABLESTREAMINTERNALS_LAZYLOADSTREAM 1
+
+#define WEBCORE_FOREACH_READABLESTREAMINTERNALS_BUILTIN_CODE(macro) \
+ macro(readableStreamInternalsReadableStreamReaderGenericInitializeCode, readableStreamReaderGenericInitialize, ASCIILiteral(), s_readableStreamInternalsReadableStreamReaderGenericInitializeCodeLength) \
+ macro(readableStreamInternalsPrivateInitializeReadableStreamDefaultControllerCode, privateInitializeReadableStreamDefaultController, ASCIILiteral(), s_readableStreamInternalsPrivateInitializeReadableStreamDefaultControllerCodeLength) \
+ macro(readableStreamInternalsReadableStreamDefaultControllerErrorCode, readableStreamDefaultControllerError, ASCIILiteral(), s_readableStreamInternalsReadableStreamDefaultControllerErrorCodeLength) \
+ macro(readableStreamInternalsReadableStreamPipeToCode, readableStreamPipeTo, ASCIILiteral(), s_readableStreamInternalsReadableStreamPipeToCodeLength) \
+ macro(readableStreamInternalsAcquireReadableStreamDefaultReaderCode, acquireReadableStreamDefaultReader, ASCIILiteral(), s_readableStreamInternalsAcquireReadableStreamDefaultReaderCodeLength) \
+ macro(readableStreamInternalsSetupReadableStreamDefaultControllerCode, setupReadableStreamDefaultController, ASCIILiteral(), s_readableStreamInternalsSetupReadableStreamDefaultControllerCodeLength) \
+ macro(readableStreamInternalsCreateReadableStreamControllerCode, createReadableStreamController, ASCIILiteral(), s_readableStreamInternalsCreateReadableStreamControllerCodeLength) \
+ macro(readableStreamInternalsReadableStreamDefaultControllerStartCode, readableStreamDefaultControllerStart, ASCIILiteral(), s_readableStreamInternalsReadableStreamDefaultControllerStartCodeLength) \
+ macro(readableStreamInternalsReadableStreamPipeToWritableStreamCode, readableStreamPipeToWritableStream, ASCIILiteral(), s_readableStreamInternalsReadableStreamPipeToWritableStreamCodeLength) \
+ macro(readableStreamInternalsPipeToLoopCode, pipeToLoop, ASCIILiteral(), s_readableStreamInternalsPipeToLoopCodeLength) \
+ macro(readableStreamInternalsPipeToDoReadWriteCode, pipeToDoReadWrite, ASCIILiteral(), s_readableStreamInternalsPipeToDoReadWriteCodeLength) \
+ macro(readableStreamInternalsPipeToErrorsMustBePropagatedForwardCode, pipeToErrorsMustBePropagatedForward, ASCIILiteral(), s_readableStreamInternalsPipeToErrorsMustBePropagatedForwardCodeLength) \
+ macro(readableStreamInternalsPipeToErrorsMustBePropagatedBackwardCode, pipeToErrorsMustBePropagatedBackward, ASCIILiteral(), s_readableStreamInternalsPipeToErrorsMustBePropagatedBackwardCodeLength) \
+ macro(readableStreamInternalsPipeToClosingMustBePropagatedForwardCode, pipeToClosingMustBePropagatedForward, ASCIILiteral(), s_readableStreamInternalsPipeToClosingMustBePropagatedForwardCodeLength) \
+ macro(readableStreamInternalsPipeToClosingMustBePropagatedBackwardCode, pipeToClosingMustBePropagatedBackward, ASCIILiteral(), s_readableStreamInternalsPipeToClosingMustBePropagatedBackwardCodeLength) \
+ macro(readableStreamInternalsPipeToShutdownWithActionCode, pipeToShutdownWithAction, ASCIILiteral(), s_readableStreamInternalsPipeToShutdownWithActionCodeLength) \
+ macro(readableStreamInternalsPipeToShutdownCode, pipeToShutdown, ASCIILiteral(), s_readableStreamInternalsPipeToShutdownCodeLength) \
+ macro(readableStreamInternalsPipeToFinalizeCode, pipeToFinalize, ASCIILiteral(), s_readableStreamInternalsPipeToFinalizeCodeLength) \
+ macro(readableStreamInternalsReadableStreamTeeCode, readableStreamTee, ASCIILiteral(), s_readableStreamInternalsReadableStreamTeeCodeLength) \
+ macro(readableStreamInternalsReadableStreamTeePullFunctionCode, readableStreamTeePullFunction, ASCIILiteral(), s_readableStreamInternalsReadableStreamTeePullFunctionCodeLength) \
+ macro(readableStreamInternalsReadableStreamTeeBranch1CancelFunctionCode, readableStreamTeeBranch1CancelFunction, ASCIILiteral(), s_readableStreamInternalsReadableStreamTeeBranch1CancelFunctionCodeLength) \
+ macro(readableStreamInternalsReadableStreamTeeBranch2CancelFunctionCode, readableStreamTeeBranch2CancelFunction, ASCIILiteral(), s_readableStreamInternalsReadableStreamTeeBranch2CancelFunctionCodeLength) \
+ macro(readableStreamInternalsIsReadableStreamCode, isReadableStream, ASCIILiteral(), s_readableStreamInternalsIsReadableStreamCodeLength) \
+ macro(readableStreamInternalsIsReadableStreamDefaultReaderCode, isReadableStreamDefaultReader, ASCIILiteral(), s_readableStreamInternalsIsReadableStreamDefaultReaderCodeLength) \
+ macro(readableStreamInternalsIsReadableStreamDefaultControllerCode, isReadableStreamDefaultController, ASCIILiteral(), s_readableStreamInternalsIsReadableStreamDefaultControllerCodeLength) \
+ macro(readableStreamInternalsAssignDirectStreamCode, assignDirectStream, ASCIILiteral(), s_readableStreamInternalsAssignDirectStreamCodeLength) \
+ macro(readableStreamInternalsHandleDirectStreamErrorCode, handleDirectStreamError, ASCIILiteral(), s_readableStreamInternalsHandleDirectStreamErrorCodeLength) \
+ macro(readableStreamInternalsHandleDirectStreamErrorRejectCode, handleDirectStreamErrorReject, ASCIILiteral(), s_readableStreamInternalsHandleDirectStreamErrorRejectCodeLength) \
+ macro(readableStreamInternalsOnPullDirectStreamCode, onPullDirectStream, ASCIILiteral(), s_readableStreamInternalsOnPullDirectStreamCodeLength) \
+ macro(readableStreamInternalsNoopDoneFunctionCode, noopDoneFunction, ASCIILiteral(), s_readableStreamInternalsNoopDoneFunctionCodeLength) \
+ macro(readableStreamInternalsOnReadableStreamDirectControllerClosedCode, onReadableStreamDirectControllerClosed, ASCIILiteral(), s_readableStreamInternalsOnReadableStreamDirectControllerClosedCodeLength) \
+ macro(readableStreamInternalsOnCloseDirectStreamCode, onCloseDirectStream, ASCIILiteral(), s_readableStreamInternalsOnCloseDirectStreamCodeLength) \
+ macro(readableStreamInternalsOnDrainDirectStreamCode, onDrainDirectStream, ASCIILiteral(), s_readableStreamInternalsOnDrainDirectStreamCodeLength) \
+ macro(readableStreamInternalsInitializeArrayBufferStreamCode, initializeArrayBufferStream, ASCIILiteral(), s_readableStreamInternalsInitializeArrayBufferStreamCodeLength) \
+ macro(readableStreamInternalsReadableStreamErrorCode, readableStreamError, ASCIILiteral(), s_readableStreamInternalsReadableStreamErrorCodeLength) \
+ macro(readableStreamInternalsReadableStreamDefaultControllerShouldCallPullCode, readableStreamDefaultControllerShouldCallPull, ASCIILiteral(), s_readableStreamInternalsReadableStreamDefaultControllerShouldCallPullCodeLength) \
+ macro(readableStreamInternalsReadableStreamDefaultControllerCallPullIfNeededCode, readableStreamDefaultControllerCallPullIfNeeded, ASCIILiteral(), s_readableStreamInternalsReadableStreamDefaultControllerCallPullIfNeededCodeLength) \
+ macro(readableStreamInternalsIsReadableStreamLockedCode, isReadableStreamLocked, ASCIILiteral(), s_readableStreamInternalsIsReadableStreamLockedCodeLength) \
+ macro(readableStreamInternalsReadableStreamDefaultControllerGetDesiredSizeCode, readableStreamDefaultControllerGetDesiredSize, ASCIILiteral(), s_readableStreamInternalsReadableStreamDefaultControllerGetDesiredSizeCodeLength) \
+ macro(readableStreamInternalsReadableStreamReaderGenericCancelCode, readableStreamReaderGenericCancel, ASCIILiteral(), s_readableStreamInternalsReadableStreamReaderGenericCancelCodeLength) \
+ macro(readableStreamInternalsReadableStreamCancelCode, readableStreamCancel, ASCIILiteral(), s_readableStreamInternalsReadableStreamCancelCodeLength) \
+ macro(readableStreamInternalsReadableStreamDefaultControllerCancelCode, readableStreamDefaultControllerCancel, ASCIILiteral(), s_readableStreamInternalsReadableStreamDefaultControllerCancelCodeLength) \
+ macro(readableStreamInternalsReadableStreamDefaultControllerPullCode, readableStreamDefaultControllerPull, ASCIILiteral(), s_readableStreamInternalsReadableStreamDefaultControllerPullCodeLength) \
+ macro(readableStreamInternalsReadableStreamDefaultControllerCloseCode, readableStreamDefaultControllerClose, ASCIILiteral(), s_readableStreamInternalsReadableStreamDefaultControllerCloseCodeLength) \
+ macro(readableStreamInternalsReadableStreamCloseCode, readableStreamClose, ASCIILiteral(), s_readableStreamInternalsReadableStreamCloseCodeLength) \
+ macro(readableStreamInternalsReadableStreamFulfillReadRequestCode, readableStreamFulfillReadRequest, ASCIILiteral(), s_readableStreamInternalsReadableStreamFulfillReadRequestCodeLength) \
+ macro(readableStreamInternalsReadableStreamDefaultControllerEnqueueCode, readableStreamDefaultControllerEnqueue, ASCIILiteral(), s_readableStreamInternalsReadableStreamDefaultControllerEnqueueCodeLength) \
+ macro(readableStreamInternalsReadableStreamDefaultReaderReadCode, readableStreamDefaultReaderRead, ASCIILiteral(), s_readableStreamInternalsReadableStreamDefaultReaderReadCodeLength) \
+ macro(readableStreamInternalsReadableStreamAddReadRequestCode, readableStreamAddReadRequest, ASCIILiteral(), s_readableStreamInternalsReadableStreamAddReadRequestCodeLength) \
+ macro(readableStreamInternalsIsReadableStreamDisturbedCode, isReadableStreamDisturbed, ASCIILiteral(), s_readableStreamInternalsIsReadableStreamDisturbedCodeLength) \
+ macro(readableStreamInternalsReadableStreamReaderGenericReleaseCode, readableStreamReaderGenericRelease, ASCIILiteral(), s_readableStreamInternalsReadableStreamReaderGenericReleaseCodeLength) \
+ macro(readableStreamInternalsReadableStreamDefaultControllerCanCloseOrEnqueueCode, readableStreamDefaultControllerCanCloseOrEnqueue, ASCIILiteral(), s_readableStreamInternalsReadableStreamDefaultControllerCanCloseOrEnqueueCodeLength) \
+ macro(readableStreamInternalsLazyLoadStreamCode, lazyLoadStream, ASCIILiteral(), s_readableStreamInternalsLazyLoadStreamCodeLength) \
+
+#define WEBCORE_FOREACH_READABLESTREAMINTERNALS_BUILTIN_FUNCTION_NAME(macro) \
+ macro(acquireReadableStreamDefaultReader) \
+ macro(assignDirectStream) \
+ macro(createReadableStreamController) \
+ macro(handleDirectStreamError) \
+ macro(handleDirectStreamErrorReject) \
+ macro(initializeArrayBufferStream) \
+ macro(isReadableStream) \
+ macro(isReadableStreamDefaultController) \
+ macro(isReadableStreamDefaultReader) \
+ macro(isReadableStreamDisturbed) \
+ macro(isReadableStreamLocked) \
+ macro(lazyLoadStream) \
+ macro(noopDoneFunction) \
+ macro(onCloseDirectStream) \
+ macro(onDrainDirectStream) \
+ macro(onPullDirectStream) \
+ macro(onReadableStreamDirectControllerClosed) \
+ macro(pipeToClosingMustBePropagatedBackward) \
+ macro(pipeToClosingMustBePropagatedForward) \
+ macro(pipeToDoReadWrite) \
+ macro(pipeToErrorsMustBePropagatedBackward) \
+ macro(pipeToErrorsMustBePropagatedForward) \
+ macro(pipeToFinalize) \
+ macro(pipeToLoop) \
+ macro(pipeToShutdown) \
+ macro(pipeToShutdownWithAction) \
+ macro(privateInitializeReadableStreamDefaultController) \
+ macro(readableStreamAddReadRequest) \
+ macro(readableStreamCancel) \
+ macro(readableStreamClose) \
+ macro(readableStreamDefaultControllerCallPullIfNeeded) \
+ macro(readableStreamDefaultControllerCanCloseOrEnqueue) \
+ macro(readableStreamDefaultControllerCancel) \
+ macro(readableStreamDefaultControllerClose) \
+ macro(readableStreamDefaultControllerEnqueue) \
+ macro(readableStreamDefaultControllerError) \
+ macro(readableStreamDefaultControllerGetDesiredSize) \
+ macro(readableStreamDefaultControllerPull) \
+ macro(readableStreamDefaultControllerShouldCallPull) \
+ macro(readableStreamDefaultControllerStart) \
+ macro(readableStreamDefaultReaderRead) \
+ macro(readableStreamError) \
+ macro(readableStreamFulfillReadRequest) \
+ macro(readableStreamPipeTo) \
+ macro(readableStreamPipeToWritableStream) \
+ macro(readableStreamReaderGenericCancel) \
+ macro(readableStreamReaderGenericInitialize) \
+ macro(readableStreamReaderGenericRelease) \
+ macro(readableStreamTee) \
+ macro(readableStreamTeeBranch1CancelFunction) \
+ macro(readableStreamTeeBranch2CancelFunction) \
+ macro(readableStreamTeePullFunction) \
+ macro(setupReadableStreamDefaultController) \
+
+#define DECLARE_BUILTIN_GENERATOR(codeName, functionName, overriddenName, argumentCount) \
+ JSC::FunctionExecutable* codeName##Generator(JSC::VM&);
+
+WEBCORE_FOREACH_READABLESTREAMINTERNALS_BUILTIN_CODE(DECLARE_BUILTIN_GENERATOR)
+#undef DECLARE_BUILTIN_GENERATOR
+
+class ReadableStreamInternalsBuiltinsWrapper : private JSC::WeakHandleOwner {
+public:
+ explicit ReadableStreamInternalsBuiltinsWrapper(JSC::VM& vm)
+ : m_vm(vm)
+ WEBCORE_FOREACH_READABLESTREAMINTERNALS_BUILTIN_FUNCTION_NAME(INITIALIZE_BUILTIN_NAMES)
+#define INITIALIZE_BUILTIN_SOURCE_MEMBERS(name, functionName, overriddenName, length) , m_##name##Source(JSC::makeSource(StringImpl::createWithoutCopying(s_##name, length), { }))
+ WEBCORE_FOREACH_READABLESTREAMINTERNALS_BUILTIN_CODE(INITIALIZE_BUILTIN_SOURCE_MEMBERS)
+#undef INITIALIZE_BUILTIN_SOURCE_MEMBERS
+ {
+ }
+
+#define EXPOSE_BUILTIN_EXECUTABLES(name, functionName, overriddenName, length) \
+ JSC::UnlinkedFunctionExecutable* name##Executable(); \
+ const JSC::SourceCode& name##Source() const { return m_##name##Source; }
+ WEBCORE_FOREACH_READABLESTREAMINTERNALS_BUILTIN_CODE(EXPOSE_BUILTIN_EXECUTABLES)
+#undef EXPOSE_BUILTIN_EXECUTABLES
+
+ WEBCORE_FOREACH_READABLESTREAMINTERNALS_BUILTIN_FUNCTION_NAME(DECLARE_BUILTIN_IDENTIFIER_ACCESSOR)
+
+ void exportNames();
+
+private:
+ JSC::VM& m_vm;
+
+ WEBCORE_FOREACH_READABLESTREAMINTERNALS_BUILTIN_FUNCTION_NAME(DECLARE_BUILTIN_NAMES)
+
+#define DECLARE_BUILTIN_SOURCE_MEMBERS(name, functionName, overriddenName, length) \
+ JSC::SourceCode m_##name##Source;\
+ JSC::Weak<JSC::UnlinkedFunctionExecutable> m_##name##Executable;
+ WEBCORE_FOREACH_READABLESTREAMINTERNALS_BUILTIN_CODE(DECLARE_BUILTIN_SOURCE_MEMBERS)
+#undef DECLARE_BUILTIN_SOURCE_MEMBERS
+
+};
+
+#define DEFINE_BUILTIN_EXECUTABLES(name, functionName, overriddenName, length) \
+inline JSC::UnlinkedFunctionExecutable* ReadableStreamInternalsBuiltinsWrapper::name##Executable() \
+{\
+ if (!m_##name##Executable) {\
+ JSC::Identifier executableName = functionName##PublicName();\
+ if (overriddenName)\
+ executableName = JSC::Identifier::fromString(m_vm, overriddenName);\
+ m_##name##Executable = JSC::Weak<JSC::UnlinkedFunctionExecutable>(JSC::createBuiltinExecutable(m_vm, m_##name##Source, executableName, s_##name##ConstructorKind, s_##name##ConstructAbility), this, &m_##name##Executable);\
+ }\
+ return m_##name##Executable.get();\
+}
+WEBCORE_FOREACH_READABLESTREAMINTERNALS_BUILTIN_CODE(DEFINE_BUILTIN_EXECUTABLES)
+#undef DEFINE_BUILTIN_EXECUTABLES
+
+inline void ReadableStreamInternalsBuiltinsWrapper::exportNames()
+{
+#define EXPORT_FUNCTION_NAME(name) m_vm.propertyNames->appendExternalName(name##PublicName(), name##PrivateName());
+ WEBCORE_FOREACH_READABLESTREAMINTERNALS_BUILTIN_FUNCTION_NAME(EXPORT_FUNCTION_NAME)
+#undef EXPORT_FUNCTION_NAME
+}
+
+class ReadableStreamInternalsBuiltinFunctions {
+public:
+ explicit ReadableStreamInternalsBuiltinFunctions(JSC::VM& vm) : m_vm(vm) { }
+
+ void init(JSC::JSGlobalObject&);
+ template<typename Visitor> void visit(Visitor&);
+
+public:
+ JSC::VM& m_vm;
+
+#define DECLARE_BUILTIN_SOURCE_MEMBERS(functionName) \
+ JSC::WriteBarrier<JSC::JSFunction> m_##functionName##Function;
+ WEBCORE_FOREACH_READABLESTREAMINTERNALS_BUILTIN_FUNCTION_NAME(DECLARE_BUILTIN_SOURCE_MEMBERS)
+#undef DECLARE_BUILTIN_SOURCE_MEMBERS
+};
+
+inline void ReadableStreamInternalsBuiltinFunctions::init(JSC::JSGlobalObject& globalObject)
+{
+#define EXPORT_FUNCTION(codeName, functionName, overriddenName, length)\
+ m_##functionName##Function.set(m_vm, &globalObject, JSC::JSFunction::create(m_vm, codeName##Generator(m_vm), &globalObject));
+ WEBCORE_FOREACH_READABLESTREAMINTERNALS_BUILTIN_CODE(EXPORT_FUNCTION)
+#undef EXPORT_FUNCTION
+}
+
+template<typename Visitor>
+inline void ReadableStreamInternalsBuiltinFunctions::visit(Visitor& visitor)
+{
+#define VISIT_FUNCTION(name) visitor.append(m_##name##Function);
+ WEBCORE_FOREACH_READABLESTREAMINTERNALS_BUILTIN_FUNCTION_NAME(VISIT_FUNCTION)
+#undef VISIT_FUNCTION
+}
+
+template void ReadableStreamInternalsBuiltinFunctions::visit(JSC::AbstractSlotVisitor&);
+template void ReadableStreamInternalsBuiltinFunctions::visit(JSC::SlotVisitor&);
+
+
+
+} // namespace WebCore
diff --git a/src/bun.js/builtins/cpp/StreamInternalsBuiltins.cpp b/src/bun.js/builtins/cpp/StreamInternalsBuiltins.cpp
new file mode 100644
index 000000000..2203ed2f2
--- /dev/null
+++ b/src/bun.js/builtins/cpp/StreamInternalsBuiltins.cpp
@@ -0,0 +1,464 @@
+/*
+ * Copyright (c) 2015 Igalia
+ * Copyright (c) 2015 Igalia S.L.
+ * Copyright (c) 2015 Igalia.
+ * Copyright (c) 2015, 2016 Canon Inc. All rights reserved.
+ * Copyright (c) 2015, 2016, 2017 Canon Inc.
+ * Copyright (c) 2016, 2020 Apple Inc. All rights reserved.
+ * Copyright (c) 2022 Codeblog Corp. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+// DO NOT EDIT THIS FILE. It is automatically generated from JavaScript files for
+// builtins by the script: Source/JavaScriptCore/Scripts/generate-js-builtins.py
+
+#include "config.h"
+#include "StreamInternalsBuiltins.h"
+
+#include "WebCoreJSClientData.h"
+#include <JavaScriptCore/HeapInlines.h>
+#include <JavaScriptCore/IdentifierInlines.h>
+#include <JavaScriptCore/Intrinsic.h>
+#include <JavaScriptCore/JSCJSValueInlines.h>
+#include <JavaScriptCore/JSCellInlines.h>
+#include <JavaScriptCore/StructureInlines.h>
+#include <JavaScriptCore/VM.h>
+
+namespace WebCore {
+
+const JSC::ConstructAbility s_streamInternalsMarkPromiseAsHandledCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_streamInternalsMarkPromiseAsHandledCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_streamInternalsMarkPromiseAsHandledCodeLength = 217;
+static const JSC::Intrinsic s_streamInternalsMarkPromiseAsHandledCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_streamInternalsMarkPromiseAsHandledCode =
+ "(function (promise)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " @assert(@isPromise(promise));\n" \
+ " @putPromiseInternalField(promise, @promiseFieldFlags, @getPromiseInternalField(promise, @promiseFieldFlags) | @promiseFlagsIsHandled);\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_streamInternalsShieldingPromiseResolveCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_streamInternalsShieldingPromiseResolveCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_streamInternalsShieldingPromiseResolveCodeLength = 198;
+static const JSC::Intrinsic s_streamInternalsShieldingPromiseResolveCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_streamInternalsShieldingPromiseResolveCode =
+ "(function (result)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " const promise = @Promise.@resolve(result);\n" \
+ " if (promise.@then === @undefined)\n" \
+ " promise.@then = @Promise.prototype.@then;\n" \
+ " return promise;\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_streamInternalsPromiseInvokeOrNoopMethodNoCatchCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_streamInternalsPromiseInvokeOrNoopMethodNoCatchCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_streamInternalsPromiseInvokeOrNoopMethodNoCatchCodeLength = 190;
+static const JSC::Intrinsic s_streamInternalsPromiseInvokeOrNoopMethodNoCatchCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_streamInternalsPromiseInvokeOrNoopMethodNoCatchCode =
+ "(function (object, method, args)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " if (method === @undefined)\n" \
+ " return @Promise.@resolve();\n" \
+ " return @shieldingPromiseResolve(method.@apply(object, args));\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_streamInternalsPromiseInvokeOrNoopNoCatchCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_streamInternalsPromiseInvokeOrNoopNoCatchCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_streamInternalsPromiseInvokeOrNoopNoCatchCodeLength = 127;
+static const JSC::Intrinsic s_streamInternalsPromiseInvokeOrNoopNoCatchCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_streamInternalsPromiseInvokeOrNoopNoCatchCode =
+ "(function (object, key, args)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " return @promiseInvokeOrNoopMethodNoCatch(object, object[key], args);\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_streamInternalsPromiseInvokeOrNoopMethodCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_streamInternalsPromiseInvokeOrNoopMethodCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_streamInternalsPromiseInvokeOrNoopMethodCodeLength = 210;
+static const JSC::Intrinsic s_streamInternalsPromiseInvokeOrNoopMethodCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_streamInternalsPromiseInvokeOrNoopMethodCode =
+ "(function (object, method, args)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " try {\n" \
+ " return @promiseInvokeOrNoopMethodNoCatch(object, method, args);\n" \
+ " }\n" \
+ " catch(error) {\n" \
+ " return @Promise.@reject(error);\n" \
+ " }\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_streamInternalsPromiseInvokeOrNoopCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_streamInternalsPromiseInvokeOrNoopCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_streamInternalsPromiseInvokeOrNoopCodeLength = 198;
+static const JSC::Intrinsic s_streamInternalsPromiseInvokeOrNoopCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_streamInternalsPromiseInvokeOrNoopCode =
+ "(function (object, key, args)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " try {\n" \
+ " return @promiseInvokeOrNoopNoCatch(object, key, args);\n" \
+ " }\n" \
+ " catch(error) {\n" \
+ " return @Promise.@reject(error);\n" \
+ " }\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_streamInternalsPromiseInvokeOrFallbackOrNoopCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_streamInternalsPromiseInvokeOrFallbackOrNoopCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_streamInternalsPromiseInvokeOrFallbackOrNoopCodeLength = 362;
+static const JSC::Intrinsic s_streamInternalsPromiseInvokeOrFallbackOrNoopCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_streamInternalsPromiseInvokeOrFallbackOrNoopCode =
+ "(function (object, key1, args1, key2, args2)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " try {\n" \
+ " const method = object[key1];\n" \
+ " if (method === @undefined)\n" \
+ " return @promiseInvokeOrNoopNoCatch(object, key2, args2);\n" \
+ " return @shieldingPromiseResolve(method.@apply(object, args1));\n" \
+ " }\n" \
+ " catch(error) {\n" \
+ " return @Promise.@reject(error);\n" \
+ " }\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_streamInternalsValidateAndNormalizeQueuingStrategyCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_streamInternalsValidateAndNormalizeQueuingStrategyCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_streamInternalsValidateAndNormalizeQueuingStrategyCodeLength = 430;
+static const JSC::Intrinsic s_streamInternalsValidateAndNormalizeQueuingStrategyCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_streamInternalsValidateAndNormalizeQueuingStrategyCode =
+ "(function (size, highWaterMark)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " if (size !== @undefined && typeof size !== \"function\")\n" \
+ " @throwTypeError(\"size parameter must be a function\");\n" \
+ "\n" \
+ " const newHighWaterMark = @toNumber(highWaterMark);\n" \
+ "\n" \
+ " if (@isNaN(newHighWaterMark) || newHighWaterMark < 0)\n" \
+ " @throwRangeError(\"highWaterMark value is negative or not a number\");\n" \
+ "\n" \
+ " return { size: size, highWaterMark: newHighWaterMark };\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_streamInternalsCreateFIFOCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_streamInternalsCreateFIFOCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_streamInternalsCreateFIFOCodeLength = 2764;
+static const JSC::Intrinsic s_streamInternalsCreateFIFOCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_streamInternalsCreateFIFOCode =
+ "(function () {\n" \
+ " \"use strict\";\n" \
+ " class Denqueue {\n" \
+ " constructor() {\n" \
+ " this._head = 0;\n" \
+ " this._tail = 0;\n" \
+ " //\n" \
+ " this._capacityMask = 0x3;\n" \
+ " this._list = @newArrayWithSize(4);\n" \
+ " }\n" \
+ " \n" \
+ " size() {\n" \
+ " if (this._head === this._tail) return 0;\n" \
+ " if (this._head < this._tail) return this._tail - this._head;\n" \
+ " else return this._capacityMask + 1 - (this._head - this._tail);\n" \
+ " }\n" \
+ "\n" \
+ " isEmpty() {\n" \
+ " return this.size() == 0;\n" \
+ " }\n" \
+ "\n" \
+ " isNotEmpty() {\n" \
+ " return this.size() > 0;\n" \
+ " }\n" \
+ " \n" \
+ " shift() {\n" \
+ " var head = this._head;\n" \
+ " if (head === this._tail) return @undefined;\n" \
+ " var item = this._list[head];\n" \
+ " @putByValDirect(this._list, head, @undefined);\n" \
+ " this._head = (head + 1) & this._capacityMask;\n" \
+ " if (head < 2 && this._tail > 10000 && this._tail <= this._list.length >>> 2) this._shrinkArray();\n" \
+ " return item;\n" \
+ " }\n" \
+ "\n" \
+ " peek() {\n" \
+ " if (this._head === this._tail) return @undefined;\n" \
+ " return this._list[this._head];\n" \
+ " }\n" \
+ " \n" \
+ " push(item) {\n" \
+ " var tail = this._tail;\n" \
+ " @putByValDirect(this._list, tail, item);\n" \
+ " this._tail = (tail + 1) & this._capacityMask;\n" \
+ " if (this._tail === this._head) {\n" \
+ " this._growArray();\n" \
+ " }\n" \
+ " //\n" \
+ " //\n" \
+ " //\n" \
+ " }\n" \
+ " \n" \
+ " toArray(fullCopy) {\n" \
+ " var list = this._list;\n" \
+ " var len = @toLength(list.length);\n" \
+ " \n" \
+ " if (fullCopy || this._head > this._tail) {\n" \
+ " var _head = @toLength(this._head);\n" \
+ " var _tail = @toLength(this._tail);\n" \
+ " var total = @toLength((len - _head) + _tail);\n" \
+ " var array = @newArrayWithSize(total);\n" \
+ " var j = 0;\n" \
+ " for (var i = _head; i < len; i++) @putByValDirect(array, j++, list[i]);\n" \
+ " for (var i = 0; i < _tail; i++) @putByValDirect(array, j++, list[i]);\n" \
+ " return array;\n" \
+ " } else {\n" \
+ " return @Array.prototype.slice.@call(list, this._head, this._tail);\n" \
+ " }\n" \
+ " }\n" \
+ " \n" \
+ " clear() {\n" \
+ " this._head = 0;\n" \
+ " this._tail = 0;\n" \
+ " this._list.fill(undefined);\n" \
+ " }\n" \
+ "\n" \
+ " _growArray() {\n" \
+ " if (this._head) {\n" \
+ " //\n" \
+ " this._list = this.toArray(true);\n" \
+ " this._head = 0;\n" \
+ " }\n" \
+ " \n" \
+ " //\n" \
+ " this._tail = @toLength(this._list.length);\n" \
+ " \n" \
+ " this._list.length <<= 1;\n" \
+ " this._capacityMask = (this._capacityMask << 1) | 1;\n" \
+ " }\n" \
+ " \n" \
+ " shrinkArray() {\n" \
+ " this._list.length >>>= 1;\n" \
+ " this._capacityMask >>>= 1;\n" \
+ " }\n" \
+ " }\n" \
+ "\n" \
+ " \n" \
+ " return new Denqueue();\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_streamInternalsNewQueueCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_streamInternalsNewQueueCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_streamInternalsNewQueueCodeLength = 85;
+static const JSC::Intrinsic s_streamInternalsNewQueueCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_streamInternalsNewQueueCode =
+ "(function ()\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " return { content: @createFIFO(), size: 0 };\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_streamInternalsDequeueValueCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_streamInternalsDequeueValueCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_streamInternalsDequeueValueCodeLength = 195;
+static const JSC::Intrinsic s_streamInternalsDequeueValueCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_streamInternalsDequeueValueCode =
+ "(function (queue)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " const record = queue.content.shift();\n" \
+ " queue.size -= record.size;\n" \
+ " //\n" \
+ " if (queue.size < 0)\n" \
+ " queue.size = 0;\n" \
+ " return record.value;\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_streamInternalsEnqueueValueWithSizeCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_streamInternalsEnqueueValueWithSizeCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_streamInternalsEnqueueValueWithSizeCodeLength = 248;
+static const JSC::Intrinsic s_streamInternalsEnqueueValueWithSizeCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_streamInternalsEnqueueValueWithSizeCode =
+ "(function (queue, value, size)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " size = @toNumber(size);\n" \
+ " if (!@isFinite(size) || size < 0)\n" \
+ " @throwRangeError(\"size has an incorrect value\");\n" \
+ " \n" \
+ " queue.content.push({ value, size });\n" \
+ " queue.size += size;\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_streamInternalsPeekQueueValueCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_streamInternalsPeekQueueValueCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_streamInternalsPeekQueueValueCodeLength = 115;
+static const JSC::Intrinsic s_streamInternalsPeekQueueValueCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_streamInternalsPeekQueueValueCode =
+ "(function (queue)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " @assert(queue.content.isNotEmpty());\n" \
+ "\n" \
+ " return queue.peek().value;\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_streamInternalsResetQueueCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_streamInternalsResetQueueCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_streamInternalsResetQueueCodeLength = 152;
+static const JSC::Intrinsic s_streamInternalsResetQueueCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_streamInternalsResetQueueCode =
+ "(function (queue)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " @assert(\"content\" in queue);\n" \
+ " @assert(\"size\" in queue);\n" \
+ " queue.content.clear();\n" \
+ " queue.size = 0;\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_streamInternalsExtractSizeAlgorithmCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_streamInternalsExtractSizeAlgorithmCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_streamInternalsExtractSizeAlgorithmCodeLength = 288;
+static const JSC::Intrinsic s_streamInternalsExtractSizeAlgorithmCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_streamInternalsExtractSizeAlgorithmCode =
+ "(function (strategy)\n" \
+ "{\n" \
+ " if (!(\"size\" in strategy))\n" \
+ " return () => 1;\n" \
+ " const sizeAlgorithm = strategy[\"size\"];\n" \
+ " if (typeof sizeAlgorithm !== \"function\")\n" \
+ " @throwTypeError(\"strategy.size must be a function\");\n" \
+ "\n" \
+ " return (chunk) => { return sizeAlgorithm(chunk); };\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_streamInternalsExtractHighWaterMarkCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_streamInternalsExtractHighWaterMarkCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_streamInternalsExtractHighWaterMarkCodeLength = 325;
+static const JSC::Intrinsic s_streamInternalsExtractHighWaterMarkCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_streamInternalsExtractHighWaterMarkCode =
+ "(function (strategy, defaultHWM)\n" \
+ "{\n" \
+ " if (!(\"highWaterMark\" in strategy))\n" \
+ " return defaultHWM;\n" \
+ " const highWaterMark = strategy[\"highWaterMark\"];\n" \
+ " if (@isNaN(highWaterMark) || highWaterMark < 0)\n" \
+ " @throwRangeError(\"highWaterMark value is negative or not a number\");\n" \
+ "\n" \
+ " return @toNumber(highWaterMark);\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_streamInternalsExtractHighWaterMarkFromQueuingStrategyInitCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_streamInternalsExtractHighWaterMarkFromQueuingStrategyInitCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_streamInternalsExtractHighWaterMarkFromQueuingStrategyInitCodeLength = 335;
+static const JSC::Intrinsic s_streamInternalsExtractHighWaterMarkFromQueuingStrategyInitCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_streamInternalsExtractHighWaterMarkFromQueuingStrategyInitCode =
+ "(function (init)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " if (!@isObject(init))\n" \
+ " @throwTypeError(\"QueuingStrategyInit argument must be an object.\");\n" \
+ " const {highWaterMark} = init;\n" \
+ " if (highWaterMark === @undefined)\n" \
+ " @throwTypeError(\"QueuingStrategyInit.highWaterMark member is required.\");\n" \
+ "\n" \
+ " return @toNumber(highWaterMark);\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_streamInternalsCreateFulfilledPromiseCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_streamInternalsCreateFulfilledPromiseCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_streamInternalsCreateFulfilledPromiseCodeLength = 115;
+static const JSC::Intrinsic s_streamInternalsCreateFulfilledPromiseCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_streamInternalsCreateFulfilledPromiseCode =
+ "(function (value)\n" \
+ "{\n" \
+ " const promise = @newPromise();\n" \
+ " @fulfillPromise(promise, value);\n" \
+ " return promise;\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_streamInternalsToDictionaryCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_streamInternalsToDictionaryCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_streamInternalsToDictionaryCodeLength = 212;
+static const JSC::Intrinsic s_streamInternalsToDictionaryCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_streamInternalsToDictionaryCode =
+ "(function (value, defaultValue, errorMessage)\n" \
+ "{\n" \
+ " if (value === @undefined || value === null)\n" \
+ " return defaultValue;\n" \
+ " if (!@isObject(value))\n" \
+ " @throwTypeError(errorMessage);\n" \
+ " return value;\n" \
+ "})\n" \
+;
+
+
+#define DEFINE_BUILTIN_GENERATOR(codeName, functionName, overriddenName, argumentCount) \
+JSC::FunctionExecutable* codeName##Generator(JSC::VM& vm) \
+{\
+ JSVMClientData* clientData = static_cast<JSVMClientData*>(vm.clientData); \
+ return clientData->builtinFunctions().streamInternalsBuiltins().codeName##Executable()->link(vm, nullptr, clientData->builtinFunctions().streamInternalsBuiltins().codeName##Source(), std::nullopt, s_##codeName##Intrinsic); \
+}
+WEBCORE_FOREACH_STREAMINTERNALS_BUILTIN_CODE(DEFINE_BUILTIN_GENERATOR)
+#undef DEFINE_BUILTIN_GENERATOR
+
+
+} // namespace WebCore
diff --git a/src/bun.js/builtins/cpp/StreamInternalsBuiltins.h b/src/bun.js/builtins/cpp/StreamInternalsBuiltins.h
new file mode 100644
index 000000000..61fb36b0e
--- /dev/null
+++ b/src/bun.js/builtins/cpp/StreamInternalsBuiltins.h
@@ -0,0 +1,308 @@
+/*
+ * Copyright (c) 2015 Igalia
+ * Copyright (c) 2015 Igalia S.L.
+ * Copyright (c) 2015 Igalia.
+ * Copyright (c) 2015, 2016 Canon Inc. All rights reserved.
+ * Copyright (c) 2015, 2016, 2017 Canon Inc.
+ * Copyright (c) 2016, 2020 Apple Inc. All rights reserved.
+ * Copyright (c) 2022 Codeblog Corp. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+// DO NOT EDIT THIS FILE. It is automatically generated from JavaScript files for
+// builtins by the script: Source/JavaScriptCore/Scripts/generate-js-builtins.py
+
+#pragma once
+
+#include <JavaScriptCore/BuiltinUtils.h>
+#include <JavaScriptCore/Identifier.h>
+#include <JavaScriptCore/JSFunction.h>
+#include <JavaScriptCore/UnlinkedFunctionExecutable.h>
+
+namespace JSC {
+class FunctionExecutable;
+}
+
+namespace WebCore {
+
+/* StreamInternals */
+extern const char* const s_streamInternalsMarkPromiseAsHandledCode;
+extern const int s_streamInternalsMarkPromiseAsHandledCodeLength;
+extern const JSC::ConstructAbility s_streamInternalsMarkPromiseAsHandledCodeConstructAbility;
+extern const JSC::ConstructorKind s_streamInternalsMarkPromiseAsHandledCodeConstructorKind;
+extern const char* const s_streamInternalsShieldingPromiseResolveCode;
+extern const int s_streamInternalsShieldingPromiseResolveCodeLength;
+extern const JSC::ConstructAbility s_streamInternalsShieldingPromiseResolveCodeConstructAbility;
+extern const JSC::ConstructorKind s_streamInternalsShieldingPromiseResolveCodeConstructorKind;
+extern const char* const s_streamInternalsPromiseInvokeOrNoopMethodNoCatchCode;
+extern const int s_streamInternalsPromiseInvokeOrNoopMethodNoCatchCodeLength;
+extern const JSC::ConstructAbility s_streamInternalsPromiseInvokeOrNoopMethodNoCatchCodeConstructAbility;
+extern const JSC::ConstructorKind s_streamInternalsPromiseInvokeOrNoopMethodNoCatchCodeConstructorKind;
+extern const char* const s_streamInternalsPromiseInvokeOrNoopNoCatchCode;
+extern const int s_streamInternalsPromiseInvokeOrNoopNoCatchCodeLength;
+extern const JSC::ConstructAbility s_streamInternalsPromiseInvokeOrNoopNoCatchCodeConstructAbility;
+extern const JSC::ConstructorKind s_streamInternalsPromiseInvokeOrNoopNoCatchCodeConstructorKind;
+extern const char* const s_streamInternalsPromiseInvokeOrNoopMethodCode;
+extern const int s_streamInternalsPromiseInvokeOrNoopMethodCodeLength;
+extern const JSC::ConstructAbility s_streamInternalsPromiseInvokeOrNoopMethodCodeConstructAbility;
+extern const JSC::ConstructorKind s_streamInternalsPromiseInvokeOrNoopMethodCodeConstructorKind;
+extern const char* const s_streamInternalsPromiseInvokeOrNoopCode;
+extern const int s_streamInternalsPromiseInvokeOrNoopCodeLength;
+extern const JSC::ConstructAbility s_streamInternalsPromiseInvokeOrNoopCodeConstructAbility;
+extern const JSC::ConstructorKind s_streamInternalsPromiseInvokeOrNoopCodeConstructorKind;
+extern const char* const s_streamInternalsPromiseInvokeOrFallbackOrNoopCode;
+extern const int s_streamInternalsPromiseInvokeOrFallbackOrNoopCodeLength;
+extern const JSC::ConstructAbility s_streamInternalsPromiseInvokeOrFallbackOrNoopCodeConstructAbility;
+extern const JSC::ConstructorKind s_streamInternalsPromiseInvokeOrFallbackOrNoopCodeConstructorKind;
+extern const char* const s_streamInternalsValidateAndNormalizeQueuingStrategyCode;
+extern const int s_streamInternalsValidateAndNormalizeQueuingStrategyCodeLength;
+extern const JSC::ConstructAbility s_streamInternalsValidateAndNormalizeQueuingStrategyCodeConstructAbility;
+extern const JSC::ConstructorKind s_streamInternalsValidateAndNormalizeQueuingStrategyCodeConstructorKind;
+extern const char* const s_streamInternalsCreateFIFOCode;
+extern const int s_streamInternalsCreateFIFOCodeLength;
+extern const JSC::ConstructAbility s_streamInternalsCreateFIFOCodeConstructAbility;
+extern const JSC::ConstructorKind s_streamInternalsCreateFIFOCodeConstructorKind;
+extern const char* const s_streamInternalsNewQueueCode;
+extern const int s_streamInternalsNewQueueCodeLength;
+extern const JSC::ConstructAbility s_streamInternalsNewQueueCodeConstructAbility;
+extern const JSC::ConstructorKind s_streamInternalsNewQueueCodeConstructorKind;
+extern const char* const s_streamInternalsDequeueValueCode;
+extern const int s_streamInternalsDequeueValueCodeLength;
+extern const JSC::ConstructAbility s_streamInternalsDequeueValueCodeConstructAbility;
+extern const JSC::ConstructorKind s_streamInternalsDequeueValueCodeConstructorKind;
+extern const char* const s_streamInternalsEnqueueValueWithSizeCode;
+extern const int s_streamInternalsEnqueueValueWithSizeCodeLength;
+extern const JSC::ConstructAbility s_streamInternalsEnqueueValueWithSizeCodeConstructAbility;
+extern const JSC::ConstructorKind s_streamInternalsEnqueueValueWithSizeCodeConstructorKind;
+extern const char* const s_streamInternalsPeekQueueValueCode;
+extern const int s_streamInternalsPeekQueueValueCodeLength;
+extern const JSC::ConstructAbility s_streamInternalsPeekQueueValueCodeConstructAbility;
+extern const JSC::ConstructorKind s_streamInternalsPeekQueueValueCodeConstructorKind;
+extern const char* const s_streamInternalsResetQueueCode;
+extern const int s_streamInternalsResetQueueCodeLength;
+extern const JSC::ConstructAbility s_streamInternalsResetQueueCodeConstructAbility;
+extern const JSC::ConstructorKind s_streamInternalsResetQueueCodeConstructorKind;
+extern const char* const s_streamInternalsExtractSizeAlgorithmCode;
+extern const int s_streamInternalsExtractSizeAlgorithmCodeLength;
+extern const JSC::ConstructAbility s_streamInternalsExtractSizeAlgorithmCodeConstructAbility;
+extern const JSC::ConstructorKind s_streamInternalsExtractSizeAlgorithmCodeConstructorKind;
+extern const char* const s_streamInternalsExtractHighWaterMarkCode;
+extern const int s_streamInternalsExtractHighWaterMarkCodeLength;
+extern const JSC::ConstructAbility s_streamInternalsExtractHighWaterMarkCodeConstructAbility;
+extern const JSC::ConstructorKind s_streamInternalsExtractHighWaterMarkCodeConstructorKind;
+extern const char* const s_streamInternalsExtractHighWaterMarkFromQueuingStrategyInitCode;
+extern const int s_streamInternalsExtractHighWaterMarkFromQueuingStrategyInitCodeLength;
+extern const JSC::ConstructAbility s_streamInternalsExtractHighWaterMarkFromQueuingStrategyInitCodeConstructAbility;
+extern const JSC::ConstructorKind s_streamInternalsExtractHighWaterMarkFromQueuingStrategyInitCodeConstructorKind;
+extern const char* const s_streamInternalsCreateFulfilledPromiseCode;
+extern const int s_streamInternalsCreateFulfilledPromiseCodeLength;
+extern const JSC::ConstructAbility s_streamInternalsCreateFulfilledPromiseCodeConstructAbility;
+extern const JSC::ConstructorKind s_streamInternalsCreateFulfilledPromiseCodeConstructorKind;
+extern const char* const s_streamInternalsToDictionaryCode;
+extern const int s_streamInternalsToDictionaryCodeLength;
+extern const JSC::ConstructAbility s_streamInternalsToDictionaryCodeConstructAbility;
+extern const JSC::ConstructorKind s_streamInternalsToDictionaryCodeConstructorKind;
+
+#define WEBCORE_FOREACH_STREAMINTERNALS_BUILTIN_DATA(macro) \
+ macro(markPromiseAsHandled, streamInternalsMarkPromiseAsHandled, 1) \
+ macro(shieldingPromiseResolve, streamInternalsShieldingPromiseResolve, 1) \
+ macro(promiseInvokeOrNoopMethodNoCatch, streamInternalsPromiseInvokeOrNoopMethodNoCatch, 3) \
+ macro(promiseInvokeOrNoopNoCatch, streamInternalsPromiseInvokeOrNoopNoCatch, 3) \
+ macro(promiseInvokeOrNoopMethod, streamInternalsPromiseInvokeOrNoopMethod, 3) \
+ macro(promiseInvokeOrNoop, streamInternalsPromiseInvokeOrNoop, 3) \
+ macro(promiseInvokeOrFallbackOrNoop, streamInternalsPromiseInvokeOrFallbackOrNoop, 5) \
+ macro(validateAndNormalizeQueuingStrategy, streamInternalsValidateAndNormalizeQueuingStrategy, 2) \
+ macro(createFIFO, streamInternalsCreateFIFO, 0) \
+ macro(newQueue, streamInternalsNewQueue, 0) \
+ macro(dequeueValue, streamInternalsDequeueValue, 1) \
+ macro(enqueueValueWithSize, streamInternalsEnqueueValueWithSize, 3) \
+ macro(peekQueueValue, streamInternalsPeekQueueValue, 1) \
+ macro(resetQueue, streamInternalsResetQueue, 1) \
+ macro(extractSizeAlgorithm, streamInternalsExtractSizeAlgorithm, 1) \
+ macro(extractHighWaterMark, streamInternalsExtractHighWaterMark, 2) \
+ macro(extractHighWaterMarkFromQueuingStrategyInit, streamInternalsExtractHighWaterMarkFromQueuingStrategyInit, 1) \
+ macro(createFulfilledPromise, streamInternalsCreateFulfilledPromise, 1) \
+ macro(toDictionary, streamInternalsToDictionary, 3) \
+
+#define WEBCORE_BUILTIN_STREAMINTERNALS_MARKPROMISEASHANDLED 1
+#define WEBCORE_BUILTIN_STREAMINTERNALS_SHIELDINGPROMISERESOLVE 1
+#define WEBCORE_BUILTIN_STREAMINTERNALS_PROMISEINVOKEORNOOPMETHODNOCATCH 1
+#define WEBCORE_BUILTIN_STREAMINTERNALS_PROMISEINVOKEORNOOPNOCATCH 1
+#define WEBCORE_BUILTIN_STREAMINTERNALS_PROMISEINVOKEORNOOPMETHOD 1
+#define WEBCORE_BUILTIN_STREAMINTERNALS_PROMISEINVOKEORNOOP 1
+#define WEBCORE_BUILTIN_STREAMINTERNALS_PROMISEINVOKEORFALLBACKORNOOP 1
+#define WEBCORE_BUILTIN_STREAMINTERNALS_VALIDATEANDNORMALIZEQUEUINGSTRATEGY 1
+#define WEBCORE_BUILTIN_STREAMINTERNALS_CREATEFIFO 1
+#define WEBCORE_BUILTIN_STREAMINTERNALS_NEWQUEUE 1
+#define WEBCORE_BUILTIN_STREAMINTERNALS_DEQUEUEVALUE 1
+#define WEBCORE_BUILTIN_STREAMINTERNALS_ENQUEUEVALUEWITHSIZE 1
+#define WEBCORE_BUILTIN_STREAMINTERNALS_PEEKQUEUEVALUE 1
+#define WEBCORE_BUILTIN_STREAMINTERNALS_RESETQUEUE 1
+#define WEBCORE_BUILTIN_STREAMINTERNALS_EXTRACTSIZEALGORITHM 1
+#define WEBCORE_BUILTIN_STREAMINTERNALS_EXTRACTHIGHWATERMARK 1
+#define WEBCORE_BUILTIN_STREAMINTERNALS_EXTRACTHIGHWATERMARKFROMQUEUINGSTRATEGYINIT 1
+#define WEBCORE_BUILTIN_STREAMINTERNALS_CREATEFULFILLEDPROMISE 1
+#define WEBCORE_BUILTIN_STREAMINTERNALS_TODICTIONARY 1
+
+#define WEBCORE_FOREACH_STREAMINTERNALS_BUILTIN_CODE(macro) \
+ macro(streamInternalsMarkPromiseAsHandledCode, markPromiseAsHandled, ASCIILiteral(), s_streamInternalsMarkPromiseAsHandledCodeLength) \
+ macro(streamInternalsShieldingPromiseResolveCode, shieldingPromiseResolve, ASCIILiteral(), s_streamInternalsShieldingPromiseResolveCodeLength) \
+ macro(streamInternalsPromiseInvokeOrNoopMethodNoCatchCode, promiseInvokeOrNoopMethodNoCatch, ASCIILiteral(), s_streamInternalsPromiseInvokeOrNoopMethodNoCatchCodeLength) \
+ macro(streamInternalsPromiseInvokeOrNoopNoCatchCode, promiseInvokeOrNoopNoCatch, ASCIILiteral(), s_streamInternalsPromiseInvokeOrNoopNoCatchCodeLength) \
+ macro(streamInternalsPromiseInvokeOrNoopMethodCode, promiseInvokeOrNoopMethod, ASCIILiteral(), s_streamInternalsPromiseInvokeOrNoopMethodCodeLength) \
+ macro(streamInternalsPromiseInvokeOrNoopCode, promiseInvokeOrNoop, ASCIILiteral(), s_streamInternalsPromiseInvokeOrNoopCodeLength) \
+ macro(streamInternalsPromiseInvokeOrFallbackOrNoopCode, promiseInvokeOrFallbackOrNoop, ASCIILiteral(), s_streamInternalsPromiseInvokeOrFallbackOrNoopCodeLength) \
+ macro(streamInternalsValidateAndNormalizeQueuingStrategyCode, validateAndNormalizeQueuingStrategy, ASCIILiteral(), s_streamInternalsValidateAndNormalizeQueuingStrategyCodeLength) \
+ macro(streamInternalsCreateFIFOCode, createFIFO, ASCIILiteral(), s_streamInternalsCreateFIFOCodeLength) \
+ macro(streamInternalsNewQueueCode, newQueue, ASCIILiteral(), s_streamInternalsNewQueueCodeLength) \
+ macro(streamInternalsDequeueValueCode, dequeueValue, ASCIILiteral(), s_streamInternalsDequeueValueCodeLength) \
+ macro(streamInternalsEnqueueValueWithSizeCode, enqueueValueWithSize, ASCIILiteral(), s_streamInternalsEnqueueValueWithSizeCodeLength) \
+ macro(streamInternalsPeekQueueValueCode, peekQueueValue, ASCIILiteral(), s_streamInternalsPeekQueueValueCodeLength) \
+ macro(streamInternalsResetQueueCode, resetQueue, ASCIILiteral(), s_streamInternalsResetQueueCodeLength) \
+ macro(streamInternalsExtractSizeAlgorithmCode, extractSizeAlgorithm, ASCIILiteral(), s_streamInternalsExtractSizeAlgorithmCodeLength) \
+ macro(streamInternalsExtractHighWaterMarkCode, extractHighWaterMark, ASCIILiteral(), s_streamInternalsExtractHighWaterMarkCodeLength) \
+ macro(streamInternalsExtractHighWaterMarkFromQueuingStrategyInitCode, extractHighWaterMarkFromQueuingStrategyInit, ASCIILiteral(), s_streamInternalsExtractHighWaterMarkFromQueuingStrategyInitCodeLength) \
+ macro(streamInternalsCreateFulfilledPromiseCode, createFulfilledPromise, ASCIILiteral(), s_streamInternalsCreateFulfilledPromiseCodeLength) \
+ macro(streamInternalsToDictionaryCode, toDictionary, ASCIILiteral(), s_streamInternalsToDictionaryCodeLength) \
+
+#define WEBCORE_FOREACH_STREAMINTERNALS_BUILTIN_FUNCTION_NAME(macro) \
+ macro(createFIFO) \
+ macro(createFulfilledPromise) \
+ macro(dequeueValue) \
+ macro(enqueueValueWithSize) \
+ macro(extractHighWaterMark) \
+ macro(extractHighWaterMarkFromQueuingStrategyInit) \
+ macro(extractSizeAlgorithm) \
+ macro(markPromiseAsHandled) \
+ macro(newQueue) \
+ macro(peekQueueValue) \
+ macro(promiseInvokeOrFallbackOrNoop) \
+ macro(promiseInvokeOrNoop) \
+ macro(promiseInvokeOrNoopMethod) \
+ macro(promiseInvokeOrNoopMethodNoCatch) \
+ macro(promiseInvokeOrNoopNoCatch) \
+ macro(resetQueue) \
+ macro(shieldingPromiseResolve) \
+ macro(toDictionary) \
+ macro(validateAndNormalizeQueuingStrategy) \
+
+#define DECLARE_BUILTIN_GENERATOR(codeName, functionName, overriddenName, argumentCount) \
+ JSC::FunctionExecutable* codeName##Generator(JSC::VM&);
+
+WEBCORE_FOREACH_STREAMINTERNALS_BUILTIN_CODE(DECLARE_BUILTIN_GENERATOR)
+#undef DECLARE_BUILTIN_GENERATOR
+
+class StreamInternalsBuiltinsWrapper : private JSC::WeakHandleOwner {
+public:
+ explicit StreamInternalsBuiltinsWrapper(JSC::VM& vm)
+ : m_vm(vm)
+ WEBCORE_FOREACH_STREAMINTERNALS_BUILTIN_FUNCTION_NAME(INITIALIZE_BUILTIN_NAMES)
+#define INITIALIZE_BUILTIN_SOURCE_MEMBERS(name, functionName, overriddenName, length) , m_##name##Source(JSC::makeSource(StringImpl::createWithoutCopying(s_##name, length), { }))
+ WEBCORE_FOREACH_STREAMINTERNALS_BUILTIN_CODE(INITIALIZE_BUILTIN_SOURCE_MEMBERS)
+#undef INITIALIZE_BUILTIN_SOURCE_MEMBERS
+ {
+ }
+
+#define EXPOSE_BUILTIN_EXECUTABLES(name, functionName, overriddenName, length) \
+ JSC::UnlinkedFunctionExecutable* name##Executable(); \
+ const JSC::SourceCode& name##Source() const { return m_##name##Source; }
+ WEBCORE_FOREACH_STREAMINTERNALS_BUILTIN_CODE(EXPOSE_BUILTIN_EXECUTABLES)
+#undef EXPOSE_BUILTIN_EXECUTABLES
+
+ WEBCORE_FOREACH_STREAMINTERNALS_BUILTIN_FUNCTION_NAME(DECLARE_BUILTIN_IDENTIFIER_ACCESSOR)
+
+ void exportNames();
+
+private:
+ JSC::VM& m_vm;
+
+ WEBCORE_FOREACH_STREAMINTERNALS_BUILTIN_FUNCTION_NAME(DECLARE_BUILTIN_NAMES)
+
+#define DECLARE_BUILTIN_SOURCE_MEMBERS(name, functionName, overriddenName, length) \
+ JSC::SourceCode m_##name##Source;\
+ JSC::Weak<JSC::UnlinkedFunctionExecutable> m_##name##Executable;
+ WEBCORE_FOREACH_STREAMINTERNALS_BUILTIN_CODE(DECLARE_BUILTIN_SOURCE_MEMBERS)
+#undef DECLARE_BUILTIN_SOURCE_MEMBERS
+
+};
+
+#define DEFINE_BUILTIN_EXECUTABLES(name, functionName, overriddenName, length) \
+inline JSC::UnlinkedFunctionExecutable* StreamInternalsBuiltinsWrapper::name##Executable() \
+{\
+ if (!m_##name##Executable) {\
+ JSC::Identifier executableName = functionName##PublicName();\
+ if (overriddenName)\
+ executableName = JSC::Identifier::fromString(m_vm, overriddenName);\
+ m_##name##Executable = JSC::Weak<JSC::UnlinkedFunctionExecutable>(JSC::createBuiltinExecutable(m_vm, m_##name##Source, executableName, s_##name##ConstructorKind, s_##name##ConstructAbility), this, &m_##name##Executable);\
+ }\
+ return m_##name##Executable.get();\
+}
+WEBCORE_FOREACH_STREAMINTERNALS_BUILTIN_CODE(DEFINE_BUILTIN_EXECUTABLES)
+#undef DEFINE_BUILTIN_EXECUTABLES
+
+inline void StreamInternalsBuiltinsWrapper::exportNames()
+{
+#define EXPORT_FUNCTION_NAME(name) m_vm.propertyNames->appendExternalName(name##PublicName(), name##PrivateName());
+ WEBCORE_FOREACH_STREAMINTERNALS_BUILTIN_FUNCTION_NAME(EXPORT_FUNCTION_NAME)
+#undef EXPORT_FUNCTION_NAME
+}
+
+class StreamInternalsBuiltinFunctions {
+public:
+ explicit StreamInternalsBuiltinFunctions(JSC::VM& vm) : m_vm(vm) { }
+
+ void init(JSC::JSGlobalObject&);
+ template<typename Visitor> void visit(Visitor&);
+
+public:
+ JSC::VM& m_vm;
+
+#define DECLARE_BUILTIN_SOURCE_MEMBERS(functionName) \
+ JSC::WriteBarrier<JSC::JSFunction> m_##functionName##Function;
+ WEBCORE_FOREACH_STREAMINTERNALS_BUILTIN_FUNCTION_NAME(DECLARE_BUILTIN_SOURCE_MEMBERS)
+#undef DECLARE_BUILTIN_SOURCE_MEMBERS
+};
+
+inline void StreamInternalsBuiltinFunctions::init(JSC::JSGlobalObject& globalObject)
+{
+#define EXPORT_FUNCTION(codeName, functionName, overriddenName, length)\
+ m_##functionName##Function.set(m_vm, &globalObject, JSC::JSFunction::create(m_vm, codeName##Generator(m_vm), &globalObject));
+ WEBCORE_FOREACH_STREAMINTERNALS_BUILTIN_CODE(EXPORT_FUNCTION)
+#undef EXPORT_FUNCTION
+}
+
+template<typename Visitor>
+inline void StreamInternalsBuiltinFunctions::visit(Visitor& visitor)
+{
+#define VISIT_FUNCTION(name) visitor.append(m_##name##Function);
+ WEBCORE_FOREACH_STREAMINTERNALS_BUILTIN_FUNCTION_NAME(VISIT_FUNCTION)
+#undef VISIT_FUNCTION
+}
+
+template void StreamInternalsBuiltinFunctions::visit(JSC::AbstractSlotVisitor&);
+template void StreamInternalsBuiltinFunctions::visit(JSC::SlotVisitor&);
+
+
+
+} // namespace WebCore
diff --git a/src/bun.js/builtins/cpp/TransformStreamBuiltins.cpp b/src/bun.js/builtins/cpp/TransformStreamBuiltins.cpp
new file mode 100644
index 000000000..027abb5c8
--- /dev/null
+++ b/src/bun.js/builtins/cpp/TransformStreamBuiltins.cpp
@@ -0,0 +1,170 @@
+/*
+ * Copyright (c) 2015 Igalia
+ * Copyright (c) 2015 Igalia S.L.
+ * Copyright (c) 2015 Igalia.
+ * Copyright (c) 2015, 2016 Canon Inc. All rights reserved.
+ * Copyright (c) 2015, 2016, 2017 Canon Inc.
+ * Copyright (c) 2016, 2020 Apple Inc. All rights reserved.
+ * Copyright (c) 2022 Codeblog Corp. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+// DO NOT EDIT THIS FILE. It is automatically generated from JavaScript files for
+// builtins by the script: Source/JavaScriptCore/Scripts/generate-js-builtins.py
+
+#include "config.h"
+#include "TransformStreamBuiltins.h"
+
+#include "WebCoreJSClientData.h"
+#include <JavaScriptCore/HeapInlines.h>
+#include <JavaScriptCore/IdentifierInlines.h>
+#include <JavaScriptCore/Intrinsic.h>
+#include <JavaScriptCore/JSCJSValueInlines.h>
+#include <JavaScriptCore/JSCellInlines.h>
+#include <JavaScriptCore/StructureInlines.h>
+#include <JavaScriptCore/VM.h>
+
+namespace WebCore {
+
+const JSC::ConstructAbility s_transformStreamInitializeTransformStreamCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_transformStreamInitializeTransformStreamCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_transformStreamInitializeTransformStreamCodeLength = 2727;
+static const JSC::Intrinsic s_transformStreamInitializeTransformStreamCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_transformStreamInitializeTransformStreamCode =
+ "(function ()\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " let transformer = arguments[0];\n" \
+ "\n" \
+ " //\n" \
+ " if (@isObject(transformer) && @getByIdDirectPrivate(transformer, \"TransformStream\"))\n" \
+ " return this;\n" \
+ "\n" \
+ " let writableStrategy = arguments[1];\n" \
+ " let readableStrategy = arguments[2];\n" \
+ "\n" \
+ " if (transformer === @undefined)\n" \
+ " transformer = null;\n" \
+ "\n" \
+ " if (readableStrategy === @undefined)\n" \
+ " readableStrategy = { };\n" \
+ "\n" \
+ " if (writableStrategy === @undefined)\n" \
+ " writableStrategy = { };\n" \
+ "\n" \
+ " let transformerDict = { };\n" \
+ " if (transformer !== null) {\n" \
+ " if (\"start\" in transformer) {\n" \
+ " transformerDict[\"start\"] = transformer[\"start\"];\n" \
+ " if (typeof transformerDict[\"start\"] !== \"function\")\n" \
+ " @throwTypeError(\"transformer.start should be a function\");\n" \
+ " }\n" \
+ " if (\"transform\" in transformer) {\n" \
+ " transformerDict[\"transform\"] = transformer[\"transform\"];\n" \
+ " if (typeof transformerDict[\"transform\"] !== \"function\")\n" \
+ " @throwTypeError(\"transformer.transform should be a function\");\n" \
+ " }\n" \
+ " if (\"flush\" in transformer) {\n" \
+ " transformerDict[\"flush\"] = transformer[\"flush\"];\n" \
+ " if (typeof transformerDict[\"flush\"] !== \"function\")\n" \
+ " @throwTypeError(\"transformer.flush should be a function\");\n" \
+ " }\n" \
+ "\n" \
+ " if (\"readableType\" in transformer)\n" \
+ " @throwRangeError(\"TransformStream transformer has a readableType\");\n" \
+ " if (\"writableType\" in transformer)\n" \
+ " @throwRangeError(\"TransformStream transformer has a writableType\");\n" \
+ " }\n" \
+ "\n" \
+ " const readableHighWaterMark = @extractHighWaterMark(readableStrategy, 0);\n" \
+ " const readableSizeAlgorithm = @extractSizeAlgorithm(readableStrategy);\n" \
+ "\n" \
+ " const writableHighWaterMark = @extractHighWaterMark(writableStrategy, 1);\n" \
+ " const writableSizeAlgorithm = @extractSizeAlgorithm(writableStrategy);\n" \
+ "\n" \
+ " const startPromiseCapability = @newPromiseCapability(@Promise);\n" \
+ " @initializeTransformStream(this, startPromiseCapability.@promise, writableHighWaterMark, writableSizeAlgorithm, readableHighWaterMark, readableSizeAlgorithm);\n" \
+ " @setUpTransformStreamDefaultControllerFromTransformer(this, transformer, transformerDict);\n" \
+ "\n" \
+ " if (\"start\" in transformerDict) {\n" \
+ " const controller = @getByIdDirectPrivate(this, \"controller\");\n" \
+ " const startAlgorithm = () => @promiseInvokeOrNoopMethodNoCatch(transformer, transformerDict[\"start\"], [controller]);\n" \
+ " startAlgorithm().@then(() => {\n" \
+ " //\n" \
+ " startPromiseCapability.@resolve.@call();\n" \
+ " }, (error) => {\n" \
+ " startPromiseCapability.@reject.@call(@undefined, error);\n" \
+ " });\n" \
+ " } else\n" \
+ " startPromiseCapability.@resolve.@call();\n" \
+ "\n" \
+ " return this;\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_transformStreamReadableCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_transformStreamReadableCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_transformStreamReadableCodeLength = 190;
+static const JSC::Intrinsic s_transformStreamReadableCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_transformStreamReadableCode =
+ "(function ()\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " if (!@isTransformStream(this))\n" \
+ " throw @makeThisTypeError(\"TransformStream\", \"readable\");\n" \
+ "\n" \
+ " return @getByIdDirectPrivate(this, \"readable\");\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_transformStreamWritableCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_transformStreamWritableCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_transformStreamWritableCodeLength = 190;
+static const JSC::Intrinsic s_transformStreamWritableCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_transformStreamWritableCode =
+ "(function ()\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " if (!@isTransformStream(this))\n" \
+ " throw @makeThisTypeError(\"TransformStream\", \"writable\");\n" \
+ "\n" \
+ " return @getByIdDirectPrivate(this, \"writable\");\n" \
+ "})\n" \
+;
+
+
+#define DEFINE_BUILTIN_GENERATOR(codeName, functionName, overriddenName, argumentCount) \
+JSC::FunctionExecutable* codeName##Generator(JSC::VM& vm) \
+{\
+ JSVMClientData* clientData = static_cast<JSVMClientData*>(vm.clientData); \
+ return clientData->builtinFunctions().transformStreamBuiltins().codeName##Executable()->link(vm, nullptr, clientData->builtinFunctions().transformStreamBuiltins().codeName##Source(), std::nullopt, s_##codeName##Intrinsic); \
+}
+WEBCORE_FOREACH_TRANSFORMSTREAM_BUILTIN_CODE(DEFINE_BUILTIN_GENERATOR)
+#undef DEFINE_BUILTIN_GENERATOR
+
+
+} // namespace WebCore
diff --git a/src/bun.js/builtins/cpp/TransformStreamBuiltins.h b/src/bun.js/builtins/cpp/TransformStreamBuiltins.h
new file mode 100644
index 000000000..bdf0c07cc
--- /dev/null
+++ b/src/bun.js/builtins/cpp/TransformStreamBuiltins.h
@@ -0,0 +1,143 @@
+/*
+ * Copyright (c) 2015 Igalia
+ * Copyright (c) 2015 Igalia S.L.
+ * Copyright (c) 2015 Igalia.
+ * Copyright (c) 2015, 2016 Canon Inc. All rights reserved.
+ * Copyright (c) 2015, 2016, 2017 Canon Inc.
+ * Copyright (c) 2016, 2020 Apple Inc. All rights reserved.
+ * Copyright (c) 2022 Codeblog Corp. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+// DO NOT EDIT THIS FILE. It is automatically generated from JavaScript files for
+// builtins by the script: Source/JavaScriptCore/Scripts/generate-js-builtins.py
+
+#pragma once
+
+#include <JavaScriptCore/BuiltinUtils.h>
+#include <JavaScriptCore/Identifier.h>
+#include <JavaScriptCore/JSFunction.h>
+#include <JavaScriptCore/UnlinkedFunctionExecutable.h>
+
+namespace JSC {
+class FunctionExecutable;
+}
+
+namespace WebCore {
+
+/* TransformStream */
+extern const char* const s_transformStreamInitializeTransformStreamCode;
+extern const int s_transformStreamInitializeTransformStreamCodeLength;
+extern const JSC::ConstructAbility s_transformStreamInitializeTransformStreamCodeConstructAbility;
+extern const JSC::ConstructorKind s_transformStreamInitializeTransformStreamCodeConstructorKind;
+extern const char* const s_transformStreamReadableCode;
+extern const int s_transformStreamReadableCodeLength;
+extern const JSC::ConstructAbility s_transformStreamReadableCodeConstructAbility;
+extern const JSC::ConstructorKind s_transformStreamReadableCodeConstructorKind;
+extern const char* const s_transformStreamWritableCode;
+extern const int s_transformStreamWritableCodeLength;
+extern const JSC::ConstructAbility s_transformStreamWritableCodeConstructAbility;
+extern const JSC::ConstructorKind s_transformStreamWritableCodeConstructorKind;
+
+#define WEBCORE_FOREACH_TRANSFORMSTREAM_BUILTIN_DATA(macro) \
+ macro(initializeTransformStream, transformStreamInitializeTransformStream, 0) \
+ macro(readable, transformStreamReadable, 0) \
+ macro(writable, transformStreamWritable, 0) \
+
+#define WEBCORE_BUILTIN_TRANSFORMSTREAM_INITIALIZETRANSFORMSTREAM 1
+#define WEBCORE_BUILTIN_TRANSFORMSTREAM_READABLE 1
+#define WEBCORE_BUILTIN_TRANSFORMSTREAM_WRITABLE 1
+
+#define WEBCORE_FOREACH_TRANSFORMSTREAM_BUILTIN_CODE(macro) \
+ macro(transformStreamInitializeTransformStreamCode, initializeTransformStream, ASCIILiteral(), s_transformStreamInitializeTransformStreamCodeLength) \
+ macro(transformStreamReadableCode, readable, "get readable"_s, s_transformStreamReadableCodeLength) \
+ macro(transformStreamWritableCode, writable, ASCIILiteral(), s_transformStreamWritableCodeLength) \
+
+#define WEBCORE_FOREACH_TRANSFORMSTREAM_BUILTIN_FUNCTION_NAME(macro) \
+ macro(initializeTransformStream) \
+ macro(readable) \
+ macro(writable) \
+
+#define DECLARE_BUILTIN_GENERATOR(codeName, functionName, overriddenName, argumentCount) \
+ JSC::FunctionExecutable* codeName##Generator(JSC::VM&);
+
+WEBCORE_FOREACH_TRANSFORMSTREAM_BUILTIN_CODE(DECLARE_BUILTIN_GENERATOR)
+#undef DECLARE_BUILTIN_GENERATOR
+
+class TransformStreamBuiltinsWrapper : private JSC::WeakHandleOwner {
+public:
+ explicit TransformStreamBuiltinsWrapper(JSC::VM& vm)
+ : m_vm(vm)
+ WEBCORE_FOREACH_TRANSFORMSTREAM_BUILTIN_FUNCTION_NAME(INITIALIZE_BUILTIN_NAMES)
+#define INITIALIZE_BUILTIN_SOURCE_MEMBERS(name, functionName, overriddenName, length) , m_##name##Source(JSC::makeSource(StringImpl::createWithoutCopying(s_##name, length), { }))
+ WEBCORE_FOREACH_TRANSFORMSTREAM_BUILTIN_CODE(INITIALIZE_BUILTIN_SOURCE_MEMBERS)
+#undef INITIALIZE_BUILTIN_SOURCE_MEMBERS
+ {
+ }
+
+#define EXPOSE_BUILTIN_EXECUTABLES(name, functionName, overriddenName, length) \
+ JSC::UnlinkedFunctionExecutable* name##Executable(); \
+ const JSC::SourceCode& name##Source() const { return m_##name##Source; }
+ WEBCORE_FOREACH_TRANSFORMSTREAM_BUILTIN_CODE(EXPOSE_BUILTIN_EXECUTABLES)
+#undef EXPOSE_BUILTIN_EXECUTABLES
+
+ WEBCORE_FOREACH_TRANSFORMSTREAM_BUILTIN_FUNCTION_NAME(DECLARE_BUILTIN_IDENTIFIER_ACCESSOR)
+
+ void exportNames();
+
+private:
+ JSC::VM& m_vm;
+
+ WEBCORE_FOREACH_TRANSFORMSTREAM_BUILTIN_FUNCTION_NAME(DECLARE_BUILTIN_NAMES)
+
+#define DECLARE_BUILTIN_SOURCE_MEMBERS(name, functionName, overriddenName, length) \
+ JSC::SourceCode m_##name##Source;\
+ JSC::Weak<JSC::UnlinkedFunctionExecutable> m_##name##Executable;
+ WEBCORE_FOREACH_TRANSFORMSTREAM_BUILTIN_CODE(DECLARE_BUILTIN_SOURCE_MEMBERS)
+#undef DECLARE_BUILTIN_SOURCE_MEMBERS
+
+};
+
+#define DEFINE_BUILTIN_EXECUTABLES(name, functionName, overriddenName, length) \
+inline JSC::UnlinkedFunctionExecutable* TransformStreamBuiltinsWrapper::name##Executable() \
+{\
+ if (!m_##name##Executable) {\
+ JSC::Identifier executableName = functionName##PublicName();\
+ if (overriddenName)\
+ executableName = JSC::Identifier::fromString(m_vm, overriddenName);\
+ m_##name##Executable = JSC::Weak<JSC::UnlinkedFunctionExecutable>(JSC::createBuiltinExecutable(m_vm, m_##name##Source, executableName, s_##name##ConstructorKind, s_##name##ConstructAbility), this, &m_##name##Executable);\
+ }\
+ return m_##name##Executable.get();\
+}
+WEBCORE_FOREACH_TRANSFORMSTREAM_BUILTIN_CODE(DEFINE_BUILTIN_EXECUTABLES)
+#undef DEFINE_BUILTIN_EXECUTABLES
+
+inline void TransformStreamBuiltinsWrapper::exportNames()
+{
+#define EXPORT_FUNCTION_NAME(name) m_vm.propertyNames->appendExternalName(name##PublicName(), name##PrivateName());
+ WEBCORE_FOREACH_TRANSFORMSTREAM_BUILTIN_FUNCTION_NAME(EXPORT_FUNCTION_NAME)
+#undef EXPORT_FUNCTION_NAME
+}
+
+} // namespace WebCore
diff --git a/src/bun.js/builtins/cpp/TransformStreamDefaultControllerBuiltins.cpp b/src/bun.js/builtins/cpp/TransformStreamDefaultControllerBuiltins.cpp
new file mode 100644
index 000000000..31c509a1c
--- /dev/null
+++ b/src/bun.js/builtins/cpp/TransformStreamDefaultControllerBuiltins.cpp
@@ -0,0 +1,142 @@
+/*
+ * Copyright (c) 2015 Igalia
+ * Copyright (c) 2015 Igalia S.L.
+ * Copyright (c) 2015 Igalia.
+ * Copyright (c) 2015, 2016 Canon Inc. All rights reserved.
+ * Copyright (c) 2015, 2016, 2017 Canon Inc.
+ * Copyright (c) 2016, 2020 Apple Inc. All rights reserved.
+ * Copyright (c) 2022 Codeblog Corp. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+// DO NOT EDIT THIS FILE. It is automatically generated from JavaScript files for
+// builtins by the script: Source/JavaScriptCore/Scripts/generate-js-builtins.py
+
+#include "config.h"
+#include "TransformStreamDefaultControllerBuiltins.h"
+
+#include "WebCoreJSClientData.h"
+#include <JavaScriptCore/HeapInlines.h>
+#include <JavaScriptCore/IdentifierInlines.h>
+#include <JavaScriptCore/Intrinsic.h>
+#include <JavaScriptCore/JSCJSValueInlines.h>
+#include <JavaScriptCore/JSCellInlines.h>
+#include <JavaScriptCore/StructureInlines.h>
+#include <JavaScriptCore/VM.h>
+
+namespace WebCore {
+
+const JSC::ConstructAbility s_transformStreamDefaultControllerInitializeTransformStreamDefaultControllerCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_transformStreamDefaultControllerInitializeTransformStreamDefaultControllerCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_transformStreamDefaultControllerInitializeTransformStreamDefaultControllerCodeLength = 54;
+static const JSC::Intrinsic s_transformStreamDefaultControllerInitializeTransformStreamDefaultControllerCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_transformStreamDefaultControllerInitializeTransformStreamDefaultControllerCode =
+ "(function ()\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " return this;\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_transformStreamDefaultControllerDesiredSizeCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_transformStreamDefaultControllerDesiredSizeCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_transformStreamDefaultControllerDesiredSizeCodeLength = 465;
+static const JSC::Intrinsic s_transformStreamDefaultControllerDesiredSizeCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_transformStreamDefaultControllerDesiredSizeCode =
+ "(function ()\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " if (!@isTransformStreamDefaultController(this))\n" \
+ " throw @makeThisTypeError(\"TransformStreamDefaultController\", \"enqueue\");\n" \
+ "\n" \
+ " const stream = @getByIdDirectPrivate(this, \"stream\");\n" \
+ " const readable = @getByIdDirectPrivate(stream, \"readable\");\n" \
+ " const readableController = @getByIdDirectPrivate(readable, \"readableStreamController\");\n" \
+ "\n" \
+ " return @readableStreamDefaultControllerGetDesiredSize(readableController);\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_transformStreamDefaultControllerEnqueueCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_transformStreamDefaultControllerEnqueueCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_transformStreamDefaultControllerEnqueueCodeLength = 235;
+static const JSC::Intrinsic s_transformStreamDefaultControllerEnqueueCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_transformStreamDefaultControllerEnqueueCode =
+ "(function (chunk)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " if (!@isTransformStreamDefaultController(this))\n" \
+ " throw @makeThisTypeError(\"TransformStreamDefaultController\", \"enqueue\");\n" \
+ "\n" \
+ " @transformStreamDefaultControllerEnqueue(this, chunk);\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_transformStreamDefaultControllerErrorCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_transformStreamDefaultControllerErrorCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_transformStreamDefaultControllerErrorCodeLength = 223;
+static const JSC::Intrinsic s_transformStreamDefaultControllerErrorCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_transformStreamDefaultControllerErrorCode =
+ "(function (e)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " if (!@isTransformStreamDefaultController(this))\n" \
+ " throw @makeThisTypeError(\"TransformStreamDefaultController\", \"error\");\n" \
+ "\n" \
+ " @transformStreamDefaultControllerError(this, e);\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_transformStreamDefaultControllerTerminateCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_transformStreamDefaultControllerTerminateCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_transformStreamDefaultControllerTerminateCodeLength = 227;
+static const JSC::Intrinsic s_transformStreamDefaultControllerTerminateCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_transformStreamDefaultControllerTerminateCode =
+ "(function ()\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " if (!@isTransformStreamDefaultController(this))\n" \
+ " throw @makeThisTypeError(\"TransformStreamDefaultController\", \"terminate\");\n" \
+ "\n" \
+ " @transformStreamDefaultControllerTerminate(this);\n" \
+ "})\n" \
+;
+
+
+#define DEFINE_BUILTIN_GENERATOR(codeName, functionName, overriddenName, argumentCount) \
+JSC::FunctionExecutable* codeName##Generator(JSC::VM& vm) \
+{\
+ JSVMClientData* clientData = static_cast<JSVMClientData*>(vm.clientData); \
+ return clientData->builtinFunctions().transformStreamDefaultControllerBuiltins().codeName##Executable()->link(vm, nullptr, clientData->builtinFunctions().transformStreamDefaultControllerBuiltins().codeName##Source(), std::nullopt, s_##codeName##Intrinsic); \
+}
+WEBCORE_FOREACH_TRANSFORMSTREAMDEFAULTCONTROLLER_BUILTIN_CODE(DEFINE_BUILTIN_GENERATOR)
+#undef DEFINE_BUILTIN_GENERATOR
+
+
+} // namespace WebCore
diff --git a/src/bun.js/builtins/cpp/TransformStreamDefaultControllerBuiltins.h b/src/bun.js/builtins/cpp/TransformStreamDefaultControllerBuiltins.h
new file mode 100644
index 000000000..302e2e21c
--- /dev/null
+++ b/src/bun.js/builtins/cpp/TransformStreamDefaultControllerBuiltins.h
@@ -0,0 +1,159 @@
+/*
+ * Copyright (c) 2015 Igalia
+ * Copyright (c) 2015 Igalia S.L.
+ * Copyright (c) 2015 Igalia.
+ * Copyright (c) 2015, 2016 Canon Inc. All rights reserved.
+ * Copyright (c) 2015, 2016, 2017 Canon Inc.
+ * Copyright (c) 2016, 2020 Apple Inc. All rights reserved.
+ * Copyright (c) 2022 Codeblog Corp. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+// DO NOT EDIT THIS FILE. It is automatically generated from JavaScript files for
+// builtins by the script: Source/JavaScriptCore/Scripts/generate-js-builtins.py
+
+#pragma once
+
+#include <JavaScriptCore/BuiltinUtils.h>
+#include <JavaScriptCore/Identifier.h>
+#include <JavaScriptCore/JSFunction.h>
+#include <JavaScriptCore/UnlinkedFunctionExecutable.h>
+
+namespace JSC {
+class FunctionExecutable;
+}
+
+namespace WebCore {
+
+/* TransformStreamDefaultController */
+extern const char* const s_transformStreamDefaultControllerInitializeTransformStreamDefaultControllerCode;
+extern const int s_transformStreamDefaultControllerInitializeTransformStreamDefaultControllerCodeLength;
+extern const JSC::ConstructAbility s_transformStreamDefaultControllerInitializeTransformStreamDefaultControllerCodeConstructAbility;
+extern const JSC::ConstructorKind s_transformStreamDefaultControllerInitializeTransformStreamDefaultControllerCodeConstructorKind;
+extern const char* const s_transformStreamDefaultControllerDesiredSizeCode;
+extern const int s_transformStreamDefaultControllerDesiredSizeCodeLength;
+extern const JSC::ConstructAbility s_transformStreamDefaultControllerDesiredSizeCodeConstructAbility;
+extern const JSC::ConstructorKind s_transformStreamDefaultControllerDesiredSizeCodeConstructorKind;
+extern const char* const s_transformStreamDefaultControllerEnqueueCode;
+extern const int s_transformStreamDefaultControllerEnqueueCodeLength;
+extern const JSC::ConstructAbility s_transformStreamDefaultControllerEnqueueCodeConstructAbility;
+extern const JSC::ConstructorKind s_transformStreamDefaultControllerEnqueueCodeConstructorKind;
+extern const char* const s_transformStreamDefaultControllerErrorCode;
+extern const int s_transformStreamDefaultControllerErrorCodeLength;
+extern const JSC::ConstructAbility s_transformStreamDefaultControllerErrorCodeConstructAbility;
+extern const JSC::ConstructorKind s_transformStreamDefaultControllerErrorCodeConstructorKind;
+extern const char* const s_transformStreamDefaultControllerTerminateCode;
+extern const int s_transformStreamDefaultControllerTerminateCodeLength;
+extern const JSC::ConstructAbility s_transformStreamDefaultControllerTerminateCodeConstructAbility;
+extern const JSC::ConstructorKind s_transformStreamDefaultControllerTerminateCodeConstructorKind;
+
+#define WEBCORE_FOREACH_TRANSFORMSTREAMDEFAULTCONTROLLER_BUILTIN_DATA(macro) \
+ macro(initializeTransformStreamDefaultController, transformStreamDefaultControllerInitializeTransformStreamDefaultController, 0) \
+ macro(desiredSize, transformStreamDefaultControllerDesiredSize, 0) \
+ macro(enqueue, transformStreamDefaultControllerEnqueue, 1) \
+ macro(error, transformStreamDefaultControllerError, 1) \
+ macro(terminate, transformStreamDefaultControllerTerminate, 0) \
+
+#define WEBCORE_BUILTIN_TRANSFORMSTREAMDEFAULTCONTROLLER_INITIALIZETRANSFORMSTREAMDEFAULTCONTROLLER 1
+#define WEBCORE_BUILTIN_TRANSFORMSTREAMDEFAULTCONTROLLER_DESIREDSIZE 1
+#define WEBCORE_BUILTIN_TRANSFORMSTREAMDEFAULTCONTROLLER_ENQUEUE 1
+#define WEBCORE_BUILTIN_TRANSFORMSTREAMDEFAULTCONTROLLER_ERROR 1
+#define WEBCORE_BUILTIN_TRANSFORMSTREAMDEFAULTCONTROLLER_TERMINATE 1
+
+#define WEBCORE_FOREACH_TRANSFORMSTREAMDEFAULTCONTROLLER_BUILTIN_CODE(macro) \
+ macro(transformStreamDefaultControllerInitializeTransformStreamDefaultControllerCode, initializeTransformStreamDefaultController, ASCIILiteral(), s_transformStreamDefaultControllerInitializeTransformStreamDefaultControllerCodeLength) \
+ macro(transformStreamDefaultControllerDesiredSizeCode, desiredSize, "get desiredSize"_s, s_transformStreamDefaultControllerDesiredSizeCodeLength) \
+ macro(transformStreamDefaultControllerEnqueueCode, enqueue, ASCIILiteral(), s_transformStreamDefaultControllerEnqueueCodeLength) \
+ macro(transformStreamDefaultControllerErrorCode, error, ASCIILiteral(), s_transformStreamDefaultControllerErrorCodeLength) \
+ macro(transformStreamDefaultControllerTerminateCode, terminate, ASCIILiteral(), s_transformStreamDefaultControllerTerminateCodeLength) \
+
+#define WEBCORE_FOREACH_TRANSFORMSTREAMDEFAULTCONTROLLER_BUILTIN_FUNCTION_NAME(macro) \
+ macro(desiredSize) \
+ macro(enqueue) \
+ macro(error) \
+ macro(initializeTransformStreamDefaultController) \
+ macro(terminate) \
+
+#define DECLARE_BUILTIN_GENERATOR(codeName, functionName, overriddenName, argumentCount) \
+ JSC::FunctionExecutable* codeName##Generator(JSC::VM&);
+
+WEBCORE_FOREACH_TRANSFORMSTREAMDEFAULTCONTROLLER_BUILTIN_CODE(DECLARE_BUILTIN_GENERATOR)
+#undef DECLARE_BUILTIN_GENERATOR
+
+class TransformStreamDefaultControllerBuiltinsWrapper : private JSC::WeakHandleOwner {
+public:
+ explicit TransformStreamDefaultControllerBuiltinsWrapper(JSC::VM& vm)
+ : m_vm(vm)
+ WEBCORE_FOREACH_TRANSFORMSTREAMDEFAULTCONTROLLER_BUILTIN_FUNCTION_NAME(INITIALIZE_BUILTIN_NAMES)
+#define INITIALIZE_BUILTIN_SOURCE_MEMBERS(name, functionName, overriddenName, length) , m_##name##Source(JSC::makeSource(StringImpl::createWithoutCopying(s_##name, length), { }))
+ WEBCORE_FOREACH_TRANSFORMSTREAMDEFAULTCONTROLLER_BUILTIN_CODE(INITIALIZE_BUILTIN_SOURCE_MEMBERS)
+#undef INITIALIZE_BUILTIN_SOURCE_MEMBERS
+ {
+ }
+
+#define EXPOSE_BUILTIN_EXECUTABLES(name, functionName, overriddenName, length) \
+ JSC::UnlinkedFunctionExecutable* name##Executable(); \
+ const JSC::SourceCode& name##Source() const { return m_##name##Source; }
+ WEBCORE_FOREACH_TRANSFORMSTREAMDEFAULTCONTROLLER_BUILTIN_CODE(EXPOSE_BUILTIN_EXECUTABLES)
+#undef EXPOSE_BUILTIN_EXECUTABLES
+
+ WEBCORE_FOREACH_TRANSFORMSTREAMDEFAULTCONTROLLER_BUILTIN_FUNCTION_NAME(DECLARE_BUILTIN_IDENTIFIER_ACCESSOR)
+
+ void exportNames();
+
+private:
+ JSC::VM& m_vm;
+
+ WEBCORE_FOREACH_TRANSFORMSTREAMDEFAULTCONTROLLER_BUILTIN_FUNCTION_NAME(DECLARE_BUILTIN_NAMES)
+
+#define DECLARE_BUILTIN_SOURCE_MEMBERS(name, functionName, overriddenName, length) \
+ JSC::SourceCode m_##name##Source;\
+ JSC::Weak<JSC::UnlinkedFunctionExecutable> m_##name##Executable;
+ WEBCORE_FOREACH_TRANSFORMSTREAMDEFAULTCONTROLLER_BUILTIN_CODE(DECLARE_BUILTIN_SOURCE_MEMBERS)
+#undef DECLARE_BUILTIN_SOURCE_MEMBERS
+
+};
+
+#define DEFINE_BUILTIN_EXECUTABLES(name, functionName, overriddenName, length) \
+inline JSC::UnlinkedFunctionExecutable* TransformStreamDefaultControllerBuiltinsWrapper::name##Executable() \
+{\
+ if (!m_##name##Executable) {\
+ JSC::Identifier executableName = functionName##PublicName();\
+ if (overriddenName)\
+ executableName = JSC::Identifier::fromString(m_vm, overriddenName);\
+ m_##name##Executable = JSC::Weak<JSC::UnlinkedFunctionExecutable>(JSC::createBuiltinExecutable(m_vm, m_##name##Source, executableName, s_##name##ConstructorKind, s_##name##ConstructAbility), this, &m_##name##Executable);\
+ }\
+ return m_##name##Executable.get();\
+}
+WEBCORE_FOREACH_TRANSFORMSTREAMDEFAULTCONTROLLER_BUILTIN_CODE(DEFINE_BUILTIN_EXECUTABLES)
+#undef DEFINE_BUILTIN_EXECUTABLES
+
+inline void TransformStreamDefaultControllerBuiltinsWrapper::exportNames()
+{
+#define EXPORT_FUNCTION_NAME(name) m_vm.propertyNames->appendExternalName(name##PublicName(), name##PrivateName());
+ WEBCORE_FOREACH_TRANSFORMSTREAMDEFAULTCONTROLLER_BUILTIN_FUNCTION_NAME(EXPORT_FUNCTION_NAME)
+#undef EXPORT_FUNCTION_NAME
+}
+
+} // namespace WebCore
diff --git a/src/bun.js/builtins/cpp/TransformStreamInternalsBuiltins.cpp b/src/bun.js/builtins/cpp/TransformStreamInternalsBuiltins.cpp
new file mode 100644
index 000000000..560a6350c
--- /dev/null
+++ b/src/bun.js/builtins/cpp/TransformStreamInternalsBuiltins.cpp
@@ -0,0 +1,492 @@
+/*
+ * Copyright (c) 2015 Igalia
+ * Copyright (c) 2015 Igalia S.L.
+ * Copyright (c) 2015 Igalia.
+ * Copyright (c) 2015, 2016 Canon Inc. All rights reserved.
+ * Copyright (c) 2015, 2016, 2017 Canon Inc.
+ * Copyright (c) 2016, 2020 Apple Inc. All rights reserved.
+ * Copyright (c) 2022 Codeblog Corp. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+// DO NOT EDIT THIS FILE. It is automatically generated from JavaScript files for
+// builtins by the script: Source/JavaScriptCore/Scripts/generate-js-builtins.py
+
+#include "config.h"
+#include "TransformStreamInternalsBuiltins.h"
+
+#include "WebCoreJSClientData.h"
+#include <JavaScriptCore/HeapInlines.h>
+#include <JavaScriptCore/IdentifierInlines.h>
+#include <JavaScriptCore/Intrinsic.h>
+#include <JavaScriptCore/JSCJSValueInlines.h>
+#include <JavaScriptCore/JSCellInlines.h>
+#include <JavaScriptCore/StructureInlines.h>
+#include <JavaScriptCore/VM.h>
+
+namespace WebCore {
+
+const JSC::ConstructAbility s_transformStreamInternalsIsTransformStreamCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_transformStreamInternalsIsTransformStreamCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_transformStreamInternalsIsTransformStreamCodeLength = 120;
+static const JSC::Intrinsic s_transformStreamInternalsIsTransformStreamCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_transformStreamInternalsIsTransformStreamCode =
+ "(function (stream)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " return @isObject(stream) && !!@getByIdDirectPrivate(stream, \"readable\");\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_transformStreamInternalsIsTransformStreamDefaultControllerCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_transformStreamInternalsIsTransformStreamDefaultControllerCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_transformStreamInternalsIsTransformStreamDefaultControllerCodeLength = 142;
+static const JSC::Intrinsic s_transformStreamInternalsIsTransformStreamDefaultControllerCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_transformStreamInternalsIsTransformStreamDefaultControllerCode =
+ "(function (controller)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " return @isObject(controller) && !!@getByIdDirectPrivate(controller, \"transformAlgorithm\");\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_transformStreamInternalsCreateTransformStreamCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_transformStreamInternalsCreateTransformStreamCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_transformStreamInternalsCreateTransformStreamCodeLength = 1317;
+static const JSC::Intrinsic s_transformStreamInternalsCreateTransformStreamCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_transformStreamInternalsCreateTransformStreamCode =
+ "(function (startAlgorithm, transformAlgorithm, flushAlgorithm, writableHighWaterMark, writableSizeAlgorithm, readableHighWaterMark, readableSizeAlgorithm)\n" \
+ "{\n" \
+ " if (writableHighWaterMark === @undefined)\n" \
+ " writableHighWaterMark = 1;\n" \
+ " if (writableSizeAlgorithm === @undefined)\n" \
+ " writableSizeAlgorithm = () => 1;\n" \
+ " if (readableHighWaterMark === @undefined)\n" \
+ " readableHighWaterMark = 0;\n" \
+ " if (readableSizeAlgorithm === @undefined)\n" \
+ " readableSizeAlgorithm = () => 1;\n" \
+ " @assert(writableHighWaterMark >= 0);\n" \
+ " @assert(readableHighWaterMark >= 0);\n" \
+ "\n" \
+ " const transform = {};\n" \
+ " @putByIdDirectPrivate(transform, \"TransformStream\", true);\n" \
+ "\n" \
+ " const stream = new @TransformStream(transform);\n" \
+ " const startPromiseCapability = @newPromiseCapability(@Promise);\n" \
+ " @initializeTransformStream(stream, startPromiseCapability.@promise, writableHighWaterMark, writableSizeAlgorithm, readableHighWaterMark, readableSizeAlgorithm);\n" \
+ "\n" \
+ " const controller = new @TransformStreamDefaultController();\n" \
+ " @setUpTransformStreamDefaultController(stream, controller, transformAlgorithm, flushAlgorithm);\n" \
+ "\n" \
+ " startAlgorithm().@then(() => {\n" \
+ " startPromiseCapability.@resolve.@call();\n" \
+ " }, (error) => {\n" \
+ " startPromiseCapability.@reject.@call(@undefined, error);\n" \
+ " });\n" \
+ "\n" \
+ " return stream;\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_transformStreamInternalsInitializeTransformStreamCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_transformStreamInternalsInitializeTransformStreamCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_transformStreamInternalsInitializeTransformStreamCodeLength = 1881;
+static const JSC::Intrinsic s_transformStreamInternalsInitializeTransformStreamCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_transformStreamInternalsInitializeTransformStreamCode =
+ "(function (stream, startPromise, writableHighWaterMark, writableSizeAlgorithm, readableHighWaterMark, readableSizeAlgorithm)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " const startAlgorithm = () => { return startPromise; };\n" \
+ " const writeAlgorithm = (chunk) => { return @transformStreamDefaultSinkWriteAlgorithm(stream, chunk); }\n" \
+ " const abortAlgorithm = (reason) => { return @transformStreamDefaultSinkAbortAlgorithm(stream, reason); }\n" \
+ " const closeAlgorithm = () => { return @transformStreamDefaultSinkCloseAlgorithm(stream); }\n" \
+ " const writable = @createWritableStream(startAlgorithm, writeAlgorithm, closeAlgorithm, abortAlgorithm, writableHighWaterMark, writableSizeAlgorithm);\n" \
+ "\n" \
+ " const pullAlgorithm = () => { return @transformStreamDefaultSourcePullAlgorithm(stream); };\n" \
+ " const cancelAlgorithm = (reason) => {\n" \
+ " @transformStreamErrorWritableAndUnblockWrite(stream, reason);\n" \
+ " return @Promise.@resolve();\n" \
+ " };\n" \
+ " const underlyingSource = { };\n" \
+ " @putByIdDirectPrivate(underlyingSource, \"start\", startAlgorithm);\n" \
+ " @putByIdDirectPrivate(underlyingSource, \"pull\", pullAlgorithm);\n" \
+ " @putByIdDirectPrivate(underlyingSource, \"cancel\", cancelAlgorithm);\n" \
+ " const options = { };\n" \
+ " @putByIdDirectPrivate(options, \"size\", readableSizeAlgorithm);\n" \
+ " @putByIdDirectPrivate(options, \"highWaterMark\", readableHighWaterMark);\n" \
+ " const readable = new @ReadableStream(underlyingSource, options);\n" \
+ "\n" \
+ " //\n" \
+ " @putByIdDirectPrivate(stream, \"writable\", writable);\n" \
+ " //\n" \
+ " @putByIdDirectPrivate(stream, \"internalWritable\", @getInternalWritableStream(writable));\n" \
+ "\n" \
+ " @putByIdDirectPrivate(stream, \"readable\", readable);\n" \
+ " @putByIdDirectPrivate(stream, \"backpressure\", @undefined);\n" \
+ " @putByIdDirectPrivate(stream, \"backpressureChangePromise\", @undefined);\n" \
+ "\n" \
+ " @transformStreamSetBackpressure(stream, true);\n" \
+ " @putByIdDirectPrivate(stream, \"controller\", @undefined);\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_transformStreamInternalsTransformStreamErrorCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_transformStreamInternalsTransformStreamErrorCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_transformStreamInternalsTransformStreamErrorCodeLength = 330;
+static const JSC::Intrinsic s_transformStreamInternalsTransformStreamErrorCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_transformStreamInternalsTransformStreamErrorCode =
+ "(function (stream, e)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " const readable = @getByIdDirectPrivate(stream, \"readable\");\n" \
+ " const readableController = @getByIdDirectPrivate(readable, \"readableStreamController\");\n" \
+ " @readableStreamDefaultControllerError(readableController, e);\n" \
+ "\n" \
+ " @transformStreamErrorWritableAndUnblockWrite(stream, e);\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_transformStreamInternalsTransformStreamErrorWritableAndUnblockWriteCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_transformStreamInternalsTransformStreamErrorWritableAndUnblockWriteCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_transformStreamInternalsTransformStreamErrorWritableAndUnblockWriteCodeLength = 431;
+static const JSC::Intrinsic s_transformStreamInternalsTransformStreamErrorWritableAndUnblockWriteCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_transformStreamInternalsTransformStreamErrorWritableAndUnblockWriteCode =
+ "(function (stream, e)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " @transformStreamDefaultControllerClearAlgorithms(@getByIdDirectPrivate(stream, \"controller\"));\n" \
+ "\n" \
+ " const writable = @getByIdDirectPrivate(stream, \"internalWritable\");\n" \
+ " @writableStreamDefaultControllerErrorIfNeeded(@getByIdDirectPrivate(writable, \"controller\"), e);\n" \
+ "\n" \
+ " if (@getByIdDirectPrivate(stream, \"backpressure\"))\n" \
+ " @transformStreamSetBackpressure(stream, false);\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_transformStreamInternalsTransformStreamSetBackpressureCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_transformStreamInternalsTransformStreamSetBackpressureCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_transformStreamInternalsTransformStreamSetBackpressureCodeLength = 498;
+static const JSC::Intrinsic s_transformStreamInternalsTransformStreamSetBackpressureCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_transformStreamInternalsTransformStreamSetBackpressureCode =
+ "(function (stream, backpressure)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " @assert(@getByIdDirectPrivate(stream, \"backpressure\") !== backpressure);\n" \
+ "\n" \
+ " const backpressureChangePromise = @getByIdDirectPrivate(stream, \"backpressureChangePromise\");\n" \
+ " if (backpressureChangePromise !== @undefined)\n" \
+ " backpressureChangePromise.@resolve.@call();\n" \
+ "\n" \
+ " @putByIdDirectPrivate(stream, \"backpressureChangePromise\", @newPromiseCapability(@Promise));\n" \
+ " @putByIdDirectPrivate(stream, \"backpressure\", backpressure);\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_transformStreamInternalsSetUpTransformStreamDefaultControllerCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_transformStreamInternalsSetUpTransformStreamDefaultControllerCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_transformStreamInternalsSetUpTransformStreamDefaultControllerCodeLength = 478;
+static const JSC::Intrinsic s_transformStreamInternalsSetUpTransformStreamDefaultControllerCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_transformStreamInternalsSetUpTransformStreamDefaultControllerCode =
+ "(function (stream, controller, transformAlgorithm, flushAlgorithm)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " @assert(@isTransformStream(stream));\n" \
+ " @assert(@getByIdDirectPrivate(stream, \"controller\") === @undefined);\n" \
+ "\n" \
+ " @putByIdDirectPrivate(controller, \"stream\", stream);\n" \
+ " @putByIdDirectPrivate(stream, \"controller\", controller);\n" \
+ " @putByIdDirectPrivate(controller, \"transformAlgorithm\", transformAlgorithm);\n" \
+ " @putByIdDirectPrivate(controller, \"flushAlgorithm\", flushAlgorithm);\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_transformStreamInternalsSetUpTransformStreamDefaultControllerFromTransformerCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_transformStreamInternalsSetUpTransformStreamDefaultControllerFromTransformerCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_transformStreamInternalsSetUpTransformStreamDefaultControllerFromTransformerCodeLength = 940;
+static const JSC::Intrinsic s_transformStreamInternalsSetUpTransformStreamDefaultControllerFromTransformerCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_transformStreamInternalsSetUpTransformStreamDefaultControllerFromTransformerCode =
+ "(function (stream, transformer, transformerDict)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " const controller = new @TransformStreamDefaultController();\n" \
+ " let transformAlgorithm = (chunk) => {\n" \
+ " try {\n" \
+ " @transformStreamDefaultControllerEnqueue(controller, chunk);\n" \
+ " } catch (e) {\n" \
+ " return @Promise.@reject(e);\n" \
+ " }\n" \
+ " return @Promise.@resolve();\n" \
+ " };\n" \
+ " let flushAlgorithm = () => { return @Promise.@resolve(); };\n" \
+ "\n" \
+ " if (\"transform\" in transformerDict)\n" \
+ " transformAlgorithm = (chunk) => {\n" \
+ " return @promiseInvokeOrNoopMethod(transformer, transformerDict[\"transform\"], [chunk, controller]);\n" \
+ " };\n" \
+ "\n" \
+ " if (\"flush\" in transformerDict) {\n" \
+ " flushAlgorithm = () => {\n" \
+ " return @promiseInvokeOrNoopMethod(transformer, transformerDict[\"flush\"], [controller]);\n" \
+ " };\n" \
+ " }\n" \
+ "\n" \
+ " @setUpTransformStreamDefaultController(stream, controller, transformAlgorithm, flushAlgorithm);\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_transformStreamInternalsTransformStreamDefaultControllerClearAlgorithmsCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_transformStreamInternalsTransformStreamDefaultControllerClearAlgorithmsCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_transformStreamInternalsTransformStreamDefaultControllerClearAlgorithmsCodeLength = 190;
+static const JSC::Intrinsic s_transformStreamInternalsTransformStreamDefaultControllerClearAlgorithmsCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_transformStreamInternalsTransformStreamDefaultControllerClearAlgorithmsCode =
+ "(function (controller)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " //\n" \
+ " @putByIdDirectPrivate(controller, \"transformAlgorithm\", true);\n" \
+ " @putByIdDirectPrivate(controller, \"flushAlgorithm\", @undefined);\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_transformStreamInternalsTransformStreamDefaultControllerEnqueueCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_transformStreamInternalsTransformStreamDefaultControllerEnqueueCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_transformStreamInternalsTransformStreamDefaultControllerEnqueueCodeLength = 979;
+static const JSC::Intrinsic s_transformStreamInternalsTransformStreamDefaultControllerEnqueueCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_transformStreamInternalsTransformStreamDefaultControllerEnqueueCode =
+ "(function (controller, chunk)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " const stream = @getByIdDirectPrivate(controller, \"stream\");\n" \
+ " const readable = @getByIdDirectPrivate(stream, \"readable\");\n" \
+ " const readableController = @getByIdDirectPrivate(readable, \"readableStreamController\");\n" \
+ "\n" \
+ " @assert(readableController !== @undefined);\n" \
+ " if (!@readableStreamDefaultControllerCanCloseOrEnqueue(readableController))\n" \
+ " @throwTypeError(\"TransformStream.readable cannot close or enqueue\");\n" \
+ "\n" \
+ " try {\n" \
+ " @readableStreamDefaultControllerEnqueue(readableController, chunk);\n" \
+ " } catch (e) {\n" \
+ " @transformStreamErrorWritableAndUnblockWrite(stream, e);\n" \
+ " throw @getByIdDirectPrivate(readable, \"storedError\");\n" \
+ " }\n" \
+ "\n" \
+ " const backpressure = !@readableStreamDefaultControllerShouldCallPull(readableController);\n" \
+ " if (backpressure !== @getByIdDirectPrivate(stream, \"backpressure\")) {\n" \
+ " @assert(backpressure);\n" \
+ " @transformStreamSetBackpressure(stream, true);\n" \
+ " }\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_transformStreamInternalsTransformStreamDefaultControllerErrorCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_transformStreamInternalsTransformStreamDefaultControllerErrorCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_transformStreamInternalsTransformStreamDefaultControllerErrorCodeLength = 125;
+static const JSC::Intrinsic s_transformStreamInternalsTransformStreamDefaultControllerErrorCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_transformStreamInternalsTransformStreamDefaultControllerErrorCode =
+ "(function (controller, e)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " @transformStreamError(@getByIdDirectPrivate(controller, \"stream\"), e);\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_transformStreamInternalsTransformStreamDefaultControllerPerformTransformCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_transformStreamInternalsTransformStreamDefaultControllerPerformTransformCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_transformStreamInternalsTransformStreamDefaultControllerPerformTransformCodeLength = 500;
+static const JSC::Intrinsic s_transformStreamInternalsTransformStreamDefaultControllerPerformTransformCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_transformStreamInternalsTransformStreamDefaultControllerPerformTransformCode =
+ "(function (controller, chunk)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " const promiseCapability = @newPromiseCapability(@Promise);\n" \
+ "\n" \
+ " const transformPromise = @getByIdDirectPrivate(controller, \"transformAlgorithm\").@call(@undefined, chunk);\n" \
+ " transformPromise.@then(() => {\n" \
+ " promiseCapability.@resolve();\n" \
+ " }, (r) => {\n" \
+ " @transformStreamError(@getByIdDirectPrivate(controller, \"stream\"), r);\n" \
+ " promiseCapability.@reject.@call(@undefined, r);\n" \
+ " });\n" \
+ " return promiseCapability.@promise;\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_transformStreamInternalsTransformStreamDefaultControllerTerminateCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_transformStreamInternalsTransformStreamDefaultControllerTerminateCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_transformStreamInternalsTransformStreamDefaultControllerTerminateCodeLength = 554;
+static const JSC::Intrinsic s_transformStreamInternalsTransformStreamDefaultControllerTerminateCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_transformStreamInternalsTransformStreamDefaultControllerTerminateCode =
+ "(function (controller)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " const stream = @getByIdDirectPrivate(controller, \"stream\");\n" \
+ " const readable = @getByIdDirectPrivate(stream, \"readable\");\n" \
+ " const readableController = @getByIdDirectPrivate(readable, \"readableStreamController\");\n" \
+ "\n" \
+ " //\n" \
+ " if (@readableStreamDefaultControllerCanCloseOrEnqueue(readableController))\n" \
+ " @readableStreamDefaultControllerClose(readableController);\n" \
+ " const error = @makeTypeError(\"the stream has been terminated\");\n" \
+ " @transformStreamErrorWritableAndUnblockWrite(stream, error);\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_transformStreamInternalsTransformStreamDefaultSinkWriteAlgorithmCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_transformStreamInternalsTransformStreamDefaultSinkWriteAlgorithmCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_transformStreamInternalsTransformStreamDefaultSinkWriteAlgorithmCodeLength = 1373;
+static const JSC::Intrinsic s_transformStreamInternalsTransformStreamDefaultSinkWriteAlgorithmCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_transformStreamInternalsTransformStreamDefaultSinkWriteAlgorithmCode =
+ "(function (stream, chunk)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " const writable = @getByIdDirectPrivate(stream, \"internalWritable\");\n" \
+ "\n" \
+ " @assert(@getByIdDirectPrivate(writable, \"state\") === \"writable\");\n" \
+ "\n" \
+ " const controller = @getByIdDirectPrivate(stream, \"controller\");\n" \
+ "\n" \
+ " if (@getByIdDirectPrivate(stream, \"backpressure\")) {\n" \
+ " const promiseCapability = @newPromiseCapability(@Promise);\n" \
+ "\n" \
+ " const backpressureChangePromise = @getByIdDirectPrivate(stream, \"backpressureChangePromise\");\n" \
+ " @assert(backpressureChangePromise !== @undefined);\n" \
+ " backpressureChangePromise.@promise.@then(() => {\n" \
+ " const state = @getByIdDirectPrivate(writable, \"state\");\n" \
+ " if (state === \"erroring\") {\n" \
+ " promiseCapability.@reject.@call(@undefined, @getByIdDirectPrivate(writable, \"storedError\"));\n" \
+ " return;\n" \
+ " }\n" \
+ "\n" \
+ " @assert(state === \"writable\");\n" \
+ " @transformStreamDefaultControllerPerformTransform(controller, chunk).@then(() => {\n" \
+ " promiseCapability.@resolve();\n" \
+ " }, (e) => {\n" \
+ " promiseCapability.@reject.@call(@undefined, e);\n" \
+ " });\n" \
+ " }, (e) => {\n" \
+ " promiseCapability.@reject.@call(@undefined, e);\n" \
+ " });\n" \
+ "\n" \
+ " return promiseCapability.@promise;\n" \
+ " }\n" \
+ " return @transformStreamDefaultControllerPerformTransform(controller, chunk);\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_transformStreamInternalsTransformStreamDefaultSinkAbortAlgorithmCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_transformStreamInternalsTransformStreamDefaultSinkAbortAlgorithmCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_transformStreamInternalsTransformStreamDefaultSinkAbortAlgorithmCodeLength = 126;
+static const JSC::Intrinsic s_transformStreamInternalsTransformStreamDefaultSinkAbortAlgorithmCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_transformStreamInternalsTransformStreamDefaultSinkAbortAlgorithmCode =
+ "(function (stream, reason)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " @transformStreamError(stream, reason);\n" \
+ " return @Promise.@resolve();\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_transformStreamInternalsTransformStreamDefaultSinkCloseAlgorithmCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_transformStreamInternalsTransformStreamDefaultSinkCloseAlgorithmCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_transformStreamInternalsTransformStreamDefaultSinkCloseAlgorithmCodeLength = 1295;
+static const JSC::Intrinsic s_transformStreamInternalsTransformStreamDefaultSinkCloseAlgorithmCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_transformStreamInternalsTransformStreamDefaultSinkCloseAlgorithmCode =
+ "(function (stream)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ " const readable = @getByIdDirectPrivate(stream, \"readable\");\n" \
+ " const controller = @getByIdDirectPrivate(stream, \"controller\");\n" \
+ " const readableController = @getByIdDirectPrivate(readable, \"readableStreamController\");\n" \
+ "\n" \
+ " const flushAlgorithm = @getByIdDirectPrivate(controller, \"flushAlgorithm\");\n" \
+ " @assert(flushAlgorithm !== @undefined);\n" \
+ " const flushPromise = @getByIdDirectPrivate(controller, \"flushAlgorithm\").@call();\n" \
+ " @transformStreamDefaultControllerClearAlgorithms(controller);\n" \
+ "\n" \
+ " const promiseCapability = @newPromiseCapability(@Promise);\n" \
+ " flushPromise.@then(() => {\n" \
+ " if (@getByIdDirectPrivate(readable, \"state\") === @streamErrored) {\n" \
+ " promiseCapability.@reject.@call(@undefined, @getByIdDirectPrivate(readable, \"storedError\"));\n" \
+ " return;\n" \
+ " }\n" \
+ "\n" \
+ " //\n" \
+ " if (@readableStreamDefaultControllerCanCloseOrEnqueue(readableController))\n" \
+ " @readableStreamDefaultControllerClose(readableController);\n" \
+ " promiseCapability.@resolve();\n" \
+ " }, (r) => {\n" \
+ " @transformStreamError(@getByIdDirectPrivate(controller, \"stream\"), r);\n" \
+ " promiseCapability.@reject.@call(@undefined, @getByIdDirectPrivate(readable, \"storedError\"));\n" \
+ " });\n" \
+ " return promiseCapability.@promise;\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_transformStreamInternalsTransformStreamDefaultSourcePullAlgorithmCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_transformStreamInternalsTransformStreamDefaultSourcePullAlgorithmCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_transformStreamInternalsTransformStreamDefaultSourcePullAlgorithmCodeLength = 325;
+static const JSC::Intrinsic s_transformStreamInternalsTransformStreamDefaultSourcePullAlgorithmCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_transformStreamInternalsTransformStreamDefaultSourcePullAlgorithmCode =
+ "(function (stream)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " @assert(@getByIdDirectPrivate(stream, \"backpressure\"));\n" \
+ " @assert(@getByIdDirectPrivate(stream, \"backpressureChangePromise\") !== @undefined);\n" \
+ "\n" \
+ " @transformStreamSetBackpressure(stream, false);\n" \
+ "\n" \
+ " return @getByIdDirectPrivate(stream, \"backpressureChangePromise\").@promise;\n" \
+ "})\n" \
+;
+
+
+#define DEFINE_BUILTIN_GENERATOR(codeName, functionName, overriddenName, argumentCount) \
+JSC::FunctionExecutable* codeName##Generator(JSC::VM& vm) \
+{\
+ JSVMClientData* clientData = static_cast<JSVMClientData*>(vm.clientData); \
+ return clientData->builtinFunctions().transformStreamInternalsBuiltins().codeName##Executable()->link(vm, nullptr, clientData->builtinFunctions().transformStreamInternalsBuiltins().codeName##Source(), std::nullopt, s_##codeName##Intrinsic); \
+}
+WEBCORE_FOREACH_TRANSFORMSTREAMINTERNALS_BUILTIN_CODE(DEFINE_BUILTIN_GENERATOR)
+#undef DEFINE_BUILTIN_GENERATOR
+
+
+} // namespace WebCore
diff --git a/src/bun.js/builtins/cpp/TransformStreamInternalsBuiltins.h b/src/bun.js/builtins/cpp/TransformStreamInternalsBuiltins.h
new file mode 100644
index 000000000..ad19d0a7e
--- /dev/null
+++ b/src/bun.js/builtins/cpp/TransformStreamInternalsBuiltins.h
@@ -0,0 +1,300 @@
+/*
+ * Copyright (c) 2015 Igalia
+ * Copyright (c) 2015 Igalia S.L.
+ * Copyright (c) 2015 Igalia.
+ * Copyright (c) 2015, 2016 Canon Inc. All rights reserved.
+ * Copyright (c) 2015, 2016, 2017 Canon Inc.
+ * Copyright (c) 2016, 2020 Apple Inc. All rights reserved.
+ * Copyright (c) 2022 Codeblog Corp. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+// DO NOT EDIT THIS FILE. It is automatically generated from JavaScript files for
+// builtins by the script: Source/JavaScriptCore/Scripts/generate-js-builtins.py
+
+#pragma once
+
+#include <JavaScriptCore/BuiltinUtils.h>
+#include <JavaScriptCore/Identifier.h>
+#include <JavaScriptCore/JSFunction.h>
+#include <JavaScriptCore/UnlinkedFunctionExecutable.h>
+
+namespace JSC {
+class FunctionExecutable;
+}
+
+namespace WebCore {
+
+/* TransformStreamInternals */
+extern const char* const s_transformStreamInternalsIsTransformStreamCode;
+extern const int s_transformStreamInternalsIsTransformStreamCodeLength;
+extern const JSC::ConstructAbility s_transformStreamInternalsIsTransformStreamCodeConstructAbility;
+extern const JSC::ConstructorKind s_transformStreamInternalsIsTransformStreamCodeConstructorKind;
+extern const char* const s_transformStreamInternalsIsTransformStreamDefaultControllerCode;
+extern const int s_transformStreamInternalsIsTransformStreamDefaultControllerCodeLength;
+extern const JSC::ConstructAbility s_transformStreamInternalsIsTransformStreamDefaultControllerCodeConstructAbility;
+extern const JSC::ConstructorKind s_transformStreamInternalsIsTransformStreamDefaultControllerCodeConstructorKind;
+extern const char* const s_transformStreamInternalsCreateTransformStreamCode;
+extern const int s_transformStreamInternalsCreateTransformStreamCodeLength;
+extern const JSC::ConstructAbility s_transformStreamInternalsCreateTransformStreamCodeConstructAbility;
+extern const JSC::ConstructorKind s_transformStreamInternalsCreateTransformStreamCodeConstructorKind;
+extern const char* const s_transformStreamInternalsInitializeTransformStreamCode;
+extern const int s_transformStreamInternalsInitializeTransformStreamCodeLength;
+extern const JSC::ConstructAbility s_transformStreamInternalsInitializeTransformStreamCodeConstructAbility;
+extern const JSC::ConstructorKind s_transformStreamInternalsInitializeTransformStreamCodeConstructorKind;
+extern const char* const s_transformStreamInternalsTransformStreamErrorCode;
+extern const int s_transformStreamInternalsTransformStreamErrorCodeLength;
+extern const JSC::ConstructAbility s_transformStreamInternalsTransformStreamErrorCodeConstructAbility;
+extern const JSC::ConstructorKind s_transformStreamInternalsTransformStreamErrorCodeConstructorKind;
+extern const char* const s_transformStreamInternalsTransformStreamErrorWritableAndUnblockWriteCode;
+extern const int s_transformStreamInternalsTransformStreamErrorWritableAndUnblockWriteCodeLength;
+extern const JSC::ConstructAbility s_transformStreamInternalsTransformStreamErrorWritableAndUnblockWriteCodeConstructAbility;
+extern const JSC::ConstructorKind s_transformStreamInternalsTransformStreamErrorWritableAndUnblockWriteCodeConstructorKind;
+extern const char* const s_transformStreamInternalsTransformStreamSetBackpressureCode;
+extern const int s_transformStreamInternalsTransformStreamSetBackpressureCodeLength;
+extern const JSC::ConstructAbility s_transformStreamInternalsTransformStreamSetBackpressureCodeConstructAbility;
+extern const JSC::ConstructorKind s_transformStreamInternalsTransformStreamSetBackpressureCodeConstructorKind;
+extern const char* const s_transformStreamInternalsSetUpTransformStreamDefaultControllerCode;
+extern const int s_transformStreamInternalsSetUpTransformStreamDefaultControllerCodeLength;
+extern const JSC::ConstructAbility s_transformStreamInternalsSetUpTransformStreamDefaultControllerCodeConstructAbility;
+extern const JSC::ConstructorKind s_transformStreamInternalsSetUpTransformStreamDefaultControllerCodeConstructorKind;
+extern const char* const s_transformStreamInternalsSetUpTransformStreamDefaultControllerFromTransformerCode;
+extern const int s_transformStreamInternalsSetUpTransformStreamDefaultControllerFromTransformerCodeLength;
+extern const JSC::ConstructAbility s_transformStreamInternalsSetUpTransformStreamDefaultControllerFromTransformerCodeConstructAbility;
+extern const JSC::ConstructorKind s_transformStreamInternalsSetUpTransformStreamDefaultControllerFromTransformerCodeConstructorKind;
+extern const char* const s_transformStreamInternalsTransformStreamDefaultControllerClearAlgorithmsCode;
+extern const int s_transformStreamInternalsTransformStreamDefaultControllerClearAlgorithmsCodeLength;
+extern const JSC::ConstructAbility s_transformStreamInternalsTransformStreamDefaultControllerClearAlgorithmsCodeConstructAbility;
+extern const JSC::ConstructorKind s_transformStreamInternalsTransformStreamDefaultControllerClearAlgorithmsCodeConstructorKind;
+extern const char* const s_transformStreamInternalsTransformStreamDefaultControllerEnqueueCode;
+extern const int s_transformStreamInternalsTransformStreamDefaultControllerEnqueueCodeLength;
+extern const JSC::ConstructAbility s_transformStreamInternalsTransformStreamDefaultControllerEnqueueCodeConstructAbility;
+extern const JSC::ConstructorKind s_transformStreamInternalsTransformStreamDefaultControllerEnqueueCodeConstructorKind;
+extern const char* const s_transformStreamInternalsTransformStreamDefaultControllerErrorCode;
+extern const int s_transformStreamInternalsTransformStreamDefaultControllerErrorCodeLength;
+extern const JSC::ConstructAbility s_transformStreamInternalsTransformStreamDefaultControllerErrorCodeConstructAbility;
+extern const JSC::ConstructorKind s_transformStreamInternalsTransformStreamDefaultControllerErrorCodeConstructorKind;
+extern const char* const s_transformStreamInternalsTransformStreamDefaultControllerPerformTransformCode;
+extern const int s_transformStreamInternalsTransformStreamDefaultControllerPerformTransformCodeLength;
+extern const JSC::ConstructAbility s_transformStreamInternalsTransformStreamDefaultControllerPerformTransformCodeConstructAbility;
+extern const JSC::ConstructorKind s_transformStreamInternalsTransformStreamDefaultControllerPerformTransformCodeConstructorKind;
+extern const char* const s_transformStreamInternalsTransformStreamDefaultControllerTerminateCode;
+extern const int s_transformStreamInternalsTransformStreamDefaultControllerTerminateCodeLength;
+extern const JSC::ConstructAbility s_transformStreamInternalsTransformStreamDefaultControllerTerminateCodeConstructAbility;
+extern const JSC::ConstructorKind s_transformStreamInternalsTransformStreamDefaultControllerTerminateCodeConstructorKind;
+extern const char* const s_transformStreamInternalsTransformStreamDefaultSinkWriteAlgorithmCode;
+extern const int s_transformStreamInternalsTransformStreamDefaultSinkWriteAlgorithmCodeLength;
+extern const JSC::ConstructAbility s_transformStreamInternalsTransformStreamDefaultSinkWriteAlgorithmCodeConstructAbility;
+extern const JSC::ConstructorKind s_transformStreamInternalsTransformStreamDefaultSinkWriteAlgorithmCodeConstructorKind;
+extern const char* const s_transformStreamInternalsTransformStreamDefaultSinkAbortAlgorithmCode;
+extern const int s_transformStreamInternalsTransformStreamDefaultSinkAbortAlgorithmCodeLength;
+extern const JSC::ConstructAbility s_transformStreamInternalsTransformStreamDefaultSinkAbortAlgorithmCodeConstructAbility;
+extern const JSC::ConstructorKind s_transformStreamInternalsTransformStreamDefaultSinkAbortAlgorithmCodeConstructorKind;
+extern const char* const s_transformStreamInternalsTransformStreamDefaultSinkCloseAlgorithmCode;
+extern const int s_transformStreamInternalsTransformStreamDefaultSinkCloseAlgorithmCodeLength;
+extern const JSC::ConstructAbility s_transformStreamInternalsTransformStreamDefaultSinkCloseAlgorithmCodeConstructAbility;
+extern const JSC::ConstructorKind s_transformStreamInternalsTransformStreamDefaultSinkCloseAlgorithmCodeConstructorKind;
+extern const char* const s_transformStreamInternalsTransformStreamDefaultSourcePullAlgorithmCode;
+extern const int s_transformStreamInternalsTransformStreamDefaultSourcePullAlgorithmCodeLength;
+extern const JSC::ConstructAbility s_transformStreamInternalsTransformStreamDefaultSourcePullAlgorithmCodeConstructAbility;
+extern const JSC::ConstructorKind s_transformStreamInternalsTransformStreamDefaultSourcePullAlgorithmCodeConstructorKind;
+
+#define WEBCORE_FOREACH_TRANSFORMSTREAMINTERNALS_BUILTIN_DATA(macro) \
+ macro(isTransformStream, transformStreamInternalsIsTransformStream, 1) \
+ macro(isTransformStreamDefaultController, transformStreamInternalsIsTransformStreamDefaultController, 1) \
+ macro(createTransformStream, transformStreamInternalsCreateTransformStream, 7) \
+ macro(initializeTransformStream, transformStreamInternalsInitializeTransformStream, 6) \
+ macro(transformStreamError, transformStreamInternalsTransformStreamError, 2) \
+ macro(transformStreamErrorWritableAndUnblockWrite, transformStreamInternalsTransformStreamErrorWritableAndUnblockWrite, 2) \
+ macro(transformStreamSetBackpressure, transformStreamInternalsTransformStreamSetBackpressure, 2) \
+ macro(setUpTransformStreamDefaultController, transformStreamInternalsSetUpTransformStreamDefaultController, 4) \
+ macro(setUpTransformStreamDefaultControllerFromTransformer, transformStreamInternalsSetUpTransformStreamDefaultControllerFromTransformer, 3) \
+ macro(transformStreamDefaultControllerClearAlgorithms, transformStreamInternalsTransformStreamDefaultControllerClearAlgorithms, 1) \
+ macro(transformStreamDefaultControllerEnqueue, transformStreamInternalsTransformStreamDefaultControllerEnqueue, 2) \
+ macro(transformStreamDefaultControllerError, transformStreamInternalsTransformStreamDefaultControllerError, 2) \
+ macro(transformStreamDefaultControllerPerformTransform, transformStreamInternalsTransformStreamDefaultControllerPerformTransform, 2) \
+ macro(transformStreamDefaultControllerTerminate, transformStreamInternalsTransformStreamDefaultControllerTerminate, 1) \
+ macro(transformStreamDefaultSinkWriteAlgorithm, transformStreamInternalsTransformStreamDefaultSinkWriteAlgorithm, 2) \
+ macro(transformStreamDefaultSinkAbortAlgorithm, transformStreamInternalsTransformStreamDefaultSinkAbortAlgorithm, 2) \
+ macro(transformStreamDefaultSinkCloseAlgorithm, transformStreamInternalsTransformStreamDefaultSinkCloseAlgorithm, 1) \
+ macro(transformStreamDefaultSourcePullAlgorithm, transformStreamInternalsTransformStreamDefaultSourcePullAlgorithm, 1) \
+
+#define WEBCORE_BUILTIN_TRANSFORMSTREAMINTERNALS_ISTRANSFORMSTREAM 1
+#define WEBCORE_BUILTIN_TRANSFORMSTREAMINTERNALS_ISTRANSFORMSTREAMDEFAULTCONTROLLER 1
+#define WEBCORE_BUILTIN_TRANSFORMSTREAMINTERNALS_CREATETRANSFORMSTREAM 1
+#define WEBCORE_BUILTIN_TRANSFORMSTREAMINTERNALS_INITIALIZETRANSFORMSTREAM 1
+#define WEBCORE_BUILTIN_TRANSFORMSTREAMINTERNALS_TRANSFORMSTREAMERROR 1
+#define WEBCORE_BUILTIN_TRANSFORMSTREAMINTERNALS_TRANSFORMSTREAMERRORWRITABLEANDUNBLOCKWRITE 1
+#define WEBCORE_BUILTIN_TRANSFORMSTREAMINTERNALS_TRANSFORMSTREAMSETBACKPRESSURE 1
+#define WEBCORE_BUILTIN_TRANSFORMSTREAMINTERNALS_SETUPTRANSFORMSTREAMDEFAULTCONTROLLER 1
+#define WEBCORE_BUILTIN_TRANSFORMSTREAMINTERNALS_SETUPTRANSFORMSTREAMDEFAULTCONTROLLERFROMTRANSFORMER 1
+#define WEBCORE_BUILTIN_TRANSFORMSTREAMINTERNALS_TRANSFORMSTREAMDEFAULTCONTROLLERCLEARALGORITHMS 1
+#define WEBCORE_BUILTIN_TRANSFORMSTREAMINTERNALS_TRANSFORMSTREAMDEFAULTCONTROLLERENQUEUE 1
+#define WEBCORE_BUILTIN_TRANSFORMSTREAMINTERNALS_TRANSFORMSTREAMDEFAULTCONTROLLERERROR 1
+#define WEBCORE_BUILTIN_TRANSFORMSTREAMINTERNALS_TRANSFORMSTREAMDEFAULTCONTROLLERPERFORMTRANSFORM 1
+#define WEBCORE_BUILTIN_TRANSFORMSTREAMINTERNALS_TRANSFORMSTREAMDEFAULTCONTROLLERTERMINATE 1
+#define WEBCORE_BUILTIN_TRANSFORMSTREAMINTERNALS_TRANSFORMSTREAMDEFAULTSINKWRITEALGORITHM 1
+#define WEBCORE_BUILTIN_TRANSFORMSTREAMINTERNALS_TRANSFORMSTREAMDEFAULTSINKABORTALGORITHM 1
+#define WEBCORE_BUILTIN_TRANSFORMSTREAMINTERNALS_TRANSFORMSTREAMDEFAULTSINKCLOSEALGORITHM 1
+#define WEBCORE_BUILTIN_TRANSFORMSTREAMINTERNALS_TRANSFORMSTREAMDEFAULTSOURCEPULLALGORITHM 1
+
+#define WEBCORE_FOREACH_TRANSFORMSTREAMINTERNALS_BUILTIN_CODE(macro) \
+ macro(transformStreamInternalsIsTransformStreamCode, isTransformStream, ASCIILiteral(), s_transformStreamInternalsIsTransformStreamCodeLength) \
+ macro(transformStreamInternalsIsTransformStreamDefaultControllerCode, isTransformStreamDefaultController, ASCIILiteral(), s_transformStreamInternalsIsTransformStreamDefaultControllerCodeLength) \
+ macro(transformStreamInternalsCreateTransformStreamCode, createTransformStream, ASCIILiteral(), s_transformStreamInternalsCreateTransformStreamCodeLength) \
+ macro(transformStreamInternalsInitializeTransformStreamCode, initializeTransformStream, ASCIILiteral(), s_transformStreamInternalsInitializeTransformStreamCodeLength) \
+ macro(transformStreamInternalsTransformStreamErrorCode, transformStreamError, ASCIILiteral(), s_transformStreamInternalsTransformStreamErrorCodeLength) \
+ macro(transformStreamInternalsTransformStreamErrorWritableAndUnblockWriteCode, transformStreamErrorWritableAndUnblockWrite, ASCIILiteral(), s_transformStreamInternalsTransformStreamErrorWritableAndUnblockWriteCodeLength) \
+ macro(transformStreamInternalsTransformStreamSetBackpressureCode, transformStreamSetBackpressure, ASCIILiteral(), s_transformStreamInternalsTransformStreamSetBackpressureCodeLength) \
+ macro(transformStreamInternalsSetUpTransformStreamDefaultControllerCode, setUpTransformStreamDefaultController, ASCIILiteral(), s_transformStreamInternalsSetUpTransformStreamDefaultControllerCodeLength) \
+ macro(transformStreamInternalsSetUpTransformStreamDefaultControllerFromTransformerCode, setUpTransformStreamDefaultControllerFromTransformer, ASCIILiteral(), s_transformStreamInternalsSetUpTransformStreamDefaultControllerFromTransformerCodeLength) \
+ macro(transformStreamInternalsTransformStreamDefaultControllerClearAlgorithmsCode, transformStreamDefaultControllerClearAlgorithms, ASCIILiteral(), s_transformStreamInternalsTransformStreamDefaultControllerClearAlgorithmsCodeLength) \
+ macro(transformStreamInternalsTransformStreamDefaultControllerEnqueueCode, transformStreamDefaultControllerEnqueue, ASCIILiteral(), s_transformStreamInternalsTransformStreamDefaultControllerEnqueueCodeLength) \
+ macro(transformStreamInternalsTransformStreamDefaultControllerErrorCode, transformStreamDefaultControllerError, ASCIILiteral(), s_transformStreamInternalsTransformStreamDefaultControllerErrorCodeLength) \
+ macro(transformStreamInternalsTransformStreamDefaultControllerPerformTransformCode, transformStreamDefaultControllerPerformTransform, ASCIILiteral(), s_transformStreamInternalsTransformStreamDefaultControllerPerformTransformCodeLength) \
+ macro(transformStreamInternalsTransformStreamDefaultControllerTerminateCode, transformStreamDefaultControllerTerminate, ASCIILiteral(), s_transformStreamInternalsTransformStreamDefaultControllerTerminateCodeLength) \
+ macro(transformStreamInternalsTransformStreamDefaultSinkWriteAlgorithmCode, transformStreamDefaultSinkWriteAlgorithm, ASCIILiteral(), s_transformStreamInternalsTransformStreamDefaultSinkWriteAlgorithmCodeLength) \
+ macro(transformStreamInternalsTransformStreamDefaultSinkAbortAlgorithmCode, transformStreamDefaultSinkAbortAlgorithm, ASCIILiteral(), s_transformStreamInternalsTransformStreamDefaultSinkAbortAlgorithmCodeLength) \
+ macro(transformStreamInternalsTransformStreamDefaultSinkCloseAlgorithmCode, transformStreamDefaultSinkCloseAlgorithm, ASCIILiteral(), s_transformStreamInternalsTransformStreamDefaultSinkCloseAlgorithmCodeLength) \
+ macro(transformStreamInternalsTransformStreamDefaultSourcePullAlgorithmCode, transformStreamDefaultSourcePullAlgorithm, ASCIILiteral(), s_transformStreamInternalsTransformStreamDefaultSourcePullAlgorithmCodeLength) \
+
+#define WEBCORE_FOREACH_TRANSFORMSTREAMINTERNALS_BUILTIN_FUNCTION_NAME(macro) \
+ macro(createTransformStream) \
+ macro(initializeTransformStream) \
+ macro(isTransformStream) \
+ macro(isTransformStreamDefaultController) \
+ macro(setUpTransformStreamDefaultController) \
+ macro(setUpTransformStreamDefaultControllerFromTransformer) \
+ macro(transformStreamDefaultControllerClearAlgorithms) \
+ macro(transformStreamDefaultControllerEnqueue) \
+ macro(transformStreamDefaultControllerError) \
+ macro(transformStreamDefaultControllerPerformTransform) \
+ macro(transformStreamDefaultControllerTerminate) \
+ macro(transformStreamDefaultSinkAbortAlgorithm) \
+ macro(transformStreamDefaultSinkCloseAlgorithm) \
+ macro(transformStreamDefaultSinkWriteAlgorithm) \
+ macro(transformStreamDefaultSourcePullAlgorithm) \
+ macro(transformStreamError) \
+ macro(transformStreamErrorWritableAndUnblockWrite) \
+ macro(transformStreamSetBackpressure) \
+
+#define DECLARE_BUILTIN_GENERATOR(codeName, functionName, overriddenName, argumentCount) \
+ JSC::FunctionExecutable* codeName##Generator(JSC::VM&);
+
+WEBCORE_FOREACH_TRANSFORMSTREAMINTERNALS_BUILTIN_CODE(DECLARE_BUILTIN_GENERATOR)
+#undef DECLARE_BUILTIN_GENERATOR
+
+class TransformStreamInternalsBuiltinsWrapper : private JSC::WeakHandleOwner {
+public:
+ explicit TransformStreamInternalsBuiltinsWrapper(JSC::VM& vm)
+ : m_vm(vm)
+ WEBCORE_FOREACH_TRANSFORMSTREAMINTERNALS_BUILTIN_FUNCTION_NAME(INITIALIZE_BUILTIN_NAMES)
+#define INITIALIZE_BUILTIN_SOURCE_MEMBERS(name, functionName, overriddenName, length) , m_##name##Source(JSC::makeSource(StringImpl::createWithoutCopying(s_##name, length), { }))
+ WEBCORE_FOREACH_TRANSFORMSTREAMINTERNALS_BUILTIN_CODE(INITIALIZE_BUILTIN_SOURCE_MEMBERS)
+#undef INITIALIZE_BUILTIN_SOURCE_MEMBERS
+ {
+ }
+
+#define EXPOSE_BUILTIN_EXECUTABLES(name, functionName, overriddenName, length) \
+ JSC::UnlinkedFunctionExecutable* name##Executable(); \
+ const JSC::SourceCode& name##Source() const { return m_##name##Source; }
+ WEBCORE_FOREACH_TRANSFORMSTREAMINTERNALS_BUILTIN_CODE(EXPOSE_BUILTIN_EXECUTABLES)
+#undef EXPOSE_BUILTIN_EXECUTABLES
+
+ WEBCORE_FOREACH_TRANSFORMSTREAMINTERNALS_BUILTIN_FUNCTION_NAME(DECLARE_BUILTIN_IDENTIFIER_ACCESSOR)
+
+ void exportNames();
+
+private:
+ JSC::VM& m_vm;
+
+ WEBCORE_FOREACH_TRANSFORMSTREAMINTERNALS_BUILTIN_FUNCTION_NAME(DECLARE_BUILTIN_NAMES)
+
+#define DECLARE_BUILTIN_SOURCE_MEMBERS(name, functionName, overriddenName, length) \
+ JSC::SourceCode m_##name##Source;\
+ JSC::Weak<JSC::UnlinkedFunctionExecutable> m_##name##Executable;
+ WEBCORE_FOREACH_TRANSFORMSTREAMINTERNALS_BUILTIN_CODE(DECLARE_BUILTIN_SOURCE_MEMBERS)
+#undef DECLARE_BUILTIN_SOURCE_MEMBERS
+
+};
+
+#define DEFINE_BUILTIN_EXECUTABLES(name, functionName, overriddenName, length) \
+inline JSC::UnlinkedFunctionExecutable* TransformStreamInternalsBuiltinsWrapper::name##Executable() \
+{\
+ if (!m_##name##Executable) {\
+ JSC::Identifier executableName = functionName##PublicName();\
+ if (overriddenName)\
+ executableName = JSC::Identifier::fromString(m_vm, overriddenName);\
+ m_##name##Executable = JSC::Weak<JSC::UnlinkedFunctionExecutable>(JSC::createBuiltinExecutable(m_vm, m_##name##Source, executableName, s_##name##ConstructorKind, s_##name##ConstructAbility), this, &m_##name##Executable);\
+ }\
+ return m_##name##Executable.get();\
+}
+WEBCORE_FOREACH_TRANSFORMSTREAMINTERNALS_BUILTIN_CODE(DEFINE_BUILTIN_EXECUTABLES)
+#undef DEFINE_BUILTIN_EXECUTABLES
+
+inline void TransformStreamInternalsBuiltinsWrapper::exportNames()
+{
+#define EXPORT_FUNCTION_NAME(name) m_vm.propertyNames->appendExternalName(name##PublicName(), name##PrivateName());
+ WEBCORE_FOREACH_TRANSFORMSTREAMINTERNALS_BUILTIN_FUNCTION_NAME(EXPORT_FUNCTION_NAME)
+#undef EXPORT_FUNCTION_NAME
+}
+
+class TransformStreamInternalsBuiltinFunctions {
+public:
+ explicit TransformStreamInternalsBuiltinFunctions(JSC::VM& vm) : m_vm(vm) { }
+
+ void init(JSC::JSGlobalObject&);
+ template<typename Visitor> void visit(Visitor&);
+
+public:
+ JSC::VM& m_vm;
+
+#define DECLARE_BUILTIN_SOURCE_MEMBERS(functionName) \
+ JSC::WriteBarrier<JSC::JSFunction> m_##functionName##Function;
+ WEBCORE_FOREACH_TRANSFORMSTREAMINTERNALS_BUILTIN_FUNCTION_NAME(DECLARE_BUILTIN_SOURCE_MEMBERS)
+#undef DECLARE_BUILTIN_SOURCE_MEMBERS
+};
+
+inline void TransformStreamInternalsBuiltinFunctions::init(JSC::JSGlobalObject& globalObject)
+{
+#define EXPORT_FUNCTION(codeName, functionName, overriddenName, length)\
+ m_##functionName##Function.set(m_vm, &globalObject, JSC::JSFunction::create(m_vm, codeName##Generator(m_vm), &globalObject));
+ WEBCORE_FOREACH_TRANSFORMSTREAMINTERNALS_BUILTIN_CODE(EXPORT_FUNCTION)
+#undef EXPORT_FUNCTION
+}
+
+template<typename Visitor>
+inline void TransformStreamInternalsBuiltinFunctions::visit(Visitor& visitor)
+{
+#define VISIT_FUNCTION(name) visitor.append(m_##name##Function);
+ WEBCORE_FOREACH_TRANSFORMSTREAMINTERNALS_BUILTIN_FUNCTION_NAME(VISIT_FUNCTION)
+#undef VISIT_FUNCTION
+}
+
+template void TransformStreamInternalsBuiltinFunctions::visit(JSC::AbstractSlotVisitor&);
+template void TransformStreamInternalsBuiltinFunctions::visit(JSC::SlotVisitor&);
+
+
+
+} // namespace WebCore
diff --git a/src/bun.js/builtins/cpp/WebCoreJSBuiltinInternals.h b/src/bun.js/builtins/cpp/WebCoreJSBuiltinInternals.h
new file mode 100644
index 000000000..c52f65d85
--- /dev/null
+++ b/src/bun.js/builtins/cpp/WebCoreJSBuiltinInternals.h
@@ -0,0 +1,74 @@
+//clang-format off
+namespace Zig { class GlobalObject; }
+/*
+ * Copyright (c) 2015 Igalia
+ * Copyright (c) 2015 Igalia S.L.
+ * Copyright (c) 2015 Igalia.
+ * Copyright (c) 2015, 2016 Canon Inc. All rights reserved.
+ * Copyright (c) 2015, 2016, 2017 Canon Inc.
+ * Copyright (c) 2016, 2020 Apple Inc. All rights reserved.
+ * Copyright (c) 2022 Codeblog Corp. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+// DO NOT EDIT THIS FILE. It is automatically generated from JavaScript files for
+// builtins by the script: Source/JavaScriptCore/Scripts/generate-js-builtins.py
+
+#pragma once
+
+#include "ReadableByteStreamInternalsBuiltins.h"
+#include "ReadableStreamInternalsBuiltins.h"
+#include "StreamInternalsBuiltins.h"
+#include "TransformStreamInternalsBuiltins.h"
+#include "WritableStreamInternalsBuiltins.h"
+#include <JavaScriptCore/VM.h>
+#include <JavaScriptCore/WeakInlines.h>
+
+namespace WebCore {
+
+using JSDOMGlobalObject = Zig::GlobalObject;
+
+class JSBuiltinInternalFunctions {
+public:
+ explicit JSBuiltinInternalFunctions(JSC::VM&);
+
+ template<typename Visitor> void visit(Visitor&);
+ void initialize(JSDOMGlobalObject&);
+
+ ReadableByteStreamInternalsBuiltinFunctions& readableByteStreamInternals() { return m_readableByteStreamInternals; }
+ ReadableStreamInternalsBuiltinFunctions& readableStreamInternals() { return m_readableStreamInternals; }
+ StreamInternalsBuiltinFunctions& streamInternals() { return m_streamInternals; }
+ TransformStreamInternalsBuiltinFunctions& transformStreamInternals() { return m_transformStreamInternals; }
+ WritableStreamInternalsBuiltinFunctions& writableStreamInternals() { return m_writableStreamInternals; }
+
+private:
+ JSC::VM& m_vm;
+ ReadableByteStreamInternalsBuiltinFunctions m_readableByteStreamInternals;
+ ReadableStreamInternalsBuiltinFunctions m_readableStreamInternals;
+ StreamInternalsBuiltinFunctions m_streamInternals;
+ TransformStreamInternalsBuiltinFunctions m_transformStreamInternals;
+ WritableStreamInternalsBuiltinFunctions m_writableStreamInternals;
+};
+
+} // namespace WebCore
diff --git a/src/bun.js/builtins/cpp/WebCoreJSBuiltins.h b/src/bun.js/builtins/cpp/WebCoreJSBuiltins.h
new file mode 100644
index 000000000..0650e1613
--- /dev/null
+++ b/src/bun.js/builtins/cpp/WebCoreJSBuiltins.h
@@ -0,0 +1,139 @@
+/*
+ * Copyright (c) 2015 Igalia
+ * Copyright (c) 2015 Igalia S.L.
+ * Copyright (c) 2015 Igalia.
+ * Copyright (c) 2015, 2016 Canon Inc. All rights reserved.
+ * Copyright (c) 2015, 2016, 2017 Canon Inc.
+ * Copyright (c) 2016, 2020 Apple Inc. All rights reserved.
+ * Copyright (c) 2022 Codeblog Corp. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+// DO NOT EDIT THIS FILE. It is automatically generated from JavaScript files for
+// builtins by the script: Source/JavaScriptCore/Scripts/generate-js-builtins.py
+
+#pragma once
+
+#include "ByteLengthQueuingStrategyBuiltins.h"
+#include "CountQueuingStrategyBuiltins.h"
+#include "JSBufferConstructorBuiltins.h"
+#include "JSBufferPrototypeBuiltins.h"
+#include "JSZigGlobalObjectBuiltins.h"
+#include "ReadableByteStreamControllerBuiltins.h"
+#include "ReadableByteStreamInternalsBuiltins.h"
+#include "ReadableStreamBYOBReaderBuiltins.h"
+#include "ReadableStreamBYOBRequestBuiltins.h"
+#include "ReadableStreamBuiltins.h"
+#include "ReadableStreamDefaultControllerBuiltins.h"
+#include "ReadableStreamDefaultReaderBuiltins.h"
+#include "ReadableStreamInternalsBuiltins.h"
+#include "StreamInternalsBuiltins.h"
+#include "TransformStreamBuiltins.h"
+#include "TransformStreamDefaultControllerBuiltins.h"
+#include "TransformStreamInternalsBuiltins.h"
+#include "WritableStreamDefaultControllerBuiltins.h"
+#include "WritableStreamDefaultWriterBuiltins.h"
+#include "WritableStreamInternalsBuiltins.h"
+#include <JavaScriptCore/VM.h>
+
+namespace WebCore {
+
+class JSBuiltinFunctions {
+public:
+ explicit JSBuiltinFunctions(JSC::VM& vm)
+ : m_vm(vm)
+ , m_byteLengthQueuingStrategyBuiltins(m_vm)
+ , m_countQueuingStrategyBuiltins(m_vm)
+ , m_jsBufferConstructorBuiltins(m_vm)
+ , m_jsBufferPrototypeBuiltins(m_vm)
+ , m_jsZigGlobalObjectBuiltins(m_vm)
+ , m_readableByteStreamControllerBuiltins(m_vm)
+ , m_readableByteStreamInternalsBuiltins(m_vm)
+ , m_readableStreamBuiltins(m_vm)
+ , m_readableStreamBYOBReaderBuiltins(m_vm)
+ , m_readableStreamBYOBRequestBuiltins(m_vm)
+ , m_readableStreamDefaultControllerBuiltins(m_vm)
+ , m_readableStreamDefaultReaderBuiltins(m_vm)
+ , m_readableStreamInternalsBuiltins(m_vm)
+ , m_streamInternalsBuiltins(m_vm)
+ , m_transformStreamBuiltins(m_vm)
+ , m_transformStreamDefaultControllerBuiltins(m_vm)
+ , m_transformStreamInternalsBuiltins(m_vm)
+ , m_writableStreamDefaultControllerBuiltins(m_vm)
+ , m_writableStreamDefaultWriterBuiltins(m_vm)
+ , m_writableStreamInternalsBuiltins(m_vm)
+ {
+ m_readableByteStreamInternalsBuiltins.exportNames();
+ m_readableStreamInternalsBuiltins.exportNames();
+ m_streamInternalsBuiltins.exportNames();
+ m_transformStreamInternalsBuiltins.exportNames();
+ m_writableStreamInternalsBuiltins.exportNames();
+ }
+
+ ByteLengthQueuingStrategyBuiltinsWrapper& byteLengthQueuingStrategyBuiltins() { return m_byteLengthQueuingStrategyBuiltins; }
+ CountQueuingStrategyBuiltinsWrapper& countQueuingStrategyBuiltins() { return m_countQueuingStrategyBuiltins; }
+ JSBufferConstructorBuiltinsWrapper& jsBufferConstructorBuiltins() { return m_jsBufferConstructorBuiltins; }
+ JSBufferPrototypeBuiltinsWrapper& jsBufferPrototypeBuiltins() { return m_jsBufferPrototypeBuiltins; }
+ JSZigGlobalObjectBuiltinsWrapper& jsZigGlobalObjectBuiltins() { return m_jsZigGlobalObjectBuiltins; }
+ ReadableByteStreamControllerBuiltinsWrapper& readableByteStreamControllerBuiltins() { return m_readableByteStreamControllerBuiltins; }
+ ReadableByteStreamInternalsBuiltinsWrapper& readableByteStreamInternalsBuiltins() { return m_readableByteStreamInternalsBuiltins; }
+ ReadableStreamBuiltinsWrapper& readableStreamBuiltins() { return m_readableStreamBuiltins; }
+ ReadableStreamBYOBReaderBuiltinsWrapper& readableStreamBYOBReaderBuiltins() { return m_readableStreamBYOBReaderBuiltins; }
+ ReadableStreamBYOBRequestBuiltinsWrapper& readableStreamBYOBRequestBuiltins() { return m_readableStreamBYOBRequestBuiltins; }
+ ReadableStreamDefaultControllerBuiltinsWrapper& readableStreamDefaultControllerBuiltins() { return m_readableStreamDefaultControllerBuiltins; }
+ ReadableStreamDefaultReaderBuiltinsWrapper& readableStreamDefaultReaderBuiltins() { return m_readableStreamDefaultReaderBuiltins; }
+ ReadableStreamInternalsBuiltinsWrapper& readableStreamInternalsBuiltins() { return m_readableStreamInternalsBuiltins; }
+ StreamInternalsBuiltinsWrapper& streamInternalsBuiltins() { return m_streamInternalsBuiltins; }
+ TransformStreamBuiltinsWrapper& transformStreamBuiltins() { return m_transformStreamBuiltins; }
+ TransformStreamDefaultControllerBuiltinsWrapper& transformStreamDefaultControllerBuiltins() { return m_transformStreamDefaultControllerBuiltins; }
+ TransformStreamInternalsBuiltinsWrapper& transformStreamInternalsBuiltins() { return m_transformStreamInternalsBuiltins; }
+ WritableStreamDefaultControllerBuiltinsWrapper& writableStreamDefaultControllerBuiltins() { return m_writableStreamDefaultControllerBuiltins; }
+ WritableStreamDefaultWriterBuiltinsWrapper& writableStreamDefaultWriterBuiltins() { return m_writableStreamDefaultWriterBuiltins; }
+ WritableStreamInternalsBuiltinsWrapper& writableStreamInternalsBuiltins() { return m_writableStreamInternalsBuiltins; }
+
+private:
+ JSC::VM& m_vm;
+ ByteLengthQueuingStrategyBuiltinsWrapper m_byteLengthQueuingStrategyBuiltins;
+ CountQueuingStrategyBuiltinsWrapper m_countQueuingStrategyBuiltins;
+ JSBufferConstructorBuiltinsWrapper m_jsBufferConstructorBuiltins;
+ JSBufferPrototypeBuiltinsWrapper m_jsBufferPrototypeBuiltins;
+ JSZigGlobalObjectBuiltinsWrapper m_jsZigGlobalObjectBuiltins;
+ ReadableByteStreamControllerBuiltinsWrapper m_readableByteStreamControllerBuiltins;
+ ReadableByteStreamInternalsBuiltinsWrapper m_readableByteStreamInternalsBuiltins;
+ ReadableStreamBuiltinsWrapper m_readableStreamBuiltins;
+ ReadableStreamBYOBReaderBuiltinsWrapper m_readableStreamBYOBReaderBuiltins;
+ ReadableStreamBYOBRequestBuiltinsWrapper m_readableStreamBYOBRequestBuiltins;
+ ReadableStreamDefaultControllerBuiltinsWrapper m_readableStreamDefaultControllerBuiltins;
+ ReadableStreamDefaultReaderBuiltinsWrapper m_readableStreamDefaultReaderBuiltins;
+ ReadableStreamInternalsBuiltinsWrapper m_readableStreamInternalsBuiltins;
+ StreamInternalsBuiltinsWrapper m_streamInternalsBuiltins;
+ TransformStreamBuiltinsWrapper m_transformStreamBuiltins;
+ TransformStreamDefaultControllerBuiltinsWrapper m_transformStreamDefaultControllerBuiltins;
+ TransformStreamInternalsBuiltinsWrapper m_transformStreamInternalsBuiltins;
+ WritableStreamDefaultControllerBuiltinsWrapper m_writableStreamDefaultControllerBuiltins;
+ WritableStreamDefaultWriterBuiltinsWrapper m_writableStreamDefaultWriterBuiltins;
+ WritableStreamInternalsBuiltinsWrapper m_writableStreamInternalsBuiltins;
+};
+
+} // namespace WebCore
diff --git a/src/bun.js/builtins/cpp/WritableStreamDefaultControllerBuiltins.cpp b/src/bun.js/builtins/cpp/WritableStreamDefaultControllerBuiltins.cpp
new file mode 100644
index 000000000..c259364d7
--- /dev/null
+++ b/src/bun.js/builtins/cpp/WritableStreamDefaultControllerBuiltins.cpp
@@ -0,0 +1,104 @@
+/*
+ * Copyright (c) 2015 Igalia
+ * Copyright (c) 2015 Igalia S.L.
+ * Copyright (c) 2015 Igalia.
+ * Copyright (c) 2015, 2016 Canon Inc. All rights reserved.
+ * Copyright (c) 2015, 2016, 2017 Canon Inc.
+ * Copyright (c) 2016, 2020 Apple Inc. All rights reserved.
+ * Copyright (c) 2022 Codeblog Corp. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+// DO NOT EDIT THIS FILE. It is automatically generated from JavaScript files for
+// builtins by the script: Source/JavaScriptCore/Scripts/generate-js-builtins.py
+
+#include "config.h"
+#include "WritableStreamDefaultControllerBuiltins.h"
+
+#include "WebCoreJSClientData.h"
+#include <JavaScriptCore/HeapInlines.h>
+#include <JavaScriptCore/IdentifierInlines.h>
+#include <JavaScriptCore/Intrinsic.h>
+#include <JavaScriptCore/JSCJSValueInlines.h>
+#include <JavaScriptCore/JSCellInlines.h>
+#include <JavaScriptCore/StructureInlines.h>
+#include <JavaScriptCore/VM.h>
+
+namespace WebCore {
+
+const JSC::ConstructAbility s_writableStreamDefaultControllerInitializeWritableStreamDefaultControllerCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_writableStreamDefaultControllerInitializeWritableStreamDefaultControllerCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_writableStreamDefaultControllerInitializeWritableStreamDefaultControllerCodeLength = 482;
+static const JSC::Intrinsic s_writableStreamDefaultControllerInitializeWritableStreamDefaultControllerCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_writableStreamDefaultControllerInitializeWritableStreamDefaultControllerCode =
+ "(function ()\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " @putByIdDirectPrivate(this, \"queue\", @newQueue());\n" \
+ " @putByIdDirectPrivate(this, \"abortSteps\", (reason) => {\n" \
+ " const result = @getByIdDirectPrivate(this, \"abortAlgorithm\").@call(@undefined, reason);\n" \
+ " @writableStreamDefaultControllerClearAlgorithms(this);\n" \
+ " return result;\n" \
+ " });\n" \
+ "\n" \
+ " @putByIdDirectPrivate(this, \"errorSteps\", () => {\n" \
+ " @resetQueue(@getByIdDirectPrivate(this, \"queue\"));\n" \
+ " });\n" \
+ "\n" \
+ " return this;\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_writableStreamDefaultControllerErrorCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_writableStreamDefaultControllerErrorCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_writableStreamDefaultControllerErrorCodeLength = 372;
+static const JSC::Intrinsic s_writableStreamDefaultControllerErrorCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_writableStreamDefaultControllerErrorCode =
+ "(function (e)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " if (@getByIdDirectPrivate(this, \"abortSteps\") === @undefined)\n" \
+ " throw @makeThisTypeError(\"WritableStreamDefaultController\", \"error\");\n" \
+ "\n" \
+ " const stream = @getByIdDirectPrivate(this, \"stream\");\n" \
+ " if (@getByIdDirectPrivate(stream, \"state\") !== \"writable\")\n" \
+ " return;\n" \
+ " @writableStreamDefaultControllerError(this, e);\n" \
+ "})\n" \
+;
+
+
+#define DEFINE_BUILTIN_GENERATOR(codeName, functionName, overriddenName, argumentCount) \
+JSC::FunctionExecutable* codeName##Generator(JSC::VM& vm) \
+{\
+ JSVMClientData* clientData = static_cast<JSVMClientData*>(vm.clientData); \
+ return clientData->builtinFunctions().writableStreamDefaultControllerBuiltins().codeName##Executable()->link(vm, nullptr, clientData->builtinFunctions().writableStreamDefaultControllerBuiltins().codeName##Source(), std::nullopt, s_##codeName##Intrinsic); \
+}
+WEBCORE_FOREACH_WRITABLESTREAMDEFAULTCONTROLLER_BUILTIN_CODE(DEFINE_BUILTIN_GENERATOR)
+#undef DEFINE_BUILTIN_GENERATOR
+
+
+} // namespace WebCore
diff --git a/src/bun.js/builtins/cpp/WritableStreamDefaultControllerBuiltins.h b/src/bun.js/builtins/cpp/WritableStreamDefaultControllerBuiltins.h
new file mode 100644
index 000000000..5ffd82b88
--- /dev/null
+++ b/src/bun.js/builtins/cpp/WritableStreamDefaultControllerBuiltins.h
@@ -0,0 +1,135 @@
+/*
+ * Copyright (c) 2015 Igalia
+ * Copyright (c) 2015 Igalia S.L.
+ * Copyright (c) 2015 Igalia.
+ * Copyright (c) 2015, 2016 Canon Inc. All rights reserved.
+ * Copyright (c) 2015, 2016, 2017 Canon Inc.
+ * Copyright (c) 2016, 2020 Apple Inc. All rights reserved.
+ * Copyright (c) 2022 Codeblog Corp. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+// DO NOT EDIT THIS FILE. It is automatically generated from JavaScript files for
+// builtins by the script: Source/JavaScriptCore/Scripts/generate-js-builtins.py
+
+#pragma once
+
+#include <JavaScriptCore/BuiltinUtils.h>
+#include <JavaScriptCore/Identifier.h>
+#include <JavaScriptCore/JSFunction.h>
+#include <JavaScriptCore/UnlinkedFunctionExecutable.h>
+
+namespace JSC {
+class FunctionExecutable;
+}
+
+namespace WebCore {
+
+/* WritableStreamDefaultController */
+extern const char* const s_writableStreamDefaultControllerInitializeWritableStreamDefaultControllerCode;
+extern const int s_writableStreamDefaultControllerInitializeWritableStreamDefaultControllerCodeLength;
+extern const JSC::ConstructAbility s_writableStreamDefaultControllerInitializeWritableStreamDefaultControllerCodeConstructAbility;
+extern const JSC::ConstructorKind s_writableStreamDefaultControllerInitializeWritableStreamDefaultControllerCodeConstructorKind;
+extern const char* const s_writableStreamDefaultControllerErrorCode;
+extern const int s_writableStreamDefaultControllerErrorCodeLength;
+extern const JSC::ConstructAbility s_writableStreamDefaultControllerErrorCodeConstructAbility;
+extern const JSC::ConstructorKind s_writableStreamDefaultControllerErrorCodeConstructorKind;
+
+#define WEBCORE_FOREACH_WRITABLESTREAMDEFAULTCONTROLLER_BUILTIN_DATA(macro) \
+ macro(initializeWritableStreamDefaultController, writableStreamDefaultControllerInitializeWritableStreamDefaultController, 0) \
+ macro(error, writableStreamDefaultControllerError, 1) \
+
+#define WEBCORE_BUILTIN_WRITABLESTREAMDEFAULTCONTROLLER_INITIALIZEWRITABLESTREAMDEFAULTCONTROLLER 1
+#define WEBCORE_BUILTIN_WRITABLESTREAMDEFAULTCONTROLLER_ERROR 1
+
+#define WEBCORE_FOREACH_WRITABLESTREAMDEFAULTCONTROLLER_BUILTIN_CODE(macro) \
+ macro(writableStreamDefaultControllerInitializeWritableStreamDefaultControllerCode, initializeWritableStreamDefaultController, ASCIILiteral(), s_writableStreamDefaultControllerInitializeWritableStreamDefaultControllerCodeLength) \
+ macro(writableStreamDefaultControllerErrorCode, error, ASCIILiteral(), s_writableStreamDefaultControllerErrorCodeLength) \
+
+#define WEBCORE_FOREACH_WRITABLESTREAMDEFAULTCONTROLLER_BUILTIN_FUNCTION_NAME(macro) \
+ macro(error) \
+ macro(initializeWritableStreamDefaultController) \
+
+#define DECLARE_BUILTIN_GENERATOR(codeName, functionName, overriddenName, argumentCount) \
+ JSC::FunctionExecutable* codeName##Generator(JSC::VM&);
+
+WEBCORE_FOREACH_WRITABLESTREAMDEFAULTCONTROLLER_BUILTIN_CODE(DECLARE_BUILTIN_GENERATOR)
+#undef DECLARE_BUILTIN_GENERATOR
+
+class WritableStreamDefaultControllerBuiltinsWrapper : private JSC::WeakHandleOwner {
+public:
+ explicit WritableStreamDefaultControllerBuiltinsWrapper(JSC::VM& vm)
+ : m_vm(vm)
+ WEBCORE_FOREACH_WRITABLESTREAMDEFAULTCONTROLLER_BUILTIN_FUNCTION_NAME(INITIALIZE_BUILTIN_NAMES)
+#define INITIALIZE_BUILTIN_SOURCE_MEMBERS(name, functionName, overriddenName, length) , m_##name##Source(JSC::makeSource(StringImpl::createWithoutCopying(s_##name, length), { }))
+ WEBCORE_FOREACH_WRITABLESTREAMDEFAULTCONTROLLER_BUILTIN_CODE(INITIALIZE_BUILTIN_SOURCE_MEMBERS)
+#undef INITIALIZE_BUILTIN_SOURCE_MEMBERS
+ {
+ }
+
+#define EXPOSE_BUILTIN_EXECUTABLES(name, functionName, overriddenName, length) \
+ JSC::UnlinkedFunctionExecutable* name##Executable(); \
+ const JSC::SourceCode& name##Source() const { return m_##name##Source; }
+ WEBCORE_FOREACH_WRITABLESTREAMDEFAULTCONTROLLER_BUILTIN_CODE(EXPOSE_BUILTIN_EXECUTABLES)
+#undef EXPOSE_BUILTIN_EXECUTABLES
+
+ WEBCORE_FOREACH_WRITABLESTREAMDEFAULTCONTROLLER_BUILTIN_FUNCTION_NAME(DECLARE_BUILTIN_IDENTIFIER_ACCESSOR)
+
+ void exportNames();
+
+private:
+ JSC::VM& m_vm;
+
+ WEBCORE_FOREACH_WRITABLESTREAMDEFAULTCONTROLLER_BUILTIN_FUNCTION_NAME(DECLARE_BUILTIN_NAMES)
+
+#define DECLARE_BUILTIN_SOURCE_MEMBERS(name, functionName, overriddenName, length) \
+ JSC::SourceCode m_##name##Source;\
+ JSC::Weak<JSC::UnlinkedFunctionExecutable> m_##name##Executable;
+ WEBCORE_FOREACH_WRITABLESTREAMDEFAULTCONTROLLER_BUILTIN_CODE(DECLARE_BUILTIN_SOURCE_MEMBERS)
+#undef DECLARE_BUILTIN_SOURCE_MEMBERS
+
+};
+
+#define DEFINE_BUILTIN_EXECUTABLES(name, functionName, overriddenName, length) \
+inline JSC::UnlinkedFunctionExecutable* WritableStreamDefaultControllerBuiltinsWrapper::name##Executable() \
+{\
+ if (!m_##name##Executable) {\
+ JSC::Identifier executableName = functionName##PublicName();\
+ if (overriddenName)\
+ executableName = JSC::Identifier::fromString(m_vm, overriddenName);\
+ m_##name##Executable = JSC::Weak<JSC::UnlinkedFunctionExecutable>(JSC::createBuiltinExecutable(m_vm, m_##name##Source, executableName, s_##name##ConstructorKind, s_##name##ConstructAbility), this, &m_##name##Executable);\
+ }\
+ return m_##name##Executable.get();\
+}
+WEBCORE_FOREACH_WRITABLESTREAMDEFAULTCONTROLLER_BUILTIN_CODE(DEFINE_BUILTIN_EXECUTABLES)
+#undef DEFINE_BUILTIN_EXECUTABLES
+
+inline void WritableStreamDefaultControllerBuiltinsWrapper::exportNames()
+{
+#define EXPORT_FUNCTION_NAME(name) m_vm.propertyNames->appendExternalName(name##PublicName(), name##PrivateName());
+ WEBCORE_FOREACH_WRITABLESTREAMDEFAULTCONTROLLER_BUILTIN_FUNCTION_NAME(EXPORT_FUNCTION_NAME)
+#undef EXPORT_FUNCTION_NAME
+}
+
+} // namespace WebCore
diff --git a/src/bun.js/builtins/cpp/WritableStreamDefaultWriterBuiltins.cpp b/src/bun.js/builtins/cpp/WritableStreamDefaultWriterBuiltins.cpp
new file mode 100644
index 000000000..160f7af20
--- /dev/null
+++ b/src/bun.js/builtins/cpp/WritableStreamDefaultWriterBuiltins.cpp
@@ -0,0 +1,217 @@
+/*
+ * Copyright (c) 2015 Igalia
+ * Copyright (c) 2015 Igalia S.L.
+ * Copyright (c) 2015 Igalia.
+ * Copyright (c) 2015, 2016 Canon Inc. All rights reserved.
+ * Copyright (c) 2015, 2016, 2017 Canon Inc.
+ * Copyright (c) 2016, 2020 Apple Inc. All rights reserved.
+ * Copyright (c) 2022 Codeblog Corp. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+// DO NOT EDIT THIS FILE. It is automatically generated from JavaScript files for
+// builtins by the script: Source/JavaScriptCore/Scripts/generate-js-builtins.py
+
+#include "config.h"
+#include "WritableStreamDefaultWriterBuiltins.h"
+
+#include "WebCoreJSClientData.h"
+#include <JavaScriptCore/HeapInlines.h>
+#include <JavaScriptCore/IdentifierInlines.h>
+#include <JavaScriptCore/Intrinsic.h>
+#include <JavaScriptCore/JSCJSValueInlines.h>
+#include <JavaScriptCore/JSCellInlines.h>
+#include <JavaScriptCore/StructureInlines.h>
+#include <JavaScriptCore/VM.h>
+
+namespace WebCore {
+
+const JSC::ConstructAbility s_writableStreamDefaultWriterInitializeWritableStreamDefaultWriterCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_writableStreamDefaultWriterInitializeWritableStreamDefaultWriterCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_writableStreamDefaultWriterInitializeWritableStreamDefaultWriterCodeLength = 376;
+static const JSC::Intrinsic s_writableStreamDefaultWriterInitializeWritableStreamDefaultWriterCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_writableStreamDefaultWriterInitializeWritableStreamDefaultWriterCode =
+ "(function (stream)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " //\n" \
+ " //\n" \
+ " const internalStream = @getInternalWritableStream(stream);\n" \
+ " if (internalStream)\n" \
+ " stream = internalStream;\n" \
+ "\n" \
+ " if (!@isWritableStream(stream))\n" \
+ " @throwTypeError(\"WritableStreamDefaultWriter constructor takes a WritableStream\");\n" \
+ "\n" \
+ " @setUpWritableStreamDefaultWriter(this, stream);\n" \
+ " return this;\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_writableStreamDefaultWriterClosedCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_writableStreamDefaultWriterClosedCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_writableStreamDefaultWriterClosedCodeLength = 247;
+static const JSC::Intrinsic s_writableStreamDefaultWriterClosedCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_writableStreamDefaultWriterClosedCode =
+ "(function ()\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " if (!@isWritableStreamDefaultWriter(this))\n" \
+ " return @Promise.@reject(@makeGetterTypeError(\"WritableStreamDefaultWriter\", \"closed\"));\n" \
+ "\n" \
+ " return @getByIdDirectPrivate(this, \"closedPromise\").@promise;\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_writableStreamDefaultWriterDesiredSizeCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_writableStreamDefaultWriterDesiredSizeCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_writableStreamDefaultWriterDesiredSizeCodeLength = 359;
+static const JSC::Intrinsic s_writableStreamDefaultWriterDesiredSizeCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_writableStreamDefaultWriterDesiredSizeCode =
+ "(function ()\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " if (!@isWritableStreamDefaultWriter(this))\n" \
+ " throw @makeThisTypeError(\"WritableStreamDefaultWriter\", \"desiredSize\");\n" \
+ "\n" \
+ " if (@getByIdDirectPrivate(this, \"stream\") === @undefined)\n" \
+ " @throwTypeError(\"WritableStreamDefaultWriter has no stream\");\n" \
+ "\n" \
+ " return @writableStreamDefaultWriterGetDesiredSize(this);\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_writableStreamDefaultWriterReadyCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_writableStreamDefaultWriterReadyCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_writableStreamDefaultWriterReadyCodeLength = 243;
+static const JSC::Intrinsic s_writableStreamDefaultWriterReadyCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_writableStreamDefaultWriterReadyCode =
+ "(function ()\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " if (!@isWritableStreamDefaultWriter(this))\n" \
+ " return @Promise.@reject(@makeThisTypeError(\"WritableStreamDefaultWriter\", \"ready\"));\n" \
+ "\n" \
+ " return @getByIdDirectPrivate(this, \"readyPromise\").@promise;\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_writableStreamDefaultWriterAbortCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_writableStreamDefaultWriterAbortCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_writableStreamDefaultWriterAbortCodeLength = 401;
+static const JSC::Intrinsic s_writableStreamDefaultWriterAbortCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_writableStreamDefaultWriterAbortCode =
+ "(function (reason)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " if (!@isWritableStreamDefaultWriter(this))\n" \
+ " return @Promise.@reject(@makeThisTypeError(\"WritableStreamDefaultWriter\", \"abort\"));\n" \
+ "\n" \
+ " if (@getByIdDirectPrivate(this, \"stream\") === @undefined)\n" \
+ " return @Promise.@reject(@makeTypeError(\"WritableStreamDefaultWriter has no stream\"));\n" \
+ "\n" \
+ " return @writableStreamDefaultWriterAbort(this, reason);\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_writableStreamDefaultWriterCloseCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_writableStreamDefaultWriterCloseCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_writableStreamDefaultWriterCloseCodeLength = 569;
+static const JSC::Intrinsic s_writableStreamDefaultWriterCloseCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_writableStreamDefaultWriterCloseCode =
+ "(function ()\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " if (!@isWritableStreamDefaultWriter(this))\n" \
+ " return @Promise.@reject(@makeThisTypeError(\"WritableStreamDefaultWriter\", \"close\"));\n" \
+ "\n" \
+ " const stream = @getByIdDirectPrivate(this, \"stream\");\n" \
+ " if (stream === @undefined)\n" \
+ " return @Promise.@reject(@makeTypeError(\"WritableStreamDefaultWriter has no stream\"));\n" \
+ "\n" \
+ " if (@writableStreamCloseQueuedOrInFlight(stream))\n" \
+ " return @Promise.@reject(@makeTypeError(\"WritableStreamDefaultWriter is being closed\"));\n" \
+ " \n" \
+ " return @writableStreamDefaultWriterClose(this);\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_writableStreamDefaultWriterReleaseLockCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_writableStreamDefaultWriterReleaseLockCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_writableStreamDefaultWriterReleaseLockCodeLength = 387;
+static const JSC::Intrinsic s_writableStreamDefaultWriterReleaseLockCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_writableStreamDefaultWriterReleaseLockCode =
+ "(function ()\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " if (!@isWritableStreamDefaultWriter(this))\n" \
+ " throw @makeThisTypeError(\"WritableStreamDefaultWriter\", \"releaseLock\");\n" \
+ "\n" \
+ " const stream = @getByIdDirectPrivate(this, \"stream\");\n" \
+ " if (stream === @undefined)\n" \
+ " return;\n" \
+ "\n" \
+ " @assert(@getByIdDirectPrivate(stream, \"writer\") !== @undefined);\n" \
+ " @writableStreamDefaultWriterRelease(this);\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_writableStreamDefaultWriterWriteCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_writableStreamDefaultWriterWriteCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_writableStreamDefaultWriterWriteCodeLength = 399;
+static const JSC::Intrinsic s_writableStreamDefaultWriterWriteCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_writableStreamDefaultWriterWriteCode =
+ "(function (chunk)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " if (!@isWritableStreamDefaultWriter(this))\n" \
+ " return @Promise.@reject(@makeThisTypeError(\"WritableStreamDefaultWriter\", \"write\"));\n" \
+ "\n" \
+ " if (@getByIdDirectPrivate(this, \"stream\") === @undefined)\n" \
+ " return @Promise.@reject(@makeTypeError(\"WritableStreamDefaultWriter has no stream\"));\n" \
+ "\n" \
+ " return @writableStreamDefaultWriterWrite(this, chunk);\n" \
+ "})\n" \
+;
+
+
+#define DEFINE_BUILTIN_GENERATOR(codeName, functionName, overriddenName, argumentCount) \
+JSC::FunctionExecutable* codeName##Generator(JSC::VM& vm) \
+{\
+ JSVMClientData* clientData = static_cast<JSVMClientData*>(vm.clientData); \
+ return clientData->builtinFunctions().writableStreamDefaultWriterBuiltins().codeName##Executable()->link(vm, nullptr, clientData->builtinFunctions().writableStreamDefaultWriterBuiltins().codeName##Source(), std::nullopt, s_##codeName##Intrinsic); \
+}
+WEBCORE_FOREACH_WRITABLESTREAMDEFAULTWRITER_BUILTIN_CODE(DEFINE_BUILTIN_GENERATOR)
+#undef DEFINE_BUILTIN_GENERATOR
+
+
+} // namespace WebCore
diff --git a/src/bun.js/builtins/cpp/WritableStreamDefaultWriterBuiltins.h b/src/bun.js/builtins/cpp/WritableStreamDefaultWriterBuiltins.h
new file mode 100644
index 000000000..28455eedf
--- /dev/null
+++ b/src/bun.js/builtins/cpp/WritableStreamDefaultWriterBuiltins.h
@@ -0,0 +1,183 @@
+/*
+ * Copyright (c) 2015 Igalia
+ * Copyright (c) 2015 Igalia S.L.
+ * Copyright (c) 2015 Igalia.
+ * Copyright (c) 2015, 2016 Canon Inc. All rights reserved.
+ * Copyright (c) 2015, 2016, 2017 Canon Inc.
+ * Copyright (c) 2016, 2020 Apple Inc. All rights reserved.
+ * Copyright (c) 2022 Codeblog Corp. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+// DO NOT EDIT THIS FILE. It is automatically generated from JavaScript files for
+// builtins by the script: Source/JavaScriptCore/Scripts/generate-js-builtins.py
+
+#pragma once
+
+#include <JavaScriptCore/BuiltinUtils.h>
+#include <JavaScriptCore/Identifier.h>
+#include <JavaScriptCore/JSFunction.h>
+#include <JavaScriptCore/UnlinkedFunctionExecutable.h>
+
+namespace JSC {
+class FunctionExecutable;
+}
+
+namespace WebCore {
+
+/* WritableStreamDefaultWriter */
+extern const char* const s_writableStreamDefaultWriterInitializeWritableStreamDefaultWriterCode;
+extern const int s_writableStreamDefaultWriterInitializeWritableStreamDefaultWriterCodeLength;
+extern const JSC::ConstructAbility s_writableStreamDefaultWriterInitializeWritableStreamDefaultWriterCodeConstructAbility;
+extern const JSC::ConstructorKind s_writableStreamDefaultWriterInitializeWritableStreamDefaultWriterCodeConstructorKind;
+extern const char* const s_writableStreamDefaultWriterClosedCode;
+extern const int s_writableStreamDefaultWriterClosedCodeLength;
+extern const JSC::ConstructAbility s_writableStreamDefaultWriterClosedCodeConstructAbility;
+extern const JSC::ConstructorKind s_writableStreamDefaultWriterClosedCodeConstructorKind;
+extern const char* const s_writableStreamDefaultWriterDesiredSizeCode;
+extern const int s_writableStreamDefaultWriterDesiredSizeCodeLength;
+extern const JSC::ConstructAbility s_writableStreamDefaultWriterDesiredSizeCodeConstructAbility;
+extern const JSC::ConstructorKind s_writableStreamDefaultWriterDesiredSizeCodeConstructorKind;
+extern const char* const s_writableStreamDefaultWriterReadyCode;
+extern const int s_writableStreamDefaultWriterReadyCodeLength;
+extern const JSC::ConstructAbility s_writableStreamDefaultWriterReadyCodeConstructAbility;
+extern const JSC::ConstructorKind s_writableStreamDefaultWriterReadyCodeConstructorKind;
+extern const char* const s_writableStreamDefaultWriterAbortCode;
+extern const int s_writableStreamDefaultWriterAbortCodeLength;
+extern const JSC::ConstructAbility s_writableStreamDefaultWriterAbortCodeConstructAbility;
+extern const JSC::ConstructorKind s_writableStreamDefaultWriterAbortCodeConstructorKind;
+extern const char* const s_writableStreamDefaultWriterCloseCode;
+extern const int s_writableStreamDefaultWriterCloseCodeLength;
+extern const JSC::ConstructAbility s_writableStreamDefaultWriterCloseCodeConstructAbility;
+extern const JSC::ConstructorKind s_writableStreamDefaultWriterCloseCodeConstructorKind;
+extern const char* const s_writableStreamDefaultWriterReleaseLockCode;
+extern const int s_writableStreamDefaultWriterReleaseLockCodeLength;
+extern const JSC::ConstructAbility s_writableStreamDefaultWriterReleaseLockCodeConstructAbility;
+extern const JSC::ConstructorKind s_writableStreamDefaultWriterReleaseLockCodeConstructorKind;
+extern const char* const s_writableStreamDefaultWriterWriteCode;
+extern const int s_writableStreamDefaultWriterWriteCodeLength;
+extern const JSC::ConstructAbility s_writableStreamDefaultWriterWriteCodeConstructAbility;
+extern const JSC::ConstructorKind s_writableStreamDefaultWriterWriteCodeConstructorKind;
+
+#define WEBCORE_FOREACH_WRITABLESTREAMDEFAULTWRITER_BUILTIN_DATA(macro) \
+ macro(initializeWritableStreamDefaultWriter, writableStreamDefaultWriterInitializeWritableStreamDefaultWriter, 1) \
+ macro(closed, writableStreamDefaultWriterClosed, 0) \
+ macro(desiredSize, writableStreamDefaultWriterDesiredSize, 0) \
+ macro(ready, writableStreamDefaultWriterReady, 0) \
+ macro(abort, writableStreamDefaultWriterAbort, 1) \
+ macro(close, writableStreamDefaultWriterClose, 0) \
+ macro(releaseLock, writableStreamDefaultWriterReleaseLock, 0) \
+ macro(write, writableStreamDefaultWriterWrite, 1) \
+
+#define WEBCORE_BUILTIN_WRITABLESTREAMDEFAULTWRITER_INITIALIZEWRITABLESTREAMDEFAULTWRITER 1
+#define WEBCORE_BUILTIN_WRITABLESTREAMDEFAULTWRITER_CLOSED 1
+#define WEBCORE_BUILTIN_WRITABLESTREAMDEFAULTWRITER_DESIREDSIZE 1
+#define WEBCORE_BUILTIN_WRITABLESTREAMDEFAULTWRITER_READY 1
+#define WEBCORE_BUILTIN_WRITABLESTREAMDEFAULTWRITER_ABORT 1
+#define WEBCORE_BUILTIN_WRITABLESTREAMDEFAULTWRITER_CLOSE 1
+#define WEBCORE_BUILTIN_WRITABLESTREAMDEFAULTWRITER_RELEASELOCK 1
+#define WEBCORE_BUILTIN_WRITABLESTREAMDEFAULTWRITER_WRITE 1
+
+#define WEBCORE_FOREACH_WRITABLESTREAMDEFAULTWRITER_BUILTIN_CODE(macro) \
+ macro(writableStreamDefaultWriterInitializeWritableStreamDefaultWriterCode, initializeWritableStreamDefaultWriter, ASCIILiteral(), s_writableStreamDefaultWriterInitializeWritableStreamDefaultWriterCodeLength) \
+ macro(writableStreamDefaultWriterClosedCode, closed, "get closed"_s, s_writableStreamDefaultWriterClosedCodeLength) \
+ macro(writableStreamDefaultWriterDesiredSizeCode, desiredSize, "get desiredSize"_s, s_writableStreamDefaultWriterDesiredSizeCodeLength) \
+ macro(writableStreamDefaultWriterReadyCode, ready, "get ready"_s, s_writableStreamDefaultWriterReadyCodeLength) \
+ macro(writableStreamDefaultWriterAbortCode, abort, ASCIILiteral(), s_writableStreamDefaultWriterAbortCodeLength) \
+ macro(writableStreamDefaultWriterCloseCode, close, ASCIILiteral(), s_writableStreamDefaultWriterCloseCodeLength) \
+ macro(writableStreamDefaultWriterReleaseLockCode, releaseLock, ASCIILiteral(), s_writableStreamDefaultWriterReleaseLockCodeLength) \
+ macro(writableStreamDefaultWriterWriteCode, write, ASCIILiteral(), s_writableStreamDefaultWriterWriteCodeLength) \
+
+#define WEBCORE_FOREACH_WRITABLESTREAMDEFAULTWRITER_BUILTIN_FUNCTION_NAME(macro) \
+ macro(abort) \
+ macro(close) \
+ macro(closed) \
+ macro(desiredSize) \
+ macro(initializeWritableStreamDefaultWriter) \
+ macro(ready) \
+ macro(releaseLock) \
+ macro(write) \
+
+#define DECLARE_BUILTIN_GENERATOR(codeName, functionName, overriddenName, argumentCount) \
+ JSC::FunctionExecutable* codeName##Generator(JSC::VM&);
+
+WEBCORE_FOREACH_WRITABLESTREAMDEFAULTWRITER_BUILTIN_CODE(DECLARE_BUILTIN_GENERATOR)
+#undef DECLARE_BUILTIN_GENERATOR
+
+class WritableStreamDefaultWriterBuiltinsWrapper : private JSC::WeakHandleOwner {
+public:
+ explicit WritableStreamDefaultWriterBuiltinsWrapper(JSC::VM& vm)
+ : m_vm(vm)
+ WEBCORE_FOREACH_WRITABLESTREAMDEFAULTWRITER_BUILTIN_FUNCTION_NAME(INITIALIZE_BUILTIN_NAMES)
+#define INITIALIZE_BUILTIN_SOURCE_MEMBERS(name, functionName, overriddenName, length) , m_##name##Source(JSC::makeSource(StringImpl::createWithoutCopying(s_##name, length), { }))
+ WEBCORE_FOREACH_WRITABLESTREAMDEFAULTWRITER_BUILTIN_CODE(INITIALIZE_BUILTIN_SOURCE_MEMBERS)
+#undef INITIALIZE_BUILTIN_SOURCE_MEMBERS
+ {
+ }
+
+#define EXPOSE_BUILTIN_EXECUTABLES(name, functionName, overriddenName, length) \
+ JSC::UnlinkedFunctionExecutable* name##Executable(); \
+ const JSC::SourceCode& name##Source() const { return m_##name##Source; }
+ WEBCORE_FOREACH_WRITABLESTREAMDEFAULTWRITER_BUILTIN_CODE(EXPOSE_BUILTIN_EXECUTABLES)
+#undef EXPOSE_BUILTIN_EXECUTABLES
+
+ WEBCORE_FOREACH_WRITABLESTREAMDEFAULTWRITER_BUILTIN_FUNCTION_NAME(DECLARE_BUILTIN_IDENTIFIER_ACCESSOR)
+
+ void exportNames();
+
+private:
+ JSC::VM& m_vm;
+
+ WEBCORE_FOREACH_WRITABLESTREAMDEFAULTWRITER_BUILTIN_FUNCTION_NAME(DECLARE_BUILTIN_NAMES)
+
+#define DECLARE_BUILTIN_SOURCE_MEMBERS(name, functionName, overriddenName, length) \
+ JSC::SourceCode m_##name##Source;\
+ JSC::Weak<JSC::UnlinkedFunctionExecutable> m_##name##Executable;
+ WEBCORE_FOREACH_WRITABLESTREAMDEFAULTWRITER_BUILTIN_CODE(DECLARE_BUILTIN_SOURCE_MEMBERS)
+#undef DECLARE_BUILTIN_SOURCE_MEMBERS
+
+};
+
+#define DEFINE_BUILTIN_EXECUTABLES(name, functionName, overriddenName, length) \
+inline JSC::UnlinkedFunctionExecutable* WritableStreamDefaultWriterBuiltinsWrapper::name##Executable() \
+{\
+ if (!m_##name##Executable) {\
+ JSC::Identifier executableName = functionName##PublicName();\
+ if (overriddenName)\
+ executableName = JSC::Identifier::fromString(m_vm, overriddenName);\
+ m_##name##Executable = JSC::Weak<JSC::UnlinkedFunctionExecutable>(JSC::createBuiltinExecutable(m_vm, m_##name##Source, executableName, s_##name##ConstructorKind, s_##name##ConstructAbility), this, &m_##name##Executable);\
+ }\
+ return m_##name##Executable.get();\
+}
+WEBCORE_FOREACH_WRITABLESTREAMDEFAULTWRITER_BUILTIN_CODE(DEFINE_BUILTIN_EXECUTABLES)
+#undef DEFINE_BUILTIN_EXECUTABLES
+
+inline void WritableStreamDefaultWriterBuiltinsWrapper::exportNames()
+{
+#define EXPORT_FUNCTION_NAME(name) m_vm.propertyNames->appendExternalName(name##PublicName(), name##PrivateName());
+ WEBCORE_FOREACH_WRITABLESTREAMDEFAULTWRITER_BUILTIN_FUNCTION_NAME(EXPORT_FUNCTION_NAME)
+#undef EXPORT_FUNCTION_NAME
+}
+
+} // namespace WebCore
diff --git a/src/bun.js/builtins/cpp/WritableStreamInternalsBuiltins.cpp b/src/bun.js/builtins/cpp/WritableStreamInternalsBuiltins.cpp
new file mode 100644
index 000000000..34a680bdc
--- /dev/null
+++ b/src/bun.js/builtins/cpp/WritableStreamInternalsBuiltins.cpp
@@ -0,0 +1,1183 @@
+/*
+ * Copyright (c) 2015 Igalia
+ * Copyright (c) 2015 Igalia S.L.
+ * Copyright (c) 2015 Igalia.
+ * Copyright (c) 2015, 2016 Canon Inc. All rights reserved.
+ * Copyright (c) 2015, 2016, 2017 Canon Inc.
+ * Copyright (c) 2016, 2020 Apple Inc. All rights reserved.
+ * Copyright (c) 2022 Codeblog Corp. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+// DO NOT EDIT THIS FILE. It is automatically generated from JavaScript files for
+// builtins by the script: Source/JavaScriptCore/Scripts/generate-js-builtins.py
+
+#include "config.h"
+#include "WritableStreamInternalsBuiltins.h"
+
+#include "WebCoreJSClientData.h"
+#include <JavaScriptCore/HeapInlines.h>
+#include <JavaScriptCore/IdentifierInlines.h>
+#include <JavaScriptCore/Intrinsic.h>
+#include <JavaScriptCore/JSCJSValueInlines.h>
+#include <JavaScriptCore/JSCellInlines.h>
+#include <JavaScriptCore/StructureInlines.h>
+#include <JavaScriptCore/VM.h>
+
+namespace WebCore {
+
+const JSC::ConstructAbility s_writableStreamInternalsIsWritableStreamCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_writableStreamInternalsIsWritableStreamCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_writableStreamInternalsIsWritableStreamCodeLength = 126;
+static const JSC::Intrinsic s_writableStreamInternalsIsWritableStreamCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_writableStreamInternalsIsWritableStreamCode =
+ "(function (stream)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " return @isObject(stream) && !!@getByIdDirectPrivate(stream, \"underlyingSink\");\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_writableStreamInternalsIsWritableStreamDefaultWriterCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_writableStreamInternalsIsWritableStreamDefaultWriterCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_writableStreamInternalsIsWritableStreamDefaultWriterCodeLength = 125;
+static const JSC::Intrinsic s_writableStreamInternalsIsWritableStreamDefaultWriterCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_writableStreamInternalsIsWritableStreamDefaultWriterCode =
+ "(function (writer)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " return @isObject(writer) && !!@getByIdDirectPrivate(writer, \"closedPromise\");\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_writableStreamInternalsAcquireWritableStreamDefaultWriterCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_writableStreamInternalsAcquireWritableStreamDefaultWriterCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_writableStreamInternalsAcquireWritableStreamDefaultWriterCodeLength = 77;
+static const JSC::Intrinsic s_writableStreamInternalsAcquireWritableStreamDefaultWriterCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_writableStreamInternalsAcquireWritableStreamDefaultWriterCode =
+ "(function (stream)\n" \
+ "{\n" \
+ " return new @WritableStreamDefaultWriter(stream);\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_writableStreamInternalsCreateWritableStreamCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_writableStreamInternalsCreateWritableStreamCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_writableStreamInternalsCreateWritableStreamCodeLength = 588;
+static const JSC::Intrinsic s_writableStreamInternalsCreateWritableStreamCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_writableStreamInternalsCreateWritableStreamCode =
+ "(function (startAlgorithm, writeAlgorithm, closeAlgorithm, abortAlgorithm, highWaterMark, sizeAlgorithm)\n" \
+ "{\n" \
+ " @assert(typeof highWaterMark === \"number\" && !@isNaN(highWaterMark) && highWaterMark >= 0);\n" \
+ "\n" \
+ " const internalStream = { };\n" \
+ " @initializeWritableStreamSlots(internalStream, { });\n" \
+ " const controller = new @WritableStreamDefaultController();\n" \
+ "\n" \
+ " @setUpWritableStreamDefaultController(internalStream, controller, startAlgorithm, writeAlgorithm, closeAlgorithm, abortAlgorithm, highWaterMark, sizeAlgorithm);\n" \
+ "\n" \
+ " return @createWritableStreamFromInternal(internalStream);\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_writableStreamInternalsCreateInternalWritableStreamFromUnderlyingSinkCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_writableStreamInternalsCreateInternalWritableStreamFromUnderlyingSinkCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_writableStreamInternalsCreateInternalWritableStreamFromUnderlyingSinkCodeLength = 1776;
+static const JSC::Intrinsic s_writableStreamInternalsCreateInternalWritableStreamFromUnderlyingSinkCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_writableStreamInternalsCreateInternalWritableStreamFromUnderlyingSinkCode =
+ "(function (underlyingSink, strategy)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " const stream = { };\n" \
+ "\n" \
+ " if (underlyingSink === @undefined)\n" \
+ " underlyingSink = { };\n" \
+ "\n" \
+ " if (strategy === @undefined)\n" \
+ " strategy = { };\n" \
+ "\n" \
+ " if (!@isObject(underlyingSink))\n" \
+ " @throwTypeError(\"WritableStream constructor takes an object as first argument\");\n" \
+ "\n" \
+ " if (\"type\" in underlyingSink)\n" \
+ " @throwRangeError(\"Invalid type is specified\");\n" \
+ "\n" \
+ " const sizeAlgorithm = @extractSizeAlgorithm(strategy);\n" \
+ " const highWaterMark = @extractHighWaterMark(strategy, 1);\n" \
+ "\n" \
+ " const underlyingSinkDict = { };\n" \
+ " if (\"start\" in underlyingSink) {\n" \
+ " underlyingSinkDict[\"start\"] = underlyingSink[\"start\"];\n" \
+ " if (typeof underlyingSinkDict[\"start\"] !== \"function\")\n" \
+ " @throwTypeError(\"underlyingSink.start should be a function\");\n" \
+ " }\n" \
+ " if (\"write\" in underlyingSink) {\n" \
+ " underlyingSinkDict[\"write\"] = underlyingSink[\"write\"];\n" \
+ " if (typeof underlyingSinkDict[\"write\"] !== \"function\")\n" \
+ " @throwTypeError(\"underlyingSink.write should be a function\");\n" \
+ " }\n" \
+ " if (\"close\" in underlyingSink) {\n" \
+ " underlyingSinkDict[\"close\"] = underlyingSink[\"close\"];\n" \
+ " if (typeof underlyingSinkDict[\"close\"] !== \"function\")\n" \
+ " @throwTypeError(\"underlyingSink.close should be a function\");\n" \
+ " }\n" \
+ " if (\"abort\" in underlyingSink) {\n" \
+ " underlyingSinkDict[\"abort\"] = underlyingSink[\"abort\"];\n" \
+ " if (typeof underlyingSinkDict[\"abort\"] !== \"function\")\n" \
+ " @throwTypeError(\"underlyingSink.abort should be a function\");\n" \
+ " }\n" \
+ "\n" \
+ " @initializeWritableStreamSlots(stream, underlyingSink);\n" \
+ " @setUpWritableStreamDefaultControllerFromUnderlyingSink(stream, underlyingSink, underlyingSinkDict, highWaterMark, sizeAlgorithm);\n" \
+ "\n" \
+ " return stream;\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_writableStreamInternalsInitializeWritableStreamSlotsCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_writableStreamInternalsInitializeWritableStreamSlotsCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_writableStreamInternalsInitializeWritableStreamSlotsCodeLength = 762;
+static const JSC::Intrinsic s_writableStreamInternalsInitializeWritableStreamSlotsCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_writableStreamInternalsInitializeWritableStreamSlotsCode =
+ "(function (stream, underlyingSink)\n" \
+ "{ \"use strict\";\n" \
+ "\n" \
+ " @putByIdDirectPrivate(stream, \"state\", \"writable\");\n" \
+ " @putByIdDirectPrivate(stream, \"storedError\", @undefined);\n" \
+ " @putByIdDirectPrivate(stream, \"writer\", @undefined);\n" \
+ " @putByIdDirectPrivate(stream, \"controller\", @undefined);\n" \
+ " @putByIdDirectPrivate(stream, \"inFlightWriteRequest\", @undefined);\n" \
+ " @putByIdDirectPrivate(stream, \"closeRequest\", @undefined);\n" \
+ " @putByIdDirectPrivate(stream, \"inFlightCloseRequest\", @undefined);\n" \
+ " @putByIdDirectPrivate(stream, \"pendingAbortRequest\", @undefined);\n" \
+ " @putByIdDirectPrivate(stream, \"writeRequests\", @createFIFO());\n" \
+ " @putByIdDirectPrivate(stream, \"backpressure\", false);\n" \
+ " @putByIdDirectPrivate(stream, \"underlyingSink\", underlyingSink);\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_writableStreamInternalsWritableStreamCloseForBindingsCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_writableStreamInternalsWritableStreamCloseForBindingsCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_writableStreamInternalsWritableStreamCloseForBindingsCodeLength = 434;
+static const JSC::Intrinsic s_writableStreamInternalsWritableStreamCloseForBindingsCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_writableStreamInternalsWritableStreamCloseForBindingsCode =
+ "(function (stream)\n" \
+ "{ \"use strict\";\n" \
+ "\n" \
+ " if (@isWritableStreamLocked(stream))\n" \
+ " return @Promise.@reject(@makeTypeError(\"WritableStream.close method can only be used on non locked WritableStream\"));\n" \
+ "\n" \
+ " if (@writableStreamCloseQueuedOrInFlight(stream))\n" \
+ " return @Promise.@reject(@makeTypeError(\"WritableStream.close method can only be used on a being close WritableStream\"));\n" \
+ "\n" \
+ " return @writableStreamClose(stream);\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_writableStreamInternalsWritableStreamAbortForBindingsCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_writableStreamInternalsWritableStreamAbortForBindingsCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_writableStreamInternalsWritableStreamAbortForBindingsCodeLength = 266;
+static const JSC::Intrinsic s_writableStreamInternalsWritableStreamAbortForBindingsCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_writableStreamInternalsWritableStreamAbortForBindingsCode =
+ "(function (stream, reason)\n" \
+ "{ \"use strict\";\n" \
+ "\n" \
+ " if (@isWritableStreamLocked(stream))\n" \
+ " return @Promise.@reject(@makeTypeError(\"WritableStream.abort method can only be used on non locked WritableStream\"));\n" \
+ "\n" \
+ " return @writableStreamAbort(stream, reason);\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_writableStreamInternalsIsWritableStreamLockedCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_writableStreamInternalsIsWritableStreamLockedCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_writableStreamInternalsIsWritableStreamLockedCodeLength = 108;
+static const JSC::Intrinsic s_writableStreamInternalsIsWritableStreamLockedCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_writableStreamInternalsIsWritableStreamLockedCode =
+ "(function (stream)\n" \
+ "{ \"use strict\";\n" \
+ "\n" \
+ " return @getByIdDirectPrivate(stream, \"writer\") !== @undefined;\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_writableStreamInternalsSetUpWritableStreamDefaultWriterCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_writableStreamInternalsSetUpWritableStreamDefaultWriterCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_writableStreamInternalsSetUpWritableStreamDefaultWriterCodeLength = 1538;
+static const JSC::Intrinsic s_writableStreamInternalsSetUpWritableStreamDefaultWriterCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_writableStreamInternalsSetUpWritableStreamDefaultWriterCode =
+ "(function (writer, stream)\n" \
+ "{ \"use strict\";\n" \
+ "\n" \
+ " if (@isWritableStreamLocked(stream))\n" \
+ " @throwTypeError(\"WritableStream is locked\");\n" \
+ "\n" \
+ " @putByIdDirectPrivate(writer, \"stream\", stream);\n" \
+ " @putByIdDirectPrivate(stream, \"writer\", writer);\n" \
+ "\n" \
+ " const readyPromiseCapability = @newPromiseCapability(@Promise);\n" \
+ " const closedPromiseCapability = @newPromiseCapability(@Promise);\n" \
+ " @putByIdDirectPrivate(writer, \"readyPromise\", readyPromiseCapability);\n" \
+ " @putByIdDirectPrivate(writer, \"closedPromise\", closedPromiseCapability);\n" \
+ "\n" \
+ " const state = @getByIdDirectPrivate(stream, \"state\");\n" \
+ " if (state === \"writable\") {\n" \
+ " if (@writableStreamCloseQueuedOrInFlight(stream) || !@getByIdDirectPrivate(stream, \"backpressure\"))\n" \
+ " readyPromiseCapability.@resolve.@call();\n" \
+ " } else if (state === \"erroring\") {\n" \
+ " readyPromiseCapability.@reject.@call(@undefined, @getByIdDirectPrivate(stream, \"storedError\"));\n" \
+ " @markPromiseAsHandled(readyPromiseCapability.@promise);\n" \
+ " } else if (state === \"closed\") {\n" \
+ " readyPromiseCapability.@resolve.@call();\n" \
+ " closedPromiseCapability.@resolve.@call();\n" \
+ " } else {\n" \
+ " @assert(state === \"errored\");\n" \
+ " const storedError = @getByIdDirectPrivate(stream, \"storedError\");\n" \
+ " readyPromiseCapability.@reject.@call(@undefined, storedError);\n" \
+ " @markPromiseAsHandled(readyPromiseCapability.@promise);\n" \
+ " closedPromiseCapability.@reject.@call(@undefined, storedError);\n" \
+ " @markPromiseAsHandled(closedPromiseCapability.@promise);\n" \
+ " }\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_writableStreamInternalsWritableStreamAbortCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_writableStreamInternalsWritableStreamAbortCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_writableStreamInternalsWritableStreamAbortCodeLength = 928;
+static const JSC::Intrinsic s_writableStreamInternalsWritableStreamAbortCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_writableStreamInternalsWritableStreamAbortCode =
+ "(function (stream, reason)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ " const state = @getByIdDirectPrivate(stream, \"state\");\n" \
+ " if (state === \"closed\" || state === \"errored\")\n" \
+ " return @Promise.@resolve();\n" \
+ "\n" \
+ " const pendingAbortRequest = @getByIdDirectPrivate(stream, \"pendingAbortRequest\");\n" \
+ " if (pendingAbortRequest !== @undefined)\n" \
+ " return pendingAbortRequest.promise.@promise;\n" \
+ "\n" \
+ " @assert(state === \"writable\" || state === \"erroring\");\n" \
+ " let wasAlreadyErroring = false;\n" \
+ " if (state === \"erroring\") {\n" \
+ " wasAlreadyErroring = true;\n" \
+ " reason = @undefined;\n" \
+ " }\n" \
+ "\n" \
+ " const abortPromiseCapability = @newPromiseCapability(@Promise);\n" \
+ " @putByIdDirectPrivate(stream, \"pendingAbortRequest\", { promise : abortPromiseCapability, reason : reason, wasAlreadyErroring : wasAlreadyErroring });\n" \
+ "\n" \
+ " if (!wasAlreadyErroring)\n" \
+ " @writableStreamStartErroring(stream, reason);\n" \
+ " return abortPromiseCapability.@promise;\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_writableStreamInternalsWritableStreamCloseCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_writableStreamInternalsWritableStreamCloseCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_writableStreamInternalsWritableStreamCloseCodeLength = 904;
+static const JSC::Intrinsic s_writableStreamInternalsWritableStreamCloseCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_writableStreamInternalsWritableStreamCloseCode =
+ "(function (stream)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " const state = @getByIdDirectPrivate(stream, \"state\");\n" \
+ " if (state === \"closed\" || state === \"errored\")\n" \
+ " return @Promise.@reject(@makeTypeError(\"Cannot close a writable stream that is closed or errored\"));\n" \
+ "\n" \
+ " @assert(state === \"writable\" || state === \"erroring\");\n" \
+ " @assert(!@writableStreamCloseQueuedOrInFlight(stream));\n" \
+ "\n" \
+ " const closePromiseCapability = @newPromiseCapability(@Promise);\n" \
+ " @putByIdDirectPrivate(stream, \"closeRequest\", closePromiseCapability);\n" \
+ "\n" \
+ " const writer = @getByIdDirectPrivate(stream, \"writer\");\n" \
+ " if (writer !== @undefined && @getByIdDirectPrivate(stream, \"backpressure\") && state === \"writable\")\n" \
+ " @getByIdDirectPrivate(writer, \"readyPromise\").@resolve.@call();\n" \
+ " \n" \
+ " @writableStreamDefaultControllerClose(@getByIdDirectPrivate(stream, \"controller\"));\n" \
+ "\n" \
+ " return closePromiseCapability.@promise;\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_writableStreamInternalsWritableStreamAddWriteRequestCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_writableStreamInternalsWritableStreamAddWriteRequestCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_writableStreamInternalsWritableStreamAddWriteRequestCodeLength = 391;
+static const JSC::Intrinsic s_writableStreamInternalsWritableStreamAddWriteRequestCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_writableStreamInternalsWritableStreamAddWriteRequestCode =
+ "(function (stream)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " @assert(@isWritableStreamLocked(stream))\n" \
+ " @assert(@getByIdDirectPrivate(stream, \"state\") === \"writable\");\n" \
+ "\n" \
+ " const writePromiseCapability = @newPromiseCapability(@Promise);\n" \
+ " const writeRequests = @getByIdDirectPrivate(stream, \"writeRequests\");\n" \
+ " writeRequests.push(writePromiseCapability);\n" \
+ " return writePromiseCapability.@promise;\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_writableStreamInternalsWritableStreamCloseQueuedOrInFlightCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_writableStreamInternalsWritableStreamCloseQueuedOrInFlightCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_writableStreamInternalsWritableStreamCloseQueuedOrInFlightCodeLength = 188;
+static const JSC::Intrinsic s_writableStreamInternalsWritableStreamCloseQueuedOrInFlightCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_writableStreamInternalsWritableStreamCloseQueuedOrInFlightCode =
+ "(function (stream)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " return @getByIdDirectPrivate(stream, \"closeRequest\") !== @undefined || @getByIdDirectPrivate(stream, \"inFlightCloseRequest\") !== @undefined;\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_writableStreamInternalsWritableStreamDealWithRejectionCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_writableStreamInternalsWritableStreamDealWithRejectionCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_writableStreamInternalsWritableStreamDealWithRejectionCodeLength = 294;
+static const JSC::Intrinsic s_writableStreamInternalsWritableStreamDealWithRejectionCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_writableStreamInternalsWritableStreamDealWithRejectionCode =
+ "(function (stream, error)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " const state = @getByIdDirectPrivate(stream, \"state\");\n" \
+ " if (state === \"writable\") {\n" \
+ " @writableStreamStartErroring(stream, error);\n" \
+ " return;\n" \
+ " }\n" \
+ "\n" \
+ " @assert(state === \"erroring\");\n" \
+ " @writableStreamFinishErroring(stream);\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_writableStreamInternalsWritableStreamFinishErroringCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_writableStreamInternalsWritableStreamFinishErroringCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_writableStreamInternalsWritableStreamFinishErroringCodeLength = 1575;
+static const JSC::Intrinsic s_writableStreamInternalsWritableStreamFinishErroringCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_writableStreamInternalsWritableStreamFinishErroringCode =
+ "(function (stream)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " @assert(@getByIdDirectPrivate(stream, \"state\") === \"erroring\");\n" \
+ " @assert(!@writableStreamHasOperationMarkedInFlight(stream));\n" \
+ "\n" \
+ " @putByIdDirectPrivate(stream, \"state\", \"errored\");\n" \
+ "\n" \
+ " const controller = @getByIdDirectPrivate(stream, \"controller\");\n" \
+ " @getByIdDirectPrivate(controller, \"errorSteps\").@call();\n" \
+ "\n" \
+ " const storedError = @getByIdDirectPrivate(stream, \"storedError\");\n" \
+ " const requests = @getByIdDirectPrivate(stream, \"writeRequests\");\n" \
+ " for (var request = requests.shift(); request; request = requests.shift())\n" \
+ " request.@reject.@call(@undefined, storedError);\n" \
+ "\n" \
+ " //\n" \
+ " @putByIdDirectPrivate(stream, \"writeRequests\", @createFIFO());\n" \
+ "\n" \
+ " const abortRequest = @getByIdDirectPrivate(stream, \"pendingAbortRequest\");\n" \
+ " if (abortRequest === @undefined) {\n" \
+ " @writableStreamRejectCloseAndClosedPromiseIfNeeded(stream);\n" \
+ " return;\n" \
+ " }\n" \
+ "\n" \
+ " @putByIdDirectPrivate(stream, \"pendingAbortRequest\", @undefined);\n" \
+ " if (abortRequest.wasAlreadyErroring) {\n" \
+ " abortRequest.promise.@reject.@call(@undefined, storedError);\n" \
+ " @writableStreamRejectCloseAndClosedPromiseIfNeeded(stream);\n" \
+ " return;\n" \
+ " }\n" \
+ "\n" \
+ " @getByIdDirectPrivate(controller, \"abortSteps\").@call(@undefined, abortRequest.reason).@then(() => {\n" \
+ " abortRequest.promise.@resolve.@call();\n" \
+ " @writableStreamRejectCloseAndClosedPromiseIfNeeded(stream);\n" \
+ " }, (reason) => {\n" \
+ " abortRequest.promise.@reject.@call(@undefined, reason);\n" \
+ " @writableStreamRejectCloseAndClosedPromiseIfNeeded(stream);\n" \
+ " });\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_writableStreamInternalsWritableStreamFinishInFlightCloseCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_writableStreamInternalsWritableStreamFinishInFlightCloseCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_writableStreamInternalsWritableStreamFinishInFlightCloseCodeLength = 1111;
+static const JSC::Intrinsic s_writableStreamInternalsWritableStreamFinishInFlightCloseCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_writableStreamInternalsWritableStreamFinishInFlightCloseCode =
+ "(function (stream)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " const inFlightCloseRequest = @getByIdDirectPrivate(stream, \"inFlightCloseRequest\");\n" \
+ " inFlightCloseRequest.@resolve.@call();\n" \
+ "\n" \
+ " @putByIdDirectPrivate(stream, \"inFlightCloseRequest\", @undefined);\n" \
+ "\n" \
+ " const state = @getByIdDirectPrivate(stream, \"state\");\n" \
+ " @assert(state === \"writable\" || state === \"erroring\");\n" \
+ "\n" \
+ " if (state === \"erroring\") {\n" \
+ " @putByIdDirectPrivate(stream, \"storedError\", @undefined);\n" \
+ " const abortRequest = @getByIdDirectPrivate(stream, \"pendingAbortRequest\");\n" \
+ " if (abortRequest !== @undefined) {\n" \
+ " abortRequest.promise.@resolve.@call();\n" \
+ " @putByIdDirectPrivate(stream, \"pendingAbortRequest\", @undefined);\n" \
+ " }\n" \
+ " }\n" \
+ "\n" \
+ " @putByIdDirectPrivate(stream, \"state\", \"closed\");\n" \
+ "\n" \
+ " const writer = @getByIdDirectPrivate(stream, \"writer\");\n" \
+ " if (writer !== @undefined)\n" \
+ " @getByIdDirectPrivate(writer, \"closedPromise\").@resolve.@call();\n" \
+ "\n" \
+ " @assert(@getByIdDirectPrivate(stream, \"pendingAbortRequest\") === @undefined);\n" \
+ " @assert(@getByIdDirectPrivate(stream, \"storedError\") === @undefined);\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_writableStreamInternalsWritableStreamFinishInFlightCloseWithErrorCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_writableStreamInternalsWritableStreamFinishInFlightCloseWithErrorCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_writableStreamInternalsWritableStreamFinishInFlightCloseWithErrorCodeLength = 753;
+static const JSC::Intrinsic s_writableStreamInternalsWritableStreamFinishInFlightCloseWithErrorCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_writableStreamInternalsWritableStreamFinishInFlightCloseWithErrorCode =
+ "(function (stream, error)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " const inFlightCloseRequest = @getByIdDirectPrivate(stream, \"inFlightCloseRequest\");\n" \
+ " @assert(inFlightCloseRequest !== @undefined);\n" \
+ " inFlightCloseRequest.@reject.@call(@undefined, error);\n" \
+ "\n" \
+ " @putByIdDirectPrivate(stream, \"inFlightCloseRequest\", @undefined);\n" \
+ "\n" \
+ " const state = @getByIdDirectPrivate(stream, \"state\");\n" \
+ " @assert(state === \"writable\" || state === \"erroring\");\n" \
+ "\n" \
+ " const abortRequest = @getByIdDirectPrivate(stream, \"pendingAbortRequest\");\n" \
+ " if (abortRequest !== @undefined) {\n" \
+ " abortRequest.promise.@reject.@call(@undefined, error);\n" \
+ " @putByIdDirectPrivate(stream, \"pendingAbortRequest\", @undefined);\n" \
+ " }\n" \
+ "\n" \
+ " @writableStreamDealWithRejection(stream, error);\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_writableStreamInternalsWritableStreamFinishInFlightWriteCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_writableStreamInternalsWritableStreamFinishInFlightWriteCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_writableStreamInternalsWritableStreamFinishInFlightWriteCodeLength = 296;
+static const JSC::Intrinsic s_writableStreamInternalsWritableStreamFinishInFlightWriteCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_writableStreamInternalsWritableStreamFinishInFlightWriteCode =
+ "(function (stream)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " const inFlightWriteRequest = @getByIdDirectPrivate(stream, \"inFlightWriteRequest\");\n" \
+ " @assert(inFlightWriteRequest !== @undefined);\n" \
+ " inFlightWriteRequest.@resolve.@call();\n" \
+ "\n" \
+ " @putByIdDirectPrivate(stream, \"inFlightWriteRequest\", @undefined);\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_writableStreamInternalsWritableStreamFinishInFlightWriteWithErrorCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_writableStreamInternalsWritableStreamFinishInFlightWriteWithErrorCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_writableStreamInternalsWritableStreamFinishInFlightWriteWithErrorCodeLength = 491;
+static const JSC::Intrinsic s_writableStreamInternalsWritableStreamFinishInFlightWriteWithErrorCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_writableStreamInternalsWritableStreamFinishInFlightWriteWithErrorCode =
+ "(function (stream, error)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " const inFlightWriteRequest = @getByIdDirectPrivate(stream, \"inFlightWriteRequest\");\n" \
+ " @assert(inFlightWriteRequest !== @undefined);\n" \
+ " inFlightWriteRequest.@reject.@call(@undefined, error);\n" \
+ "\n" \
+ " @putByIdDirectPrivate(stream, \"inFlightWriteRequest\", @undefined);\n" \
+ "\n" \
+ " const state = @getByIdDirectPrivate(stream, \"state\");\n" \
+ " @assert(state === \"writable\" || state === \"erroring\");\n" \
+ "\n" \
+ " @writableStreamDealWithRejection(stream, error);\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_writableStreamInternalsWritableStreamHasOperationMarkedInFlightCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_writableStreamInternalsWritableStreamHasOperationMarkedInFlightCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_writableStreamInternalsWritableStreamHasOperationMarkedInFlightCodeLength = 196;
+static const JSC::Intrinsic s_writableStreamInternalsWritableStreamHasOperationMarkedInFlightCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_writableStreamInternalsWritableStreamHasOperationMarkedInFlightCode =
+ "(function (stream)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " return @getByIdDirectPrivate(stream, \"inFlightWriteRequest\") !== @undefined || @getByIdDirectPrivate(stream, \"inFlightCloseRequest\") !== @undefined;\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_writableStreamInternalsWritableStreamMarkCloseRequestInFlightCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_writableStreamInternalsWritableStreamMarkCloseRequestInFlightCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_writableStreamInternalsWritableStreamMarkCloseRequestInFlightCodeLength = 377;
+static const JSC::Intrinsic s_writableStreamInternalsWritableStreamMarkCloseRequestInFlightCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_writableStreamInternalsWritableStreamMarkCloseRequestInFlightCode =
+ "(function (stream)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " const closeRequest = @getByIdDirectPrivate(stream, \"closeRequest\");\n" \
+ " @assert(@getByIdDirectPrivate(stream, \"inFlightCloseRequest\") === @undefined);\n" \
+ " @assert(closeRequest !== @undefined);\n" \
+ "\n" \
+ " @putByIdDirectPrivate(stream, \"inFlightCloseRequest\", closeRequest);\n" \
+ " @putByIdDirectPrivate(stream, \"closeRequest\", @undefined);\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_writableStreamInternalsWritableStreamMarkFirstWriteRequestInFlightCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_writableStreamInternalsWritableStreamMarkFirstWriteRequestInFlightCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_writableStreamInternalsWritableStreamMarkFirstWriteRequestInFlightCodeLength = 363;
+static const JSC::Intrinsic s_writableStreamInternalsWritableStreamMarkFirstWriteRequestInFlightCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_writableStreamInternalsWritableStreamMarkFirstWriteRequestInFlightCode =
+ "(function (stream)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " const writeRequests = @getByIdDirectPrivate(stream, \"writeRequests\");\n" \
+ " @assert(@getByIdDirectPrivate(stream, \"inFlightWriteRequest\") === @undefined);\n" \
+ " @assert(writeRequests.isNotEmpty());\n" \
+ "\n" \
+ " const writeRequest = writeRequests.shift();\n" \
+ " @putByIdDirectPrivate(stream, \"inFlightWriteRequest\", writeRequest);\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_writableStreamInternalsWritableStreamRejectCloseAndClosedPromiseIfNeededCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_writableStreamInternalsWritableStreamRejectCloseAndClosedPromiseIfNeededCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_writableStreamInternalsWritableStreamRejectCloseAndClosedPromiseIfNeededCodeLength = 809;
+static const JSC::Intrinsic s_writableStreamInternalsWritableStreamRejectCloseAndClosedPromiseIfNeededCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_writableStreamInternalsWritableStreamRejectCloseAndClosedPromiseIfNeededCode =
+ "(function (stream)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " @assert(@getByIdDirectPrivate(stream, \"state\") === \"errored\");\n" \
+ "\n" \
+ " const storedError = @getByIdDirectPrivate(stream, \"storedError\");\n" \
+ "\n" \
+ " const closeRequest = @getByIdDirectPrivate(stream, \"closeRequest\");\n" \
+ " if (closeRequest !== @undefined) {\n" \
+ " @assert(@getByIdDirectPrivate(stream, \"inFlightCloseRequest\") === @undefined);\n" \
+ " closeRequest.@reject.@call(@undefined, storedError);\n" \
+ " @putByIdDirectPrivate(stream, \"closeRequest\", @undefined);\n" \
+ " }\n" \
+ "\n" \
+ " const writer = @getByIdDirectPrivate(stream, \"writer\");\n" \
+ " if (writer !== @undefined) {\n" \
+ " const closedPromise = @getByIdDirectPrivate(writer, \"closedPromise\");\n" \
+ " closedPromise.@reject.@call(@undefined, storedError);\n" \
+ " @markPromiseAsHandled(closedPromise.@promise);\n" \
+ " }\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_writableStreamInternalsWritableStreamStartErroringCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_writableStreamInternalsWritableStreamStartErroringCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_writableStreamInternalsWritableStreamStartErroringCodeLength = 752;
+static const JSC::Intrinsic s_writableStreamInternalsWritableStreamStartErroringCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_writableStreamInternalsWritableStreamStartErroringCode =
+ "(function (stream, reason)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " @assert(@getByIdDirectPrivate(stream, \"storedError\") === @undefined);\n" \
+ " @assert(@getByIdDirectPrivate(stream, \"state\") === \"writable\");\n" \
+ " \n" \
+ " const controller = @getByIdDirectPrivate(stream, \"controller\");\n" \
+ " @assert(controller !== @undefined);\n" \
+ "\n" \
+ " @putByIdDirectPrivate(stream, \"state\", \"erroring\");\n" \
+ " @putByIdDirectPrivate(stream, \"storedError\", reason);\n" \
+ "\n" \
+ " const writer = @getByIdDirectPrivate(stream, \"writer\");\n" \
+ " if (writer !== @undefined)\n" \
+ " @writableStreamDefaultWriterEnsureReadyPromiseRejected(writer, reason);\n" \
+ "\n" \
+ " if (!@writableStreamHasOperationMarkedInFlight(stream) && @getByIdDirectPrivate(controller, \"started\") === 1)\n" \
+ " @writableStreamFinishErroring(stream);\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_writableStreamInternalsWritableStreamUpdateBackpressureCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_writableStreamInternalsWritableStreamUpdateBackpressureCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_writableStreamInternalsWritableStreamUpdateBackpressureCodeLength = 621;
+static const JSC::Intrinsic s_writableStreamInternalsWritableStreamUpdateBackpressureCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_writableStreamInternalsWritableStreamUpdateBackpressureCode =
+ "(function (stream, backpressure)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ " @assert(@getByIdDirectPrivate(stream, \"state\") === \"writable\");\n" \
+ " @assert(!@writableStreamCloseQueuedOrInFlight(stream));\n" \
+ "\n" \
+ " const writer = @getByIdDirectPrivate(stream, \"writer\");\n" \
+ " if (writer !== @undefined && backpressure !== @getByIdDirectPrivate(stream, \"backpressure\")) {\n" \
+ " if (backpressure)\n" \
+ " @putByIdDirectPrivate(writer, \"readyPromise\", @newPromiseCapability(@Promise));\n" \
+ " else\n" \
+ " @getByIdDirectPrivate(writer, \"readyPromise\").@resolve.@call();\n" \
+ " }\n" \
+ " @putByIdDirectPrivate(stream, \"backpressure\", backpressure);\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_writableStreamInternalsWritableStreamDefaultWriterAbortCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_writableStreamInternalsWritableStreamDefaultWriterAbortCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_writableStreamInternalsWritableStreamDefaultWriterAbortCodeLength = 195;
+static const JSC::Intrinsic s_writableStreamInternalsWritableStreamDefaultWriterAbortCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_writableStreamInternalsWritableStreamDefaultWriterAbortCode =
+ "(function (writer, reason)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ " const stream = @getByIdDirectPrivate(writer, \"stream\");\n" \
+ " @assert(stream !== @undefined);\n" \
+ " return @writableStreamAbort(stream, reason);\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_writableStreamInternalsWritableStreamDefaultWriterCloseCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_writableStreamInternalsWritableStreamDefaultWriterCloseCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_writableStreamInternalsWritableStreamDefaultWriterCloseCodeLength = 179;
+static const JSC::Intrinsic s_writableStreamInternalsWritableStreamDefaultWriterCloseCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_writableStreamInternalsWritableStreamDefaultWriterCloseCode =
+ "(function (writer)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ " const stream = @getByIdDirectPrivate(writer, \"stream\");\n" \
+ " @assert(stream !== @undefined);\n" \
+ " return @writableStreamClose(stream);\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_writableStreamInternalsWritableStreamDefaultWriterCloseWithErrorPropagationCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_writableStreamInternalsWritableStreamDefaultWriterCloseWithErrorPropagationCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_writableStreamInternalsWritableStreamDefaultWriterCloseWithErrorPropagationCodeLength = 533;
+static const JSC::Intrinsic s_writableStreamInternalsWritableStreamDefaultWriterCloseWithErrorPropagationCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_writableStreamInternalsWritableStreamDefaultWriterCloseWithErrorPropagationCode =
+ "(function (writer)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ " const stream = @getByIdDirectPrivate(writer, \"stream\");\n" \
+ " @assert(stream !== @undefined);\n" \
+ "\n" \
+ " const state = @getByIdDirectPrivate(stream, \"state\");\n" \
+ "\n" \
+ " if (@writableStreamCloseQueuedOrInFlight(stream) || state === \"closed\")\n" \
+ " return @Promise.@resolve();\n" \
+ "\n" \
+ " if (state === \"errored\")\n" \
+ " return @Promise.@reject(@getByIdDirectPrivate(stream, \"storedError\"));\n" \
+ "\n" \
+ " @assert(state === \"writable\" || state === \"erroring\");\n" \
+ " return @writableStreamDefaultWriterClose(writer);\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_writableStreamInternalsWritableStreamDefaultWriterEnsureClosedPromiseRejectedCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_writableStreamInternalsWritableStreamDefaultWriterEnsureClosedPromiseRejectedCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_writableStreamInternalsWritableStreamDefaultWriterEnsureClosedPromiseRejectedCodeLength = 625;
+static const JSC::Intrinsic s_writableStreamInternalsWritableStreamDefaultWriterEnsureClosedPromiseRejectedCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_writableStreamInternalsWritableStreamDefaultWriterEnsureClosedPromiseRejectedCode =
+ "(function (writer, error)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ " let closedPromiseCapability = @getByIdDirectPrivate(writer, \"closedPromise\");\n" \
+ " let closedPromise = closedPromiseCapability.@promise;\n" \
+ "\n" \
+ " if ((@getPromiseInternalField(closedPromise, @promiseFieldFlags) & @promiseStateMask) !== @promiseStatePending) {\n" \
+ " closedPromiseCapability = @newPromiseCapability(@Promise);\n" \
+ " closedPromise = closedPromiseCapability.@promise;\n" \
+ " @putByIdDirectPrivate(writer, \"closedPromise\", closedPromiseCapability);\n" \
+ " }\n" \
+ "\n" \
+ " closedPromiseCapability.@reject.@call(@undefined, error);\n" \
+ " @markPromiseAsHandled(closedPromise);\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_writableStreamInternalsWritableStreamDefaultWriterEnsureReadyPromiseRejectedCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_writableStreamInternalsWritableStreamDefaultWriterEnsureReadyPromiseRejectedCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_writableStreamInternalsWritableStreamDefaultWriterEnsureReadyPromiseRejectedCodeLength = 613;
+static const JSC::Intrinsic s_writableStreamInternalsWritableStreamDefaultWriterEnsureReadyPromiseRejectedCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_writableStreamInternalsWritableStreamDefaultWriterEnsureReadyPromiseRejectedCode =
+ "(function (writer, error)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ " let readyPromiseCapability = @getByIdDirectPrivate(writer, \"readyPromise\");\n" \
+ " let readyPromise = readyPromiseCapability.@promise;\n" \
+ "\n" \
+ " if ((@getPromiseInternalField(readyPromise, @promiseFieldFlags) & @promiseStateMask) !== @promiseStatePending) {\n" \
+ " readyPromiseCapability = @newPromiseCapability(@Promise);\n" \
+ " readyPromise = readyPromiseCapability.@promise;\n" \
+ " @putByIdDirectPrivate(writer, \"readyPromise\", readyPromiseCapability);\n" \
+ " }\n" \
+ "\n" \
+ " readyPromiseCapability.@reject.@call(@undefined, error);\n" \
+ " @markPromiseAsHandled(readyPromise);\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_writableStreamInternalsWritableStreamDefaultWriterGetDesiredSizeCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_writableStreamInternalsWritableStreamDefaultWriterGetDesiredSizeCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_writableStreamInternalsWritableStreamDefaultWriterGetDesiredSizeCodeLength = 424;
+static const JSC::Intrinsic s_writableStreamInternalsWritableStreamDefaultWriterGetDesiredSizeCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_writableStreamInternalsWritableStreamDefaultWriterGetDesiredSizeCode =
+ "(function (writer)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ " const stream = @getByIdDirectPrivate(writer, \"stream\");\n" \
+ " @assert(stream !== @undefined);\n" \
+ "\n" \
+ " const state = @getByIdDirectPrivate(stream, \"state\");\n" \
+ "\n" \
+ " if (state === \"errored\" || state === \"erroring\")\n" \
+ " return null;\n" \
+ "\n" \
+ " if (state === \"closed\")\n" \
+ " return 0;\n" \
+ "\n" \
+ " return @writableStreamDefaultControllerGetDesiredSize(@getByIdDirectPrivate(stream, \"controller\"));\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_writableStreamInternalsWritableStreamDefaultWriterReleaseCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_writableStreamInternalsWritableStreamDefaultWriterReleaseCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_writableStreamInternalsWritableStreamDefaultWriterReleaseCodeLength = 568;
+static const JSC::Intrinsic s_writableStreamInternalsWritableStreamDefaultWriterReleaseCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_writableStreamInternalsWritableStreamDefaultWriterReleaseCode =
+ "(function (writer)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " const stream = @getByIdDirectPrivate(writer, \"stream\");\n" \
+ " @assert(stream !== @undefined);\n" \
+ " @assert(@getByIdDirectPrivate(stream, \"writer\") === writer);\n" \
+ "\n" \
+ " const releasedError = @makeTypeError(\"writableStreamDefaultWriterRelease\");\n" \
+ "\n" \
+ " @writableStreamDefaultWriterEnsureReadyPromiseRejected(writer, releasedError);\n" \
+ " @writableStreamDefaultWriterEnsureClosedPromiseRejected(writer, releasedError);\n" \
+ "\n" \
+ " @putByIdDirectPrivate(stream, \"writer\", @undefined);\n" \
+ " @putByIdDirectPrivate(writer, \"stream\", @undefined);\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_writableStreamInternalsWritableStreamDefaultWriterWriteCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_writableStreamInternalsWritableStreamDefaultWriterWriteCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_writableStreamInternalsWritableStreamDefaultWriterWriteCodeLength = 1266;
+static const JSC::Intrinsic s_writableStreamInternalsWritableStreamDefaultWriterWriteCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_writableStreamInternalsWritableStreamDefaultWriterWriteCode =
+ "(function (writer, chunk)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " const stream = @getByIdDirectPrivate(writer, \"stream\");\n" \
+ " @assert(stream !== @undefined);\n" \
+ "\n" \
+ " const controller = @getByIdDirectPrivate(stream, \"controller\");\n" \
+ " @assert(controller !== @undefined);\n" \
+ " const chunkSize = @writableStreamDefaultControllerGetChunkSize(controller, chunk);\n" \
+ "\n" \
+ " if (stream !== @getByIdDirectPrivate(writer, \"stream\"))\n" \
+ " return @Promise.@reject(@makeTypeError(\"writer is not stream's writer\"));\n" \
+ "\n" \
+ " const state = @getByIdDirectPrivate(stream, \"state\");\n" \
+ " if (state === \"errored\")\n" \
+ " return @Promise.@reject(@getByIdDirectPrivate(stream, \"storedError\"));\n" \
+ "\n" \
+ " if (@writableStreamCloseQueuedOrInFlight(stream) || state === \"closed\")\n" \
+ " return @Promise.@reject(@makeTypeError(\"stream is closing or closed\"));\n" \
+ "\n" \
+ " if (@writableStreamCloseQueuedOrInFlight(stream) || state === \"closed\")\n" \
+ " return @Promise.@reject(@makeTypeError(\"stream is closing or closed\"));\n" \
+ "\n" \
+ " if (state === \"erroring\")\n" \
+ " return @Promise.@reject(@getByIdDirectPrivate(stream, \"storedError\"));\n" \
+ "\n" \
+ " @assert(state === \"writable\");\n" \
+ "\n" \
+ " const promise = @writableStreamAddWriteRequest(stream);\n" \
+ " @writableStreamDefaultControllerWrite(controller, chunk, chunkSize);\n" \
+ " return promise;\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_writableStreamInternalsSetUpWritableStreamDefaultControllerCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_writableStreamInternalsSetUpWritableStreamDefaultControllerCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_writableStreamInternalsSetUpWritableStreamDefaultControllerCodeLength = 1142;
+static const JSC::Intrinsic s_writableStreamInternalsSetUpWritableStreamDefaultControllerCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_writableStreamInternalsSetUpWritableStreamDefaultControllerCode =
+ "(function (stream, controller, startAlgorithm, writeAlgorithm, closeAlgorithm, abortAlgorithm, highWaterMark, sizeAlgorithm)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " @assert(@isWritableStream(stream));\n" \
+ " @assert(@getByIdDirectPrivate(stream, \"controller\") === @undefined);\n" \
+ "\n" \
+ " @putByIdDirectPrivate(controller, \"stream\", stream);\n" \
+ " @putByIdDirectPrivate(stream, \"controller\", controller);\n" \
+ "\n" \
+ " @resetQueue(@getByIdDirectPrivate(controller, \"queue\"));\n" \
+ "\n" \
+ " @putByIdDirectPrivate(controller, \"started\", -1);\n" \
+ " @putByIdDirectPrivate(controller, \"startAlgorithm\", startAlgorithm);\n" \
+ " @putByIdDirectPrivate(controller, \"strategySizeAlgorithm\", sizeAlgorithm);\n" \
+ " @putByIdDirectPrivate(controller, \"strategyHWM\", highWaterMark);\n" \
+ " @putByIdDirectPrivate(controller, \"writeAlgorithm\", writeAlgorithm);\n" \
+ " @putByIdDirectPrivate(controller, \"closeAlgorithm\", closeAlgorithm);\n" \
+ " @putByIdDirectPrivate(controller, \"abortAlgorithm\", abortAlgorithm);\n" \
+ "\n" \
+ " const backpressure = @writableStreamDefaultControllerGetBackpressure(controller);\n" \
+ " @writableStreamUpdateBackpressure(stream, backpressure);\n" \
+ "\n" \
+ " @writableStreamDefaultControllerStart(controller);\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_writableStreamInternalsWritableStreamDefaultControllerStartCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_writableStreamInternalsWritableStreamDefaultControllerStartCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_writableStreamInternalsWritableStreamDefaultControllerStartCodeLength = 982;
+static const JSC::Intrinsic s_writableStreamInternalsWritableStreamDefaultControllerStartCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_writableStreamInternalsWritableStreamDefaultControllerStartCode =
+ "(function (controller) {\n" \
+ " \"use strict\";\n" \
+ "\n" \
+ " if (@getByIdDirectPrivate(controller, \"started\") !== -1)\n" \
+ " return;\n" \
+ "\n" \
+ " @putByIdDirectPrivate(controller, \"started\", 0);\n" \
+ "\n" \
+ " const startAlgorithm = @getByIdDirectPrivate(controller, \"startAlgorithm\");\n" \
+ " @putByIdDirectPrivate(controller, \"startAlgorithm\", @undefined);\n" \
+ " const stream = @getByIdDirectPrivate(controller, \"stream\");\n" \
+ " return @Promise.@resolve(startAlgorithm.@call()).@then(() => {\n" \
+ " const state = @getByIdDirectPrivate(stream, \"state\");\n" \
+ " @assert(state === \"writable\" || state === \"erroring\");\n" \
+ " @putByIdDirectPrivate(controller, \"started\", 1);\n" \
+ " @writableStreamDefaultControllerAdvanceQueueIfNeeded(controller);\n" \
+ " }, (error) => {\n" \
+ " const state = @getByIdDirectPrivate(stream, \"state\");\n" \
+ " @assert(state === \"writable\" || state === \"erroring\");\n" \
+ " @putByIdDirectPrivate(controller, \"started\", 1);\n" \
+ " @writableStreamDealWithRejection(stream, error);\n" \
+ " });\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_writableStreamInternalsSetUpWritableStreamDefaultControllerFromUnderlyingSinkCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_writableStreamInternalsSetUpWritableStreamDefaultControllerFromUnderlyingSinkCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_writableStreamInternalsSetUpWritableStreamDefaultControllerFromUnderlyingSinkCodeLength = 1394;
+static const JSC::Intrinsic s_writableStreamInternalsSetUpWritableStreamDefaultControllerFromUnderlyingSinkCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_writableStreamInternalsSetUpWritableStreamDefaultControllerFromUnderlyingSinkCode =
+ "(function (stream, underlyingSink, underlyingSinkDict, highWaterMark, sizeAlgorithm)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ " const controller = new @WritableStreamDefaultController();\n" \
+ "\n" \
+ " let startAlgorithm = () => { };\n" \
+ " let writeAlgorithm = () => { return @Promise.@resolve(); };\n" \
+ " let closeAlgorithm = () => { return @Promise.@resolve(); };\n" \
+ " let abortAlgorithm = () => { return @Promise.@resolve(); };\n" \
+ "\n" \
+ " if (\"start\" in underlyingSinkDict) {\n" \
+ " const startMethod = underlyingSinkDict[\"start\"];\n" \
+ " startAlgorithm = () => @promiseInvokeOrNoopMethodNoCatch(underlyingSink, startMethod, [controller]);\n" \
+ " }\n" \
+ " if (\"write\" in underlyingSinkDict) {\n" \
+ " const writeMethod = underlyingSinkDict[\"write\"];\n" \
+ " writeAlgorithm = (chunk) => @promiseInvokeOrNoopMethod(underlyingSink, writeMethod, [chunk, controller]);\n" \
+ " }\n" \
+ " if (\"close\" in underlyingSinkDict) {\n" \
+ " const closeMethod = underlyingSinkDict[\"close\"];\n" \
+ " closeAlgorithm = () => @promiseInvokeOrNoopMethod(underlyingSink, closeMethod, []);\n" \
+ " }\n" \
+ " if (\"abort\" in underlyingSinkDict) {\n" \
+ " const abortMethod = underlyingSinkDict[\"abort\"];\n" \
+ " abortAlgorithm = (reason) => @promiseInvokeOrNoopMethod(underlyingSink, abortMethod, [reason]);\n" \
+ " }\n" \
+ "\n" \
+ " @setUpWritableStreamDefaultController(stream, controller, startAlgorithm, writeAlgorithm, closeAlgorithm, abortAlgorithm, highWaterMark, sizeAlgorithm);\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_writableStreamInternalsWritableStreamDefaultControllerAdvanceQueueIfNeededCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_writableStreamInternalsWritableStreamDefaultControllerAdvanceQueueIfNeededCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_writableStreamInternalsWritableStreamDefaultControllerAdvanceQueueIfNeededCodeLength = 895;
+static const JSC::Intrinsic s_writableStreamInternalsWritableStreamDefaultControllerAdvanceQueueIfNeededCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_writableStreamInternalsWritableStreamDefaultControllerAdvanceQueueIfNeededCode =
+ "(function (controller)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ " const stream = @getByIdDirectPrivate(controller, \"stream\");\n" \
+ "\n" \
+ " if (@getByIdDirectPrivate(controller, \"started\") !== 1)\n" \
+ " return;\n" \
+ "\n" \
+ " @assert(stream !== @undefined);\n" \
+ " if (@getByIdDirectPrivate(stream, \"inFlightWriteRequest\") !== @undefined)\n" \
+ " return;\n" \
+ "\n" \
+ " const state = @getByIdDirectPrivate(stream, \"state\");\n" \
+ " @assert(state !== \"closed\" || state !== \"errored\");\n" \
+ " if (state === \"erroring\") {\n" \
+ " @writableStreamFinishErroring(stream);\n" \
+ " return;\n" \
+ " }\n" \
+ "\n" \
+ " if (@getByIdDirectPrivate(controller, \"queue\").content?.isEmpty() ?? false)\n" \
+ " return;\n" \
+ "\n" \
+ " const value = @peekQueueValue(@getByIdDirectPrivate(controller, \"queue\"));\n" \
+ " if (value === @isCloseSentinel)\n" \
+ " @writableStreamDefaultControllerProcessClose(controller);\n" \
+ " else\n" \
+ " @writableStreamDefaultControllerProcessWrite(controller, value);\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_writableStreamInternalsIsCloseSentinelCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_writableStreamInternalsIsCloseSentinelCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_writableStreamInternalsIsCloseSentinelCodeLength = 18;
+static const JSC::Intrinsic s_writableStreamInternalsIsCloseSentinelCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_writableStreamInternalsIsCloseSentinelCode =
+ "(function ()\n" \
+ "{\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_writableStreamInternalsWritableStreamDefaultControllerClearAlgorithmsCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_writableStreamInternalsWritableStreamDefaultControllerClearAlgorithmsCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_writableStreamInternalsWritableStreamDefaultControllerClearAlgorithmsCodeLength = 329;
+static const JSC::Intrinsic s_writableStreamInternalsWritableStreamDefaultControllerClearAlgorithmsCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_writableStreamInternalsWritableStreamDefaultControllerClearAlgorithmsCode =
+ "(function (controller)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ " @putByIdDirectPrivate(controller, \"writeAlgorithm\", @undefined);\n" \
+ " @putByIdDirectPrivate(controller, \"closeAlgorithm\", @undefined);\n" \
+ " @putByIdDirectPrivate(controller, \"abortAlgorithm\", @undefined);\n" \
+ " @putByIdDirectPrivate(controller, \"strategySizeAlgorithm\", @undefined);\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_writableStreamInternalsWritableStreamDefaultControllerCloseCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_writableStreamInternalsWritableStreamDefaultControllerCloseCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_writableStreamInternalsWritableStreamDefaultControllerCloseCodeLength = 208;
+static const JSC::Intrinsic s_writableStreamInternalsWritableStreamDefaultControllerCloseCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_writableStreamInternalsWritableStreamDefaultControllerCloseCode =
+ "(function (controller)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ " @enqueueValueWithSize(@getByIdDirectPrivate(controller, \"queue\"), @isCloseSentinel, 0);\n" \
+ " @writableStreamDefaultControllerAdvanceQueueIfNeeded(controller);\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_writableStreamInternalsWritableStreamDefaultControllerErrorCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_writableStreamInternalsWritableStreamDefaultControllerErrorCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_writableStreamInternalsWritableStreamDefaultControllerErrorCodeLength = 336;
+static const JSC::Intrinsic s_writableStreamInternalsWritableStreamDefaultControllerErrorCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_writableStreamInternalsWritableStreamDefaultControllerErrorCode =
+ "(function (controller, error)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ " const stream = @getByIdDirectPrivate(controller, \"stream\");\n" \
+ " @assert(stream !== @undefined);\n" \
+ " @assert(@getByIdDirectPrivate(stream, \"state\") === \"writable\");\n" \
+ "\n" \
+ " @writableStreamDefaultControllerClearAlgorithms(controller);\n" \
+ " @writableStreamStartErroring(stream, error);\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_writableStreamInternalsWritableStreamDefaultControllerErrorIfNeededCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_writableStreamInternalsWritableStreamDefaultControllerErrorIfNeededCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_writableStreamInternalsWritableStreamDefaultControllerErrorIfNeededCodeLength = 246;
+static const JSC::Intrinsic s_writableStreamInternalsWritableStreamDefaultControllerErrorIfNeededCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_writableStreamInternalsWritableStreamDefaultControllerErrorIfNeededCode =
+ "(function (controller, error)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ " const stream = @getByIdDirectPrivate(controller, \"stream\");\n" \
+ " if (@getByIdDirectPrivate(stream, \"state\") === \"writable\")\n" \
+ " @writableStreamDefaultControllerError(controller, error);\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_writableStreamInternalsWritableStreamDefaultControllerGetBackpressureCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_writableStreamInternalsWritableStreamDefaultControllerGetBackpressureCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_writableStreamInternalsWritableStreamDefaultControllerGetBackpressureCodeLength = 159;
+static const JSC::Intrinsic s_writableStreamInternalsWritableStreamDefaultControllerGetBackpressureCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_writableStreamInternalsWritableStreamDefaultControllerGetBackpressureCode =
+ "(function (controller)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ " const desiredSize = @writableStreamDefaultControllerGetDesiredSize(controller);\n" \
+ " return desiredSize <= 0;\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_writableStreamInternalsWritableStreamDefaultControllerGetChunkSizeCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_writableStreamInternalsWritableStreamDefaultControllerGetChunkSizeCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_writableStreamInternalsWritableStreamDefaultControllerGetChunkSizeCodeLength = 275;
+static const JSC::Intrinsic s_writableStreamInternalsWritableStreamDefaultControllerGetChunkSizeCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_writableStreamInternalsWritableStreamDefaultControllerGetChunkSizeCode =
+ "(function (controller, chunk)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ " try {\n" \
+ " return @getByIdDirectPrivate(controller, \"strategySizeAlgorithm\").@call(@undefined, chunk);\n" \
+ " } catch (e) {\n" \
+ " @writableStreamDefaultControllerErrorIfNeeded(controller, e);\n" \
+ " return 1;\n" \
+ " }\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_writableStreamInternalsWritableStreamDefaultControllerGetDesiredSizeCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_writableStreamInternalsWritableStreamDefaultControllerGetDesiredSizeCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_writableStreamInternalsWritableStreamDefaultControllerGetDesiredSizeCodeLength = 157;
+static const JSC::Intrinsic s_writableStreamInternalsWritableStreamDefaultControllerGetDesiredSizeCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_writableStreamInternalsWritableStreamDefaultControllerGetDesiredSizeCode =
+ "(function (controller)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ " return @getByIdDirectPrivate(controller, \"strategyHWM\") - @getByIdDirectPrivate(controller, \"queue\").size;\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_writableStreamInternalsWritableStreamDefaultControllerProcessCloseCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_writableStreamInternalsWritableStreamDefaultControllerProcessCloseCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_writableStreamInternalsWritableStreamDefaultControllerProcessCloseCodeLength = 646;
+static const JSC::Intrinsic s_writableStreamInternalsWritableStreamDefaultControllerProcessCloseCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_writableStreamInternalsWritableStreamDefaultControllerProcessCloseCode =
+ "(function (controller)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ " const stream = @getByIdDirectPrivate(controller, \"stream\");\n" \
+ "\n" \
+ " @writableStreamMarkCloseRequestInFlight(stream);\n" \
+ " @dequeueValue(@getByIdDirectPrivate(controller, \"queue\"));\n" \
+ "\n" \
+ " @assert(@getByIdDirectPrivate(controller, \"queue\").content?.isEmpty());\n" \
+ "\n" \
+ " const sinkClosePromise = @getByIdDirectPrivate(controller, \"closeAlgorithm\").@call();\n" \
+ " @writableStreamDefaultControllerClearAlgorithms(controller);\n" \
+ "\n" \
+ " sinkClosePromise.@then(() => {\n" \
+ " @writableStreamFinishInFlightClose(stream);\n" \
+ " }, (reason) => {\n" \
+ " @writableStreamFinishInFlightCloseWithError(stream, reason);\n" \
+ " });\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_writableStreamInternalsWritableStreamDefaultControllerProcessWriteCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_writableStreamInternalsWritableStreamDefaultControllerProcessWriteCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_writableStreamInternalsWritableStreamDefaultControllerProcessWriteCodeLength = 1165;
+static const JSC::Intrinsic s_writableStreamInternalsWritableStreamDefaultControllerProcessWriteCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_writableStreamInternalsWritableStreamDefaultControllerProcessWriteCode =
+ "(function (controller, chunk)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ " const stream = @getByIdDirectPrivate(controller, \"stream\");\n" \
+ "\n" \
+ " @writableStreamMarkFirstWriteRequestInFlight(stream);\n" \
+ "\n" \
+ " const sinkWritePromise = @getByIdDirectPrivate(controller, \"writeAlgorithm\").@call(@undefined, chunk);\n" \
+ "\n" \
+ " sinkWritePromise.@then(() => {\n" \
+ " @writableStreamFinishInFlightWrite(stream);\n" \
+ " const state = @getByIdDirectPrivate(stream, \"state\");\n" \
+ " @assert(state === \"writable\" || state === \"erroring\");\n" \
+ "\n" \
+ " @dequeueValue(@getByIdDirectPrivate(controller, \"queue\"));\n" \
+ " if (!@writableStreamCloseQueuedOrInFlight(stream) && state === \"writable\") {\n" \
+ " const backpressure = @writableStreamDefaultControllerGetBackpressure(controller);\n" \
+ " @writableStreamUpdateBackpressure(stream, backpressure);\n" \
+ " }\n" \
+ " @writableStreamDefaultControllerAdvanceQueueIfNeeded(controller);\n" \
+ " }, (reason) => {\n" \
+ " const state = @getByIdDirectPrivate(stream, \"state\");\n" \
+ " if (state === \"writable\")\n" \
+ " @writableStreamDefaultControllerClearAlgorithms(controller);\n" \
+ "\n" \
+ " @writableStreamFinishInFlightWriteWithError(stream, reason);\n" \
+ " });\n" \
+ "})\n" \
+;
+
+const JSC::ConstructAbility s_writableStreamInternalsWritableStreamDefaultControllerWriteCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
+const JSC::ConstructorKind s_writableStreamInternalsWritableStreamDefaultControllerWriteCodeConstructorKind = JSC::ConstructorKind::None;
+const int s_writableStreamInternalsWritableStreamDefaultControllerWriteCodeLength = 725;
+static const JSC::Intrinsic s_writableStreamInternalsWritableStreamDefaultControllerWriteCodeIntrinsic = JSC::NoIntrinsic;
+const char* const s_writableStreamInternalsWritableStreamDefaultControllerWriteCode =
+ "(function (controller, chunk, chunkSize)\n" \
+ "{\n" \
+ " \"use strict\";\n" \
+ " try {\n" \
+ " @enqueueValueWithSize(@getByIdDirectPrivate(controller, \"queue\"), chunk, chunkSize);\n" \
+ "\n" \
+ " const stream = @getByIdDirectPrivate(controller, \"stream\");\n" \
+ "\n" \
+ " const state = @getByIdDirectPrivate(stream, \"state\");\n" \
+ " if (!@writableStreamCloseQueuedOrInFlight(stream) && state === \"writable\") {\n" \
+ " const backpressure = @writableStreamDefaultControllerGetBackpressure(controller);\n" \
+ " @writableStreamUpdateBackpressure(stream, backpressure);\n" \
+ " }\n" \
+ " @writableStreamDefaultControllerAdvanceQueueIfNeeded(controller);\n" \
+ " } catch (e) {\n" \
+ " @writableStreamDefaultControllerErrorIfNeeded(controller, e);\n" \
+ " }\n" \
+ "})\n" \
+;
+
+
+#define DEFINE_BUILTIN_GENERATOR(codeName, functionName, overriddenName, argumentCount) \
+JSC::FunctionExecutable* codeName##Generator(JSC::VM& vm) \
+{\
+ JSVMClientData* clientData = static_cast<JSVMClientData*>(vm.clientData); \
+ return clientData->builtinFunctions().writableStreamInternalsBuiltins().codeName##Executable()->link(vm, nullptr, clientData->builtinFunctions().writableStreamInternalsBuiltins().codeName##Source(), std::nullopt, s_##codeName##Intrinsic); \
+}
+WEBCORE_FOREACH_WRITABLESTREAMINTERNALS_BUILTIN_CODE(DEFINE_BUILTIN_GENERATOR)
+#undef DEFINE_BUILTIN_GENERATOR
+
+
+} // namespace WebCore
diff --git a/src/bun.js/builtins/cpp/WritableStreamInternalsBuiltins.h b/src/bun.js/builtins/cpp/WritableStreamInternalsBuiltins.h
new file mode 100644
index 000000000..bc41d2ee3
--- /dev/null
+++ b/src/bun.js/builtins/cpp/WritableStreamInternalsBuiltins.h
@@ -0,0 +1,548 @@
+/*
+ * Copyright (c) 2015 Igalia
+ * Copyright (c) 2015 Igalia S.L.
+ * Copyright (c) 2015 Igalia.
+ * Copyright (c) 2015, 2016 Canon Inc. All rights reserved.
+ * Copyright (c) 2015, 2016, 2017 Canon Inc.
+ * Copyright (c) 2016, 2020 Apple Inc. All rights reserved.
+ * Copyright (c) 2022 Codeblog Corp. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+// DO NOT EDIT THIS FILE. It is automatically generated from JavaScript files for
+// builtins by the script: Source/JavaScriptCore/Scripts/generate-js-builtins.py
+
+#pragma once
+
+#include <JavaScriptCore/BuiltinUtils.h>
+#include <JavaScriptCore/Identifier.h>
+#include <JavaScriptCore/JSFunction.h>
+#include <JavaScriptCore/UnlinkedFunctionExecutable.h>
+
+namespace JSC {
+class FunctionExecutable;
+}
+
+namespace WebCore {
+
+/* WritableStreamInternals */
+extern const char* const s_writableStreamInternalsIsWritableStreamCode;
+extern const int s_writableStreamInternalsIsWritableStreamCodeLength;
+extern const JSC::ConstructAbility s_writableStreamInternalsIsWritableStreamCodeConstructAbility;
+extern const JSC::ConstructorKind s_writableStreamInternalsIsWritableStreamCodeConstructorKind;
+extern const char* const s_writableStreamInternalsIsWritableStreamDefaultWriterCode;
+extern const int s_writableStreamInternalsIsWritableStreamDefaultWriterCodeLength;
+extern const JSC::ConstructAbility s_writableStreamInternalsIsWritableStreamDefaultWriterCodeConstructAbility;
+extern const JSC::ConstructorKind s_writableStreamInternalsIsWritableStreamDefaultWriterCodeConstructorKind;
+extern const char* const s_writableStreamInternalsAcquireWritableStreamDefaultWriterCode;
+extern const int s_writableStreamInternalsAcquireWritableStreamDefaultWriterCodeLength;
+extern const JSC::ConstructAbility s_writableStreamInternalsAcquireWritableStreamDefaultWriterCodeConstructAbility;
+extern const JSC::ConstructorKind s_writableStreamInternalsAcquireWritableStreamDefaultWriterCodeConstructorKind;
+extern const char* const s_writableStreamInternalsCreateWritableStreamCode;
+extern const int s_writableStreamInternalsCreateWritableStreamCodeLength;
+extern const JSC::ConstructAbility s_writableStreamInternalsCreateWritableStreamCodeConstructAbility;
+extern const JSC::ConstructorKind s_writableStreamInternalsCreateWritableStreamCodeConstructorKind;
+extern const char* const s_writableStreamInternalsCreateInternalWritableStreamFromUnderlyingSinkCode;
+extern const int s_writableStreamInternalsCreateInternalWritableStreamFromUnderlyingSinkCodeLength;
+extern const JSC::ConstructAbility s_writableStreamInternalsCreateInternalWritableStreamFromUnderlyingSinkCodeConstructAbility;
+extern const JSC::ConstructorKind s_writableStreamInternalsCreateInternalWritableStreamFromUnderlyingSinkCodeConstructorKind;
+extern const char* const s_writableStreamInternalsInitializeWritableStreamSlotsCode;
+extern const int s_writableStreamInternalsInitializeWritableStreamSlotsCodeLength;
+extern const JSC::ConstructAbility s_writableStreamInternalsInitializeWritableStreamSlotsCodeConstructAbility;
+extern const JSC::ConstructorKind s_writableStreamInternalsInitializeWritableStreamSlotsCodeConstructorKind;
+extern const char* const s_writableStreamInternalsWritableStreamCloseForBindingsCode;
+extern const int s_writableStreamInternalsWritableStreamCloseForBindingsCodeLength;
+extern const JSC::ConstructAbility s_writableStreamInternalsWritableStreamCloseForBindingsCodeConstructAbility;
+extern const JSC::ConstructorKind s_writableStreamInternalsWritableStreamCloseForBindingsCodeConstructorKind;
+extern const char* const s_writableStreamInternalsWritableStreamAbortForBindingsCode;
+extern const int s_writableStreamInternalsWritableStreamAbortForBindingsCodeLength;
+extern const JSC::ConstructAbility s_writableStreamInternalsWritableStreamAbortForBindingsCodeConstructAbility;
+extern const JSC::ConstructorKind s_writableStreamInternalsWritableStreamAbortForBindingsCodeConstructorKind;
+extern const char* const s_writableStreamInternalsIsWritableStreamLockedCode;
+extern const int s_writableStreamInternalsIsWritableStreamLockedCodeLength;
+extern const JSC::ConstructAbility s_writableStreamInternalsIsWritableStreamLockedCodeConstructAbility;
+extern const JSC::ConstructorKind s_writableStreamInternalsIsWritableStreamLockedCodeConstructorKind;
+extern const char* const s_writableStreamInternalsSetUpWritableStreamDefaultWriterCode;
+extern const int s_writableStreamInternalsSetUpWritableStreamDefaultWriterCodeLength;
+extern const JSC::ConstructAbility s_writableStreamInternalsSetUpWritableStreamDefaultWriterCodeConstructAbility;
+extern const JSC::ConstructorKind s_writableStreamInternalsSetUpWritableStreamDefaultWriterCodeConstructorKind;
+extern const char* const s_writableStreamInternalsWritableStreamAbortCode;
+extern const int s_writableStreamInternalsWritableStreamAbortCodeLength;
+extern const JSC::ConstructAbility s_writableStreamInternalsWritableStreamAbortCodeConstructAbility;
+extern const JSC::ConstructorKind s_writableStreamInternalsWritableStreamAbortCodeConstructorKind;
+extern const char* const s_writableStreamInternalsWritableStreamCloseCode;
+extern const int s_writableStreamInternalsWritableStreamCloseCodeLength;
+extern const JSC::ConstructAbility s_writableStreamInternalsWritableStreamCloseCodeConstructAbility;
+extern const JSC::ConstructorKind s_writableStreamInternalsWritableStreamCloseCodeConstructorKind;
+extern const char* const s_writableStreamInternalsWritableStreamAddWriteRequestCode;
+extern const int s_writableStreamInternalsWritableStreamAddWriteRequestCodeLength;
+extern const JSC::ConstructAbility s_writableStreamInternalsWritableStreamAddWriteRequestCodeConstructAbility;
+extern const JSC::ConstructorKind s_writableStreamInternalsWritableStreamAddWriteRequestCodeConstructorKind;
+extern const char* const s_writableStreamInternalsWritableStreamCloseQueuedOrInFlightCode;
+extern const int s_writableStreamInternalsWritableStreamCloseQueuedOrInFlightCodeLength;
+extern const JSC::ConstructAbility s_writableStreamInternalsWritableStreamCloseQueuedOrInFlightCodeConstructAbility;
+extern const JSC::ConstructorKind s_writableStreamInternalsWritableStreamCloseQueuedOrInFlightCodeConstructorKind;
+extern const char* const s_writableStreamInternalsWritableStreamDealWithRejectionCode;
+extern const int s_writableStreamInternalsWritableStreamDealWithRejectionCodeLength;
+extern const JSC::ConstructAbility s_writableStreamInternalsWritableStreamDealWithRejectionCodeConstructAbility;
+extern const JSC::ConstructorKind s_writableStreamInternalsWritableStreamDealWithRejectionCodeConstructorKind;
+extern const char* const s_writableStreamInternalsWritableStreamFinishErroringCode;
+extern const int s_writableStreamInternalsWritableStreamFinishErroringCodeLength;
+extern const JSC::ConstructAbility s_writableStreamInternalsWritableStreamFinishErroringCodeConstructAbility;
+extern const JSC::ConstructorKind s_writableStreamInternalsWritableStreamFinishErroringCodeConstructorKind;
+extern const char* const s_writableStreamInternalsWritableStreamFinishInFlightCloseCode;
+extern const int s_writableStreamInternalsWritableStreamFinishInFlightCloseCodeLength;
+extern const JSC::ConstructAbility s_writableStreamInternalsWritableStreamFinishInFlightCloseCodeConstructAbility;
+extern const JSC::ConstructorKind s_writableStreamInternalsWritableStreamFinishInFlightCloseCodeConstructorKind;
+extern const char* const s_writableStreamInternalsWritableStreamFinishInFlightCloseWithErrorCode;
+extern const int s_writableStreamInternalsWritableStreamFinishInFlightCloseWithErrorCodeLength;
+extern const JSC::ConstructAbility s_writableStreamInternalsWritableStreamFinishInFlightCloseWithErrorCodeConstructAbility;
+extern const JSC::ConstructorKind s_writableStreamInternalsWritableStreamFinishInFlightCloseWithErrorCodeConstructorKind;
+extern const char* const s_writableStreamInternalsWritableStreamFinishInFlightWriteCode;
+extern const int s_writableStreamInternalsWritableStreamFinishInFlightWriteCodeLength;
+extern const JSC::ConstructAbility s_writableStreamInternalsWritableStreamFinishInFlightWriteCodeConstructAbility;
+extern const JSC::ConstructorKind s_writableStreamInternalsWritableStreamFinishInFlightWriteCodeConstructorKind;
+extern const char* const s_writableStreamInternalsWritableStreamFinishInFlightWriteWithErrorCode;
+extern const int s_writableStreamInternalsWritableStreamFinishInFlightWriteWithErrorCodeLength;
+extern const JSC::ConstructAbility s_writableStreamInternalsWritableStreamFinishInFlightWriteWithErrorCodeConstructAbility;
+extern const JSC::ConstructorKind s_writableStreamInternalsWritableStreamFinishInFlightWriteWithErrorCodeConstructorKind;
+extern const char* const s_writableStreamInternalsWritableStreamHasOperationMarkedInFlightCode;
+extern const int s_writableStreamInternalsWritableStreamHasOperationMarkedInFlightCodeLength;
+extern const JSC::ConstructAbility s_writableStreamInternalsWritableStreamHasOperationMarkedInFlightCodeConstructAbility;
+extern const JSC::ConstructorKind s_writableStreamInternalsWritableStreamHasOperationMarkedInFlightCodeConstructorKind;
+extern const char* const s_writableStreamInternalsWritableStreamMarkCloseRequestInFlightCode;
+extern const int s_writableStreamInternalsWritableStreamMarkCloseRequestInFlightCodeLength;
+extern const JSC::ConstructAbility s_writableStreamInternalsWritableStreamMarkCloseRequestInFlightCodeConstructAbility;
+extern const JSC::ConstructorKind s_writableStreamInternalsWritableStreamMarkCloseRequestInFlightCodeConstructorKind;
+extern const char* const s_writableStreamInternalsWritableStreamMarkFirstWriteRequestInFlightCode;
+extern const int s_writableStreamInternalsWritableStreamMarkFirstWriteRequestInFlightCodeLength;
+extern const JSC::ConstructAbility s_writableStreamInternalsWritableStreamMarkFirstWriteRequestInFlightCodeConstructAbility;
+extern const JSC::ConstructorKind s_writableStreamInternalsWritableStreamMarkFirstWriteRequestInFlightCodeConstructorKind;
+extern const char* const s_writableStreamInternalsWritableStreamRejectCloseAndClosedPromiseIfNeededCode;
+extern const int s_writableStreamInternalsWritableStreamRejectCloseAndClosedPromiseIfNeededCodeLength;
+extern const JSC::ConstructAbility s_writableStreamInternalsWritableStreamRejectCloseAndClosedPromiseIfNeededCodeConstructAbility;
+extern const JSC::ConstructorKind s_writableStreamInternalsWritableStreamRejectCloseAndClosedPromiseIfNeededCodeConstructorKind;
+extern const char* const s_writableStreamInternalsWritableStreamStartErroringCode;
+extern const int s_writableStreamInternalsWritableStreamStartErroringCodeLength;
+extern const JSC::ConstructAbility s_writableStreamInternalsWritableStreamStartErroringCodeConstructAbility;
+extern const JSC::ConstructorKind s_writableStreamInternalsWritableStreamStartErroringCodeConstructorKind;
+extern const char* const s_writableStreamInternalsWritableStreamUpdateBackpressureCode;
+extern const int s_writableStreamInternalsWritableStreamUpdateBackpressureCodeLength;
+extern const JSC::ConstructAbility s_writableStreamInternalsWritableStreamUpdateBackpressureCodeConstructAbility;
+extern const JSC::ConstructorKind s_writableStreamInternalsWritableStreamUpdateBackpressureCodeConstructorKind;
+extern const char* const s_writableStreamInternalsWritableStreamDefaultWriterAbortCode;
+extern const int s_writableStreamInternalsWritableStreamDefaultWriterAbortCodeLength;
+extern const JSC::ConstructAbility s_writableStreamInternalsWritableStreamDefaultWriterAbortCodeConstructAbility;
+extern const JSC::ConstructorKind s_writableStreamInternalsWritableStreamDefaultWriterAbortCodeConstructorKind;
+extern const char* const s_writableStreamInternalsWritableStreamDefaultWriterCloseCode;
+extern const int s_writableStreamInternalsWritableStreamDefaultWriterCloseCodeLength;
+extern const JSC::ConstructAbility s_writableStreamInternalsWritableStreamDefaultWriterCloseCodeConstructAbility;
+extern const JSC::ConstructorKind s_writableStreamInternalsWritableStreamDefaultWriterCloseCodeConstructorKind;
+extern const char* const s_writableStreamInternalsWritableStreamDefaultWriterCloseWithErrorPropagationCode;
+extern const int s_writableStreamInternalsWritableStreamDefaultWriterCloseWithErrorPropagationCodeLength;
+extern const JSC::ConstructAbility s_writableStreamInternalsWritableStreamDefaultWriterCloseWithErrorPropagationCodeConstructAbility;
+extern const JSC::ConstructorKind s_writableStreamInternalsWritableStreamDefaultWriterCloseWithErrorPropagationCodeConstructorKind;
+extern const char* const s_writableStreamInternalsWritableStreamDefaultWriterEnsureClosedPromiseRejectedCode;
+extern const int s_writableStreamInternalsWritableStreamDefaultWriterEnsureClosedPromiseRejectedCodeLength;
+extern const JSC::ConstructAbility s_writableStreamInternalsWritableStreamDefaultWriterEnsureClosedPromiseRejectedCodeConstructAbility;
+extern const JSC::ConstructorKind s_writableStreamInternalsWritableStreamDefaultWriterEnsureClosedPromiseRejectedCodeConstructorKind;
+extern const char* const s_writableStreamInternalsWritableStreamDefaultWriterEnsureReadyPromiseRejectedCode;
+extern const int s_writableStreamInternalsWritableStreamDefaultWriterEnsureReadyPromiseRejectedCodeLength;
+extern const JSC::ConstructAbility s_writableStreamInternalsWritableStreamDefaultWriterEnsureReadyPromiseRejectedCodeConstructAbility;
+extern const JSC::ConstructorKind s_writableStreamInternalsWritableStreamDefaultWriterEnsureReadyPromiseRejectedCodeConstructorKind;
+extern const char* const s_writableStreamInternalsWritableStreamDefaultWriterGetDesiredSizeCode;
+extern const int s_writableStreamInternalsWritableStreamDefaultWriterGetDesiredSizeCodeLength;
+extern const JSC::ConstructAbility s_writableStreamInternalsWritableStreamDefaultWriterGetDesiredSizeCodeConstructAbility;
+extern const JSC::ConstructorKind s_writableStreamInternalsWritableStreamDefaultWriterGetDesiredSizeCodeConstructorKind;
+extern const char* const s_writableStreamInternalsWritableStreamDefaultWriterReleaseCode;
+extern const int s_writableStreamInternalsWritableStreamDefaultWriterReleaseCodeLength;
+extern const JSC::ConstructAbility s_writableStreamInternalsWritableStreamDefaultWriterReleaseCodeConstructAbility;
+extern const JSC::ConstructorKind s_writableStreamInternalsWritableStreamDefaultWriterReleaseCodeConstructorKind;
+extern const char* const s_writableStreamInternalsWritableStreamDefaultWriterWriteCode;
+extern const int s_writableStreamInternalsWritableStreamDefaultWriterWriteCodeLength;
+extern const JSC::ConstructAbility s_writableStreamInternalsWritableStreamDefaultWriterWriteCodeConstructAbility;
+extern const JSC::ConstructorKind s_writableStreamInternalsWritableStreamDefaultWriterWriteCodeConstructorKind;
+extern const char* const s_writableStreamInternalsSetUpWritableStreamDefaultControllerCode;
+extern const int s_writableStreamInternalsSetUpWritableStreamDefaultControllerCodeLength;
+extern const JSC::ConstructAbility s_writableStreamInternalsSetUpWritableStreamDefaultControllerCodeConstructAbility;
+extern const JSC::ConstructorKind s_writableStreamInternalsSetUpWritableStreamDefaultControllerCodeConstructorKind;
+extern const char* const s_writableStreamInternalsWritableStreamDefaultControllerStartCode;
+extern const int s_writableStreamInternalsWritableStreamDefaultControllerStartCodeLength;
+extern const JSC::ConstructAbility s_writableStreamInternalsWritableStreamDefaultControllerStartCodeConstructAbility;
+extern const JSC::ConstructorKind s_writableStreamInternalsWritableStreamDefaultControllerStartCodeConstructorKind;
+extern const char* const s_writableStreamInternalsSetUpWritableStreamDefaultControllerFromUnderlyingSinkCode;
+extern const int s_writableStreamInternalsSetUpWritableStreamDefaultControllerFromUnderlyingSinkCodeLength;
+extern const JSC::ConstructAbility s_writableStreamInternalsSetUpWritableStreamDefaultControllerFromUnderlyingSinkCodeConstructAbility;
+extern const JSC::ConstructorKind s_writableStreamInternalsSetUpWritableStreamDefaultControllerFromUnderlyingSinkCodeConstructorKind;
+extern const char* const s_writableStreamInternalsWritableStreamDefaultControllerAdvanceQueueIfNeededCode;
+extern const int s_writableStreamInternalsWritableStreamDefaultControllerAdvanceQueueIfNeededCodeLength;
+extern const JSC::ConstructAbility s_writableStreamInternalsWritableStreamDefaultControllerAdvanceQueueIfNeededCodeConstructAbility;
+extern const JSC::ConstructorKind s_writableStreamInternalsWritableStreamDefaultControllerAdvanceQueueIfNeededCodeConstructorKind;
+extern const char* const s_writableStreamInternalsIsCloseSentinelCode;
+extern const int s_writableStreamInternalsIsCloseSentinelCodeLength;
+extern const JSC::ConstructAbility s_writableStreamInternalsIsCloseSentinelCodeConstructAbility;
+extern const JSC::ConstructorKind s_writableStreamInternalsIsCloseSentinelCodeConstructorKind;
+extern const char* const s_writableStreamInternalsWritableStreamDefaultControllerClearAlgorithmsCode;
+extern const int s_writableStreamInternalsWritableStreamDefaultControllerClearAlgorithmsCodeLength;
+extern const JSC::ConstructAbility s_writableStreamInternalsWritableStreamDefaultControllerClearAlgorithmsCodeConstructAbility;
+extern const JSC::ConstructorKind s_writableStreamInternalsWritableStreamDefaultControllerClearAlgorithmsCodeConstructorKind;
+extern const char* const s_writableStreamInternalsWritableStreamDefaultControllerCloseCode;
+extern const int s_writableStreamInternalsWritableStreamDefaultControllerCloseCodeLength;
+extern const JSC::ConstructAbility s_writableStreamInternalsWritableStreamDefaultControllerCloseCodeConstructAbility;
+extern const JSC::ConstructorKind s_writableStreamInternalsWritableStreamDefaultControllerCloseCodeConstructorKind;
+extern const char* const s_writableStreamInternalsWritableStreamDefaultControllerErrorCode;
+extern const int s_writableStreamInternalsWritableStreamDefaultControllerErrorCodeLength;
+extern const JSC::ConstructAbility s_writableStreamInternalsWritableStreamDefaultControllerErrorCodeConstructAbility;
+extern const JSC::ConstructorKind s_writableStreamInternalsWritableStreamDefaultControllerErrorCodeConstructorKind;
+extern const char* const s_writableStreamInternalsWritableStreamDefaultControllerErrorIfNeededCode;
+extern const int s_writableStreamInternalsWritableStreamDefaultControllerErrorIfNeededCodeLength;
+extern const JSC::ConstructAbility s_writableStreamInternalsWritableStreamDefaultControllerErrorIfNeededCodeConstructAbility;
+extern const JSC::ConstructorKind s_writableStreamInternalsWritableStreamDefaultControllerErrorIfNeededCodeConstructorKind;
+extern const char* const s_writableStreamInternalsWritableStreamDefaultControllerGetBackpressureCode;
+extern const int s_writableStreamInternalsWritableStreamDefaultControllerGetBackpressureCodeLength;
+extern const JSC::ConstructAbility s_writableStreamInternalsWritableStreamDefaultControllerGetBackpressureCodeConstructAbility;
+extern const JSC::ConstructorKind s_writableStreamInternalsWritableStreamDefaultControllerGetBackpressureCodeConstructorKind;
+extern const char* const s_writableStreamInternalsWritableStreamDefaultControllerGetChunkSizeCode;
+extern const int s_writableStreamInternalsWritableStreamDefaultControllerGetChunkSizeCodeLength;
+extern const JSC::ConstructAbility s_writableStreamInternalsWritableStreamDefaultControllerGetChunkSizeCodeConstructAbility;
+extern const JSC::ConstructorKind s_writableStreamInternalsWritableStreamDefaultControllerGetChunkSizeCodeConstructorKind;
+extern const char* const s_writableStreamInternalsWritableStreamDefaultControllerGetDesiredSizeCode;
+extern const int s_writableStreamInternalsWritableStreamDefaultControllerGetDesiredSizeCodeLength;
+extern const JSC::ConstructAbility s_writableStreamInternalsWritableStreamDefaultControllerGetDesiredSizeCodeConstructAbility;
+extern const JSC::ConstructorKind s_writableStreamInternalsWritableStreamDefaultControllerGetDesiredSizeCodeConstructorKind;
+extern const char* const s_writableStreamInternalsWritableStreamDefaultControllerProcessCloseCode;
+extern const int s_writableStreamInternalsWritableStreamDefaultControllerProcessCloseCodeLength;
+extern const JSC::ConstructAbility s_writableStreamInternalsWritableStreamDefaultControllerProcessCloseCodeConstructAbility;
+extern const JSC::ConstructorKind s_writableStreamInternalsWritableStreamDefaultControllerProcessCloseCodeConstructorKind;
+extern const char* const s_writableStreamInternalsWritableStreamDefaultControllerProcessWriteCode;
+extern const int s_writableStreamInternalsWritableStreamDefaultControllerProcessWriteCodeLength;
+extern const JSC::ConstructAbility s_writableStreamInternalsWritableStreamDefaultControllerProcessWriteCodeConstructAbility;
+extern const JSC::ConstructorKind s_writableStreamInternalsWritableStreamDefaultControllerProcessWriteCodeConstructorKind;
+extern const char* const s_writableStreamInternalsWritableStreamDefaultControllerWriteCode;
+extern const int s_writableStreamInternalsWritableStreamDefaultControllerWriteCodeLength;
+extern const JSC::ConstructAbility s_writableStreamInternalsWritableStreamDefaultControllerWriteCodeConstructAbility;
+extern const JSC::ConstructorKind s_writableStreamInternalsWritableStreamDefaultControllerWriteCodeConstructorKind;
+
+#define WEBCORE_FOREACH_WRITABLESTREAMINTERNALS_BUILTIN_DATA(macro) \
+ macro(isWritableStream, writableStreamInternalsIsWritableStream, 1) \
+ macro(isWritableStreamDefaultWriter, writableStreamInternalsIsWritableStreamDefaultWriter, 1) \
+ macro(acquireWritableStreamDefaultWriter, writableStreamInternalsAcquireWritableStreamDefaultWriter, 1) \
+ macro(createWritableStream, writableStreamInternalsCreateWritableStream, 6) \
+ macro(createInternalWritableStreamFromUnderlyingSink, writableStreamInternalsCreateInternalWritableStreamFromUnderlyingSink, 2) \
+ macro(initializeWritableStreamSlots, writableStreamInternalsInitializeWritableStreamSlots, 2) \
+ macro(writableStreamCloseForBindings, writableStreamInternalsWritableStreamCloseForBindings, 1) \
+ macro(writableStreamAbortForBindings, writableStreamInternalsWritableStreamAbortForBindings, 2) \
+ macro(isWritableStreamLocked, writableStreamInternalsIsWritableStreamLocked, 1) \
+ macro(setUpWritableStreamDefaultWriter, writableStreamInternalsSetUpWritableStreamDefaultWriter, 2) \
+ macro(writableStreamAbort, writableStreamInternalsWritableStreamAbort, 2) \
+ macro(writableStreamClose, writableStreamInternalsWritableStreamClose, 1) \
+ macro(writableStreamAddWriteRequest, writableStreamInternalsWritableStreamAddWriteRequest, 1) \
+ macro(writableStreamCloseQueuedOrInFlight, writableStreamInternalsWritableStreamCloseQueuedOrInFlight, 1) \
+ macro(writableStreamDealWithRejection, writableStreamInternalsWritableStreamDealWithRejection, 2) \
+ macro(writableStreamFinishErroring, writableStreamInternalsWritableStreamFinishErroring, 1) \
+ macro(writableStreamFinishInFlightClose, writableStreamInternalsWritableStreamFinishInFlightClose, 1) \
+ macro(writableStreamFinishInFlightCloseWithError, writableStreamInternalsWritableStreamFinishInFlightCloseWithError, 2) \
+ macro(writableStreamFinishInFlightWrite, writableStreamInternalsWritableStreamFinishInFlightWrite, 1) \
+ macro(writableStreamFinishInFlightWriteWithError, writableStreamInternalsWritableStreamFinishInFlightWriteWithError, 2) \
+ macro(writableStreamHasOperationMarkedInFlight, writableStreamInternalsWritableStreamHasOperationMarkedInFlight, 1) \
+ macro(writableStreamMarkCloseRequestInFlight, writableStreamInternalsWritableStreamMarkCloseRequestInFlight, 1) \
+ macro(writableStreamMarkFirstWriteRequestInFlight, writableStreamInternalsWritableStreamMarkFirstWriteRequestInFlight, 1) \
+ macro(writableStreamRejectCloseAndClosedPromiseIfNeeded, writableStreamInternalsWritableStreamRejectCloseAndClosedPromiseIfNeeded, 1) \
+ macro(writableStreamStartErroring, writableStreamInternalsWritableStreamStartErroring, 2) \
+ macro(writableStreamUpdateBackpressure, writableStreamInternalsWritableStreamUpdateBackpressure, 2) \
+ macro(writableStreamDefaultWriterAbort, writableStreamInternalsWritableStreamDefaultWriterAbort, 2) \
+ macro(writableStreamDefaultWriterClose, writableStreamInternalsWritableStreamDefaultWriterClose, 1) \
+ macro(writableStreamDefaultWriterCloseWithErrorPropagation, writableStreamInternalsWritableStreamDefaultWriterCloseWithErrorPropagation, 1) \
+ macro(writableStreamDefaultWriterEnsureClosedPromiseRejected, writableStreamInternalsWritableStreamDefaultWriterEnsureClosedPromiseRejected, 2) \
+ macro(writableStreamDefaultWriterEnsureReadyPromiseRejected, writableStreamInternalsWritableStreamDefaultWriterEnsureReadyPromiseRejected, 2) \
+ macro(writableStreamDefaultWriterGetDesiredSize, writableStreamInternalsWritableStreamDefaultWriterGetDesiredSize, 1) \
+ macro(writableStreamDefaultWriterRelease, writableStreamInternalsWritableStreamDefaultWriterRelease, 1) \
+ macro(writableStreamDefaultWriterWrite, writableStreamInternalsWritableStreamDefaultWriterWrite, 2) \
+ macro(setUpWritableStreamDefaultController, writableStreamInternalsSetUpWritableStreamDefaultController, 8) \
+ macro(writableStreamDefaultControllerStart, writableStreamInternalsWritableStreamDefaultControllerStart, 1) \
+ macro(setUpWritableStreamDefaultControllerFromUnderlyingSink, writableStreamInternalsSetUpWritableStreamDefaultControllerFromUnderlyingSink, 5) \
+ macro(writableStreamDefaultControllerAdvanceQueueIfNeeded, writableStreamInternalsWritableStreamDefaultControllerAdvanceQueueIfNeeded, 1) \
+ macro(isCloseSentinel, writableStreamInternalsIsCloseSentinel, 0) \
+ macro(writableStreamDefaultControllerClearAlgorithms, writableStreamInternalsWritableStreamDefaultControllerClearAlgorithms, 1) \
+ macro(writableStreamDefaultControllerClose, writableStreamInternalsWritableStreamDefaultControllerClose, 1) \
+ macro(writableStreamDefaultControllerError, writableStreamInternalsWritableStreamDefaultControllerError, 2) \
+ macro(writableStreamDefaultControllerErrorIfNeeded, writableStreamInternalsWritableStreamDefaultControllerErrorIfNeeded, 2) \
+ macro(writableStreamDefaultControllerGetBackpressure, writableStreamInternalsWritableStreamDefaultControllerGetBackpressure, 1) \
+ macro(writableStreamDefaultControllerGetChunkSize, writableStreamInternalsWritableStreamDefaultControllerGetChunkSize, 2) \
+ macro(writableStreamDefaultControllerGetDesiredSize, writableStreamInternalsWritableStreamDefaultControllerGetDesiredSize, 1) \
+ macro(writableStreamDefaultControllerProcessClose, writableStreamInternalsWritableStreamDefaultControllerProcessClose, 1) \
+ macro(writableStreamDefaultControllerProcessWrite, writableStreamInternalsWritableStreamDefaultControllerProcessWrite, 2) \
+ macro(writableStreamDefaultControllerWrite, writableStreamInternalsWritableStreamDefaultControllerWrite, 3) \
+
+#define WEBCORE_BUILTIN_WRITABLESTREAMINTERNALS_ISWRITABLESTREAM 1
+#define WEBCORE_BUILTIN_WRITABLESTREAMINTERNALS_ISWRITABLESTREAMDEFAULTWRITER 1
+#define WEBCORE_BUILTIN_WRITABLESTREAMINTERNALS_ACQUIREWRITABLESTREAMDEFAULTWRITER 1
+#define WEBCORE_BUILTIN_WRITABLESTREAMINTERNALS_CREATEWRITABLESTREAM 1
+#define WEBCORE_BUILTIN_WRITABLESTREAMINTERNALS_CREATEINTERNALWRITABLESTREAMFROMUNDERLYINGSINK 1
+#define WEBCORE_BUILTIN_WRITABLESTREAMINTERNALS_INITIALIZEWRITABLESTREAMSLOTS 1
+#define WEBCORE_BUILTIN_WRITABLESTREAMINTERNALS_WRITABLESTREAMCLOSEFORBINDINGS 1
+#define WEBCORE_BUILTIN_WRITABLESTREAMINTERNALS_WRITABLESTREAMABORTFORBINDINGS 1
+#define WEBCORE_BUILTIN_WRITABLESTREAMINTERNALS_ISWRITABLESTREAMLOCKED 1
+#define WEBCORE_BUILTIN_WRITABLESTREAMINTERNALS_SETUPWRITABLESTREAMDEFAULTWRITER 1
+#define WEBCORE_BUILTIN_WRITABLESTREAMINTERNALS_WRITABLESTREAMABORT 1
+#define WEBCORE_BUILTIN_WRITABLESTREAMINTERNALS_WRITABLESTREAMCLOSE 1
+#define WEBCORE_BUILTIN_WRITABLESTREAMINTERNALS_WRITABLESTREAMADDWRITEREQUEST 1
+#define WEBCORE_BUILTIN_WRITABLESTREAMINTERNALS_WRITABLESTREAMCLOSEQUEUEDORINFLIGHT 1
+#define WEBCORE_BUILTIN_WRITABLESTREAMINTERNALS_WRITABLESTREAMDEALWITHREJECTION 1
+#define WEBCORE_BUILTIN_WRITABLESTREAMINTERNALS_WRITABLESTREAMFINISHERRORING 1
+#define WEBCORE_BUILTIN_WRITABLESTREAMINTERNALS_WRITABLESTREAMFINISHINFLIGHTCLOSE 1
+#define WEBCORE_BUILTIN_WRITABLESTREAMINTERNALS_WRITABLESTREAMFINISHINFLIGHTCLOSEWITHERROR 1
+#define WEBCORE_BUILTIN_WRITABLESTREAMINTERNALS_WRITABLESTREAMFINISHINFLIGHTWRITE 1
+#define WEBCORE_BUILTIN_WRITABLESTREAMINTERNALS_WRITABLESTREAMFINISHINFLIGHTWRITEWITHERROR 1
+#define WEBCORE_BUILTIN_WRITABLESTREAMINTERNALS_WRITABLESTREAMHASOPERATIONMARKEDINFLIGHT 1
+#define WEBCORE_BUILTIN_WRITABLESTREAMINTERNALS_WRITABLESTREAMMARKCLOSEREQUESTINFLIGHT 1
+#define WEBCORE_BUILTIN_WRITABLESTREAMINTERNALS_WRITABLESTREAMMARKFIRSTWRITEREQUESTINFLIGHT 1
+#define WEBCORE_BUILTIN_WRITABLESTREAMINTERNALS_WRITABLESTREAMREJECTCLOSEANDCLOSEDPROMISEIFNEEDED 1
+#define WEBCORE_BUILTIN_WRITABLESTREAMINTERNALS_WRITABLESTREAMSTARTERRORING 1
+#define WEBCORE_BUILTIN_WRITABLESTREAMINTERNALS_WRITABLESTREAMUPDATEBACKPRESSURE 1
+#define WEBCORE_BUILTIN_WRITABLESTREAMINTERNALS_WRITABLESTREAMDEFAULTWRITERABORT 1
+#define WEBCORE_BUILTIN_WRITABLESTREAMINTERNALS_WRITABLESTREAMDEFAULTWRITERCLOSE 1
+#define WEBCORE_BUILTIN_WRITABLESTREAMINTERNALS_WRITABLESTREAMDEFAULTWRITERCLOSEWITHERRORPROPAGATION 1
+#define WEBCORE_BUILTIN_WRITABLESTREAMINTERNALS_WRITABLESTREAMDEFAULTWRITERENSURECLOSEDPROMISEREJECTED 1
+#define WEBCORE_BUILTIN_WRITABLESTREAMINTERNALS_WRITABLESTREAMDEFAULTWRITERENSUREREADYPROMISEREJECTED 1
+#define WEBCORE_BUILTIN_WRITABLESTREAMINTERNALS_WRITABLESTREAMDEFAULTWRITERGETDESIREDSIZE 1
+#define WEBCORE_BUILTIN_WRITABLESTREAMINTERNALS_WRITABLESTREAMDEFAULTWRITERRELEASE 1
+#define WEBCORE_BUILTIN_WRITABLESTREAMINTERNALS_WRITABLESTREAMDEFAULTWRITERWRITE 1
+#define WEBCORE_BUILTIN_WRITABLESTREAMINTERNALS_SETUPWRITABLESTREAMDEFAULTCONTROLLER 1
+#define WEBCORE_BUILTIN_WRITABLESTREAMINTERNALS_WRITABLESTREAMDEFAULTCONTROLLERSTART 1
+#define WEBCORE_BUILTIN_WRITABLESTREAMINTERNALS_SETUPWRITABLESTREAMDEFAULTCONTROLLERFROMUNDERLYINGSINK 1
+#define WEBCORE_BUILTIN_WRITABLESTREAMINTERNALS_WRITABLESTREAMDEFAULTCONTROLLERADVANCEQUEUEIFNEEDED 1
+#define WEBCORE_BUILTIN_WRITABLESTREAMINTERNALS_ISCLOSESENTINEL 1
+#define WEBCORE_BUILTIN_WRITABLESTREAMINTERNALS_WRITABLESTREAMDEFAULTCONTROLLERCLEARALGORITHMS 1
+#define WEBCORE_BUILTIN_WRITABLESTREAMINTERNALS_WRITABLESTREAMDEFAULTCONTROLLERCLOSE 1
+#define WEBCORE_BUILTIN_WRITABLESTREAMINTERNALS_WRITABLESTREAMDEFAULTCONTROLLERERROR 1
+#define WEBCORE_BUILTIN_WRITABLESTREAMINTERNALS_WRITABLESTREAMDEFAULTCONTROLLERERRORIFNEEDED 1
+#define WEBCORE_BUILTIN_WRITABLESTREAMINTERNALS_WRITABLESTREAMDEFAULTCONTROLLERGETBACKPRESSURE 1
+#define WEBCORE_BUILTIN_WRITABLESTREAMINTERNALS_WRITABLESTREAMDEFAULTCONTROLLERGETCHUNKSIZE 1
+#define WEBCORE_BUILTIN_WRITABLESTREAMINTERNALS_WRITABLESTREAMDEFAULTCONTROLLERGETDESIREDSIZE 1
+#define WEBCORE_BUILTIN_WRITABLESTREAMINTERNALS_WRITABLESTREAMDEFAULTCONTROLLERPROCESSCLOSE 1
+#define WEBCORE_BUILTIN_WRITABLESTREAMINTERNALS_WRITABLESTREAMDEFAULTCONTROLLERPROCESSWRITE 1
+#define WEBCORE_BUILTIN_WRITABLESTREAMINTERNALS_WRITABLESTREAMDEFAULTCONTROLLERWRITE 1
+
+#define WEBCORE_FOREACH_WRITABLESTREAMINTERNALS_BUILTIN_CODE(macro) \
+ macro(writableStreamInternalsIsWritableStreamCode, isWritableStream, ASCIILiteral(), s_writableStreamInternalsIsWritableStreamCodeLength) \
+ macro(writableStreamInternalsIsWritableStreamDefaultWriterCode, isWritableStreamDefaultWriter, ASCIILiteral(), s_writableStreamInternalsIsWritableStreamDefaultWriterCodeLength) \
+ macro(writableStreamInternalsAcquireWritableStreamDefaultWriterCode, acquireWritableStreamDefaultWriter, ASCIILiteral(), s_writableStreamInternalsAcquireWritableStreamDefaultWriterCodeLength) \
+ macro(writableStreamInternalsCreateWritableStreamCode, createWritableStream, ASCIILiteral(), s_writableStreamInternalsCreateWritableStreamCodeLength) \
+ macro(writableStreamInternalsCreateInternalWritableStreamFromUnderlyingSinkCode, createInternalWritableStreamFromUnderlyingSink, ASCIILiteral(), s_writableStreamInternalsCreateInternalWritableStreamFromUnderlyingSinkCodeLength) \
+ macro(writableStreamInternalsInitializeWritableStreamSlotsCode, initializeWritableStreamSlots, ASCIILiteral(), s_writableStreamInternalsInitializeWritableStreamSlotsCodeLength) \
+ macro(writableStreamInternalsWritableStreamCloseForBindingsCode, writableStreamCloseForBindings, ASCIILiteral(), s_writableStreamInternalsWritableStreamCloseForBindingsCodeLength) \
+ macro(writableStreamInternalsWritableStreamAbortForBindingsCode, writableStreamAbortForBindings, ASCIILiteral(), s_writableStreamInternalsWritableStreamAbortForBindingsCodeLength) \
+ macro(writableStreamInternalsIsWritableStreamLockedCode, isWritableStreamLocked, ASCIILiteral(), s_writableStreamInternalsIsWritableStreamLockedCodeLength) \
+ macro(writableStreamInternalsSetUpWritableStreamDefaultWriterCode, setUpWritableStreamDefaultWriter, ASCIILiteral(), s_writableStreamInternalsSetUpWritableStreamDefaultWriterCodeLength) \
+ macro(writableStreamInternalsWritableStreamAbortCode, writableStreamAbort, ASCIILiteral(), s_writableStreamInternalsWritableStreamAbortCodeLength) \
+ macro(writableStreamInternalsWritableStreamCloseCode, writableStreamClose, ASCIILiteral(), s_writableStreamInternalsWritableStreamCloseCodeLength) \
+ macro(writableStreamInternalsWritableStreamAddWriteRequestCode, writableStreamAddWriteRequest, ASCIILiteral(), s_writableStreamInternalsWritableStreamAddWriteRequestCodeLength) \
+ macro(writableStreamInternalsWritableStreamCloseQueuedOrInFlightCode, writableStreamCloseQueuedOrInFlight, ASCIILiteral(), s_writableStreamInternalsWritableStreamCloseQueuedOrInFlightCodeLength) \
+ macro(writableStreamInternalsWritableStreamDealWithRejectionCode, writableStreamDealWithRejection, ASCIILiteral(), s_writableStreamInternalsWritableStreamDealWithRejectionCodeLength) \
+ macro(writableStreamInternalsWritableStreamFinishErroringCode, writableStreamFinishErroring, ASCIILiteral(), s_writableStreamInternalsWritableStreamFinishErroringCodeLength) \
+ macro(writableStreamInternalsWritableStreamFinishInFlightCloseCode, writableStreamFinishInFlightClose, ASCIILiteral(), s_writableStreamInternalsWritableStreamFinishInFlightCloseCodeLength) \
+ macro(writableStreamInternalsWritableStreamFinishInFlightCloseWithErrorCode, writableStreamFinishInFlightCloseWithError, ASCIILiteral(), s_writableStreamInternalsWritableStreamFinishInFlightCloseWithErrorCodeLength) \
+ macro(writableStreamInternalsWritableStreamFinishInFlightWriteCode, writableStreamFinishInFlightWrite, ASCIILiteral(), s_writableStreamInternalsWritableStreamFinishInFlightWriteCodeLength) \
+ macro(writableStreamInternalsWritableStreamFinishInFlightWriteWithErrorCode, writableStreamFinishInFlightWriteWithError, ASCIILiteral(), s_writableStreamInternalsWritableStreamFinishInFlightWriteWithErrorCodeLength) \
+ macro(writableStreamInternalsWritableStreamHasOperationMarkedInFlightCode, writableStreamHasOperationMarkedInFlight, ASCIILiteral(), s_writableStreamInternalsWritableStreamHasOperationMarkedInFlightCodeLength) \
+ macro(writableStreamInternalsWritableStreamMarkCloseRequestInFlightCode, writableStreamMarkCloseRequestInFlight, ASCIILiteral(), s_writableStreamInternalsWritableStreamMarkCloseRequestInFlightCodeLength) \
+ macro(writableStreamInternalsWritableStreamMarkFirstWriteRequestInFlightCode, writableStreamMarkFirstWriteRequestInFlight, ASCIILiteral(), s_writableStreamInternalsWritableStreamMarkFirstWriteRequestInFlightCodeLength) \
+ macro(writableStreamInternalsWritableStreamRejectCloseAndClosedPromiseIfNeededCode, writableStreamRejectCloseAndClosedPromiseIfNeeded, ASCIILiteral(), s_writableStreamInternalsWritableStreamRejectCloseAndClosedPromiseIfNeededCodeLength) \
+ macro(writableStreamInternalsWritableStreamStartErroringCode, writableStreamStartErroring, ASCIILiteral(), s_writableStreamInternalsWritableStreamStartErroringCodeLength) \
+ macro(writableStreamInternalsWritableStreamUpdateBackpressureCode, writableStreamUpdateBackpressure, ASCIILiteral(), s_writableStreamInternalsWritableStreamUpdateBackpressureCodeLength) \
+ macro(writableStreamInternalsWritableStreamDefaultWriterAbortCode, writableStreamDefaultWriterAbort, ASCIILiteral(), s_writableStreamInternalsWritableStreamDefaultWriterAbortCodeLength) \
+ macro(writableStreamInternalsWritableStreamDefaultWriterCloseCode, writableStreamDefaultWriterClose, ASCIILiteral(), s_writableStreamInternalsWritableStreamDefaultWriterCloseCodeLength) \
+ macro(writableStreamInternalsWritableStreamDefaultWriterCloseWithErrorPropagationCode, writableStreamDefaultWriterCloseWithErrorPropagation, ASCIILiteral(), s_writableStreamInternalsWritableStreamDefaultWriterCloseWithErrorPropagationCodeLength) \
+ macro(writableStreamInternalsWritableStreamDefaultWriterEnsureClosedPromiseRejectedCode, writableStreamDefaultWriterEnsureClosedPromiseRejected, ASCIILiteral(), s_writableStreamInternalsWritableStreamDefaultWriterEnsureClosedPromiseRejectedCodeLength) \
+ macro(writableStreamInternalsWritableStreamDefaultWriterEnsureReadyPromiseRejectedCode, writableStreamDefaultWriterEnsureReadyPromiseRejected, ASCIILiteral(), s_writableStreamInternalsWritableStreamDefaultWriterEnsureReadyPromiseRejectedCodeLength) \
+ macro(writableStreamInternalsWritableStreamDefaultWriterGetDesiredSizeCode, writableStreamDefaultWriterGetDesiredSize, ASCIILiteral(), s_writableStreamInternalsWritableStreamDefaultWriterGetDesiredSizeCodeLength) \
+ macro(writableStreamInternalsWritableStreamDefaultWriterReleaseCode, writableStreamDefaultWriterRelease, ASCIILiteral(), s_writableStreamInternalsWritableStreamDefaultWriterReleaseCodeLength) \
+ macro(writableStreamInternalsWritableStreamDefaultWriterWriteCode, writableStreamDefaultWriterWrite, ASCIILiteral(), s_writableStreamInternalsWritableStreamDefaultWriterWriteCodeLength) \
+ macro(writableStreamInternalsSetUpWritableStreamDefaultControllerCode, setUpWritableStreamDefaultController, ASCIILiteral(), s_writableStreamInternalsSetUpWritableStreamDefaultControllerCodeLength) \
+ macro(writableStreamInternalsWritableStreamDefaultControllerStartCode, writableStreamDefaultControllerStart, ASCIILiteral(), s_writableStreamInternalsWritableStreamDefaultControllerStartCodeLength) \
+ macro(writableStreamInternalsSetUpWritableStreamDefaultControllerFromUnderlyingSinkCode, setUpWritableStreamDefaultControllerFromUnderlyingSink, ASCIILiteral(), s_writableStreamInternalsSetUpWritableStreamDefaultControllerFromUnderlyingSinkCodeLength) \
+ macro(writableStreamInternalsWritableStreamDefaultControllerAdvanceQueueIfNeededCode, writableStreamDefaultControllerAdvanceQueueIfNeeded, ASCIILiteral(), s_writableStreamInternalsWritableStreamDefaultControllerAdvanceQueueIfNeededCodeLength) \
+ macro(writableStreamInternalsIsCloseSentinelCode, isCloseSentinel, ASCIILiteral(), s_writableStreamInternalsIsCloseSentinelCodeLength) \
+ macro(writableStreamInternalsWritableStreamDefaultControllerClearAlgorithmsCode, writableStreamDefaultControllerClearAlgorithms, ASCIILiteral(), s_writableStreamInternalsWritableStreamDefaultControllerClearAlgorithmsCodeLength) \
+ macro(writableStreamInternalsWritableStreamDefaultControllerCloseCode, writableStreamDefaultControllerClose, ASCIILiteral(), s_writableStreamInternalsWritableStreamDefaultControllerCloseCodeLength) \
+ macro(writableStreamInternalsWritableStreamDefaultControllerErrorCode, writableStreamDefaultControllerError, ASCIILiteral(), s_writableStreamInternalsWritableStreamDefaultControllerErrorCodeLength) \
+ macro(writableStreamInternalsWritableStreamDefaultControllerErrorIfNeededCode, writableStreamDefaultControllerErrorIfNeeded, ASCIILiteral(), s_writableStreamInternalsWritableStreamDefaultControllerErrorIfNeededCodeLength) \
+ macro(writableStreamInternalsWritableStreamDefaultControllerGetBackpressureCode, writableStreamDefaultControllerGetBackpressure, ASCIILiteral(), s_writableStreamInternalsWritableStreamDefaultControllerGetBackpressureCodeLength) \
+ macro(writableStreamInternalsWritableStreamDefaultControllerGetChunkSizeCode, writableStreamDefaultControllerGetChunkSize, ASCIILiteral(), s_writableStreamInternalsWritableStreamDefaultControllerGetChunkSizeCodeLength) \
+ macro(writableStreamInternalsWritableStreamDefaultControllerGetDesiredSizeCode, writableStreamDefaultControllerGetDesiredSize, ASCIILiteral(), s_writableStreamInternalsWritableStreamDefaultControllerGetDesiredSizeCodeLength) \
+ macro(writableStreamInternalsWritableStreamDefaultControllerProcessCloseCode, writableStreamDefaultControllerProcessClose, ASCIILiteral(), s_writableStreamInternalsWritableStreamDefaultControllerProcessCloseCodeLength) \
+ macro(writableStreamInternalsWritableStreamDefaultControllerProcessWriteCode, writableStreamDefaultControllerProcessWrite, ASCIILiteral(), s_writableStreamInternalsWritableStreamDefaultControllerProcessWriteCodeLength) \
+ macro(writableStreamInternalsWritableStreamDefaultControllerWriteCode, writableStreamDefaultControllerWrite, ASCIILiteral(), s_writableStreamInternalsWritableStreamDefaultControllerWriteCodeLength) \
+
+#define WEBCORE_FOREACH_WRITABLESTREAMINTERNALS_BUILTIN_FUNCTION_NAME(macro) \
+ macro(acquireWritableStreamDefaultWriter) \
+ macro(createInternalWritableStreamFromUnderlyingSink) \
+ macro(createWritableStream) \
+ macro(initializeWritableStreamSlots) \
+ macro(isCloseSentinel) \
+ macro(isWritableStream) \
+ macro(isWritableStreamDefaultWriter) \
+ macro(isWritableStreamLocked) \
+ macro(setUpWritableStreamDefaultController) \
+ macro(setUpWritableStreamDefaultControllerFromUnderlyingSink) \
+ macro(setUpWritableStreamDefaultWriter) \
+ macro(writableStreamAbort) \
+ macro(writableStreamAbortForBindings) \
+ macro(writableStreamAddWriteRequest) \
+ macro(writableStreamClose) \
+ macro(writableStreamCloseForBindings) \
+ macro(writableStreamCloseQueuedOrInFlight) \
+ macro(writableStreamDealWithRejection) \
+ macro(writableStreamDefaultControllerAdvanceQueueIfNeeded) \
+ macro(writableStreamDefaultControllerClearAlgorithms) \
+ macro(writableStreamDefaultControllerClose) \
+ macro(writableStreamDefaultControllerError) \
+ macro(writableStreamDefaultControllerErrorIfNeeded) \
+ macro(writableStreamDefaultControllerGetBackpressure) \
+ macro(writableStreamDefaultControllerGetChunkSize) \
+ macro(writableStreamDefaultControllerGetDesiredSize) \
+ macro(writableStreamDefaultControllerProcessClose) \
+ macro(writableStreamDefaultControllerProcessWrite) \
+ macro(writableStreamDefaultControllerStart) \
+ macro(writableStreamDefaultControllerWrite) \
+ macro(writableStreamDefaultWriterAbort) \
+ macro(writableStreamDefaultWriterClose) \
+ macro(writableStreamDefaultWriterCloseWithErrorPropagation) \
+ macro(writableStreamDefaultWriterEnsureClosedPromiseRejected) \
+ macro(writableStreamDefaultWriterEnsureReadyPromiseRejected) \
+ macro(writableStreamDefaultWriterGetDesiredSize) \
+ macro(writableStreamDefaultWriterRelease) \
+ macro(writableStreamDefaultWriterWrite) \
+ macro(writableStreamFinishErroring) \
+ macro(writableStreamFinishInFlightClose) \
+ macro(writableStreamFinishInFlightCloseWithError) \
+ macro(writableStreamFinishInFlightWrite) \
+ macro(writableStreamFinishInFlightWriteWithError) \
+ macro(writableStreamHasOperationMarkedInFlight) \
+ macro(writableStreamMarkCloseRequestInFlight) \
+ macro(writableStreamMarkFirstWriteRequestInFlight) \
+ macro(writableStreamRejectCloseAndClosedPromiseIfNeeded) \
+ macro(writableStreamStartErroring) \
+ macro(writableStreamUpdateBackpressure) \
+
+#define DECLARE_BUILTIN_GENERATOR(codeName, functionName, overriddenName, argumentCount) \
+ JSC::FunctionExecutable* codeName##Generator(JSC::VM&);
+
+WEBCORE_FOREACH_WRITABLESTREAMINTERNALS_BUILTIN_CODE(DECLARE_BUILTIN_GENERATOR)
+#undef DECLARE_BUILTIN_GENERATOR
+
+class WritableStreamInternalsBuiltinsWrapper : private JSC::WeakHandleOwner {
+public:
+ explicit WritableStreamInternalsBuiltinsWrapper(JSC::VM& vm)
+ : m_vm(vm)
+ WEBCORE_FOREACH_WRITABLESTREAMINTERNALS_BUILTIN_FUNCTION_NAME(INITIALIZE_BUILTIN_NAMES)
+#define INITIALIZE_BUILTIN_SOURCE_MEMBERS(name, functionName, overriddenName, length) , m_##name##Source(JSC::makeSource(StringImpl::createWithoutCopying(s_##name, length), { }))
+ WEBCORE_FOREACH_WRITABLESTREAMINTERNALS_BUILTIN_CODE(INITIALIZE_BUILTIN_SOURCE_MEMBERS)
+#undef INITIALIZE_BUILTIN_SOURCE_MEMBERS
+ {
+ }
+
+#define EXPOSE_BUILTIN_EXECUTABLES(name, functionName, overriddenName, length) \
+ JSC::UnlinkedFunctionExecutable* name##Executable(); \
+ const JSC::SourceCode& name##Source() const { return m_##name##Source; }
+ WEBCORE_FOREACH_WRITABLESTREAMINTERNALS_BUILTIN_CODE(EXPOSE_BUILTIN_EXECUTABLES)
+#undef EXPOSE_BUILTIN_EXECUTABLES
+
+ WEBCORE_FOREACH_WRITABLESTREAMINTERNALS_BUILTIN_FUNCTION_NAME(DECLARE_BUILTIN_IDENTIFIER_ACCESSOR)
+
+ void exportNames();
+
+private:
+ JSC::VM& m_vm;
+
+ WEBCORE_FOREACH_WRITABLESTREAMINTERNALS_BUILTIN_FUNCTION_NAME(DECLARE_BUILTIN_NAMES)
+
+#define DECLARE_BUILTIN_SOURCE_MEMBERS(name, functionName, overriddenName, length) \
+ JSC::SourceCode m_##name##Source;\
+ JSC::Weak<JSC::UnlinkedFunctionExecutable> m_##name##Executable;
+ WEBCORE_FOREACH_WRITABLESTREAMINTERNALS_BUILTIN_CODE(DECLARE_BUILTIN_SOURCE_MEMBERS)
+#undef DECLARE_BUILTIN_SOURCE_MEMBERS
+
+};
+
+#define DEFINE_BUILTIN_EXECUTABLES(name, functionName, overriddenName, length) \
+inline JSC::UnlinkedFunctionExecutable* WritableStreamInternalsBuiltinsWrapper::name##Executable() \
+{\
+ if (!m_##name##Executable) {\
+ JSC::Identifier executableName = functionName##PublicName();\
+ if (overriddenName)\
+ executableName = JSC::Identifier::fromString(m_vm, overriddenName);\
+ m_##name##Executable = JSC::Weak<JSC::UnlinkedFunctionExecutable>(JSC::createBuiltinExecutable(m_vm, m_##name##Source, executableName, s_##name##ConstructorKind, s_##name##ConstructAbility), this, &m_##name##Executable);\
+ }\
+ return m_##name##Executable.get();\
+}
+WEBCORE_FOREACH_WRITABLESTREAMINTERNALS_BUILTIN_CODE(DEFINE_BUILTIN_EXECUTABLES)
+#undef DEFINE_BUILTIN_EXECUTABLES
+
+inline void WritableStreamInternalsBuiltinsWrapper::exportNames()
+{
+#define EXPORT_FUNCTION_NAME(name) m_vm.propertyNames->appendExternalName(name##PublicName(), name##PrivateName());
+ WEBCORE_FOREACH_WRITABLESTREAMINTERNALS_BUILTIN_FUNCTION_NAME(EXPORT_FUNCTION_NAME)
+#undef EXPORT_FUNCTION_NAME
+}
+
+class WritableStreamInternalsBuiltinFunctions {
+public:
+ explicit WritableStreamInternalsBuiltinFunctions(JSC::VM& vm) : m_vm(vm) { }
+
+ void init(JSC::JSGlobalObject&);
+ template<typename Visitor> void visit(Visitor&);
+
+public:
+ JSC::VM& m_vm;
+
+#define DECLARE_BUILTIN_SOURCE_MEMBERS(functionName) \
+ JSC::WriteBarrier<JSC::JSFunction> m_##functionName##Function;
+ WEBCORE_FOREACH_WRITABLESTREAMINTERNALS_BUILTIN_FUNCTION_NAME(DECLARE_BUILTIN_SOURCE_MEMBERS)
+#undef DECLARE_BUILTIN_SOURCE_MEMBERS
+};
+
+inline void WritableStreamInternalsBuiltinFunctions::init(JSC::JSGlobalObject& globalObject)
+{
+#define EXPORT_FUNCTION(codeName, functionName, overriddenName, length)\
+ m_##functionName##Function.set(m_vm, &globalObject, JSC::JSFunction::create(m_vm, codeName##Generator(m_vm), &globalObject));
+ WEBCORE_FOREACH_WRITABLESTREAMINTERNALS_BUILTIN_CODE(EXPORT_FUNCTION)
+#undef EXPORT_FUNCTION
+}
+
+template<typename Visitor>
+inline void WritableStreamInternalsBuiltinFunctions::visit(Visitor& visitor)
+{
+#define VISIT_FUNCTION(name) visitor.append(m_##name##Function);
+ WEBCORE_FOREACH_WRITABLESTREAMINTERNALS_BUILTIN_FUNCTION_NAME(VISIT_FUNCTION)
+#undef VISIT_FUNCTION
+}
+
+template void WritableStreamInternalsBuiltinFunctions::visit(JSC::AbstractSlotVisitor&);
+template void WritableStreamInternalsBuiltinFunctions::visit(JSC::SlotVisitor&);
+
+
+
+} // namespace WebCore
diff --git a/src/bun.js/builtins/js/ByteLengthQueuingStrategy.js b/src/bun.js/builtins/js/ByteLengthQueuingStrategy.js
new file mode 100644
index 000000000..e8f5b1cfc
--- /dev/null
+++ b/src/bun.js/builtins/js/ByteLengthQueuingStrategy.js
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2015 Canon Inc.
+ * Copyright (C) 2015 Igalia S.L.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+@getter
+function highWaterMark()
+{
+ "use strict";
+
+ const highWaterMark = @getByIdDirectPrivate(this, "highWaterMark");
+ if (highWaterMark === @undefined)
+ @throwTypeError("ByteLengthQueuingStrategy.highWaterMark getter called on incompatible |this| value.");
+
+ return highWaterMark;
+}
+
+function size(chunk)
+{
+ "use strict";
+
+ return chunk.byteLength;
+}
+
+function initializeByteLengthQueuingStrategy(parameters)
+{
+ "use strict";
+
+ @putByIdDirectPrivate(this, "highWaterMark", @extractHighWaterMarkFromQueuingStrategyInit(parameters));
+}
diff --git a/src/bun.js/builtins/js/CountQueuingStrategy.js b/src/bun.js/builtins/js/CountQueuingStrategy.js
new file mode 100644
index 000000000..3cd9cffc2
--- /dev/null
+++ b/src/bun.js/builtins/js/CountQueuingStrategy.js
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 2015 Canon Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+@getter
+function highWaterMark()
+{
+ "use strict";
+
+ const highWaterMark = @getByIdDirectPrivate(this, "highWaterMark");
+ if (highWaterMark === @undefined)
+ @throwTypeError("CountQueuingStrategy.highWaterMark getter called on incompatible |this| value.");
+
+ return highWaterMark;
+}
+
+function size()
+{
+ "use strict";
+
+ return 1;
+}
+
+function initializeCountQueuingStrategy(parameters)
+{
+ "use strict";
+
+ @putByIdDirectPrivate(this, "highWaterMark", @extractHighWaterMarkFromQueuingStrategyInit(parameters));
+}
diff --git a/src/bun.js/builtins/js/JSBufferConstructor.js b/src/bun.js/builtins/js/JSBufferConstructor.js
new file mode 100644
index 000000000..9a3f0e1b7
--- /dev/null
+++ b/src/bun.js/builtins/js/JSBufferConstructor.js
@@ -0,0 +1,65 @@
+/*
+ * Copyright 2022 Codeblog Corp. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+// ^ that comment is required or the builtins generator will have a fit.
+
+
+function from(items) {
+ "use strict";
+
+ if (!@isConstructor(this))
+ @throwTypeError("Buffer.from requires |this| to be a constructor");
+
+
+ // TODO: figure out why private symbol not found
+ if (typeof items === 'string' || (typeof items === 'object' && items && (items instanceof ArrayBuffer || items instanceof SharedArrayBuffer))) {
+ switch (@argumentCount()) {
+ case 1: {
+ return new this(items);
+ }
+ case 2: {
+ return new this(items, @argument(1));
+ }
+ default: {
+ return new this(items, @argument(1), @argument(2));
+ }
+ }
+ }
+
+
+ var arrayLike = @toObject(items, "Buffer.from requires an array-like object - not null or undefined");
+
+ // Buffer-specific fast path:
+ // - uninitialized memory
+ // - use .set
+ if (@isTypedArrayView(arrayLike)) {
+ var length = @typedArrayLength(arrayLike);
+ var result = this.allocUnsafe(length);
+ result.set(arrayLike);
+ return result;
+ }
+
+ return @tailCallForwardArguments(@Uint8Array.from, this);
+}
diff --git a/src/bun.js/builtins/js/JSBufferPrototype.js b/src/bun.js/builtins/js/JSBufferPrototype.js
new file mode 100644
index 000000000..c841bcd6c
--- /dev/null
+++ b/src/bun.js/builtins/js/JSBufferPrototype.js
@@ -0,0 +1,303 @@
+/*
+ * Copyright 2022 Codeblog Corp. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+
+// ^ that comment is required or the builtins generator will have a fit.
+
+// The fastest way as of April 2022 is to use DataView.
+// DataView has intrinsics that cause inlining
+
+function setBigUint64(offset, value, le) {
+ "use strict";
+ return this.dataView.setBigUint64(offset, value, le);
+}
+function readInt8(offset) {
+ "use strict";
+ return this.dataView.getInt8(offset);
+}
+function readUInt8(offset) {
+ "use strict";
+ return this.dataView.getUint8(offset);
+}
+function readInt16LE(offset) {
+ "use strict";
+ return this.dataView.getInt16(offset, true);
+}
+function readInt16BE(offset) {
+ "use strict";
+ return this.dataView.getInt16(offset, false);
+}
+function readUInt16LE(offset) {
+ "use strict";
+ return this.dataView.getUint16(offset, true);
+}
+function readUInt16BE(offset) {
+ "use strict";
+ return this.dataView.getUint16(offset, false);
+}
+function readInt32LE(offset) {
+ "use strict";
+ return this.dataView.getInt32(offset, true);
+}
+function readInt32BE(offset) {
+ "use strict";
+ return this.dataView.getInt32(offset, false);
+}
+function readUInt32LE(offset) {
+ "use strict";
+ return this.dataView.getUint32(offset, true);
+}
+function readUInt32BE(offset) {
+ "use strict";
+ return this.dataView.getUint32(offset, false);
+}
+function readFloatLE(offset) {
+ "use strict";
+ return this.dataView.getFloat32(offset, true);
+}
+function readFloatBE(offset) {
+ "use strict";
+ return this.dataView.getFloat32(offset, false);
+}
+function readDoubleLE(offset) {
+ "use strict";
+ return this.dataView.getFloat64(offset, true);
+}
+function readDoubleBE(offset) {
+ "use strict";
+ return this.dataView.getFloat64(offset, false);
+}
+function readBigInt64LE(offset) {
+ "use strict";
+ return this.dataView.getBigInt64(offset, true);
+}
+function readBigInt64BE(offset) {
+ "use strict";
+ return this.dataView.getBigInt64(offset, false);
+}
+function readBigUInt64LE(offset) {
+ "use strict";
+ return this.dataView.getBigUint64(offset, true);
+}
+function readBigUInt64BE(offset) {
+ "use strict";
+ return this.dataView.getBigUint64(offset, false);
+}
+function writeInt8(value, offset) {
+ "use strict";
+ this.dataView.setInt8(offset, value);
+ return offset + 1;
+}
+function writeUInt8(value, offset) {
+ "use strict";
+ this.dataView.setUint8(offset, value);
+ return offset + 1;
+}
+function writeInt16LE(value, offset) {
+ "use strict";
+ this.dataView.setInt16(offset, value, true);
+ return offset + 2;
+}
+function writeInt16BE(value, offset) {
+ "use strict";
+ this.dataView.setInt16(offset, value, false);
+ return offset + 2;
+}
+function writeUInt16LE(value, offset) {
+ "use strict";
+ this.dataView.setUint16(offset, value, true);
+ return offset + 2;
+}
+function writeUInt16BE(value, offset) {
+ "use strict";
+ this.dataView.setUint16(offset, value, false);
+ return offset + 2;
+}
+function writeInt32LE(value, offset) {
+ "use strict";
+ this.dataView.setInt32(offset, value, true);
+ return offset + 4;
+}
+function writeInt32BE(value, offset) {
+ "use strict";
+ this.dataView.setInt32(offset, value, false);
+ return offset + 4;
+}
+function writeUInt32LE(value, offset) {
+ "use strict";
+ this.dataView.setUint32(offset, value, true);
+ return offset + 4;
+}
+function writeUInt32BE(value, offset) {
+ "use strict";
+ this.dataView.setUint32(offset, value, false);
+ return offset + 4;
+}
+
+function writeFloatLE(value, offset) {
+ "use strict";
+ this.dataView.setFloat32(offset, value, true);
+ return offset + 4;
+}
+
+function writeFloatBE(value, offset) {
+ "use strict";
+ this.dataView.setFloat32(offset, value, false);
+ return offset + 4;
+}
+
+function writeDoubleLE(value, offset) {
+ "use strict";
+ this.dataView.setFloat64(offset, value, true);
+ return offset + 8;
+}
+
+function writeDoubleBE(value, offset) {
+ "use strict";
+ this.dataView.setFloat64(offset, value, false);
+ return offset + 8;
+}
+
+function writeBigInt64LE(value, offset) {
+ "use strict";
+ this.dataView.setBigInt64(offset, value, true);
+ return offset + 8;
+}
+
+function writeBigInt64BE(value, offset) {
+ "use strict";
+ this.dataView.setBigInt64(offset, value, false);
+ return offset + 8;
+}
+
+function writeBigUInt64LE(value, offset) {
+ "use strict";
+ this.dataView.setBigUint64(offset, value, true);
+ return offset + 8;
+}
+
+function writeBigUInt64BE(value, offset) {
+ "use strict";
+ this.dataView.setBigUint64(offset, value, false);
+ return offset + 8;
+}
+
+function slice(start, end) {
+ "use strict";
+ if (start === undefined && end === undefined) {
+ return this;
+ }
+
+ Buffer[Symbol.species] ||= Buffer;
+
+ return new Buffer(this.buffer, this.byteOffset + (start || 0), (end || this.byteLength) - (start || 0));
+}
+
+function utf8Write(text, offset, length) {
+ "use strict";
+ return this.write(text, offset, length, "utf8");
+}
+function ucs2Write(text, offset, length) {
+ "use strict";
+ return this.write(text, offset, length, "ucs2");
+}
+function utf16leWrite(text, offset, length) {
+ "use strict";
+ return this.write(text, offset, length, "utf16le");
+}
+function latin1Write(text, offset, length) {
+ "use strict";
+ return this.write(text, offset, length, "latin1");
+}
+function asciiWrite(text, offset, length) {
+ "use strict";
+ return this.write(text, offset, length, "ascii");
+}
+function base64Write(text, offset, length) {
+ "use strict";
+ return this.write(text, offset, length, "base64");
+}
+function base64urlWrite(text, offset, length) {
+ "use strict";
+ return this.write(text, offset, length, "base64url");
+}
+function hexWrite(text, offset, length) {
+ "use strict";
+ return this.write(text, offset, length, "hex");
+}
+
+function utf8Slice(offset, length) {
+ "use strict";
+ return this.toString(offset, length, "utf8");
+}
+function ucs2Slice(offset, length) {
+ "use strict";
+ return this.toString(offset, length, "ucs2");
+}
+function utf16leSlice(offset, length) {
+ "use strict";
+ return this.toString(offset, length, "utf16le");
+}
+function latin1Slice(offset, length) {
+ "use strict";
+ return this.toString(offset, length, "latin1");
+}
+function asciiSlice(offset, length) {
+ "use strict";
+ return this.toString(offset, length, "ascii");
+}
+function base64Slice(offset, length) {
+ "use strict";
+ return this.toString(offset, length, "base64");
+}
+function base64urlSlice(offset, length) {
+ "use strict";
+ return this.toString(offset, length, "base64url");
+}
+function hexSlice(offset, length) {
+ "use strict";
+ return this.toString(offset, length, "hex");
+}
+
+function toJSON() {
+ "use strict";
+ const type = "Buffer";
+ const data = @Array.from(this);
+ return { type, data };
+}
+
+function subarray(start, end) {
+ "use strict";
+
+ Buffer[Symbol.species] ??= Buffer;
+ return new Buffer(this.buffer, this.byteOffset + (start || 0), (end || this.byteLength) - (start || 0));
+}
+
+
+function initializeBunBuffer(parameters)
+{
+ "use strict";
+
+}
diff --git a/src/bun.js/builtins/js/JSZigGlobalObject.js b/src/bun.js/builtins/js/JSZigGlobalObject.js
new file mode 100644
index 000000000..cb3446159
--- /dev/null
+++ b/src/bun.js/builtins/js/JSZigGlobalObject.js
@@ -0,0 +1,62 @@
+/*
+ * Copyright 2022 Codeblog Corp. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+function require(name) {
+ "use strict";
+ if (typeof name !== "string") {
+ @throwTypeError("require() expects a string as its argument");
+ }
+
+ const resolved = this.resolveSync(name, this.path);
+ var requireCache = (globalThis[Symbol.for("_requireCache")] ||= new @Map);
+ var cached = requireCache.@get(resolved);
+ if (cached) {
+ if (resolved.endsWith(".node")) {
+ return cached.exports;
+ }
+
+ return cached;
+ }
+
+ // TODO: remove this hardcoding
+ if (resolved.endsWith(".json")) {
+ var fs = (globalThis[Symbol.for("_fs")] ||= Bun.fs());
+ var exports = JSON.parse(fs.readFileSync(resolved, "utf8"));
+ requireCache.@set(resolved, exports);
+ return exports;
+ } else if (resolved.endsWith(".node")) {
+ var module = { exports: {} };
+ globalThis.process.dlopen(module, resolved);
+ requireCache.@set(resolved, module);
+ return module.exports;
+ } else if (resolved.endsWith(".toml")) {
+ var fs = (globalThis[Symbol.for("_fs")] ||= Bun.fs());
+ var exports = Bun.TOML.parse(fs.readFileSync(resolved, "utf8"));
+ requireCache.@set(resolved, exports);
+ return exports;
+ }
+
+ @throwTypeError(`Dynamic require isn't supported for file type: ${resolved.subsring(resolved.lastIndexOf(".") + 1) || resolved}`);
+}
diff --git a/src/bun.js/builtins/js/ReadableByteStreamController.js b/src/bun.js/builtins/js/ReadableByteStreamController.js
new file mode 100644
index 000000000..0b47d730c
--- /dev/null
+++ b/src/bun.js/builtins/js/ReadableByteStreamController.js
@@ -0,0 +1,117 @@
+/*
+ * Copyright (C) 2016 Canon Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+function initializeReadableByteStreamController(stream, underlyingByteSource, highWaterMark)
+{
+ "use strict";
+
+ if (arguments.length !== 4 && arguments[3] !== @isReadableStream)
+ @throwTypeError("ReadableByteStreamController constructor should not be called directly");
+
+ return @privateInitializeReadableByteStreamController.@call(this, stream, underlyingByteSource, highWaterMark);
+}
+
+function enqueue(chunk)
+{
+ "use strict";
+
+ if (!@isReadableByteStreamController(this))
+ throw @makeThisTypeError("ReadableByteStreamController", "enqueue");
+
+ if (@getByIdDirectPrivate(this, "closeRequested"))
+ @throwTypeError("ReadableByteStreamController is requested to close");
+
+ if (@getByIdDirectPrivate(@getByIdDirectPrivate(this, "controlledReadableStream"), "state") !== @streamReadable)
+ @throwTypeError("ReadableStream is not readable");
+
+ if (!@isObject(chunk) || !@ArrayBuffer.@isView(chunk))
+ @throwTypeError("Provided chunk is not a TypedArray");
+
+ return @readableByteStreamControllerEnqueue(this, chunk);
+}
+
+function error(error)
+{
+ "use strict";
+
+ if (!@isReadableByteStreamController(this))
+ throw @makeThisTypeError("ReadableByteStreamController", "error");
+
+ if (@getByIdDirectPrivate(@getByIdDirectPrivate(this, "controlledReadableStream"), "state") !== @streamReadable)
+ @throwTypeError("ReadableStream is not readable");
+
+ @readableByteStreamControllerError(this, error);
+}
+
+function close()
+{
+ "use strict";
+
+ if (!@isReadableByteStreamController(this))
+ throw @makeThisTypeError("ReadableByteStreamController", "close");
+
+ if (@getByIdDirectPrivate(this, "closeRequested"))
+ @throwTypeError("Close has already been requested");
+
+ if (@getByIdDirectPrivate(@getByIdDirectPrivate(this, "controlledReadableStream"), "state") !== @streamReadable)
+ @throwTypeError("ReadableStream is not readable");
+
+ @readableByteStreamControllerClose(this);
+}
+
+@getter
+function byobRequest()
+{
+ "use strict";
+
+ if (!@isReadableByteStreamController(this))
+ throw @makeGetterTypeError("ReadableByteStreamController", "byobRequest");
+
+
+ var request = @getByIdDirectPrivate(this, "byobRequest");
+ if (request === @undefined) {
+ var pending = @getByIdDirectPrivate(this, "pendingPullIntos");
+ const firstDescriptor = pending.peek();
+ if (firstDescriptor) {
+ const view = new @Uint8Array(firstDescriptor.buffer,
+ firstDescriptor.byteOffset + firstDescriptor.bytesFilled,
+ firstDescriptor.byteLength - firstDescriptor.bytesFilled);
+ @putByIdDirectPrivate(this, "byobRequest", new @ReadableStreamBYOBRequest(this, view, @isReadableStream));
+ }
+ }
+
+ return @getByIdDirectPrivate(this, "byobRequest");
+}
+
+@getter
+function desiredSize()
+{
+ "use strict";
+
+ if (!@isReadableByteStreamController(this))
+ throw @makeGetterTypeError("ReadableByteStreamController", "desiredSize");
+
+ return @readableByteStreamControllerGetDesiredSize(this);
+}
diff --git a/src/bun.js/builtins/js/ReadableByteStreamInternals.js b/src/bun.js/builtins/js/ReadableByteStreamInternals.js
new file mode 100644
index 000000000..01da62e1a
--- /dev/null
+++ b/src/bun.js/builtins/js/ReadableByteStreamInternals.js
@@ -0,0 +1,712 @@
+/*
+ * Copyright (C) 2016 Canon Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+// @internal
+
+function privateInitializeReadableByteStreamController(stream, underlyingByteSource, highWaterMark)
+{
+ "use strict";
+
+ if (!@isReadableStream(stream))
+ @throwTypeError("ReadableByteStreamController needs a ReadableStream");
+
+ // readableStreamController is initialized with null value.
+ if (@getByIdDirectPrivate(stream, "readableStreamController") !== null)
+ @throwTypeError("ReadableStream already has a controller");
+
+ @putByIdDirectPrivate(this, "controlledReadableStream", stream);
+ @putByIdDirectPrivate(this, "underlyingByteSource", underlyingByteSource);
+ @putByIdDirectPrivate(this, "pullAgain", false);
+ @putByIdDirectPrivate(this, "pulling", false);
+ @readableByteStreamControllerClearPendingPullIntos(this);
+ @putByIdDirectPrivate(this, "queue", @newQueue());
+ @putByIdDirectPrivate(this, "started", 0);
+ @putByIdDirectPrivate(this, "closeRequested", false);
+
+ let hwm = @toNumber(highWaterMark);
+ if (@isNaN(hwm) || hwm < 0)
+ @throwRangeError("highWaterMark value is negative or not a number");
+ @putByIdDirectPrivate(this, "strategyHWM", hwm);
+
+ let autoAllocateChunkSize = underlyingByteSource.autoAllocateChunkSize;
+ if (autoAllocateChunkSize !== @undefined) {
+ autoAllocateChunkSize = @toNumber(autoAllocateChunkSize);
+ if (autoAllocateChunkSize <= 0 || autoAllocateChunkSize === @Infinity || autoAllocateChunkSize === -@Infinity)
+ @throwRangeError("autoAllocateChunkSize value is negative or equal to positive or negative infinity");
+ }
+ @putByIdDirectPrivate(this, "autoAllocateChunkSize", autoAllocateChunkSize);
+ @putByIdDirectPrivate(this, "pendingPullIntos", @createFIFO());
+
+
+ const controller = this;
+ @promiseInvokeOrNoopNoCatch(@getByIdDirectPrivate(controller, "underlyingByteSource"), "start", [controller]).@then(() => {
+ @putByIdDirectPrivate(controller, "started", 1);
+ @assert(!@getByIdDirectPrivate(controller, "pulling"));
+ @assert(!@getByIdDirectPrivate(controller, "pullAgain"));
+ @readableByteStreamControllerCallPullIfNeeded(controller);
+ }, (error) => {
+ if (@getByIdDirectPrivate(stream, "state") === @streamReadable)
+ @readableByteStreamControllerError(controller, error);
+ });
+
+ @putByIdDirectPrivate(this, "cancel", @readableByteStreamControllerCancel);
+ @putByIdDirectPrivate(this, "pull", @readableByteStreamControllerPull);
+
+ return this;
+}
+
+function readableStreamByteStreamControllerStart(controller) {
+ "use strict";
+ @putByIdDirectPrivate(controller, "start", @undefined);
+
+}
+
+
+function privateInitializeReadableStreamBYOBRequest(controller, view)
+{
+ "use strict";
+
+ @putByIdDirectPrivate(this, "associatedReadableByteStreamController", controller);
+ @putByIdDirectPrivate(this, "view", view);
+}
+
+function isReadableByteStreamController(controller)
+{
+ "use strict";
+
+ // Same test mechanism as in isReadableStreamDefaultController (ReadableStreamInternals.js).
+ // See corresponding function for explanations.
+ return @isObject(controller) && !!@getByIdDirectPrivate(controller, "underlyingByteSource");
+}
+
+function isReadableStreamBYOBRequest(byobRequest)
+{
+ "use strict";
+
+ // Same test mechanism as in isReadableStreamDefaultController (ReadableStreamInternals.js).
+ // See corresponding function for explanations.
+ return @isObject(byobRequest) && !!@getByIdDirectPrivate(byobRequest, "associatedReadableByteStreamController");
+}
+
+function isReadableStreamBYOBReader(reader)
+{
+ "use strict";
+
+ // Spec tells to return true only if reader has a readIntoRequests internal slot.
+ // However, since it is a private slot, it cannot be checked using hasOwnProperty().
+ // Since readIntoRequests is initialized with an empty array, the following test is ok.
+ return @isObject(reader) && !!@getByIdDirectPrivate(reader, "readIntoRequests");
+}
+
+function readableByteStreamControllerCancel(controller, reason)
+{
+ "use strict";
+
+ var pendingPullIntos = @getByIdDirectPrivate(controller, "pendingPullIntos");
+ var first = pendingPullIntos.peek();
+ if (first)
+ first.bytesFilled = 0;
+
+ @putByIdDirectPrivate(controller, "queue", @newQueue());
+ return @promiseInvokeOrNoop(@getByIdDirectPrivate(controller, "underlyingByteSource"), "cancel", [reason]);
+}
+
+function readableByteStreamControllerError(controller, e)
+{
+ "use strict";
+
+ @assert(@getByIdDirectPrivate(@getByIdDirectPrivate(controller, "controlledReadableStream"), "state") === @streamReadable);
+ @readableByteStreamControllerClearPendingPullIntos(controller);
+ @putByIdDirectPrivate(controller, "queue", @newQueue());
+ @readableStreamError(@getByIdDirectPrivate(controller, "controlledReadableStream"), e);
+}
+
+function readableByteStreamControllerClose(controller)
+{
+ "use strict";
+
+ @assert(!@getByIdDirectPrivate(controller, "closeRequested"));
+ @assert(@getByIdDirectPrivate(@getByIdDirectPrivate(controller, "controlledReadableStream"), "state") === @streamReadable);
+
+ if (@getByIdDirectPrivate(controller, "queue").size > 0) {
+ @putByIdDirectPrivate(controller, "closeRequested", true);
+ return;
+ }
+
+ var first = @getByIdDirectPrivate(controller, "pendingPullIntos")?.peek();
+ if (first) {
+ if (first.bytesFilled > 0) {
+ const e = @makeTypeError("Close requested while there remain pending bytes");
+ @readableByteStreamControllerError(controller, e);
+ throw e;
+ }
+ }
+
+ @readableStreamClose(@getByIdDirectPrivate(controller, "controlledReadableStream"));
+}
+
+function readableByteStreamControllerClearPendingPullIntos(controller)
+{
+ "use strict";
+
+ @readableByteStreamControllerInvalidateBYOBRequest(controller);
+ var existing = @getByIdDirectPrivate(controller, "pendingPullIntos");
+ if (existing !== @undefined) {
+ existing.clear();
+ } else {
+ @putByIdDirectPrivate(controller, "pendingPullIntos", @createFIFO());
+ }
+}
+
+function readableByteStreamControllerGetDesiredSize(controller)
+{
+ "use strict";
+
+ const stream = @getByIdDirectPrivate(controller, "controlledReadableStream");
+ const state = @getByIdDirectPrivate(stream, "state");
+
+ if (state === @streamErrored)
+ return null;
+ if (state === @streamClosed)
+ return 0;
+
+ return @getByIdDirectPrivate(controller, "strategyHWM") - @getByIdDirectPrivate(controller, "queue").size;
+}
+
+function readableStreamHasBYOBReader(stream)
+{
+ "use strict";
+
+ const reader = @getByIdDirectPrivate(stream, "reader");
+ return reader !== @undefined && @isReadableStreamBYOBReader(reader);
+}
+
+function readableStreamHasDefaultReader(stream)
+{
+ "use strict";
+
+ const reader = @getByIdDirectPrivate(stream, "reader");
+ return reader !== @undefined && @isReadableStreamDefaultReader(reader);
+}
+
+function readableByteStreamControllerHandleQueueDrain(controller) {
+
+ "use strict";
+
+ @assert(@getByIdDirectPrivate(@getByIdDirectPrivate(controller, "controlledReadableStream"), "state") === @streamReadable);
+ if (!@getByIdDirectPrivate(controller, "queue").size && @getByIdDirectPrivate(controller, "closeRequested"))
+ @readableStreamClose(@getByIdDirectPrivate(controller, "controlledReadableStream"));
+ else
+ @readableByteStreamControllerCallPullIfNeeded(controller);
+}
+
+function readableByteStreamControllerPull(controller)
+{
+ "use strict";
+
+ const stream = @getByIdDirectPrivate(controller, "controlledReadableStream");
+ @assert(@readableStreamHasDefaultReader(stream));
+ if (@getByIdDirectPrivate(controller, "queue").content?.isNotEmpty()) {
+ const entry = @getByIdDirectPrivate(controller, "queue").content.shift();
+ @getByIdDirectPrivate(controller, "queue").size -= entry.byteLength;
+ @readableByteStreamControllerHandleQueueDrain(controller);
+ let view;
+ try {
+ view = new @Uint8Array(entry.buffer, entry.byteOffset, entry.byteLength);
+ } catch (error) {
+ return @Promise.@reject(error);
+ }
+ return @createFulfilledPromise({ value: view, done: false });
+ }
+
+ if (@getByIdDirectPrivate(controller, "autoAllocateChunkSize") !== @undefined) {
+ let buffer;
+ try {
+ buffer = @createUninitializedArrayBuffer(@getByIdDirectPrivate(controller, "autoAllocateChunkSize"));
+ } catch (error) {
+ return @Promise.@reject(error);
+ }
+ const pullIntoDescriptor = {
+ buffer,
+ byteOffset: 0,
+ byteLength: @getByIdDirectPrivate(controller, "autoAllocateChunkSize"),
+ bytesFilled: 0,
+ elementSize: 1,
+ ctor: @Uint8Array,
+ readerType: 'default'
+ };
+ @getByIdDirectPrivate(controller, "pendingPullIntos").push(pullIntoDescriptor);
+ }
+
+ const promise = @readableStreamAddReadRequest(stream);
+ @readableByteStreamControllerCallPullIfNeeded(controller);
+ return promise;
+}
+
+function readableByteStreamControllerShouldCallPull(controller)
+{
+ "use strict";
+
+ const stream = @getByIdDirectPrivate(controller, "controlledReadableStream");
+
+ if (@getByIdDirectPrivate(stream, "state") !== @streamReadable)
+ return false;
+ if (@getByIdDirectPrivate(controller, "closeRequested"))
+ return false;
+ if (!(@getByIdDirectPrivate(controller, "started") > 0))
+ return false;
+ const reader = @getByIdDirectPrivate(stream, "reader");
+
+ if (reader && (@getByIdDirectPrivate(reader, "readRequests")?.isNotEmpty() || !!@getByIdDirectPrivate(reader, "bunNativePtr")))
+ return true;
+ if (@readableStreamHasBYOBReader(stream) && @getByIdDirectPrivate(@getByIdDirectPrivate(stream, "reader"), "readIntoRequests")?.isNotEmpty())
+ return true;
+ if (@readableByteStreamControllerGetDesiredSize(controller) > 0)
+ return true;
+ return false;
+}
+
+function readableByteStreamControllerCallPullIfNeeded(controller)
+{
+ "use strict";
+
+ if (!@readableByteStreamControllerShouldCallPull(controller))
+ return;
+
+ if (@getByIdDirectPrivate(controller, "pulling")) {
+ @putByIdDirectPrivate(controller, "pullAgain", true);
+ return;
+ }
+
+ @assert(!@getByIdDirectPrivate(controller, "pullAgain"));
+ @putByIdDirectPrivate(controller, "pulling", true);
+ @promiseInvokeOrNoop(@getByIdDirectPrivate(controller, "underlyingByteSource"), "pull", [controller]).@then(() => {
+ @putByIdDirectPrivate(controller, "pulling", false);
+ if (@getByIdDirectPrivate(controller, "pullAgain")) {
+ @putByIdDirectPrivate(controller, "pullAgain", false);
+ @readableByteStreamControllerCallPullIfNeeded(controller);
+ }
+ }, (error) => {
+ if (@getByIdDirectPrivate(@getByIdDirectPrivate(controller, "controlledReadableStream"), "state") === @streamReadable)
+ @readableByteStreamControllerError(controller, error);
+ });
+}
+
+function transferBufferToCurrentRealm(buffer)
+{
+ "use strict";
+
+ // FIXME: Determine what should be done here exactly (what is already existing in current
+ // codebase and what has to be added). According to spec, Transfer operation should be
+ // performed in order to transfer buffer to current realm. For the moment, simply return
+ // received buffer.
+ return buffer;
+}
+
+function readableStreamReaderKind(reader) {
+ "use strict";
+
+
+ if (!!@getByIdDirectPrivate(reader, "readRequests"))
+ return @getByIdDirectPrivate(reader, "bunNativePtr") ? 3 : 1;
+
+ if (!!@getByIdDirectPrivate(reader, "readIntoRequests"))
+ return 2;
+
+ return 0;
+}
+function readableByteStreamControllerEnqueue(controller, chunk)
+{
+ "use strict";
+
+ const stream = @getByIdDirectPrivate(controller, "controlledReadableStream");
+ @assert(!@getByIdDirectPrivate(controller, "closeRequested"));
+ @assert(@getByIdDirectPrivate(stream, "state") === @streamReadable);
+
+
+ switch (@getByIdDirectPrivate(stream, "reader") ? @readableStreamReaderKind(@getByIdDirectPrivate(stream, "reader")) : 0) {
+ /* default reader */
+ case 1: {
+ if (!@getByIdDirectPrivate(@getByIdDirectPrivate(stream, "reader"), "readRequests")?.isNotEmpty())
+ @readableByteStreamControllerEnqueueChunk(controller, @transferBufferToCurrentRealm(chunk.buffer), chunk.byteOffset, chunk.byteLength);
+ else {
+ @assert(!@getByIdDirectPrivate(controller, "queue").content.size());
+ const transferredView = chunk.constructor === @Uint8Array ? chunk : new @Uint8Array(chunk.buffer, chunk.byteOffset, chunk.byteLength);
+ @readableStreamFulfillReadRequest(stream, transferredView, false);
+ }
+ break;
+ }
+
+ /* BYOB */
+ case 2: {
+ @readableByteStreamControllerEnqueueChunk(controller, @transferBufferToCurrentRealm(chunk.buffer), chunk.byteOffset, chunk.byteLength);
+ @readableByteStreamControllerProcessPullDescriptors(controller);
+ break;
+ }
+
+ /* NativeReader */
+ case 3: {
+ // reader.@enqueueNative(@getByIdDirectPrivate(reader, "bunNativePtr"), chunk);
+
+ break;
+ }
+
+ default: {
+ @assert(!@isReadableStreamLocked(stream));
+ @readableByteStreamControllerEnqueueChunk(controller, @transferBufferToCurrentRealm(chunk.buffer), chunk.byteOffset, chunk.byteLength);
+ break;
+ }
+ }
+}
+
+// Spec name: readableByteStreamControllerEnqueueChunkToQueue.
+function readableByteStreamControllerEnqueueChunk(controller, buffer, byteOffset, byteLength)
+{
+ "use strict";
+
+ @getByIdDirectPrivate(controller, "queue").content.push({
+ buffer: buffer,
+ byteOffset: byteOffset,
+ byteLength: byteLength
+ });
+ @getByIdDirectPrivate(controller, "queue").size += byteLength;
+}
+
+function readableByteStreamControllerRespondWithNewView(controller, view)
+{
+ "use strict";
+
+ @assert(@getByIdDirectPrivate(controller, "pendingPullIntos").isNotEmpty());
+
+ let firstDescriptor = @getByIdDirectPrivate(controller, "pendingPullIntos").peek();
+
+ if (firstDescriptor.byteOffset + firstDescriptor.bytesFilled !== view.byteOffset)
+ @throwRangeError("Invalid value for view.byteOffset");
+
+ if (firstDescriptor.byteLength !== view.byteLength)
+ @throwRangeError("Invalid value for view.byteLength");
+
+ firstDescriptor.buffer = view.buffer;
+ @readableByteStreamControllerRespondInternal(controller, view.byteLength);
+}
+
+function readableByteStreamControllerRespond(controller, bytesWritten)
+{
+ "use strict";
+
+ bytesWritten = @toNumber(bytesWritten);
+
+ if (@isNaN(bytesWritten) || bytesWritten === @Infinity || bytesWritten < 0 )
+ @throwRangeError("bytesWritten has an incorrect value");
+
+ @assert(@getByIdDirectPrivate(controller, "pendingPullIntos").isNotEmpty());
+
+ @readableByteStreamControllerRespondInternal(controller, bytesWritten);
+}
+
+function readableByteStreamControllerRespondInternal(controller, bytesWritten)
+{
+ "use strict";
+
+ let firstDescriptor = @getByIdDirectPrivate(controller, "pendingPullIntos").peek();
+ let stream = @getByIdDirectPrivate(controller, "controlledReadableStream");
+
+ if (@getByIdDirectPrivate(stream, "state") === @streamClosed) {
+ if (bytesWritten !== 0)
+ @throwTypeError("bytesWritten is different from 0 even though stream is closed");
+ @readableByteStreamControllerRespondInClosedState(controller, firstDescriptor);
+ } else {
+ @assert(@getByIdDirectPrivate(stream, "state") === @streamReadable);
+ @readableByteStreamControllerRespondInReadableState(controller, bytesWritten, firstDescriptor);
+ }
+}
+
+function readableByteStreamControllerRespondInReadableState(controller, bytesWritten, pullIntoDescriptor)
+{
+ "use strict";
+
+ if (pullIntoDescriptor.bytesFilled + bytesWritten > pullIntoDescriptor.byteLength)
+ @throwRangeError("bytesWritten value is too great");
+
+ @assert(@getByIdDirectPrivate(controller, "pendingPullIntos").isEmpty() || @getByIdDirectPrivate(controller, "pendingPullIntos").peek() === pullIntoDescriptor);
+ @readableByteStreamControllerInvalidateBYOBRequest(controller);
+ pullIntoDescriptor.bytesFilled += bytesWritten;
+
+ if (pullIntoDescriptor.bytesFilled < pullIntoDescriptor.elementSize)
+ return;
+
+ @readableByteStreamControllerShiftPendingDescriptor(controller);
+ const remainderSize = pullIntoDescriptor.bytesFilled % pullIntoDescriptor.elementSize;
+
+ if (remainderSize > 0) {
+ const end = pullIntoDescriptor.byteOffset + pullIntoDescriptor.bytesFilled;
+ const remainder = @cloneArrayBuffer(pullIntoDescriptor.buffer, end - remainderSize, remainderSize);
+ @readableByteStreamControllerEnqueueChunk(controller, remainder, 0, remainder.byteLength);
+ }
+
+ pullIntoDescriptor.buffer = @transferBufferToCurrentRealm(pullIntoDescriptor.buffer);
+ pullIntoDescriptor.bytesFilled -= remainderSize;
+ @readableByteStreamControllerCommitDescriptor(@getByIdDirectPrivate(controller, "controlledReadableStream"), pullIntoDescriptor);
+ @readableByteStreamControllerProcessPullDescriptors(controller);
+}
+
+function readableByteStreamControllerRespondInClosedState(controller, firstDescriptor)
+{
+ "use strict";
+
+ firstDescriptor.buffer = @transferBufferToCurrentRealm(firstDescriptor.buffer);
+ @assert(firstDescriptor.bytesFilled === 0);
+
+ if (@readableStreamHasBYOBReader(@getByIdDirectPrivate(controller, "controlledReadableStream"))) {
+ while (@getByIdDirectPrivate(@getByIdDirectPrivate(@getByIdDirectPrivate(controller, "controlledReadableStream"), "reader"), "readIntoRequests")?.isNotEmpty()) {
+ let pullIntoDescriptor = @readableByteStreamControllerShiftPendingDescriptor(controller);
+ @readableByteStreamControllerCommitDescriptor(@getByIdDirectPrivate(controller, "controlledReadableStream"), pullIntoDescriptor);
+ }
+ }
+}
+
+// Spec name: readableByteStreamControllerProcessPullIntoDescriptorsUsingQueue (shortened for readability).
+function readableByteStreamControllerProcessPullDescriptors(controller)
+{
+ "use strict";
+
+ @assert(!@getByIdDirectPrivate(controller, "closeRequested"));
+ while (@getByIdDirectPrivate(controller, "pendingPullIntos").isNotEmpty()) {
+ if (@getByIdDirectPrivate(controller, "queue").size === 0)
+ return;
+ let pullIntoDescriptor = @getByIdDirectPrivate(controller, "pendingPullIntos").peek();
+ if (@readableByteStreamControllerFillDescriptorFromQueue(controller, pullIntoDescriptor)) {
+ @readableByteStreamControllerShiftPendingDescriptor(controller);
+ @readableByteStreamControllerCommitDescriptor(@getByIdDirectPrivate(controller, "controlledReadableStream"), pullIntoDescriptor);
+ }
+ }
+}
+
+// Spec name: readableByteStreamControllerFillPullIntoDescriptorFromQueue (shortened for readability).
+function readableByteStreamControllerFillDescriptorFromQueue(controller, pullIntoDescriptor)
+{
+ "use strict";
+
+ const currentAlignedBytes = pullIntoDescriptor.bytesFilled - (pullIntoDescriptor.bytesFilled % pullIntoDescriptor.elementSize);
+ const maxBytesToCopy = @getByIdDirectPrivate(controller, "queue").size < pullIntoDescriptor.byteLength - pullIntoDescriptor.bytesFilled ?
+ @getByIdDirectPrivate(controller, "queue").size : pullIntoDescriptor.byteLength - pullIntoDescriptor.bytesFilled;
+ const maxBytesFilled = pullIntoDescriptor.bytesFilled + maxBytesToCopy;
+ const maxAlignedBytes = maxBytesFilled - (maxBytesFilled % pullIntoDescriptor.elementSize);
+ let totalBytesToCopyRemaining = maxBytesToCopy;
+ let ready = false;
+
+ if (maxAlignedBytes > currentAlignedBytes) {
+ totalBytesToCopyRemaining = maxAlignedBytes - pullIntoDescriptor.bytesFilled;
+ ready = true;
+ }
+
+ while (totalBytesToCopyRemaining > 0) {
+ let headOfQueue = @getByIdDirectPrivate(controller, "queue").content.peek();
+ const bytesToCopy = totalBytesToCopyRemaining < headOfQueue.byteLength ? totalBytesToCopyRemaining : headOfQueue.byteLength;
+ // Copy appropriate part of pullIntoDescriptor.buffer to headOfQueue.buffer.
+ // Remark: this implementation is not completely aligned on the definition of CopyDataBlockBytes
+ // operation of ECMAScript (the case of Shared Data Block is not considered here, but it doesn't seem to be an issue).
+ const destStart = pullIntoDescriptor.byteOffset + pullIntoDescriptor.bytesFilled;
+ // FIXME: As indicated in comments of bug 172717, access to set is not safe. However, using prototype.@set.@call does
+ // not work (@set is undefined). A safe way to do that is needed.
+ new @Uint8Array(pullIntoDescriptor.buffer).set(new @Uint8Array(headOfQueue.buffer, headOfQueue.byteOffset, bytesToCopy), destStart);
+
+ if (headOfQueue.byteLength === bytesToCopy)
+ @getByIdDirectPrivate(controller, "queue").content.shift();
+ else {
+ headOfQueue.byteOffset += bytesToCopy;
+ headOfQueue.byteLength -= bytesToCopy;
+ }
+
+ @getByIdDirectPrivate(controller, "queue").size -= bytesToCopy;
+ @assert(@getByIdDirectPrivate(controller, "pendingPullIntos").isEmpty() || @getByIdDirectPrivate(controller, "pendingPullIntos").peek() === pullIntoDescriptor);
+ @readableByteStreamControllerInvalidateBYOBRequest(controller);
+ pullIntoDescriptor.bytesFilled += bytesToCopy;
+ totalBytesToCopyRemaining -= bytesToCopy;
+ }
+
+ if (!ready) {
+ @assert(@getByIdDirectPrivate(controller, "queue").size === 0);
+ @assert(pullIntoDescriptor.bytesFilled > 0);
+ @assert(pullIntoDescriptor.bytesFilled < pullIntoDescriptor.elementSize);
+ }
+
+ return ready;
+}
+
+// Spec name: readableByteStreamControllerShiftPendingPullInto (renamed for consistency).
+function readableByteStreamControllerShiftPendingDescriptor(controller)
+{
+ "use strict";
+
+ let descriptor = @getByIdDirectPrivate(controller, "pendingPullIntos").shift();
+ @readableByteStreamControllerInvalidateBYOBRequest(controller);
+ return descriptor;
+}
+
+function readableByteStreamControllerInvalidateBYOBRequest(controller)
+{
+ "use strict";
+
+ if (@getByIdDirectPrivate(controller, "byobRequest") === @undefined)
+ return;
+ const byobRequest = @getByIdDirectPrivate(controller, "byobRequest");
+ @putByIdDirectPrivate(byobRequest, "associatedReadableByteStreamController", @undefined);
+ @putByIdDirectPrivate(byobRequest, "view", @undefined);
+ @putByIdDirectPrivate(controller, "byobRequest", @undefined);
+}
+
+// Spec name: readableByteStreamControllerCommitPullIntoDescriptor (shortened for readability).
+function readableByteStreamControllerCommitDescriptor(stream, pullIntoDescriptor)
+{
+ "use strict";
+
+ @assert(@getByIdDirectPrivate(stream, "state") !== @streamErrored);
+ let done = false;
+ if (@getByIdDirectPrivate(stream, "state") === @streamClosed) {
+ @assert(!pullIntoDescriptor.bytesFilled);
+ done = true;
+ }
+ let filledView = @readableByteStreamControllerConvertDescriptor(pullIntoDescriptor);
+ if (pullIntoDescriptor.readerType === "default")
+ @readableStreamFulfillReadRequest(stream, filledView, done);
+ else {
+ @assert(pullIntoDescriptor.readerType === "byob");
+ @readableStreamFulfillReadIntoRequest(stream, filledView, done);
+ }
+}
+
+// Spec name: readableByteStreamControllerConvertPullIntoDescriptor (shortened for readability).
+function readableByteStreamControllerConvertDescriptor(pullIntoDescriptor)
+{
+ "use strict";
+
+ @assert(pullIntoDescriptor.bytesFilled <= pullIntoDescriptor.byteLength);
+ @assert(pullIntoDescriptor.bytesFilled % pullIntoDescriptor.elementSize === 0);
+
+ return new pullIntoDescriptor.ctor(pullIntoDescriptor.buffer, pullIntoDescriptor.byteOffset, pullIntoDescriptor.bytesFilled / pullIntoDescriptor.elementSize);
+}
+
+function readableStreamFulfillReadIntoRequest(stream, chunk, done)
+{
+ "use strict";
+ const readIntoRequest = @getByIdDirectPrivate(@getByIdDirectPrivate(stream, "reader"), "readIntoRequests").shift();
+ @fulfillPromise(readIntoRequest, { value: chunk, done: done });
+}
+
+function readableStreamBYOBReaderRead(reader, view)
+{
+ "use strict";
+
+ const stream = @getByIdDirectPrivate(reader, "ownerReadableStream");
+ @assert(!!stream);
+
+ @putByIdDirectPrivate(stream, "disturbed", true);
+ if (@getByIdDirectPrivate(stream, "state") === @streamErrored)
+ return @Promise.@reject(@getByIdDirectPrivate(stream, "storedError"));
+
+ return @readableByteStreamControllerPullInto(@getByIdDirectPrivate(stream, "readableStreamController"), view);
+}
+
+function readableByteStreamControllerPullInto(controller, view)
+{
+ "use strict";
+
+ const stream = @getByIdDirectPrivate(controller, "controlledReadableStream");
+ let elementSize = 1;
+ // Spec describes that in the case where view is a TypedArray, elementSize
+ // should be set to the size of an element (e.g. 2 for UInt16Array). For
+ // DataView, BYTES_PER_ELEMENT is undefined, contrary to the same property
+ // for TypedArrays.
+ // FIXME: Getting BYTES_PER_ELEMENT like this is not safe (property is read-only
+ // but can be modified if the prototype is redefined). A safe way of getting
+ // it would be to determine which type of ArrayBufferView view is an instance
+ // of based on typed arrays private variables. However, this is not possible due
+ // to bug 167697, which prevents access to typed arrays through their private
+ // names unless public name has already been met before.
+ if (view.BYTES_PER_ELEMENT !== @undefined)
+ elementSize = view.BYTES_PER_ELEMENT;
+
+ // FIXME: Getting constructor like this is not safe. A safe way of getting
+ // it would be to determine which type of ArrayBufferView view is an instance
+ // of, and to assign appropriate constructor based on this (e.g. ctor =
+ // @Uint8Array). However, this is not possible due to bug 167697, which
+ // prevents access to typed arrays through their private names unless public
+ // name has already been met before.
+ const ctor = view.constructor;
+
+ const pullIntoDescriptor = {
+ buffer: view.buffer,
+ byteOffset: view.byteOffset,
+ byteLength: view.byteLength,
+ bytesFilled: 0,
+ elementSize,
+ ctor,
+ readerType: 'byob'
+ };
+
+ var pending = @getByIdDirectPrivate(controller, "pendingPullIntos");
+ if (pending?.isNotEmpty()) {
+ pullIntoDescriptor.buffer = @transferBufferToCurrentRealm(pullIntoDescriptor.buffer);
+ pending.push(pullIntoDescriptor);
+ return @readableStreamAddReadIntoRequest(stream);
+ }
+
+ if (@getByIdDirectPrivate(stream, "state") === @streamClosed) {
+ const emptyView = new ctor(pullIntoDescriptor.buffer, pullIntoDescriptor.byteOffset, 0);
+ return @createFulfilledPromise({ value: emptyView, done: true });
+ }
+
+ if (@getByIdDirectPrivate(controller, "queue").size > 0) {
+ if (@readableByteStreamControllerFillDescriptorFromQueue(controller, pullIntoDescriptor)) {
+ const filledView = @readableByteStreamControllerConvertDescriptor(pullIntoDescriptor);
+ @readableByteStreamControllerHandleQueueDrain(controller);
+ return @createFulfilledPromise({ value: filledView, done: false });
+ }
+ if (@getByIdDirectPrivate(controller, "closeRequested")) {
+ const e = @makeTypeError("Closing stream has been requested");
+ @readableByteStreamControllerError(controller, e);
+ return @Promise.@reject(e);
+ }
+ }
+
+ pullIntoDescriptor.buffer = @transferBufferToCurrentRealm(pullIntoDescriptor.buffer);
+ @getByIdDirectPrivate(controller, "pendingPullIntos").push(pullIntoDescriptor);
+ const promise = @readableStreamAddReadIntoRequest(stream);
+ @readableByteStreamControllerCallPullIfNeeded(controller);
+ return promise;
+}
+
+function readableStreamAddReadIntoRequest(stream)
+{
+ "use strict";
+
+ @assert(@isReadableStreamBYOBReader(@getByIdDirectPrivate(stream, "reader")));
+ @assert(@getByIdDirectPrivate(stream, "state") === @streamReadable || @getByIdDirectPrivate(stream, "state") === @streamClosed);
+
+ const readRequest = @newPromise();
+ @getByIdDirectPrivate(@getByIdDirectPrivate(stream, "reader"), "readIntoRequests").push(readRequest);
+
+ return readRequest;
+}
diff --git a/src/bun.js/builtins/js/ReadableStream.js b/src/bun.js/builtins/js/ReadableStream.js
new file mode 100644
index 000000000..db7cf85a8
--- /dev/null
+++ b/src/bun.js/builtins/js/ReadableStream.js
@@ -0,0 +1,506 @@
+/*
+ * Copyright (C) 2015 Canon Inc.
+ * Copyright (C) 2015 Igalia.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+function initializeReadableStream(underlyingSource, strategy)
+{
+ "use strict";
+
+ if (underlyingSource === @undefined)
+ underlyingSource = { @bunNativeType: 0, @bunNativePtr: 0, @lazy: false };
+ if (strategy === @undefined)
+ strategy = { };
+
+ if (!@isObject(underlyingSource))
+ @throwTypeError("ReadableStream constructor takes an object as first argument");
+
+ if (strategy !== @undefined && !@isObject(strategy))
+ @throwTypeError("ReadableStream constructor takes an object as second argument, if any");
+
+ @putByIdDirectPrivate(this, "state", @streamReadable);
+
+ @putByIdDirectPrivate(this, "reader", @undefined);
+
+ @putByIdDirectPrivate(this, "storedError", @undefined);
+
+ @putByIdDirectPrivate(this, "disturbed", false);
+
+ // Initialized with null value to enable distinction with undefined case.
+ @putByIdDirectPrivate(this, "readableStreamController", null);
+ @putByIdDirectPrivate(this, "bunNativeType", @getByIdDirectPrivate(underlyingSource, "bunNativeType") ?? 0);
+ @putByIdDirectPrivate(this, "bunNativePtr", @getByIdDirectPrivate(underlyingSource, "bunNativePtr") ?? 0);
+
+ const isDirect = underlyingSource.type === "direct";
+ // direct streams are always lazy
+ const isUnderlyingSourceLazy = !!underlyingSource.@lazy;
+ const isLazy = isDirect || isUnderlyingSourceLazy;
+
+ // // FIXME: We should introduce https://streams.spec.whatwg.org/#create-readable-stream.
+ // // For now, we emulate this with underlyingSource with private properties.
+ if (@getByIdDirectPrivate(underlyingSource, "pull") !== @undefined && !isLazy) {
+ const size = @getByIdDirectPrivate(strategy, "size");
+ const highWaterMark = @getByIdDirectPrivate(strategy, "highWaterMark");
+ @setupReadableStreamDefaultController(this, underlyingSource, size, highWaterMark !== @undefined ? highWaterMark : 1, @getByIdDirectPrivate(underlyingSource, "start"), @getByIdDirectPrivate(underlyingSource, "pull"), @getByIdDirectPrivate(underlyingSource, "cancel"));
+
+ return this;
+ }
+ if (isDirect) {
+ @putByIdDirectPrivate(this, "start", () => @createReadableStreamController(this, underlyingSource, strategy));
+ } else if (isLazy) {
+ const autoAllocateChunkSize = underlyingSource.autoAllocateChunkSize;
+
+
+ @putByIdDirectPrivate(this, "start", () => {
+ const instance = @lazyLoadStream(this, autoAllocateChunkSize);
+ if (instance) {
+ @createReadableStreamController(this, instance, strategy);
+ }
+ });
+ } else {
+ @putByIdDirectPrivate(this, "start", @undefined);
+ @createReadableStreamController(this, underlyingSource, strategy);
+ }
+
+
+ return this;
+}
+
+
+@globalPrivate
+function readableStreamToArray(stream) {
+ "use strict";
+
+ if (!stream || @getByIdDirectPrivate(stream, "state") === @streamClosed) {
+ return null;
+ }
+ var reader = stream.getReader();
+ var manyResult = reader.readMany();
+
+ async function processManyResult(result) {
+
+ if (result.done) {
+ return null;
+ }
+
+ var chunks = result.value || [];
+
+ while (true) {
+ var thisResult = await reader.read();
+
+ if (thisResult.done) {
+ return chunks;
+ }
+
+ chunks.push(thisResult.value);
+ }
+
+ return chunks;
+ };
+
+
+ if (manyResult && @isPromise(manyResult)) {
+ return manyResult.@then(processManyResult);
+ }
+
+ if (manyResult && manyResult.done) {
+ return null;
+ }
+
+ return processManyResult(manyResult);
+}
+
+@globalPrivate
+function readableStreamToText(stream) {
+ "use strict";
+
+ // TODO: optimize this to skip the extra ArrayBuffer
+ return globalThis.Bun.readableStreamToArrayBuffer(stream).@then(function(arrayBuffer) {
+ return new globalThis.TextDecoder().decode(arrayBuffer);
+ });
+}
+
+@globalPrivate
+function readableStreamToJSON(stream) {
+ "use strict";
+
+ // TODO: optimize this to skip the extra ArrayBuffer
+ return globalThis.Bun.readableStreamToArrayBuffer(stream).@then(function(arrayBuffer) {
+ return globalThis.JSON.parse(new globalThis.TextDecoder().decode(arrayBuffer));
+ });
+}
+
+@globalPrivate
+function readableStreamToBlob(stream) {
+ "use strict";
+
+
+ const array = @readableStreamToArray(stream);
+ if (array === null) {
+ return new globalThis.Blob();
+ }
+
+ return array.@then(function(chunks) {
+ if (chunks === null || chunks.length === 0) {
+ return new globalThis.Blob();
+ }
+
+ return new globalThis.Blob(chunks);
+ });
+}
+
+@globalPrivate
+function readableStreamToArrayPublic(stream) {
+ "use strict";
+
+ if (@getByIdDirectPrivate(stream, "state") === @streamClosed) {
+ return [];
+ }
+ var reader = stream.getReader();
+
+ var manyResult = reader.readMany();
+
+ var processManyResult = (0, (async function(result) {
+ if (result.done) {
+ return [];
+ }
+
+ var chunks = result.value || [];
+
+ while (true) {
+ var thisResult = await reader.read();
+ if (thisResult.done) {
+ return chunks;
+ }
+
+ chunks.push(thisResult.value);
+ }
+
+ return chunks;
+ }));
+
+
+ if (manyResult && @isPromise(manyResult)) {
+ return manyResult.then(processManyResult);
+ }
+
+ if (manyResult && manyResult.done) {
+ return [];
+ }
+
+ return processManyResult(manyResult);
+}
+
+
+
+@globalPrivate
+function consumeReadableStream(nativePtr, nativeType, inputStream) {
+ "use strict";
+ const symbol = globalThis.Symbol.for("Bun.consumeReadableStreamPrototype");
+ var cached = globalThis[symbol];
+ if (!cached) {
+ cached = globalThis[symbol] = [];
+ }
+ var Prototype = cached[nativeType];
+ if (Prototype === @undefined) {
+ var [doRead, doError, doReadMany, doClose, onClose, deinit] = globalThis[globalThis.Symbol.for("Bun.lazy")](nativeType);
+
+ Prototype = class NativeReadableStreamSink {
+ constructor(reader, ptr) {
+ this.#ptr = ptr;
+ this.#reader = reader;
+ this.#didClose = false;
+
+ this.handleError = this._handleError.bind(this);
+ this.handleClosed = this._handleClosed.bind(this);
+ this.processResult = this._processResult.bind(this);
+
+ reader.closed.then(this.handleClosed, this.handleError);
+ }
+
+ handleError;
+ handleClosed;
+ _handleClosed() {
+ if (this.#didClose) return;
+ this.#didClose = true;
+ var ptr = this.#ptr;
+ this.#ptr = 0;
+ doClose(ptr);
+ deinit(ptr);
+ }
+
+ _handleError(error) {
+ if (this.#didClose) return;
+ this.#didClose = true;
+ var ptr = this.#ptr;
+ this.#ptr = 0;
+ doError(ptr, error);
+ deinit(ptr);
+ }
+
+ #ptr;
+ #didClose = false;
+ #reader;
+
+ _handleReadMany({value, done, size}) {
+ if (done) {
+ this.handleClosed();
+ return;
+ }
+
+ if (this.#didClose) return;
+
+
+ doReadMany(this.#ptr, value, done, size);
+ }
+
+
+ read() {
+ if (!this.#ptr) return @throwTypeError("ReadableStreamSink is already closed");
+
+ return this.processResult(this.#reader.read());
+
+ }
+
+ _processResult(result) {
+ if (result && @isPromise(result)) {
+ const flags = @getPromiseInternalField(result, @promiseFieldFlags);
+ if (flags & @promiseStateFulfilled) {
+ const fulfilledValue = @getPromiseInternalField(result, @promiseFieldReactionsOrResult);
+ if (fulfilledValue) {
+ result = fulfilledValue;
+ }
+ }
+ }
+
+ if (result && @isPromise(result)) {
+ result.then(this.processResult, this.handleError);
+ return null;
+ }
+
+ if (result.done) {
+ this.handleClosed();
+ return 0;
+ } else if (result.value) {
+ return result.value;
+ } else {
+ return -1;
+ }
+ }
+
+ readMany() {
+ if (!this.#ptr) return @throwTypeError("ReadableStreamSink is already closed");
+ return this.processResult(this.#reader.readMany());
+ }
+
+
+ };
+
+ const minlength = nativeType + 1;
+ if (cached.length < minlength) {
+ cached.length = minlength;
+ }
+ @putByValDirect(cached, nativeType, Prototype);
+ }
+
+ if (@isReadableStreamLocked(inputStream)) {
+ @throwTypeError("Cannot start reading from a locked stream");
+ }
+
+ return new Prototype(inputStream.getReader(), nativePtr);
+}
+
+@globalPrivate
+function createEmptyReadableStream() {
+ "use strict";
+
+ var stream = new @ReadableStream({
+ pull() {},
+ });
+ @readableStreamClose(stream);
+ return stream;
+}
+
+@globalPrivate
+function createNativeReadableStream(nativePtr, nativeType, autoAllocateChunkSize) {
+ "use strict";
+ return new @ReadableStream({
+ @lazy: true,
+ @bunNativeType: nativeType,
+ @bunNativePtr: nativePtr,
+ autoAllocateChunkSize: autoAllocateChunkSize,
+ });
+}
+
+function cancel(reason)
+{
+ "use strict";
+
+ if (!@isReadableStream(this))
+ return @Promise.@reject(@makeThisTypeError("ReadableStream", "cancel"));
+
+ if (@isReadableStreamLocked(this))
+ return @Promise.@reject(@makeTypeError("ReadableStream is locked"));
+
+ return @readableStreamCancel(this, reason);
+}
+
+function getReader(options)
+{
+ "use strict";
+
+ if (!@isReadableStream(this))
+ throw @makeThisTypeError("ReadableStream", "getReader");
+
+ const mode = @toDictionary(options, { }, "ReadableStream.getReader takes an object as first argument").mode;
+ if (mode === @undefined) {
+ var start_ = @getByIdDirectPrivate(this, "start");
+ if (start_) {
+ @putByIdDirectPrivate(this, "start", @undefined);
+ start_();
+ }
+
+ return new @ReadableStreamDefaultReader(this);
+ }
+ // String conversion is required by spec, hence double equals.
+ if (mode == 'byob') {
+ return new @ReadableStreamBYOBReader(this);
+ }
+
+
+ @throwTypeError("Invalid mode is specified");
+}
+
+function pipeThrough(streams, options)
+{
+ "use strict";
+
+ const transforms = streams;
+
+ const readable = transforms["readable"];
+ if (!@isReadableStream(readable))
+ throw @makeTypeError("readable should be ReadableStream");
+
+ const writable = transforms["writable"];
+ const internalWritable = @getInternalWritableStream(writable);
+ if (!@isWritableStream(internalWritable))
+ throw @makeTypeError("writable should be WritableStream");
+
+ let preventClose = false;
+ let preventAbort = false;
+ let preventCancel = false;
+ let signal;
+ if (!@isUndefinedOrNull(options)) {
+ if (!@isObject(options))
+ throw @makeTypeError("options must be an object");
+
+ preventAbort = !!options["preventAbort"];
+ preventCancel = !!options["preventCancel"];
+ preventClose = !!options["preventClose"];
+
+ signal = options["signal"];
+ if (signal !== @undefined && !@isAbortSignal(signal))
+ throw @makeTypeError("options.signal must be AbortSignal");
+ }
+
+ if (!@isReadableStream(this))
+ throw @makeThisTypeError("ReadableStream", "pipeThrough");
+
+ if (@isReadableStreamLocked(this))
+ throw @makeTypeError("ReadableStream is locked");
+
+ if (@isWritableStreamLocked(internalWritable))
+ throw @makeTypeError("WritableStream is locked");
+
+ @readableStreamPipeToWritableStream(this, internalWritable, preventClose, preventAbort, preventCancel, signal);
+
+ return readable;
+}
+
+function pipeTo(destination)
+{
+ "use strict";
+
+ // FIXME: https://bugs.webkit.org/show_bug.cgi?id=159869.
+ // Built-in generator should be able to parse function signature to compute the function length correctly.
+ let options = arguments[1];
+
+ let preventClose = false;
+ let preventAbort = false;
+ let preventCancel = false;
+ let signal;
+ if (!@isUndefinedOrNull(options)) {
+ if (!@isObject(options))
+ return @Promise.@reject(@makeTypeError("options must be an object"));
+
+ try {
+ preventAbort = !!options["preventAbort"];
+ preventCancel = !!options["preventCancel"];
+ preventClose = !!options["preventClose"];
+
+ signal = options["signal"];
+ } catch(e) {
+ return @Promise.@reject(e);
+ }
+
+ if (signal !== @undefined && !@isAbortSignal(signal))
+ return @Promise.@reject(@makeTypeError("options.signal must be AbortSignal"));
+ }
+
+ const internalDestination = @getInternalWritableStream(destination);
+ if (!@isWritableStream(internalDestination))
+ return @Promise.@reject(@makeTypeError("ReadableStream pipeTo requires a WritableStream"));
+
+ if (!@isReadableStream(this))
+ return @Promise.@reject(@makeThisTypeError("ReadableStream", "pipeTo"));
+
+ if (@isReadableStreamLocked(this))
+ return @Promise.@reject(@makeTypeError("ReadableStream is locked"));
+
+ if (@isWritableStreamLocked(internalDestination))
+ return @Promise.@reject(@makeTypeError("WritableStream is locked"));
+
+ return @readableStreamPipeToWritableStream(this, internalDestination, preventClose, preventAbort, preventCancel, signal);
+}
+
+function tee()
+{
+ "use strict";
+
+ if (!@isReadableStream(this))
+ throw @makeThisTypeError("ReadableStream", "tee");
+
+ return @readableStreamTee(this, false);
+}
+
+@getter
+function locked()
+{
+ "use strict";
+
+ if (!@isReadableStream(this))
+ throw @makeGetterTypeError("ReadableStream", "locked");
+
+ return @isReadableStreamLocked(this);
+}
diff --git a/src/bun.js/builtins/js/ReadableStreamBYOBReader.js b/src/bun.js/builtins/js/ReadableStreamBYOBReader.js
new file mode 100644
index 000000000..16e4ebce5
--- /dev/null
+++ b/src/bun.js/builtins/js/ReadableStreamBYOBReader.js
@@ -0,0 +1,102 @@
+/*
+ * Copyright (C) 2017 Canon Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY CANON INC. AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL CANON INC. AND ITS CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+function initializeReadableStreamBYOBReader(stream)
+{
+ "use strict";
+
+ if (!@isReadableStream(stream))
+ @throwTypeError("ReadableStreamBYOBReader needs a ReadableStream");
+ if (!@isReadableByteStreamController(@getByIdDirectPrivate(stream, "readableStreamController")))
+ @throwTypeError("ReadableStreamBYOBReader needs a ReadableByteStreamController");
+ if (@isReadableStreamLocked(stream))
+ @throwTypeError("ReadableStream is locked");
+
+ @readableStreamReaderGenericInitialize(this, stream);
+ @putByIdDirectPrivate(this, "readIntoRequests", @createFIFO());
+
+ return this;
+}
+
+function cancel(reason)
+{
+ "use strict";
+
+ if (!@isReadableStreamBYOBReader(this))
+ return @Promise.@reject(@makeThisTypeError("ReadableStreamBYOBReader", "cancel"));
+
+ if (!@getByIdDirectPrivate(this, "ownerReadableStream"))
+ return @Promise.@reject(@makeTypeError("cancel() called on a reader owned by no readable stream"));
+
+ return @readableStreamReaderGenericCancel(this, reason);
+}
+
+function read(view)
+{
+ "use strict";
+
+ if (!@isReadableStreamBYOBReader(this))
+ return @Promise.@reject(@makeThisTypeError("ReadableStreamBYOBReader", "read"));
+
+ if (!@getByIdDirectPrivate(this, "ownerReadableStream"))
+ return @Promise.@reject(@makeTypeError("read() called on a reader owned by no readable stream"));
+
+ if (!@isObject(view))
+ return @Promise.@reject(@makeTypeError("Provided view is not an object"));
+
+ if (!@ArrayBuffer.@isView(view))
+ return @Promise.@reject(@makeTypeError("Provided view is not an ArrayBufferView"));
+
+ if (view.byteLength === 0)
+ return @Promise.@reject(@makeTypeError("Provided view cannot have a 0 byteLength"));
+
+ return @readableStreamBYOBReaderRead(this, view);
+}
+
+function releaseLock()
+{
+ "use strict";
+
+ if (!@isReadableStreamBYOBReader(this))
+ throw @makeThisTypeError("ReadableStreamBYOBReader", "releaseLock");
+
+ if (!@getByIdDirectPrivate(this, "ownerReadableStream"))
+ return;
+
+ if (@getByIdDirectPrivate(this, "readIntoRequests")?.isNotEmpty())
+ @throwTypeError("There are still pending read requests, cannot release the lock");
+
+ @readableStreamReaderGenericRelease(this);
+}
+
+@getter
+function closed()
+{
+ "use strict";
+
+ if (!@isReadableStreamBYOBReader(this))
+ return @Promise.@reject(@makeGetterTypeError("ReadableStreamBYOBReader", "closed"));
+
+ return @getByIdDirectPrivate(this, "closedPromiseCapability").@promise;
+}
diff --git a/src/bun.js/builtins/js/ReadableStreamBYOBRequest.js b/src/bun.js/builtins/js/ReadableStreamBYOBRequest.js
new file mode 100644
index 000000000..d97667165
--- /dev/null
+++ b/src/bun.js/builtins/js/ReadableStreamBYOBRequest.js
@@ -0,0 +1,77 @@
+/*
+ * Copyright (C) 2017 Canon Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+function initializeReadableStreamBYOBRequest(controller, view)
+{
+ "use strict";
+
+ if (arguments.length !== 3 && arguments[2] !== @isReadableStream)
+ @throwTypeError("ReadableStreamBYOBRequest constructor should not be called directly");
+
+ return @privateInitializeReadableStreamBYOBRequest.@call(this, controller, view);
+}
+
+function respond(bytesWritten)
+{
+ "use strict";
+
+ if (!@isReadableStreamBYOBRequest(this))
+ throw @makeThisTypeError("ReadableStreamBYOBRequest", "respond");
+
+ if (@getByIdDirectPrivate(this, "associatedReadableByteStreamController") === @undefined)
+ @throwTypeError("ReadableStreamBYOBRequest.associatedReadableByteStreamController is undefined");
+
+ return @readableByteStreamControllerRespond(@getByIdDirectPrivate(this, "associatedReadableByteStreamController"), bytesWritten);
+}
+
+function respondWithNewView(view)
+{
+ "use strict";
+
+ if (!@isReadableStreamBYOBRequest(this))
+ throw @makeThisTypeError("ReadableStreamBYOBRequest", "respond");
+
+ if (@getByIdDirectPrivate(this, "associatedReadableByteStreamController") === @undefined)
+ @throwTypeError("ReadableStreamBYOBRequest.associatedReadableByteStreamController is undefined");
+
+ if (!@isObject(view))
+ @throwTypeError("Provided view is not an object");
+
+ if (!@ArrayBuffer.@isView(view))
+ @throwTypeError("Provided view is not an ArrayBufferView");
+
+ return @readableByteStreamControllerRespondWithNewView(@getByIdDirectPrivate(this, "associatedReadableByteStreamController"), view);
+}
+
+@getter
+function view()
+{
+ "use strict";
+
+ if (!@isReadableStreamBYOBRequest(this))
+ throw @makeGetterTypeError("ReadableStreamBYOBRequest", "view");
+
+ return @getByIdDirectPrivate(this, "view");
+}
diff --git a/src/bun.js/builtins/js/ReadableStreamDefaultController.js b/src/bun.js/builtins/js/ReadableStreamDefaultController.js
new file mode 100644
index 000000000..07fc65cb1
--- /dev/null
+++ b/src/bun.js/builtins/js/ReadableStreamDefaultController.js
@@ -0,0 +1,82 @@
+/*
+ * Copyright (C) 2015 Canon Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+function initializeReadableStreamDefaultController(stream, underlyingSource, size, highWaterMark)
+{
+ "use strict";
+
+ if (arguments.length !== 5 && arguments[4] !== @isReadableStream)
+ @throwTypeError("ReadableStreamDefaultController constructor should not be called directly");
+
+ return @privateInitializeReadableStreamDefaultController.@call(this, stream, underlyingSource, size, highWaterMark);
+}
+
+function enqueue(chunk)
+{
+ "use strict";
+
+ if (!@isReadableStreamDefaultController(this))
+ throw @makeThisTypeError("ReadableStreamDefaultController", "enqueue");
+
+ if (!@readableStreamDefaultControllerCanCloseOrEnqueue(this))
+ @throwTypeError("ReadableStreamDefaultController is not in a state where chunk can be enqueued");
+
+ return @readableStreamDefaultControllerEnqueue(this, chunk);
+}
+
+function error(error)
+{
+ "use strict";
+
+ if (!@isReadableStreamDefaultController(this))
+ throw @makeThisTypeError("ReadableStreamDefaultController", "error");
+
+ @readableStreamDefaultControllerError(this, error);
+}
+
+function close()
+{
+ "use strict";
+
+ if (!@isReadableStreamDefaultController(this))
+ throw @makeThisTypeError("ReadableStreamDefaultController", "close");
+
+ if (!@readableStreamDefaultControllerCanCloseOrEnqueue(this))
+ @throwTypeError("ReadableStreamDefaultController is not in a state where it can be closed");
+
+ @readableStreamDefaultControllerClose(this);
+}
+
+@getter
+function desiredSize()
+{
+ "use strict";
+
+ if (!@isReadableStreamDefaultController(this))
+ throw @makeGetterTypeError("ReadableStreamDefaultController", "desiredSize");
+
+ return @readableStreamDefaultControllerGetDesiredSize(this);
+}
+
diff --git a/src/bun.js/builtins/js/ReadableStreamDefaultReader.js b/src/bun.js/builtins/js/ReadableStreamDefaultReader.js
new file mode 100644
index 000000000..774c7161e
--- /dev/null
+++ b/src/bun.js/builtins/js/ReadableStreamDefaultReader.js
@@ -0,0 +1,182 @@
+/*
+ * Copyright (C) 2015 Canon Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+function initializeReadableStreamDefaultReader(stream)
+{
+ "use strict";
+
+ if (!@isReadableStream(stream))
+ @throwTypeError("ReadableStreamDefaultReader needs a ReadableStream");
+ if (@isReadableStreamLocked(stream))
+ @throwTypeError("ReadableStream is locked");
+
+ @readableStreamReaderGenericInitialize(this, stream);
+ @putByIdDirectPrivate(this, "readRequests", @createFIFO());
+
+ return this;
+}
+
+function cancel(reason)
+{
+ "use strict";
+
+ if (!@isReadableStreamDefaultReader(this))
+ return @Promise.@reject(@makeThisTypeError("ReadableStreamDefaultReader", "cancel"));
+
+ if (!@getByIdDirectPrivate(this, "ownerReadableStream"))
+ return @Promise.@reject(@makeTypeError("cancel() called on a reader owned by no readable stream"));
+
+ return @readableStreamReaderGenericCancel(this, reason);
+}
+
+function readMany()
+{
+ "use strict";
+
+ if (!@isReadableStreamDefaultReader(this))
+ @throwTypeError("ReadableStreamDefaultReader.readMany() should not be called directly");
+
+ const stream = @getByIdDirectPrivate(this, "ownerReadableStream");
+ if (!stream)
+ @throwTypeError("readMany() called on a reader owned by no readable stream");
+
+ const state = @getByIdDirectPrivate(stream, "state");
+ @putByIdDirectPrivate(stream, "disturbed", true);
+ if (state === @streamClosed)
+ return {value: [], size: 0, done: true};
+ else if (state === @streamErrored) {
+ throw @getByIdDirectPrivate(stream, "storedError");
+ }
+
+
+ var controller = @getByIdDirectPrivate(stream, "readableStreamController");
+
+ const content = @getByIdDirectPrivate(controller, "queue").content;
+ var size = @getByIdDirectPrivate(controller, "queue").size;
+ var values = content.toArray(false);
+ var length = values.length;
+
+ if (length > 0) {
+
+ if (@isReadableByteStreamController(controller)) {
+ for (var i = 0; i < value.length; i++) {
+ const buf = value[i];
+ if (!(@ArrayBuffer.@isView(buf) || buf instanceof @ArrayBuffer)) {
+ value[i] = new @Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength);
+ }
+ }
+ }
+
+ @resetQueue(@getByIdDirectPrivate(controller, "queue"));
+
+ if (@getByIdDirectPrivate(controller, "closeRequested"))
+ @readableStreamClose(@getByIdDirectPrivate(controller, "controlledReadableStream"));
+ else if (@isReadableStreamDefaultController(controller))
+ @readableStreamDefaultControllerCallPullIfNeeded(controller);
+ else if (@isReadableByteStreamController(controller))
+ @readableByteStreamControllerCallPullIfNeeded(controller);
+
+ return {value: values, size, done: false};
+ }
+
+ var onPullMany = (result) => {
+ if (result.done) {
+ return {value: [], size: 0, done: true};
+ }
+ var controller = @getByIdDirectPrivate(stream, "readableStreamController");
+
+ var queue = @getByIdDirectPrivate(controller, "queue");
+ var value = [result.value].concat(queue.content.toArray(false));
+
+ if (@isReadableByteStreamController(controller)) {
+ for (var i = 0; i < value.length; i++) {
+ const buf = value[i];
+ if (!(@ArrayBuffer.@isView(buf) || buf instanceof @ArrayBuffer)) {
+ value[i] = new @Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength);
+ }
+ }
+ }
+
+ var size = queue.size;
+ @resetQueue(queue);
+
+ if (@getByIdDirectPrivate(controller, "closeRequested"))
+ @readableStreamClose(@getByIdDirectPrivate(controller, "controlledReadableStream"));
+ else if (@isReadableStreamDefaultController(controller))
+ @readableStreamDefaultControllerCallPullIfNeeded(controller);
+ else if (@isReadableByteStreamController(controller))
+ @readableByteStreamControllerCallPullIfNeeded(controller);
+
+
+
+ return {value: value, size: size, done: false};
+ };
+
+ var pullResult = controller.@pull(controller);
+ if (pullResult && @isPromise(pullResult)) {
+ return pullResult.@then(onPullMany);
+ }
+
+ return onPullMany(pullResult);
+}
+
+function read()
+{
+ "use strict";
+
+ if (!@isReadableStreamDefaultReader(this))
+ return @Promise.@reject(@makeThisTypeError("ReadableStreamDefaultReader", "read"));
+ if (!@getByIdDirectPrivate(this, "ownerReadableStream"))
+ return @Promise.@reject(@makeTypeError("read() called on a reader owned by no readable stream"));
+
+ return @readableStreamDefaultReaderRead(this);
+}
+
+function releaseLock()
+{
+ "use strict";
+
+ if (!@isReadableStreamDefaultReader(this))
+ throw @makeThisTypeError("ReadableStreamDefaultReader", "releaseLock");
+
+ if (!@getByIdDirectPrivate(this, "ownerReadableStream"))
+ return;
+
+ if (@getByIdDirectPrivate(this, "readRequests")?.isNotEmpty())
+ @throwTypeError("There are still pending read requests, cannot release the lock");
+
+ @readableStreamReaderGenericRelease(this);
+}
+
+@getter
+function closed()
+{
+ "use strict";
+
+ if (!@isReadableStreamDefaultReader(this))
+ return @Promise.@reject(@makeGetterTypeError("ReadableStreamDefaultReader", "closed"));
+
+ return @getByIdDirectPrivate(this, "closedPromiseCapability").@promise;
+}
diff --git a/src/bun.js/builtins/js/ReadableStreamInternals.js b/src/bun.js/builtins/js/ReadableStreamInternals.js
new file mode 100644
index 000000000..3e6590f31
--- /dev/null
+++ b/src/bun.js/builtins/js/ReadableStreamInternals.js
@@ -0,0 +1,1255 @@
+/*
+ * Copyright (C) 2015 Canon Inc. All rights reserved.
+ * Copyright (C) 2015 Igalia.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+// @internal
+
+function readableStreamReaderGenericInitialize(reader, stream)
+{
+ "use strict";
+
+ @putByIdDirectPrivate(reader, "ownerReadableStream", stream);
+ @putByIdDirectPrivate(stream, "reader", reader);
+ if (@getByIdDirectPrivate(stream, "state") === @streamReadable)
+ @putByIdDirectPrivate(reader, "closedPromiseCapability", @newPromiseCapability(@Promise));
+ else if (@getByIdDirectPrivate(stream, "state") === @streamClosed)
+ @putByIdDirectPrivate(reader, "closedPromiseCapability", { @promise: @Promise.@resolve() });
+ else {
+ @assert(@getByIdDirectPrivate(stream, "state") === @streamErrored);
+ @putByIdDirectPrivate(reader, "closedPromiseCapability", { @promise: @newHandledRejectedPromise(@getByIdDirectPrivate(stream, "storedError")) });
+ }
+}
+
+function privateInitializeReadableStreamDefaultController(stream, underlyingSource, size, highWaterMark)
+{
+ "use strict";
+
+ if (!@isReadableStream(stream))
+ @throwTypeError("ReadableStreamDefaultController needs a ReadableStream");
+
+ // readableStreamController is initialized with null value.
+ if (@getByIdDirectPrivate(stream, "readableStreamController") !== null)
+ @throwTypeError("ReadableStream already has a controller");
+
+
+
+ @putByIdDirectPrivate(this, "controlledReadableStream", stream);
+ @putByIdDirectPrivate(this, "underlyingSource", underlyingSource);
+ @putByIdDirectPrivate(this, "queue", @newQueue());
+ @putByIdDirectPrivate(this, "started", -1);
+ @putByIdDirectPrivate(this, "closeRequested", false);
+ @putByIdDirectPrivate(this, "pullAgain", false);
+ @putByIdDirectPrivate(this, "pulling", false);
+ @putByIdDirectPrivate(this, "strategy", @validateAndNormalizeQueuingStrategy(size, highWaterMark));
+
+ return this;
+}
+
+function readableStreamDefaultControllerError(controller, error)
+{
+ "use strict";
+
+ const stream = @getByIdDirectPrivate(controller, "controlledReadableStream");
+ if (@getByIdDirectPrivate(stream, "state") !== @streamReadable)
+ return;
+ @putByIdDirectPrivate(controller, "queue", @newQueue());
+
+ @readableStreamError(stream, error);
+}
+
+function readableStreamPipeTo(stream, sink)
+{
+ "use strict";
+ @assert(@isReadableStream(stream));
+
+ const reader = new @ReadableStreamDefaultReader(stream);
+
+ @getByIdDirectPrivate(reader, "closedPromiseCapability").@promise.@then(() => { }, (e) => { sink.error(e); });
+
+ function doPipe() {
+ @readableStreamDefaultReaderRead(reader).@then(function(result) {
+ if (result.done) {
+ sink.close();
+ return;
+ }
+ try {
+ sink.enqueue(result.value);
+ } catch (e) {
+ sink.error("ReadableStream chunk enqueueing in the sink failed");
+ return;
+ }
+ doPipe();
+ }, function(e) {
+ sink.error(e);
+ });
+ }
+ doPipe();
+}
+
+
+
+function acquireReadableStreamDefaultReader(stream)
+{
+ "use strict";
+ var start = @getByIdDirectPrivate(stream, "start");
+ if (start) {
+ start.@call(stream);
+ }
+
+ return new @ReadableStreamDefaultReader(stream);
+}
+
+// https://streams.spec.whatwg.org/#set-up-readable-stream-default-controller, starting from step 6.
+// The other part is implemented in privateInitializeReadableStreamDefaultController.
+function setupReadableStreamDefaultController(stream, underlyingSource, size, highWaterMark, startMethod, pullMethod, cancelMethod)
+{
+ "use strict";
+
+ const controller = new @ReadableStreamDefaultController(stream, underlyingSource, size, highWaterMark, @isReadableStream);
+
+ const pullAlgorithm = () => @promiseInvokeOrNoopMethod(underlyingSource, pullMethod, [controller]);
+ const cancelAlgorithm = (reason) => @promiseInvokeOrNoopMethod(underlyingSource, cancelMethod, [reason]);
+
+ @putByIdDirectPrivate(controller, "pullAlgorithm", pullAlgorithm);
+ @putByIdDirectPrivate(controller, "cancelAlgorithm", cancelAlgorithm);
+ @putByIdDirectPrivate(controller, "pull", @readableStreamDefaultControllerPull);
+ @putByIdDirectPrivate(controller, "cancel", @readableStreamDefaultControllerCancel);
+ @putByIdDirectPrivate(stream, "readableStreamController", controller);
+
+ @readableStreamDefaultControllerStart(controller);
+
+}
+
+
+function createReadableStreamController(stream, underlyingSource, strategy) {
+ "use strict";
+
+ const type = underlyingSource.type;
+ const typeString = @toString(type);
+
+ if (typeString === "bytes") {
+ // if (!@readableByteStreamAPIEnabled())
+ // @throwTypeError("ReadableByteStreamController is not implemented");
+
+ if (strategy.highWaterMark === @undefined)
+ strategy.highWaterMark = 0;
+ if (strategy.size !== @undefined)
+ @throwRangeError("Strategy for a ReadableByteStreamController cannot have a size");
+
+ @putByIdDirectPrivate(stream, "readableStreamController", new @ReadableByteStreamController(stream, underlyingSource, strategy.highWaterMark, @isReadableStream));
+ } else if (typeString === "direct") {
+ var highWaterMark = strategy?.highWaterMark;
+ @initializeArrayBufferStream.@call(stream, underlyingSource, highWaterMark);
+ } else if (type === @undefined) {
+ if (strategy.highWaterMark === @undefined)
+ strategy.highWaterMark = 1;
+
+ @setupReadableStreamDefaultController(stream, underlyingSource, strategy.size, strategy.highWaterMark, underlyingSource.start, underlyingSource.pull, underlyingSource.cancel);
+ } else
+ @throwRangeError("Invalid type for underlying source");
+
+}
+
+function readableStreamDefaultControllerStart(controller) {
+ "use strict";
+
+
+
+ if (@getByIdDirectPrivate(controller, "started") !== -1)
+ return;
+
+ const underlyingSource = @getByIdDirectPrivate(controller, "underlyingSource");
+ const startMethod = underlyingSource.start;
+ @putByIdDirectPrivate(controller, "started", 0);
+
+ @promiseInvokeOrNoopMethodNoCatch(underlyingSource, startMethod, [controller]).@then(() => {
+ @putByIdDirectPrivate(controller, "started", 1);
+ @assert(!@getByIdDirectPrivate(controller, "pulling"));
+ @assert(!@getByIdDirectPrivate(controller, "pullAgain"));
+ @readableStreamDefaultControllerCallPullIfNeeded(controller);
+ }, (error) => {
+ @readableStreamDefaultControllerError(controller, error);
+ });
+}
+
+
+// FIXME: Replace readableStreamPipeTo by below function.
+// This method implements the latest https://streams.spec.whatwg.org/#readable-stream-pipe-to.
+function readableStreamPipeToWritableStream(source, destination, preventClose, preventAbort, preventCancel, signal)
+{
+ "use strict";
+
+ @assert(@isReadableStream(source));
+ @assert(@isWritableStream(destination));
+ @assert(!@isReadableStreamLocked(source));
+ @assert(!@isWritableStreamLocked(destination));
+ @assert(signal === @undefined || @isAbortSignal(signal));
+
+ if (@getByIdDirectPrivate(source, "underlyingByteSource") !== @undefined)
+ return @Promise.@reject("Piping to a readable bytestream is not supported");
+
+ let pipeState = { source : source, destination : destination, preventAbort : preventAbort, preventCancel : preventCancel, preventClose : preventClose, signal : signal };
+
+ pipeState.reader = @acquireReadableStreamDefaultReader(source);
+ pipeState.writer = @acquireWritableStreamDefaultWriter(destination);
+
+ @putByIdDirectPrivate(source, "disturbed", true);
+
+ pipeState.finalized = false;
+ pipeState.shuttingDown = false;
+ pipeState.promiseCapability = @newPromiseCapability(@Promise);
+ pipeState.pendingReadPromiseCapability = @newPromiseCapability(@Promise);
+ pipeState.pendingReadPromiseCapability.@resolve.@call();
+ pipeState.pendingWritePromise = @Promise.@resolve();
+
+ if (signal !== @undefined) {
+ const algorithm = () => {
+ if (pipeState.finalized)
+ return;
+
+ const error = @makeDOMException("AbortError", "abort pipeTo from signal");
+
+ @pipeToShutdownWithAction(pipeState, () => {
+ const shouldAbortDestination = !pipeState.preventAbort && @getByIdDirectPrivate(pipeState.destination, "state") === "writable";
+ const promiseDestination = shouldAbortDestination ? @writableStreamAbort(pipeState.destination, error) : @Promise.@resolve();
+
+ const shouldAbortSource = !pipeState.preventCancel && @getByIdDirectPrivate(pipeState.source, "state") === @streamReadable;
+ const promiseSource = shouldAbortSource ? @readableStreamCancel(pipeState.source, error) : @Promise.@resolve();
+
+ let promiseCapability = @newPromiseCapability(@Promise);
+ let shouldWait = true;
+ let handleResolvedPromise = () => {
+ if (shouldWait) {
+ shouldWait = false;
+ return;
+ }
+ promiseCapability.@resolve.@call();
+ }
+ let handleRejectedPromise = (e) => {
+ promiseCapability.@reject.@call(@undefined, e);
+ }
+ promiseDestination.@then(handleResolvedPromise, handleRejectedPromise);
+ promiseSource.@then(handleResolvedPromise, handleRejectedPromise);
+ return promiseCapability.@promise;
+ }, error);
+ };
+ if (@whenSignalAborted(signal, algorithm))
+ return pipeState.promiseCapability.@promise;
+ }
+
+ @pipeToErrorsMustBePropagatedForward(pipeState);
+ @pipeToErrorsMustBePropagatedBackward(pipeState);
+ @pipeToClosingMustBePropagatedForward(pipeState);
+ @pipeToClosingMustBePropagatedBackward(pipeState);
+
+ @pipeToLoop(pipeState);
+
+ return pipeState.promiseCapability.@promise;
+}
+
+function pipeToLoop(pipeState)
+{
+ "use strict";
+ if (pipeState.shuttingDown)
+ return;
+
+ @pipeToDoReadWrite(pipeState).@then((result) => {
+ if (result)
+ @pipeToLoop(pipeState);
+ });
+}
+
+function pipeToDoReadWrite(pipeState)
+{
+ "use strict";
+ @assert(!pipeState.shuttingDown);
+
+ pipeState.pendingReadPromiseCapability = @newPromiseCapability(@Promise);
+ @getByIdDirectPrivate(pipeState.writer, "readyPromise").@promise.@then(() => {
+ if (pipeState.shuttingDown) {
+ pipeState.pendingReadPromiseCapability.@resolve.@call(@undefined, false);
+ return;
+ }
+
+ @readableStreamDefaultReaderRead(pipeState.reader).@then((result) => {
+ const canWrite = !result.done && @getByIdDirectPrivate(pipeState.writer, "stream") !== @undefined;
+ pipeState.pendingReadPromiseCapability.@resolve.@call(@undefined, canWrite);
+ if (!canWrite)
+ return;
+
+ pipeState.pendingWritePromise = @writableStreamDefaultWriterWrite(pipeState.writer, result.value);
+ }, (e) => {
+ pipeState.pendingReadPromiseCapability.@resolve.@call(@undefined, false);
+ });
+ }, (e) => {
+ pipeState.pendingReadPromiseCapability.@resolve.@call(@undefined, false);
+ });
+ return pipeState.pendingReadPromiseCapability.@promise;
+}
+
+function pipeToErrorsMustBePropagatedForward(pipeState)
+{
+ "use strict";
+
+ const action = () => {
+ pipeState.pendingReadPromiseCapability.@resolve.@call(@undefined, false);
+ const error = @getByIdDirectPrivate(pipeState.source, "storedError");
+ if (!pipeState.preventAbort) {
+ @pipeToShutdownWithAction(pipeState, () => @writableStreamAbort(pipeState.destination, error), error);
+ return;
+ }
+ @pipeToShutdown(pipeState, error);
+ };
+
+ if (@getByIdDirectPrivate(pipeState.source, "state") === @streamErrored) {
+ action();
+ return;
+ }
+
+ @getByIdDirectPrivate(pipeState.reader, "closedPromiseCapability").@promise.@then(@undefined, action);
+}
+
+function pipeToErrorsMustBePropagatedBackward(pipeState)
+{
+ "use strict";
+ const action = () => {
+ const error = @getByIdDirectPrivate(pipeState.destination, "storedError");
+ if (!pipeState.preventCancel) {
+ @pipeToShutdownWithAction(pipeState, () => @readableStreamCancel(pipeState.source, error), error);
+ return;
+ }
+ @pipeToShutdown(pipeState, error);
+ };
+ if (@getByIdDirectPrivate(pipeState.destination, "state") === "errored") {
+ action();
+ return;
+ }
+ @getByIdDirectPrivate(pipeState.writer, "closedPromise").@promise.@then(@undefined, action);
+}
+
+function pipeToClosingMustBePropagatedForward(pipeState)
+{
+ "use strict";
+ const action = () => {
+ pipeState.pendingReadPromiseCapability.@resolve.@call(@undefined, false);
+ const error = @getByIdDirectPrivate(pipeState.source, "storedError");
+ if (!pipeState.preventClose) {
+ @pipeToShutdownWithAction(pipeState, () => @writableStreamDefaultWriterCloseWithErrorPropagation(pipeState.writer));
+ return;
+ }
+ @pipeToShutdown(pipeState);
+ };
+ if (@getByIdDirectPrivate(pipeState.source, "state") === @streamClosed) {
+ action();
+ return;
+ }
+ @getByIdDirectPrivate(pipeState.reader, "closedPromiseCapability").@promise.@then(action, @undefined);
+}
+
+function pipeToClosingMustBePropagatedBackward(pipeState)
+{
+ "use strict";
+ if (!@writableStreamCloseQueuedOrInFlight(pipeState.destination) && @getByIdDirectPrivate(pipeState.destination, "state") !== "closed")
+ return;
+
+ // @assert no chunks have been read/written
+
+ const error = @makeTypeError("closing is propagated backward");
+ if (!pipeState.preventCancel) {
+ @pipeToShutdownWithAction(pipeState, () => @readableStreamCancel(pipeState.source, error), error);
+ return;
+ }
+ @pipeToShutdown(pipeState, error);
+}
+
+function pipeToShutdownWithAction(pipeState, action)
+{
+ "use strict";
+
+ if (pipeState.shuttingDown)
+ return;
+
+ pipeState.shuttingDown = true;
+
+ const hasError = arguments.length > 2;
+ const error = arguments[2];
+ const finalize = () => {
+ const promise = action();
+ promise.@then(() => {
+ if (hasError)
+ @pipeToFinalize(pipeState, error);
+ else
+ @pipeToFinalize(pipeState);
+ }, (e) => {
+ @pipeToFinalize(pipeState, e);
+ });
+ };
+
+ if (@getByIdDirectPrivate(pipeState.destination, "state") === "writable" && !@writableStreamCloseQueuedOrInFlight(pipeState.destination)) {
+ pipeState.pendingReadPromiseCapability.@promise.@then(() => {
+ pipeState.pendingWritePromise.@then(finalize, finalize);
+ }, (e) => @pipeToFinalize(pipeState, e));
+ return;
+ }
+
+ finalize();
+}
+
+function pipeToShutdown(pipeState)
+{
+ "use strict";
+
+ if (pipeState.shuttingDown)
+ return;
+
+ pipeState.shuttingDown = true;
+
+ const hasError = arguments.length > 1;
+ const error = arguments[1];
+ const finalize = () => {
+ if (hasError)
+ @pipeToFinalize(pipeState, error);
+ else
+ @pipeToFinalize(pipeState);
+ };
+
+ if (@getByIdDirectPrivate(pipeState.destination, "state") === "writable" && !@writableStreamCloseQueuedOrInFlight(pipeState.destination)) {
+ pipeState.pendingReadPromiseCapability.@promise.@then(() => {
+ pipeState.pendingWritePromise.@then(finalize, finalize);
+ }, (e) => @pipeToFinalize(pipeState, e));
+ return;
+ }
+ finalize();
+}
+
+function pipeToFinalize(pipeState)
+{
+ "use strict";
+
+ @writableStreamDefaultWriterRelease(pipeState.writer);
+ @readableStreamReaderGenericRelease(pipeState.reader);
+
+ // Instead of removing the abort algorithm as per spec, we make it a no-op which is equivalent.
+ pipeState.finalized = true;
+
+ if (arguments.length > 1)
+ pipeState.promiseCapability.@reject.@call(@undefined, arguments[1]);
+ else
+ pipeState.promiseCapability.@resolve.@call();
+}
+
+function readableStreamTee(stream, shouldClone)
+{
+ "use strict";
+
+ @assert(@isReadableStream(stream));
+ @assert(typeof(shouldClone) === "boolean");
+
+ const reader = new @ReadableStreamDefaultReader(stream);
+
+ const teeState = {
+ closedOrErrored: false,
+ canceled1: false,
+ canceled2: false,
+ reason1: @undefined,
+ reason2: @undefined,
+ };
+
+ teeState.cancelPromiseCapability = @newPromiseCapability(@Promise);
+
+ const pullFunction = @readableStreamTeePullFunction(teeState, reader, shouldClone);
+
+ const branch1Source = { };
+ @putByIdDirectPrivate(branch1Source, "pull", pullFunction);
+ @putByIdDirectPrivate(branch1Source, "cancel", @readableStreamTeeBranch1CancelFunction(teeState, stream));
+
+ const branch2Source = { };
+ @putByIdDirectPrivate(branch2Source, "pull", pullFunction);
+ @putByIdDirectPrivate(branch2Source, "cancel", @readableStreamTeeBranch2CancelFunction(teeState, stream));
+
+ const branch1 = new @ReadableStream(branch1Source);
+ const branch2 = new @ReadableStream(branch2Source);
+
+ @getByIdDirectPrivate(reader, "closedPromiseCapability").@promise.@then(@undefined, function(e) {
+ if (teeState.closedOrErrored)
+ return;
+ @readableStreamDefaultControllerError(branch1.@readableStreamController, e);
+ @readableStreamDefaultControllerError(branch2.@readableStreamController, e);
+ teeState.closedOrErrored = true;
+ if (!teeState.canceled1 || !teeState.canceled2)
+ teeState.cancelPromiseCapability.@resolve.@call();
+ });
+
+ // Additional fields compared to the spec, as they are needed within pull/cancel functions.
+ teeState.branch1 = branch1;
+ teeState.branch2 = branch2;
+
+ return [branch1, branch2];
+}
+
+function readableStreamTeePullFunction(teeState, reader, shouldClone)
+{
+ "use strict";
+
+ return function() {
+ @Promise.prototype.@then.@call(@readableStreamDefaultReaderRead(reader), function(result) {
+ @assert(@isObject(result));
+ @assert(typeof result.done === "boolean");
+ if (result.done && !teeState.closedOrErrored) {
+ if (!teeState.canceled1)
+ @readableStreamDefaultControllerClose(teeState.branch1.@readableStreamController);
+ if (!teeState.canceled2)
+ @readableStreamDefaultControllerClose(teeState.branch2.@readableStreamController);
+ teeState.closedOrErrored = true;
+ if (!teeState.canceled1 || !teeState.canceled2)
+ teeState.cancelPromiseCapability.@resolve.@call();
+ }
+ if (teeState.closedOrErrored)
+ return;
+ if (!teeState.canceled1)
+ @readableStreamDefaultControllerEnqueue(teeState.branch1.@readableStreamController, result.value);
+ if (!teeState.canceled2)
+ @readableStreamDefaultControllerEnqueue(teeState.branch2.@readableStreamController, shouldClone ? @structuredCloneForStream(result.value) : result.value);
+ });
+ }
+}
+
+function readableStreamTeeBranch1CancelFunction(teeState, stream)
+{
+ "use strict";
+
+ return function(r) {
+ teeState.canceled1 = true;
+ teeState.reason1 = r;
+ if (teeState.canceled2) {
+ @readableStreamCancel(stream, [teeState.reason1, teeState.reason2]).@then(
+ teeState.cancelPromiseCapability.@resolve,
+ teeState.cancelPromiseCapability.@reject);
+ }
+ return teeState.cancelPromiseCapability.@promise;
+ }
+}
+
+function readableStreamTeeBranch2CancelFunction(teeState, stream)
+{
+ "use strict";
+
+ return function(r) {
+ teeState.canceled2 = true;
+ teeState.reason2 = r;
+ if (teeState.canceled1) {
+ @readableStreamCancel(stream, [teeState.reason1, teeState.reason2]).@then(
+ teeState.cancelPromiseCapability.@resolve,
+ teeState.cancelPromiseCapability.@reject);
+ }
+ return teeState.cancelPromiseCapability.@promise;
+ }
+}
+
+function isReadableStream(stream)
+{
+ "use strict";
+
+ // Spec tells to return true only if stream has a readableStreamController internal slot.
+ // However, since it is a private slot, it cannot be checked using hasOwnProperty().
+ // Therefore, readableStreamController is initialized with null value.
+ return @isObject(stream) && @getByIdDirectPrivate(stream, "readableStreamController") !== @undefined;
+}
+
+function isReadableStreamDefaultReader(reader)
+{
+ "use strict";
+
+ // Spec tells to return true only if reader has a readRequests internal slot.
+ // However, since it is a private slot, it cannot be checked using hasOwnProperty().
+ // Since readRequests is initialized with an empty array, the following test is ok.
+ return @isObject(reader) && !!@getByIdDirectPrivate(reader, "readRequests");
+}
+
+function isReadableStreamDefaultController(controller)
+{
+ "use strict";
+
+ // Spec tells to return true only if controller has an underlyingSource internal slot.
+ // However, since it is a private slot, it cannot be checked using hasOwnProperty().
+ // underlyingSource is obtained in ReadableStream constructor: if undefined, it is set
+ // to an empty object. Therefore, following test is ok.
+ return @isObject(controller) && !!@getByIdDirectPrivate(controller, "underlyingSource");
+}
+
+
+@globalPrivate
+function assignDirectStream() {
+ "use strict";
+
+ var stream = this;
+}
+
+
+function handleDirectStreamError(e) {
+ "use strict";
+
+ var controller = this;
+ var sink = controller.@sink;
+ if (sink) {
+ @putByIdDirectPrivate(controller, "sink", @undefined);
+ try {
+ sink.close(e);
+ } catch (f) {}
+ }
+
+ this.error = this.drain = this.write = this.close = this.end = @onReadableStreamDirectControllerClosed;
+
+ if (typeof this.@underlyingSource.close === 'function') {
+ try {
+ this.@underlyingSource.close.@call(this.@underlyingSource, e);
+ } catch (e) {
+ }
+ }
+
+ try {
+ var pend = controller._pendingRead;
+ if (pend) {
+ controller._pendingRead = @undefined;
+ @rejectPromise(pend, e);
+ }
+ } catch (f) {}
+ var stream = controller.@controlledReadableStream;
+ if (stream) @readableStreamError(stream, e);
+}
+
+function handleDirectStreamErrorReject(e) {
+ @handleDirectStreamError.@call(this, e);
+ return @Promise.@reject(e);
+}
+
+function onPullDirectStream(controller)
+{
+
+ "use strict";
+
+ var stream = controller.@controlledReadableStream;
+ if (!stream || @getByIdDirectPrivate(stream, "state") !== @streamReadable)
+ return;
+
+ // pull is in progress
+ // this is a recursive call
+ // ignore it
+ if (controller._deferClose === -1) {
+ return;
+ }
+
+
+ controller._deferClose = -1;
+ controller._deferDrain = -1;
+ var deferClose;
+ var deferDrain;
+
+ // Direct streams allow @pull to be called multiple times, unlike the spec.
+ // Backpressure is handled by the destination, not by the underlying source.
+ // In this case, we rely on the heuristic that repeatedly draining in the same tick
+ // is bad for performance
+ // this code is only run when consuming a direct stream from JS
+ // without the HTTP server or anything else
+ try {
+ var result = controller.@underlyingSource.pull(
+ controller,
+ );
+
+ if (result && @isPromise(result)) {
+ if (controller._handleError === @undefined) {
+ controller._handleError = @handleDirectStreamErrorReject.bind(controller);
+ }
+
+ @Promise.prototype.catch.@call(result, controller._handleError);
+ }
+ } catch(e) {
+ return @handleDirectStreamErrorReject.@call(controller, e);
+ } finally {
+ deferClose = controller._deferClose;
+ deferDrain = controller._deferDrain;
+ controller._deferDrain = controller._deferClose = 0;
+ }
+
+
+ var promiseToReturn;
+
+
+ if (controller._pendingRead === @undefined) {
+ controller._pendingRead = promiseToReturn = @newPromise();
+ } else {
+ promiseToReturn = @readableStreamAddReadRequest(stream);
+ }
+
+
+ // they called close during @pull()
+ // we delay that
+ if (deferClose === 1) {
+ var reason = controller._deferCloseReason;
+ controller._deferCloseReason = @undefined;
+ @onCloseDirectStream.@call(controller, reason);
+ return promiseToReturn;
+ }
+
+ // not done, but they called drain()
+ if (deferDrain === 1) {
+ @onDrainDirectStream.@call(controller);
+ }
+
+
+ return promiseToReturn;
+}
+
+function noopDoneFunction() {
+ return @Promise.@resolve({value: @undefined, done: true});
+}
+
+function onReadableStreamDirectControllerClosed(reason)
+{
+ "use strict";
+ @throwTypeError("ReadableStreamDirectController is now closed");
+}
+
+function onCloseDirectStream(reason)
+{
+ "use strict";
+ var stream = this.@controlledReadableStream;
+ if (!stream || @getByIdDirectPrivate(stream, "state") !== @streamReadable)
+ return;
+
+ if (this._deferClose !== 0) {
+ this._deferClose = 1;
+ this._deferCloseReason = reason;
+ return;
+ }
+
+ @putByIdDirectPrivate(stream, "state", @streamClosing);
+ if (typeof this.@underlyingSource.close === 'function') {
+ try {
+ this.@underlyingSource.close.@call(this.@underlyingSource, reason);
+ } catch (e) {
+
+ }
+ }
+
+ var drained;
+ try {
+ drained = this.@sink.end();
+ @putByIdDirectPrivate(this, "sink", @undefined);
+ } catch (e) {
+ if (this._pendingRead) {
+ var read = this._pendingRead;
+ this._pendingRead = @undefined;
+ @rejectPromise(read, e);
+ }
+ @readableStreamError(stream, e);
+ return;
+ }
+
+ this.error = this.drain = this.write = this.close = this.end = @onReadableStreamDirectControllerClosed;
+
+ var reader = @getByIdDirectPrivate(stream, "reader");
+
+ if (reader && @isReadableStreamDefaultReader(reader)) {
+ var _pendingRead = this._pendingRead;
+ if (_pendingRead && @isPromise(_pendingRead) && drained?.byteLength) {
+ this._pendingRead = @undefined;
+ @fulfillPromise(_pendingRead, {value: drained, done: false});
+ @readableStreamClose(stream);
+ return;
+ }
+ }
+
+ if (drained?.byteLength) {
+ var requests = @getByIdDirectPrivate(reader, "readRequests");
+ if (requests?.isNotEmpty()) {
+ @readableStreamFulfillReadRequest(stream, drained, false);
+ @readableStreamClose(stream);
+ return;
+ }
+
+ @putByIdDirectPrivate(stream, "state", @streamReadable);
+ this.@pull = () => {
+ var thisResult = @createFulfilledPromise({value: drained, done: false});
+ drained = @undefined;
+ @readableStreamClose(stream);
+ stream = @undefined;
+ return thisResult;
+ };
+ } else if (this._pendingRead) {
+ var read = this._pendingRead;
+ this._pendingRead = @undefined;
+ @putByIdDirectPrivate(this, "pull", @noopDoneFunction);
+ @fulfillPromise(read, {value: @undefined, done: true});
+ }
+
+ @readableStreamClose(stream);
+}
+
+function onDrainDirectStream()
+{
+ "use strict";
+
+ var stream = this.@controlledReadableStream;
+ var reader = @getByIdDirectPrivate(stream, "reader");
+ if (!reader || !@isReadableStreamDefaultReader(reader)) {
+ return;
+ }
+
+ var _pendingRead = this._pendingRead;
+ this._pendingRead = @undefined;
+ if (_pendingRead && @isPromise(_pendingRead)) {
+ var drained = this.@sink.drain();
+ if (drained?.byteLength) {
+ this._pendingRead = @getByIdDirectPrivate(stream, "readRequests")?.shift();
+ @fulfillPromise(_pendingRead, {value: drained, done: false});
+ } else {
+ this._pendingRead = _pendingRead;
+ }
+ } else if (@getByIdDirectPrivate(stream, "readRequests")?.isNotEmpty()) {
+ var drained = this.@sink.drain();
+ if (drained?.byteLength) {
+ @readableStreamFulfillReadRequest(stream, drained, false);
+ }
+ } else if (this._deferDrain === -1) {
+ this._deferDrain = 1;
+ }
+
+}
+
+function initializeArrayBufferStream(underlyingSource, highWaterMark)
+{
+ "use strict";
+
+ // This is the fallback implementation for direct streams
+ // When we don't know what the destination type is
+ // We assume it is a Uint8Array.
+
+ var opts = highWaterMark ? {highWaterMark, stream: true, asUint8Array: true} : {stream: true, asUint8Array: true};
+ var sink = new globalThis.Bun.ArrayBufferSink();
+ sink.start(opts);
+
+ var controller = {
+ @underlyingSource: underlyingSource,
+ @pull: @onPullDirectStream,
+ @controlledReadableStream: this,
+ @sink: sink,
+ close: @onCloseDirectStream,
+ write: sink.write.bind(sink),
+ error: @handleDirectStreamError,
+ end: @onCloseDirectStream,
+ @close: @onCloseDirectStream,
+ drain: @onDrainDirectStream,
+ _pendingRead: @undefined,
+ _deferClose: 0,
+ _deferDrain: 0,
+ _deferCloseReason: @undefined,
+ _handleError: @undefined,
+ };
+
+
+ @putByIdDirectPrivate(this, "readableStreamController", controller);
+
+}
+
+function readableStreamError(stream, error)
+{
+ "use strict";
+
+ @assert(@isReadableStream(stream));
+ @assert(@getByIdDirectPrivate(stream, "state") === @streamReadable);
+ @putByIdDirectPrivate(stream, "state", @streamErrored);
+ @putByIdDirectPrivate(stream, "storedError", error);
+
+ const reader = @getByIdDirectPrivate(stream, "reader");
+
+ if (!reader)
+ return;
+
+ if (@isReadableStreamDefaultReader(reader)) {
+ const requests = @getByIdDirectPrivate(reader, "readRequests");
+ @putByIdDirectPrivate(reader, "readRequests", @createFIFO());
+ for (var request = requests.shift(); request; request = requests.shift())
+ @rejectPromise(request, error);
+ } else {
+ @assert(@isReadableStreamBYOBReader(reader));
+ const requests = @getByIdDirectPrivate(reader, "readIntoRequests");
+ @putByIdDirectPrivate(reader, "readIntoRequests", @createFIFO());
+ for (var request = requests.shift(); request; request = requests.shift())
+ @rejectPromise(request, error);
+ }
+
+ @getByIdDirectPrivate(reader, "closedPromiseCapability").@reject.@call(@undefined, error);
+ const promise = @getByIdDirectPrivate(reader, "closedPromiseCapability").@promise;
+ @markPromiseAsHandled(promise);
+}
+
+function readableStreamDefaultControllerShouldCallPull(controller)
+{
+ "use strict";
+
+ const stream = @getByIdDirectPrivate(controller, "controlledReadableStream");
+
+ if (!@readableStreamDefaultControllerCanCloseOrEnqueue(controller))
+ return false;
+ if (!(@getByIdDirectPrivate(controller, "started") === 1))
+ return false;
+ if ((!@isReadableStreamLocked(stream) || !@getByIdDirectPrivate(@getByIdDirectPrivate(stream, "reader"), "readRequests")?.isNotEmpty()) && @readableStreamDefaultControllerGetDesiredSize(controller) <= 0)
+ return false;
+ const desiredSize = @readableStreamDefaultControllerGetDesiredSize(controller);
+ @assert(desiredSize !== null);
+ return desiredSize > 0;
+}
+
+function readableStreamDefaultControllerCallPullIfNeeded(controller)
+{
+ "use strict";
+
+ // FIXME: use @readableStreamDefaultControllerShouldCallPull
+ const stream = @getByIdDirectPrivate(controller, "controlledReadableStream");
+
+ if (!@readableStreamDefaultControllerCanCloseOrEnqueue(controller))
+ return;
+ if (!(@getByIdDirectPrivate(controller, "started") === 1))
+ return;
+ if ((!@isReadableStreamLocked(stream) || !@getByIdDirectPrivate(@getByIdDirectPrivate(stream, "reader"), "readRequests")?.isNotEmpty()) && @readableStreamDefaultControllerGetDesiredSize(controller) <= 0)
+ return;
+
+ if (@getByIdDirectPrivate(controller, "pulling")) {
+ @putByIdDirectPrivate(controller, "pullAgain", true);
+ return;
+ }
+
+
+ @assert(!@getByIdDirectPrivate(controller, "pullAgain"));
+ @putByIdDirectPrivate(controller, "pulling", true);
+
+ @getByIdDirectPrivate(controller, "pullAlgorithm").@call(@undefined).@then(function() {
+ @putByIdDirectPrivate(controller, "pulling", false);
+ if (@getByIdDirectPrivate(controller, "pullAgain")) {
+ @putByIdDirectPrivate(controller, "pullAgain", false);
+
+ @readableStreamDefaultControllerCallPullIfNeeded(controller);
+ }
+ }, function(error) {
+ @readableStreamDefaultControllerError(controller, error);
+ });
+}
+
+function isReadableStreamLocked(stream)
+{
+ "use strict";
+
+ @assert(@isReadableStream(stream));
+ return !!@getByIdDirectPrivate(stream, "reader");
+}
+
+function readableStreamDefaultControllerGetDesiredSize(controller)
+{
+ "use strict";
+
+ const stream = @getByIdDirectPrivate(controller, "controlledReadableStream");
+ const state = @getByIdDirectPrivate(stream, "state");
+
+ if (state === @streamErrored)
+ return null;
+ if (state === @streamClosed)
+ return 0;
+
+ return @getByIdDirectPrivate(controller, "strategy").highWaterMark - @getByIdDirectPrivate(controller, "queue").size;
+}
+
+
+function readableStreamReaderGenericCancel(reader, reason)
+{
+ "use strict";
+
+ const stream = @getByIdDirectPrivate(reader, "ownerReadableStream");
+ @assert(!!stream);
+ return @readableStreamCancel(stream, reason);
+}
+
+function readableStreamCancel(stream, reason)
+{
+ "use strict";
+
+ @putByIdDirectPrivate(stream, "disturbed", true);
+ const state = @getByIdDirectPrivate(stream, "state");
+ if (state === @streamClosed)
+ return @Promise.@resolve();
+ if (state === @streamErrored)
+ return @Promise.@reject(@getByIdDirectPrivate(stream, "storedError"));
+ @readableStreamClose(stream);
+
+ var controller = @getByIdDirectPrivate(stream, "readableStreamController");
+ return controller.@cancel(controller, reason).@then(function() { });
+}
+
+function readableStreamDefaultControllerCancel(controller, reason)
+{
+ "use strict";
+
+ @putByIdDirectPrivate(controller, "queue", @newQueue());
+ return @getByIdDirectPrivate(controller, "cancelAlgorithm").@call(@undefined, reason);
+}
+
+function readableStreamDefaultControllerPull(controller)
+{
+ "use strict";
+
+ var queue = @getByIdDirectPrivate(controller, "queue");
+ if (queue.content.isNotEmpty()) {
+ const chunk = @dequeueValue(queue);
+ if (@getByIdDirectPrivate(controller, "closeRequested") && queue.content.isEmpty())
+ @readableStreamClose(@getByIdDirectPrivate(controller, "controlledReadableStream"));
+ else
+ @readableStreamDefaultControllerCallPullIfNeeded(controller);
+
+ return @createFulfilledPromise({ value: chunk, done: false });
+ }
+ const pendingPromise = @readableStreamAddReadRequest(@getByIdDirectPrivate(controller, "controlledReadableStream"));
+ @readableStreamDefaultControllerCallPullIfNeeded(controller);
+ return pendingPromise;
+}
+
+function readableStreamDefaultControllerClose(controller)
+{
+ "use strict";
+
+ @assert(@readableStreamDefaultControllerCanCloseOrEnqueue(controller));
+ @putByIdDirectPrivate(controller, "closeRequested", true);
+ if (@getByIdDirectPrivate(controller, "queue")?.content?.isEmpty())
+ @readableStreamClose(@getByIdDirectPrivate(controller, "controlledReadableStream"));
+}
+
+function readableStreamClose(stream)
+{
+ "use strict";
+
+ @assert(@getByIdDirectPrivate(stream, "state") === @streamReadable);
+ @putByIdDirectPrivate(stream, "state", @streamClosed);
+ if (!@getByIdDirectPrivate(stream, "reader"))
+ return;
+
+ if (@isReadableStreamDefaultReader(@getByIdDirectPrivate(stream, "reader"))) {
+ const requests = @getByIdDirectPrivate(@getByIdDirectPrivate(stream, "reader"), "readRequests");
+ if (requests.isNotEmpty()) {
+ @putByIdDirectPrivate(@getByIdDirectPrivate(stream, "reader"), "readRequests", @createFIFO());
+
+ for (var request = requests.shift(); request; request = requests.shift())
+ @fulfillPromise(request, { value: @undefined, done: true });
+ }
+ }
+
+ @getByIdDirectPrivate(@getByIdDirectPrivate(stream, "reader"), "closedPromiseCapability").@resolve.@call();
+}
+
+function readableStreamFulfillReadRequest(stream, chunk, done)
+{
+ "use strict";
+ const readRequest = @getByIdDirectPrivate(@getByIdDirectPrivate(stream, "reader"), "readRequests").shift();
+ @fulfillPromise(readRequest, { value: chunk, done: done });
+}
+
+function readableStreamDefaultControllerEnqueue(controller, chunk)
+{
+ "use strict";
+
+ const stream = @getByIdDirectPrivate(controller, "controlledReadableStream");
+ // this is checked by callers
+ @assert(@readableStreamDefaultControllerCanCloseOrEnqueue(controller));
+
+ if (@isReadableStreamLocked(stream) && @getByIdDirectPrivate(@getByIdDirectPrivate(stream, "reader"), "readRequests")?.isNotEmpty()) {
+ @readableStreamFulfillReadRequest(stream, chunk, false);
+ @readableStreamDefaultControllerCallPullIfNeeded(controller);
+ return;
+ }
+
+ try {
+ let chunkSize = 1;
+ if (@getByIdDirectPrivate(controller, "strategy").size !== @undefined)
+ chunkSize = @getByIdDirectPrivate(controller, "strategy").size(chunk);
+ @enqueueValueWithSize(@getByIdDirectPrivate(controller, "queue"), chunk, chunkSize);
+ }
+ catch(error) {
+ @readableStreamDefaultControllerError(controller, error);
+ throw error;
+ }
+ @readableStreamDefaultControllerCallPullIfNeeded(controller);
+}
+
+function readableStreamDefaultReaderRead(reader)
+{
+ "use strict";
+
+ const stream = @getByIdDirectPrivate(reader, "ownerReadableStream");
+ @assert(!!stream);
+ const state = @getByIdDirectPrivate(stream, "state");
+
+ @putByIdDirectPrivate(stream, "disturbed", true);
+ if (state === @streamClosed)
+ return @createFulfilledPromise({ value: @undefined, done: true });
+ if (state === @streamErrored)
+ return @Promise.@reject(@getByIdDirectPrivate(stream, "storedError"));
+ @assert(state === @streamReadable);
+
+ return @getByIdDirectPrivate(stream, "readableStreamController").@pull(@getByIdDirectPrivate(stream, "readableStreamController"));
+}
+
+function readableStreamAddReadRequest(stream)
+{
+ "use strict";
+
+ @assert(@isReadableStreamDefaultReader(@getByIdDirectPrivate(stream, "reader")));
+ @assert(@getByIdDirectPrivate(stream, "state") == @streamReadable);
+
+ const readRequest = @newPromise();
+
+ @getByIdDirectPrivate(@getByIdDirectPrivate(stream, "reader"), "readRequests").push(readRequest);
+
+ return readRequest;
+}
+
+function isReadableStreamDisturbed(stream)
+{
+ "use strict";
+
+ @assert(@isReadableStream(stream));
+ return @getByIdDirectPrivate(stream, "disturbed");
+}
+
+function readableStreamReaderGenericRelease(reader)
+{
+ "use strict";
+
+ @assert(!!@getByIdDirectPrivate(reader, "ownerReadableStream"));
+ @assert(@getByIdDirectPrivate(@getByIdDirectPrivate(reader, "ownerReadableStream"), "reader") === reader);
+
+ if (@getByIdDirectPrivate(@getByIdDirectPrivate(reader, "ownerReadableStream"), "state") === @streamReadable)
+ @getByIdDirectPrivate(reader, "closedPromiseCapability").@reject.@call(@undefined, @makeTypeError("releasing lock of reader whose stream is still in readable state"));
+ else
+ @putByIdDirectPrivate(reader, "closedPromiseCapability", { @promise: @newHandledRejectedPromise(@makeTypeError("reader released lock")) });
+
+ const promise = @getByIdDirectPrivate(reader, "closedPromiseCapability").@promise;
+ @markPromiseAsHandled(promise);
+ @putByIdDirectPrivate(@getByIdDirectPrivate(reader, "ownerReadableStream"), "reader", @undefined);
+ @putByIdDirectPrivate(reader, "ownerReadableStream", @undefined);
+}
+
+function readableStreamDefaultControllerCanCloseOrEnqueue(controller)
+{
+ "use strict";
+
+ return !@getByIdDirectPrivate(controller, "closeRequested") && @getByIdDirectPrivate(@getByIdDirectPrivate(controller, "controlledReadableStream"), "state") === @streamReadable;
+}
+
+
+function lazyLoadStream(stream, autoAllocateChunkSize) {
+ "use strict";
+
+ var nativeType = @getByIdDirectPrivate(stream, "bunNativeType");
+ var nativePtr = @getByIdDirectPrivate(stream, "bunNativePtr");
+ var cached = @lazyStreamPrototypeMap;
+ var Prototype = cached.@get(nativeType);
+ if (Prototype === @undefined) {
+ var [pull, start, cancel, setClose, deinit] = @lazyLoad(nativeType);
+ var closer = [false];
+ var handleResult;
+ function handleNativeReadableStreamPromiseResult(val) {
+ "use strict";
+ var {c, v} = this;
+ this.c = @undefined;
+ this.v = @undefined;
+ handleResult(val, c, v);
+ }
+
+ handleResult = function handleResult(result, controller, view) {
+ "use strict";
+
+ if (result && @isPromise(result)) {
+ return result.then(handleNativeReadableStreamPromiseResult.bind({c: controller, v: view}), (err) => controller.error(err));
+ } else if (result !== false) {
+ if (view && view.byteLength === result) {
+ controller.byobRequest.respondWithNewView(view);
+ } else {
+ controller.byobRequest.respond(result);
+ }
+ }
+
+ if (closer[0] || result === false) {
+ @enqueueJob(() => controller.close());
+ closer[0] = false;
+ }
+ };
+
+ Prototype = class NativeReadableStreamSource {
+ constructor(tag, autoAllocateChunkSize) {
+ this.pull = this.pull_.bind(tag);
+ this.cancel = this.cancel_.bind(tag);
+ this.autoAllocateChunkSize = autoAllocateChunkSize;
+ }
+
+ pull;
+ cancel;
+
+ type = "bytes";
+ autoAllocateChunkSize = 0;
+
+ static startSync = start;
+
+ pull_(controller) {
+ closer[0] = false;
+ var result;
+
+ const view = controller.byobRequest.view;
+ try {
+ result = pull(this, view, closer);
+ } catch(err) {
+ return controller.error(err);
+ }
+
+ return handleResult(result, controller, view);
+ }
+
+ cancel_(reason) {
+ cancel(this, reason);
+ }
+ static deinit = deinit;
+ static registry = new FinalizationRegistry(deinit);
+ }
+ cached.@set(nativeType, Prototype);
+ }
+
+ const chunkSize = Prototype.startSync(nativePtr, autoAllocateChunkSize);
+
+ // empty file, no need for native back-and-forth on this
+ if (chunkSize === 0) {
+ @readableStreamClose(stream);
+ return null;
+ }
+ var instance = new Prototype(nativePtr, chunkSize);
+ Prototype.registry.register(instance, nativePtr);
+ return instance;
+} \ No newline at end of file
diff --git a/src/bun.js/builtins/js/StreamInternals.js b/src/bun.js/builtins/js/StreamInternals.js
new file mode 100644
index 000000000..c2ca3f5b5
--- /dev/null
+++ b/src/bun.js/builtins/js/StreamInternals.js
@@ -0,0 +1,317 @@
+/*
+ * Copyright (C) 2015 Canon Inc.
+ * Copyright (C) 2015 Igalia.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+// @internal
+
+function markPromiseAsHandled(promise)
+{
+ "use strict";
+
+ @assert(@isPromise(promise));
+ @putPromiseInternalField(promise, @promiseFieldFlags, @getPromiseInternalField(promise, @promiseFieldFlags) | @promiseFlagsIsHandled);
+}
+
+function shieldingPromiseResolve(result)
+{
+ "use strict";
+
+ const promise = @Promise.@resolve(result);
+ if (promise.@then === @undefined)
+ promise.@then = @Promise.prototype.@then;
+ return promise;
+}
+
+function promiseInvokeOrNoopMethodNoCatch(object, method, args)
+{
+ "use strict";
+
+ if (method === @undefined)
+ return @Promise.@resolve();
+ return @shieldingPromiseResolve(method.@apply(object, args));
+}
+
+function promiseInvokeOrNoopNoCatch(object, key, args)
+{
+ "use strict";
+
+ return @promiseInvokeOrNoopMethodNoCatch(object, object[key], args);
+}
+
+function promiseInvokeOrNoopMethod(object, method, args)
+{
+ "use strict";
+
+ try {
+ return @promiseInvokeOrNoopMethodNoCatch(object, method, args);
+ }
+ catch(error) {
+ return @Promise.@reject(error);
+ }
+}
+
+function promiseInvokeOrNoop(object, key, args)
+{
+ "use strict";
+
+ try {
+ return @promiseInvokeOrNoopNoCatch(object, key, args);
+ }
+ catch(error) {
+ return @Promise.@reject(error);
+ }
+}
+
+function promiseInvokeOrFallbackOrNoop(object, key1, args1, key2, args2)
+{
+ "use strict";
+
+ try {
+ const method = object[key1];
+ if (method === @undefined)
+ return @promiseInvokeOrNoopNoCatch(object, key2, args2);
+ return @shieldingPromiseResolve(method.@apply(object, args1));
+ }
+ catch(error) {
+ return @Promise.@reject(error);
+ }
+}
+
+function validateAndNormalizeQueuingStrategy(size, highWaterMark)
+{
+ "use strict";
+
+ if (size !== @undefined && typeof size !== "function")
+ @throwTypeError("size parameter must be a function");
+
+ const newHighWaterMark = @toNumber(highWaterMark);
+
+ if (@isNaN(newHighWaterMark) || newHighWaterMark < 0)
+ @throwRangeError("highWaterMark value is negative or not a number");
+
+ return { size: size, highWaterMark: newHighWaterMark };
+}
+
+@globalPrivate
+function createFIFO() {
+ "use strict";
+ class Denqueue {
+ constructor() {
+ this._head = 0;
+ this._tail = 0;
+ // this._capacity = 0;
+ this._capacityMask = 0x3;
+ this._list = @newArrayWithSize(4);
+ }
+
+ size() {
+ if (this._head === this._tail) return 0;
+ if (this._head < this._tail) return this._tail - this._head;
+ else return this._capacityMask + 1 - (this._head - this._tail);
+ }
+
+ isEmpty() {
+ return this.size() == 0;
+ }
+
+ isNotEmpty() {
+ return this.size() > 0;
+ }
+
+ shift() {
+ var head = this._head;
+ if (head === this._tail) return @undefined;
+ var item = this._list[head];
+ @putByValDirect(this._list, head, @undefined);
+ this._head = (head + 1) & this._capacityMask;
+ if (head < 2 && this._tail > 10000 && this._tail <= this._list.length >>> 2) this._shrinkArray();
+ return item;
+ }
+
+ peek() {
+ if (this._head === this._tail) return @undefined;
+ return this._list[this._head];
+ }
+
+ push(item) {
+ var tail = this._tail;
+ @putByValDirect(this._list, tail, item);
+ this._tail = (tail + 1) & this._capacityMask;
+ if (this._tail === this._head) {
+ this._growArray();
+ }
+ // if (this._capacity && this.size() > this._capacity) {
+ // this.shift();
+ // }
+ }
+
+ toArray(fullCopy) {
+ var list = this._list;
+ var len = @toLength(list.length);
+
+ if (fullCopy || this._head > this._tail) {
+ var _head = @toLength(this._head);
+ var _tail = @toLength(this._tail);
+ var total = @toLength((len - _head) + _tail);
+ var array = @newArrayWithSize(total);
+ var j = 0;
+ for (var i = _head; i < len; i++) @putByValDirect(array, j++, list[i]);
+ for (var i = 0; i < _tail; i++) @putByValDirect(array, j++, list[i]);
+ return array;
+ } else {
+ return @Array.prototype.slice.@call(list, this._head, this._tail);
+ }
+ }
+
+ clear() {
+ this._head = 0;
+ this._tail = 0;
+ this._list.fill(undefined);
+ }
+
+ _growArray() {
+ if (this._head) {
+ // copy existing data, head to end, then beginning to tail.
+ this._list = this.toArray(true);
+ this._head = 0;
+ }
+
+ // head is at 0 and array is now full, safe to extend
+ this._tail = @toLength(this._list.length);
+
+ this._list.length <<= 1;
+ this._capacityMask = (this._capacityMask << 1) | 1;
+ }
+
+ shrinkArray() {
+ this._list.length >>>= 1;
+ this._capacityMask >>>= 1;
+ }
+ }
+
+
+ return new Denqueue();
+}
+
+function newQueue()
+{
+ "use strict";
+
+ return { content: @createFIFO(), size: 0 };
+}
+
+function dequeueValue(queue)
+{
+ "use strict";
+
+ const record = queue.content.shift();
+ queue.size -= record.size;
+ // As described by spec, below case may occur due to rounding errors.
+ if (queue.size < 0)
+ queue.size = 0;
+ return record.value;
+}
+
+function enqueueValueWithSize(queue, value, size)
+{
+ "use strict";
+
+ size = @toNumber(size);
+ if (!@isFinite(size) || size < 0)
+ @throwRangeError("size has an incorrect value");
+
+ queue.content.push({ value, size });
+ queue.size += size;
+}
+
+function peekQueueValue(queue)
+{
+ "use strict";
+
+ @assert(queue.content.isNotEmpty());
+
+ return queue.peek().value;
+}
+
+function resetQueue(queue)
+{
+ "use strict";
+
+ @assert("content" in queue);
+ @assert("size" in queue);
+ queue.content.clear();
+ queue.size = 0;
+}
+
+function extractSizeAlgorithm(strategy)
+{
+ if (!("size" in strategy))
+ return () => 1;
+ const sizeAlgorithm = strategy["size"];
+ if (typeof sizeAlgorithm !== "function")
+ @throwTypeError("strategy.size must be a function");
+
+ return (chunk) => { return sizeAlgorithm(chunk); };
+}
+
+function extractHighWaterMark(strategy, defaultHWM)
+{
+ if (!("highWaterMark" in strategy))
+ return defaultHWM;
+ const highWaterMark = strategy["highWaterMark"];
+ if (@isNaN(highWaterMark) || highWaterMark < 0)
+ @throwRangeError("highWaterMark value is negative or not a number");
+
+ return @toNumber(highWaterMark);
+}
+
+function extractHighWaterMarkFromQueuingStrategyInit(init)
+{
+ "use strict";
+
+ if (!@isObject(init))
+ @throwTypeError("QueuingStrategyInit argument must be an object.");
+ const {highWaterMark} = init;
+ if (highWaterMark === @undefined)
+ @throwTypeError("QueuingStrategyInit.highWaterMark member is required.");
+
+ return @toNumber(highWaterMark);
+}
+
+function createFulfilledPromise(value)
+{
+ const promise = @newPromise();
+ @fulfillPromise(promise, value);
+ return promise;
+}
+
+function toDictionary(value, defaultValue, errorMessage)
+{
+ if (value === @undefined || value === null)
+ return defaultValue;
+ if (!@isObject(value))
+ @throwTypeError(errorMessage);
+ return value;
+}
diff --git a/src/bun.js/builtins/js/TransformStream.js b/src/bun.js/builtins/js/TransformStream.js
new file mode 100644
index 000000000..8d82d87d8
--- /dev/null
+++ b/src/bun.js/builtins/js/TransformStream.js
@@ -0,0 +1,116 @@
+/*
+ * Copyright (C) 2020 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+function initializeTransformStream()
+{
+ "use strict";
+
+ let transformer = arguments[0];
+
+ // This is the path for CreateTransformStream.
+ if (@isObject(transformer) && @getByIdDirectPrivate(transformer, "TransformStream"))
+ return this;
+
+ let writableStrategy = arguments[1];
+ let readableStrategy = arguments[2];
+
+ if (transformer === @undefined)
+ transformer = null;
+
+ if (readableStrategy === @undefined)
+ readableStrategy = { };
+
+ if (writableStrategy === @undefined)
+ writableStrategy = { };
+
+ let transformerDict = { };
+ if (transformer !== null) {
+ if ("start" in transformer) {
+ transformerDict["start"] = transformer["start"];
+ if (typeof transformerDict["start"] !== "function")
+ @throwTypeError("transformer.start should be a function");
+ }
+ if ("transform" in transformer) {
+ transformerDict["transform"] = transformer["transform"];
+ if (typeof transformerDict["transform"] !== "function")
+ @throwTypeError("transformer.transform should be a function");
+ }
+ if ("flush" in transformer) {
+ transformerDict["flush"] = transformer["flush"];
+ if (typeof transformerDict["flush"] !== "function")
+ @throwTypeError("transformer.flush should be a function");
+ }
+
+ if ("readableType" in transformer)
+ @throwRangeError("TransformStream transformer has a readableType");
+ if ("writableType" in transformer)
+ @throwRangeError("TransformStream transformer has a writableType");
+ }
+
+ const readableHighWaterMark = @extractHighWaterMark(readableStrategy, 0);
+ const readableSizeAlgorithm = @extractSizeAlgorithm(readableStrategy);
+
+ const writableHighWaterMark = @extractHighWaterMark(writableStrategy, 1);
+ const writableSizeAlgorithm = @extractSizeAlgorithm(writableStrategy);
+
+ const startPromiseCapability = @newPromiseCapability(@Promise);
+ @initializeTransformStream(this, startPromiseCapability.@promise, writableHighWaterMark, writableSizeAlgorithm, readableHighWaterMark, readableSizeAlgorithm);
+ @setUpTransformStreamDefaultControllerFromTransformer(this, transformer, transformerDict);
+
+ if ("start" in transformerDict) {
+ const controller = @getByIdDirectPrivate(this, "controller");
+ const startAlgorithm = () => @promiseInvokeOrNoopMethodNoCatch(transformer, transformerDict["start"], [controller]);
+ startAlgorithm().@then(() => {
+ // FIXME: We probably need to resolve start promise with the result of the start algorithm.
+ startPromiseCapability.@resolve.@call();
+ }, (error) => {
+ startPromiseCapability.@reject.@call(@undefined, error);
+ });
+ } else
+ startPromiseCapability.@resolve.@call();
+
+ return this;
+}
+
+@getter
+function readable()
+{
+ "use strict";
+
+ if (!@isTransformStream(this))
+ throw @makeThisTypeError("TransformStream", "readable");
+
+ return @getByIdDirectPrivate(this, "readable");
+}
+
+function writable()
+{
+ "use strict";
+
+ if (!@isTransformStream(this))
+ throw @makeThisTypeError("TransformStream", "writable");
+
+ return @getByIdDirectPrivate(this, "writable");
+}
diff --git a/src/bun.js/builtins/js/TransformStreamDefaultController.js b/src/bun.js/builtins/js/TransformStreamDefaultController.js
new file mode 100644
index 000000000..5ed7d0dfa
--- /dev/null
+++ b/src/bun.js/builtins/js/TransformStreamDefaultController.js
@@ -0,0 +1,76 @@
+/*
+ * Copyright (C) 2020 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+function initializeTransformStreamDefaultController()
+{
+ "use strict";
+
+ return this;
+}
+
+@getter
+function desiredSize()
+{
+ "use strict";
+
+ if (!@isTransformStreamDefaultController(this))
+ throw @makeThisTypeError("TransformStreamDefaultController", "enqueue");
+
+ const stream = @getByIdDirectPrivate(this, "stream");
+ const readable = @getByIdDirectPrivate(stream, "readable");
+ const readableController = @getByIdDirectPrivate(readable, "readableStreamController");
+
+ return @readableStreamDefaultControllerGetDesiredSize(readableController);
+}
+
+function enqueue(chunk)
+{
+ "use strict";
+
+ if (!@isTransformStreamDefaultController(this))
+ throw @makeThisTypeError("TransformStreamDefaultController", "enqueue");
+
+ @transformStreamDefaultControllerEnqueue(this, chunk);
+}
+
+function error(e)
+{
+ "use strict";
+
+ if (!@isTransformStreamDefaultController(this))
+ throw @makeThisTypeError("TransformStreamDefaultController", "error");
+
+ @transformStreamDefaultControllerError(this, e);
+}
+
+function terminate()
+{
+ "use strict";
+
+ if (!@isTransformStreamDefaultController(this))
+ throw @makeThisTypeError("TransformStreamDefaultController", "terminate");
+
+ @transformStreamDefaultControllerTerminate(this);
+}
diff --git a/src/bun.js/builtins/js/TransformStreamInternals.js b/src/bun.js/builtins/js/TransformStreamInternals.js
new file mode 100644
index 000000000..4263e3991
--- /dev/null
+++ b/src/bun.js/builtins/js/TransformStreamInternals.js
@@ -0,0 +1,350 @@
+/*
+ * Copyright (C) 2020 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+// @internal
+
+function isTransformStream(stream)
+{
+ "use strict";
+
+ return @isObject(stream) && !!@getByIdDirectPrivate(stream, "readable");
+}
+
+function isTransformStreamDefaultController(controller)
+{
+ "use strict";
+
+ return @isObject(controller) && !!@getByIdDirectPrivate(controller, "transformAlgorithm");
+}
+
+function createTransformStream(startAlgorithm, transformAlgorithm, flushAlgorithm, writableHighWaterMark, writableSizeAlgorithm, readableHighWaterMark, readableSizeAlgorithm)
+{
+ if (writableHighWaterMark === @undefined)
+ writableHighWaterMark = 1;
+ if (writableSizeAlgorithm === @undefined)
+ writableSizeAlgorithm = () => 1;
+ if (readableHighWaterMark === @undefined)
+ readableHighWaterMark = 0;
+ if (readableSizeAlgorithm === @undefined)
+ readableSizeAlgorithm = () => 1;
+ @assert(writableHighWaterMark >= 0);
+ @assert(readableHighWaterMark >= 0);
+
+ const transform = {};
+ @putByIdDirectPrivate(transform, "TransformStream", true);
+
+ const stream = new @TransformStream(transform);
+ const startPromiseCapability = @newPromiseCapability(@Promise);
+ @initializeTransformStream(stream, startPromiseCapability.@promise, writableHighWaterMark, writableSizeAlgorithm, readableHighWaterMark, readableSizeAlgorithm);
+
+ const controller = new @TransformStreamDefaultController();
+ @setUpTransformStreamDefaultController(stream, controller, transformAlgorithm, flushAlgorithm);
+
+ startAlgorithm().@then(() => {
+ startPromiseCapability.@resolve.@call();
+ }, (error) => {
+ startPromiseCapability.@reject.@call(@undefined, error);
+ });
+
+ return stream;
+}
+
+function initializeTransformStream(stream, startPromise, writableHighWaterMark, writableSizeAlgorithm, readableHighWaterMark, readableSizeAlgorithm)
+{
+ "use strict";
+
+ const startAlgorithm = () => { return startPromise; };
+ const writeAlgorithm = (chunk) => { return @transformStreamDefaultSinkWriteAlgorithm(stream, chunk); }
+ const abortAlgorithm = (reason) => { return @transformStreamDefaultSinkAbortAlgorithm(stream, reason); }
+ const closeAlgorithm = () => { return @transformStreamDefaultSinkCloseAlgorithm(stream); }
+ const writable = @createWritableStream(startAlgorithm, writeAlgorithm, closeAlgorithm, abortAlgorithm, writableHighWaterMark, writableSizeAlgorithm);
+
+ const pullAlgorithm = () => { return @transformStreamDefaultSourcePullAlgorithm(stream); };
+ const cancelAlgorithm = (reason) => {
+ @transformStreamErrorWritableAndUnblockWrite(stream, reason);
+ return @Promise.@resolve();
+ };
+ const underlyingSource = { };
+ @putByIdDirectPrivate(underlyingSource, "start", startAlgorithm);
+ @putByIdDirectPrivate(underlyingSource, "pull", pullAlgorithm);
+ @putByIdDirectPrivate(underlyingSource, "cancel", cancelAlgorithm);
+ const options = { };
+ @putByIdDirectPrivate(options, "size", readableSizeAlgorithm);
+ @putByIdDirectPrivate(options, "highWaterMark", readableHighWaterMark);
+ const readable = new @ReadableStream(underlyingSource, options);
+
+ // The writable to expose to JS through writable getter.
+ @putByIdDirectPrivate(stream, "writable", writable);
+ // The writable to use for the actual transform algorithms.
+ @putByIdDirectPrivate(stream, "internalWritable", @getInternalWritableStream(writable));
+
+ @putByIdDirectPrivate(stream, "readable", readable);
+ @putByIdDirectPrivate(stream, "backpressure", @undefined);
+ @putByIdDirectPrivate(stream, "backpressureChangePromise", @undefined);
+
+ @transformStreamSetBackpressure(stream, true);
+ @putByIdDirectPrivate(stream, "controller", @undefined);
+}
+
+function transformStreamError(stream, e)
+{
+ "use strict";
+
+ const readable = @getByIdDirectPrivate(stream, "readable");
+ const readableController = @getByIdDirectPrivate(readable, "readableStreamController");
+ @readableStreamDefaultControllerError(readableController, e);
+
+ @transformStreamErrorWritableAndUnblockWrite(stream, e);
+}
+
+function transformStreamErrorWritableAndUnblockWrite(stream, e)
+{
+ "use strict";
+
+ @transformStreamDefaultControllerClearAlgorithms(@getByIdDirectPrivate(stream, "controller"));
+
+ const writable = @getByIdDirectPrivate(stream, "internalWritable");
+ @writableStreamDefaultControllerErrorIfNeeded(@getByIdDirectPrivate(writable, "controller"), e);
+
+ if (@getByIdDirectPrivate(stream, "backpressure"))
+ @transformStreamSetBackpressure(stream, false);
+}
+
+function transformStreamSetBackpressure(stream, backpressure)
+{
+ "use strict";
+
+ @assert(@getByIdDirectPrivate(stream, "backpressure") !== backpressure);
+
+ const backpressureChangePromise = @getByIdDirectPrivate(stream, "backpressureChangePromise");
+ if (backpressureChangePromise !== @undefined)
+ backpressureChangePromise.@resolve.@call();
+
+ @putByIdDirectPrivate(stream, "backpressureChangePromise", @newPromiseCapability(@Promise));
+ @putByIdDirectPrivate(stream, "backpressure", backpressure);
+}
+
+function setUpTransformStreamDefaultController(stream, controller, transformAlgorithm, flushAlgorithm)
+{
+ "use strict";
+
+ @assert(@isTransformStream(stream));
+ @assert(@getByIdDirectPrivate(stream, "controller") === @undefined);
+
+ @putByIdDirectPrivate(controller, "stream", stream);
+ @putByIdDirectPrivate(stream, "controller", controller);
+ @putByIdDirectPrivate(controller, "transformAlgorithm", transformAlgorithm);
+ @putByIdDirectPrivate(controller, "flushAlgorithm", flushAlgorithm);
+}
+
+
+function setUpTransformStreamDefaultControllerFromTransformer(stream, transformer, transformerDict)
+{
+ "use strict";
+
+ const controller = new @TransformStreamDefaultController();
+ let transformAlgorithm = (chunk) => {
+ try {
+ @transformStreamDefaultControllerEnqueue(controller, chunk);
+ } catch (e) {
+ return @Promise.@reject(e);
+ }
+ return @Promise.@resolve();
+ };
+ let flushAlgorithm = () => { return @Promise.@resolve(); };
+
+ if ("transform" in transformerDict)
+ transformAlgorithm = (chunk) => {
+ return @promiseInvokeOrNoopMethod(transformer, transformerDict["transform"], [chunk, controller]);
+ };
+
+ if ("flush" in transformerDict) {
+ flushAlgorithm = () => {
+ return @promiseInvokeOrNoopMethod(transformer, transformerDict["flush"], [controller]);
+ };
+ }
+
+ @setUpTransformStreamDefaultController(stream, controller, transformAlgorithm, flushAlgorithm);
+}
+
+function transformStreamDefaultControllerClearAlgorithms(controller)
+{
+ "use strict";
+
+ // We set transformAlgorithm to true to allow GC but keep the isTransformStreamDefaultController check.
+ @putByIdDirectPrivate(controller, "transformAlgorithm", true);
+ @putByIdDirectPrivate(controller, "flushAlgorithm", @undefined);
+}
+
+function transformStreamDefaultControllerEnqueue(controller, chunk)
+{
+ "use strict";
+
+ const stream = @getByIdDirectPrivate(controller, "stream");
+ const readable = @getByIdDirectPrivate(stream, "readable");
+ const readableController = @getByIdDirectPrivate(readable, "readableStreamController");
+
+ @assert(readableController !== @undefined);
+ if (!@readableStreamDefaultControllerCanCloseOrEnqueue(readableController))
+ @throwTypeError("TransformStream.readable cannot close or enqueue");
+
+ try {
+ @readableStreamDefaultControllerEnqueue(readableController, chunk);
+ } catch (e) {
+ @transformStreamErrorWritableAndUnblockWrite(stream, e);
+ throw @getByIdDirectPrivate(readable, "storedError");
+ }
+
+ const backpressure = !@readableStreamDefaultControllerShouldCallPull(readableController);
+ if (backpressure !== @getByIdDirectPrivate(stream, "backpressure")) {
+ @assert(backpressure);
+ @transformStreamSetBackpressure(stream, true);
+ }
+}
+
+function transformStreamDefaultControllerError(controller, e)
+{
+ "use strict";
+
+ @transformStreamError(@getByIdDirectPrivate(controller, "stream"), e);
+}
+
+function transformStreamDefaultControllerPerformTransform(controller, chunk)
+{
+ "use strict";
+
+ const promiseCapability = @newPromiseCapability(@Promise);
+
+ const transformPromise = @getByIdDirectPrivate(controller, "transformAlgorithm").@call(@undefined, chunk);
+ transformPromise.@then(() => {
+ promiseCapability.@resolve();
+ }, (r) => {
+ @transformStreamError(@getByIdDirectPrivate(controller, "stream"), r);
+ promiseCapability.@reject.@call(@undefined, r);
+ });
+ return promiseCapability.@promise;
+}
+
+function transformStreamDefaultControllerTerminate(controller)
+{
+ "use strict";
+
+ const stream = @getByIdDirectPrivate(controller, "stream");
+ const readable = @getByIdDirectPrivate(stream, "readable");
+ const readableController = @getByIdDirectPrivate(readable, "readableStreamController");
+
+ // FIXME: Update readableStreamDefaultControllerClose to make this check.
+ if (@readableStreamDefaultControllerCanCloseOrEnqueue(readableController))
+ @readableStreamDefaultControllerClose(readableController);
+ const error = @makeTypeError("the stream has been terminated");
+ @transformStreamErrorWritableAndUnblockWrite(stream, error);
+}
+
+function transformStreamDefaultSinkWriteAlgorithm(stream, chunk)
+{
+ "use strict";
+
+ const writable = @getByIdDirectPrivate(stream, "internalWritable");
+
+ @assert(@getByIdDirectPrivate(writable, "state") === "writable");
+
+ const controller = @getByIdDirectPrivate(stream, "controller");
+
+ if (@getByIdDirectPrivate(stream, "backpressure")) {
+ const promiseCapability = @newPromiseCapability(@Promise);
+
+ const backpressureChangePromise = @getByIdDirectPrivate(stream, "backpressureChangePromise");
+ @assert(backpressureChangePromise !== @undefined);
+ backpressureChangePromise.@promise.@then(() => {
+ const state = @getByIdDirectPrivate(writable, "state");
+ if (state === "erroring") {
+ promiseCapability.@reject.@call(@undefined, @getByIdDirectPrivate(writable, "storedError"));
+ return;
+ }
+
+ @assert(state === "writable");
+ @transformStreamDefaultControllerPerformTransform(controller, chunk).@then(() => {
+ promiseCapability.@resolve();
+ }, (e) => {
+ promiseCapability.@reject.@call(@undefined, e);
+ });
+ }, (e) => {
+ promiseCapability.@reject.@call(@undefined, e);
+ });
+
+ return promiseCapability.@promise;
+ }
+ return @transformStreamDefaultControllerPerformTransform(controller, chunk);
+}
+
+function transformStreamDefaultSinkAbortAlgorithm(stream, reason)
+{
+ "use strict";
+
+ @transformStreamError(stream, reason);
+ return @Promise.@resolve();
+}
+
+function transformStreamDefaultSinkCloseAlgorithm(stream)
+{
+ "use strict";
+ const readable = @getByIdDirectPrivate(stream, "readable");
+ const controller = @getByIdDirectPrivate(stream, "controller");
+ const readableController = @getByIdDirectPrivate(readable, "readableStreamController");
+
+ const flushAlgorithm = @getByIdDirectPrivate(controller, "flushAlgorithm");
+ @assert(flushAlgorithm !== @undefined);
+ const flushPromise = @getByIdDirectPrivate(controller, "flushAlgorithm").@call();
+ @transformStreamDefaultControllerClearAlgorithms(controller);
+
+ const promiseCapability = @newPromiseCapability(@Promise);
+ flushPromise.@then(() => {
+ if (@getByIdDirectPrivate(readable, "state") === @streamErrored) {
+ promiseCapability.@reject.@call(@undefined, @getByIdDirectPrivate(readable, "storedError"));
+ return;
+ }
+
+ // FIXME: Update readableStreamDefaultControllerClose to make this check.
+ if (@readableStreamDefaultControllerCanCloseOrEnqueue(readableController))
+ @readableStreamDefaultControllerClose(readableController);
+ promiseCapability.@resolve();
+ }, (r) => {
+ @transformStreamError(@getByIdDirectPrivate(controller, "stream"), r);
+ promiseCapability.@reject.@call(@undefined, @getByIdDirectPrivate(readable, "storedError"));
+ });
+ return promiseCapability.@promise;
+}
+
+function transformStreamDefaultSourcePullAlgorithm(stream)
+{
+ "use strict";
+
+ @assert(@getByIdDirectPrivate(stream, "backpressure"));
+ @assert(@getByIdDirectPrivate(stream, "backpressureChangePromise") !== @undefined);
+
+ @transformStreamSetBackpressure(stream, false);
+
+ return @getByIdDirectPrivate(stream, "backpressureChangePromise").@promise;
+}
diff --git a/src/bun.js/builtins/js/WritableStreamDefaultController.js b/src/bun.js/builtins/js/WritableStreamDefaultController.js
new file mode 100644
index 000000000..8c42212e0
--- /dev/null
+++ b/src/bun.js/builtins/js/WritableStreamDefaultController.js
@@ -0,0 +1,56 @@
+/*
+ * Copyright (C) 2020 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+
+function initializeWritableStreamDefaultController()
+{
+ "use strict";
+
+ @putByIdDirectPrivate(this, "queue", @newQueue());
+ @putByIdDirectPrivate(this, "abortSteps", (reason) => {
+ const result = @getByIdDirectPrivate(this, "abortAlgorithm").@call(@undefined, reason);
+ @writableStreamDefaultControllerClearAlgorithms(this);
+ return result;
+ });
+
+ @putByIdDirectPrivate(this, "errorSteps", () => {
+ @resetQueue(@getByIdDirectPrivate(this, "queue"));
+ });
+
+ return this;
+}
+
+function error(e)
+{
+ "use strict";
+
+ if (@getByIdDirectPrivate(this, "abortSteps") === @undefined)
+ throw @makeThisTypeError("WritableStreamDefaultController", "error");
+
+ const stream = @getByIdDirectPrivate(this, "stream");
+ if (@getByIdDirectPrivate(stream, "state") !== "writable")
+ return;
+ @writableStreamDefaultControllerError(this, e);
+}
diff --git a/src/bun.js/builtins/js/WritableStreamDefaultWriter.js b/src/bun.js/builtins/js/WritableStreamDefaultWriter.js
new file mode 100644
index 000000000..69a953fc3
--- /dev/null
+++ b/src/bun.js/builtins/js/WritableStreamDefaultWriter.js
@@ -0,0 +1,135 @@
+/*
+ * Copyright (C) 2020 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+function initializeWritableStreamDefaultWriter(stream)
+{
+ "use strict";
+
+ // stream can be a WritableStream if WritableStreamDefaultWriter constructor is called directly from JS
+ // or an InternalWritableStream in other code paths.
+ const internalStream = @getInternalWritableStream(stream);
+ if (internalStream)
+ stream = internalStream;
+
+ if (!@isWritableStream(stream))
+ @throwTypeError("WritableStreamDefaultWriter constructor takes a WritableStream");
+
+ @setUpWritableStreamDefaultWriter(this, stream);
+ return this;
+}
+
+@getter
+function closed()
+{
+ "use strict";
+
+ if (!@isWritableStreamDefaultWriter(this))
+ return @Promise.@reject(@makeGetterTypeError("WritableStreamDefaultWriter", "closed"));
+
+ return @getByIdDirectPrivate(this, "closedPromise").@promise;
+}
+
+@getter
+function desiredSize()
+{
+ "use strict";
+
+ if (!@isWritableStreamDefaultWriter(this))
+ throw @makeThisTypeError("WritableStreamDefaultWriter", "desiredSize");
+
+ if (@getByIdDirectPrivate(this, "stream") === @undefined)
+ @throwTypeError("WritableStreamDefaultWriter has no stream");
+
+ return @writableStreamDefaultWriterGetDesiredSize(this);
+}
+
+@getter
+function ready()
+{
+ "use strict";
+
+ if (!@isWritableStreamDefaultWriter(this))
+ return @Promise.@reject(@makeThisTypeError("WritableStreamDefaultWriter", "ready"));
+
+ return @getByIdDirectPrivate(this, "readyPromise").@promise;
+}
+
+function abort(reason)
+{
+ "use strict";
+
+ if (!@isWritableStreamDefaultWriter(this))
+ return @Promise.@reject(@makeThisTypeError("WritableStreamDefaultWriter", "abort"));
+
+ if (@getByIdDirectPrivate(this, "stream") === @undefined)
+ return @Promise.@reject(@makeTypeError("WritableStreamDefaultWriter has no stream"));
+
+ return @writableStreamDefaultWriterAbort(this, reason);
+}
+
+function close()
+{
+ "use strict";
+
+ if (!@isWritableStreamDefaultWriter(this))
+ return @Promise.@reject(@makeThisTypeError("WritableStreamDefaultWriter", "close"));
+
+ const stream = @getByIdDirectPrivate(this, "stream");
+ if (stream === @undefined)
+ return @Promise.@reject(@makeTypeError("WritableStreamDefaultWriter has no stream"));
+
+ if (@writableStreamCloseQueuedOrInFlight(stream))
+ return @Promise.@reject(@makeTypeError("WritableStreamDefaultWriter is being closed"));
+
+ return @writableStreamDefaultWriterClose(this);
+}
+
+function releaseLock()
+{
+ "use strict";
+
+ if (!@isWritableStreamDefaultWriter(this))
+ throw @makeThisTypeError("WritableStreamDefaultWriter", "releaseLock");
+
+ const stream = @getByIdDirectPrivate(this, "stream");
+ if (stream === @undefined)
+ return;
+
+ @assert(@getByIdDirectPrivate(stream, "writer") !== @undefined);
+ @writableStreamDefaultWriterRelease(this);
+}
+
+function write(chunk)
+{
+ "use strict";
+
+ if (!@isWritableStreamDefaultWriter(this))
+ return @Promise.@reject(@makeThisTypeError("WritableStreamDefaultWriter", "write"));
+
+ if (@getByIdDirectPrivate(this, "stream") === @undefined)
+ return @Promise.@reject(@makeTypeError("WritableStreamDefaultWriter has no stream"));
+
+ return @writableStreamDefaultWriterWrite(this, chunk);
+}
diff --git a/src/bun.js/builtins/js/WritableStreamInternals.js b/src/bun.js/builtins/js/WritableStreamInternals.js
new file mode 100644
index 000000000..5a97155f2
--- /dev/null
+++ b/src/bun.js/builtins/js/WritableStreamInternals.js
@@ -0,0 +1,856 @@
+/*
+ * Copyright (C) 2015 Canon Inc.
+ * Copyright (C) 2015 Igalia
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+// @internal
+
+function isWritableStream(stream)
+{
+ "use strict";
+
+ return @isObject(stream) && !!@getByIdDirectPrivate(stream, "underlyingSink");
+}
+
+function isWritableStreamDefaultWriter(writer)
+{
+ "use strict";
+
+ return @isObject(writer) && !!@getByIdDirectPrivate(writer, "closedPromise");
+}
+
+function acquireWritableStreamDefaultWriter(stream)
+{
+ return new @WritableStreamDefaultWriter(stream);
+}
+
+// https://streams.spec.whatwg.org/#create-writable-stream
+function createWritableStream(startAlgorithm, writeAlgorithm, closeAlgorithm, abortAlgorithm, highWaterMark, sizeAlgorithm)
+{
+ @assert(typeof highWaterMark === "number" && !@isNaN(highWaterMark) && highWaterMark >= 0);
+
+ const internalStream = { };
+ @initializeWritableStreamSlots(internalStream, { });
+ const controller = new @WritableStreamDefaultController();
+
+ @setUpWritableStreamDefaultController(internalStream, controller, startAlgorithm, writeAlgorithm, closeAlgorithm, abortAlgorithm, highWaterMark, sizeAlgorithm);
+
+ return @createWritableStreamFromInternal(internalStream);
+}
+
+function createInternalWritableStreamFromUnderlyingSink(underlyingSink, strategy)
+{
+ "use strict";
+
+ const stream = { };
+
+ if (underlyingSink === @undefined)
+ underlyingSink = { };
+
+ if (strategy === @undefined)
+ strategy = { };
+
+ if (!@isObject(underlyingSink))
+ @throwTypeError("WritableStream constructor takes an object as first argument");
+
+ if ("type" in underlyingSink)
+ @throwRangeError("Invalid type is specified");
+
+ const sizeAlgorithm = @extractSizeAlgorithm(strategy);
+ const highWaterMark = @extractHighWaterMark(strategy, 1);
+
+ const underlyingSinkDict = { };
+ if ("start" in underlyingSink) {
+ underlyingSinkDict["start"] = underlyingSink["start"];
+ if (typeof underlyingSinkDict["start"] !== "function")
+ @throwTypeError("underlyingSink.start should be a function");
+ }
+ if ("write" in underlyingSink) {
+ underlyingSinkDict["write"] = underlyingSink["write"];
+ if (typeof underlyingSinkDict["write"] !== "function")
+ @throwTypeError("underlyingSink.write should be a function");
+ }
+ if ("close" in underlyingSink) {
+ underlyingSinkDict["close"] = underlyingSink["close"];
+ if (typeof underlyingSinkDict["close"] !== "function")
+ @throwTypeError("underlyingSink.close should be a function");
+ }
+ if ("abort" in underlyingSink) {
+ underlyingSinkDict["abort"] = underlyingSink["abort"];
+ if (typeof underlyingSinkDict["abort"] !== "function")
+ @throwTypeError("underlyingSink.abort should be a function");
+ }
+
+ @initializeWritableStreamSlots(stream, underlyingSink);
+ @setUpWritableStreamDefaultControllerFromUnderlyingSink(stream, underlyingSink, underlyingSinkDict, highWaterMark, sizeAlgorithm);
+
+ return stream;
+}
+
+function initializeWritableStreamSlots(stream, underlyingSink)
+{ "use strict";
+
+ @putByIdDirectPrivate(stream, "state", "writable");
+ @putByIdDirectPrivate(stream, "storedError", @undefined);
+ @putByIdDirectPrivate(stream, "writer", @undefined);
+ @putByIdDirectPrivate(stream, "controller", @undefined);
+ @putByIdDirectPrivate(stream, "inFlightWriteRequest", @undefined);
+ @putByIdDirectPrivate(stream, "closeRequest", @undefined);
+ @putByIdDirectPrivate(stream, "inFlightCloseRequest", @undefined);
+ @putByIdDirectPrivate(stream, "pendingAbortRequest", @undefined);
+ @putByIdDirectPrivate(stream, "writeRequests", @createFIFO());
+ @putByIdDirectPrivate(stream, "backpressure", false);
+ @putByIdDirectPrivate(stream, "underlyingSink", underlyingSink);
+}
+
+function writableStreamCloseForBindings(stream)
+{ "use strict";
+
+ if (@isWritableStreamLocked(stream))
+ return @Promise.@reject(@makeTypeError("WritableStream.close method can only be used on non locked WritableStream"));
+
+ if (@writableStreamCloseQueuedOrInFlight(stream))
+ return @Promise.@reject(@makeTypeError("WritableStream.close method can only be used on a being close WritableStream"));
+
+ return @writableStreamClose(stream);
+}
+
+function writableStreamAbortForBindings(stream, reason)
+{ "use strict";
+
+ if (@isWritableStreamLocked(stream))
+ return @Promise.@reject(@makeTypeError("WritableStream.abort method can only be used on non locked WritableStream"));
+
+ return @writableStreamAbort(stream, reason);
+}
+
+function isWritableStreamLocked(stream)
+{ "use strict";
+
+ return @getByIdDirectPrivate(stream, "writer") !== @undefined;
+}
+
+function setUpWritableStreamDefaultWriter(writer, stream)
+{ "use strict";
+
+ if (@isWritableStreamLocked(stream))
+ @throwTypeError("WritableStream is locked");
+
+ @putByIdDirectPrivate(writer, "stream", stream);
+ @putByIdDirectPrivate(stream, "writer", writer);
+
+ const readyPromiseCapability = @newPromiseCapability(@Promise);
+ const closedPromiseCapability = @newPromiseCapability(@Promise);
+ @putByIdDirectPrivate(writer, "readyPromise", readyPromiseCapability);
+ @putByIdDirectPrivate(writer, "closedPromise", closedPromiseCapability);
+
+ const state = @getByIdDirectPrivate(stream, "state");
+ if (state === "writable") {
+ if (@writableStreamCloseQueuedOrInFlight(stream) || !@getByIdDirectPrivate(stream, "backpressure"))
+ readyPromiseCapability.@resolve.@call();
+ } else if (state === "erroring") {
+ readyPromiseCapability.@reject.@call(@undefined, @getByIdDirectPrivate(stream, "storedError"));
+ @markPromiseAsHandled(readyPromiseCapability.@promise);
+ } else if (state === "closed") {
+ readyPromiseCapability.@resolve.@call();
+ closedPromiseCapability.@resolve.@call();
+ } else {
+ @assert(state === "errored");
+ const storedError = @getByIdDirectPrivate(stream, "storedError");
+ readyPromiseCapability.@reject.@call(@undefined, storedError);
+ @markPromiseAsHandled(readyPromiseCapability.@promise);
+ closedPromiseCapability.@reject.@call(@undefined, storedError);
+ @markPromiseAsHandled(closedPromiseCapability.@promise);
+ }
+}
+
+function writableStreamAbort(stream, reason)
+{
+ "use strict";
+ const state = @getByIdDirectPrivate(stream, "state");
+ if (state === "closed" || state === "errored")
+ return @Promise.@resolve();
+
+ const pendingAbortRequest = @getByIdDirectPrivate(stream, "pendingAbortRequest");
+ if (pendingAbortRequest !== @undefined)
+ return pendingAbortRequest.promise.@promise;
+
+ @assert(state === "writable" || state === "erroring");
+ let wasAlreadyErroring = false;
+ if (state === "erroring") {
+ wasAlreadyErroring = true;
+ reason = @undefined;
+ }
+
+ const abortPromiseCapability = @newPromiseCapability(@Promise);
+ @putByIdDirectPrivate(stream, "pendingAbortRequest", { promise : abortPromiseCapability, reason : reason, wasAlreadyErroring : wasAlreadyErroring });
+
+ if (!wasAlreadyErroring)
+ @writableStreamStartErroring(stream, reason);
+ return abortPromiseCapability.@promise;
+}
+
+function writableStreamClose(stream)
+{
+ "use strict";
+
+ const state = @getByIdDirectPrivate(stream, "state");
+ if (state === "closed" || state === "errored")
+ return @Promise.@reject(@makeTypeError("Cannot close a writable stream that is closed or errored"));
+
+ @assert(state === "writable" || state === "erroring");
+ @assert(!@writableStreamCloseQueuedOrInFlight(stream));
+
+ const closePromiseCapability = @newPromiseCapability(@Promise);
+ @putByIdDirectPrivate(stream, "closeRequest", closePromiseCapability);
+
+ const writer = @getByIdDirectPrivate(stream, "writer");
+ if (writer !== @undefined && @getByIdDirectPrivate(stream, "backpressure") && state === "writable")
+ @getByIdDirectPrivate(writer, "readyPromise").@resolve.@call();
+
+ @writableStreamDefaultControllerClose(@getByIdDirectPrivate(stream, "controller"));
+
+ return closePromiseCapability.@promise;
+}
+
+function writableStreamAddWriteRequest(stream)
+{
+ "use strict";
+
+ @assert(@isWritableStreamLocked(stream))
+ @assert(@getByIdDirectPrivate(stream, "state") === "writable");
+
+ const writePromiseCapability = @newPromiseCapability(@Promise);
+ const writeRequests = @getByIdDirectPrivate(stream, "writeRequests");
+ writeRequests.push(writePromiseCapability);
+ return writePromiseCapability.@promise;
+}
+
+function writableStreamCloseQueuedOrInFlight(stream)
+{
+ "use strict";
+
+ return @getByIdDirectPrivate(stream, "closeRequest") !== @undefined || @getByIdDirectPrivate(stream, "inFlightCloseRequest") !== @undefined;
+}
+
+function writableStreamDealWithRejection(stream, error)
+{
+ "use strict";
+
+ const state = @getByIdDirectPrivate(stream, "state");
+ if (state === "writable") {
+ @writableStreamStartErroring(stream, error);
+ return;
+ }
+
+ @assert(state === "erroring");
+ @writableStreamFinishErroring(stream);
+}
+
+function writableStreamFinishErroring(stream)
+{
+ "use strict";
+
+ @assert(@getByIdDirectPrivate(stream, "state") === "erroring");
+ @assert(!@writableStreamHasOperationMarkedInFlight(stream));
+
+ @putByIdDirectPrivate(stream, "state", "errored");
+
+ const controller = @getByIdDirectPrivate(stream, "controller");
+ @getByIdDirectPrivate(controller, "errorSteps").@call();
+
+ const storedError = @getByIdDirectPrivate(stream, "storedError");
+ const requests = @getByIdDirectPrivate(stream, "writeRequests");
+ for (var request = requests.shift(); request; request = requests.shift())
+ request.@reject.@call(@undefined, storedError);
+
+ // TODO: is this still necessary?
+ @putByIdDirectPrivate(stream, "writeRequests", @createFIFO());
+
+ const abortRequest = @getByIdDirectPrivate(stream, "pendingAbortRequest");
+ if (abortRequest === @undefined) {
+ @writableStreamRejectCloseAndClosedPromiseIfNeeded(stream);
+ return;
+ }
+
+ @putByIdDirectPrivate(stream, "pendingAbortRequest", @undefined);
+ if (abortRequest.wasAlreadyErroring) {
+ abortRequest.promise.@reject.@call(@undefined, storedError);
+ @writableStreamRejectCloseAndClosedPromiseIfNeeded(stream);
+ return;
+ }
+
+ @getByIdDirectPrivate(controller, "abortSteps").@call(@undefined, abortRequest.reason).@then(() => {
+ abortRequest.promise.@resolve.@call();
+ @writableStreamRejectCloseAndClosedPromiseIfNeeded(stream);
+ }, (reason) => {
+ abortRequest.promise.@reject.@call(@undefined, reason);
+ @writableStreamRejectCloseAndClosedPromiseIfNeeded(stream);
+ });
+}
+
+function writableStreamFinishInFlightClose(stream)
+{
+ "use strict";
+
+ const inFlightCloseRequest = @getByIdDirectPrivate(stream, "inFlightCloseRequest");
+ inFlightCloseRequest.@resolve.@call();
+
+ @putByIdDirectPrivate(stream, "inFlightCloseRequest", @undefined);
+
+ const state = @getByIdDirectPrivate(stream, "state");
+ @assert(state === "writable" || state === "erroring");
+
+ if (state === "erroring") {
+ @putByIdDirectPrivate(stream, "storedError", @undefined);
+ const abortRequest = @getByIdDirectPrivate(stream, "pendingAbortRequest");
+ if (abortRequest !== @undefined) {
+ abortRequest.promise.@resolve.@call();
+ @putByIdDirectPrivate(stream, "pendingAbortRequest", @undefined);
+ }
+ }
+
+ @putByIdDirectPrivate(stream, "state", "closed");
+
+ const writer = @getByIdDirectPrivate(stream, "writer");
+ if (writer !== @undefined)
+ @getByIdDirectPrivate(writer, "closedPromise").@resolve.@call();
+
+ @assert(@getByIdDirectPrivate(stream, "pendingAbortRequest") === @undefined);
+ @assert(@getByIdDirectPrivate(stream, "storedError") === @undefined);
+}
+
+function writableStreamFinishInFlightCloseWithError(stream, error)
+{
+ "use strict";
+
+ const inFlightCloseRequest = @getByIdDirectPrivate(stream, "inFlightCloseRequest");
+ @assert(inFlightCloseRequest !== @undefined);
+ inFlightCloseRequest.@reject.@call(@undefined, error);
+
+ @putByIdDirectPrivate(stream, "inFlightCloseRequest", @undefined);
+
+ const state = @getByIdDirectPrivate(stream, "state");
+ @assert(state === "writable" || state === "erroring");
+
+ const abortRequest = @getByIdDirectPrivate(stream, "pendingAbortRequest");
+ if (abortRequest !== @undefined) {
+ abortRequest.promise.@reject.@call(@undefined, error);
+ @putByIdDirectPrivate(stream, "pendingAbortRequest", @undefined);
+ }
+
+ @writableStreamDealWithRejection(stream, error);
+}
+
+function writableStreamFinishInFlightWrite(stream)
+{
+ "use strict";
+
+ const inFlightWriteRequest = @getByIdDirectPrivate(stream, "inFlightWriteRequest");
+ @assert(inFlightWriteRequest !== @undefined);
+ inFlightWriteRequest.@resolve.@call();
+
+ @putByIdDirectPrivate(stream, "inFlightWriteRequest", @undefined);
+}
+
+function writableStreamFinishInFlightWriteWithError(stream, error)
+{
+ "use strict";
+
+ const inFlightWriteRequest = @getByIdDirectPrivate(stream, "inFlightWriteRequest");
+ @assert(inFlightWriteRequest !== @undefined);
+ inFlightWriteRequest.@reject.@call(@undefined, error);
+
+ @putByIdDirectPrivate(stream, "inFlightWriteRequest", @undefined);
+
+ const state = @getByIdDirectPrivate(stream, "state");
+ @assert(state === "writable" || state === "erroring");
+
+ @writableStreamDealWithRejection(stream, error);
+}
+
+function writableStreamHasOperationMarkedInFlight(stream)
+{
+ "use strict";
+
+ return @getByIdDirectPrivate(stream, "inFlightWriteRequest") !== @undefined || @getByIdDirectPrivate(stream, "inFlightCloseRequest") !== @undefined;
+}
+
+function writableStreamMarkCloseRequestInFlight(stream)
+{
+ "use strict";
+
+ const closeRequest = @getByIdDirectPrivate(stream, "closeRequest");
+ @assert(@getByIdDirectPrivate(stream, "inFlightCloseRequest") === @undefined);
+ @assert(closeRequest !== @undefined);
+
+ @putByIdDirectPrivate(stream, "inFlightCloseRequest", closeRequest);
+ @putByIdDirectPrivate(stream, "closeRequest", @undefined);
+}
+
+function writableStreamMarkFirstWriteRequestInFlight(stream)
+{
+ "use strict";
+
+ const writeRequests = @getByIdDirectPrivate(stream, "writeRequests");
+ @assert(@getByIdDirectPrivate(stream, "inFlightWriteRequest") === @undefined);
+ @assert(writeRequests.isNotEmpty());
+
+ const writeRequest = writeRequests.shift();
+ @putByIdDirectPrivate(stream, "inFlightWriteRequest", writeRequest);
+}
+
+function writableStreamRejectCloseAndClosedPromiseIfNeeded(stream)
+{
+ "use strict";
+
+ @assert(@getByIdDirectPrivate(stream, "state") === "errored");
+
+ const storedError = @getByIdDirectPrivate(stream, "storedError");
+
+ const closeRequest = @getByIdDirectPrivate(stream, "closeRequest");
+ if (closeRequest !== @undefined) {
+ @assert(@getByIdDirectPrivate(stream, "inFlightCloseRequest") === @undefined);
+ closeRequest.@reject.@call(@undefined, storedError);
+ @putByIdDirectPrivate(stream, "closeRequest", @undefined);
+ }
+
+ const writer = @getByIdDirectPrivate(stream, "writer");
+ if (writer !== @undefined) {
+ const closedPromise = @getByIdDirectPrivate(writer, "closedPromise");
+ closedPromise.@reject.@call(@undefined, storedError);
+ @markPromiseAsHandled(closedPromise.@promise);
+ }
+}
+
+function writableStreamStartErroring(stream, reason)
+{
+ "use strict";
+
+ @assert(@getByIdDirectPrivate(stream, "storedError") === @undefined);
+ @assert(@getByIdDirectPrivate(stream, "state") === "writable");
+
+ const controller = @getByIdDirectPrivate(stream, "controller");
+ @assert(controller !== @undefined);
+
+ @putByIdDirectPrivate(stream, "state", "erroring");
+ @putByIdDirectPrivate(stream, "storedError", reason);
+
+ const writer = @getByIdDirectPrivate(stream, "writer");
+ if (writer !== @undefined)
+ @writableStreamDefaultWriterEnsureReadyPromiseRejected(writer, reason);
+
+ if (!@writableStreamHasOperationMarkedInFlight(stream) && @getByIdDirectPrivate(controller, "started") === 1)
+ @writableStreamFinishErroring(stream);
+}
+
+function writableStreamUpdateBackpressure(stream, backpressure)
+{
+ "use strict";
+ @assert(@getByIdDirectPrivate(stream, "state") === "writable");
+ @assert(!@writableStreamCloseQueuedOrInFlight(stream));
+
+ const writer = @getByIdDirectPrivate(stream, "writer");
+ if (writer !== @undefined && backpressure !== @getByIdDirectPrivate(stream, "backpressure")) {
+ if (backpressure)
+ @putByIdDirectPrivate(writer, "readyPromise", @newPromiseCapability(@Promise));
+ else
+ @getByIdDirectPrivate(writer, "readyPromise").@resolve.@call();
+ }
+ @putByIdDirectPrivate(stream, "backpressure", backpressure);
+}
+
+function writableStreamDefaultWriterAbort(writer, reason)
+{
+ "use strict";
+ const stream = @getByIdDirectPrivate(writer, "stream");
+ @assert(stream !== @undefined);
+ return @writableStreamAbort(stream, reason);
+}
+
+function writableStreamDefaultWriterClose(writer)
+{
+ "use strict";
+ const stream = @getByIdDirectPrivate(writer, "stream");
+ @assert(stream !== @undefined);
+ return @writableStreamClose(stream);
+}
+
+function writableStreamDefaultWriterCloseWithErrorPropagation(writer)
+{
+ "use strict";
+ const stream = @getByIdDirectPrivate(writer, "stream");
+ @assert(stream !== @undefined);
+
+ const state = @getByIdDirectPrivate(stream, "state");
+
+ if (@writableStreamCloseQueuedOrInFlight(stream) || state === "closed")
+ return @Promise.@resolve();
+
+ if (state === "errored")
+ return @Promise.@reject(@getByIdDirectPrivate(stream, "storedError"));
+
+ @assert(state === "writable" || state === "erroring");
+ return @writableStreamDefaultWriterClose(writer);
+}
+
+function writableStreamDefaultWriterEnsureClosedPromiseRejected(writer, error)
+{
+ "use strict";
+ let closedPromiseCapability = @getByIdDirectPrivate(writer, "closedPromise");
+ let closedPromise = closedPromiseCapability.@promise;
+
+ if ((@getPromiseInternalField(closedPromise, @promiseFieldFlags) & @promiseStateMask) !== @promiseStatePending) {
+ closedPromiseCapability = @newPromiseCapability(@Promise);
+ closedPromise = closedPromiseCapability.@promise;
+ @putByIdDirectPrivate(writer, "closedPromise", closedPromiseCapability);
+ }
+
+ closedPromiseCapability.@reject.@call(@undefined, error);
+ @markPromiseAsHandled(closedPromise);
+}
+
+function writableStreamDefaultWriterEnsureReadyPromiseRejected(writer, error)
+{
+ "use strict";
+ let readyPromiseCapability = @getByIdDirectPrivate(writer, "readyPromise");
+ let readyPromise = readyPromiseCapability.@promise;
+
+ if ((@getPromiseInternalField(readyPromise, @promiseFieldFlags) & @promiseStateMask) !== @promiseStatePending) {
+ readyPromiseCapability = @newPromiseCapability(@Promise);
+ readyPromise = readyPromiseCapability.@promise;
+ @putByIdDirectPrivate(writer, "readyPromise", readyPromiseCapability);
+ }
+
+ readyPromiseCapability.@reject.@call(@undefined, error);
+ @markPromiseAsHandled(readyPromise);
+}
+
+function writableStreamDefaultWriterGetDesiredSize(writer)
+{
+ "use strict";
+ const stream = @getByIdDirectPrivate(writer, "stream");
+ @assert(stream !== @undefined);
+
+ const state = @getByIdDirectPrivate(stream, "state");
+
+ if (state === "errored" || state === "erroring")
+ return null;
+
+ if (state === "closed")
+ return 0;
+
+ return @writableStreamDefaultControllerGetDesiredSize(@getByIdDirectPrivate(stream, "controller"));
+}
+
+function writableStreamDefaultWriterRelease(writer)
+{
+ "use strict";
+
+ const stream = @getByIdDirectPrivate(writer, "stream");
+ @assert(stream !== @undefined);
+ @assert(@getByIdDirectPrivate(stream, "writer") === writer);
+
+ const releasedError = @makeTypeError("writableStreamDefaultWriterRelease");
+
+ @writableStreamDefaultWriterEnsureReadyPromiseRejected(writer, releasedError);
+ @writableStreamDefaultWriterEnsureClosedPromiseRejected(writer, releasedError);
+
+ @putByIdDirectPrivate(stream, "writer", @undefined);
+ @putByIdDirectPrivate(writer, "stream", @undefined);
+}
+
+function writableStreamDefaultWriterWrite(writer, chunk)
+{
+ "use strict";
+
+ const stream = @getByIdDirectPrivate(writer, "stream");
+ @assert(stream !== @undefined);
+
+ const controller = @getByIdDirectPrivate(stream, "controller");
+ @assert(controller !== @undefined);
+ const chunkSize = @writableStreamDefaultControllerGetChunkSize(controller, chunk);
+
+ if (stream !== @getByIdDirectPrivate(writer, "stream"))
+ return @Promise.@reject(@makeTypeError("writer is not stream's writer"));
+
+ const state = @getByIdDirectPrivate(stream, "state");
+ if (state === "errored")
+ return @Promise.@reject(@getByIdDirectPrivate(stream, "storedError"));
+
+ if (@writableStreamCloseQueuedOrInFlight(stream) || state === "closed")
+ return @Promise.@reject(@makeTypeError("stream is closing or closed"));
+
+ if (@writableStreamCloseQueuedOrInFlight(stream) || state === "closed")
+ return @Promise.@reject(@makeTypeError("stream is closing or closed"));
+
+ if (state === "erroring")
+ return @Promise.@reject(@getByIdDirectPrivate(stream, "storedError"));
+
+ @assert(state === "writable");
+
+ const promise = @writableStreamAddWriteRequest(stream);
+ @writableStreamDefaultControllerWrite(controller, chunk, chunkSize);
+ return promise;
+}
+
+function setUpWritableStreamDefaultController(stream, controller, startAlgorithm, writeAlgorithm, closeAlgorithm, abortAlgorithm, highWaterMark, sizeAlgorithm)
+{
+ "use strict";
+
+ @assert(@isWritableStream(stream));
+ @assert(@getByIdDirectPrivate(stream, "controller") === @undefined);
+
+ @putByIdDirectPrivate(controller, "stream", stream);
+ @putByIdDirectPrivate(stream, "controller", controller);
+
+ @resetQueue(@getByIdDirectPrivate(controller, "queue"));
+
+ @putByIdDirectPrivate(controller, "started", -1);
+ @putByIdDirectPrivate(controller, "startAlgorithm", startAlgorithm);
+ @putByIdDirectPrivate(controller, "strategySizeAlgorithm", sizeAlgorithm);
+ @putByIdDirectPrivate(controller, "strategyHWM", highWaterMark);
+ @putByIdDirectPrivate(controller, "writeAlgorithm", writeAlgorithm);
+ @putByIdDirectPrivate(controller, "closeAlgorithm", closeAlgorithm);
+ @putByIdDirectPrivate(controller, "abortAlgorithm", abortAlgorithm);
+
+ const backpressure = @writableStreamDefaultControllerGetBackpressure(controller);
+ @writableStreamUpdateBackpressure(stream, backpressure);
+
+ @writableStreamDefaultControllerStart(controller);
+}
+
+function writableStreamDefaultControllerStart(controller) {
+ "use strict";
+
+ if (@getByIdDirectPrivate(controller, "started") !== -1)
+ return;
+
+ @putByIdDirectPrivate(controller, "started", 0);
+
+ const startAlgorithm = @getByIdDirectPrivate(controller, "startAlgorithm");
+ @putByIdDirectPrivate(controller, "startAlgorithm", @undefined);
+ const stream = @getByIdDirectPrivate(controller, "stream");
+ return @Promise.@resolve(startAlgorithm.@call()).@then(() => {
+ const state = @getByIdDirectPrivate(stream, "state");
+ @assert(state === "writable" || state === "erroring");
+ @putByIdDirectPrivate(controller, "started", 1);
+ @writableStreamDefaultControllerAdvanceQueueIfNeeded(controller);
+ }, (error) => {
+ const state = @getByIdDirectPrivate(stream, "state");
+ @assert(state === "writable" || state === "erroring");
+ @putByIdDirectPrivate(controller, "started", 1);
+ @writableStreamDealWithRejection(stream, error);
+ });
+}
+
+function setUpWritableStreamDefaultControllerFromUnderlyingSink(stream, underlyingSink, underlyingSinkDict, highWaterMark, sizeAlgorithm)
+{
+ "use strict";
+ const controller = new @WritableStreamDefaultController();
+
+ let startAlgorithm = () => { };
+ let writeAlgorithm = () => { return @Promise.@resolve(); };
+ let closeAlgorithm = () => { return @Promise.@resolve(); };
+ let abortAlgorithm = () => { return @Promise.@resolve(); };
+
+ if ("start" in underlyingSinkDict) {
+ const startMethod = underlyingSinkDict["start"];
+ startAlgorithm = () => @promiseInvokeOrNoopMethodNoCatch(underlyingSink, startMethod, [controller]);
+ }
+ if ("write" in underlyingSinkDict) {
+ const writeMethod = underlyingSinkDict["write"];
+ writeAlgorithm = (chunk) => @promiseInvokeOrNoopMethod(underlyingSink, writeMethod, [chunk, controller]);
+ }
+ if ("close" in underlyingSinkDict) {
+ const closeMethod = underlyingSinkDict["close"];
+ closeAlgorithm = () => @promiseInvokeOrNoopMethod(underlyingSink, closeMethod, []);
+ }
+ if ("abort" in underlyingSinkDict) {
+ const abortMethod = underlyingSinkDict["abort"];
+ abortAlgorithm = (reason) => @promiseInvokeOrNoopMethod(underlyingSink, abortMethod, [reason]);
+ }
+
+ @setUpWritableStreamDefaultController(stream, controller, startAlgorithm, writeAlgorithm, closeAlgorithm, abortAlgorithm, highWaterMark, sizeAlgorithm);
+}
+
+function writableStreamDefaultControllerAdvanceQueueIfNeeded(controller)
+{
+ "use strict";
+ const stream = @getByIdDirectPrivate(controller, "stream");
+
+ if (@getByIdDirectPrivate(controller, "started") !== 1)
+ return;
+
+ @assert(stream !== @undefined);
+ if (@getByIdDirectPrivate(stream, "inFlightWriteRequest") !== @undefined)
+ return;
+
+ const state = @getByIdDirectPrivate(stream, "state");
+ @assert(state !== "closed" || state !== "errored");
+ if (state === "erroring") {
+ @writableStreamFinishErroring(stream);
+ return;
+ }
+
+ if (@getByIdDirectPrivate(controller, "queue").content?.isEmpty() ?? false)
+ return;
+
+ const value = @peekQueueValue(@getByIdDirectPrivate(controller, "queue"));
+ if (value === @isCloseSentinel)
+ @writableStreamDefaultControllerProcessClose(controller);
+ else
+ @writableStreamDefaultControllerProcessWrite(controller, value);
+}
+
+function isCloseSentinel()
+{
+}
+
+function writableStreamDefaultControllerClearAlgorithms(controller)
+{
+ "use strict";
+ @putByIdDirectPrivate(controller, "writeAlgorithm", @undefined);
+ @putByIdDirectPrivate(controller, "closeAlgorithm", @undefined);
+ @putByIdDirectPrivate(controller, "abortAlgorithm", @undefined);
+ @putByIdDirectPrivate(controller, "strategySizeAlgorithm", @undefined);
+}
+
+function writableStreamDefaultControllerClose(controller)
+{
+ "use strict";
+ @enqueueValueWithSize(@getByIdDirectPrivate(controller, "queue"), @isCloseSentinel, 0);
+ @writableStreamDefaultControllerAdvanceQueueIfNeeded(controller);
+}
+
+function writableStreamDefaultControllerError(controller, error)
+{
+ "use strict";
+ const stream = @getByIdDirectPrivate(controller, "stream");
+ @assert(stream !== @undefined);
+ @assert(@getByIdDirectPrivate(stream, "state") === "writable");
+
+ @writableStreamDefaultControllerClearAlgorithms(controller);
+ @writableStreamStartErroring(stream, error);
+}
+
+function writableStreamDefaultControllerErrorIfNeeded(controller, error)
+{
+ "use strict";
+ const stream = @getByIdDirectPrivate(controller, "stream");
+ if (@getByIdDirectPrivate(stream, "state") === "writable")
+ @writableStreamDefaultControllerError(controller, error);
+}
+
+function writableStreamDefaultControllerGetBackpressure(controller)
+{
+ "use strict";
+ const desiredSize = @writableStreamDefaultControllerGetDesiredSize(controller);
+ return desiredSize <= 0;
+}
+
+function writableStreamDefaultControllerGetChunkSize(controller, chunk)
+{
+ "use strict";
+ try {
+ return @getByIdDirectPrivate(controller, "strategySizeAlgorithm").@call(@undefined, chunk);
+ } catch (e) {
+ @writableStreamDefaultControllerErrorIfNeeded(controller, e);
+ return 1;
+ }
+}
+
+function writableStreamDefaultControllerGetDesiredSize(controller)
+{
+ "use strict";
+ return @getByIdDirectPrivate(controller, "strategyHWM") - @getByIdDirectPrivate(controller, "queue").size;
+}
+
+function writableStreamDefaultControllerProcessClose(controller)
+{
+ "use strict";
+ const stream = @getByIdDirectPrivate(controller, "stream");
+
+ @writableStreamMarkCloseRequestInFlight(stream);
+ @dequeueValue(@getByIdDirectPrivate(controller, "queue"));
+
+ @assert(@getByIdDirectPrivate(controller, "queue").content?.isEmpty());
+
+ const sinkClosePromise = @getByIdDirectPrivate(controller, "closeAlgorithm").@call();
+ @writableStreamDefaultControllerClearAlgorithms(controller);
+
+ sinkClosePromise.@then(() => {
+ @writableStreamFinishInFlightClose(stream);
+ }, (reason) => {
+ @writableStreamFinishInFlightCloseWithError(stream, reason);
+ });
+}
+
+function writableStreamDefaultControllerProcessWrite(controller, chunk)
+{
+ "use strict";
+ const stream = @getByIdDirectPrivate(controller, "stream");
+
+ @writableStreamMarkFirstWriteRequestInFlight(stream);
+
+ const sinkWritePromise = @getByIdDirectPrivate(controller, "writeAlgorithm").@call(@undefined, chunk);
+
+ sinkWritePromise.@then(() => {
+ @writableStreamFinishInFlightWrite(stream);
+ const state = @getByIdDirectPrivate(stream, "state");
+ @assert(state === "writable" || state === "erroring");
+
+ @dequeueValue(@getByIdDirectPrivate(controller, "queue"));
+ if (!@writableStreamCloseQueuedOrInFlight(stream) && state === "writable") {
+ const backpressure = @writableStreamDefaultControllerGetBackpressure(controller);
+ @writableStreamUpdateBackpressure(stream, backpressure);
+ }
+ @writableStreamDefaultControllerAdvanceQueueIfNeeded(controller);
+ }, (reason) => {
+ const state = @getByIdDirectPrivate(stream, "state");
+ if (state === "writable")
+ @writableStreamDefaultControllerClearAlgorithms(controller);
+
+ @writableStreamFinishInFlightWriteWithError(stream, reason);
+ });
+}
+
+function writableStreamDefaultControllerWrite(controller, chunk, chunkSize)
+{
+ "use strict";
+ try {
+ @enqueueValueWithSize(@getByIdDirectPrivate(controller, "queue"), chunk, chunkSize);
+
+ const stream = @getByIdDirectPrivate(controller, "stream");
+
+ const state = @getByIdDirectPrivate(stream, "state");
+ if (!@writableStreamCloseQueuedOrInFlight(stream) && state === "writable") {
+ const backpressure = @writableStreamDefaultControllerGetBackpressure(controller);
+ @writableStreamUpdateBackpressure(stream, backpressure);
+ }
+ @writableStreamDefaultControllerAdvanceQueueIfNeeded(controller);
+ } catch (e) {
+ @writableStreamDefaultControllerErrorIfNeeded(controller, e);
+ }
+}