Compare commits

...

46 Commits

Author SHA1 Message Date
Jarred-Sumner
4e5cae8727 bun run prettier:extra 2024-12-27 20:36:58 +00:00
Jarred Sumner
bdcb6ec891 Update ReadableStream.mjs 2024-12-27 12:35:40 -08:00
Jarred Sumner
1f6e67c7cb working better 2024-12-27 03:15:25 -08:00
Jarred Sumner
1e3496512a sort of owrks 2024-12-27 01:26:03 -08:00
Jarred Sumner
44465a8fef Update BunReadableStream.h 2024-12-26 23:38:42 -08:00
Jarred Sumner
c22d1a6831 Update BunReadableStreamDefaultReader.cpp 2024-12-26 23:36:35 -08:00
Jarred Sumner
44714cb257 We are streaming 2024-12-26 23:33:12 -08:00
Jarred Sumner
9bea782324 it compiled once again 2024-12-26 19:03:38 -08:00
Jarred Sumner
cfcef4be53 wip 2024-12-26 17:20:41 -08:00
Jarred Sumner
243b087b6d much 2024-12-26 17:07:15 -08:00
Jarred Sumner
dbdceefce6 more 2024-12-26 17:07:04 -08:00
Jarred Sumner
98e130a518 there's more 2024-12-26 15:20:17 -08:00
Jarred Sumner
9127371309 delete probably too much code 2024-12-26 15:18:05 -08:00
Jarred Sumner
c04bef64b6 It compiled 2024-12-26 14:47:41 -08:00
Jarred Sumner
6c4d833e71 more 2024-12-26 12:45:57 -08:00
Jarred Sumner
f08c1a3ca1 Merge branch 'main' into jarred/streamy- 2024-12-26 12:17:36 -08:00
Jarred Sumner
665e1f81bd more 2024-12-20 00:17:33 -08:00
Jarred Sumner
00b9b9471d more 2024-12-19 22:55:53 -08:00
Jarred Sumner
122e87531c Update BunReadableStreamDefaultController.cpp 2024-12-19 20:53:25 -08:00
Jarred Sumner
cfc3907614 Update BunReadableStreamDefaultReaderConstructor.cpp 2024-12-19 20:52:13 -08:00
Jarred Sumner
d03f88a75c More 2024-12-19 20:51:05 -08:00
Jarred Sumner
49647de33a More files 2024-12-19 20:50:37 -08:00
Jarred Sumner
4f6b066255 Update BunWritableStreamConstructor.h 2024-12-19 20:16:28 -08:00
Jarred Sumner
5fc5baaddd More files 2024-12-19 20:04:40 -08:00
Jarred Sumner
799770680d More files 2024-12-19 19:59:33 -08:00
Jarred Sumner
c25bb295fd Update BunReadableStream.h 2024-12-19 19:43:45 -08:00
Jarred Sumner
20c8bb1777 More files 2024-12-19 19:30:08 -08:00
Jarred Sumner
d76d8b775a More files 2024-12-19 19:22:24 -08:00
Jarred Sumner
bdab548b4a More files 2024-12-19 19:13:39 -08:00
Jarred Sumner
a03502e3d8 More files 2024-12-19 19:06:00 -08:00
Jarred Sumner
b152f07c78 move some things around 2024-12-19 18:56:33 -08:00
Jarred Sumner
9894605bad Update .cursorignore 2024-12-19 17:23:47 -08:00
Jarred Sumner
c76ad94376 more 2024-12-19 06:14:42 -08:00
Jarred Sumner
fcb0daeaf4 Update BunWritableStream.cpp 2024-12-19 05:50:02 -08:00
Jarred Sumner
7c2b935249 more 2024-12-19 05:44:30 -08:00
Jarred Sumner
33db8447b0 more 2024-12-19 05:36:15 -08:00
Jarred Sumner
7bff270e87 Update BunReadableStreamDefaultController.h 2024-12-19 05:08:29 -08:00
Jarred Sumner
be1631d28b Fix more errors 2024-12-19 05:07:18 -08:00
Jarred Sumner
c2b9ea21e2 more 2024-12-19 05:01:04 -08:00
Jarred Sumner
3a39b18389 wip 2024-12-19 04:12:47 -08:00
Jarred Sumner
38f98d3f51 Create .cursorignore 2024-12-19 04:06:14 -08:00
Jarred Sumner
14e8c47139 Update BunWritableStream.cpp 2024-12-18 21:58:40 -08:00
Jarred Sumner
110f94d4a1 Merge branch 'main' into jarred/streamy- 2024-12-18 21:21:12 -08:00
Jarred Sumner
83e813fd9a Create ReadableStream.mjs 2024-12-18 15:23:04 -08:00
Jarred Sumner
64df1de435 more 2024-12-18 04:59:07 -08:00
Jarred Sumner
fbe1895f58 wip 2024-12-18 02:55:56 -08:00
139 changed files with 7196 additions and 11053 deletions

View File

@@ -1,7 +1,22 @@
vendor
src/bun.js/bindings/webcore/JSReadableStream.h
src/bun.js/bindings/webcore/JSReadableStreamDefaultReader.h
src/bun.js/bindings/webcore/JSReadableStreamDefaultReader.cpp
src/bun.js/bindings/webcore/JSReadableStreamDefaultController.h
src/bun.js/bindings/webcore/JSReadableStreamDefaultController.cpp
src/bun.js/bindings/webcore/JSReadableStream.h
src/bun.js/bindings/webcore/JSWritableStreamDefaultWriter.h
src/bun.js/bindings/webcore/JSWritableStreamDefaultWriter.cpp
src/bun.js/bindings/webcore/JSWritableStreamDefaultController.h
src/bun.js/bindings/webcore/JSWritableStreamDefaultController.cpp
src/bun.js/bindings/webcore/JSTransformStreamDefaultController.h
src/bun.js/bindings/webcore/JSTransformStreamDefaultController.cpp
src/bun.js/bindings/webcore/JSTransformStream.h
src/bun.js/bindings/webcore/JSTransformStream.cpp
# Add directories or file patterns to ignore during indexing (e.g. foo/ or *.csv)
bench
vendor
*-fixture.{js,ts}
zig-cache
packages/bun-uws/fuzzing
build
build

View File

@@ -0,0 +1,91 @@
import React from "react";
import { renderToReadableStream } from "react-dom/server.browser";
import { bench, run } from "../runner.mjs";
const reactElement = React.createElement(
"body",
null,
React.createElement("div", null, React.createElement("address", null, "hi")),
);
bench("ReactDOM.renderToReadableStream", async () => {
const stream = await renderToReadableStream(reactElement);
await stream.allReady;
const reader = stream.getReader();
while (true) {
const { value, done } = await reader.read();
if (done) {
break;
}
}
});
bench("ReadableStream (3 reads)", async () => {
const stream = new ReadableStream({
start(controller) {
controller.enqueue("Hello");
},
pull(controller) {
controller.enqueue("World");
controller.close();
},
});
const reader = stream.getReader();
var { value, done } = await reader.read();
({ value, done } = await reader.read());
({ value, done } = await reader.read());
if (!done) {
throw new Error("failed");
}
});
bench("ReadableStream (1 read -> 1 pull) x 32 * 1024 ", async () => {
let next = Promise.withResolvers();
let remaining = 32 * 1024;
const stream = new ReadableStream({
pull(controller) {
next = Promise.withResolvers();
controller.enqueue("Hello");
next.resolve();
if (remaining-- === 0) {
controller.close();
}
},
});
const reader = stream.getReader();
while (true) {
var { value, done } = await reader.read();
if (done) {
break;
}
await next.promise;
}
});
{
let next = Promise.withResolvers();
const stream = new ReadableStream({
pull(controller) {
next = Promise.withResolvers();
next.resolve();
controller.enqueue("Hello");
},
});
const reader = stream.getReader();
bench("ReadableStream (1 read -> 1 pull) same instance x 10 times ", async () => {
for (let i = 0; i < 10; i++) {
var { value, done } = await reader.read();
await next.promise;
}
});
}
await run();

View File

@@ -0,0 +1,12 @@
#pragma once
namespace Bun {
static inline JSC::JSPromise* createFulfilledPromise(JSC::JSGlobalObject* globalObject, JSC::JSValue value)
{
JSC::JSPromise* promise = JSC::JSPromise::create(globalObject->vm(), globalObject->promiseStructure());
promise->fulfill(globalObject, value);
return promise;
}
}

View File

@@ -0,0 +1,380 @@
#include "root.h"
#include <JavaScriptCore/JSObject.h>
#include <JavaScriptCore/JSObjectInlines.h>
#include "JavaScriptCore/JSCast.h"
#include <JavaScriptCore/JSPromise.h>
#include <JavaScriptCore/JSArray.h>
#include <JavaScriptCore/WriteBarrier.h>
#include "BunStreamInlines.h"
#include "BunTeeState.h"
#include "JSAbortSignal.h"
#include <JavaScriptCore/Completion.h>
#include <JavaScriptCore/JSCInlines.h>
#include <JavaScriptCore/CallData.h>
#include <JavaScriptCore/Completion.h>
#include "BunReadableStreamPipeToOperation.h"
#include "BunReadableStreamDefaultReader.h"
#include "BunReadableStreamBYOBReader.h"
#include "BunWritableStream.h"
#include "BunWritableStreamDefaultWriter.h"
#include "BunReadableStream.h"
#include "BunReadableStreamDefaultController.h"
#include "BunPromiseInlines.h"
#include <JavaScriptCore/VMTrapsInlines.h>
namespace Bun {
using namespace JSC;
JSC::GCClient::IsoSubspace* JSReadableStream::subspaceForImpl(JSC::VM& vm)
{
return WebCore::subspaceForImpl<JSReadableStream, WebCore::UseCustomHeapCellType::No>(
vm,
[](auto& spaces) { return spaces.m_clientSubspaceForReadableStream.get(); },
[](auto& spaces, auto&& space) { spaces.m_clientSubspaceForReadableStream = std::forward<decltype(space)>(space); },
[](auto& spaces) { return spaces.m_subspaceForReadableStream.get(); },
[](auto& spaces, auto&& space) { spaces.m_subspaceForReadableStream = std::forward<decltype(space)>(space); });
}
JSReadableStreamDefaultReader* JSReadableStream::reader() const
{
return jsCast<JSReadableStreamDefaultReader*>(m_reader.get());
}
JSReadableStreamDefaultController* JSReadableStream::controller() const
{
return jsCast<JSReadableStreamDefaultController*>(m_controller.get());
}
JSValue JSReadableStream::getReader(VM& vm, JSGlobalObject* globalObject, JSValue options)
{
auto scope = DECLARE_THROW_SCOPE(vm);
if (locked()) {
throwTypeError(globalObject, scope, "ReadableStream is locked"_s);
return {};
}
auto* domGlobalObject = defaultGlobalObject(globalObject);
auto& streams = domGlobalObject->streams();
if (!options.isUndefined()) {
JSObject* optionsObject = options.toObject(globalObject);
RETURN_IF_EXCEPTION(scope, {});
JSValue mode = optionsObject->get(globalObject, Identifier::fromString(vm, "mode"_s));
RETURN_IF_EXCEPTION(scope, {});
if (mode.getString(globalObject) == "byob"_s) {
auto* controller = jsCast<JSReadableStreamDefaultController*>(m_controller.get());
if (!controller || !controller->isByteController()) {
throwTypeError(globalObject, scope, "Cannot get a BYOB reader for a non-byte stream"_s);
return {};
}
Structure* readerStructure = streams.structure<JSReadableStreamBYOBReader>(domGlobalObject);
auto* reader = JSReadableStreamBYOBReader::create(vm, globalObject, readerStructure, this);
m_reader.set(vm, this, reader);
return reader;
}
}
Structure* readerStructure = streams.structure<JSReadableStreamDefaultReader>(domGlobalObject);
auto* reader = JSReadableStreamDefaultReader::create(vm, globalObject, readerStructure, this);
m_reader.set(vm, this, reader);
return reader;
}
JSPromise* JSReadableStream::cancel(VM& vm, JSGlobalObject* globalObject, JSValue reason)
{
auto scope = DECLARE_THROW_SCOPE(vm);
if (locked()) {
throwTypeError(globalObject, scope, "ReadableStream is locked"_s);
return nullptr;
}
if (m_state == State::Closed)
return Bun::createFulfilledPromise(globalObject, jsUndefined());
if (m_state == State::Errored) {
return JSPromise::rejectedPromise(globalObject, storedError());
}
m_disturbed = true;
if (!m_controller)
return Bun::createFulfilledPromise(globalObject, jsUndefined());
auto* controller = this->controller();
JSObject* cancelAlgorithm = controller->cancelAlgorithm();
m_controller.clear();
if (!cancelAlgorithm)
return Bun::createFulfilledPromise(globalObject, jsUndefined());
JSC::CallData callData = JSC::getCallData(cancelAlgorithm);
if (callData.type == JSC::CallData::Type::None)
return Bun::createFulfilledPromise(globalObject, jsUndefined());
MarkedArgumentBuffer args;
args.append(reason);
JSValue result = JSC::profiledCall(globalObject, ProfilingReason::API, cancelAlgorithm, callData, controller->underlyingSource(), args);
RETURN_IF_EXCEPTION(scope, nullptr);
if (auto* promise = jsDynamicCast<JSPromise*>(result))
return promise;
return Bun::createFulfilledPromise(globalObject, result);
}
JSPromise* JSReadableStream::pipeTo(VM& vm, JSGlobalObject* globalObject, JSObject* destination, JSValue options)
{
auto scope = DECLARE_THROW_SCOPE(vm);
if (!destination) {
throwTypeError(globalObject, scope, "Destination must be a WritableStream"_s);
return nullptr;
}
JSWritableStream* writableStream = jsDynamicCast<JSWritableStream*>(destination);
if (!writableStream) {
throwTypeError(globalObject, scope, "Destination must be a WritableStream"_s);
return nullptr;
}
if (locked() || writableStream->isLocked()) {
throwTypeError(globalObject, scope, "Cannot pipe to/from a locked stream"_s);
return nullptr;
}
bool preventClose [[maybe_unused]] = false;
bool preventAbort [[maybe_unused]] = false;
bool preventCancel [[maybe_unused]] = false;
JSObject* signal [[maybe_unused]] = nullptr;
if (!options.isUndefined()) {
JSObject* optionsObject = options.toObject(globalObject);
RETURN_IF_EXCEPTION(scope, nullptr);
JSValue preventCloseValue = optionsObject->get(globalObject, Identifier::fromString(vm, "preventClose"_s));
RETURN_IF_EXCEPTION(scope, nullptr);
preventClose = preventCloseValue.toBoolean(globalObject);
RETURN_IF_EXCEPTION(scope, nullptr);
JSValue preventAbortValue = optionsObject->get(globalObject, Identifier::fromString(vm, "preventAbort"_s));
RETURN_IF_EXCEPTION(scope, nullptr);
preventAbort = preventAbortValue.toBoolean(globalObject);
RETURN_IF_EXCEPTION(scope, nullptr);
JSValue preventCancelValue = optionsObject->get(globalObject, Identifier::fromString(vm, "preventCancel"_s));
RETURN_IF_EXCEPTION(scope, nullptr);
preventCancel = preventCancelValue.toBoolean(globalObject);
RETURN_IF_EXCEPTION(scope, nullptr);
JSValue signalValue = optionsObject->get(globalObject, Identifier::fromString(vm, "signal"_s));
RETURN_IF_EXCEPTION(scope, nullptr);
if (!signalValue.isUndefined()) {
signal = signalValue.toObject(globalObject);
if (!signal) {
throwTypeError(globalObject, scope, "Signal must be an object"_s);
return nullptr;
}
}
}
m_disturbed = true;
auto* domGlobalObject = defaultGlobalObject(globalObject);
auto& streams = domGlobalObject->streams();
auto* reader = JSReadableStreamDefaultReader::create(vm, globalObject, streams.structure<JSReadableStreamDefaultReader>(domGlobalObject), this);
m_reader.set(vm, this, reader);
auto* writer [[maybe_unused]] = JSWritableStreamDefaultWriter::create(vm, streams.structure<JSWritableStreamDefaultWriter>(domGlobalObject), writableStream);
JSPromise* promise = JSPromise::create(vm, globalObject->promiseStructure());
// auto* pipeToOperation = PipeToOperation::create(vm, globalObject, reader, writer, preventClose, preventAbort, preventCancel, signal, promise);
// pipeToOperation->perform(vm, globalObject);
// promise->reject(globalObject, )
return promise;
}
JSValue JSReadableStream::pipeThrough(VM& vm, JSGlobalObject* globalObject, JSObject* transform, JSValue options)
{
auto scope = DECLARE_THROW_SCOPE(vm);
if (!transform) {
throwTypeError(globalObject, scope, "Transform must be an object"_s);
return {};
}
JSValue readableValue = transform->get(globalObject, Identifier::fromString(vm, "readable"_s));
RETURN_IF_EXCEPTION(scope, {});
JSValue writableValue = transform->get(globalObject, Identifier::fromString(vm, "writable"_s));
RETURN_IF_EXCEPTION(scope, {});
JSReadableStream* readable = jsDynamicCast<JSReadableStream*>(readableValue);
if (UNLIKELY(!readable)) {
throwTypeError(globalObject, scope, "Transform must have readable property that is a stream"_s);
return {};
}
JSWritableStream* writable = jsDynamicCast<JSWritableStream*>(writableValue);
if (UNLIKELY(!writable)) {
throwTypeError(globalObject, scope, "Transform must have writable property that is a stream"_s);
return {};
}
JSPromise* pipePromise = pipeTo(vm, globalObject, jsCast<JSWritableStream*>(writable), options);
RETURN_IF_EXCEPTION(scope, {});
// We don't want to expose the pipeTo promise to user code
pipePromise->markAsHandled(globalObject);
return readable;
}
void JSReadableStream::tee(VM& vm, JSGlobalObject* globalObject, JSValue& firstStream, JSValue& secondStream)
{
auto scope = DECLARE_THROW_SCOPE(vm);
if (locked()) {
throwTypeError(globalObject, scope, "ReadableStream is locked"_s);
return;
}
auto* domGlobalObject = defaultGlobalObject(globalObject);
auto& streams = domGlobalObject->streams();
if (m_state == State::Errored) {
auto* error = m_storedError.get();
Structure* streamStructure = streams.structure<JSReadableStream>(domGlobalObject);
auto* stream1 = JSReadableStream::create(vm, globalObject, streamStructure);
auto* stream2 = JSReadableStream::create(vm, globalObject, streamStructure);
stream1->error(globalObject, error);
stream2->error(globalObject, error);
firstStream = stream1;
secondStream = stream2;
return;
}
m_disturbed = true;
auto* reader = JSReadableStreamDefaultReader::create(vm, globalObject, streams.structure<JSReadableStreamDefaultReader>(domGlobalObject), this);
m_reader.set(vm, this, reader);
Structure* streamStructure = streams.structure<JSReadableStream>(domGlobalObject);
auto* branch1 = JSReadableStream::create(vm, globalObject, streamStructure);
auto* branch2 = JSReadableStream::create(vm, globalObject, streamStructure);
firstStream = branch1;
secondStream = branch2;
TeeState* teeState = TeeState::create(vm, globalObject, reader, branch1, branch2);
teeState->perform(vm, globalObject);
}
const ClassInfo JSReadableStream::s_info = { "ReadableStream"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSReadableStream) };
template<typename Visitor>
void JSReadableStream::visitChildrenImpl(JSCell* cell, Visitor& visitor)
{
auto* thisObject = jsCast<JSReadableStream*>(cell);
ASSERT_GC_OBJECT_INHERITS(thisObject, info());
Base::visitChildren(thisObject, visitor);
thisObject->visitAdditionalChildren(visitor);
}
template<typename Visitor>
void JSReadableStream::visitAdditionalChildren(Visitor& visitor)
{
visitor.append(m_reader);
visitor.append(m_controller);
visitor.append(m_storedError);
}
template<typename Visitor>
void JSReadableStream::visitOutputConstraintsImpl(JSCell* cell, Visitor& visitor)
{
auto* thisObject = jsCast<JSReadableStream*>(cell);
Base::visitOutputConstraints(cell, visitor);
thisObject->visitAdditionalChildren(visitor);
}
DEFINE_VISIT_CHILDREN(JSReadableStream);
DEFINE_VISIT_ADDITIONAL_CHILDREN(JSReadableStream);
DEFINE_VISIT_OUTPUT_CONSTRAINTS(JSReadableStream);
bool JSReadableStream::isLocked() const
{
return locked();
}
JSReadableStream* JSReadableStream::create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure)
{
JSReadableStream* stream = new (NotNull, allocateCell<JSReadableStream>(vm)) JSReadableStream(vm, structure);
stream->finishCreation(vm);
return stream;
}
JSReadableStream::JSReadableStream(VM& vm, Structure* structure)
: Base(vm, structure)
{
}
void JSReadableStream::finishCreation(VM& vm)
{
Base::finishCreation(vm);
m_state = State::Readable;
m_disturbed = false;
m_reader.clear();
m_controller.clear();
m_storedError.clear();
}
void JSReadableStream::setController(JSC::VM& vm, JSReadableStreamDefaultController* controller)
{
m_controller.set(vm, this, controller);
}
Structure* JSReadableStream::createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
{
return Structure::create(vm, globalObject, prototype, TypeInfo(ObjectType, StructureFlags), info());
}
void JSReadableStream::close(JSGlobalObject* globalObject)
{
m_state = State::Closed;
if (auto* reader = this->reader())
reader->closedPromise()->fulfill(globalObject, jsUndefined());
}
void JSReadableStream::error(JSGlobalObject* globalObject, JSValue error)
{
VM& vm = globalObject->vm();
m_state = State::Errored;
m_storedError.set(vm, this, error.toObject(globalObject));
if (auto* reader = this->reader())
reader->closedPromise()->reject(globalObject, error);
}
void JSReadableStream::setReader(JSC::VM& vm, JSReadableStreamDefaultReader* reader)
{
if (reader) {
m_reader.set(vm, this, reader);
} else {
m_reader.clear();
}
}
}

View File

@@ -0,0 +1,79 @@
#pragma once
#include "root.h"
#include <JavaScriptCore/JSGlobalObject.h>
#include <JavaScriptCore/JSObject.h>
#include <JavaScriptCore/JSCell.h>
namespace Bun {
class JSReadableStreamDefaultController;
class JSReadableStreamDefaultReader;
class JSReadableStreamPrototype;
class JSReadableStreamConstructor;
using namespace JSC;
class JSReadableStream final : public JSC::JSNonFinalObject {
public:
using Base = JSC::JSNonFinalObject;
static constexpr unsigned StructureFlags = Base::StructureFlags;
template<typename, JSC::SubspaceAccess mode>
static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm)
{
if constexpr (mode == JSC::SubspaceAccess::Concurrently)
return nullptr;
return subspaceForImpl(vm);
}
static JSC::GCClient::IsoSubspace* subspaceForImpl(JSC::VM& vm);
static JSReadableStream* create(JSC::VM&, JSC::JSGlobalObject*, JSC::Structure*);
static JSC::Structure* createStructure(JSC::VM&, JSC::JSGlobalObject*, JSC::JSValue prototype);
enum class State {
Readable,
Closed,
Errored,
};
DECLARE_INFO;
DECLARE_VISIT_CHILDREN;
DECLARE_VISIT_OUTPUT_CONSTRAINTS;
template<typename Visitor>
void visitAdditionalChildren(Visitor& visitor);
// Public API for C++ usage
bool isLocked() const;
bool isDisturbed() const { return m_disturbed; }
JSReadableStreamDefaultController* controller() const;
JSReadableStreamDefaultReader* reader() const;
bool locked() const { return !!m_reader; }
JSC::JSValue getReader(VM&, JSGlobalObject*, JSValue options = jsUndefined());
JSC::JSPromise* cancel(VM&, JSGlobalObject*, JSValue reason = jsUndefined());
JSC::JSPromise* pipeTo(VM&, JSGlobalObject*, JSObject* destination, JSValue options = jsUndefined());
JSC::JSValue pipeThrough(VM&, JSGlobalObject*, JSObject* transform, JSValue options = jsUndefined());
void tee(VM&, JSGlobalObject*, JSValue& firstStream, JSValue& secondStream);
void error(JSGlobalObject*, JSValue);
void close(JSGlobalObject*);
void setReader(JSC::VM& vm, JSReadableStreamDefaultReader*);
void setController(JSC::VM& vm, JSReadableStreamDefaultController*);
State state() const { return m_state; }
JSValue storedError() const { return m_storedError.get(); }
private:
JSReadableStream(VM&, Structure*);
void finishCreation(VM&);
mutable JSC::WriteBarrier<JSObject> m_controller;
mutable JSC::WriteBarrier<JSObject> m_reader;
mutable JSC::WriteBarrier<JSObject> m_storedError;
State m_state { State::Readable };
bool m_disturbed { false };
};
}

View File

@@ -0,0 +1,137 @@
#include "root.h"
#include <JavaScriptCore/JSPromise.h>
#include <JavaScriptCore/JSArray.h>
#include <JavaScriptCore/JSObjectInlines.h>
#include <JavaScriptCore/ArrayBuffer.h>
#include <JavaScriptCore/ArrayBufferView.h>
#include <JavaScriptCore/Error.h>
#include <JavaScriptCore/ObjectConstructor.h>
#include "BunReadableStreamBYOBReader.h"
#include "BunReadableStream.h"
#include "BunReadableStreamDefaultController.h"
#include "BunReadableStreamDefaultReader.h"
#include "BunStreamInlines.h"
namespace Bun {
using namespace JSC;
const ClassInfo JSReadableStreamBYOBReader::s_info = { "ReadableStreamBYOBReader"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSReadableStreamBYOBReader) };
JSReadableStreamBYOBReader::JSReadableStreamBYOBReader(VM& vm, Structure* structure)
: Base(vm, structure)
{
}
void JSReadableStreamBYOBReader::finishCreation(VM& vm)
{
Base::finishCreation(vm);
ASSERT(inherits(info()));
}
JSReadableStreamBYOBReader* JSReadableStreamBYOBReader::create(VM& vm, JSGlobalObject* globalObject, Structure* structure, JSReadableStream* stream)
{
JSReadableStreamBYOBReader* reader = new (NotNull, allocateCell<JSReadableStreamBYOBReader>(vm)) JSReadableStreamBYOBReader(vm, structure);
reader->finishCreation(vm);
reader->setStream(vm, stream);
reader->setReadRequests(vm, constructEmptyArray(globalObject, nullptr));
reader->setClosedPromise(vm, JSPromise::create(vm, globalObject->promiseStructure()));
reader->setReadyPromise(vm, JSPromise::create(vm, globalObject->promiseStructure()));
return reader;
}
template<typename Visitor>
void JSReadableStreamBYOBReader::visitChildrenImpl(JSCell* cell, Visitor& visitor)
{
JSReadableStreamBYOBReader* thisObject = jsCast<JSReadableStreamBYOBReader*>(cell);
ASSERT(thisObject->inherits(JSReadableStreamBYOBReader::info()));
Base::visitChildren(thisObject, visitor);
visitor.append(thisObject->m_stream);
visitor.append(thisObject->m_readRequests);
visitor.append(thisObject->m_closedPromise);
visitor.append(thisObject->m_readyPromise);
}
DEFINE_VISIT_CHILDREN(JSReadableStreamBYOBReader);
JSValue JSReadableStreamBYOBReader::read(VM& vm, JSGlobalObject* globalObject, JSArrayBufferView* view, uint64_t minRequested)
{
auto scope = DECLARE_THROW_SCOPE(vm);
// 5. Check if view's buffer is detached
if (view->isDetached()) {
throwVMTypeError(globalObject, scope, "Cannot read into a detached ArrayBuffer"_s);
return {};
}
// 6. Check view's byte length
if (view->byteLength() == 0) {
throwVMTypeError(globalObject, scope, "Cannot read into a zero-length view"_s);
return {};
}
// 8. Create a new promise for the read result
JSPromise* promise = JSPromise::create(vm, globalObject->promiseStructure());
// 9. Create a read-into request
JSObject* readIntoRequest = constructEmptyObject(globalObject);
readIntoRequest->putDirect(vm, Identifier::fromString(vm, "promise"_s), promise);
readIntoRequest->putDirect(vm, Identifier::fromString(vm, "view"_s), view);
readIntoRequest->putDirect(vm, Identifier::fromString(vm, "min"_s), jsNumber(minRequested));
// 10. Add to read requests queue
JSArray* readRequests = this->readRequests();
readRequests->push(globalObject, readIntoRequest);
RETURN_IF_EXCEPTION(scope, {});
// 11. Return the promise
return promise;
}
void JSReadableStreamBYOBReader::releaseLock(VM& vm, JSGlobalObject* globalObject)
{
auto scope = DECLARE_THROW_SCOPE(vm);
if (!stream())
return;
auto* readRequests = this->readRequests();
if (readRequests->length() > 0) {
for (unsigned i = 0; i < readRequests->length(); ++i) {
auto* request = jsCast<JSObject*>(readRequests->get(globalObject, i));
auto* promise = jsCast<JSPromise*>(request->get(globalObject, Identifier::fromString(vm, "promise"_s)));
promise->reject(globalObject, createTypeError(globalObject, "Reader was released"_s));
}
}
if (stream()) {
stream()->setReader(vm, nullptr);
clearStream();
}
closedPromise()->reject(globalObject, createTypeError(globalObject, "Reader was released"_s));
}
JSValue JSReadableStreamBYOBReader::cancel(VM& vm, JSGlobalObject* globalObject, JSValue reason)
{
auto scope = DECLARE_THROW_SCOPE(vm);
if (!stream())
return throwTypeError(globalObject, scope, "Cannot cancel a released reader"_s);
return stream()->cancel(vm, globalObject, reason);
}
JSC::GCClient::IsoSubspace* JSReadableStreamBYOBReader::subspaceForImpl(JSC::VM& vm)
{
return WebCore::subspaceForImpl<JSReadableStreamBYOBReader, WebCore::UseCustomHeapCellType::No>(
vm,
[](auto& spaces) { return spaces.m_clientSubspaceForReadableStreamBYOBReader.get(); },
[](auto& spaces, auto&& space) { spaces.m_clientSubspaceForReadableStreamBYOBReader = std::forward<decltype(space)>(space); },
[](auto& spaces) { return spaces.m_subspaceForReadableStreamBYOBReader.get(); },
[](auto& spaces, auto&& space) { spaces.m_subspaceForReadableStreamBYOBReader = std::forward<decltype(space)>(space); });
}
} // namespace Bun

View File

@@ -0,0 +1,66 @@
#pragma once
#include "root.h"
#include <JavaScriptCore/JSObject.h>
#include <JavaScriptCore/JSObjectInlines.h>
#include <JavaScriptCore/JSPromise.h>
#include <JavaScriptCore/JSArray.h>
#include <JavaScriptCore/Strong.h>
#include <JavaScriptCore/WriteBarrier.h>
namespace Bun {
class JSReadableStream;
class JSReadableStreamBYOBReader : public JSC::JSNonFinalObject {
public:
using Base = JSC::JSNonFinalObject;
static constexpr bool needsDestruction = false;
template<typename, JSC::SubspaceAccess mode> static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm)
{
if constexpr (mode == JSC::SubspaceAccess::Concurrently)
return nullptr;
return subspaceForImpl(vm);
}
static JSC::GCClient::IsoSubspace* subspaceForImpl(JSC::VM& vm);
static JSReadableStreamBYOBReader* create(JSC::VM&, JSC::JSGlobalObject*, JSC::Structure*, JSReadableStream*);
static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
{
return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info());
}
DECLARE_INFO;
DECLARE_VISIT_CHILDREN;
static constexpr unsigned StructureFlags = Base::StructureFlags;
JSReadableStream* stream() const { return m_stream.get(); }
JSC::JSPromise* closedPromise() const { return m_closedPromise.get(); }
JSC::JSPromise* readyPromise() const { return m_readyPromise.get(); }
JSC::JSArray* readRequests() const { return m_readRequests.get(); }
void setStream(JSC::VM& vm, JSReadableStream* stream) { m_stream.set(vm, this, stream); }
void setClosedPromise(JSC::VM& vm, JSC::JSPromise* promise) { m_closedPromise.set(vm, this, promise); }
void setReadyPromise(JSC::VM& vm, JSC::JSPromise* promise) { m_readyPromise.set(vm, this, promise); }
void setReadRequests(JSC::VM& vm, JSC::JSArray* requests) { m_readRequests.set(vm, this, requests); }
void clearStream() { m_stream.clear(); }
JSC::JSValue read(JSC::VM&, JSC::JSGlobalObject*, JSC::JSArrayBufferView*, uint64_t minRequested = 1);
void releaseLock(JSC::VM&, JSC::JSGlobalObject*);
JSC::JSValue cancel(JSC::VM&, JSC::JSGlobalObject*, JSC::JSValue reason);
protected:
JSReadableStreamBYOBReader(JSC::VM&, JSC::Structure*);
void finishCreation(JSC::VM&);
private:
JSC::WriteBarrier<JSReadableStream> m_stream;
JSC::WriteBarrier<JSC::JSPromise> m_closedPromise;
JSC::WriteBarrier<JSC::JSPromise> m_readyPromise;
JSC::WriteBarrier<JSC::JSArray> m_readRequests;
};
} // namespace Bun

View File

@@ -0,0 +1,46 @@
#include "root.h"
#include "BunReadableStreamBYOBReaderConstructor.h"
#include "BunReadableStreamBYOBReader.h"
#include "BunReadableStream.h"
#include "JavaScriptCore/InternalFunction.h"
#include <JavaScriptCore/JSCInlines.h>
#include <JavaScriptCore/JSObjectInlines.h>
#include <JavaScriptCore/Error.h>
#include "JSDOMConstructorBase.h"
#include "JSDOMConstructorNotConstructable.h"
namespace Bun {
using namespace JSC;
const ClassInfo JSReadableStreamBYOBReaderConstructor::s_info = { "ReadableStreamBYOBReader"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSReadableStreamBYOBReaderConstructor) };
JSReadableStreamBYOBReaderConstructor::JSReadableStreamBYOBReaderConstructor(VM& vm, Structure* structure)
: Base(vm, structure, WebCore::callThrowTypeErrorForJSDOMConstructorNotCallableOrConstructable, WebCore::callThrowTypeErrorForJSDOMConstructorNotCallableOrConstructable)
{
}
void JSReadableStreamBYOBReaderConstructor::finishCreation(VM& vm, JSObject* prototype)
{
Base::finishCreation(vm, 1, "ReadableStreamBYOBReader"_s, InternalFunction::PropertyAdditionMode::WithStructureTransition);
ASSERT(inherits(info()));
putDirect(vm, vm.propertyNames->prototype, prototype, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly);
}
JSReadableStreamBYOBReaderConstructor* JSReadableStreamBYOBReaderConstructor::create(VM& vm, JSGlobalObject* globalObject, JSObject* prototype)
{
auto* structure = createStructure(vm, globalObject, prototype);
JSReadableStreamBYOBReaderConstructor* constructor = new (NotNull, allocateCell<JSReadableStreamBYOBReaderConstructor>(vm)) JSReadableStreamBYOBReaderConstructor(vm, structure);
constructor->finishCreation(vm, prototype);
return constructor;
}
Structure* JSReadableStreamBYOBReaderConstructor::createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
{
return Structure::create(vm, globalObject, prototype, TypeInfo(InternalFunctionType, StructureFlags), info());
}
} // namespace Bun

View File

@@ -0,0 +1,30 @@
#pragma once
#include "root.h"
#include <JavaScriptCore/JSObject.h>
#include <JavaScriptCore/JSObjectInlines.h>
namespace Bun {
class JSReadableStreamBYOBReaderConstructor final : public JSC::InternalFunction {
public:
using Base = JSC::InternalFunction;
static constexpr unsigned StructureFlags = Base::StructureFlags;
static JSReadableStreamBYOBReaderConstructor* create(JSC::VM&, JSC::JSGlobalObject*, JSObject* prototype);
static JSC::Structure* createStructure(JSC::VM&, JSC::JSGlobalObject*, JSC::JSValue prototype);
template<typename CellType, JSC::SubspaceAccess mode>
static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm)
{
return &vm.internalFunctionSpace();
}
DECLARE_INFO;
private:
JSReadableStreamBYOBReaderConstructor(JSC::VM&, JSC::Structure*);
void finishCreation(JSC::VM&, JSObject* prototype);
};
} // namespace Bun

View File

@@ -0,0 +1,166 @@
#include "root.h"
#include "BunReadableStreamBYOBReaderPrototype.h"
#include "BunReadableStreamBYOBReader.h"
#include "BunReadableStream.h"
#include "ZigGlobalObject.h"
namespace Bun {
using namespace JSC;
static JSC_DECLARE_CUSTOM_GETTER(jsReadableStreamBYOBReaderClosedGetter);
static JSC_DECLARE_CUSTOM_GETTER(jsReadableStreamBYOBReaderConstructor);
static JSC_DECLARE_HOST_FUNCTION(jsReadableStreamBYOBReaderRead);
static JSC_DECLARE_HOST_FUNCTION(jsReadableStreamBYOBReaderReleaseLock);
static JSC_DECLARE_HOST_FUNCTION(jsReadableStreamBYOBReaderCancel);
/* Hash table for prototype */
static const HashTableValue JSReadableStreamBYOBReaderPrototypeTableValues[] = {
{ "closed"_s, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::ReadOnly), NoIntrinsic, { HashTableValue::GetterSetterType, jsReadableStreamBYOBReaderClosedGetter, 0 } },
{ "read"_s, static_cast<unsigned>(JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::Builtin), NoIntrinsic, { HashTableValue::NativeFunctionType, jsReadableStreamBYOBReaderRead, 0 } },
{ "cancel"_s, static_cast<unsigned>(JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::Builtin), NoIntrinsic, { HashTableValue::NativeFunctionType, jsReadableStreamBYOBReaderCancel, 0 } },
{ "releaseLock"_s, static_cast<unsigned>(JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::Builtin), NoIntrinsic, { HashTableValue::NativeFunctionType, jsReadableStreamBYOBReaderReleaseLock, 0 } },
};
const ClassInfo JSReadableStreamBYOBReaderPrototype::s_info = { "ReadableStreamBYOBReader"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSReadableStreamBYOBReaderPrototype) };
JSReadableStreamBYOBReaderPrototype* JSReadableStreamBYOBReaderPrototype::create(VM& vm, JSGlobalObject* globalObject, Structure* structure)
{
auto* prototype = new (NotNull, allocateCell<JSReadableStreamBYOBReaderPrototype>(vm)) JSReadableStreamBYOBReaderPrototype(vm, structure);
prototype->finishCreation(vm);
return prototype;
}
Structure* JSReadableStreamBYOBReaderPrototype::createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
{
return Structure::create(vm, globalObject, prototype, TypeInfo(ObjectType, StructureFlags), info());
}
JSReadableStreamBYOBReaderPrototype::JSReadableStreamBYOBReaderPrototype(VM& vm, Structure* structure)
: Base(vm, structure)
{
}
void JSReadableStreamBYOBReaderPrototype::finishCreation(VM& vm)
{
Base::finishCreation(vm);
ASSERT(inherits(info()));
reifyStaticProperties(vm, info(), JSReadableStreamBYOBReaderPrototypeTableValues, *this);
this->structure()->setMayBePrototype(true);
}
JSC_DEFINE_CUSTOM_GETTER(jsReadableStreamBYOBReaderClosedGetter, (JSGlobalObject * globalObject, EncodedJSValue thisValue, PropertyName))
{
VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
auto* reader = jsDynamicCast<JSReadableStreamBYOBReader*>(JSValue::decode(thisValue));
if (!reader)
return throwVMTypeError(globalObject, scope, "ReadableStreamBYOBReader.prototype.closed called on incompatible receiver"_s);
return JSValue::encode(reader->closedPromise());
}
JSC_DEFINE_HOST_FUNCTION(jsReadableStreamBYOBReaderRead, (JSGlobalObject * globalObject, CallFrame* callFrame))
{
VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
// 1. Validate the reader
auto* reader = jsDynamicCast<JSReadableStreamBYOBReader*>(callFrame->thisValue());
if (!reader)
return throwVMTypeError(globalObject, scope, "ReadableStreamBYOBReader.prototype.read called on incompatible receiver"_s);
// 2. Check if stream is undefined (released)
if (!reader->stream())
return throwVMTypeError(globalObject, scope, "Cannot read from a released reader"_s);
// 3. Validate view argument
if (!callFrame->argumentCount())
return throwVMTypeError(globalObject, scope, "ReadableStreamBYOBReader.prototype.read requires at least one argument"_s);
JSValue viewValue = callFrame->argument(0);
if (!viewValue.isObject())
return throwVMTypeError(globalObject, scope, "ReadableStreamBYOBReader.prototype.read requires an ArrayBufferView argument"_s);
// 4. Get the ArrayBufferView
JSArrayBufferView* view = jsDynamicCast<JSArrayBufferView*>(viewValue);
if (!view)
return throwVMTypeError(globalObject, scope, "ReadableStreamBYOBReader.prototype.read requires an ArrayBufferView argument"_s);
// 7. Get read options
uint64_t minRequested = 1;
if (callFrame->argumentCount() > 1) {
JSValue options = callFrame->argument(1);
if (!options.isUndefined()) {
if (!options.isObject())
return throwVMTypeError(globalObject, scope, "ReadableStreamBYOBReader read options must be an object"_s);
JSObject* optionsObj = jsCast<JSObject*>(options);
JSValue minValue = optionsObj->get(globalObject, Identifier::fromString(vm, "min"_s));
RETURN_IF_EXCEPTION(scope, encodedJSValue());
if (!minValue.isUndefined()) {
minRequested = minValue.toNumber(globalObject);
RETURN_IF_EXCEPTION(scope, encodedJSValue());
if (minRequested == 0)
return throwVMTypeError(globalObject, scope, "min option must be greater than 0"_s);
if (minRequested > view->byteLength())
return throwVMRangeError(globalObject, scope, "min option cannot be greater than view's byte length"_s);
}
}
}
return JSValue::encode(reader->read(vm, globalObject, view, minRequested));
}
JSC_DEFINE_HOST_FUNCTION(jsReadableStreamBYOBReaderReleaseLock, (JSGlobalObject * globalObject, CallFrame* callFrame))
{
VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
// 1. Validate the reader
auto* reader = jsDynamicCast<JSReadableStreamBYOBReader*>(callFrame->thisValue());
if (!reader)
return throwVMTypeError(globalObject, scope, "ReadableStreamBYOBReader.prototype.releaseLock called on incompatible receiver"_s);
reader->releaseLock(vm, globalObject);
RETURN_IF_EXCEPTION(scope, encodedJSValue());
return JSValue::encode(jsUndefined());
}
JSC_DEFINE_HOST_FUNCTION(jsReadableStreamBYOBReaderCancel, (JSGlobalObject * globalObject, CallFrame* callFrame))
{
VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
// 1. Validate the reader
auto* reader = jsDynamicCast<JSReadableStreamBYOBReader*>(callFrame->thisValue());
if (!reader)
return throwVMTypeError(globalObject, scope, "ReadableStreamBYOBReader.prototype.cancel called on incompatible receiver"_s);
// 2. Check if stream is undefined (released)
JSReadableStream* stream = reader->stream();
if (!stream)
return throwVMTypeError(globalObject, scope, "Cannot cancel a released reader"_s);
// 3. Get cancel reason
JSValue reason = callFrame->argument(0);
// 4. Cancel the stream with the given reason
JSPromise* promise = stream->cancel(vm, globalObject, reason);
RETURN_IF_EXCEPTION(scope, encodedJSValue());
return JSValue::encode(promise);
}
JSC_DEFINE_CUSTOM_GETTER(jsReadableStreamBYOBReaderConstructor, (JSGlobalObject * globalObject, EncodedJSValue thisValue, PropertyName))
{
VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
return JSValue::encode(defaultGlobalObject(globalObject)->streams().constructor<JSReadableStreamBYOBReader>(globalObject));
}
}

View File

@@ -0,0 +1,30 @@
#pragma once
#include "root.h"
#include <JavaScriptCore/JSObject.h>
#include <JavaScriptCore/JSObjectInlines.h>
namespace Bun {
class JSReadableStreamBYOBReaderPrototype final : public JSC::JSNonFinalObject {
public:
using Base = JSC::JSNonFinalObject;
static constexpr unsigned StructureFlags = Base::StructureFlags;
static JSReadableStreamBYOBReaderPrototype* create(JSC::VM&, JSC::JSGlobalObject*, JSC::Structure*);
static JSC::Structure* createStructure(JSC::VM&, JSC::JSGlobalObject*, JSC::JSValue prototype);
template<typename CellType, JSC::SubspaceAccess mode>
static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm)
{
return &vm.plainObjectSpace();
}
DECLARE_INFO;
private:
JSReadableStreamBYOBReaderPrototype(JSC::VM&, JSC::Structure*);
void finishCreation(JSC::VM&);
};
} // namespace Bun

View File

@@ -0,0 +1,175 @@
#include "root.h"
#include "BunReadableStreamConstructor.h"
#include "BunReadableStream.h"
#include <JavaScriptCore/JSObjectInlines.h>
#include <JavaScriptCore/JSCInlines.h>
#include "ZigGlobalObject.h"
#include <JavaScriptCore/FunctionPrototype.h>
#include "ErrorCode.h"
#include "BunReadableStreamDefaultController.h"
namespace Bun {
using namespace JSC;
const ClassInfo JSReadableStreamConstructor::s_info = { "Function"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSReadableStreamConstructor) };
JSReadableStreamConstructor* JSReadableStreamConstructor::create(VM& vm, JSGlobalObject* globalObject, JSObject* prototype)
{
auto* structure = createStructure(vm, globalObject, prototype);
auto* constructor = new (NotNull, allocateCell<JSReadableStreamConstructor>(vm)) JSReadableStreamConstructor(vm, structure);
constructor->finishCreation(vm, globalObject, prototype);
return constructor;
}
Structure* JSReadableStreamConstructor::createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
{
return Structure::create(vm, globalObject, prototype, TypeInfo(InternalFunctionType, StructureFlags), info());
}
JSReadableStreamConstructor::JSReadableStreamConstructor(VM& vm, Structure* structure)
: Base(vm, structure, call, construct)
{
}
void JSReadableStreamConstructor::finishCreation(VM& vm, JSGlobalObject* globalObject, JSObject* prototype)
{
Base::finishCreation(vm, 1, "ReadableStream"_s, PropertyAdditionMode::WithStructureTransition);
putDirect(vm, vm.propertyNames->prototype, prototype, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly);
}
JSC::EncodedJSValue JSC_HOST_CALL_ATTRIBUTES JSReadableStreamConstructor::construct(JSGlobalObject* globalObject, CallFrame* callFrame)
{
VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
auto* zigGlobalObject = defaultGlobalObject(globalObject);
JSObject* newTarget = asObject(callFrame->newTarget());
auto& streams = zigGlobalObject->streams();
Structure* structure = streams.structure<JSReadableStream>(globalObject);
auto* constructor = streams.constructor<JSReadableStream>(globalObject);
if (!(!newTarget || newTarget != constructor)) {
if (newTarget) {
structure = JSC::InternalFunction::createSubclassStructure(getFunctionRealm(globalObject, newTarget), newTarget, structure);
} else {
structure = JSC::InternalFunction::createSubclassStructure(globalObject, constructor, structure);
}
}
JSValue underlyingSourceDict = callFrame->argument(0);
JSObject* underlyingSourceObj = nullptr;
if (!underlyingSourceDict.isUndefined() && !underlyingSourceDict.isNull()) {
underlyingSourceObj = underlyingSourceDict.getObject();
if (!underlyingSourceObj) {
Bun::throwError(globalObject, scope, Bun::ErrorCode::ERR_INVALID_ARG_TYPE, "underlyingSource must be an object or undefined"_s);
return {};
}
}
double highWaterMark = 1;
JSObject* startFunction = nullptr;
JSC::CallData startCallData;
JSObject* pullFunction = nullptr;
JSObject* cancelFunction = nullptr;
JSObject* sizeFunction = nullptr;
bool isBYOB = false;
auto& builtinNames = WebCore::builtinNames(vm);
if (underlyingSourceObj) {
JSValue typeValue = underlyingSourceObj->getIfPropertyExists(globalObject, vm.propertyNames->type);
RETURN_IF_EXCEPTION(scope, {});
if (typeValue && !typeValue.isNull() && !typeValue.isUndefined()) {
if (!typeValue.isString()) {
Bun::throwError(globalObject, scope, Bun::ErrorCode::ERR_INVALID_ARG_TYPE, "ReadableStream 'type' must be a string or undefined"_s);
return {};
}
auto typeString = typeValue.toWTFString(globalObject);
RETURN_IF_EXCEPTION(scope, {});
if (typeString == "byob"_s) {
isBYOB = true;
}
}
JSValue startValue = underlyingSourceObj->getIfPropertyExists(globalObject, builtinNames.startPublicName());
RETURN_IF_EXCEPTION(scope, {});
if (startValue && !startValue.isNull() && !startValue.isUndefined()) {
startFunction = startValue.getObject();
if (!startFunction) {
Bun::throwError(globalObject, scope, Bun::ErrorCode::ERR_INVALID_ARG_TYPE, "ReadableStream 'start' must be a function or undefined"_s);
return {};
}
startCallData = JSC::getCallData(startFunction);
if (startCallData.type == CallData::Type::None) {
Bun::throwError(globalObject, scope, Bun::ErrorCode::ERR_INVALID_ARG_TYPE, "ReadableStream 'start' must be a function or undefined"_s);
return {};
}
}
JSValue pullValue = underlyingSourceObj->getIfPropertyExists(globalObject, builtinNames.pullPublicName());
RETURN_IF_EXCEPTION(scope, {});
if (pullValue && !pullValue.isNull() && !pullValue.isUndefined()) {
pullFunction = pullValue.getObject();
if (!pullFunction || !pullFunction->isCallable()) {
Bun::throwError(globalObject, scope, Bun::ErrorCode::ERR_INVALID_ARG_TYPE, "ReadableStream 'pull' must be a function or undefined"_s);
return {};
}
}
JSValue cancelValue = underlyingSourceObj->getIfPropertyExists(globalObject, builtinNames.cancelPublicName());
RETURN_IF_EXCEPTION(scope, {});
if (cancelValue && !cancelValue.isNull() && !cancelValue.isUndefined()) {
cancelFunction = cancelValue.getObject();
if (!cancelFunction || !cancelFunction->isCallable()) {
Bun::throwError(globalObject, scope, Bun::ErrorCode::ERR_INVALID_ARG_TYPE, "ReadableStream 'cancel' must be a function or undefined"_s);
return {};
}
}
JSValue sizeValue = underlyingSourceObj->getIfPropertyExists(globalObject, vm.propertyNames->size);
RETURN_IF_EXCEPTION(scope, {});
if (sizeValue && !sizeValue.isNull() && !sizeValue.isUndefined()) {
sizeFunction = sizeValue.getObject();
}
}
if (isBYOB) {
// TODO: Implement BYOB
scope.throwException(globalObject, JSC::createTypeError(globalObject, "BYOB ReadableStream is not implemented"_s));
return {};
}
auto* stream = JSReadableStream::create(vm, globalObject, structure);
RETURN_IF_EXCEPTION(scope, {});
JSReadableStreamDefaultController* controller = JSReadableStreamDefaultController::create(vm, globalObject, streams.structure<JSReadableStreamDefaultController>(globalObject), stream);
RETURN_IF_EXCEPTION(scope, {});
stream->setController(vm, controller);
controller->setup(vm, globalObject, stream, underlyingSourceObj, startFunction, pullFunction, cancelFunction, highWaterMark, sizeFunction);
return JSValue::encode(stream);
}
JSC::EncodedJSValue JSC_HOST_CALL_ATTRIBUTES JSReadableStreamConstructor::call(JSGlobalObject* globalObject, CallFrame* callFrame)
{
VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
return throwVMTypeError(globalObject, scope, "ReadableStream constructor cannot be called without 'new'"_s);
}
} // namespace Bun

View File

@@ -0,0 +1,36 @@
#pragma once
#include "root.h"
#include <JavaScriptCore/JSGlobalObject.h>
#include <JavaScriptCore/InternalFunction.h>
#include <JavaScriptCore/JSObject.h>
#include <JavaScriptCore/JSValue.h>
namespace Bun {
using namespace JSC;
class JSReadableStreamConstructor final : public JSC::InternalFunction {
public:
using Base = JSC::InternalFunction;
static constexpr unsigned StructureFlags = Base::StructureFlags;
static JSReadableStreamConstructor* create(VM&, JSGlobalObject*, JSObject*);
static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype);
DECLARE_INFO;
template<typename CellType, SubspaceAccess>
static JSC::GCClient::IsoSubspace* subspaceFor(VM& vm)
{
return &vm.internalFunctionSpace();
}
static JSC::EncodedJSValue JSC_HOST_CALL_ATTRIBUTES construct(JSGlobalObject*, CallFrame*);
static JSC::EncodedJSValue JSC_HOST_CALL_ATTRIBUTES call(JSGlobalObject*, CallFrame*);
private:
JSReadableStreamConstructor(VM& vm, Structure* structure);
void finishCreation(VM& vm, JSGlobalObject* globalObject, JSObject* prototype);
};
} // namespace Bun

View File

@@ -0,0 +1,402 @@
#include "JavaScriptCore/SlotVisitorMacros.h"
#include "root.h"
#include "JavaScriptCore/IteratorOperations.h"
#include "BunReadableStreamDefaultController.h"
#include <JavaScriptCore/JSObject.h>
#include <JavaScriptCore/JSObjectInlines.h>
#include <JavaScriptCore/JSArray.h>
#include "BunReadableStream.h"
#include <JavaScriptCore/ObjectConstructor.h>
#include <JavaScriptCore/Completion.h>
#include "BunReadableStreamDefaultReader.h"
#include "DOMIsoSubspaces.h"
#include "BunClientData.h"
#include "BunStreamStructures.h"
#include "DOMClientIsoSubspaces.h"
#include <JavaScriptCore/LazyPropertyInlines.h>
#include <JavaScriptCore/JSPromise.h>
#include "BunStreamInlines.h"
#include "wtf/Assertions.h"
namespace Bun {
using namespace JSC;
template<typename CellType, JSC::SubspaceAccess mode>
JSC::GCClient::IsoSubspace* JSReadableStreamDefaultController::subspaceFor(JSC::VM& vm)
{
return WebCore::subspaceForImpl<JSReadableStreamDefaultController, WebCore::UseCustomHeapCellType::No>(
vm,
[](auto& spaces) { return spaces.m_clientSubspaceForJSReadableStreamDefaultController.get(); },
[](auto& spaces, auto&& space) { spaces.m_clientSubspaceForJSReadableStreamDefaultController = std::forward<decltype(space)>(space); },
[](auto& spaces) { return spaces.m_subspaceForJSReadableStreamDefaultController.get(); },
[](auto& spaces, auto&& space) { spaces.m_subspaceForJSReadableStreamDefaultController = std::forward<decltype(space)>(space); });
}
JSReadableStreamDefaultController::JSReadableStreamDefaultController(VM& vm, Structure* structure)
: Base(vm, structure)
{
}
template<typename Visitor>
void JSReadableStreamDefaultController::visitChildrenImpl(JSC::JSCell* cell, Visitor& visitor)
{
auto* thisObject = static_cast<JSReadableStreamDefaultController*>(cell);
Base::visitChildren(cell, visitor);
thisObject->visitAdditionalChildren(visitor);
}
template<typename Visitor>
void JSReadableStreamDefaultController::visitAdditionalChildren(Visitor& visitor)
{
visitor.append(m_underlyingSource);
visitor.append(m_pullAlgorithm);
visitor.append(m_cancelAlgorithm);
visitor.append(m_stream);
m_queue.visit<Visitor>(this, visitor);
}
template<typename Visitor>
void JSReadableStreamDefaultController::visitOutputConstraintsImpl(JSCell* cell, Visitor& visitor)
{
auto* thisObject = jsCast<JSReadableStreamDefaultController*>(cell);
Base::visitOutputConstraints(cell, visitor);
thisObject->visitAdditionalChildren(visitor);
}
DEFINE_VISIT_CHILDREN(JSReadableStreamDefaultController);
DEFINE_VISIT_ADDITIONAL_CHILDREN(JSReadableStreamDefaultController);
DEFINE_VISIT_OUTPUT_CONSTRAINTS(JSReadableStreamDefaultController);
JSReadableStreamDefaultController* JSReadableStreamDefaultController::create(VM& vm, JSGlobalObject* globalObject, Structure* structure, JSReadableStream* stream)
{
JSReadableStreamDefaultController* controller = new (NotNull, JSC::allocateCell<JSReadableStreamDefaultController>(vm)) JSReadableStreamDefaultController(vm, structure);
controller->finishCreation(vm, stream);
return controller;
}
JSReadableStream* JSReadableStreamDefaultController::stream() const
{
return jsDynamicCast<JSReadableStream*>(m_stream.get());
}
JSValue JSReadableStreamDefaultController::desiredSizeValue()
{
if (!canCloseOrEnqueue())
return jsNull();
// According to spec, desiredSize = highWaterMark - queueTotalSize
return jsNumber(queue().desiredSize());
}
double JSReadableStreamDefaultController::desiredSize() const
{
if (!canCloseOrEnqueue())
return PNaN;
return queue().desiredSize();
}
bool JSReadableStreamDefaultController::canCloseOrEnqueue() const
{
// If closeRequested, we can no longer enqueue
if (m_closeRequested)
return false;
// Get stream state
auto* stream = this->stream();
ASSERT(stream);
return stream->state() == JSReadableStream::State::Readable;
}
void JSReadableStreamDefaultController::performPullSteps(VM& vm, JSGlobalObject* globalObject, JSPromise* readRequest)
{
auto* stream = this->stream();
ASSERT(stream);
if (!this->queue().isEmpty()) {
// Let chunk be ! DequeueValue(this).
JSValue chunk = this->queue().dequeueValue(vm, globalObject, this);
ASSERT(!chunk.isEmpty());
// Perform readRequests chunk steps, given chunk.
readRequest->fulfill(globalObject, JSC::createIteratorResultObject(globalObject, chunk, false));
return;
}
if (m_closeRequested) {
// Perform ! ReadableStreamDefaultControllerClearAlgorithms(this).
this->clearAlgorithms();
// Perform ! ReadableStreamClose(stream).
stream->close(globalObject);
readRequest->fulfill(globalObject, createIteratorResultObject(globalObject, jsUndefined(), true));
return;
}
stream->reader()->addReadRequest(vm, globalObject, readRequest);
// Otherwise, perform ! ReadableStreamDefaultControllerCallPullIfNeeded(this).
this->callPullIfNeeded(globalObject);
}
JSValue JSReadableStreamDefaultController::enqueue(VM& vm, JSGlobalObject* globalObject, JSValue chunk)
{
auto scope = DECLARE_THROW_SCOPE(vm);
if (!canCloseOrEnqueue())
return throwTypeError(globalObject, scope, "Cannot enqueue chunk to closed stream"_s);
if (auto* reader = stream()->reader()) {
if (!reader->isEmpty()) {
// Assert: ! ReadableStreamHasDefaultReader(stream) is true.
// 1. Let reader be stream.[[reader]].
// 2. Assert: reader.[[readRequests]] is not empty.
// 3. Let readRequest be reader.[[readRequests]][0].
JSPromise* readRequest = reader->takeFirst(vm, globalObject);
JSObject* result = JSC::createIteratorResultObject(globalObject, chunk, false);
readRequest->fulfill(globalObject, result);
callPullIfNeeded(globalObject);
return jsUndefined();
}
}
queue().enqueueValueAndGetSize(vm, globalObject, this, chunk);
RETURN_IF_EXCEPTION(scope, {});
callPullIfNeeded(globalObject);
return jsUndefined();
}
void JSReadableStreamDefaultController::error(VM& vm, JSGlobalObject* globalObject, JSValue error)
{
auto* stream = jsDynamicCast<JSReadableStream*>(m_stream.get());
ASSERT(stream);
if (stream->state() != JSReadableStream::State::Readable)
return;
// Reset queue
queue().resetQueue(vm, globalObject, this);
// Clear our algorithms so we stop executing them
clearAlgorithms();
stream->error(globalObject, error);
}
void JSReadableStreamDefaultController::close(VM& vm, JSGlobalObject* globalObject)
{
if (!canCloseOrEnqueue())
return;
auto* stream = this->stream();
ASSERT(stream);
m_closeRequested = true;
// If queue is empty, we can close immediately
if (queue().isEmpty()) {
clearAlgorithms();
stream->close(globalObject);
}
}
JSC_DEFINE_HOST_FUNCTION(jsReadableStreamDefaultControllerFullfillPull, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame))
{
auto& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
JSReadableStreamDefaultController* thisObject = jsDynamicCast<JSReadableStreamDefaultController*>(callFrame->argument(1));
if (!thisObject)
return throwVMTypeError(globalObject, scope, "ReadableStreamDefaultController.prototype.callPullIfNeeded called on incompatible object"_s);
thisObject->fulfillPull(globalObject);
return JSValue::encode(jsUndefined());
}
void JSReadableStreamDefaultController::fulfillPull(JSGlobalObject* globalObject)
{
m_pulling = false;
// If pullAgain was set while we were pulling, pull again
if (m_pullAgain) {
m_pullAgain = false;
this->callPullIfNeeded(globalObject);
}
}
JSC_DEFINE_HOST_FUNCTION(jsReadableStreamDefaultControllerRejectPull, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame))
{
auto& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
JSReadableStreamDefaultController* thisObject = jsDynamicCast<JSReadableStreamDefaultController*>(callFrame->argument(1));
if (!thisObject)
return throwVMTypeError(globalObject, scope, "ReadableStreamDefaultController.prototype.rejectPull called on incompatible object"_s);
thisObject->rejectPull(globalObject, callFrame->argument(0));
return JSValue::encode(jsUndefined());
}
void JSReadableStreamDefaultController::rejectPull(JSGlobalObject* globalObject, JSValue error)
{
m_pulling = false;
this->error(globalObject, error);
}
void JSReadableStreamDefaultController::setup(
JSC::VM& vm,
JSC::JSGlobalObject* globalObject,
Bun::JSReadableStream* stream,
JSC::JSObject* underlyingSource,
JSC::JSObject* startAlgorithm,
JSC::JSObject* pullAlgorithm,
JSC::JSObject* cancelAlgorithm,
double highWaterMark,
JSC::JSObject* sizeAlgorithm)
{
queue().initialize(vm, globalObject, highWaterMark, this, sizeAlgorithm);
if (pullAlgorithm) setPullAlgorithm(pullAlgorithm);
if (cancelAlgorithm) setCancelAlgorithm(cancelAlgorithm);
if (underlyingSource) setUnderlyingSource(underlyingSource);
// 4. Set controller.[[started]], controller.[[closeRequested]], controller.[[pullAgain]], and controller.[[pulling]] to false.
m_started = false;
m_closeRequested = false;
m_pullAgain = false;
m_pulling = false;
// Set stream's controller to this
stream->setController(vm, this);
auto scope = DECLARE_THROW_SCOPE(vm);
// Call start algorithm if provided
if (startAlgorithm) {
MarkedArgumentBuffer args;
args.append(this);
auto callData = JSC::getCallData(startAlgorithm);
if (callData.type == JSC::CallData::Type::None) {
throwTypeError(globalObject, scope, "Start function is not callable"_s);
return;
}
JSValue startResult = JSC::profiledCall(globalObject, ProfilingReason::API, startAlgorithm, callData, underlyingSource, args);
RETURN_IF_EXCEPTION(scope, );
// Handle promise fulfillment/rejection
if (startResult && !startResult.isUndefined()) {
if (JSPromise* promise = jsDynamicCast<JSPromise*>(startResult)) {
switch (promise->status(vm)) {
case JSPromise::Status::Fulfilled:
break;
case JSPromise::Status::Rejected:
this->error(globalObject, promise->result(vm));
return;
case JSPromise::Status::Pending:
// We need to wait for the promise to resolve
ASSERT_NOT_REACHED_WITH_MESSAGE("TODO: handle pending start promise");
return;
}
}
}
}
m_started = true;
callPullIfNeeded(globalObject);
}
void JSReadableStreamDefaultController::callPullIfNeeded(JSGlobalObject* globalObject)
{
VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
// Return if we can't/shouldn't pull
if (!shouldCallPull())
return;
// Already pulling, flag to pull again when done
if (m_pulling) {
m_pullAgain = true;
return;
}
// Call pull algorithm
JSObject* pullAlgorithm = m_pullAlgorithm.get();
if (!pullAlgorithm) {
m_pulling = false;
m_pullAgain = false;
return;
}
m_pulling = true;
MarkedArgumentBuffer args;
args.append(this);
EnsureStillAliveScope ensureStillAliveScope(this);
JSValue result = JSC::profiledCall(globalObject, ProfilingReason::API, pullAlgorithm, JSC::getCallData(pullAlgorithm), m_underlyingSource.get(), args);
if (scope.exception()) {
m_pulling = false;
// TODO: is there more we should do here?
return;
}
// Handle the promise returned by pull
if (JSPromise* promise = jsDynamicCast<JSPromise*>(result)) {
Bun::then(globalObject, promise, jsReadableStreamDefaultControllerFullfillPull, jsReadableStreamDefaultControllerRejectPull, this);
} else {
// Not a promise, just mark pulling as done
m_pulling = false;
}
}
bool JSReadableStreamDefaultController::shouldCallPull() const
{
auto* stream = this->stream();
ASSERT(stream);
if (!m_started)
return false;
if (stream->state() != JSReadableStream::State::Readable)
return false;
if (m_closeRequested)
return false;
auto* reader = stream->reader();
// If ! IsReadableStreamLocked(stream) is true and ! ReadableStreamGetNumReadRequests(stream) > 0, return true.
if ((!stream->isLocked() || reader->isEmpty()) && desiredSize() <= 0)
return false;
return true;
}
void JSReadableStreamDefaultController::clearAlgorithms()
{
// m_pullAlgorithm.clear();
// m_cancelAlgorithm.clear();
// m_underlyingSource.clear();
// queue().clearAlgorithms();
}
void JSReadableStreamDefaultController::finishCreation(VM& vm, JSReadableStream* stream)
{
Base::finishCreation(vm);
m_stream.set(vm, this, stream);
m_pullAlgorithm.clear();
m_cancelAlgorithm.clear();
m_underlyingSource.clear();
queue().resetQueue(vm, globalObject(), this);
}
const ClassInfo JSReadableStreamDefaultController::s_info = { "ReadableStreamDefaultController"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSReadableStreamDefaultController) };
}

View File

@@ -0,0 +1,115 @@
#pragma once
#include "root.h"
#include <JavaScriptCore/JSObject.h>
#include <JavaScriptCore/JSObjectInlines.h>
#include "JavaScriptCore/JSCast.h"
#include <JavaScriptCore/LazyProperty.h>
#include "BunStreamQueue.h"
namespace Bun {
class JSReadableStream;
class JSReadableStreamDefaultController final : public JSC::JSDestructibleObject {
public:
using Base = JSC::JSDestructibleObject;
static constexpr bool needsDestruction = true;
static void destroy(JSC::JSCell* cell)
{
static_cast<JSReadableStreamDefaultController*>(cell)->~JSReadableStreamDefaultController();
}
~JSReadableStreamDefaultController()
{
}
static JSReadableStreamDefaultController* create(JSC::VM&, JSC::JSGlobalObject*, JSC::Structure*, JSReadableStream*);
static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
{
return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info());
}
template<typename CellType, JSC::SubspaceAccess mode>
static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm);
DECLARE_INFO;
DECLARE_VISIT_CHILDREN;
DECLARE_VISIT_OUTPUT_CONSTRAINTS;
template<typename Visitor>
void visitAdditionalChildren(Visitor& visitor);
void performPullSteps(JSC::VM&, JSC::JSGlobalObject*, JSC::JSPromise* readRequest);
// SetUpReadableStreamDefaultController(stream, controller, startAlgorithm, pullAlgorithm, cancelAlgorithm, highWaterMark, sizeAlgorithm) performs the following steps:
void setup(
JSC::VM& vm,
JSC::JSGlobalObject* globalObject,
Bun::JSReadableStream* stream,
JSC::JSObject* underlyingSource = nullptr,
JSC::JSObject* startAlgorithm = nullptr,
JSC::JSObject* pullAlgorithm = nullptr,
JSC::JSObject* cancelAlgorithm = nullptr,
double highWaterMark = 1,
JSC::JSObject* sizeAlgorithm = nullptr);
void attach(JSReadableStream* stream);
bool isByteController() const { return false; }
JSC::JSObject* cancelAlgorithm() const { return m_cancelAlgorithm.get(); }
// Internal slots from the spec
const Bun::StreamQueue& queue() const { return m_queue; }
Bun::StreamQueue& queue() { return m_queue; }
bool started() const { return m_started; }
bool closeRequested() const { return m_closeRequested; }
bool pullAgain() const { return m_pullAgain; }
bool pulling() const { return m_pulling; }
double desiredSize() const;
JSC::JSValue desiredSizeValue();
// API for C++ usage
JSC::JSValue enqueue(JSC::VM&, JSC::JSGlobalObject*, JSC::JSValue chunk);
JSC::JSValue enqueue(JSC::JSGlobalObject* globalObject, JSC::JSValue chunk) { return this->enqueue(this->vm(), globalObject, chunk); }
void error(JSC::VM&, JSC::JSGlobalObject*, JSC::JSValue error);
void error(JSC::JSGlobalObject* globalObject, JSC::JSValue error) { this->error(this->vm(), globalObject, error); }
void close(JSC::VM&, JSC::JSGlobalObject*);
void close(JSC::JSGlobalObject* globalObject) { this->close(this->vm(), globalObject); }
bool canCloseOrEnqueue() const;
JSC::JSObject* pullAlgorithm() const { return m_pullAlgorithm.get(); }
void setPullAlgorithm(JSC::JSObject* callback) { m_pullAlgorithm.set(vm(), this, callback); }
void setCancelAlgorithm(JSC::JSObject* callback) { m_cancelAlgorithm.set(vm(), this, callback); }
void setUnderlyingSource(JSC::JSObject* underlyingSource) { m_underlyingSource.set(vm(), this, underlyingSource); }
void fulfillPull(JSC::JSGlobalObject*);
void rejectPull(JSC::JSGlobalObject*, JSC::JSValue error);
void callPullIfNeeded(JSC::JSGlobalObject*);
bool shouldCallPull() const;
JSReadableStream* stream() const;
JSC::JSObject* underlyingSource() const { return m_underlyingSource.get(); }
void clearAlgorithms();
void setHighWaterMark(double highWaterMark) { m_queue.highWaterMark = highWaterMark; }
private:
JSReadableStreamDefaultController(JSC::VM&, JSC::Structure*);
void finishCreation(JSC::VM&, JSReadableStream*);
// Internal slots
Bun::StreamQueue m_queue {};
mutable JSC::WriteBarrier<JSReadableStream> m_stream;
mutable JSC::WriteBarrier<JSC::JSObject> m_pullAlgorithm;
mutable JSC::WriteBarrier<JSC::JSObject> m_cancelAlgorithm;
mutable JSC::WriteBarrier<JSC::JSObject> m_underlyingSource;
bool m_started { false };
bool m_closeRequested { false };
bool m_pullAgain { false };
bool m_pulling { false };
};
} // namespace Bun

View File

@@ -0,0 +1,31 @@
#include "root.h"
#include "BunReadableStreamDefaultControllerConstructor.h"
#include <JavaScriptCore/JSObjectInlines.h>
#include "JSDOMConstructorBase.h"
namespace Bun {
using namespace JSC;
const ClassInfo JSReadableStreamDefaultControllerConstructor::s_info = { "ReadableStreamDefaultController"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSReadableStreamDefaultControllerConstructor) };
JSReadableStreamDefaultControllerConstructor* JSReadableStreamDefaultControllerConstructor::create(VM& vm, JSGlobalObject* globalObject, JSObject* prototype)
{
auto* structure = createStructure(vm, globalObject, prototype);
JSReadableStreamDefaultControllerConstructor* ptr = new (NotNull, allocateCell<JSReadableStreamDefaultControllerConstructor>(vm)) JSReadableStreamDefaultControllerConstructor(vm, structure);
ptr->finishCreation(vm, globalObject, prototype);
return ptr;
}
JSReadableStreamDefaultControllerConstructor::JSReadableStreamDefaultControllerConstructor(VM& vm, Structure* structure)
: Base(vm, structure, WebCore::callThrowTypeErrorForJSDOMConstructorNotCallableOrConstructable, WebCore::callThrowTypeErrorForJSDOMConstructorNotCallableOrConstructable)
{
}
void JSReadableStreamDefaultControllerConstructor::finishCreation(VM& vm, JSGlobalObject* globalObject, JSObject* prototype)
{
Base::finishCreation(vm, 0, "ReadableStreamDefaultController"_s, PropertyAdditionMode::WithStructureTransition);
putDirect(vm, vm.propertyNames->prototype, prototype, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly);
}
} // namespace Bun

View File

@@ -0,0 +1,34 @@
#pragma once
#include "root.h"
#include <JavaScriptCore/InternalFunction.h>
#include <JavaScriptCore/JSObject.h>
#include <JavaScriptCore/JSObjectInlines.h>
namespace Bun {
class JSReadableStreamDefaultControllerConstructor final : public JSC::InternalFunction {
public:
using Base = JSC::InternalFunction;
static JSReadableStreamDefaultControllerConstructor* create(JSC::VM&, JSC::JSGlobalObject*, JSC::JSObject* prototype);
DECLARE_INFO;
template<typename CellType, JSC::SubspaceAccess>
static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm)
{
return &vm.internalFunctionSpace();
}
static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
{
return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::InternalFunctionType, StructureFlags), info());
}
private:
JSReadableStreamDefaultControllerConstructor(JSC::VM&, JSC::Structure*);
void finishCreation(JSC::VM&, JSC::JSGlobalObject*, JSC::JSObject* prototype);
};
} // namespace Bun

View File

@@ -0,0 +1,94 @@
#include "root.h"
#include "BunReadableStreamDefaultControllerPrototype.h"
#include "BunReadableStreamDefaultController.h"
#include <JavaScriptCore/JSObjectInlines.h>
namespace Bun {
using namespace JSC;
const ClassInfo JSReadableStreamDefaultControllerPrototype::s_info = { "ReadableStreamDefaultController"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSReadableStreamDefaultControllerPrototype) };
JSC_DEFINE_HOST_FUNCTION(jsReadableStreamDefaultControllerPrototypeClose, (JSGlobalObject * globalObject, CallFrame* callFrame))
{
VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
JSReadableStreamDefaultController* controller = jsDynamicCast<JSReadableStreamDefaultController*>(callFrame->thisValue());
if (!controller)
return throwVMTypeError(globalObject, scope, "ReadableStreamDefaultController.prototype.close called on incompatible object"_s);
controller->close(globalObject);
return JSValue::encode(jsUndefined());
}
JSC_DEFINE_HOST_FUNCTION(jsReadableStreamDefaultControllerPrototypeEnqueue, (JSGlobalObject * globalObject, CallFrame* callFrame))
{
VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
JSReadableStreamDefaultController* controller = jsDynamicCast<JSReadableStreamDefaultController*>(callFrame->thisValue());
if (!controller)
return throwVMTypeError(globalObject, scope, "ReadableStreamDefaultController.prototype.enqueue called on incompatible object"_s);
JSValue chunk = callFrame->argument(0);
return JSValue::encode(controller->enqueue(vm, globalObject, chunk));
}
JSC_DEFINE_HOST_FUNCTION(jsReadableStreamDefaultControllerPrototypeError, (JSGlobalObject * globalObject, CallFrame* callFrame))
{
VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
JSReadableStreamDefaultController* controller = jsDynamicCast<JSReadableStreamDefaultController*>(callFrame->thisValue());
if (!controller)
return throwVMTypeError(globalObject, scope, "ReadableStreamDefaultController.prototype.error called on incompatible object"_s);
JSValue error = callFrame->argument(0);
controller->error(globalObject, error);
return JSValue::encode(jsUndefined());
}
JSC_DEFINE_CUSTOM_GETTER(jsReadableStreamDefaultControllerPrototypeDesiredSizeGetter, (JSGlobalObject * globalObject, EncodedJSValue thisValue, PropertyName))
{
VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
JSReadableStreamDefaultController* controller = jsDynamicCast<JSReadableStreamDefaultController*>(JSValue::decode(thisValue));
if (!controller)
return throwVMTypeError(globalObject, scope, "ReadableStreamDefaultController.prototype.desiredSize called on incompatible object"_s);
return JSValue::encode(controller->desiredSizeValue());
}
static const HashTableValue JSReadableStreamDefaultControllerPrototypeTableValues[] = {
{ "close"_s, static_cast<unsigned>(PropertyAttribute::Function), NoIntrinsic,
{ HashTableValue::NativeFunctionType, jsReadableStreamDefaultControllerPrototypeClose, 0 } },
{ "enqueue"_s, static_cast<unsigned>(PropertyAttribute::Function), NoIntrinsic,
{ HashTableValue::NativeFunctionType, jsReadableStreamDefaultControllerPrototypeEnqueue, 1 } },
{ "error"_s, static_cast<unsigned>(PropertyAttribute::Function), NoIntrinsic,
{ HashTableValue::NativeFunctionType, jsReadableStreamDefaultControllerPrototypeError, 1 } },
{ "desiredSize"_s, static_cast<unsigned>(PropertyAttribute::CustomAccessor | PropertyAttribute::ReadOnly), NoIntrinsic,
{ HashTableValue::GetterSetterType, jsReadableStreamDefaultControllerPrototypeDesiredSizeGetter, nullptr } }
};
JSReadableStreamDefaultControllerPrototype* JSReadableStreamDefaultControllerPrototype::create(VM& vm, JSGlobalObject* globalObject, Structure* structure)
{
JSReadableStreamDefaultControllerPrototype* ptr = new (NotNull, allocateCell<JSReadableStreamDefaultControllerPrototype>(vm)) JSReadableStreamDefaultControllerPrototype(vm, structure);
ptr->finishCreation(vm, globalObject);
return ptr;
}
JSReadableStreamDefaultControllerPrototype::JSReadableStreamDefaultControllerPrototype(VM& vm, Structure* structure)
: Base(vm, structure)
{
}
void JSReadableStreamDefaultControllerPrototype::finishCreation(VM& vm, JSGlobalObject* globalObject)
{
Base::finishCreation(vm);
reifyStaticProperties(vm, info(), JSReadableStreamDefaultControllerPrototypeTableValues, *this);
JSC_TO_STRING_TAG_WITHOUT_TRANSITION();
}
} // namespace Bun

View File

@@ -0,0 +1,36 @@
#pragma once
#include "root.h"
#include <JavaScriptCore/JSObject.h>
#include <JavaScriptCore/JSObjectInlines.h>
namespace Bun {
class JSReadableStreamDefaultControllerPrototype final : public JSC::JSNonFinalObject {
public:
using Base = JSC::JSNonFinalObject;
static JSReadableStreamDefaultControllerPrototype* create(JSC::VM&, JSC::JSGlobalObject*, JSC::Structure*);
DECLARE_INFO;
template<typename CellType, JSC::SubspaceAccess>
static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm)
{
STATIC_ASSERT_ISO_SUBSPACE_SHARABLE(JSReadableStreamDefaultControllerPrototype, Base);
return &vm.plainObjectSpace();
}
static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
{
auto* structure = JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info());
structure->setMayBePrototype(true);
return structure;
}
private:
JSReadableStreamDefaultControllerPrototype(JSC::VM&, JSC::Structure*);
void finishCreation(JSC::VM&, JSC::JSGlobalObject*);
};
} // namespace Bun

View File

@@ -0,0 +1,171 @@
#include "root.h"
#include "JavaScriptCore/ArrayAllocationProfile.h"
#include "JavaScriptCore/JSGlobalObject.h"
#include <JavaScriptCore/LazyPropertyInlines.h>
#include "BunReadableStreamDefaultReader.h"
#include "BunClientData.h"
#include "BunReadableStream.h"
#include "BunReadableStreamDefaultController.h"
#include "BunStreamInlines.h"
#include "BunTeeState.h"
#include "JSAbortSignal.h"
#include <JavaScriptCore/JSPromise.h>
#include <JavaScriptCore/JSArray.h>
#include <JavaScriptCore/JSObjectInlines.h>
#include <JavaScriptCore/WriteBarrierInlines.h>
#include <JavaScriptCore/VMTrapsInlines.h>
namespace Bun {
using namespace JSC;
const ClassInfo JSReadableStreamDefaultReader::s_info = { "ReadableStreamDefaultReader"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSReadableStreamDefaultReader) };
JSReadableStreamDefaultReader* JSReadableStreamDefaultReader::create(JSC::VM& vm, JSGlobalObject* globalObject, JSC::Structure* structure, JSReadableStream* stream)
{
JSReadableStreamDefaultReader* reader = new (NotNull, JSC::allocateCell<JSReadableStreamDefaultReader>(vm)) JSReadableStreamDefaultReader(vm, structure);
reader->finishCreation(vm, stream);
return reader;
}
template<typename Visitor>
void JSReadableStreamDefaultReader::visitChildrenImpl(JSCell* cell, Visitor& visitor)
{
auto* reader = static_cast<JSReadableStreamDefaultReader*>(cell);
ASSERT_GC_OBJECT_INHERITS(reader, JSReadableStreamDefaultReader::info());
Base::visitChildren(reader, visitor);
reader->visitAdditionalChildren(visitor);
}
template<typename Visitor>
void JSReadableStreamDefaultReader::visitAdditionalChildren(Visitor& visitor)
{
m_readyPromise.visit(visitor);
m_closedPromise.visit(visitor);
visitor.append(m_stream);
{
WTF::Locker lock(cellLock());
for (auto request : m_readRequests) {
if (request.isCell())
visitor.appendUnbarriered(request);
}
}
}
DEFINE_VISIT_CHILDREN(JSReadableStreamDefaultReader);
template<typename Visitor>
void JSReadableStreamDefaultReader::visitOutputConstraintsImpl(JSCell* cell, Visitor& visitor)
{
auto* thisObject = jsCast<JSReadableStreamDefaultReader*>(cell);
Base::visitOutputConstraints(cell, visitor);
thisObject->visitAdditionalChildren(visitor);
}
DEFINE_VISIT_ADDITIONAL_CHILDREN(JSReadableStreamDefaultReader);
DEFINE_VISIT_OUTPUT_CONSTRAINTS(JSReadableStreamDefaultReader);
void JSReadableStreamDefaultReader::finishCreation(JSC::VM& vm, JSReadableStream* stream)
{
Base::finishCreation(vm);
ASSERT(inherits(info()));
m_stream.setMayBeNull(vm, this, stream);
m_closedPromise.initLater(
[](const auto& init) {
auto& vm = init.vm;
auto* globalObject = init.owner->globalObject();
init.set(JSC::JSPromise::create(vm, globalObject->promiseStructure()));
});
m_readyPromise.initLater(
[](const auto& init) {
auto& vm = init.vm;
auto* globalObject = init.owner->globalObject();
init.set(JSC::JSPromise::create(vm, globalObject->promiseStructure()));
});
}
JSPromise* JSReadableStreamDefaultReader::takeFirst(JSC::VM& vm, JSGlobalObject* globalObject)
{
if (m_readRequests.isEmpty()) {
return nullptr;
}
JSValue first;
{
WTF::Locker lock(cellLock());
first = m_readRequests.takeFirst();
}
return jsCast<JSPromise*>(first);
}
void JSReadableStreamDefaultReader::detach()
{
ASSERT(isActive());
m_stream.clear();
}
void JSReadableStreamDefaultReader::releaseLock()
{
if (!isActive())
return;
// Release the stream's reader reference
stream()->setReader(vm(), nullptr);
detach();
}
JSPromise* JSReadableStreamDefaultReader::cancel(JSC::VM& vm, JSGlobalObject* globalObject, JSValue reason)
{
auto* stream = this->stream();
if (!stream) {
return JSPromise::rejectedPromise(globalObject, createTypeError(globalObject, "ReadableStreamDefaultReader.prototype.cancel called on reader with no ReadableStream"_s));
}
return stream->cancel(vm, globalObject, reason);
}
void JSReadableStreamDefaultReader::addReadRequest(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue promise)
{
WTF::Locker lock(cellLock());
m_readRequests.append(promise);
}
JSPromise* JSReadableStreamDefaultReader::read(JSC::VM& vm, JSGlobalObject* globalObject)
{
auto scope = DECLARE_THROW_SCOPE(vm);
if (!this->isActive()) {
scope.throwException(globalObject, createTypeError(globalObject, "ReadableStreamDefaultReader.prototype.read called on released reader"_s));
return nullptr;
}
JSPromise* promise = JSPromise::create(vm, globalObject->promiseStructure());
EnsureStillAliveScope ensureStillAlive(promise);
stream()->controller()->performPullSteps(vm, globalObject, promise);
return promise;
}
JSReadableStream* JSReadableStreamDefaultReader::stream() const
{
return jsCast<JSReadableStream*>(m_stream.get());
}
GCClient::IsoSubspace* JSReadableStreamDefaultReader::subspaceForImpl(JSC::VM& vm)
{
return WebCore::subspaceForImpl<JSReadableStreamDefaultReader, WebCore::UseCustomHeapCellType::No>(
vm,
[](auto& spaces) { return spaces.m_clientSubspaceForJSReadableStreamDefaultReader.get(); },
[](auto& spaces, auto&& space) { spaces.m_clientSubspaceForJSReadableStreamDefaultReader = std::forward<decltype(space)>(space); },
[](auto& spaces) { return spaces.m_subspaceForJSReadableStreamDefaultReader.get(); },
[](auto& spaces, auto&& space) { spaces.m_subspaceForJSReadableStreamDefaultReader = std::forward<decltype(space)>(space); });
}
} // namespace Bun

View File

@@ -0,0 +1,91 @@
#pragma once
#include "JavaScriptCore/JSGlobalObject.h"
#include "root.h"
#include "JavaScriptCore/JSDestructibleObject.h"
#include <JavaScriptCore/JSObject.h>
#include <JavaScriptCore/JSObjectInlines.h>
#include <JavaScriptCore/JSPromise.h>
#include <JavaScriptCore/JSArray.h>
#include <JavaScriptCore/WriteBarrier.h>
namespace Bun {
using namespace JSC;
class JSReadableStream;
class JSReadableStreamDefaultReader final : public JSC::JSDestructibleObject {
public:
using Base = JSC::JSDestructibleObject;
static constexpr bool needsDestruction = true;
static void destroy(JSC::JSCell* cell)
{
static_cast<JSReadableStreamDefaultReader*>(cell)->~JSReadableStreamDefaultReader();
}
~JSReadableStreamDefaultReader()
{
}
static JSReadableStreamDefaultReader* create(JSC::VM& vm, JSGlobalObject* globalObject, JSC::Structure* structure, JSReadableStream* stream);
static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
{
return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info());
}
static JSObject* prototype(JSC::VM& vm, JSGlobalObject* globalObject);
static JSObject* constructor(JSC::VM& vm, JSGlobalObject* globalObject, JSValue prototype);
DECLARE_INFO;
DECLARE_VISIT_CHILDREN;
DECLARE_VISIT_OUTPUT_CONSTRAINTS;
template<typename Visitor>
void visitAdditionalChildren(Visitor& visitor);
template<typename, JSC::SubspaceAccess mode>
static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm)
{
if constexpr (mode == JSC::SubspaceAccess::Concurrently)
return nullptr;
return subspaceForImpl(vm);
}
static JSC::GCClient::IsoSubspace* subspaceForImpl(JSC::VM& vm);
// Public API for C++ usage
JSC::JSPromise* readyPromise() { return m_readyPromise.get(this); }
JSC::JSPromise* closedPromise() { return m_closedPromise.get(this); }
JSReadableStream* stream() const;
JSC::JSPromise* read(JSC::VM&, JSGlobalObject*);
JSC::JSPromise* cancel(JSC::VM&, JSGlobalObject*, JSValue reason);
bool isActive() const { return !!m_stream; }
void detach();
bool isEmpty()
{
return m_readRequests.isEmpty();
}
// Implements ReadableStreamDefaultReader
void releaseLock();
JSC::JSPromise* takeFirst(JSC::VM&, JSC::JSGlobalObject*);
void addReadRequest(JSC::VM&, JSC::JSGlobalObject* globalObject, JSC::JSValue promise);
private:
JSReadableStreamDefaultReader(JSC::VM& vm, JSC::Structure* structure)
: Base(vm, structure)
{
}
void finishCreation(JSC::VM&, JSReadableStream* stream);
WTF::Deque<JSC::JSValue> m_readRequests;
// Internal slots defined by the spec
mutable JSC::WriteBarrier<JSObject> m_stream;
JSC::LazyProperty<JSObject, JSC::JSPromise> m_readyPromise;
JSC::LazyProperty<JSObject, JSC::JSPromise> m_closedPromise;
};
} // namespace Bun

View File

@@ -0,0 +1,100 @@
#include "root.h"
#include "BunReadableStreamDefaultController.h"
#include "BunReadableStream.h"
#include "BunReadableStreamDefaultReader.h"
#include "ErrorCode.h"
#include <JavaScriptCore/JSObjectInlines.h>
#include "BunReadableStreamDefaultReaderPrototype.h"
#include "BunReadableStreamDefaultReaderConstructor.h"
namespace Bun {
using namespace JSC;
const ClassInfo JSReadableStreamDefaultReaderConstructor::s_info = { "ReadableStreamDefaultReader"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSReadableStreamDefaultReaderConstructor) };
JSReadableStreamDefaultReaderConstructor* JSReadableStreamDefaultReaderConstructor::create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSReadableStreamDefaultReaderPrototype* prototype)
{
auto* structure = createStructure(vm, globalObject, prototype);
JSReadableStreamDefaultReaderConstructor* constructor = new (NotNull, JSC::allocateCell<JSReadableStreamDefaultReaderConstructor>(vm)) JSReadableStreamDefaultReaderConstructor(vm, structure);
constructor->finishCreation(vm, globalObject, prototype);
return constructor;
}
void JSReadableStreamDefaultReaderConstructor::finishCreation(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSReadableStreamDefaultReaderPrototype* prototype)
{
Base::finishCreation(vm, 1, "ReadableStreamDefaultReader"_s, PropertyAdditionMode::WithStructureTransition);
ASSERT(inherits(info()));
putDirect(vm, vm.propertyNames->prototype, prototype, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly);
}
JSC::EncodedJSValue JSC_HOST_CALL_ATTRIBUTES JSReadableStreamDefaultReaderConstructor::call(JSC::JSGlobalObject* globalObject, JSC::CallFrame*)
{
VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
Bun::throwError(globalObject, scope, Bun::ErrorCode::ERR_ILLEGAL_CONSTRUCTOR, "ReadableStreamDefaultReader constructor cannot be called as a function"_s);
return {};
}
JSC::EncodedJSValue JSC_HOST_CALL_ATTRIBUTES JSReadableStreamDefaultReaderConstructor::construct(JSC::JSGlobalObject* globalObject, JSC::CallFrame* callFrame)
{
VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
if (callFrame->argumentCount() < 1) {
return throwVMTypeError(globalObject, scope, "ReadableStreamDefaultReader constructor requires a ReadableStream argument"_s);
}
JSValue streamValue = callFrame->uncheckedArgument(0);
JSReadableStream* stream = jsDynamicCast<JSReadableStream*>(streamValue);
if (!stream) {
return throwVMTypeError(globalObject, scope, "ReadableStreamDefaultReader constructor argument must be a ReadableStream"_s);
}
// Check if stream is already locked
if (stream->isLocked()) {
return throwVMTypeError(globalObject, scope, "Cannot construct a ReadableStreamDefaultReader for a locked ReadableStream"_s);
}
JSC::JSObject* newTarget = callFrame->newTarget().getObject();
JSC::JSObject* constructor = callFrame->jsCallee();
auto* domGlobalObject = defaultGlobalObject(globalObject);
auto& streams = domGlobalObject->streams();
auto* structure = streams.structure<JSReadableStreamDefaultReader>(domGlobalObject);
// TODO: double-check this.
if (!(!newTarget || newTarget == constructor)) {
if (newTarget) {
structure = JSC::InternalFunction::createSubclassStructure(getFunctionRealm(globalObject, newTarget), newTarget, structure);
} else {
structure = JSC::InternalFunction::createSubclassStructure(globalObject, constructor, structure);
}
}
RETURN_IF_EXCEPTION(scope, {});
JSReadableStreamDefaultReader* reader = JSReadableStreamDefaultReader::create(vm, globalObject, structure, stream);
RETURN_IF_EXCEPTION(scope, {});
// Lock the stream to this reader
stream->setReader(vm, reader);
// Set up initial ready state
if (stream->isDisturbed() || stream->state() == JSReadableStream::State::Errored) {
JSValue error = stream->storedError();
if (!error)
error = jsUndefined();
reader->readyPromise()->reject(globalObject, error);
} else {
reader->readyPromise()->fulfillWithNonPromise(globalObject, jsUndefined());
}
RELEASE_AND_RETURN(scope, JSValue::encode(reader));
}
} // namespace Bun

View File

@@ -0,0 +1,48 @@
#pragma once
#include "root.h"
#include <JavaScriptCore/InternalFunction.h>
namespace Bun {
using namespace JSC;
class JSReadableStreamDefaultReaderPrototype;
class JSReadableStreamDefaultReaderConstructor final : public JSC::InternalFunction {
public:
using Base = JSC::InternalFunction;
static JSReadableStreamDefaultReaderConstructor* create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSReadableStreamDefaultReaderPrototype* prototype);
DECLARE_INFO;
template<typename, JSC::SubspaceAccess mode>
static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm)
{
if constexpr (mode == JSC::SubspaceAccess::Concurrently)
return nullptr;
return &vm.plainObjectSpace();
}
static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
{
return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::InternalFunctionType, StructureFlags), info());
}
static constexpr unsigned StructureFlags = Base::StructureFlags;
static constexpr bool needsDestruction = false;
private:
JSReadableStreamDefaultReaderConstructor(JSC::VM& vm, JSC::Structure* structure)
: Base(vm, structure, call, construct)
{
}
void finishCreation(JSC::VM&, JSC::JSGlobalObject*, JSReadableStreamDefaultReaderPrototype*);
static JSC::EncodedJSValue JSC_HOST_CALL_ATTRIBUTES call(JSC::JSGlobalObject*, JSC::CallFrame*);
static JSC::EncodedJSValue JSC_HOST_CALL_ATTRIBUTES construct(JSC::JSGlobalObject*, JSC::CallFrame*);
};
} // namespace Bun

View File

@@ -0,0 +1,136 @@
#include "BunReadableStreamDefaultReaderPrototype.h"
#include "BunReadableStreamDefaultReader.h"
#include "BunReadableStream.h"
#include <JavaScriptCore/JSPromise.h>
#include <JavaScriptCore/JSObjectInlines.h>
namespace Bun {
using namespace JSC;
static JSC_DECLARE_CUSTOM_GETTER(readableStreamDefaultReaderClosedGetter);
static JSC_DECLARE_CUSTOM_GETTER(readableStreamDefaultReaderReadyGetter);
static JSC_DECLARE_HOST_FUNCTION(readableStreamDefaultReaderRead);
static JSC_DECLARE_HOST_FUNCTION(readableStreamDefaultReaderReleaseLock);
static JSC_DECLARE_HOST_FUNCTION(readableStreamDefaultReaderCancel);
const ClassInfo JSReadableStreamDefaultReaderPrototype::s_info = { "ReadableStreamDefaultReader"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSReadableStreamDefaultReaderPrototype) };
static const HashTableValue JSReadableStreamDefaultReaderPrototypeTableValues[] = {
{ "closed"_s,
static_cast<unsigned>(JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor),
NoIntrinsic,
{ HashTableValue::GetterSetterType, readableStreamDefaultReaderClosedGetter, nullptr } },
{ "ready"_s,
static_cast<unsigned>(JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor),
NoIntrinsic,
{ HashTableValue::GetterSetterType, readableStreamDefaultReaderReadyGetter, nullptr } },
{ "read"_s,
static_cast<unsigned>(JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::Function),
NoIntrinsic,
{ HashTableValue::NativeFunctionType, readableStreamDefaultReaderRead, 0 } },
{ "releaseLock"_s,
static_cast<unsigned>(JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::Function),
NoIntrinsic,
{ HashTableValue::NativeFunctionType, readableStreamDefaultReaderReleaseLock, 0 } },
{ "cancel"_s,
static_cast<unsigned>(JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::Function),
NoIntrinsic,
{ HashTableValue::NativeFunctionType, readableStreamDefaultReaderCancel, 1 } },
};
JSReadableStreamDefaultReaderPrototype* JSReadableStreamDefaultReaderPrototype::create(JSC::VM& vm, JSGlobalObject* globalObject, JSC::Structure* structure)
{
JSReadableStreamDefaultReaderPrototype* ptr = new (NotNull, JSC::allocateCell<JSReadableStreamDefaultReaderPrototype>(vm)) JSReadableStreamDefaultReaderPrototype(vm, globalObject, structure);
ptr->finishCreation(vm);
return ptr;
}
void JSReadableStreamDefaultReaderPrototype::finishCreation(JSC::VM& vm)
{
Base::finishCreation(vm);
reifyStaticProperties(vm, JSReadableStreamDefaultReader::info(), JSReadableStreamDefaultReaderPrototypeTableValues, *this);
JSC_TO_STRING_TAG_WITHOUT_TRANSITION();
}
// JS Bindings Implementation
JSC_DEFINE_HOST_FUNCTION(readableStreamDefaultReaderRead, (JSGlobalObject * globalObject, CallFrame* callFrame))
{
VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
JSReadableStreamDefaultReader* reader = jsDynamicCast<JSReadableStreamDefaultReader*>(callFrame->thisValue());
if (!reader) {
scope.throwException(globalObject, createTypeError(globalObject, "ReadableStreamDefaultReader.prototype.read called on incompatible object"_s));
return {};
}
JSC::JSPromise* promise = reader->read(vm, globalObject);
RETURN_IF_EXCEPTION(scope, {});
return JSC::JSValue::encode(promise);
}
JSC_DEFINE_HOST_FUNCTION(readableStreamDefaultReaderReleaseLock, (JSGlobalObject * globalObject, CallFrame* callFrame))
{
VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
JSReadableStreamDefaultReader* reader = jsDynamicCast<JSReadableStreamDefaultReader*>(callFrame->thisValue());
if (!reader) {
scope.throwException(globalObject, createTypeError(globalObject, "ReadableStreamDefaultReader.prototype.releaseLock called on incompatible object"_s));
return {};
}
reader->releaseLock();
return JSValue::encode(jsUndefined());
}
JSC_DEFINE_CUSTOM_GETTER(readableStreamDefaultReaderClosedGetter, (JSGlobalObject * globalObject, EncodedJSValue thisValue, PropertyName))
{
VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
JSReadableStreamDefaultReader* reader = jsDynamicCast<JSReadableStreamDefaultReader*>(JSValue::decode(thisValue));
if (!reader) {
scope.throwException(globalObject, createTypeError(globalObject, "ReadableStreamDefaultReader.prototype.closed called on incompatible object"_s));
return {};
}
return JSValue::encode(reader->closedPromise());
}
JSC_DEFINE_CUSTOM_GETTER(readableStreamDefaultReaderReadyGetter, (JSGlobalObject * globalObject, EncodedJSValue thisValue, PropertyName))
{
VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
JSReadableStreamDefaultReader* reader = jsDynamicCast<JSReadableStreamDefaultReader*>(JSValue::decode(thisValue));
if (!reader) {
scope.throwException(globalObject, createTypeError(globalObject, "ReadableStreamDefaultReader.prototype.ready called on incompatible object"_s));
return {};
}
return JSValue::encode(reader->readyPromise());
}
JSC_DEFINE_HOST_FUNCTION(readableStreamDefaultReaderCancel, (JSGlobalObject * globalObject, CallFrame* callFrame))
{
VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
JSReadableStreamDefaultReader* reader = jsDynamicCast<JSReadableStreamDefaultReader*>(callFrame->thisValue());
if (!reader) {
scope.throwException(globalObject, createTypeError(globalObject, "ReadableStreamDefaultReader.prototype.cancel called on incompatible object"_s));
return {};
}
JSValue reason = callFrame->argument(0);
if (!reader->isActive()) {
scope.throwException(globalObject, createTypeError(globalObject, "ReadableStreamDefaultReader.prototype.cancel called on released reader"_s));
return {};
}
return JSValue::encode(reader->stream()->cancel(vm, globalObject, reason));
}
} // namespace Bun

View File

@@ -0,0 +1,40 @@
#pragma once
#include "root.h"
#include <JavaScriptCore/JSObject.h>
#include <JavaScriptCore/JSObjectInlines.h>
namespace Bun {
using namespace JSC;
class JSReadableStreamDefaultReaderPrototype final : public JSC::JSNonFinalObject {
public:
using Base = JSC::JSNonFinalObject;
static JSReadableStreamDefaultReaderPrototype* create(JSC::VM& vm, JSGlobalObject* globalObject, JSC::Structure* structure);
DECLARE_INFO;
template<typename CellType, JSC::SubspaceAccess>
static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm)
{
STATIC_ASSERT_ISO_SUBSPACE_SHARABLE(JSReadableStreamDefaultReaderPrototype, Base);
return &vm.plainObjectSpace();
}
static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
{
return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info());
}
private:
JSReadableStreamDefaultReaderPrototype(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure)
: Base(vm, structure)
{
}
void finishCreation(JSC::VM&);
};
} // namespace Bun

View File

@@ -0,0 +1,56 @@
#pragma once
#include "root.h"
#include "JavaScriptCore/InternalFieldTuple.h"
namespace Bun {
class JSReadableStreamDefaultReader;
class JSWritableStreamDefaultWriter;
// class PipeToOperation : public JSC::JSInternalFieldObjectImpl<7> {
// public:
// static constexpr unsigned numberOfInternalFields = 7;
// using Base = JSC::JSInternalFieldObjectImpl<numberOfInternalFields>;
// static PipeToOperation* create(JSC::VM& vm, JSC::JSGlobalObject* globalObject,
// JSC::JSObject* reader, JSC::JSObject* writer,
// bool preventClose, bool preventAbort, bool preventCancel, JSC::JSObject* signal, JSC::JSPromise* promise)
// {
// PipeToOperation* operation = new (NotNull, JSC::allocateCell<PipeToOperation>(vm)) PipeToOperation(vm, globalObject);
// operation->finishCreation(vm, reader, writer, preventClose, preventAbort, preventCancel, signal, promise);
// return operation;
// }
// void perform(JSC::VM& vm, JSC::JSGlobalObject* globalObject) {}
// bool preventClose { false };
// bool preventAbort { false };
// bool preventCancel { false };
// mutable JSC::WriteBarrier<JSC::JSObject> reader;
// mutable JSC::WriteBarrier<JSC::JSObject> writer;
// mutable JSC::WriteBarrier<JSC::JSObject> signal;
// mutable JSC::WriteBarrier<JSC::JSPromise> promise;
// private:
// PipeToOperation(JSC::VM& vm, JSC::JSGlobalObject* globalObject)
// : Base(vm, globalObject)
// {
// }
// void finishCreation(JSC::VM& vm, JSC::JSObject* reader, JSC::JSObject* writer,
// bool preventClose, bool preventAbort, bool preventCancel, JSC::JSObject* signal, JSC::JSPromise* promise)
// {
// Base::finishCreation(vm);
// internalField(0).set(vm, this, reader);
// internalField(1).set(vm, this, writer);
// internalField(2).set(vm, this, JSC::jsBoolean(preventClose));
// internalField(3).set(vm, this, JSC::jsBoolean(preventAbort));
// internalField(4).set(vm, this, JSC::jsBoolean(preventCancel));
// internalField(5).set(vm, this, signal ? signal : JSC::jsUndefined());
// internalField(6).set(vm, this, promise);
// }
// };
}

View File

@@ -0,0 +1,171 @@
#include "BunReadableStreamPrototype.h"
#include "BunReadableStream.h"
#include <JavaScriptCore/JSObjectInlines.h>
#include <JavaScriptCore/JSCInlines.h>
#include <JavaScriptCore/JSPromise.h>
#include <JavaScriptCore/JSArray.h>
namespace Bun {
using namespace JSC;
static JSC_DECLARE_CUSTOM_GETTER(jsReadableStreamGetLocked);
static JSC_DECLARE_HOST_FUNCTION(jsReadableStreamGetReader);
static JSC_DECLARE_HOST_FUNCTION(jsReadableStreamCancel);
static JSC_DECLARE_HOST_FUNCTION(jsReadableStreamPipeTo);
static JSC_DECLARE_HOST_FUNCTION(jsReadableStreamPipeThrough);
static JSC_DECLARE_HOST_FUNCTION(jsReadableStreamTee);
static const HashTableValue JSReadableStreamPrototypeTableValues[] = {
{ "locked"_s,
static_cast<unsigned>(PropertyAttribute::ReadOnly | PropertyAttribute::CustomAccessor),
NoIntrinsic,
{ HashTableValue::GetterSetterType, jsReadableStreamGetLocked, nullptr } },
{ "getReader"_s,
static_cast<unsigned>(PropertyAttribute::Function),
NoIntrinsic,
{ HashTableValue::NativeFunctionType, jsReadableStreamGetReader, 1 } },
{ "cancel"_s,
static_cast<unsigned>(PropertyAttribute::Function),
NoIntrinsic,
{ HashTableValue::NativeFunctionType, jsReadableStreamCancel, 1 } },
{ "pipeTo"_s,
static_cast<unsigned>(PropertyAttribute::Function),
NoIntrinsic,
{ HashTableValue::NativeFunctionType, jsReadableStreamPipeTo, 2 } },
{ "pipeThrough"_s,
static_cast<unsigned>(PropertyAttribute::Function),
NoIntrinsic,
{ HashTableValue::NativeFunctionType, jsReadableStreamPipeThrough, 2 } },
{ "tee"_s,
static_cast<unsigned>(PropertyAttribute::Function),
NoIntrinsic,
{ HashTableValue::NativeFunctionType, jsReadableStreamTee, 0 } }
};
const ClassInfo JSReadableStreamPrototype::s_info = { "ReadableStream"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSReadableStreamPrototype) };
JSReadableStreamPrototype* JSReadableStreamPrototype::create(VM& vm, JSGlobalObject* globalObject, Structure* structure)
{
auto* thisObject = new (NotNull, allocateCell<JSReadableStreamPrototype>(vm)) JSReadableStreamPrototype(vm, structure);
thisObject->finishCreation(vm, globalObject);
return thisObject;
}
Structure* JSReadableStreamPrototype::createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
{
auto* structure = Base::createStructure(vm, globalObject, prototype);
structure->setMayBePrototype(true);
return structure;
}
template<typename CellType, SubspaceAccess>
JSC::GCClient::IsoSubspace* JSReadableStreamPrototype::subspaceFor(VM& vm)
{
STATIC_ASSERT_ISO_SUBSPACE_SHARABLE(JSReadableStreamPrototype, Base);
return &vm.plainObjectSpace();
}
JSReadableStreamPrototype::JSReadableStreamPrototype(VM& vm, Structure* structure)
: Base(vm, structure)
{
}
void JSReadableStreamPrototype::finishCreation(VM& vm, JSGlobalObject* globalObject)
{
Base::finishCreation(vm);
reifyStaticProperties(vm, info(), JSReadableStreamPrototypeTableValues, *this);
JSC_TO_STRING_TAG_WITHOUT_TRANSITION();
}
// JavaScript bindings
// JavaScript bindings
JSC_DEFINE_CUSTOM_GETTER(jsReadableStreamGetLocked, (JSGlobalObject * globalObject, EncodedJSValue thisValue, PropertyName))
{
VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
JSReadableStream* stream = jsDynamicCast<JSReadableStream*>(JSValue::decode(thisValue));
if (!stream)
return throwVMTypeError(globalObject, scope, "Not a ReadableStream"_s);
return JSValue::encode(jsBoolean(stream->locked()));
}
JSC_DEFINE_HOST_FUNCTION(jsReadableStreamGetReader, (JSGlobalObject * globalObject, CallFrame* callFrame))
{
VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
JSReadableStream* stream = jsDynamicCast<JSReadableStream*>(callFrame->thisValue());
if (!stream)
return throwVMTypeError(globalObject, scope, "Not a ReadableStream"_s);
JSValue options = callFrame->argument(0);
return JSValue::encode(stream->getReader(vm, globalObject, options));
}
JSC_DEFINE_HOST_FUNCTION(jsReadableStreamCancel, (JSGlobalObject * globalObject, CallFrame* callFrame))
{
VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
JSReadableStream* stream = jsDynamicCast<JSReadableStream*>(callFrame->thisValue());
if (!stream)
return throwVMTypeError(globalObject, scope, "Not a ReadableStream"_s);
JSValue reason = callFrame->argument(0);
return JSValue::encode(stream->cancel(vm, globalObject, reason));
}
JSC_DEFINE_HOST_FUNCTION(jsReadableStreamPipeTo, (JSGlobalObject * globalObject, CallFrame* callFrame))
{
VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
JSReadableStream* stream = jsDynamicCast<JSReadableStream*>(callFrame->thisValue());
if (!stream)
return throwVMTypeError(globalObject, scope, "Not a ReadableStream"_s);
JSValue destination = callFrame->argument(0);
JSValue options = callFrame->argument(1);
return JSValue::encode(stream->pipeTo(vm, globalObject, destination.toObject(globalObject), options));
}
JSC_DEFINE_HOST_FUNCTION(jsReadableStreamPipeThrough, (JSGlobalObject * globalObject, CallFrame* callFrame))
{
VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
JSReadableStream* stream = jsDynamicCast<JSReadableStream*>(callFrame->thisValue());
if (!stream)
return throwVMTypeError(globalObject, scope, "Not a ReadableStream"_s);
JSValue transform = callFrame->argument(0);
JSValue options = callFrame->argument(1);
return JSValue::encode(stream->pipeThrough(vm, globalObject, transform.toObject(globalObject), options));
}
JSC_DEFINE_HOST_FUNCTION(jsReadableStreamTee, (JSGlobalObject * globalObject, CallFrame* callFrame))
{
VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
JSReadableStream* stream = jsDynamicCast<JSReadableStream*>(callFrame->thisValue());
if (!stream)
return throwVMTypeError(globalObject, scope, "Not a ReadableStream"_s);
JSC::JSValue firstStream;
JSC::JSValue secondStream;
stream->tee(vm, globalObject, firstStream, secondStream);
RETURN_IF_EXCEPTION(scope, {});
JSArray* array = constructEmptyArray(globalObject, static_cast<ArrayAllocationProfile*>(nullptr), 2);
array->putDirectIndex(globalObject, 0, firstStream);
array->putDirectIndex(globalObject, 1, secondStream);
return JSValue::encode(array);
}
} // namespace Bun

View File

@@ -0,0 +1,29 @@
#pragma once
#include "root.h"
#include <JavaScriptCore/JSGlobalObject.h>
#include <JavaScriptCore/JSObject.h>
#include <JavaScriptCore/JSValue.h>
#include <JavaScriptCore/JSCell.h>
namespace Bun {
using namespace JSC;
class JSReadableStreamPrototype final : public JSC::JSNonFinalObject {
public:
using Base = JSC::JSNonFinalObject;
static JSReadableStreamPrototype* create(VM& vm, JSGlobalObject* globalObject, Structure* structure);
static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype);
DECLARE_INFO;
template<typename CellType, SubspaceAccess>
static JSC::GCClient::IsoSubspace* subspaceFor(VM& vm);
private:
JSReadableStreamPrototype(VM& vm, Structure* structure);
void finishCreation(VM& vm, JSGlobalObject* globalObject);
};
} // namespace Bun

View File

@@ -0,0 +1,45 @@
#include "root.h"
#include <JavaScriptCore/JSPromise.h>
#include "ZigGlobalObject.h"
namespace Bun {
using namespace JSC;
static inline JSValue then(JSGlobalObject* globalObject, JSPromise* promise, Zig::GlobalObject::PromiseHandler resolverFunction, Zig::GlobalObject::PromiseHandler rejecterFunction, JSValue ctx = jsUndefined())
{
JSFunction* performPromiseThenFunction = globalObject->performPromiseThenFunction();
auto callData = JSC::getCallData(performPromiseThenFunction);
ASSERT(callData.type != CallData::Type::None);
MarkedArgumentBuffer arguments;
arguments.append(promise);
auto* bunGlobalObject = jsDynamicCast<Zig::GlobalObject*>(globalObject);
arguments.append(bunGlobalObject->thenable(resolverFunction));
arguments.append(bunGlobalObject->thenable(rejecterFunction));
arguments.append(jsUndefined());
arguments.append(ctx);
ASSERT(!arguments.hasOverflowed());
// async context tracking is handled by performPromiseThenFunction internally.
return JSC::profiledCall(globalObject, JSC::ProfilingReason::Microtask, performPromiseThenFunction, callData, jsUndefined(), arguments);
}
static inline JSValue then(JSGlobalObject* globalObject, JSPromise* promise, JSValue resolverFunction, JSValue rejecterFunction, JSValue ctx = jsUndefined())
{
JSFunction* performPromiseThenFunction = globalObject->performPromiseThenFunction();
auto callData = JSC::getCallData(performPromiseThenFunction);
ASSERT(callData.type != CallData::Type::None);
MarkedArgumentBuffer arguments;
arguments.append(promise);
arguments.append(resolverFunction);
arguments.append(rejecterFunction);
arguments.append(jsUndefined());
arguments.append(ctx);
ASSERT(!arguments.hasOverflowed());
// async context tracking is handled by performPromiseThenFunction internally.
return JSC::profiledCall(globalObject, JSC::ProfilingReason::Microtask, performPromiseThenFunction, callData, jsUndefined(), arguments);
}
}

View File

@@ -0,0 +1,176 @@
#include "root.h"
#include "BunStreamQueue.h"
#include <JavaScriptCore/JSArray.h>
#include "JSByteLengthQueuingStrategy.h"
#include "JSCountQueuingStrategy.h"
#include "ErrorCode.h"
namespace Bun {
using namespace JSC;
static int64_t byteLength(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSValue value)
{
if (auto* arrayBufferView = jsDynamicCast<JSArrayBufferView*>(value)) {
return arrayBufferView->byteLength();
}
if (auto* arrayBuffer = jsDynamicCast<JSArrayBuffer*>(value)) {
if (auto* impl = arrayBuffer->impl()) {
return impl->byteLength();
} else {
return 0;
}
}
if (auto* object = value.getObject()) {
JSValue byteLengthProperty = object->getIfPropertyExists(globalObject, vm.propertyNames->byteLength);
if (byteLengthProperty) {
return byteLengthProperty.toLength(globalObject);
}
}
return 0;
}
void StreamQueue::initialize(JSC::VM& vm, JSC::JSGlobalObject* globalObject, double highWaterMark, JSObject* owner, JSObject* sizeAlgorithm)
{
auto scope = DECLARE_THROW_SCOPE(vm);
this->highWaterMark = highWaterMark;
this->queueTotalSize = 0;
if (sizeAlgorithm) {
if (auto* byteLengthStrategy = jsDynamicCast<JSByteLengthQueuingStrategy*>(sizeAlgorithm)) {
this->type = StreamQueueType::ByteLengthQueuingStrategy;
m_userDefinedStrategy.clear();
} else if (auto* countStrategy = jsDynamicCast<JSCountQueuingStrategy*>(sizeAlgorithm)) {
this->type = StreamQueueType::CountQueuingStrategy;
m_userDefinedStrategy.clear();
} else if (auto sizeFunction = sizeAlgorithm->getIfPropertyExists(globalObject, vm.propertyNames->size)) {
if (!sizeFunction.isUndefinedOrNull()) {
if (!sizeFunction.isCallable()) {
Bun::throwError(globalObject, scope, Bun::ErrorCode::ERR_INVALID_ARG_TYPE, "Expected 'size' to be a function"_s);
return;
}
m_userDefinedStrategy.set(vm, owner, sizeFunction.getObject());
this->type = StreamQueueType::UserDefined;
}
}
}
}
void StreamQueue::resetQueue(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSObject* owner)
{
{
WTF::Locker lock(owner->cellLock());
m_queue.clear();
}
this->queueTotalSize = 0;
m_userDefinedQueueSizes.clear();
}
void StreamQueue::clearAlgorithms()
{
m_userDefinedStrategy.clear();
}
void StreamQueue::enqueueValueWithSize(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSObject* owner, JSValue value, double size)
{
{
WTF::Locker lock(owner->cellLock());
m_queue.append(value);
}
this->queueTotalSize += size;
if (type == StreamQueueType::UserDefined) {
m_userDefinedQueueSizes.append(size);
}
}
JSValue StreamQueue::peekQueueValue(JSC::VM& vm, JSC::JSGlobalObject* globalObject)
{
if (m_queue.isEmpty()) {
return {};
}
return m_queue.first();
}
void StreamQueue::enqueueValueAndGetSize(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSObject* owner, JSC::JSValue value)
{
auto scope = DECLARE_THROW_SCOPE(vm);
double size;
switch (type) {
case StreamQueueType::UserDefined: {
auto* userDefinedStrategy = m_userDefinedStrategy.get();
JSC::CallData callData = JSC::getCallData(userDefinedStrategy);
ASSERT_WITH_MESSAGE(callData.type != JSC::CallData::Type::None, "User defined strategy is not callable");
MarkedArgumentBuffer args;
args.append(value);
JSValue result = JSC::call(globalObject, userDefinedStrategy, callData, jsUndefined(), args);
RETURN_IF_EXCEPTION(scope, void());
size = result.toNumber(globalObject);
RETURN_IF_EXCEPTION(scope, void());
if (size < 0) {
Bun::throwError(globalObject, scope, Bun::ErrorCode::ERR_INVALID_ARG_TYPE, "Expected 'size' to be a non-negative number"_s);
return;
} else if (size == PNaN) {
size = 0;
} else if (size == std::numeric_limits<double>::infinity()) {
Bun::throwError(globalObject, scope, Bun::ErrorCode::ERR_INVALID_ARG_TYPE, "Expected 'size' to be a finite number"_s);
return;
}
break;
}
case StreamQueueType::CountQueuingStrategy:
size = 1;
break;
case StreamQueueType::ByteLengthQueuingStrategy:
size = byteLength(vm, globalObject, value);
RETURN_IF_EXCEPTION(scope, void());
break;
}
this->enqueueValueWithSize(vm, globalObject, owner, value, size);
}
JSValue StreamQueue::dequeueValue(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSObject* owner)
{
JSValue result;
{
WTF::Locker lock(owner->cellLock());
result = m_queue.takeFirst();
}
auto scope = DECLARE_THROW_SCOPE(vm);
RETURN_IF_EXCEPTION(scope, {});
if (!result) {
return {};
}
if (type == StreamQueueType::UserDefined) {
auto size = m_userDefinedQueueSizes.takeFirst();
this->queueTotalSize -= size;
} else if (type == StreamQueueType::CountQueuingStrategy) {
this->queueTotalSize -= 1;
} else if (type == StreamQueueType::ByteLengthQueuingStrategy) {
// This can technically throw because we call .byteLength on the value
// and that value could be a JSObject with a getter for "byteLength"
// that throws.
this->queueTotalSize -= byteLength(vm, globalObject, result);
RETURN_IF_EXCEPTION(scope, {});
}
if (UNLIKELY(this->queueTotalSize < 0)) {
this->queueTotalSize = 0;
}
return result;
}
}

View File

@@ -0,0 +1,79 @@
#pragma once
#include "root.h"
namespace Bun {
enum class StreamQueueType : uint8_t {
CountQueuingStrategy,
ByteLengthQueuingStrategy,
UserDefined,
};
class StreamQueue {
public:
StreamQueueType type { StreamQueueType::CountQueuingStrategy };
double highWaterMark { 0 };
// Due to the limited precision of floating-point arithmetic, the framework
// specified here, of keeping a running total in the [[queueTotalSize]]
// slot, is not equivalent to adding up the size of all chunks in [[queue]].
// (However, this only makes a difference when there is a huge (~10^15)
// variance in size between chunks, or when trillions of chunks are
// enqueued.)
double queueTotalSize { 0 };
template<typename Visitor>
void visit(JSCell* owner, Visitor& visitor)
{
if (m_userDefinedStrategy)
visitor.append(m_userDefinedStrategy);
{
WTF::Locker lock(owner->cellLock());
for (auto value : m_queue) {
if (value.isCell())
visitor.appendUnbarriered(value);
}
}
}
void setUserDefinedStrategy(JSC::JSObject* strategy);
void initialize(JSC::VM& vm, JSC::JSGlobalObject* globalObject, double highWaterMark, JSC::JSObject* owner, JSC::JSObject* sizeAlgorithm);
// 1. Assert: container has [[queue]] and [[queueTotalSize]] internal slots.
// 2. Set container.[[queue]] to a new empty list.
// 3. Set container.[[queueTotalSize]] to 0.
void resetQueue(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSObject* owner);
JSC::JSValue peekQueueValue(JSC::VM& vm, JSC::JSGlobalObject* globalObject);
void enqueueValueWithSize(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSObject* owner, JSC::JSValue value, double size);
JSC::JSValue dequeueValue(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSObject* owner);
void enqueueValueAndGetSize(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSObject* owner, JSC::JSValue value);
void clearAlgorithms();
mutable JSC::WriteBarrier<JSC::JSObject> m_userDefinedStrategy;
WTF::Deque<double, 0> m_userDefinedQueueSizes = {};
bool isEmpty()
{
const bool isEmpty = queueTotalSize == 0;
#if ASSERT_ENABLED
ASSERT(type == StreamQueueType::UserDefined ? m_userDefinedQueueSizes.isEmpty() == isEmpty : true);
#endif
return isEmpty;
}
double desiredSize() const
{
return highWaterMark - queueTotalSize;
}
private:
WTF::Deque<JSC::JSValue, 3>& queue() { return m_queue; }
const WTF::Deque<JSC::JSValue, 3>& queue() const { return m_queue; }
WTF::Deque<JSC::JSValue, 3> m_queue = {};
};
}

View File

@@ -0,0 +1,88 @@
#include "root.h"
#include <JavaScriptCore/LazyClassStructure.h>
#include <JavaScriptCore/LazyClassStructureInlines.h>
#include "ZigGlobalObject.h"
#include "BunStreamStructures.h"
#include "BunReadableStream.h"
#include "BunReadableStreamPrototype.h"
#include "BunReadableStreamConstructor.h"
#include "BunReadableStreamDefaultReader.h"
#include "BunReadableStreamDefaultReaderPrototype.h"
#include "BunReadableStreamDefaultReaderConstructor.h"
#include "BunReadableStreamDefaultController.h"
#include "BunReadableStreamDefaultControllerPrototype.h"
#include "BunReadableStreamDefaultControllerConstructor.h"
#include "BunReadableStreamBYOBReader.h"
#include "BunReadableStreamBYOBReaderPrototype.h"
#include "BunReadableStreamBYOBReaderConstructor.h"
#include "BunWritableStream.h"
#include "BunWritableStreamPrototype.h"
#include "BunWritableStreamConstructor.h"
#include "BunWritableStreamDefaultWriter.h"
#include "BunWritableStreamDefaultWriterPrototype.h"
#include "BunWritableStreamDefaultWriterConstructor.h"
#include "BunWritableStreamDefaultController.h"
#include "BunWritableStreamDefaultControllerPrototype.h"
#include "BunWritableStreamDefaultControllerConstructor.h"
#include "BunTransformStream.h"
#include "BunTransformStreamPrototype.h"
#include "BunTransformStreamConstructor.h"
#include "BunTransformStreamDefaultController.h"
#include "BunTransformStreamDefaultControllerPrototype.h"
#include "BunTransformStreamDefaultControllerConstructor.h"
#include <JavaScriptCore/VMTrapsInlines.h>
namespace Bun {
void StreamStructures::initialize(VM& vm, JSC::JSGlobalObject* _globalObject)
{
#define INIT_WHATWG_STREAM_CONSTRUCTOR(ConstructorName) \
m_##ConstructorName.initLater( \
[](LazyClassStructure::Initializer& init) { \
auto* globalObject = reinterpret_cast<Zig::GlobalObject*>(init.global); \
auto* prototype = ConstructorName##Prototype::create(init.vm, globalObject, ConstructorName##Prototype::createStructure(init.vm, globalObject, globalObject->objectPrototype())); \
auto* structure = ConstructorName::createStructure(init.vm, globalObject, prototype); \
auto* constructor = ConstructorName##Constructor::create(init.vm, globalObject, prototype); \
init.setPrototype(prototype); \
init.setStructure(structure); \
init.setConstructor(constructor); \
});
FOR_EACH_WHATWG_STREAM_CLASS_TYPE(INIT_WHATWG_STREAM_CONSTRUCTOR)
#undef INIT_WHATWG_STREAM_CONSTRUCTOR
}
#define DEFINE_STREAM_MEMBERS(ClassName) \
template<> \
JSObject* StreamStructures::constructor<ClassName>(const JSGlobalObject* globalObject) \
{ \
return m_##ClassName.constructor(globalObject); \
} \
template<> \
Structure* StreamStructures::structure<ClassName>(const JSGlobalObject* globalObject) \
{ \
return m_##ClassName.get(globalObject); \
} \
template<> \
JSObject* StreamStructures::prototype<ClassName>(const JSGlobalObject* globalObject) \
{ \
return m_##ClassName.prototype(globalObject); \
}
FOR_EACH_WHATWG_STREAM_CLASS_TYPE(DEFINE_STREAM_MEMBERS)
#undef DEFINE_STREAM_MEMBERS
}

View File

@@ -0,0 +1,66 @@
#pragma once
#include "root.h"
#include "JavaScriptCore/LazyClassStructure.h"
#include <JavaScriptCore/JSObject.h>
namespace Bun {
using namespace JSC;
// Forward declarations
class JSReadableStream;
class JSReadableStreamDefaultReader;
class JSReadableStreamDefaultController;
class JSReadableStreamByteController;
class JSReadableStreamBYOBReader;
class JSWritableStream;
class JSWritableStreamDefaultWriter;
class JSWritableStreamDefaultController;
class JSTransformStream;
class JSTransformStreamDefaultController;
// clang-format off
#define FOR_EACH_WHATWG_STREAM_CLASS_TYPE(macro) \
macro(JSReadableStream) \
macro(JSReadableStreamDefaultReader) \
macro(JSReadableStreamDefaultController) \
macro(JSReadableStreamBYOBReader) \
macro(JSWritableStream) \
macro(JSWritableStreamDefaultWriter) \
macro(JSWritableStreamDefaultController) \
macro(JSTransformStream) \
macro(JSTransformStreamDefaultController)
// clang-format on
// Stream-related structures for the global object
struct StreamStructures {
public:
#define DECLARE_STREAM_MEMBER(ClassName) LazyClassStructure m_##ClassName;
FOR_EACH_WHATWG_STREAM_CLASS_TYPE(DECLARE_STREAM_MEMBER)
#undef DECLARE_STREAM_MEMBER
template<typename T>
JSObject* constructor(const JSGlobalObject* globalObject);
template<typename T>
Structure* structure(const JSGlobalObject* globalObject);
template<typename T>
JSObject* prototype(const JSGlobalObject* globalObject);
void initialize(VM& vm, JSC::JSGlobalObject* globalObject);
};
#define DECLARE_STREAM_TEMPLATE_METHODS(ClassName) \
template<> \
JSObject* StreamStructures::constructor<ClassName>(const JSGlobalObject* globalObject); \
template<> \
Structure* StreamStructures::structure<ClassName>(const JSGlobalObject* globalObject); \
template<> \
JSObject* StreamStructures::prototype<ClassName>(const JSGlobalObject* globalObject);
FOR_EACH_WHATWG_STREAM_CLASS_TYPE(DECLARE_STREAM_TEMPLATE_METHODS)
}

View File

@@ -0,0 +1,205 @@
#include "root.h"
#include "BunReadableStream.h"
#include "BunWritableStream.h"
#include "BunTransformStream.h"
#include "BunReadableStreamDefaultReader.h"
#include "BunTeeState.h"
#include "JSTextEncoderStream.h"
#include "BunStreamInlines.h"
#include "BunReadableStreamDefaultReader.h"
#include "BunReadableStreamDefaultController.h"
#include "ZigGlobalObject.h"
#include "StructuredClone.h"
#include "JavaScriptCore/IteratorOperations.h"
#include "BunPromiseInlines.h"
namespace Bun {
using namespace JSC;
const ClassInfo TeeState::s_info = { "TeeState"_s, nullptr, nullptr, nullptr, CREATE_METHOD_TABLE(TeeState) };
TeeState::TeeState(VM& vm, Structure* structure)
: Base(vm, structure)
{
}
JSC::GCClient::IsoSubspace* TeeState::subspaceForImpl(JSC::VM& vm)
{
return WebCore::subspaceForImpl<TeeState, WebCore::UseCustomHeapCellType::No>(
vm,
[](auto& spaces) { return spaces.m_clientSubspaceForTeeState.get(); },
[](auto& spaces, auto&& space) { spaces.m_clientSubspaceForTeeState = std::forward<decltype(space)>(space); },
[](auto& spaces) { return spaces.m_subspaceForTeeState.get(); },
[](auto& spaces, auto&& space) { spaces.m_subspaceForTeeState = std::forward<decltype(space)>(space); });
}
void TeeState::finishCreation(VM& vm)
{
Base::finishCreation(vm);
ASSERT(inherits(info()));
}
JSC::JSPromise* TeeState::cancel(VM& vm, JSGlobalObject* globalObject, Bun::JSReadableStream* canceledBranch, JSValue reason)
{
auto scope = DECLARE_THROW_SCOPE(vm);
if (m_closedOrErrored)
return Bun::createFulfilledPromise(globalObject, jsUndefined());
if (canceledBranch == m_branch1.get()) {
m_canceled1 = true;
m_reason1.set(vm, this, reason);
} else {
m_canceled2 = true;
m_reason2.set(vm, this, reason);
}
// Create the cancelPromise if it doesn't exist
if (!m_cancelPromise) {
m_cancelPromise.set(vm, this, JSPromise::create(vm, globalObject->promiseStructure()));
}
if (!m_canceled1 || !m_canceled2)
return m_cancelPromise.get();
// Both branches are now canceled - composite the reasons
auto* reasons = JSC::constructEmptyArray(globalObject, static_cast<ArrayAllocationProfile*>(nullptr), 2);
reasons->putDirectIndex(globalObject, 0, m_reason1.get());
reasons->putDirectIndex(globalObject, 1, m_reason2.get());
JSC::JSPromise* result = this->m_reader->cancel(vm, globalObject, reasons);
RETURN_IF_EXCEPTION(scope, nullptr);
JSValue resolve = m_cancelPromiseResolve.get();
JSValue reject = m_cancelPromiseReject.get();
m_cancelPromiseResolve.clear();
m_cancelPromiseReject.clear();
Bun::then(globalObject, result, resolve, reject);
return m_cancelPromise.get();
}
void TeeState::perform(JSC::VM& vm, JSC::JSGlobalObject* globalObject)
{
// Start pulling from the original stream
pullAlgorithm(vm, globalObject);
}
Structure* TeeState::createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject)
{
return Structure::create(vm, globalObject, jsNull(), TypeInfo(CellType, StructureFlags), info());
}
TeeState* TeeState::create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, Bun::JSReadableStreamDefaultReader* reader, Bun::JSReadableStream* branch1, Bun::JSReadableStream* branch2)
{
auto* structure = defaultGlobalObject(globalObject)->teeStateStructure();
auto* teeState = new (NotNull, allocateCell<TeeState>(vm)) TeeState(vm, structure);
teeState->finishCreation(vm, reader, branch1, branch2);
return teeState;
}
void TeeState::finishCreation(JSC::VM& vm, Bun::JSReadableStreamDefaultReader* reader, Bun::JSReadableStream* branch1, Bun::JSReadableStream* branch2)
{
Base::finishCreation(vm);
m_reader.set(vm, this, reader);
m_branch1.set(vm, this, branch1);
m_branch2.set(vm, this, branch2);
}
void TeeState::pullAlgorithmReject(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue error)
{
m_closedOrErrored = true;
if (!m_canceled1)
m_branch1->controller()->error(vm, globalObject, error);
if (!m_canceled2)
m_branch2->controller()->error(vm, globalObject, error);
}
void TeeState::pullAlgorithmFulfill(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue result)
{
auto scope = DECLARE_THROW_SCOPE(vm);
JSObject* resultObj = result.toObject(globalObject);
RETURN_IF_EXCEPTION(scope, void());
bool done = resultObj->get(globalObject, vm.propertyNames->done).toBoolean(globalObject);
JSValue value = resultObj->get(globalObject, vm.propertyNames->value);
if (done) {
if (!m_canceled1)
m_branch1->controller()->close(vm, globalObject);
if (!m_canceled2)
m_branch2->controller()->close(vm, globalObject);
m_closedOrErrored = true;
} else {
// Enqueue the chunk to both branches
JSValue chunk1 = value;
JSValue chunk2 = value;
if (!m_canceled1)
m_branch1->controller()->enqueue(vm, globalObject, chunk1);
if (!m_canceled2)
m_branch2->controller()->enqueue(vm, globalObject, chunk2);
m_pullInProgress = false;
pullAlgorithm(vm, globalObject);
}
}
JSC_DEFINE_HOST_FUNCTION(jsTeeStatePullAlgorithmFulfill, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame))
{
TeeState* teeState = jsDynamicCast<TeeState*>(callFrame->argument(1));
auto scope = DECLARE_THROW_SCOPE(globalObject->vm());
if (UNLIKELY(!teeState))
return throwVMTypeError(globalObject, scope, "TeeState.pullAlgorithmFulfill called on incompatible object"_s);
teeState->pullAlgorithmFulfill(globalObject->vm(), globalObject, callFrame->argument(0));
return JSValue::encode(jsUndefined());
}
JSC_DEFINE_HOST_FUNCTION(jsTeeStatePullAlgorithmReject, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame))
{
TeeState* teeState = jsDynamicCast<TeeState*>(callFrame->argument(1));
auto scope = DECLARE_THROW_SCOPE(globalObject->vm());
if (UNLIKELY(!teeState))
return throwVMTypeError(globalObject, scope, "TeeState.pullAlgorithmReject called on incompatible object"_s);
teeState->pullAlgorithmReject(globalObject->vm(), globalObject, callFrame->argument(0));
return JSValue::encode(jsUndefined());
}
void TeeState::pullAlgorithm(VM& vm, JSGlobalObject* globalObject)
{
auto scope = DECLARE_THROW_SCOPE(vm);
if (m_pullInProgress || m_closedOrErrored)
return;
m_pullInProgress = true;
JSValue readResult = m_reader->read(vm, globalObject);
RETURN_IF_EXCEPTION(scope, void());
if (JSPromise* promise = jsDynamicCast<JSPromise*>(readResult)) {
Bun::then(globalObject, promise, jsTeeStatePullAlgorithmFulfill, jsTeeStatePullAlgorithmReject, this);
}
}
template<typename Visitor>
void TeeState::visitChildrenImpl(JSC::JSCell* cell, Visitor& visitor)
{
auto* thisObject = jsCast<TeeState*>(cell);
Base::visitChildren(thisObject, visitor);
visitor.append(thisObject->m_reader);
visitor.append(thisObject->m_branch1);
visitor.append(thisObject->m_branch2);
}
DEFINE_VISIT_CHILDREN(TeeState);
} // namespace Bun

View File

@@ -0,0 +1,64 @@
#include "root.h"
#include <JavaScriptCore/JSObject.h>
#include <JavaScriptCore/JSObjectInlines.h>
#include <JavaScriptCore/JSPromise.h>
#include <JavaScriptCore/JSFunction.h>
namespace Bun {
// Prefer forward declarations over including headers, to save compile time
class JSReadableStream;
class JSReadableStreamDefaultReader;
using namespace JSC;
class TeeState final : public JSC::JSCell {
public:
using Base = JSC::JSCell;
static TeeState* create(VM&, JSGlobalObject*, JSReadableStreamDefaultReader*, JSReadableStream* branch1, JSReadableStream* branch2);
static Structure* createStructure(VM&, JSGlobalObject*);
template<typename, JSC::SubspaceAccess mode>
static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm)
{
if constexpr (mode == JSC::SubspaceAccess::Concurrently)
return nullptr;
return subspaceForImpl(vm);
}
static JSC::GCClient::IsoSubspace* subspaceForImpl(JSC::VM& vm);
DECLARE_INFO;
DECLARE_VISIT_CHILDREN;
void perform(VM&, JSGlobalObject*); // Start the tee operation
void pullAlgorithmFulfill(VM&, JSGlobalObject*, JSValue result);
void pullAlgorithmReject(VM&, JSGlobalObject*, JSValue error);
void finishCreation(VM&, JSReadableStreamDefaultReader*, JSReadableStream* branch1, JSReadableStream* branch2);
private:
TeeState(VM&, Structure*);
void finishCreation(VM&);
// Called when either branch is canceled
JSC::JSPromise* cancel(VM&, JSGlobalObject*, JSReadableStream* canceledBranch, JSValue reason);
void pullAlgorithm(VM&, JSGlobalObject*);
mutable JSC::WriteBarrier<JSReadableStreamDefaultReader> m_reader;
mutable JSC::WriteBarrier<JSReadableStream> m_branch1;
mutable JSC::WriteBarrier<JSReadableStream> m_branch2;
mutable JSC::WriteBarrier<JSC::Unknown> m_reason1;
mutable JSC::WriteBarrier<JSC::Unknown> m_reason2;
mutable JSC::WriteBarrier<JSC::JSPromise> m_cancelPromise;
mutable JSC::WriteBarrier<JSFunction> m_cancelPromiseResolve;
mutable JSC::WriteBarrier<JSFunction> m_cancelPromiseReject;
bool m_canceled1 { false };
bool m_canceled2 { false };
bool m_closedOrErrored { false };
bool m_pullInProgress { false };
};
}

View File

@@ -0,0 +1,168 @@
#include "root.h"
#include "BunWritableStream.h"
#include "BunReadableStream.h"
#include "BunTransformStream.h"
#include "BunTransformStreamDefaultController.h"
#include "ZigGlobalObject.h"
#include <JavaScriptCore/JSPromise.h>
#include "BunWritableStreamDefaultController.h"
namespace Bun {
using namespace JSC;
const ClassInfo JSTransformStream::s_info = {
"TransformStream"_s,
&Base::s_info,
nullptr,
nullptr,
CREATE_METHOD_TABLE(JSTransformStream)
};
template<typename Visitor>
void JSTransformStream::visitChildrenImpl(JSCell* cell, Visitor& visitor)
{
auto* thisObject = jsCast<JSTransformStream*>(cell);
ASSERT_GC_OBJECT_INHERITS(thisObject, info());
Base::visitChildren(thisObject, visitor);
visitor.append(thisObject->m_readable);
visitor.append(thisObject->m_writable);
visitor.append(thisObject->m_controller);
visitor.append(thisObject->m_backpressureChangePromise);
}
DEFINE_VISIT_CHILDREN(JSTransformStream);
JSTransformStream::JSTransformStream(VM& vm, Structure* structure)
: Base(vm, structure)
{
}
void JSTransformStream::finishCreation(VM& vm, JSGlobalObject* globalObject)
{
Base::finishCreation(vm);
ASSERT(inherits(info()));
// Initialize readable/writable sides and controller
auto scope = DECLARE_THROW_SCOPE(vm);
auto* zigGlobalObject = jsDynamicCast<Zig::GlobalObject*>(globalObject);
if (UNLIKELY(!zigGlobalObject)) {
throwTypeError(globalObject, scope, "Invalid global object"_s);
return;
}
// Initialize with empty promises that will be fulfilled when ready
m_backpressureChangePromise.set(vm, this, JSPromise::create(vm, zigGlobalObject->promiseStructure()));
// Set up the controller
m_controller.set(vm, this, JSTransformStreamDefaultController::create(vm, globalObject, zigGlobalObject->streams().structure<JSTransformStreamDefaultController>(zigGlobalObject), this));
RETURN_IF_EXCEPTION(scope, void());
}
JSTransformStream* JSTransformStream::create(VM& vm, JSGlobalObject* globalObject, Structure* structure)
{
JSTransformStream* ptr = new (NotNull, JSC::allocateCell<JSTransformStream>(vm)) JSTransformStream(vm, structure);
ptr->finishCreation(vm, globalObject);
return ptr;
}
void JSTransformStream::enqueue(VM& vm, JSGlobalObject* globalObject, JSValue chunk)
{
auto scope = DECLARE_THROW_SCOPE(vm);
if (m_controller)
m_controller->enqueue(globalObject, chunk);
RETURN_IF_EXCEPTION(scope, void());
}
void JSTransformStream::error(VM& vm, JSGlobalObject* globalObject, JSValue error)
{
if (m_controller)
m_controller->error(vm, globalObject, error);
}
void JSTransformStream::terminate(VM& vm, JSGlobalObject* globalObject)
{
if (m_controller)
m_controller->terminate(vm, globalObject);
}
void JSTransformStream::errorWritableAndUnblockWrite(VM& vm, JSGlobalObject* globalObject, JSValue error)
{
if (m_controller) {
auto* controller = this->controller();
// Clear algorithms on controller
controller->clearAlgorithms();
// Error the writable stream's controller if needed
if (auto* writable = writableStream()) {
if (auto* controller = writable->controller()) {
controller->error(vm, globalObject, error);
}
}
this->unblockWrite(vm, globalObject);
}
}
void JSTransformStream::unblockWrite(JSC::VM& vm, JSC::JSGlobalObject* globalObject)
{
// If stream.[[backpressure]] is true, perform ! TransformStreamSetBackpressure(stream, false).
if (m_backpressure) {
if (m_backpressureChangePromise) {
m_backpressureChangePromise->fulfillWithNonPromise(globalObject, jsUndefined());
m_backpressureChangePromise.clear();
}
}
m_backpressure = false;
}
JSWritableStream* JSTransformStream::writableStream() const
{
return jsCast<JSWritableStream*>(m_writable.get());
}
JSReadableStream* JSTransformStream::readableStream() const
{
return jsCast<JSReadableStream*>(m_readable.get());
}
void JSTransformStream::setBackpressure(JSC::VM& vm, JSC::JSGlobalObject* globalObject)
{
if (m_backpressure) {
return;
}
// TransformStreamSetBackpressure(stream, backpressure) performs the following steps:
// Assert: stream.[[backpressure]] is not backpressure.
if (m_backpressureChangePromise) {
m_backpressureChangePromise->fulfillWithNonPromise(globalObject, jsUndefined());
m_backpressureChangePromise.clear();
}
m_backpressure = true;
}
JSTransformStreamDefaultController* JSTransformStream::controller()
{
return jsCast<JSTransformStreamDefaultController*>(m_controller.get());
}
JSC::GCClient::IsoSubspace* JSTransformStream::subspaceForImpl(JSC::VM& vm)
{
return WebCore::subspaceForImpl<JSTransformStream, WebCore::UseCustomHeapCellType::No>(
vm,
[](auto& spaces) { return spaces.m_clientSubspaceForTransformStream.get(); },
[](auto& spaces, auto&& space) { spaces.m_clientSubspaceForTransformStream = std::forward<decltype(space)>(space); },
[](auto& spaces) { return spaces.m_subspaceForTransformStream.get(); },
[](auto& spaces, auto&& space) { spaces.m_subspaceForTransformStream = std::forward<decltype(space)>(space); });
}
} // namespace Bun

View File

@@ -0,0 +1,80 @@
#include "root.h"
#include <JavaScriptCore/JSPromise.h>
#include <JavaScriptCore/JSObject.h>
#include <JavaScriptCore/JSArray.h>
namespace Bun {
class JSTransformStreamDefaultController;
class JSReadableStream;
class JSWritableStream;
class JSTransformStream final : public JSC::JSNonFinalObject {
public:
using Base = JSC::JSNonFinalObject;
// For garbage collection
DECLARE_INFO;
DECLARE_VISIT_CHILDREN;
template<typename, JSC::SubspaceAccess mode>
static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm)
{
if constexpr (mode == JSC::SubspaceAccess::Concurrently)
return nullptr;
return subspaceForImpl(vm);
}
static JSC::GCClient::IsoSubspace* subspaceForImpl(JSC::VM& vm);
static JSTransformStream* create(
JSC::VM& vm,
JSC::JSGlobalObject* globalObject,
JSC::Structure* structure);
static JSC::Structure* createStructure(
JSC::VM& vm,
JSC::JSGlobalObject* globalObject,
JSC::JSValue prototype)
{
return JSC::Structure::create(
vm,
globalObject,
prototype,
JSC::TypeInfo(JSC::JSType::ObjectType, StructureFlags),
info());
}
// Readable side operations
JSC::JSValue readable() const { return m_readable.get(); }
Bun::JSReadableStream* readableStream() const;
JSC::JSValue writable() const { return m_writable.get(); }
Bun::JSWritableStream* writableStream() const;
JSTransformStreamDefaultController* controller();
// Direct C++ API
void enqueue(JSC::VM&, JSC::JSGlobalObject*, JSC::JSValue chunk);
void error(JSC::VM&, JSC::JSGlobalObject*, JSC::JSValue error);
void terminate(JSC::VM&, JSC::JSGlobalObject*);
void errorWritableAndUnblockWrite(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue error);
void errorWritableAndUnblockWrite(JSC::JSGlobalObject* globalObject, JSC::JSValue error) { this->errorWritableAndUnblockWrite(this->vm(), globalObject, error); }
// Backpressure operations
bool hasBackpressure() const { return m_backpressure; }
void setBackpressure(JSC::VM& vm, JSC::JSGlobalObject* globalObject);
void unblockWrite(JSC::VM& vm, JSC::JSGlobalObject* globalObject);
private:
JSTransformStream(JSC::VM&, JSC::Structure*);
void finishCreation(JSC::VM&, JSC::JSGlobalObject*);
// The readable and writable sides of the transform stream
JSC::WriteBarrier<JSC::JSObject> m_readable;
JSC::WriteBarrier<JSC::JSObject> m_writable;
JSC::WriteBarrier<JSTransformStreamDefaultController> m_controller;
// State flags
bool m_backpressure { false };
JSC::WriteBarrier<JSC::JSPromise> m_backpressureChangePromise;
};
}

View File

@@ -0,0 +1,160 @@
#include "root.h"
#include "BunReadableStream.h"
#include "BunWritableStream.h"
#include "BunTransformStream.h"
#include "BunReadableStreamDefaultReader.h"
#include "BunTransformStreamDefaultController.h"
#include "ZigGlobalObject.h"
#include "BunTransformStreamConstructor.h"
#include "BunTransformStreamPrototype.h"
#include "BunBuiltinNames.h"
#include <JavaScriptCore/FunctionPrototype.h>
#include "ErrorCode.h"
namespace Bun {
using namespace JSC;
const ClassInfo JSTransformStreamConstructor::s_info = {
"Function"_s,
&Base::s_info,
nullptr,
nullptr,
CREATE_METHOD_TABLE(JSTransformStreamConstructor)
};
JSTransformStreamConstructor* JSTransformStreamConstructor::create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSTransformStreamPrototype* prototype)
{
auto* structure = createStructure(vm, globalObject, globalObject->functionPrototype());
JSTransformStreamConstructor* constructor = new (NotNull, JSC::allocateCell<JSTransformStreamConstructor>(vm)) JSTransformStreamConstructor(vm, structure);
constructor->finishCreation(vm, globalObject, prototype);
return constructor;
}
JSTransformStreamConstructor::JSTransformStreamConstructor(JSC::VM& vm, JSC::Structure* structure)
: Base(vm, structure, call, construct)
{
}
void JSTransformStreamConstructor::finishCreation(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSTransformStreamPrototype* prototype)
{
Base::finishCreation(vm, 3, "TransformStream"_s, PropertyAdditionMode::WithStructureTransition);
putDirect(vm, vm.propertyNames->prototype, prototype,
PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly);
}
JSC_DEFINE_HOST_FUNCTION(JSTransformStreamConstructor::construct, (JSGlobalObject * globalObject, CallFrame* callFrame))
{
VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
auto* zigGlobalObject = jsDynamicCast<Zig::GlobalObject*>(globalObject);
if (UNLIKELY(!zigGlobalObject))
return throwVMTypeError(globalObject, scope, "Invalid global object"_s);
JSObject* newTarget = asObject(callFrame->newTarget());
Structure* structure = zigGlobalObject->streams().structure<JSTransformStream>(zigGlobalObject);
auto* constructor = zigGlobalObject->streams().constructor<JSTransformStream>(zigGlobalObject);
if (!(!newTarget || newTarget != constructor)) {
if (newTarget) {
structure = JSC::InternalFunction::createSubclassStructure(getFunctionRealm(globalObject, newTarget), newTarget, structure);
} else {
structure = JSC::InternalFunction::createSubclassStructure(globalObject, constructor, structure);
}
}
RETURN_IF_EXCEPTION(scope, {});
// Extract constructor arguments per spec:
// new TransformStream(transformer = undefined, writableStrategy = {}, readableStrategy = {})
JSValue transformerArg = callFrame->argument(0);
JSValue writableStrategyArg = callFrame->argument(1);
JSValue readableStrategyArg = callFrame->argument(2);
// Create the underlying transform stream
JSTransformStream* transformStream = JSTransformStream::create(vm, globalObject, structure);
RETURN_IF_EXCEPTION(scope, {});
auto& builtinNames = Bun::builtinNames(vm);
// Set up readable and writable sides with provided strategies
if (!writableStrategyArg.isUndefined()) {
// Apply writable strategy
JSValue highWaterMark = writableStrategyArg.get(globalObject, builtinNames.highWaterMarkPublicName());
RETURN_IF_EXCEPTION(scope, {});
JSValue size = writableStrategyArg.get(globalObject, vm.propertyNames->size);
RETURN_IF_EXCEPTION(scope, {});
// ... apply strategy to writable side
UNUSED_PARAM(highWaterMark);
UNUSED_PARAM(size);
}
if (!readableStrategyArg.isUndefined()) {
// Apply readable strategy
JSValue highWaterMark = readableStrategyArg.get(globalObject, builtinNames.highWaterMarkPublicName());
RETURN_IF_EXCEPTION(scope, {});
JSValue size = readableStrategyArg.get(globalObject, vm.propertyNames->size);
RETURN_IF_EXCEPTION(scope, {});
// ... apply strategy to readable side
UNUSED_PARAM(highWaterMark);
UNUSED_PARAM(size);
}
// Handle transformer setup if provided
if (!transformerArg.isUndefined()) {
JSValue transformFn = transformerArg.get(globalObject, builtinNames.transformPublicName());
RETURN_IF_EXCEPTION(scope, {});
JSValue flushFn = transformerArg.get(globalObject, builtinNames.flushPublicName());
RETURN_IF_EXCEPTION(scope, {});
JSValue startFn = transformerArg.get(globalObject, builtinNames.startPublicName());
RETURN_IF_EXCEPTION(scope, {});
// Set up transform algorithm
if (!transformFn.isUndefined()) {
// Install transform function
}
// Set up flush algorithm
if (!flushFn.isUndefined()) {
// Install flush function
}
// Call start if present
if (!startFn.isUndefined()) {
auto* controller = transformStream->controller();
MarkedArgumentBuffer args;
args.append(controller);
auto callData = JSC::getCallData(startFn);
if (callData.type == JSC::CallData::Type::None) {
throwTypeError(globalObject, scope, "Start function is not callable"_s);
return {};
}
IGNORE_WARNINGS_BEGIN("unused-variable")
JSC::JSValue startResult = JSC::call(globalObject, startFn, callData, transformerArg, args);
IGNORE_WARNINGS_END
RETURN_IF_EXCEPTION(scope, {});
}
}
RELEASE_AND_RETURN(scope, JSValue::encode(transformStream));
}
JSC_DEFINE_HOST_FUNCTION(JSTransformStreamConstructor::call, (JSGlobalObject * globalObject, CallFrame*))
{
VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
Bun::throwError(globalObject, scope, Bun::ErrorCode::ERR_INVALID_ARG_TYPE, "Cannot call TransformStream"_s);
return {};
}
Structure* JSTransformStreamConstructor::createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
{
return Structure::create(vm, globalObject, prototype, TypeInfo(InternalFunctionType, StructureFlags), info());
}
} // namespace Bun

View File

@@ -0,0 +1,31 @@
#pragma once
#include <JavaScriptCore/InternalFunction.h>
namespace Bun {
class JSTransformStreamPrototype;
class JSTransformStreamConstructor final : public JSC::InternalFunction {
using Base = JSC::InternalFunction;
public:
static JSTransformStreamConstructor* create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSTransformStreamPrototype* prototype);
DECLARE_INFO;
template<typename CellType, JSC::SubspaceAccess>
static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm)
{
return &vm.internalFunctionSpace();
}
static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype);
private:
JSTransformStreamConstructor(JSC::VM& vm, JSC::Structure* structure);
void finishCreation(JSC::VM&, JSC::JSGlobalObject*, JSTransformStreamPrototype*);
static JSC::EncodedJSValue JSC_HOST_CALL_ATTRIBUTES call(JSC::JSGlobalObject*, JSC::CallFrame*);
static JSC::EncodedJSValue JSC_HOST_CALL_ATTRIBUTES construct(JSC::JSGlobalObject*, JSC::CallFrame*);
};
}

View File

@@ -0,0 +1,149 @@
#include "BunClientData.h"
#include "root.h"
#include "BunTransformStreamDefaultController.h"
#include "BunTransformStream.h"
#include "BunReadableStream.h"
#include "BunWritableStream.h"
#include "BunReadableStreamDefaultController.h"
namespace Bun {
using namespace JSC;
JSTransformStreamDefaultController* JSTransformStreamDefaultController::create(
JSC::VM& vm,
JSC::JSGlobalObject* globalObject,
JSC::Structure* structure,
JSTransformStream* transformStream)
{
JSTransformStreamDefaultController* controller = new (NotNull, JSC::allocateCell<JSTransformStreamDefaultController>(vm))
JSTransformStreamDefaultController(vm, structure);
controller->finishCreation(vm, globalObject, transformStream);
return controller;
}
JSC::GCClient::IsoSubspace* JSTransformStreamDefaultController::subspaceForImpl(JSC::VM& vm)
{
return WebCore::subspaceForImpl<JSTransformStreamDefaultController, WebCore::UseCustomHeapCellType::No>(
vm,
[](auto& spaces) { return spaces.m_clientSubspaceForTransformStreamDefaultController.get(); },
[](auto& spaces, auto&& space) { spaces.m_clientSubspaceForTransformStreamDefaultController = std::forward<decltype(space)>(space); },
[](auto& spaces) { return spaces.m_subspaceForTransformStreamDefaultController.get(); },
[](auto& spaces, auto&& space) { spaces.m_subspaceForTransformStreamDefaultController = std::forward<decltype(space)>(space); });
}
void JSTransformStreamDefaultController::finishCreation(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSTransformStream* transformStream)
{
Base::finishCreation(vm);
ASSERT(inherits(info()));
m_stream.set(vm, this, transformStream);
}
JSTransformStream* JSTransformStreamDefaultController::stream() const
{
return JSC::jsCast<JSTransformStream*>(m_stream.get());
}
template<typename Visitor>
void JSTransformStreamDefaultController::visitChildrenImpl(JSCell* cell, Visitor& visitor)
{
auto* thisObject = jsCast<JSTransformStreamDefaultController*>(cell);
ASSERT_GC_OBJECT_INHERITS(thisObject, info());
Base::visitChildren(thisObject, visitor);
visitor.append(thisObject->m_stream);
visitor.append(thisObject->m_flushPromise);
visitor.append(thisObject->m_transformAlgorithm);
visitor.append(thisObject->m_flushAlgorithm);
}
DEFINE_VISIT_CHILDREN(JSTransformStreamDefaultController);
bool JSTransformStreamDefaultController::enqueue(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue chunk)
{
auto scope = DECLARE_THROW_SCOPE(vm);
// Get the transform stream
auto* stream = jsDynamicCast<JSTransformStream*>(m_stream.get());
ASSERT(stream);
// Get the readable controller from the stream's readable side
auto* readable = jsDynamicCast<JSReadableStream*>(stream->readable());
ASSERT(readable);
auto* readableController = jsDynamicCast<JSReadableStreamDefaultController*>(readable->controller());
ASSERT(readableController);
// Check if we can enqueue to the readable controller
if (!readableController->canCloseOrEnqueue()) {
throwTypeError(globalObject, scope, "Cannot enqueue to readable side - controller cannot close or enqueue"_s);
return false;
}
// Try to enqueue the chunk to the readable controller
readableController->enqueue(vm, globalObject, chunk);
// If enqueuing resulted in an error
if (scope.exception()) {
// Get the error from the scope
JSValue error = scope.exception();
scope.clearException();
// Error the writable side and unblock write
stream->error(vm, globalObject, error);
// Throw the readable's stored error
throwException(globalObject, scope, error);
return false;
}
// Check if the readable controller now has backpressure
double desiredSize = readableController->desiredSize();
bool hasBackpressure = desiredSize <= 0;
// If backpressure state changed and is now true
if (hasBackpressure) {
stream->setBackpressure(vm, globalObject);
} else {
stream->unblockWrite(vm, globalObject);
}
return true;
}
void JSTransformStreamDefaultController::error(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue error)
{
auto* stream = this->stream();
ASSERT(stream);
stream->error(vm, globalObject, error);
}
void JSTransformStreamDefaultController::terminate(JSC::VM& vm, JSC::JSGlobalObject* globalObject)
{
auto scope = DECLARE_THROW_SCOPE(vm);
auto* stream = this->stream();
ASSERT(stream);
// Get the readable controller
auto* readable = stream->readableStream();
ASSERT(readable);
auto* readableController = readable->controller();
ASSERT(readableController);
// Close the readable controller
readableController->close(vm, globalObject);
RETURN_IF_EXCEPTION(scope, void());
// Create TypeError for termination
JSC::JSValue error = JSC::createTypeError(globalObject, "The stream has been terminated"_s);
// Error the writable side and unblock write
// Call TransformStreamErrorWritableAndUnblockWrite operation
stream->errorWritableAndUnblockWrite(vm, globalObject, error);
}
const ClassInfo JSTransformStreamDefaultController::s_info = { "TransformStreamDefaultController"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSTransformStreamDefaultController) };
} // namespace Bun

View File

@@ -0,0 +1,62 @@
#pragma once
#include "root.h"
namespace Bun {
class JSTransformStream;
class JSTransformStreamDefaultController final : public JSC::JSNonFinalObject {
using Base = JSC::JSNonFinalObject;
public:
static JSTransformStreamDefaultController* create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure, JSTransformStream* transformStream);
DECLARE_INFO;
DECLARE_VISIT_CHILDREN;
template<typename CellType, JSC::SubspaceAccess mode>
static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm)
{
if (mode == JSC::SubspaceAccess::Concurrently) {
return nullptr;
}
return subspaceForImpl(vm);
}
static JSC::GCClient::IsoSubspace* subspaceForImpl(JSC::VM& vm);
static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
{
return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info());
}
bool enqueue(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue chunk);
bool enqueue(JSC::JSGlobalObject* globalObject, JSC::JSValue chunk) { return enqueue(this->vm(), globalObject, chunk); }
void error(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue error);
void error(JSC::JSGlobalObject* globalObject, JSC::JSValue error) { this->error(this->vm(), globalObject, error); }
void terminate(JSC::VM& vm, JSC::JSGlobalObject* globalObject);
void terminate(JSC::JSGlobalObject* globalObject) { terminate(this->vm(), globalObject); }
void clearAlgorithms()
{
m_transformAlgorithm.clear();
m_flushAlgorithm.clear();
}
JSTransformStream* stream() const;
private:
JSTransformStreamDefaultController(JSC::VM& vm, JSC::Structure* structure)
: Base(vm, structure)
{
}
void finishCreation(JSC::VM&, JSC::JSGlobalObject*, JSTransformStream* transformStream);
JSC::WriteBarrier<JSObject> m_stream;
JSC::WriteBarrier<JSC::JSObject> m_flushPromise;
JSC::WriteBarrier<JSC::JSObject> m_transformAlgorithm;
JSC::WriteBarrier<JSC::JSObject> m_flushAlgorithm;
};
} // namespace Bun

View File

@@ -0,0 +1,48 @@
#include "root.h"
#include "ErrorCode.h"
#include "BunTransformStreamDefaultControllerConstructor.h"
#include "BunTransformStreamDefaultControllerPrototype.h"
#include <JavaScriptCore/FunctionPrototype.h>
namespace Bun {
const JSC::ClassInfo JSTransformStreamDefaultControllerConstructor::s_info = { "Function"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSTransformStreamDefaultControllerConstructor) };
JSTransformStreamDefaultControllerConstructor::JSTransformStreamDefaultControllerConstructor(JSC::VM& vm, JSC::Structure* structure)
: Base(vm, structure, call, construct)
{
}
JSTransformStreamDefaultControllerConstructor* JSTransformStreamDefaultControllerConstructor::create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSTransformStreamDefaultControllerPrototype* prototype)
{
auto* structure = createStructure(vm, globalObject, globalObject->functionPrototype());
JSTransformStreamDefaultControllerConstructor* constructor = new (NotNull, JSC::allocateCell<JSTransformStreamDefaultControllerConstructor>(vm))
JSTransformStreamDefaultControllerConstructor(vm, structure);
constructor->finishCreation(vm, globalObject, prototype);
return constructor;
}
void JSTransformStreamDefaultControllerConstructor::finishCreation(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSTransformStreamDefaultControllerPrototype* prototype)
{
Base::finishCreation(vm, 2, "TransformStreamDefaultController"_s, PropertyAdditionMode::WithStructureTransition);
ASSERT(inherits(info()));
putDirect(vm, vm.propertyNames->prototype, prototype, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly | 0);
}
JSC::EncodedJSValue JSC_HOST_CALL_ATTRIBUTES JSTransformStreamDefaultControllerConstructor::call(JSC::JSGlobalObject* globalObject, JSC::CallFrame* callFrame)
{
VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
return Bun::throwError(globalObject, scope, Bun::ErrorCode::ERR_ILLEGAL_CONSTRUCTOR, "TransformStreamDefaultController constructor cannot be called directly"_s);
}
JSC::EncodedJSValue JSC_HOST_CALL_ATTRIBUTES JSTransformStreamDefaultControllerConstructor::construct(JSC::JSGlobalObject* globalObject, JSC::CallFrame* callFrame)
{
VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
return Bun::throwError(globalObject, scope, Bun::ErrorCode::ERR_ILLEGAL_CONSTRUCTOR, "TransformStreamDefaultController constructor cannot be constructed directly"_s);
}
} // namespace Bun

View File

@@ -0,0 +1,35 @@
#pragma once
#include "root.h"
namespace Bun {
class JSTransformStreamDefaultControllerPrototype;
class JSTransformStreamDefaultControllerConstructor final : public JSC::InternalFunction {
using Base = JSC::InternalFunction;
public:
static JSTransformStreamDefaultControllerConstructor* create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSTransformStreamDefaultControllerPrototype* prototype);
DECLARE_INFO;
template<typename CellType, JSC::SubspaceAccess>
static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm)
{
return &vm.internalFunctionSpace();
}
static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
{
return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::InternalFunctionType, StructureFlags), info());
}
private:
JSTransformStreamDefaultControllerConstructor(JSC::VM& vm, JSC::Structure* structure);
void finishCreation(JSC::VM&, JSC::JSGlobalObject*, JSTransformStreamDefaultControllerPrototype*);
static JSC::EncodedJSValue JSC_HOST_CALL_ATTRIBUTES call(JSC::JSGlobalObject*, JSC::CallFrame*);
static JSC::EncodedJSValue JSC_HOST_CALL_ATTRIBUTES construct(JSC::JSGlobalObject*, JSC::CallFrame*);
};
} // namespace Bun

View File

@@ -0,0 +1,108 @@
#include "root.h"
#include <JavaScriptCore/Lookup.h>
#include "BunTransformStreamDefaultControllerPrototype.h"
#include "BunTransformStreamDefaultController.h"
namespace Bun {
using namespace JSC;
static JSC_DECLARE_CUSTOM_GETTER(jsTransformStreamDefaultControllerDesiredSize);
static JSC_DECLARE_HOST_FUNCTION(jsTransformStreamDefaultControllerEnqueue);
static JSC_DECLARE_HOST_FUNCTION(jsTransformStreamDefaultControllerError);
static JSC_DECLARE_HOST_FUNCTION(jsTransformStreamDefaultControllerTerminate);
static const JSC::HashTableValue JSTransformStreamDefaultControllerPrototypeTableValues[] = {
{ "enqueue"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic,
{ HashTableValue::NativeFunctionType, jsTransformStreamDefaultControllerEnqueue, 1 } },
{ "error"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic,
{ HashTableValue::NativeFunctionType, jsTransformStreamDefaultControllerError, 1 } },
{ "terminate"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic,
{ HashTableValue::NativeFunctionType, jsTransformStreamDefaultControllerTerminate, 0 } },
{ "desiredSize"_s, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor), NoIntrinsic,
{ HashTableValue::GetterSetterType, jsTransformStreamDefaultControllerDesiredSize, 0 } },
};
const JSC::ClassInfo JSTransformStreamDefaultControllerPrototype::s_info = { "Function"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSTransformStreamDefaultControllerPrototype) };
JSTransformStreamDefaultControllerPrototype::JSTransformStreamDefaultControllerPrototype(JSC::VM& vm, JSC::Structure* structure)
: Base(vm, structure)
{
}
JSTransformStreamDefaultControllerPrototype* JSTransformStreamDefaultControllerPrototype::create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure)
{
structure->setMayBePrototype(true);
JSTransformStreamDefaultControllerPrototype* ptr = new (NotNull, JSC::allocateCell<JSTransformStreamDefaultControllerPrototype>(vm))
JSTransformStreamDefaultControllerPrototype(vm, structure);
ptr->finishCreation(vm, globalObject);
return ptr;
}
void JSTransformStreamDefaultControllerPrototype::finishCreation(JSC::VM& vm, JSC::JSGlobalObject* globalObject)
{
Base::finishCreation(vm);
ASSERT(inherits(info()));
reifyStaticProperties(vm, info(), JSTransformStreamDefaultControllerPrototypeTableValues, *this);
JSC_TO_STRING_TAG_WITHOUT_TRANSITION();
}
JSC_DEFINE_CUSTOM_GETTER(jsTransformStreamDefaultControllerDesiredSize, (JSGlobalObject * globalObject, EncodedJSValue thisValue, PropertyName))
{
VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
auto* thisObject = jsDynamicCast<JSTransformStreamDefaultController*>(JSValue::decode(thisValue));
if (UNLIKELY(!thisObject))
return throwVMTypeError(globalObject, scope, "Receiver must be a TransformStreamDefaultController"_s);
// Return the desired size per spec
return JSValue::encode(jsNumber(0)); // Placeholder
}
JSC_DEFINE_HOST_FUNCTION(jsTransformStreamDefaultControllerEnqueue, (JSGlobalObject * globalObject, CallFrame* callFrame))
{
VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
auto* controller = jsDynamicCast<JSTransformStreamDefaultController*>(callFrame->thisValue());
if (UNLIKELY(!controller))
return throwVMTypeError(globalObject, scope, "Receiver must be a TransformStreamDefaultController"_s);
JSValue chunk = callFrame->argument(0);
if (!controller->enqueue(globalObject, chunk))
return JSValue::encode(jsUndefined());
return JSValue::encode(jsUndefined());
}
JSC_DEFINE_HOST_FUNCTION(jsTransformStreamDefaultControllerError, (JSGlobalObject * globalObject, CallFrame* callFrame))
{
VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
auto* controller = jsDynamicCast<JSTransformStreamDefaultController*>(callFrame->thisValue());
if (UNLIKELY(!controller))
return throwVMTypeError(globalObject, scope, "Receiver must be a TransformStreamDefaultController"_s);
controller->error(vm, globalObject, callFrame->argument(0));
return JSValue::encode(jsUndefined());
}
JSC_DEFINE_HOST_FUNCTION(jsTransformStreamDefaultControllerTerminate, (JSGlobalObject * globalObject, CallFrame* callFrame))
{
VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
auto* controller = jsDynamicCast<JSTransformStreamDefaultController*>(callFrame->thisValue());
if (UNLIKELY(!controller))
return throwVMTypeError(globalObject, scope, "Receiver must be a TransformStreamDefaultController"_s);
controller->terminate(globalObject);
return JSValue::encode(jsUndefined());
}
} // namespace Bun

View File

@@ -0,0 +1,31 @@
#pragma once
#include "root.h"
namespace Bun {
class JSTransformStreamDefaultControllerPrototype final : public JSC::JSNonFinalObject {
using Base = JSC::JSNonFinalObject;
public:
static JSTransformStreamDefaultControllerPrototype* create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure);
DECLARE_INFO;
template<typename CellType, JSC::SubspaceAccess>
static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm)
{
STATIC_ASSERT_ISO_SUBSPACE_SHARABLE(JSTransformStreamDefaultControllerPrototype, Base);
return &vm.plainObjectSpace();
}
static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
{
return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info());
}
private:
JSTransformStreamDefaultControllerPrototype(JSC::VM& vm, JSC::Structure* structure);
void finishCreation(JSC::VM&, JSC::JSGlobalObject*);
};
} // namespace Bun

View File

@@ -0,0 +1,93 @@
#include "root.h"
#include "BunTransformStreamPrototype.h"
#include "BunTransformStream.h"
#include "BunBuiltinNames.h"
#include "ZigGlobalObject.h"
namespace Bun {
using namespace JSC;
static JSC_DECLARE_CUSTOM_GETTER(jsTransformStreamReadableGetter);
static JSC_DECLARE_CUSTOM_GETTER(jsTransformStreamWritableGetter);
static JSC_DECLARE_CUSTOM_GETTER(jsTransformStreamConstructor);
// All static properties for the prototype
static const HashTableValue JSTransformStreamPrototypeTableValues[] = {
{ "readable"_s,
static_cast<unsigned>(PropertyAttribute::ReadOnly),
NoIntrinsic,
{ HashTableValue::GetterSetterType, jsTransformStreamReadableGetter, nullptr } },
{ "writable"_s,
static_cast<unsigned>(PropertyAttribute::ReadOnly),
NoIntrinsic,
{ HashTableValue::GetterSetterType, jsTransformStreamWritableGetter, nullptr } },
};
JSC_DEFINE_CUSTOM_GETTER(jsTransformStreamReadableGetter, (JSGlobalObject * globalObject, EncodedJSValue thisValue, PropertyName))
{
VM& vm = JSC::getVM(globalObject);
auto scope = DECLARE_THROW_SCOPE(vm);
auto* thisObject = jsDynamicCast<JSTransformStream*>(JSValue::decode(thisValue));
if (UNLIKELY(!thisObject)) {
return throwVMTypeError(globalObject, scope, "Cannot get readable property of non-TransformStream"_s);
}
ASSERT(thisObject->readable());
return JSValue::encode(thisObject->readable());
}
JSC_DEFINE_CUSTOM_GETTER(jsTransformStreamWritableGetter, (JSGlobalObject * globalObject, EncodedJSValue thisValue, PropertyName))
{
VM& vm = JSC::getVM(globalObject);
auto scope = DECLARE_THROW_SCOPE(vm);
auto* thisObject = jsDynamicCast<JSTransformStream*>(JSValue::decode(thisValue));
if (UNLIKELY(!thisObject)) {
return throwVMTypeError(globalObject, scope, "Cannot get writable property of non-TransformStream"_s);
}
ASSERT(thisObject->writable());
return JSValue::encode(thisObject->writable());
}
JSTransformStreamPrototype* JSTransformStreamPrototype::create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure)
{
JSTransformStreamPrototype* ptr = new (NotNull, JSC::allocateCell<JSTransformStreamPrototype>(vm)) JSTransformStreamPrototype(vm, structure);
ptr->finishCreation(vm, globalObject);
return ptr;
}
template<typename CellType, JSC::SubspaceAccess mode>
JSC::GCClient::IsoSubspace* JSTransformStreamPrototype::subspaceFor(JSC::VM& vm)
{
STATIC_ASSERT_ISO_SUBSPACE_SHARABLE(JSTransformStreamPrototype, Base);
return &vm.plainObjectSpace();
}
JSTransformStreamPrototype::JSTransformStreamPrototype(JSC::VM& vm, JSC::Structure* structure)
: Base(vm, structure)
{
}
void JSTransformStreamPrototype::finishCreation(VM& vm, JSGlobalObject* globalObject)
{
Base::finishCreation(vm);
reifyStaticProperties(
vm,
JSTransformStream::info(),
JSTransformStreamPrototypeTableValues,
*this);
JSC_TO_STRING_TAG_WITHOUT_TRANSITION();
}
const ClassInfo JSTransformStreamPrototype::s_info = { "TransformStream"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSTransformStreamPrototype) };
Structure* JSTransformStreamPrototype::createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
{
return Structure::create(vm, globalObject, prototype, TypeInfo(JSC::JSType::ObjectType, StructureFlags), info());
}
} // namespace Bun

View File

@@ -0,0 +1,23 @@
#pragma once
#include <JavaScriptCore/JSObject.h>
namespace Bun {
class JSTransformStreamPrototype final : public JSC::JSNonFinalObject {
using Base = JSC::JSNonFinalObject;
public:
static JSTransformStreamPrototype* create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure);
DECLARE_INFO;
template<typename CellType, JSC::SubspaceAccess>
static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm);
static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype);
private:
JSTransformStreamPrototype(JSC::VM& vm, JSC::Structure* structure);
void finishCreation(JSC::VM&, JSC::JSGlobalObject*);
};
}

View File

@@ -0,0 +1,438 @@
#include "root.h"
#include "BunStreamStructures.h"
#include "BunWritableStream.h"
#include "BunWritableStreamDefaultController.h"
#include "BunWritableStreamDefaultWriter.h"
#include "BunStreamStructures.h"
#include "BunStreamInlines.h"
#include "ZigGlobalObject.h"
#include "BunPromiseInlines.h"
namespace Bun {
using namespace JSC;
// Forward declarations
namespace Operations {
void WritableStreamStartErroring(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSWritableStream* stream, JSC::JSValue reason);
void WritableStreamFinishErroring(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSWritableStream* stream);
void WritableStreamDefaultWriterEnsureReadyPromiseRejected(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSWritableStreamDefaultWriter* writer, JSC::JSValue reason);
} // namespace Operations
// WritableStream implementation
const ClassInfo JSWritableStream::s_info = { "WritableStream"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSWritableStream) };
JSWritableStream::JSWritableStream(VM& vm, Structure* structure)
: Base(vm, structure)
{
}
void JSWritableStream::finishCreation(VM& vm)
{
Base::finishCreation(vm);
ASSERT(inherits(info()));
}
JSWritableStream* JSWritableStream::create(VM& vm, JSGlobalObject* globalObject, Structure* structure)
{
auto* domGlobalObject = defaultGlobalObject(globalObject);
auto& streams = domGlobalObject->streams();
Structure* streamStructure = streams.structure<JSWritableStream>(domGlobalObject);
JSWritableStream* stream = new (NotNull, allocateCell<JSWritableStream>(vm))
JSWritableStream(vm, streamStructure ? streamStructure : structure);
stream->finishCreation(vm);
return stream;
}
template<typename Visitor>
void JSWritableStream::visitChildrenImpl(JSCell* cell, Visitor& visitor)
{
auto* thisObject = jsCast<JSWritableStream*>(cell);
ASSERT_GC_OBJECT_INHERITS(thisObject, info());
Base::visitChildren(thisObject, visitor);
visitor.append(thisObject->m_controller);
visitor.append(thisObject->m_writer);
visitor.append(thisObject->m_closeRequest);
visitor.append(thisObject->m_inFlightWriteRequest);
visitor.append(thisObject->m_inFlightCloseRequest);
visitor.append(thisObject->m_storedError);
}
DEFINE_VISIT_CHILDREN(JSWritableStream);
Structure* JSWritableStream::createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
{
return Structure::create(vm, globalObject, prototype,
TypeInfo(ObjectType, StructureFlags), info());
}
bool JSWritableStream::isLocked() const
{
return !!m_writer;
}
JSValue JSWritableStream::error(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue error)
{
if (m_state == State::Writable) {
Operations::WritableStreamStartErroring(vm, globalObject, this, error);
} else if (m_state == State::Erroring) {
Operations::WritableStreamFinishErroring(vm, globalObject, this);
}
return jsUndefined();
}
void JSWritableStream::setStoredError(JSC::VM& vm, JSC::JSValue error)
{
m_storedError.set(vm, this, error);
}
namespace Operations {
void WritableStreamStartErroring(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSWritableStream* stream, JSC::JSValue reason)
{
auto scope = DECLARE_THROW_SCOPE(vm);
// 1. Assert: stream.[[storedError]] is undefined.
ASSERT(!stream->storedError() || stream->storedError().isUndefined());
// 2. Assert: stream.[[state]] is "writable".
ASSERT(stream->state() == JSWritableStream::State::Writable);
// 3. Let controller be stream.[[writableStreamController]].
auto* controller = stream->controller();
ASSERT(controller);
// 4. Set stream.[[state]] to "erroring".
stream->setState(JSWritableStream::State::Erroring);
// 5. Set stream.[[storedError]] to reason.
stream->setStoredError(vm, reason);
// 6. Let writer be stream.[[writer]].
auto* writer = stream->writer();
// 7. If writer is not undefined, perform ! WritableStreamDefaultWriterEnsureReadyPromiseRejected(writer, reason).
if (writer)
WritableStreamDefaultWriterEnsureReadyPromiseRejected(vm, globalObject, writer, reason);
// 8. If ! WritableStreamHasOperationMarkedInFlight(stream) is false and controller.[[started]] is true,
// perform ! WritableStreamFinishErroring(stream).
if (!stream->hasOperationMarkedInFlight() && controller->started())
WritableStreamFinishErroring(vm, globalObject, stream);
RETURN_IF_EXCEPTION(scope, void());
}
void WritableStreamFinishErroring(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSWritableStream* stream)
{
auto scope = DECLARE_THROW_SCOPE(vm);
// 1. Assert: stream.[[state]] is "erroring".
ASSERT(stream->state() == JSWritableStream::State::Erroring);
// 2. Assert: ! WritableStreamHasOperationMarkedInFlight(stream) is false.
ASSERT(!stream->hasOperationMarkedInFlight());
// 3. Set stream.[[state]] to "errored".
stream->setState(JSWritableStream::State::Errored);
// 4. Perform ! WritableStreamDefaultControllerErrorSteps(stream.[[writableStreamController]]).
stream->controller()->errorSteps();
JSValue storedError = stream->storedError();
// 5. Let writer be stream.[[writer]].
auto* writer = stream->writer();
// 6. If writer is not undefined,
if (writer) {
// a. Let writeRequests be writer.[[writeRequests]].
// b. Set writer.[[writeRequests]] to an empty List.
// c. For each writeRequest of writeRequests,
// 1. Reject writeRequest with stream.[[storedError]].
writer->rejectWriteRequests(vm, globalObject, storedError);
}
JSPromise* abortPromise = stream->pendingAbortRequestPromise();
// 7. Let pendingAbortRequest be stream.[[pendingAbortRequest]].
// 8. If pendingAbortRequest is undefined, return.
if (!abortPromise)
return;
JSValue abortReason = stream->pendingAbortRequestReason();
bool wasAlreadyErroring = stream->wasAlreadyErroring();
stream->clearPendingAbortRequest();
// 10. If pendingAbortRequest.[[wasAlreadyErroring]] is true,
if (wasAlreadyErroring) {
// a. Reject pendingAbortRequest.[[promise]] with pendingAbortRequest.[[reason]].
abortPromise->reject(globalObject, abortReason);
// b. Return.
return;
}
// 11. Let abortAlgorithm be stream.[[writableStreamController]].[[abortAlgorithm]].
// 12. Let result be the result of performing abortAlgorithm with argument pendingAbortRequest.[[reason]].
JSValue result = stream->controller()->performAbortAlgorithm(abortReason);
// 13. Upon fulfillment of result,
// a. Resolve pendingAbortRequest.[[promise]] with undefined.
// 14. Upon rejection of result with reason r,
// a. Reject pendingAbortRequest.[[promise]] with r.
if (JSPromise* resultPromise = jsDynamicCast<JSPromise*>(result)) {
Bun::then(globalObject, resultPromise,
jsFunctionResolveAbortPromiseWithUndefined,
jsFunctionRejectAbortPromiseWithReason,
abortPromise);
} else {
// If not a promise, treat as fulfilled
abortPromise->fulfillWithNonPromise(globalObject, jsUndefined());
}
}
void WritableStreamUpdateBackpressure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSWritableStream* stream, bool backpressure)
{
ASSERT(stream->state() == JSWritableStream::State::Writable);
ASSERT(!stream->isCloseQueuedOrInFlight());
JSWritableStreamDefaultWriter* writer = stream->writer();
if (writer && backpressure != stream->backpressure()) {
if (backpressure) {
writer->resetReadyPromise();
} else {
ASSERT(!backpressure);
writer->resolveReadyPromise();
}
}
stream->setBackpressure(backpressure);
}
void WritableStreamDefaultWriterEnsureReadyPromiseRejected(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSWritableStreamDefaultWriter* writer, JSC::JSValue reason)
{
// 1. If writer.[[readyPromise]] is pending, reject it with reason.
JSPromise* readyPromise = writer->ready();
if (readyPromise && readyPromise->status(vm) == JSPromise::Status::Pending)
readyPromise->rejectAsHandled(globalObject, reason);
// 2. Set writer.[[readyPromise]] to a promise rejected with reason.
JSPromise* newPromise = JSPromise::rejectedPromise(globalObject, reason);
writer->setReady(vm, newPromise);
}
} // namespace Operations
JSValue JSWritableStream::abort(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue reason)
{
auto scope = DECLARE_THROW_SCOPE(vm);
// 1. If ! IsWritableStreamLocked(this) is true, return a promise rejected with a TypeError exception.
if (isLocked())
return JSPromise::rejectedPromise(globalObject, createTypeError(globalObject, "Cannot abort a locked WritableStream"_s));
// 2. Let state be this.[[state]].
const auto state = m_state;
// 3. If state is "closed" or state is "errored", return a promise resolved with undefined.
if (state == State::Closed || state == State::Errored)
return Bun::createFulfilledPromise(globalObject, jsUndefined());
// 4. If this.[[pendingAbortRequest]] is not undefined, return this.[[pendingAbortRequest]].[[promise]].
if (auto promise = m_pendingAbortRequestPromise.get())
return promise;
// 5. Assert: state is "writable" or state is "erroring".
ASSERT(state == State::Writable || state == State::Erroring);
// 6. Let wasAlreadyErroring be false.
bool wasAlreadyErroring = false;
// 7. If state is "erroring",
if (state == State::Erroring) {
// a. Set wasAlreadyErroring to true.
wasAlreadyErroring = true;
// b. Set reason to undefined.
reason = jsUndefined();
}
// 8. Let promise be a new promise.
JSPromise* promise = JSPromise::create(vm, globalObject->promiseStructure());
// 9. Set this.[[pendingAbortRequest]] to record {[[promise]]: promise, [[reason]]: reason, [[wasAlreadyErroring]]: wasAlreadyErroring}.
m_pendingAbortRequestPromise.set(vm, this, promise);
m_pendingAbortRequestReason.set(vm, this, reason);
m_wasAlreadyErroring = wasAlreadyErroring;
// 10. If wasAlreadyErroring is false, perform ! WritableStreamStartErroring(this, reason).
if (!wasAlreadyErroring)
Operations::WritableStreamStartErroring(vm, globalObject, this, reason);
// 11. If this.[[state]] is "errored", perform ! WritableStreamFinishErroring(this).
if (m_state == State::Errored)
Operations::WritableStreamFinishErroring(vm, globalObject, this);
// 12. Return promise.
return promise;
}
JSValue JSWritableStream::close(JSC::VM& vm, JSC::JSGlobalObject* globalObject)
{
auto scope = DECLARE_THROW_SCOPE(vm);
// 1. If ! IsWritableStreamLocked(this) is true, return a promise rejected with a TypeError exception.
if (isLocked())
return JSPromise::rejectedPromise(globalObject, createTypeError(globalObject, "Cannot close a locked WritableStream"_s));
// 2. If ! WritableStreamCloseQueuedOrInFlight(this) is true, return a promise rejected with a TypeError exception.
if (m_closeRequest || m_inFlightCloseRequest)
return JSPromise::rejectedPromise(globalObject, createTypeError(globalObject, "Cannot close an already closing stream"_s));
// 3. Let state be this.[[state]].
const auto state = m_state;
// 4. If state is "closed", return a promise rejected with a TypeError exception.
if (state == State::Closed)
return JSPromise::rejectedPromise(globalObject, createTypeError(globalObject, "Cannot close an already closed stream"_s));
// 5. If state is "errored", return a promise rejected with this.[[storedError]].
if (state == State::Errored)
return JSPromise::rejectedPromise(globalObject, m_storedError.get());
// 6. If state is "erroring", return a promise rejected with this.[[storedError]].
if (state == State::Erroring)
return JSPromise::rejectedPromise(globalObject, m_storedError.get());
// 7. Assert: state is "writable".
ASSERT(state == State::Writable);
// 8. Let closeRequest be ! WritableStreamCreateCloseRequest(this).
JSPromise* closeRequest = JSPromise::create(vm, globalObject->promiseStructure());
m_closeRequest.set(vm, this, closeRequest);
// 9. Perform ! WritableStreamDefaultControllerClose(this.[[controller]]).
controller()->close(globalObject);
// 10. Return closeRequest.[[promise]].
return closeRequest;
}
void JSWritableStream::finishInFlightClose()
{
JSGlobalObject* globalObject = m_controller->globalObject();
// 1. Assert: this.[[inFlightCloseRequest]] is not undefined.
ASSERT(m_inFlightCloseRequest);
// 2. Resolve this.[[inFlightCloseRequest]] with undefined.
m_inFlightCloseRequest->resolve(globalObject, jsUndefined());
// 3. Set this.[[inFlightCloseRequest]] to undefined.
m_inFlightCloseRequest.clear();
// 4. Set this.[[state]] to "closed".
m_state = State::Closed;
// 5. Let writer be this.[[writer]].
auto* writer = this->writer();
// 6. If writer is not undefined,
if (writer) {
// a. Resolve writer.[[closedPromise]] with undefined.
writer->resolveClosedPromise(globalObject, jsUndefined());
}
}
void JSWritableStream::updateBackpressure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, bool backpressure)
{
}
void JSWritableStream::finishInFlightCloseWithError(JSValue error)
{
VM& vm = m_controller->vm();
JSGlobalObject* globalObject = m_controller->globalObject();
// 1. Assert: this.[[inFlightCloseRequest]] is not undefined.
ASSERT(m_inFlightCloseRequest);
// 2. Reject this.[[inFlightCloseRequest]] with error.
m_inFlightCloseRequest->reject(globalObject, error);
// 3. Set this.[[inFlightCloseRequest]] to undefined.
m_inFlightCloseRequest.clear();
// 4. Set this.[[state]] to "errored".
m_state = State::Errored;
// 5. Set this.[[storedError]] to error.
m_storedError.set(vm, this, error);
// 6. Let writer be this.[[writer]].
auto* writer = this->writer();
// 7. If writer is not undefined,
if (writer) {
// a. Reject writer.[[closedPromise]] with error.
writer->rejectClosedPromise(globalObject, error);
}
}
JSWritableStreamDefaultController* JSWritableStream::controller() const
{
return jsCast<JSWritableStreamDefaultController*>(m_controller.get());
}
void JSWritableStream::setController(JSC::VM& vm, JSWritableStreamDefaultController* controller)
{
m_controller.set(vm, this, controller);
}
JSWritableStreamDefaultWriter* JSWritableStream::writer() const
{
return jsCast<JSWritableStreamDefaultWriter*>(m_writer.get());
}
void JSWritableStream::setWriter(VM& vm, JSWritableStreamDefaultWriter* writer)
{
m_writer.set(vm, this, writer);
}
JSC_DEFINE_HOST_FUNCTION(jsFunctionResolveAbortPromiseWithUndefined, (JSGlobalObject * globalObject, CallFrame* callFrame))
{
VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
JSPromise* promise = jsDynamicCast<JSPromise*>(callFrame->argument(1));
if (!promise)
return JSValue::encode(jsUndefined());
promise->fulfillWithNonPromise(globalObject, jsUndefined());
return JSValue::encode(jsUndefined());
}
JSC_DEFINE_HOST_FUNCTION(jsFunctionRejectAbortPromiseWithReason, (JSGlobalObject * globalObject, CallFrame* callFrame))
{
VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
JSPromise* promise = jsDynamicCast<JSPromise*>(callFrame->argument(1));
if (!promise)
return JSValue::encode(jsUndefined());
promise->reject(globalObject, callFrame->argument(0));
return JSValue::encode(jsUndefined());
}
JSC::GCClient::IsoSubspace* JSWritableStream::subspaceForImpl(JSC::VM& vm)
{
return WebCore::subspaceForImpl<JSWritableStream, WebCore::UseCustomHeapCellType::No>(
vm,
[](auto& spaces) { return spaces.m_clientSubspaceForWritableStream.get(); },
[](auto& spaces, auto&& space) { spaces.m_clientSubspaceForWritableStream = std::forward<decltype(space)>(space); },
[](auto& spaces) { return spaces.m_subspaceForWritableStream.get(); },
[](auto& spaces, auto&& space) { spaces.m_subspaceForWritableStream = std::forward<decltype(space)>(space); });
}
} // namespace Bun

View File

@@ -0,0 +1,99 @@
#pragma once
#include "root.h"
#include "JavaScriptCore/JSObject.h"
namespace Bun {
using namespace JSC;
class JSWritableStreamDefaultController;
class JSWritableStreamDefaultWriter;
class JSWritableStream final : public JSNonFinalObject {
public:
using Base = JSNonFinalObject;
enum class State {
Writable,
Erroring,
Errored,
Closed
};
static JSWritableStream* create(VM&, JSGlobalObject*, Structure*);
static Structure* createStructure(VM&, JSGlobalObject*, JSValue prototype);
DECLARE_INFO;
DECLARE_VISIT_CHILDREN;
template<typename, JSC::SubspaceAccess mode>
static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm)
{
if constexpr (mode == JSC::SubspaceAccess::Concurrently)
return nullptr;
return subspaceForImpl(vm);
}
static JSC::GCClient::IsoSubspace* subspaceForImpl(JSC::VM& vm);
bool isLocked() const;
JSValue error(JSC::VM& vm, JSC::JSGlobalObject*, JSC::JSValue error);
JSValue error(JSC::JSGlobalObject* globalObject, JSC::JSValue error) { return this->error(this->vm(), globalObject, error); }
JSValue abort(JSC::VM& vm, JSC::JSGlobalObject*, JSC::JSValue reason);
JSValue abort(JSC::JSGlobalObject* globalObject, JSC::JSValue reason) { return abort(this->vm(), globalObject, reason); }
JSValue close(JSC::VM& vm, JSC::JSGlobalObject*);
JSValue close(JSC::JSGlobalObject* globalObject) { return close(this->vm(), globalObject); }
void write(JSC::VM& vm, JSC::JSGlobalObject*, JSC::JSValue chunk);
void write(JSC::JSGlobalObject* globalObject, JSC::JSValue chunk) { return write(this->vm(), globalObject, chunk); }
void finishInFlightClose();
void finishInFlightCloseWithError(JSValue error);
bool isCloseQueuedOrInFlight() const { return m_closeRequest || m_inFlightCloseRequest; }
bool isCloseQueued() const { return !!m_closeRequest; }
bool isInFlightClose() const { return !!m_inFlightCloseRequest; }
State state() const { return m_state; }
void setState(State state) { m_state = state; }
JSWritableStreamDefaultController* controller() const;
void setController(JSC::VM& vm, JSWritableStreamDefaultController* controller);
void setController(JSWritableStreamDefaultController* controller) { setController(this->vm(), controller); }
JSWritableStreamDefaultWriter* writer() const;
void setWriter(JSC::VM& vm, JSWritableStreamDefaultWriter* writer);
void setWriter(JSWritableStreamDefaultWriter* writer) { setWriter(this->vm(), writer); }
JSValue storedError() const { return m_storedError.get(); }
void setStoredError(JSC::VM& vm, JSC::JSValue error);
void setStoredError(JSC::JSValue error) { setStoredError(this->vm(), error); }
JSPromise* pendingAbortRequestPromise() const { return m_pendingAbortRequestPromise.get(); }
JSValue pendingAbortRequestReason() const { return m_pendingAbortRequestReason.get(); }
bool wasAlreadyErroring() const { return m_wasAlreadyErroring; }
void clearPendingAbortRequest()
{
m_pendingAbortRequestPromise.clear();
m_pendingAbortRequestReason.clear();
m_wasAlreadyErroring = false;
}
void updateBackpressure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, bool backpressure);
bool backpressure() const { return m_backpressure; }
bool hasOperationMarkedInFlight() const { return m_inFlightWriteRequest || m_inFlightCloseRequest; }
void setBackpressure(bool backpressure) { m_backpressure = backpressure; }
private:
JSWritableStream(VM&, Structure*);
void finishCreation(VM&);
State m_state { State::Writable };
mutable WriteBarrier<JSObject> m_controller;
mutable WriteBarrier<JSObject> m_writer;
mutable WriteBarrier<JSPromise> m_closeRequest;
mutable WriteBarrier<JSPromise> m_inFlightWriteRequest;
mutable WriteBarrier<JSPromise> m_inFlightCloseRequest;
mutable WriteBarrier<Unknown> m_storedError;
mutable WriteBarrier<JSPromise> m_pendingAbortRequestPromise;
mutable WriteBarrier<Unknown> m_pendingAbortRequestReason;
bool m_wasAlreadyErroring { false };
bool m_backpressure { false };
};
JSC_DECLARE_HOST_FUNCTION(jsFunctionResolveAbortPromiseWithUndefined);
JSC_DECLARE_HOST_FUNCTION(jsFunctionRejectAbortPromiseWithReason);
} // namespace Bun

View File

@@ -0,0 +1,249 @@
#include "BunWritableStreamConstructor.h"
#include "BunWritableStreamPrototype.h"
#include "BunWritableStream.h"
#include "BunWritableStreamDefaultController.h"
#include "ZigGlobalObject.h"
#include <JavaScriptCore/FunctionPrototype.h>
namespace Bun {
using namespace JSC;
// Constructor Implementation
const ClassInfo JSWritableStreamConstructor::s_info = { "Function"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSWritableStreamConstructor) };
JSWritableStreamConstructor::JSWritableStreamConstructor(VM& vm, Structure* structure)
: Base(vm, structure, call, construct)
{
}
JSWritableStreamConstructor* JSWritableStreamConstructor::create(VM& vm, JSGlobalObject* globalObject, JSWritableStreamPrototype* prototype)
{
auto* structure = createStructure(vm, globalObject, globalObject->functionPrototype());
JSWritableStreamConstructor* constructor = new (NotNull, allocateCell<JSWritableStreamConstructor>(vm)) JSWritableStreamConstructor(vm, structure);
constructor->finishCreation(vm, globalObject, prototype);
return constructor;
}
Structure* JSWritableStreamConstructor::createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
{
return Structure::create(vm, globalObject, prototype, TypeInfo(InternalFunctionType, StructureFlags), info());
}
static void underlyingSinkFromJS(
JSC::VM& vm, JSGlobalObject* globalObject, JSValue underlyingSinkValue,
JSC::JSValue strategyValue,
JSC::JSValue& highWaterMarkValue,
JSC::JSValue& sizeAlgorithmValue,
JSC::JSValue& closeAlgorithmValue,
JSC::JSValue& abortAlgorithmValue,
JSC::JSValue& writeAlgorithmValue,
JSC::JSValue& startAlgorithmValue)
{
auto scope = DECLARE_THROW_SCOPE(vm);
// Default values
startAlgorithmValue = jsUndefined();
writeAlgorithmValue = jsUndefined();
closeAlgorithmValue = jsUndefined();
abortAlgorithmValue = jsUndefined();
auto& propertyNames = Bun::builtinNames(vm);
// Extract strategy parameters
if (!strategyValue.isUndefined()) {
JSObject* strategyObj = strategyValue.getObject();
if (!strategyObj) {
throwVMTypeError(globalObject, scope, "WritableStream strategy must be an object"_s);
return;
}
// Get highWaterMark
highWaterMarkValue = strategyObj->getIfPropertyExists(globalObject, propertyNames.highWaterMarkPublicName());
RETURN_IF_EXCEPTION(scope, void());
if (!highWaterMarkValue || highWaterMarkValue.isUndefined()) {
highWaterMarkValue = jsNumber(1);
}
// Get size algorithm
sizeAlgorithmValue = strategyObj->getIfPropertyExists(globalObject, vm.propertyNames->size);
RETURN_IF_EXCEPTION(scope, void());
if (!sizeAlgorithmValue) {
sizeAlgorithmValue = jsUndefined();
}
if (!sizeAlgorithmValue.isUndefined() && !sizeAlgorithmValue.isCallable()) {
throwVMTypeError(globalObject, scope, "WritableStream strategy size must be callable"_s);
return;
}
strategyValue = sizeAlgorithmValue;
} else {
highWaterMarkValue = jsNumber(1);
sizeAlgorithmValue = jsUndefined();
}
// If no underlying sink, use defaults and return
if (underlyingSinkValue.isUndefinedOrNull()) {
return;
}
JSObject* underlyingSink = underlyingSinkValue.getObject();
if (!underlyingSink) {
throwVMTypeError(globalObject, scope, "WritableStream underlying sink must be an object"_s);
return;
}
// Get start method
startAlgorithmValue = underlyingSink->getIfPropertyExists(globalObject, propertyNames.startPublicName());
RETURN_IF_EXCEPTION(scope, void());
if (!startAlgorithmValue) {
startAlgorithmValue = jsUndefined();
}
if (!startAlgorithmValue.isUndefined() && !startAlgorithmValue.isCallable()) {
throwVMTypeError(globalObject, scope, "WritableStream underlying sink start must be callable"_s);
return;
}
// Get write method
writeAlgorithmValue = underlyingSink->getIfPropertyExists(globalObject, propertyNames.writePublicName());
RETURN_IF_EXCEPTION(scope, void());
if (!writeAlgorithmValue) {
writeAlgorithmValue = jsUndefined();
}
if (!writeAlgorithmValue.isUndefined() && !writeAlgorithmValue.isCallable()) {
throwVMTypeError(globalObject, scope, "WritableStream underlying sink write must be callable"_s);
return;
}
// Get close method
closeAlgorithmValue = underlyingSink->getIfPropertyExists(globalObject, propertyNames.closePublicName());
RETURN_IF_EXCEPTION(scope, void());
if (!closeAlgorithmValue) {
closeAlgorithmValue = jsUndefined();
}
if (!closeAlgorithmValue.isUndefined() && !closeAlgorithmValue.isCallable()) {
throwVMTypeError(globalObject, scope, "WritableStream underlying sink close must be callable"_s);
return;
}
// Get abort method
abortAlgorithmValue = underlyingSink->getIfPropertyExists(globalObject, Identifier::fromString(vm, "abort"_s));
RETURN_IF_EXCEPTION(scope, void());
if (!abortAlgorithmValue) {
abortAlgorithmValue = jsUndefined();
}
if (!abortAlgorithmValue.isUndefined() && !abortAlgorithmValue.isCallable()) {
throwVMTypeError(globalObject, scope, "WritableStream underlying sink abort must be callable"_s);
return;
}
// Check for type property which is currently reserved
JSValue typeValue = underlyingSink->getIfPropertyExists(globalObject, Identifier::fromString(vm, "type"_s));
RETURN_IF_EXCEPTION(scope, void());
if (!typeValue) {
typeValue = jsUndefined();
}
if (!typeValue.isUndefined()) {
throwVMTypeError(globalObject, scope, "WritableStream underlying sink type property is reserved for future use"_s);
return;
}
}
JSC_DEFINE_HOST_FUNCTION(jsWritableStreamPrivateConstructor, (JSGlobalObject * globalObject, CallFrame* callFrame))
{
// Similar to above but for internal usage
VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
auto* domGlobalObject = defaultGlobalObject(globalObject);
auto& streams = domGlobalObject->streams();
Structure* structure = streams.structure<JSWritableStream>(domGlobalObject);
JSWritableStream* stream = JSWritableStream::create(vm, globalObject, structure);
RETURN_IF_EXCEPTION(scope, {});
return JSValue::encode(stream);
}
void JSWritableStreamConstructor::finishCreation(VM& vm, JSGlobalObject* globalObject, JSWritableStreamPrototype* prototype)
{
Base::finishCreation(vm, 1, "WritableStream"_s, PropertyAdditionMode::WithStructureTransition);
putDirect(vm, vm.propertyNames->prototype, prototype, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly);
}
JSC_DEFINE_HOST_FUNCTION(JSWritableStreamConstructor::call, (JSGlobalObject * globalObject, CallFrame*))
{
VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
return throwVMTypeError(globalObject, scope, "Cannot call WritableStream"_s);
}
JSC_DEFINE_HOST_FUNCTION(JSWritableStreamConstructor::construct, (JSGlobalObject * globalObject, CallFrame* callFrame))
{
VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
auto* zigGlobalObject = jsDynamicCast<Zig::GlobalObject*>(globalObject);
if (UNLIKELY(!zigGlobalObject))
return throwVMTypeError(globalObject, scope, "Invalid global object"_s);
JSObject* newTarget = asObject(callFrame->newTarget());
Structure* structure = zigGlobalObject->streams().structure<JSWritableStream>(zigGlobalObject);
auto* constructor = zigGlobalObject->streams().constructor<JSWritableStream>(zigGlobalObject);
if (!(!newTarget || newTarget != constructor)) {
if (newTarget) {
structure = JSC::InternalFunction::createSubclassStructure(getFunctionRealm(globalObject, newTarget), newTarget, structure);
} else {
structure = JSC::InternalFunction::createSubclassStructure(globalObject, constructor, structure);
}
}
RETURN_IF_EXCEPTION(scope, {});
// Extract constructor arguments per spec:
// new WritableStream(underlyingSink = {}, strategy = {})
JSValue underlyingSinkArg = callFrame->argument(0);
JSValue strategyArg = callFrame->argument(1);
// Create the underlying writable stream
JSWritableStream* writableStream = JSWritableStream::create(vm, globalObject, structure);
RETURN_IF_EXCEPTION(scope, {});
double highWaterMark = 1;
JSC::JSValue highWaterMarkValue;
JSC::JSValue sizeAlgorithmValue;
JSC::JSValue closeAlgorithmValue;
JSC::JSValue abortAlgorithmValue;
JSC::JSValue writeAlgorithmValue;
JSC::JSValue startAlgorithmValue;
underlyingSinkFromJS(vm, globalObject, underlyingSinkArg, strategyArg, highWaterMarkValue, sizeAlgorithmValue, closeAlgorithmValue, abortAlgorithmValue, writeAlgorithmValue, startAlgorithmValue);
RETURN_IF_EXCEPTION(scope, {});
// Set up the controller
Structure* controllerStructure = zigGlobalObject->streams().structure<JSWritableStreamDefaultController>(zigGlobalObject);
auto* controller = JSWritableStreamDefaultController::create(
vm,
globalObject,
controllerStructure,
writableStream,
highWaterMark,
abortAlgorithmValue.getObject(),
closeAlgorithmValue.getObject(),
writeAlgorithmValue.getObject(),
sizeAlgorithmValue.getObject());
RETURN_IF_EXCEPTION(scope, {});
writableStream->setController(controller);
RELEASE_AND_RETURN(scope, JSValue::encode(writableStream));
}
} // namespace Bun

View File

@@ -0,0 +1,36 @@
#pragma once
#include "root.h"
namespace Bun {
class JSWritableStreamPrototype;
using namespace JSC;
class JSWritableStreamConstructor final : public InternalFunction {
public:
using Base = InternalFunction;
static constexpr unsigned StructureFlags = Base::StructureFlags;
static JSWritableStreamConstructor* create(VM&, JSGlobalObject*, JSWritableStreamPrototype*);
DECLARE_INFO;
template<typename CellType, SubspaceAccess mode>
static JSC::GCClient::IsoSubspace* subspaceFor(VM& vm)
{
if constexpr (mode == SubspaceAccess::Concurrently)
return nullptr;
return &vm.internalFunctionSpace();
}
static Structure* createStructure(VM&, JSGlobalObject*, JSValue prototype);
static EncodedJSValue JSC_HOST_CALL_ATTRIBUTES construct(JSGlobalObject*, CallFrame*);
static EncodedJSValue JSC_HOST_CALL_ATTRIBUTES call(JSGlobalObject*, CallFrame*);
private:
JSWritableStreamConstructor(VM& vm, Structure* structure);
void finishCreation(VM& vm, JSGlobalObject* globalObject, JSWritableStreamPrototype* prototype);
};
} // namespace Bun

View File

@@ -0,0 +1,338 @@
#include "root.h"
#include "AbortController.h"
#include "JSDOMConvertInterface.h"
#include <JavaScriptCore/JSPromise.h>
#include "JSAbortController.h"
#include <JavaScriptCore/WriteBarrierInlines.h>
#include "ZigGlobalObject.h"
#include <JavaScriptCore/JSGlobalObject.h>
#include <JavaScriptCore/JSArray.h>
#include "BunWritableStreamDefaultController.h"
#include "BunWritableStream.h"
#include "JSAbortSignal.h"
#include "IDLTypes.h"
#include "JSDOMBinding.h"
#include "BunStreamStructures.h"
#include <JavaScriptCore/LazyPropertyInlines.h>
#include "BunStreamInlines.h"
#include "JSAbortSignal.h"
#include "DOMJITIDLType.h"
#include <JavaScriptCore/VMTrapsInlines.h>
namespace Bun {
JSWritableStream* JSWritableStreamDefaultController::stream() const
{
return jsDynamicCast<JSWritableStream*>(m_stream.get());
}
void JSWritableStreamDefaultController::setStream(JSC::VM& vm, JSWritableStream* stream) { m_stream.set(vm, this, stream); }
void JSWritableStreamDefaultController::setAbortAlgorithm(JSC::VM& vm, JSC::JSObject* abortAlgorithm) { m_abortAlgorithm.set(vm, this, abortAlgorithm); }
void JSWritableStreamDefaultController::setCloseAlgorithm(JSC::VM& vm, JSC::JSObject* closeAlgorithm) { m_closeAlgorithm.set(vm, this, closeAlgorithm); }
void JSWritableStreamDefaultController::setWriteAlgorithm(JSC::VM& vm, JSC::JSObject* writeAlgorithm) { m_writeAlgorithm.set(vm, this, writeAlgorithm); }
JSC::GCClient::IsoSubspace* JSWritableStreamDefaultController::subspaceForImpl(JSC::VM& vm)
{
return WebCore::subspaceForImpl<JSWritableStreamDefaultController, WebCore::UseCustomHeapCellType::No>(
vm,
[](auto& spaces) { return spaces.m_clientSubspaceForWritableStreamDefaultController.get(); },
[](auto& spaces, auto&& space) { spaces.m_clientSubspaceForWritableStreamDefaultController = std::forward<decltype(space)>(space); },
[](auto& spaces) { return spaces.m_subspaceForWritableStreamDefaultController.get(); },
[](auto& spaces, auto&& space) { spaces.m_subspaceForWritableStreamDefaultController = std::forward<decltype(space)>(space); });
}
JSC_DEFINE_HOST_FUNCTION(jsWritableStreamDefaultControllerCloseFulfill, (JSGlobalObject * globalObject, CallFrame* callFrame))
{
VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
JSWritableStream* stream = jsDynamicCast<JSWritableStream*>(callFrame->argument(1));
if (UNLIKELY(!stream))
return throwVMTypeError(globalObject, scope, "WritableStreamDefaultController.close called with invalid stream"_s);
stream->finishInFlightClose();
return JSValue::encode(jsUndefined());
}
JSC_DEFINE_HOST_FUNCTION(jsWritableStreamDefaultControllerCloseReject, (JSGlobalObject * globalObject, CallFrame* callFrame))
{
VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
JSWritableStream* stream = jsDynamicCast<JSWritableStream*>(callFrame->argument(1));
if (UNLIKELY(!stream))
return throwVMTypeError(globalObject, scope, "WritableStreamDefaultController.close called with invalid stream"_s);
stream->finishInFlightCloseWithError(callFrame->argument(0));
return JSValue::encode(jsUndefined());
}
JSWritableStreamDefaultController* JSWritableStreamDefaultController::create(
JSC::VM& vm,
JSC::JSGlobalObject* globalObject,
JSC::Structure* structure,
JSWritableStream* stream,
double highWaterMark,
JSC::JSObject* abortAlgorithm,
JSC::JSObject* closeAlgorithm,
JSC::JSObject* writeAlgorithm,
JSC::JSObject* sizeAlgorithm)
{
JSWritableStreamDefaultController* controller = new (
NotNull, JSC::allocateCell<JSWritableStreamDefaultController>(vm))
JSWritableStreamDefaultController(vm, structure);
controller->finishCreation(vm);
if (abortAlgorithm)
controller->m_abortAlgorithm.setMayBeNull(vm, controller, abortAlgorithm);
else
controller->m_abortAlgorithm.clear();
if (closeAlgorithm)
controller->m_closeAlgorithm.setMayBeNull(vm, controller, closeAlgorithm);
else
controller->m_closeAlgorithm.clear();
if (writeAlgorithm)
controller->m_writeAlgorithm.setMayBeNull(vm, controller, writeAlgorithm);
else
controller->m_writeAlgorithm.clear();
if (stream)
controller->m_stream.set(vm, controller, stream);
else
controller->m_stream.clear();
controller->queue().initialize(vm, globalObject, highWaterMark, controller, sizeAlgorithm);
return controller;
}
void JSWritableStreamDefaultController::finishCreation(JSC::VM& vm)
{
Base::finishCreation(vm);
m_abortController.initLater([](const JSC::LazyProperty<JSObject, WebCore::JSAbortController>::Initializer& init) {
auto* lexicalGlobalObject = init.owner->globalObject();
Zig::GlobalObject* globalObject = defaultGlobalObject(lexicalGlobalObject);
auto& scriptExecutionContext = *globalObject->scriptExecutionContext();
Ref<WebCore::AbortController> abortController = WebCore::AbortController::create(scriptExecutionContext);
JSAbortController* abortControllerValue = jsCast<JSAbortController*>(WebCore::toJSNewlyCreated<IDLInterface<WebCore::AbortController>>(*lexicalGlobalObject, *globalObject, WTFMove(abortController)));
init.set(abortControllerValue);
});
}
WebCore::AbortSignal& JSWritableStreamDefaultController::signal() const
{
auto* abortController = m_abortController.getInitializedOnMainThread(this);
auto& impl = abortController->wrapped();
return impl.signal();
}
Ref<WebCore::AbortSignal> JSWritableStreamDefaultController::abortSignal() const
{
auto* abortController = m_abortController.getInitializedOnMainThread(this);
auto& impl = abortController->wrapped();
return impl.protectedSignal();
}
JSC::JSValue JSWritableStreamDefaultController::error(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue reason)
{
auto scope = DECLARE_THROW_SCOPE(vm);
// 1. Let stream be this.[[stream]].
JSWritableStream* stream = this->stream();
// 2. Assert: stream is not undefined.
ASSERT(stream);
// 3. Let state be stream.[[state]].
auto state = stream->state();
// 4. Assert: state is "writable".
if (state != JSWritableStream::State::Writable)
return throwTypeError(globalObject, scope, "WritableStreamDefaultController.error called on non-writable stream"_s);
// 5. Perform ! WritableStreamDefaultControllerError(this, error).
m_writeAlgorithm.clear();
m_closeAlgorithm.clear();
m_abortAlgorithm.clear();
m_queue.clearAlgorithms();
stream->error(vm, globalObject, reason);
return jsUndefined();
}
void JSWritableStreamDefaultController::write(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue chunk)
{
auto scope = DECLARE_THROW_SCOPE(vm);
// 1. Let stream be this.[[stream]].
JSWritableStream* stream = this->stream();
ASSERT(stream);
// 2. If ! WritableStreamCloseQueuedOrInFlight(stream) is true, return a promise rejected with a TypeError.
if (stream->isCloseQueuedOrInFlight()) {
throwTypeError(globalObject, scope, "Cannot write to a stream that is closed or closing"_s);
return;
}
// 3. If stream.[[state]] is not "writable", return a promise rejected with a TypeError.
if (stream->state() != JSWritableStream::State::Writable) {
throwTypeError(globalObject, scope, "Cannot write to a stream that is not writable"_s);
return;
}
// 4. Let sizeAlgorithm be this.[[strategySizeAlgorithm]].
// 5. Let chunkSize be ? Call(sizeAlgorithm, undefined, « chunk »).
// 6. Let enqueueResult be EnqueueValueWithSize(this, chunk, chunkSize).
m_queue.enqueueValueAndGetSize(vm, globalObject, this, chunk);
RETURN_IF_EXCEPTION(scope, void());
// 7. If ! WritableStreamCloseQueuedOrInFlight(stream) is false and stream.[[state]] is "writable",
if (!stream->isCloseQueuedOrInFlight() && stream->state() == JSWritableStream::State::Writable) {
// Let backpressure be ! WritableStreamDefaultControllerGetBackpressure(this).
bool backpressure = getDesiredSize() <= 0;
// Perform ! WritableStreamUpdateBackpressure(stream, backpressure).
stream->updateBackpressure(vm, globalObject, backpressure);
}
// 8. Perform ! WritableStreamDefaultControllerAdvanceQueueIfNeeded(this).
if (shouldCallWrite()) {
m_writing = true;
m_inFlightWriteRequest = true;
MarkedArgumentBuffer args;
args.append(chunk);
JSObject* writeAlgorithm = m_writeAlgorithm.get();
auto callData = JSC::getCallData(writeAlgorithm);
JSC::profiledCall(globalObject, JSC::ProfilingReason::API, writeAlgorithm, callData, jsUndefined(), args);
if (UNLIKELY(scope.exception())) {
m_writing = false;
m_inFlightWriteRequest = false;
return;
}
}
}
bool JSWritableStreamDefaultController::shouldCallWrite() const
{
if (!m_started)
return false;
if (m_writing)
return false;
if (m_inFlightWriteRequest)
return false;
if (!stream() || stream()->state() != JSWritableStream::State::Writable)
return false;
return true;
}
template<typename Visitor>
void JSWritableStreamDefaultController::visitChildrenImpl(JSCell* cell, Visitor& visitor)
{
JSWritableStreamDefaultController* thisObject = jsCast<JSWritableStreamDefaultController*>(cell);
ASSERT_GC_OBJECT_INHERITS(thisObject, info());
Base::visitChildren(thisObject, visitor);
visitor.append(thisObject->m_stream);
visitor.append(thisObject->m_abortAlgorithm);
visitor.append(thisObject->m_closeAlgorithm);
visitor.append(thisObject->m_writeAlgorithm);
thisObject->m_abortController.visit(visitor);
thisObject->m_queue.visit<Visitor>(thisObject, visitor);
}
DEFINE_VISIT_CHILDREN(JSWritableStreamDefaultController);
const JSC::ClassInfo JSWritableStreamDefaultController::s_info = {
"WritableStreamDefaultController"_s,
&Base::s_info,
nullptr,
nullptr,
CREATE_METHOD_TABLE(JSWritableStreamDefaultController)
};
JSValue JSWritableStreamDefaultController::close(JSGlobalObject* globalObject)
{
VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
// 1. Let stream be this.[[stream]].
JSWritableStream* stream = this->stream();
// 2. Assert: stream is not undefined.
ASSERT(stream);
// 3. Let state be stream.[[state]].
auto state = stream->state();
// 4. Assert: state is "writable".
ASSERT(state == JSWritableStream::State::Writable);
// 5. Let closeRequest be stream.[[closeRequest]].
// 6. Assert: closeRequest is not undefined.
// TODO: do we need to check this?
JSObject* closeFunction = m_closeAlgorithm.get();
// 7. Perform ! WritableStreamDefaultControllerClearAlgorithms(this).
m_writeAlgorithm.clear();
m_closeAlgorithm.clear();
m_abortAlgorithm.clear();
m_queue.clearAlgorithms();
// 8. Let sinkClosePromise be the result of performing this.[[closeAlgorithm]].
JSValue sinkClosePromise;
if (m_closeAlgorithm) {
if (closeFunction) {
MarkedArgumentBuffer args;
ASSERT(!args.hasOverflowed());
sinkClosePromise = JSC::profiledCall(globalObject, JSC::ProfilingReason::Microtask, closeFunction, JSC::getCallData(closeFunction), jsUndefined(), args);
RETURN_IF_EXCEPTION(scope, {});
} else {
sinkClosePromise = jsUndefined();
}
} else {
sinkClosePromise = jsUndefined();
}
// 9. Upon fulfillment of sinkClosePromise:
// a. Perform ! WritableStreamFinishInFlightClose(stream).
// 10. Upon rejection of sinkClosePromise with reason r:
// a. Perform ! WritableStreamFinishInFlightCloseWithError(stream, r).
if (JSPromise* promise = jsDynamicCast<JSPromise*>(sinkClosePromise)) {
Bun::then(globalObject, promise, jsWritableStreamDefaultControllerCloseFulfill, jsWritableStreamDefaultControllerCloseReject, stream);
} else {
// If not a promise, treat as fulfilled
stream->finishInFlightClose();
}
return jsUndefined();
}
void JSWritableStreamDefaultController::errorSteps()
{
// Implementation of error steps for the controller
if (stream())
stream()->error(globalObject(), jsUndefined());
}
JSValue JSWritableStreamDefaultController::performAbortAlgorithm(JSValue reason)
{
if (!m_abortAlgorithm)
return jsUndefined();
MarkedArgumentBuffer args;
args.append(reason);
auto callData = JSC::getCallData(m_abortAlgorithm.get());
return call(globalObject(), m_abortAlgorithm.get(), callData, jsUndefined(), args);
}
}

View File

@@ -0,0 +1,115 @@
#pragma once
#include "root.h"
#include <JavaScriptCore/JSPromise.h>
#include <JavaScriptCore/JSObject.h>
#include <JavaScriptCore/JSArray.h>
#include "BunStreamQueue.h"
namespace WebCore {
class JSAbortController;
class JSAbortSignal;
class AbortSignal;
}
namespace Bun {
class JSWritableStream;
class JSWritableStreamDefaultController final : public JSC::JSNonFinalObject {
public:
using Base = JSC::JSNonFinalObject;
static constexpr bool needsDestruction = false;
static JSWritableStreamDefaultController* create(
JSC::VM& vm,
JSC::JSGlobalObject* globalObject,
JSC::Structure* structure,
JSWritableStream* stream,
double highWaterMark,
JSC::JSObject* abortAlgorithm,
JSC::JSObject* closeAlgorithm,
JSC::JSObject* writeAlgorithm,
JSC::JSObject* sizeAlgorithm);
DECLARE_INFO;
template<typename, JSC::SubspaceAccess mode>
static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm)
{
if (mode == JSC::SubspaceAccess::Concurrently) {
return nullptr;
}
return subspaceForImpl(vm);
}
static JSC::GCClient::IsoSubspace* subspaceForImpl(JSC::VM& vm);
static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
{
return JSC::Structure::create(vm, globalObject, prototype,
JSC::TypeInfo(JSC::ObjectType, StructureFlags), info());
}
// JavaScript-facing methods
JSC::JSValue error(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue reason);
JSC::JSValue error(JSC::JSGlobalObject* globalObject, JSC::JSValue reason) { return error(this->vm(), globalObject, reason); }
JSC::JSValue close(JSC::JSGlobalObject* globalObject);
void write(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue chunk);
void write(JSC::JSGlobalObject* globalObject, JSC::JSValue chunk) { this->write(this->vm(), globalObject, chunk); }
// C++-facing methods
bool shouldCallWrite() const;
double getDesiredSize() const { return m_queue.desiredSize(); }
bool started() const { return m_started; }
void errorSteps();
JSC::JSValue performAbortAlgorithm(JSC::JSValue reason);
// For garbage collection
DECLARE_VISIT_CHILDREN;
Ref<WebCore::AbortSignal> abortSignal() const;
WebCore::AbortSignal& signal() const;
JSWritableStream* stream() const;
JSC::JSObject* abortAlgorithm() const { return m_abortAlgorithm.get(); }
JSC::JSObject* closeAlgorithm() const { return m_closeAlgorithm.get(); }
JSC::JSObject* writeAlgorithm() const { return m_writeAlgorithm.get(); }
void setStream(JSC::VM& vm, JSWritableStream* stream);
void setAbortAlgorithm(JSC::VM& vm, JSC::JSObject* abortAlgorithm);
void setCloseAlgorithm(JSC::VM& vm, JSC::JSObject* closeAlgorithm);
void setWriteAlgorithm(JSC::VM& vm, JSC::JSObject* writeAlgorithm);
void resetQueue(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSObject* owner) { m_queue.resetQueue(vm, globalObject, owner); }
Bun::StreamQueue& queue() { return m_queue; }
const Bun::StreamQueue& queue() const { return m_queue; }
private:
JSWritableStreamDefaultController(JSC::VM& vm, JSC::Structure* structure)
: Base(vm, structure)
{
}
void finishCreation(JSC::VM&);
// Internal slots per spec
JSC::WriteBarrier<JSObject> m_stream;
Bun::StreamQueue m_queue;
// Functions for us to call.
JSC::WriteBarrier<JSC::JSObject> m_abortAlgorithm;
JSC::WriteBarrier<JSC::JSObject> m_closeAlgorithm;
JSC::WriteBarrier<JSC::JSObject> m_writeAlgorithm;
bool m_started { false };
bool m_writing { false };
bool m_inFlightWriteRequest { false };
bool m_closeRequested { false };
JSC::LazyProperty<JSObject, WebCore::JSAbortController> m_abortController;
};
}

View File

@@ -0,0 +1,52 @@
#include "root.h"
#include "JavaScriptCore/InternalFunction.h"
#include "ZigGlobalObject.h"
#include "BunWritableStreamDefaultControllerConstructor.h"
#include "BunWritableStreamDefaultController.h"
#include "BunWritableStreamDefaultControllerPrototype.h"
#include <JavaScriptCore/JSGlobalObject.h>
#include <JavaScriptCore/FunctionPrototype.h>
namespace Bun {
JSWritableStreamDefaultControllerConstructor* JSWritableStreamDefaultControllerConstructor::create(
JSC::VM& vm,
JSC::JSGlobalObject* globalObject,
JSWritableStreamDefaultControllerPrototype* prototype)
{
auto* structure = createStructure(vm, globalObject, globalObject->functionPrototype());
JSWritableStreamDefaultControllerConstructor* constructor = new (
NotNull, JSC::allocateCell<JSWritableStreamDefaultControllerConstructor>(vm))
JSWritableStreamDefaultControllerConstructor(vm, structure);
constructor->finishCreation(vm, globalObject, prototype);
return constructor;
}
void JSWritableStreamDefaultControllerConstructor::finishCreation(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSWritableStreamDefaultControllerPrototype* prototype)
{
Base::finishCreation(vm, 1, "WritableStreamDefaultController"_s, JSC::InternalFunction::PropertyAdditionMode::WithStructureTransition);
putDirect(vm, vm.propertyNames->prototype, prototype, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly);
}
JSC_DEFINE_HOST_FUNCTION(constructJSWritableStreamDefaultController, (JSGlobalObject * globalObject, CallFrame*))
{
VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
return throwVMTypeError(globalObject, scope, "WritableStreamDefaultController constructor cannot be called directly"_s);
}
JSC_DEFINE_HOST_FUNCTION(callJSWritableStreamDefaultController, (JSGlobalObject * globalObject, CallFrame*))
{
VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
return throwVMTypeError(globalObject, scope, "WritableStreamDefaultController constructor cannot be called as a function"_s);
}
const JSC::ClassInfo JSWritableStreamDefaultControllerConstructor::s_info = {
"WritableStreamDefaultController"_s, &Base::s_info, nullptr, nullptr,
CREATE_METHOD_TABLE(JSWritableStreamDefaultControllerConstructor)
};
} // namespace Bun

View File

@@ -0,0 +1,50 @@
#pragma once
#include "root.h"
#include <JavaScriptCore/InternalFunction.h>
namespace Bun {
using namespace JSC;
class JSWritableStreamDefaultControllerPrototype;
JSC_DECLARE_HOST_FUNCTION(callJSWritableStreamDefaultController);
JSC_DECLARE_HOST_FUNCTION(constructJSWritableStreamDefaultController);
class JSWritableStreamDefaultControllerConstructor final : public JSC::InternalFunction {
public:
using Base = JSC::InternalFunction;
static constexpr unsigned StructureFlags = Base::StructureFlags;
static constexpr bool needsDestruction = false;
static JSWritableStreamDefaultControllerConstructor* create(
JSC::VM& vm,
JSC::JSGlobalObject* globalObject,
JSWritableStreamDefaultControllerPrototype* prototype);
DECLARE_INFO;
template<typename, JSC::SubspaceAccess mode>
static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm)
{
if constexpr (mode == JSC::SubspaceAccess::Concurrently)
return nullptr;
return &vm.internalFunctionSpace();
}
static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
{
return JSC::Structure::create(vm, globalObject, prototype,
JSC::TypeInfo(JSC::InternalFunctionType, StructureFlags), info());
}
private:
JSWritableStreamDefaultControllerConstructor(JSC::VM& vm, JSC::Structure* structure)
: Base(vm, structure, callJSWritableStreamDefaultController, constructJSWritableStreamDefaultController)
{
}
void finishCreation(JSC::VM&, JSC::JSGlobalObject*, JSWritableStreamDefaultControllerPrototype*);
};
} // namespace Bun

View File

@@ -0,0 +1,101 @@
#include "root.h"
#include <JavaScriptCore/JSGlobalObject.h>
#include <JavaScriptCore/JSArray.h>
#include <JavaScriptCore/JSPromise.h>
#include "JSAbortController.h"
#include "BunWritableStreamDefaultControllerPrototype.h"
#include "BunWritableStreamDefaultController.h"
#include "JSAbortSignal.h"
#include "IDLTypes.h"
#include "DOMJITIDLType.h"
#include "JSDOMBinding.h"
#include "BunStreamInlines.h"
#include "ZigGlobalObject.h"
#include "BunWritableStream.h"
#include "AbortSignal.h"
namespace Bun {
JSC_DEFINE_HOST_FUNCTION(jsWritableStreamDefaultControllerErrorFunction, (JSGlobalObject * globalObject, CallFrame* callFrame))
{
VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
JSWritableStreamDefaultController* controller = jsDynamicCast<JSWritableStreamDefaultController*>(callFrame->thisValue());
if (UNLIKELY(!controller)) {
scope.throwException(globalObject, createTypeError(globalObject, "WritableStreamDefaultController.prototype.error called on non-WritableStreamDefaultController"_s));
return {};
}
return JSValue::encode(controller->error(globalObject, callFrame->argument(0)));
}
JSC_DEFINE_CUSTOM_GETTER(jsWritableStreamDefaultControllerGetSignal, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName))
{
VM& vm = lexicalGlobalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
auto* thisObject = jsDynamicCast<JSWritableStreamDefaultController*>(JSValue::decode(thisValue));
if (UNLIKELY(!thisObject)) {
scope.throwException(lexicalGlobalObject, createTypeError(lexicalGlobalObject, "WritableStreamDefaultController.prototype.signal called on non-WritableStreamDefaultController"_s));
return {};
}
auto* globalObject = defaultGlobalObject(lexicalGlobalObject);
auto& abortSignal = thisObject->signal();
return JSValue::encode(WebCore::toJS(lexicalGlobalObject, globalObject, abortSignal));
}
JSC_DEFINE_CUSTOM_GETTER(jsWritableStreamDefaultControllerGetDesiredSize, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName))
{
VM& vm = lexicalGlobalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
auto* thisObject = jsDynamicCast<JSWritableStreamDefaultController*>(JSValue::decode(thisValue));
if (UNLIKELY(!thisObject)) {
scope.throwException(lexicalGlobalObject, createTypeError(lexicalGlobalObject, "WritableStreamDefaultController.prototype.desiredSize called on non-WritableStreamDefaultController"_s));
return {};
}
switch (thisObject->stream()->state()) {
case JSWritableStream::State::Errored:
return JSValue::encode(jsNull());
case JSWritableStream::State::Closed:
return JSValue::encode(jsNumber(0));
default:
return JSValue::encode(jsNumber(thisObject->getDesiredSize()));
}
}
static const HashTableValue JSWritableStreamDefaultControllerPrototypeTableValues[] = {
{ "error"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic,
{ HashTableValue::NativeFunctionType, jsWritableStreamDefaultControllerErrorFunction, 1 } },
{ "signal"_s, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor), NoIntrinsic,
{ HashTableValue::GetterSetterType, jsWritableStreamDefaultControllerGetSignal, 0 } },
{ "desiredSize"_s, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor), NoIntrinsic,
{ HashTableValue::GetterSetterType, jsWritableStreamDefaultControllerGetDesiredSize, 0 } },
};
JSWritableStreamDefaultControllerPrototype* JSWritableStreamDefaultControllerPrototype::create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure)
{
JSWritableStreamDefaultControllerPrototype* ptr = new (NotNull, JSC::allocateCell<JSWritableStreamDefaultControllerPrototype>(vm)) JSWritableStreamDefaultControllerPrototype(vm, structure);
ptr->finishCreation(vm, globalObject);
return ptr;
}
void JSWritableStreamDefaultControllerPrototype::finishCreation(JSC::VM& vm, JSC::JSGlobalObject* globalObject)
{
Base::finishCreation(vm);
reifyStaticProperties(vm, JSWritableStreamDefaultController::info(), JSWritableStreamDefaultControllerPrototypeTableValues, *this);
JSC_TO_STRING_TAG_WITHOUT_TRANSITION();
}
const JSC::ClassInfo JSWritableStreamDefaultControllerPrototype::s_info = {
"WritableStreamDefaultController"_s, &Base::s_info, nullptr, nullptr,
CREATE_METHOD_TABLE(JSWritableStreamDefaultControllerPrototype)
};
} // namespace Bun

View File

@@ -0,0 +1,35 @@
#pragma once
#include "root.h"
namespace Bun {
class JSWritableStreamDefaultControllerPrototype final : public JSC::JSNonFinalObject {
public:
using Base = JSC::JSNonFinalObject;
static JSWritableStreamDefaultControllerPrototype* create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure);
DECLARE_INFO;
template<typename CellType, JSC::SubspaceAccess>
static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm)
{
STATIC_ASSERT_ISO_SUBSPACE_SHARABLE(JSWritableStreamDefaultControllerPrototype, Base);
return &vm.plainObjectSpace();
}
static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
{
return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info());
}
private:
JSWritableStreamDefaultControllerPrototype(JSC::VM& vm, JSC::Structure* structure)
: Base(vm, structure)
{
}
void finishCreation(JSC::VM&, JSC::JSGlobalObject*);
};
} // namespace Bun

View File

@@ -0,0 +1,231 @@
#include "root.h"
#include "JavaScriptCore/JSCJSValue.h"
#include <JavaScriptCore/Lookup.h>
#include "BunWritableStreamDefaultWriter.h"
#include "BunWritableStreamDefaultController.h"
#include "BunWritableStream.h"
#include "JSDOMWrapper.h"
#include "ErrorCode.h"
#include <JavaScriptCore/LazyPropertyInlines.h>
#include "BunPromiseInlines.h"
#include <JavaScriptCore/IteratorOperations.h>
#include <JavaScriptCore/VMTrapsInlines.h>
namespace Bun {
using namespace JSC;
const ClassInfo JSWritableStreamDefaultWriter::s_info = {
"WritableStreamDefaultWriter"_s,
&Base::s_info,
nullptr,
nullptr,
CREATE_METHOD_TABLE(JSWritableStreamDefaultWriter)
};
JSWritableStreamDefaultWriter::JSWritableStreamDefaultWriter(VM& vm, Structure* structure, JSWritableStream* stream)
: Base(vm, structure)
{
}
JSC::GCClient::IsoSubspace* JSWritableStreamDefaultWriter::subspaceForImpl(JSC::VM& vm)
{
return WebCore::subspaceForImpl<JSWritableStreamDefaultWriter, WebCore::UseCustomHeapCellType::No>(
vm,
[](auto& spaces) { return spaces.m_clientSubspaceForWritableStreamDefaultWriter.get(); },
[](auto& spaces, auto&& space) { spaces.m_clientSubspaceForWritableStreamDefaultWriter = std::forward<decltype(space)>(space); },
[](auto& spaces) { return spaces.m_subspaceForWritableStreamDefaultWriter.get(); },
[](auto& spaces, auto&& space) { spaces.m_subspaceForWritableStreamDefaultWriter = std::forward<decltype(space)>(space); });
}
JSC::Structure* JSWritableStreamDefaultWriter::createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
{
return JSC::Structure::create(vm, globalObject, prototype,
JSC::TypeInfo(JSC::ObjectType, StructureFlags), info());
}
JSWritableStreamDefaultWriter* JSWritableStreamDefaultWriter::create(VM& vm, Structure* structure, JSWritableStream* stream)
{
JSWritableStreamDefaultWriter* writer = new (
NotNull,
allocateCell<JSWritableStreamDefaultWriter>(vm)) JSWritableStreamDefaultWriter(vm, structure, stream);
writer->finishCreation(vm);
return writer;
}
static constexpr auto initPendingPromise = [](const JSC::LazyProperty<JSC::JSObject, JSC::JSPromise>::Initializer& init) {
auto* globalObject = init.owner->globalObject();
init.set(JSPromise::create(init.vm, globalObject->promiseStructure()));
};
static constexpr auto initResolvedPromise
= [](const JSC::LazyProperty<JSC::JSObject, JSC::JSPromise>::Initializer& init) {
auto* globalObject = init.owner->globalObject();
init.set(Bun::createFulfilledPromise(globalObject, jsUndefined()));
};
static constexpr auto initEmptyArray = [](const JSC::LazyProperty<JSC::JSObject, JSC::JSArray>::Initializer& init) {
auto* globalObject = init.owner->globalObject();
init.set(JSC::constructEmptyArray(globalObject, static_cast<ArrayAllocationProfile*>(nullptr), 0));
};
void JSWritableStreamDefaultWriter::finishCreation(VM& vm)
{
Base::finishCreation(vm);
ASSERT(inherits(info()));
m_closedPromise.initLater(initPendingPromise);
m_readyPromise.initLater(initPendingPromise);
m_writeRequests.initLater(initEmptyArray);
}
void JSWritableStreamDefaultWriter::error(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue reason)
{
if (auto* stream = this->stream()) {
stream->error(vm, globalObject, reason);
}
}
void JSWritableStreamDefaultWriter::setReady(JSC::VM& vm, JSC::JSPromise* promise)
{
m_readyPromise.set(vm, this, promise);
}
void JSWritableStreamDefaultWriter::resetReadyPromise()
{
if (m_readyPromise.isInitialized()) {
m_readyPromise.setMayBeNull(vm(), this, nullptr);
}
m_readyPromise.initLater(initPendingPromise);
}
void JSWritableStreamDefaultWriter::resolveReadyPromise()
{
if (m_readyPromise.isInitialized()) {
m_readyPromise.get(this)->fulfillWithNonPromise(globalObject(), jsUndefined());
} else {
m_readyPromise.initLater(initResolvedPromise);
}
}
void JSWritableStreamDefaultWriter::resetClosedPromise()
{
if (m_closedPromise.isInitialized()) {
m_closedPromise.setMayBeNull(vm(), this, nullptr);
}
m_closedPromise.initLater(initPendingPromise);
}
void JSWritableStreamDefaultWriter::setClosed(JSC::VM& vm, JSC::JSPromise* promise)
{
m_closedPromise.set(vm, this, promise);
}
template<typename Visitor>
void JSWritableStreamDefaultWriter::visitChildrenImpl(JSCell* cell, Visitor& visitor)
{
auto* writer = jsCast<JSWritableStreamDefaultWriter*>(cell);
ASSERT_GC_OBJECT_INHERITS(writer, info());
Base::visitChildren(writer, visitor);
visitor.append(writer->m_stream);
writer->m_closedPromise.visit(visitor);
writer->m_readyPromise.visit(visitor);
writer->m_writeRequests.visit(visitor);
}
DEFINE_VISIT_CHILDREN(JSWritableStreamDefaultWriter);
double JSWritableStreamDefaultWriter::desiredSize()
{
auto* stream = this->stream();
if (!stream) {
return 0;
}
auto* controller = stream->controller();
if (!controller) {
return 0;
}
return controller->getDesiredSize();
}
// Non-JS Methods for C++ Use
#define CHECK_STREAM() \
if (!m_stream) { \
Bun::throwError(globalObject, scope, Bun::ErrorCode::ERR_INVALID_STATE, "WritableStreamDefaultWriter has no associated stream"_s); \
return; \
}
void JSWritableStreamDefaultWriter::write(JSGlobalObject* globalObject, JSValue chunk)
{
auto scope = DECLARE_THROW_SCOPE(globalObject->vm());
CHECK_STREAM();
m_stream->controller()->write(globalObject, chunk);
}
void JSWritableStreamDefaultWriter::rejectWriteRequests(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSValue error)
{
// a. Let writeRequests be writer.[[writeRequests]].
// b. Set writer.[[writeRequests]] to an empty List.
// c. For each writeRequest of writeRequests,
// 1. Reject writeRequest with stream.[[storedError]].
if (m_writeRequests.isInitialized()) {
auto* writeRequests = m_writeRequests.get(this);
JSC::EnsureStillAliveScope ensureStillAlive(writeRequests);
m_writeRequests.setMayBeNull(vm, this, nullptr);
m_writeRequests.initLater(initEmptyArray);
JSC::forEachInIterable(globalObject, writeRequests, [error](JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue writeRequest) {
jsCast<JSPromise*>(writeRequest)->reject(globalObject, error);
});
}
}
void JSWritableStreamDefaultWriter::close(JSGlobalObject* globalObject)
{
auto scope = DECLARE_THROW_SCOPE(globalObject->vm());
CHECK_STREAM();
m_stream->close(globalObject);
}
void JSWritableStreamDefaultWriter::abort(JSGlobalObject* globalObject, JSValue reason)
{
auto scope = DECLARE_THROW_SCOPE(globalObject->vm());
CHECK_STREAM();
m_stream->abort(globalObject, reason);
}
void JSWritableStreamDefaultWriter::release()
{
m_stream.clear();
if (m_closedPromise.isInitialized())
m_closedPromise.get(this)->rejectAsHandled(globalObject(), jsUndefined());
if (m_readyPromise.isInitialized())
m_readyPromise.get(this)->rejectAsHandled(globalObject(), jsUndefined());
}
void JSWritableStreamDefaultWriter::resolveClosedPromise(JSGlobalObject* globalObject, JSValue value)
{
if (m_closedPromise.isInitialized())
m_closedPromise.get(this)->resolve(globalObject, value);
}
void JSWritableStreamDefaultWriter::rejectClosedPromise(JSGlobalObject* globalObject, JSValue error)
{
if (m_closedPromise.isInitialized())
m_closedPromise.get(this)->rejectAsHandled(globalObject, error);
}
} // namespace Bun

View File

@@ -0,0 +1,68 @@
#pragma once
#include "root.h"
#include <JavaScriptCore/JSPromise.h>
#include <JavaScriptCore/JSObject.h>
#include <JavaScriptCore/JSArray.h>
#include <JavaScriptCore/LazyProperty.h>
namespace Bun {
class JSWritableStream;
class JSWritableStreamDefaultWriter final : public JSC::JSNonFinalObject {
public:
using Base = JSC::JSNonFinalObject;
static JSWritableStreamDefaultWriter* create(JSC::VM&, JSC::Structure*, JSWritableStream*);
template<typename, JSC::SubspaceAccess mode>
static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm)
{
if constexpr (mode == JSC::SubspaceAccess::Concurrently)
return nullptr;
return subspaceForImpl(vm);
}
static JSC::GCClient::IsoSubspace* subspaceForImpl(JSC::VM& vm);
static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype);
DECLARE_INFO;
DECLARE_VISIT_CHILDREN;
// JavaScript-visible properties
JSC::JSPromise* closed() { return m_closedPromise.get(this); }
JSC::JSPromise* ready() { return m_readyPromise.get(this); }
double desiredSize();
void resolveClosedPromise(JSC::JSGlobalObject* globalObject, JSC::JSValue value);
void rejectClosedPromise(JSC::JSGlobalObject* globalObject, JSC::JSValue error);
void rejectWriteRequests(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue reason);
void setReady(JSC::VM& vm, JSC::JSPromise* promise);
void setClosed(JSC::VM& vm, JSC::JSPromise* promise);
void error(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue reason);
void error(JSC::JSGlobalObject* globalObject, JSC::JSValue reason) { this->error(this->vm(), globalObject, reason); }
// Internal APIs for C++ use
JSWritableStream* stream() const { return m_stream.get(); }
void release(); // For releaseLock()
void write(JSC::JSGlobalObject*, JSC::JSValue chunk);
void abort(JSC::JSGlobalObject*, JSC::JSValue reason = JSC::jsUndefined());
void close(JSC::JSGlobalObject*);
void resetReadyPromise();
void resetClosedPromise();
void resolveReadyPromise();
protected:
JSWritableStreamDefaultWriter(JSC::VM&, JSC::Structure*, JSWritableStream*);
void finishCreation(JSC::VM&);
private:
mutable JSC::WriteBarrier<JSWritableStream> m_stream;
JSC::LazyProperty<JSC::JSObject, JSC::JSPromise> m_closedPromise;
JSC::LazyProperty<JSC::JSObject, JSC::JSPromise> m_readyPromise;
JSC::LazyProperty<JSC::JSObject, JSC::JSArray> m_writeRequests;
};
} // namespace Bun

View File

@@ -0,0 +1,89 @@
#include "BunWritableStreamDefaultWriterConstructor.h"
#include "BunWritableStreamDefaultWriterPrototype.h"
#include "BunWritableStreamDefaultWriter.h"
#include "BunWritableStream.h"
#include "JavaScriptCore/InternalFunction.h"
#include "ZigGlobalObject.h"
#include <JavaScriptCore/FunctionPrototype.h>
namespace Bun {
using namespace JSC;
const ClassInfo JSWritableStreamDefaultWriterConstructor::s_info = {
"Function"_s,
&Base::s_info,
nullptr,
nullptr,
CREATE_METHOD_TABLE(JSWritableStreamDefaultWriterConstructor)
};
JSWritableStreamDefaultWriterConstructor::JSWritableStreamDefaultWriterConstructor(VM& vm, Structure* structure)
: Base(vm, structure, call, construct)
{
}
void JSWritableStreamDefaultWriterConstructor::finishCreation(VM& vm, JSGlobalObject* globalObject, JSWritableStreamDefaultWriterPrototype* prototype)
{
Base::finishCreation(vm, 1, "WritableStreamDefaultWriter"_s, PropertyAdditionMode::WithStructureTransition);
putDirect(vm, vm.propertyNames->prototype, prototype, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly);
ASSERT(inherits(info()));
}
JSWritableStreamDefaultWriterConstructor* JSWritableStreamDefaultWriterConstructor::create(VM& vm, JSGlobalObject* globalObject, JSWritableStreamDefaultWriterPrototype* prototype)
{
auto* structure = createStructure(vm, globalObject, globalObject->functionPrototype());
JSWritableStreamDefaultWriterConstructor* constructor = new (NotNull, allocateCell<JSWritableStreamDefaultWriterConstructor>(vm)) JSWritableStreamDefaultWriterConstructor(vm, structure);
constructor->finishCreation(vm, globalObject, prototype);
return constructor;
}
// This is called when constructing a new writer with new WritableStreamDefaultWriter(stream)
EncodedJSValue JSC_HOST_CALL_ATTRIBUTES JSWritableStreamDefaultWriterConstructor::construct(JSGlobalObject* lexicalGlobalObject, CallFrame* callFrame)
{
VM& vm = lexicalGlobalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
if (!callFrame->argumentCount()) {
throwTypeError(lexicalGlobalObject, scope, "WritableStreamDefaultWriter constructor requires a WritableStream argument"_s);
return encodedJSValue();
}
JSValue streamValue = callFrame->argument(0);
JSWritableStream* stream = jsDynamicCast<JSWritableStream*>(streamValue);
if (!stream) {
throwTypeError(lexicalGlobalObject, scope, "WritableStreamDefaultWriter constructor argument must be a WritableStream"_s);
return encodedJSValue();
}
// Check if stream is locked
if (stream->isLocked()) {
throwTypeError(lexicalGlobalObject, scope, "Cannot construct a WritableStreamDefaultWriter for a locked WritableStream"_s);
return encodedJSValue();
}
auto* domGlobalObject = defaultGlobalObject(lexicalGlobalObject);
auto& streams = domGlobalObject->streams();
Structure* structure = streams.structure<JSWritableStreamDefaultWriter>(domGlobalObject);
JSValue newTarget = callFrame->newTarget();
if (UNLIKELY(streams.constructor<JSWritableStream>(lexicalGlobalObject) != newTarget)) {
RETURN_IF_EXCEPTION(scope, {});
structure = InternalFunction::createSubclassStructure(
lexicalGlobalObject, newTarget.getObject(), structure);
RETURN_IF_EXCEPTION(scope, {});
}
JSWritableStreamDefaultWriter* writer = JSWritableStreamDefaultWriter::create(vm, structure, stream);
return JSValue::encode(writer);
}
// This handles direct calls to WritableStreamDefaultWriter as a function, which should throw an error
EncodedJSValue JSC_HOST_CALL_ATTRIBUTES JSWritableStreamDefaultWriterConstructor::call(JSGlobalObject* globalObject, CallFrame*)
{
VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
return throwVMTypeError(globalObject, scope, "WritableStreamDefaultWriter constructor cannot be called as a function"_s);
}
} // namespace Bun

View File

@@ -0,0 +1,36 @@
#pragma once
#include "root.h"
#include <JavaScriptCore/InternalFunction.h>
namespace Bun {
class JSWritableStreamDefaultWriterPrototype;
class JSWritableStreamDefaultWriterConstructor final : public JSC::InternalFunction {
public:
using Base = JSC::InternalFunction;
static JSWritableStreamDefaultWriterConstructor* create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSWritableStreamDefaultWriterPrototype* prototype);
DECLARE_INFO;
template<typename, JSC::SubspaceAccess mode>
static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm)
{
return &vm.internalFunctionSpace();
}
static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
{
return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::InternalFunctionType, StructureFlags), info());
}
private:
JSWritableStreamDefaultWriterConstructor(JSC::VM&, JSC::Structure*);
void finishCreation(JSC::VM&, JSC::JSGlobalObject*, JSWritableStreamDefaultWriterPrototype*);
static JSC::EncodedJSValue JSC_HOST_CALL_ATTRIBUTES construct(JSC::JSGlobalObject*, JSC::CallFrame*);
static JSC::EncodedJSValue JSC_HOST_CALL_ATTRIBUTES call(JSC::JSGlobalObject*, JSC::CallFrame*);
};
} // namespace Bun

View File

@@ -0,0 +1,176 @@
#include "BunWritableStreamDefaultWriterPrototype.h"
#include "BunWritableStreamDefaultWriter.h"
#include "JSDOMWrapper.h"
namespace Bun {
using namespace JSC;
static JSC_DECLARE_CUSTOM_GETTER(jsWritableStreamDefaultWriterClosedGetter);
static JSC_DECLARE_CUSTOM_GETTER(jsWritableStreamDefaultWriterReadyGetter);
static JSC_DECLARE_CUSTOM_GETTER(jsWritableStreamDefaultWriterDesiredSizeGetter);
static JSC_DECLARE_HOST_FUNCTION(jsWritableStreamDefaultWriterWrite);
static JSC_DECLARE_HOST_FUNCTION(jsWritableStreamDefaultWriterAbort);
static JSC_DECLARE_HOST_FUNCTION(jsWritableStreamDefaultWriterClose);
static JSC_DECLARE_HOST_FUNCTION(jsWritableStreamDefaultWriterReleaseLock);
// Property attributes for standard WritableStreamDefaultWriter prototype properties
static const unsigned ProtoAccessorDontDelete = PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly | PropertyAttribute::CustomAccessor;
static const unsigned ProtoFunctionDontEnum = PropertyAttribute::DontEnum | PropertyAttribute::Function;
// Table of prototype properties and methods
static const HashTableValue JSWritableStreamDefaultWriterPrototypeTableValues[] = {
{ "closed"_s, ProtoAccessorDontDelete, NoIntrinsic,
{ HashTableValue::GetterSetterType, jsWritableStreamDefaultWriterClosedGetter, nullptr } },
{ "ready"_s, ProtoAccessorDontDelete, NoIntrinsic,
{ HashTableValue::GetterSetterType, jsWritableStreamDefaultWriterReadyGetter, nullptr } },
{ "desiredSize"_s, ProtoAccessorDontDelete, NoIntrinsic,
{ HashTableValue::GetterSetterType, jsWritableStreamDefaultWriterDesiredSizeGetter, nullptr } },
{ "write"_s, ProtoFunctionDontEnum, NoIntrinsic,
{ HashTableValue::NativeFunctionType, jsWritableStreamDefaultWriterWrite, 1 } },
{ "abort"_s, ProtoFunctionDontEnum, NoIntrinsic,
{ HashTableValue::NativeFunctionType, jsWritableStreamDefaultWriterAbort, 1 } },
{ "close"_s, ProtoFunctionDontEnum, NoIntrinsic,
{ HashTableValue::NativeFunctionType, jsWritableStreamDefaultWriterClose, 0 } },
{ "releaseLock"_s, ProtoFunctionDontEnum, NoIntrinsic,
{ HashTableValue::NativeFunctionType, jsWritableStreamDefaultWriterReleaseLock, 0 } },
};
const ClassInfo JSWritableStreamDefaultWriterPrototype::s_info = {
"WritableStreamDefaultWriter"_s,
&Base::s_info,
nullptr,
nullptr,
CREATE_METHOD_TABLE(JSWritableStreamDefaultWriterPrototype)
};
JSWritableStreamDefaultWriterPrototype* JSWritableStreamDefaultWriterPrototype::create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure)
{
JSWritableStreamDefaultWriterPrototype* ptr = new (NotNull, JSC::allocateCell<JSWritableStreamDefaultWriterPrototype>(vm)) JSWritableStreamDefaultWriterPrototype(vm, structure);
ptr->finishCreation(vm, globalObject);
return ptr;
}
void JSWritableStreamDefaultWriterPrototype::finishCreation(VM& vm, JSGlobalObject* globalObject)
{
Base::finishCreation(vm);
reifyStaticProperties(vm, info(), JSWritableStreamDefaultWriterPrototypeTableValues, *this);
JSC_TO_STRING_TAG_WITHOUT_TRANSITION();
}
// Getter implementations
JSC_DEFINE_CUSTOM_GETTER(jsWritableStreamDefaultWriterClosedGetter, (JSGlobalObject * globalObject, EncodedJSValue thisValue, PropertyName))
{
VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
auto* writer = jsDynamicCast<JSWritableStreamDefaultWriter*>(JSValue::decode(thisValue));
if (!writer) {
throwTypeError(globalObject, scope, "Not a WritableStreamDefaultWriter"_s);
return encodedJSValue();
}
return JSValue::encode(writer->closed());
}
JSC_DEFINE_CUSTOM_GETTER(jsWritableStreamDefaultWriterReadyGetter, (JSGlobalObject * globalObject, EncodedJSValue thisValue, PropertyName))
{
VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
auto* writer = jsDynamicCast<JSWritableStreamDefaultWriter*>(JSValue::decode(thisValue));
if (!writer) {
throwTypeError(globalObject, scope, "Not a WritableStreamDefaultWriter"_s);
return encodedJSValue();
}
return JSValue::encode(writer->ready());
}
JSC_DEFINE_CUSTOM_GETTER(jsWritableStreamDefaultWriterDesiredSizeGetter, (JSGlobalObject * globalObject, EncodedJSValue thisValue, PropertyName))
{
VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
auto* writer = jsDynamicCast<JSWritableStreamDefaultWriter*>(JSValue::decode(thisValue));
if (!writer) {
throwTypeError(globalObject, scope, "Not a WritableStreamDefaultWriter"_s);
return encodedJSValue();
}
return JSValue::encode(jsNumber(writer->desiredSize()));
}
// Method implementations
JSC_DEFINE_HOST_FUNCTION(jsWritableStreamDefaultWriterWrite, (JSGlobalObject * globalObject, CallFrame* callFrame))
{
VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
JSWritableStreamDefaultWriter* writer = jsDynamicCast<JSWritableStreamDefaultWriter*>(callFrame->thisValue());
if (!writer) {
scope.throwException(globalObject,
createTypeError(globalObject, "Not a WritableStreamDefaultWriter"_s));
return {};
}
JSValue chunk = callFrame->argument(0);
writer->write(globalObject, chunk);
return JSValue::encode(jsUndefined());
}
JSC_DEFINE_HOST_FUNCTION(jsWritableStreamDefaultWriterClose, (JSGlobalObject * globalObject, CallFrame* callFrame))
{
VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
JSWritableStreamDefaultWriter* writer = jsDynamicCast<JSWritableStreamDefaultWriter*>(callFrame->thisValue());
if (!writer) {
scope.throwException(globalObject,
createTypeError(globalObject, "Not a WritableStreamDefaultWriter"_s));
return {};
}
writer->close(globalObject);
return JSValue::encode(jsUndefined());
}
JSC_DEFINE_HOST_FUNCTION(jsWritableStreamDefaultWriterAbort, (JSGlobalObject * globalObject, CallFrame* callFrame))
{
VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
JSWritableStreamDefaultWriter* writer = jsDynamicCast<JSWritableStreamDefaultWriter*>(callFrame->thisValue());
if (!writer) {
scope.throwException(globalObject,
createTypeError(globalObject, "Not a WritableStreamDefaultWriter"_s));
return {};
}
JSValue reason = callFrame->argument(0);
writer->abort(globalObject, reason);
return JSValue::encode(jsUndefined());
}
JSC_DEFINE_HOST_FUNCTION(jsWritableStreamDefaultWriterReleaseLock, (JSGlobalObject * globalObject, CallFrame* callFrame))
{
VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
JSWritableStreamDefaultWriter* writer = jsDynamicCast<JSWritableStreamDefaultWriter*>(callFrame->thisValue());
if (!writer) {
scope.throwException(globalObject,
createTypeError(globalObject, "Not a WritableStreamDefaultWriter"_s));
return {};
}
writer->release();
return JSValue::encode(jsUndefined());
}
} // namespace Bun

View File

@@ -0,0 +1,37 @@
#pragma once
#include "root.h"
#include <JavaScriptCore/JSObject.h>
namespace Bun {
class JSWritableStreamDefaultWriterPrototype final : public JSC::JSNonFinalObject {
public:
using Base = JSC::JSNonFinalObject;
static JSWritableStreamDefaultWriterPrototype* create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure);
DECLARE_INFO;
template<typename CellType, JSC::SubspaceAccess>
static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm)
{
STATIC_ASSERT_ISO_SUBSPACE_SHARABLE(JSWritableStreamDefaultWriterPrototype, Base);
return &vm.plainObjectSpace();
}
static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
{
return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info());
}
private:
JSWritableStreamDefaultWriterPrototype(JSC::VM& vm, JSC::Structure* structure)
: Base(vm, structure)
{
}
void finishCreation(JSC::VM&, JSC::JSGlobalObject*);
};
} // namespace Bun

View File

@@ -0,0 +1,119 @@
#include "BunWritableStreamPrototype.h"
#include "BunWritableStream.h"
#include "BunWritableStreamDefaultController.h"
#include "BunWritableStreamDefaultWriter.h"
#include "ZigGlobalObject.h"
namespace Bun {
using namespace JSC;
// JSWritableStreamPrototype bindings
JSC_DEFINE_HOST_FUNCTION(jsWritableStreamPrototypeFunction_abort, (JSGlobalObject * globalObject, CallFrame* callFrame))
{
VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
JSWritableStream* stream = jsDynamicCast<JSWritableStream*>(callFrame->thisValue());
if (!stream)
return throwVMTypeError(globalObject, scope, "WritableStream.prototype.abort called on non-WritableStream object"_s);
JSValue reason = callFrame->argument(0);
return JSValue::encode(stream->abort(globalObject, reason));
}
JSC_DEFINE_HOST_FUNCTION(jsWritableStreamPrototypeFunction_close, (JSGlobalObject * globalObject, CallFrame* callFrame))
{
VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
JSWritableStream* stream = jsDynamicCast<JSWritableStream*>(callFrame->thisValue());
if (!stream)
return throwVMTypeError(globalObject, scope, "WritableStream.prototype.close called on non-WritableStream object"_s);
return JSValue::encode(stream->close(globalObject));
}
JSC_DEFINE_HOST_FUNCTION(jsWritableStreamPrototypeFunction_getWriter, (JSGlobalObject * globalObject, CallFrame* callFrame))
{
VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
JSWritableStream* stream = jsDynamicCast<JSWritableStream*>(callFrame->thisValue());
if (!stream)
return throwVMTypeError(globalObject, scope, "WritableStream.prototype.getWriter called on non-WritableStream object"_s);
if (stream->isLocked())
return throwVMTypeError(globalObject, scope, "Cannot get writer for locked WritableStream"_s);
auto* domGlobalObject = defaultGlobalObject(globalObject);
auto& streams = domGlobalObject->streams();
Structure* writerStructure = streams.structure<JSWritableStreamDefaultWriter>(domGlobalObject);
auto* writer = JSWritableStreamDefaultWriter::create(vm, writerStructure, stream);
RETURN_IF_EXCEPTION(scope, {});
stream->setWriter(vm, writer);
return JSValue::encode(writer);
}
JSC_DEFINE_CUSTOM_GETTER(jsWritableStreamPrototypeLockedGetter, (JSGlobalObject * globalObject, EncodedJSValue thisValue, PropertyName))
{
VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
JSWritableStream* stream = jsDynamicCast<JSWritableStream*>(JSValue::decode(thisValue));
if (!stream)
return throwVMTypeError(globalObject, scope, "WritableStream.prototype.locked called on non-WritableStream object"_s);
return JSValue::encode(jsBoolean(stream->isLocked()));
}
// Static hash table of properties
static const HashTableValue JSWritableStreamPrototypeTableValues[] = {
{ "abort"_s,
static_cast<unsigned>(PropertyAttribute::Function),
NoIntrinsic,
{ HashTableValue::NativeFunctionType, jsWritableStreamPrototypeFunction_abort, 1 } },
{ "close"_s,
static_cast<unsigned>(PropertyAttribute::Function),
NoIntrinsic,
{ HashTableValue::NativeFunctionType, jsWritableStreamPrototypeFunction_close, 0 } },
{ "getWriter"_s,
static_cast<unsigned>(PropertyAttribute::Function),
NoIntrinsic,
{ HashTableValue::NativeFunctionType, jsWritableStreamPrototypeFunction_getWriter, 0 } },
{ "locked"_s,
static_cast<unsigned>(PropertyAttribute::CustomAccessor | PropertyAttribute::ReadOnly),
NoIntrinsic,
{ HashTableValue::GetterSetterType, jsWritableStreamPrototypeLockedGetter, nullptr } }
};
// Prototype Implementation
const ClassInfo JSWritableStreamPrototype::s_info = { "WritableStream"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSWritableStreamPrototype) };
JSWritableStreamPrototype* JSWritableStreamPrototype::create(VM& vm, JSGlobalObject* globalObject, Structure* structure)
{
auto* prototype = new (NotNull, allocateCell<JSWritableStreamPrototype>(vm)) JSWritableStreamPrototype(vm, structure);
prototype->finishCreation(vm, globalObject);
return prototype;
}
JSWritableStreamPrototype::JSWritableStreamPrototype(VM& vm, Structure* structure)
: Base(vm, structure)
{
}
void JSWritableStreamPrototype::finishCreation(VM& vm, JSGlobalObject* globalObject)
{
Base::finishCreation(vm);
reifyStaticProperties(vm, JSWritableStream::info(), JSWritableStreamPrototypeTableValues, *this);
JSC_TO_STRING_TAG_WITHOUT_TRANSITION();
}
Structure* JSWritableStreamPrototype::createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
{
return Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info());
}
} // namespace Bun

View File

@@ -0,0 +1,30 @@
#pragma once
#include "root.h"
#include "BunStreamStructures.h"
namespace Bun {
using namespace JSC;
class JSWritableStreamPrototype final : public JSNonFinalObject {
public:
using Base = JSNonFinalObject;
static JSWritableStreamPrototype* create(VM& vm, JSGlobalObject* globalObject, Structure* structure);
static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype);
DECLARE_INFO;
template<typename CellType, SubspaceAccess>
static GCClient::IsoSubspace* subspaceFor(VM& vm)
{
STATIC_ASSERT_ISO_SUBSPACE_SHARABLE(JSWritableStreamPrototype, Base);
return &vm.plainObjectSpace();
}
private:
JSWritableStreamPrototype(VM& vm, Structure* structure);
void finishCreation(VM& vm, JSGlobalObject* globalObject);
};
} // namespace Bun

View File

@@ -27,6 +27,7 @@
#include "BunPlugin.h"
#include "AsyncContextFrame.h"
#include "ErrorCode.h"
#include "BunPromiseInlines.h"
BUN_DECLARE_HOST_FUNCTION(JSMock__jsUseFakeTimers);
BUN_DECLARE_HOST_FUNCTION(JSMock__jsUseRealTimers);
@@ -1180,7 +1181,7 @@ JSC_DEFINE_HOST_FUNCTION(jsMockFunctionMockResolvedValue, (JSC::JSGlobalObject *
auto scope = DECLARE_THROW_SCOPE(vm);
CHECK_IS_MOCK_FUNCTION(thisValue);
pushImpl(thisObject, globalObject, JSMockImplementation::Kind::ReturnValue, JSC::JSPromise::resolvedPromise(globalObject, callframe->argument(0)));
pushImpl(thisObject, globalObject, JSMockImplementation::Kind::ReturnValue, Bun::createFulfilledPromise(globalObject, callframe->argument(0)));
RELEASE_AND_RETURN(scope, JSValue::encode(thisObject));
}
@@ -1193,7 +1194,7 @@ JSC_DEFINE_HOST_FUNCTION(jsMockFunctionMockResolvedValueOnce, (JSC::JSGlobalObje
auto scope = DECLARE_THROW_SCOPE(vm);
CHECK_IS_MOCK_FUNCTION(thisValue);
pushImplOnce(thisObject, globalObject, JSMockImplementation::Kind::ReturnValue, JSC::JSPromise::resolvedPromise(globalObject, callframe->argument(0)));
pushImplOnce(thisObject, globalObject, JSMockImplementation::Kind::ReturnValue, Bun::createFulfilledPromise(globalObject, callframe->argument(0)));
RELEASE_AND_RETURN(scope, JSValue::encode(thisObject));
}

View File

@@ -1,7 +1,9 @@
#include "root.h"
#include "ZigGlobalObject.h"
#include "helpers.h"
#include "JavaScriptCore/ArgList.h"
#include "JSDOMGuardedObject.h"
#include "JavaScriptCore/JSImmutableButterfly.h"
#include "wtf/text/Base64.h"
#include "JavaScriptCore/BuiltinNames.h"
@@ -14,6 +16,7 @@
#include "JavaScriptCore/Error.h"
#include "JavaScriptCore/ErrorInstance.h"
#include "JavaScriptCore/Exception.h"
#include "JSDOMConvert.h"
#include "JavaScriptCore/ExceptionScope.h"
#include "JavaScriptCore/FunctionConstructor.h"
#include "JavaScriptCore/FunctionPrototype.h"
@@ -78,6 +81,7 @@
#include "JSByteLengthQueuingStrategy.h"
#include "JSCloseEvent.h"
#include "JSCountQueuingStrategy.h"
#include "JSCustomEvent.h"
#include "JSDOMConvertBase.h"
#include "JSDOMConvertUnion.h"
@@ -103,12 +107,12 @@
#include "JSPerformanceMeasure.h"
#include "JSPerformanceObserver.h"
#include "JSPerformanceObserverEntryList.h"
#include "JSReadableByteStreamController.h"
#include "JSReadableStream.h"
#include "JSReadableStreamBYOBReader.h"
#include "JSReadableStreamBYOBRequest.h"
#include "JSReadableStreamDefaultController.h"
#include "JSReadableStreamDefaultReader.h"
// #include "JSReadableByteStreamController.h"
#include "BunReadableStream.h"
#include "BunReadableStreamBYOBReader.h"
// #include "BunReadableStreamBYOBRequest.h"
#include "BunReadableStreamDefaultController.h"
#include "BunReadableStreamDefaultReader.h"
#include "JSSink.h"
#include "JSSocketAddress.h"
#include "JSSQLStatement.h"
@@ -116,14 +120,14 @@
#include "JSTextEncoder.h"
#include "JSTextEncoderStream.h"
#include "JSTextDecoderStream.h"
#include "JSTransformStream.h"
#include "JSTransformStreamDefaultController.h"
#include "BunTransformStream.h"
#include "BunTransformStreamDefaultController.h"
#include "JSURLSearchParams.h"
#include "JSWebSocket.h"
#include "JSWorker.h"
#include "JSWritableStream.h"
#include "JSWritableStreamDefaultController.h"
#include "JSWritableStreamDefaultWriter.h"
#include "BunWritableStream.h"
#include "BunWritableStreamDefaultController.h"
#include "BunWritableStreamDefaultWriter.h"
#include "libusockets.h"
#include "ModuleLoader.h"
#include "napi_external.h"
@@ -136,7 +140,6 @@
#include "ProcessBindingConstants.h"
#include "ProcessBindingTTYWrap.h"
#include "ProcessIdentifier.h"
#include "ReadableStream.h"
#include "SerializedScriptValue.h"
#include "StructuredClone.h"
#include "WebCoreJSBuiltins.h"
@@ -155,6 +158,7 @@
#include "JSPerformanceServerTiming.h"
#include "JSPerformanceResourceTiming.h"
#include "JSPerformanceTiming.h"
#include "IDLTypes.h"
#if ENABLE(REMOTE_INSPECTOR)
#include "JavaScriptCore/RemoteInspectorServer.h"
@@ -1385,24 +1389,30 @@ WEBCORE_GENERATED_CONSTRUCTOR_GETTER(PerformanceObserverEntryList)
WEBCORE_GENERATED_CONSTRUCTOR_GETTER(PerformanceResourceTiming)
WEBCORE_GENERATED_CONSTRUCTOR_GETTER(PerformanceServerTiming)
WEBCORE_GENERATED_CONSTRUCTOR_GETTER(PerformanceTiming)
WEBCORE_GENERATED_CONSTRUCTOR_GETTER(ReadableByteStreamController)
WEBCORE_GENERATED_CONSTRUCTOR_GETTER(ReadableStream)
WEBCORE_GENERATED_CONSTRUCTOR_GETTER(ReadableStreamBYOBReader)
WEBCORE_GENERATED_CONSTRUCTOR_GETTER(ReadableStreamBYOBRequest)
WEBCORE_GENERATED_CONSTRUCTOR_GETTER(ReadableStreamDefaultController)
WEBCORE_GENERATED_CONSTRUCTOR_GETTER(ReadableStreamDefaultReader)
// WEBCORE_GENERATED_CONSTRUCTOR_GETTER(ReadableByteStreamController)
WEBCORE_GENERATED_CONSTRUCTOR_GETTER(SubtleCrypto);
WEBCORE_GENERATED_CONSTRUCTOR_GETTER(TextEncoder);
WEBCORE_GENERATED_CONSTRUCTOR_GETTER(TextEncoderStream);
WEBCORE_GENERATED_CONSTRUCTOR_GETTER(TextDecoderStream);
WEBCORE_GENERATED_CONSTRUCTOR_GETTER(TransformStream)
WEBCORE_GENERATED_CONSTRUCTOR_GETTER(TransformStreamDefaultController)
WEBCORE_GENERATED_CONSTRUCTOR_GETTER(URLSearchParams);
WEBCORE_GENERATED_CONSTRUCTOR_GETTER(WebSocket);
WEBCORE_GENERATED_CONSTRUCTOR_GETTER(Worker);
WEBCORE_GENERATED_CONSTRUCTOR_GETTER(WritableStream);
WEBCORE_GENERATED_CONSTRUCTOR_GETTER(WritableStreamDefaultController);
WEBCORE_GENERATED_CONSTRUCTOR_GETTER(WritableStreamDefaultWriter);
#define WHATWG_STREAM_CONSTRUCTOR_GETTER(ConstructorName) \
JSValue ConstructorName##ConstructorCallback(VM& vm, JSObject* lexicalGlobalObject) \
{ \
auto* thisObject = jsCast<Zig::GlobalObject*>(lexicalGlobalObject); \
return thisObject->streams().constructor<ConstructorName>(jsCast<JSC::JSGlobalObject*>(lexicalGlobalObject)); \
} \
JSC_DEFINE_CUSTOM_GETTER(ConstructorName##_getter, \
(JSC::JSGlobalObject * lexicalGlobalObject, JSC::EncodedJSValue thisValue, \
JSC::PropertyName)) \
{ \
return JSC::JSValue::encode(jsCast<Zig::GlobalObject*>(lexicalGlobalObject)->streams().constructor<ConstructorName>(lexicalGlobalObject)); \
}
FOR_EACH_WHATWG_STREAM_CLASS_TYPE(WHATWG_STREAM_CONSTRUCTOR_GETTER)
#undef WHATWG_STREAM_CONSTRUCTOR_GETTER
JSC_DEFINE_HOST_FUNCTION(functionGetSelf,
(JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame))
@@ -2065,10 +2075,10 @@ JSC_DEFINE_HOST_FUNCTION(getInternalWritableStream, (JSGlobalObject*, CallFrame*
ASSERT(callFrame);
ASSERT(callFrame->argumentCount() == 1);
auto* writableStream = jsDynamicCast<JSWritableStream*>(callFrame->uncheckedArgument(0));
if (UNLIKELY(!writableStream))
return JSValue::encode(jsUndefined());
return JSValue::encode(writableStream->wrapped().internalWritableStream());
// auto* writableStream = jsDynamicCast<JSWritableStream*>(callFrame->uncheckedArgument(0));
// if (UNLIKELY(!writableStream))
return JSValue::encode(jsUndefined());
// return JSValue::encode(writableStream->wrapped().internalWritableStream());
}
JSC_DEFINE_HOST_FUNCTION(createWritableStreamFromInternal, (JSGlobalObject * globalObject, CallFrame* callFrame))
@@ -2077,9 +2087,10 @@ JSC_DEFINE_HOST_FUNCTION(createWritableStreamFromInternal, (JSGlobalObject * glo
ASSERT(callFrame->argumentCount() == 1);
ASSERT(callFrame->uncheckedArgument(0).isObject());
auto* jsDOMGlobalObject = JSC::jsCast<JSDOMGlobalObject*>(globalObject);
auto internalWritableStream = InternalWritableStream::fromObject(*jsDOMGlobalObject, *callFrame->uncheckedArgument(0).toObject(globalObject));
return JSValue::encode(toJSNewlyCreated(globalObject, jsDOMGlobalObject, WritableStream::create(WTFMove(internalWritableStream))));
return JSValue::encode(jsUndefined());
// auto* jsDOMGlobalObject = JSC::jsCast<JSDOMGlobalObject*>(globalObject);
// auto internalWritableStream = InternalWritableStream::fromObject(*jsDOMGlobalObject, *callFrame->uncheckedArgument(0).toObject(globalObject));
// return JSValue::encode(toJSNewlyCreated(globalObject, jsDOMGlobalObject, WritableStream::create(WTFMove(internalWritableStream))));
}
JSC_DEFINE_HOST_FUNCTION(addAbortAlgorithmToSignal, (JSGlobalObject * globalObject, CallFrame* callFrame))
@@ -2139,174 +2150,177 @@ static inline std::optional<JSC::JSValue> invokeReadableStreamFunction(JSC::JSGl
}
extern "C" bool ReadableStream__tee(JSC__JSValue possibleReadableStream, Zig::GlobalObject* globalObject, JSC__JSValue* possibleReadableStream1, JSC__JSValue* possibleReadableStream2)
{
auto* readableStream = jsDynamicCast<JSReadableStream*>(JSC::JSValue::decode(possibleReadableStream));
if (UNLIKELY(!readableStream))
return false;
// auto* readableStream = jsDynamicCast<JSReadableStream*>(JSC::JSValue::decode(possibleReadableStream));
// if (UNLIKELY(!readableStream))
// return false;
auto& lexicalGlobalObject = *globalObject;
auto* clientData = static_cast<JSVMClientData*>(lexicalGlobalObject.vm().clientData);
auto& privateName = clientData->builtinFunctions().readableStreamInternalsBuiltins().readableStreamTeePrivateName();
// auto& lexicalGlobalObject = *globalObject;
// auto* clientData = static_cast<JSVMClientData*>(lexicalGlobalObject.vm().clientData);
// auto& privateName = clientData->builtinFunctions().readableStreamInternalsBuiltins().readableStreamTeePrivateName();
MarkedArgumentBuffer arguments;
arguments.append(readableStream);
arguments.append(JSC::jsBoolean(true));
ASSERT(!arguments.hasOverflowed());
auto returnedValue = invokeReadableStreamFunction(lexicalGlobalObject, privateName, JSC::jsUndefined(), arguments);
if (!returnedValue)
return false;
// MarkedArgumentBuffer arguments;
// arguments.append(readableStream);
// arguments.append(JSC::jsBoolean(true));
// ASSERT(!arguments.hasOverflowed());
// auto returnedValue = invokeReadableStreamFunction(lexicalGlobalObject, privateName, JSC::jsUndefined(), arguments);
// if (!returnedValue)
return false;
auto results = Detail::SequenceConverter<IDLAny>::convert(lexicalGlobalObject, *returnedValue);
// auto results = Detail::SequenceConverter<IDLAny>::convert(lexicalGlobalObject, *returnedValue);
ASSERT(results.size() == 2);
*possibleReadableStream1 = JSValue::encode(results[0]);
*possibleReadableStream2 = JSValue::encode(results[1]);
return true;
// ASSERT(results.size() == 2);
// *possibleReadableStream1 = JSValue::encode(results[0]);
// *possibleReadableStream2 = JSValue::encode(results[1]);
// return true;
}
extern "C" void ReadableStream__cancel(JSC__JSValue possibleReadableStream, Zig::GlobalObject* globalObject)
{
auto* readableStream = jsDynamicCast<JSReadableStream*>(JSC::JSValue::decode(possibleReadableStream));
if (UNLIKELY(!readableStream))
return;
// auto* readableStream = jsDynamicCast<JSReadableStream*>(JSC::JSValue::decode(possibleReadableStream));
// if (UNLIKELY(!readableStream))
// return;
if (!ReadableStream::isLocked(globalObject, readableStream)) {
return;
}
// if (!ReadableStream::isLocked(globalObject, readableStream)) {
// return;
// }
WebCore::Exception exception { AbortError };
ReadableStream::cancel(*globalObject, readableStream, exception);
// WebCore::Exception exception { AbortError };
// ReadableStream::cancel(*globalObject, readableStream, exception);
}
extern "C" void ReadableStream__detach(JSC__JSValue possibleReadableStream, Zig::GlobalObject* globalObject)
{
auto value = JSC::JSValue::decode(possibleReadableStream);
if (value.isEmpty() || !value.isCell())
return;
// auto value = JSC::JSValue::decode(possibleReadableStream);
// if (value.isEmpty() || !value.isCell())
// return;
auto* readableStream = static_cast<JSReadableStream*>(value.asCell());
if (UNLIKELY(!readableStream))
return;
readableStream->setNativePtr(globalObject->vm(), jsNumber(-1));
readableStream->setNativeType(0);
readableStream->setDisturbed(true);
// auto* readableStream = static_cast<JSReadableStream*>(value.asCell());
// if (UNLIKELY(!readableStream))
// return;
// readableStream->setNativePtr(globalObject->vm(), jsNumber(-1));
// readableStream->setNativeType(0);
// readableStream->setDisturbed(true);
}
extern "C" bool ReadableStream__isDisturbed(JSC__JSValue possibleReadableStream, Zig::GlobalObject* globalObject);
extern "C" bool ReadableStream__isDisturbed(JSC__JSValue possibleReadableStream, Zig::GlobalObject* globalObject)
{
ASSERT(globalObject);
return ReadableStream::isDisturbed(globalObject, jsDynamicCast<WebCore::JSReadableStream*>(JSC::JSValue::decode(possibleReadableStream)));
// return ReadableStream::isDisturbed(globalObject, jsDynamicCast<WebCore::JSReadableStream*>(JSC::JSValue::decode(possibleReadableStream)));
return false;
}
extern "C" bool ReadableStream__isLocked(JSC__JSValue possibleReadableStream, Zig::GlobalObject* globalObject);
extern "C" bool ReadableStream__isLocked(JSC__JSValue possibleReadableStream, Zig::GlobalObject* globalObject)
{
ASSERT(globalObject);
WebCore::JSReadableStream* stream = jsDynamicCast<WebCore::JSReadableStream*>(JSValue::decode(possibleReadableStream));
return stream != nullptr && ReadableStream::isLocked(globalObject, stream);
// WebCore::JSReadableStream* stream = jsDynamicCast<WebCore::JSReadableStream*>(JSValue::decode(possibleReadableStream));
// return stream != nullptr && ReadableStream::isLocked(globalObject, stream);
return false;
}
extern "C" int32_t ReadableStreamTag__tagged(Zig::GlobalObject* globalObject, JSC__JSValue* possibleReadableStream, void** ptr)
{
ASSERT(globalObject);
JSC::JSObject* object = JSValue::decode(*possibleReadableStream).getObject();
if (!object) {
*ptr = nullptr;
return -1;
}
// JSC::JSObject* object = JSValue::decode(*possibleReadableStream).getObject();
// if (!object) {
*ptr = nullptr;
return -1;
// }
auto& vm = globalObject->vm();
// auto& vm = globalObject->vm();
if (!object->inherits<JSReadableStream>()) {
auto throwScope = DECLARE_THROW_SCOPE(vm);
JSValue target = object;
JSValue fn = JSValue();
auto* function = jsDynamicCast<JSC::JSFunction*>(object);
if (function && function->jsExecutable() && function->jsExecutable()->isAsyncGenerator()) {
fn = object;
target = jsUndefined();
} else if (auto iterable = object->getIfPropertyExists(globalObject, vm.propertyNames->asyncIteratorSymbol)) {
if (iterable.isCallable()) {
fn = iterable;
}
}
// if (!object->inherits<JSReadableStream>()) {
// auto throwScope = DECLARE_THROW_SCOPE(vm);
// JSValue target = object;
// JSValue fn = JSValue();
// auto* function = jsDynamicCast<JSC::JSFunction*>(object);
// if (function && function->jsExecutable() && function->jsExecutable()->isAsyncGenerator()) {
// fn = object;
// target = jsUndefined();
// } else if (auto iterable = object->getIfPropertyExists(globalObject, vm.propertyNames->asyncIteratorSymbol)) {
// if (iterable.isCallable()) {
// fn = iterable;
// }
// }
if (UNLIKELY(throwScope.exception())) {
*ptr = nullptr;
return -1;
}
// if (UNLIKELY(throwScope.exception())) {
// *ptr = nullptr;
// return -1;
// }
if (fn.isEmpty()) {
*ptr = nullptr;
return -1;
}
// if (fn.isEmpty()) {
// *ptr = nullptr;
// return -1;
// }
auto* createIterator = globalObject->builtinInternalFunctions().readableStreamInternals().m_readableStreamFromAsyncIteratorFunction.get();
// auto* createIterator = globalObject->builtinInternalFunctions().readableStreamInternals().m_readableStreamFromAsyncIteratorFunction.get();
JSC::MarkedArgumentBuffer arguments;
arguments.append(target);
arguments.append(fn);
// JSC::MarkedArgumentBuffer arguments;
// arguments.append(target);
// arguments.append(fn);
JSC::JSValue result = profiledCall(globalObject, JSC::ProfilingReason::API, createIterator, JSC::getCallData(createIterator), JSC::jsUndefined(), arguments);
// JSC::JSValue result = profiledCall(globalObject, JSC::ProfilingReason::API, createIterator, JSC::getCallData(createIterator), JSC::jsUndefined(), arguments);
if (UNLIKELY(throwScope.exception())) {
return -1;
}
// if (UNLIKELY(throwScope.exception())) {
// return -1;
// }
if (!result.isObject()) {
*ptr = nullptr;
return -1;
}
// if (!result.isObject()) {
// *ptr = nullptr;
// return -1;
// }
object = result.getObject();
// object = result.getObject();
ASSERT(object->inherits<JSReadableStream>());
*possibleReadableStream = JSValue::encode(object);
*ptr = nullptr;
ensureStillAliveHere(object);
return 0;
}
// ASSERT(object->inherits<JSReadableStream>());
// *possibleReadableStream = JSValue::encode(object);
// *ptr = nullptr;
// ensureStillAliveHere(object);
// return 0;
// }
auto* readableStream = jsCast<JSReadableStream*>(object);
// auto* readableStream = jsCast<JSReadableStream*>(object);
JSValue nativePtrHandle = readableStream->nativePtr();
if (nativePtrHandle.isEmpty() || !nativePtrHandle.isCell()) {
*ptr = nullptr;
return 0;
}
// JSValue nativePtrHandle = readableStream->nativePtr();
// if (nativePtrHandle.isEmpty() || !nativePtrHandle.isCell()) {
// *ptr = nullptr;
// return 0;
// }
JSCell* cell = nativePtrHandle.asCell();
// JSCell* cell = nativePtrHandle.asCell();
if (auto* casted = jsDynamicCast<JSBlobInternalReadableStreamSource*>(cell)) {
*ptr = casted->wrapped();
return 1;
}
// if (auto* casted = jsDynamicCast<JSBlobInternalReadableStreamSource*>(cell)) {
// *ptr = casted->wrapped();
// return 1;
// }
if (auto* casted = jsDynamicCast<JSFileInternalReadableStreamSource*>(cell)) {
*ptr = casted->wrapped();
return 2;
}
// if (auto* casted = jsDynamicCast<JSFileInternalReadableStreamSource*>(cell)) {
// *ptr = casted->wrapped();
// return 2;
// }
if (auto* casted = jsDynamicCast<JSBytesInternalReadableStreamSource*>(cell)) {
*ptr = casted->wrapped();
return 4;
}
// if (auto* casted = jsDynamicCast<JSBytesInternalReadableStreamSource*>(cell)) {
// *ptr = casted->wrapped();
// return 4;
// }
return 0;
// return 0;
}
extern "C" JSC__JSValue ZigGlobalObject__createNativeReadableStream(Zig::GlobalObject* globalObject, JSC__JSValue nativePtr)
{
auto& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
// auto& vm = globalObject->vm();
// auto scope = DECLARE_THROW_SCOPE(vm);
auto& builtinNames = WebCore::builtinNames(vm);
// auto& builtinNames = WebCore::builtinNames(vm);
auto function = globalObject->getDirect(vm, builtinNames.createNativeReadableStreamPrivateName()).getObject();
JSC::MarkedArgumentBuffer arguments = JSC::MarkedArgumentBuffer();
arguments.append(JSValue::decode(nativePtr));
// auto function = globalObject->getDirect(vm, builtinNames.createNativeReadableStreamPrivateName()).getObject();
// JSC::MarkedArgumentBuffer arguments = JSC::MarkedArgumentBuffer();
// arguments.append(JSValue::decode(nativePtr));
auto callData = JSC::getCallData(function);
return JSC::JSValue::encode(call(globalObject, function, callData, JSC::jsUndefined(), arguments));
// auto callData = JSC::getCallData(function);
// return JSC::JSValue::encode(call(globalObject, function, callData, JSC::jsUndefined(), arguments));
return JSValue::encode(jsUndefined());
}
extern "C" JSC__JSValue Bun__Jest__createTestModuleObject(JSC::JSGlobalObject*);
@@ -2819,6 +2833,7 @@ void GlobalObject::finishCreation(VM& vm)
m_http2_commongStrings.initialize();
Bun::addNodeModuleConstructorProperties(vm, this);
m_streamStructures.initialize(vm, this);
m_lazyStackCustomGetterSetter.initLater(
[](const Initializer<CustomGetterSetter>& init) {
@@ -3523,26 +3538,26 @@ JSC_DEFINE_HOST_FUNCTION(jsFunctionToClass, (JSC::JSGlobalObject * globalObject,
EncodedJSValue GlobalObject::assignToStream(JSValue stream, JSValue controller)
{
JSC::VM& vm = this->vm();
JSC::JSFunction* function = this->m_assignToStream.get();
if (!function) {
function = JSFunction::create(vm, this, static_cast<JSC::FunctionExecutable*>(readableStreamInternalsAssignToStreamCodeGenerator(vm)), this);
this->m_assignToStream.set(vm, this, function);
}
// JSC::VM& vm = this->vm();
// JSC::JSFunction* function = this->m_assignToStream.get();
// if (!function) {
// function = JSFunction::create(vm, this, static_cast<JSC::FunctionExecutable*>(readableStreamInternalsAssignToStreamCodeGenerator(vm)), this);
// this->m_assignToStream.set(vm, this, function);
// }
auto callData = JSC::getCallData(function);
JSC::MarkedArgumentBuffer arguments;
arguments.append(stream);
arguments.append(controller);
// auto callData = JSC::getCallData(function);
// JSC::MarkedArgumentBuffer arguments;
// arguments.append(stream);
// arguments.append(controller);
WTF::NakedPtr<JSC::Exception> returnedException = nullptr;
// WTF::NakedPtr<JSC::Exception> returnedException = nullptr;
auto result = JSC::profiledCall(this, ProfilingReason::API, function, callData, JSC::jsUndefined(), arguments, returnedException);
if (auto* exception = returnedException.get()) {
return JSC::JSValue::encode(exception);
}
// auto result = JSC::profiledCall(this, ProfilingReason::API, function, callData, JSC::jsUndefined(), arguments, returnedException);
// if (auto* exception = returnedException.get()) {
// return JSC::JSValue::encode(exception);
// }
return JSC::JSValue::encode(result);
return JSC::JSValue::encode(jsUndefined());
}
JSC::JSObject* GlobalObject::navigatorObject()
@@ -3609,11 +3624,11 @@ void GlobalObject::addBuiltinGlobals(JSC::VM& vm)
GlobalPropertyInfo(builtinNames.makeDOMExceptionPrivateName(), JSFunction::create(vm, this, 2, String(), makeDOMExceptionForBuiltins, ImplementationVisibility::Public), PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
GlobalPropertyInfo(builtinNames.addAbortAlgorithmToSignalPrivateName(), JSFunction::create(vm, this, 2, String(), addAbortAlgorithmToSignal, ImplementationVisibility::Public), PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
GlobalPropertyInfo(builtinNames.removeAbortAlgorithmFromSignalPrivateName(), JSFunction::create(vm, this, 2, String(), removeAbortAlgorithmFromSignal, ImplementationVisibility::Public), PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
GlobalPropertyInfo(builtinNames.cloneArrayBufferPrivateName(), JSFunction::create(vm, this, 3, String(), cloneArrayBuffer, ImplementationVisibility::Public), PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
GlobalPropertyInfo(builtinNames.structuredCloneForStreamPrivateName(), JSFunction::create(vm, this, 1, String(), structuredCloneForStream, ImplementationVisibility::Public), PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
GlobalPropertyInfo(builtinNames.cloneArrayBufferPrivateName(), JSFunction::create(vm, this, 3, String(), jsFunctionCloneArrayBuffer, ImplementationVisibility::Public), PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
GlobalPropertyInfo(builtinNames.structuredCloneForStreamPrivateName(), JSFunction::create(vm, this, 1, String(), jsFunctionStructuredCloneForStream, ImplementationVisibility::Public), PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
GlobalPropertyInfo(builtinNames.isAbortSignalPrivateName(), JSFunction::create(vm, this, 1, String(), isAbortSignal, ImplementationVisibility::Public), PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
GlobalPropertyInfo(builtinNames.getInternalWritableStreamPrivateName(), JSFunction::create(vm, this, 1, String(), getInternalWritableStream, ImplementationVisibility::Public), PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
GlobalPropertyInfo(builtinNames.createWritableStreamFromInternalPrivateName(), JSFunction::create(vm, this, 1, String(), createWritableStreamFromInternal, ImplementationVisibility::Public), PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
// GlobalPropertyInfo(builtinNames.getInternalWritableStreamPrivateName(), JSFunction::create(vm, this, 1, String(), getInternalWritableStream, ImplementationVisibility::Public), PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
// GlobalPropertyInfo(builtinNames.createWritableStreamFromInternalPrivateName(), JSFunction::create(vm, this, 1, String(), createWritableStreamFromInternal, ImplementationVisibility::Public), PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
GlobalPropertyInfo(builtinNames.fulfillModuleSyncPrivateName(), JSFunction::create(vm, this, 1, String(), functionFulfillModuleSync, ImplementationVisibility::Public), PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
GlobalPropertyInfo(vm.propertyNames->builtinNames().ArrayBufferPrivateName(), arrayBufferConstructor(), PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
GlobalPropertyInfo(builtinNames.LoaderPrivateName(), this->moduleLoader(), PropertyAttribute::DontDelete | 0),
@@ -3630,9 +3645,9 @@ void GlobalObject::addBuiltinGlobals(JSC::VM& vm)
// i've noticed doing it as is will work somewhat but getDirect() wont be able to find them
putDirectBuiltinFunction(vm, this, builtinNames.createFIFOPrivateName(), streamInternalsCreateFIFOCodeGenerator(vm), PropertyAttribute::Builtin | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly);
putDirectBuiltinFunction(vm, this, builtinNames.createEmptyReadableStreamPrivateName(), readableStreamCreateEmptyReadableStreamCodeGenerator(vm), PropertyAttribute::Builtin | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly);
putDirectBuiltinFunction(vm, this, builtinNames.createUsedReadableStreamPrivateName(), readableStreamCreateUsedReadableStreamCodeGenerator(vm), PropertyAttribute::Builtin | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly);
putDirectBuiltinFunction(vm, this, builtinNames.createNativeReadableStreamPrivateName(), readableStreamCreateNativeReadableStreamCodeGenerator(vm), PropertyAttribute::Builtin | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly);
// putDirectBuiltinFunction(vm, this, builtinNames.createEmptyReadableStreamPrivateName(), readableStreamCreateEmptyReadableStreamCodeGenerator(vm), PropertyAttribute::Builtin | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly);
// putDirectBuiltinFunction(vm, this, builtinNames.createUsedReadableStreamPrivateName(), readableStreamCreateUsedReadableStreamCodeGenerator(vm), PropertyAttribute::Builtin | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly);
// putDirectBuiltinFunction(vm, this, builtinNames.createNativeReadableStreamPrivateName(), readableStreamCreateNativeReadableStreamCodeGenerator(vm), PropertyAttribute::Builtin | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly);
putDirectBuiltinFunction(vm, this, builtinNames.requireESMPrivateName(), importMetaObjectRequireESMCodeGenerator(vm), PropertyAttribute::Builtin | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly);
putDirectBuiltinFunction(vm, this, builtinNames.loadCJS2ESMPrivateName(), importMetaObjectLoadCJS2ESMCodeGenerator(vm), PropertyAttribute::Builtin | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly);
putDirectBuiltinFunction(vm, this, builtinNames.internalRequirePrivateName(), importMetaObjectInternalRequireCodeGenerator(vm), PropertyAttribute::Builtin | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly);
@@ -3660,18 +3675,18 @@ void GlobalObject::addBuiltinGlobals(JSC::VM& vm)
PropertyAttribute::ReadOnly | PropertyAttribute::DontDelete | 0);
putDirectCustomAccessor(vm, static_cast<JSVMClientData*>(vm.clientData)->builtinNames().BufferPrivateName(), JSC::CustomGetterSetter::create(vm, JSBuffer_getter, nullptr), PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly | PropertyAttribute::CustomValue);
putDirectCustomAccessor(vm, builtinNames.lazyStreamPrototypeMapPrivateName(), JSC::CustomGetterSetter::create(vm, functionLazyLoadStreamPrototypeMap_getter, nullptr), PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly | PropertyAttribute::CustomValue);
putDirectCustomAccessor(vm, builtinNames.TransformStreamPrivateName(), CustomGetterSetter::create(vm, TransformStream_getter, nullptr), attributesForStructure(static_cast<unsigned>(PropertyAttribute::DontEnum)) | PropertyAttribute::CustomValue);
putDirectCustomAccessor(vm, builtinNames.TransformStreamDefaultControllerPrivateName(), CustomGetterSetter::create(vm, TransformStreamDefaultController_getter, nullptr), attributesForStructure(static_cast<unsigned>(PropertyAttribute::DontEnum)) | PropertyAttribute::CustomValue);
putDirectCustomAccessor(vm, builtinNames.ReadableByteStreamControllerPrivateName(), CustomGetterSetter::create(vm, ReadableByteStreamController_getter, nullptr), attributesForStructure(PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly) | PropertyAttribute::CustomValue);
putDirectCustomAccessor(vm, builtinNames.ReadableStreamPrivateName(), CustomGetterSetter::create(vm, ReadableStream_getter, nullptr), attributesForStructure(PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly) | PropertyAttribute::CustomValue);
putDirectCustomAccessor(vm, builtinNames.ReadableStreamBYOBReaderPrivateName(), CustomGetterSetter::create(vm, ReadableStreamBYOBReader_getter, nullptr), attributesForStructure(PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly) | PropertyAttribute::CustomValue);
putDirectCustomAccessor(vm, builtinNames.ReadableStreamBYOBRequestPrivateName(), CustomGetterSetter::create(vm, ReadableStreamBYOBRequest_getter, nullptr), attributesForStructure(PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly) | PropertyAttribute::CustomValue);
putDirectCustomAccessor(vm, builtinNames.ReadableStreamDefaultControllerPrivateName(), CustomGetterSetter::create(vm, ReadableStreamDefaultController_getter, nullptr), attributesForStructure(PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly) | PropertyAttribute::CustomValue);
putDirectCustomAccessor(vm, builtinNames.ReadableStreamDefaultReaderPrivateName(), CustomGetterSetter::create(vm, ReadableStreamDefaultReader_getter, nullptr), attributesForStructure(PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly) | PropertyAttribute::CustomValue);
putDirectCustomAccessor(vm, builtinNames.WritableStreamPrivateName(), CustomGetterSetter::create(vm, WritableStream_getter, nullptr), attributesForStructure(PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly) | PropertyAttribute::CustomValue);
putDirectCustomAccessor(vm, builtinNames.WritableStreamDefaultControllerPrivateName(), CustomGetterSetter::create(vm, WritableStreamDefaultController_getter, nullptr), attributesForStructure(PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly) | PropertyAttribute::CustomValue);
putDirectCustomAccessor(vm, builtinNames.WritableStreamDefaultWriterPrivateName(), CustomGetterSetter::create(vm, WritableStreamDefaultWriter_getter, nullptr), attributesForStructure(PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly) | PropertyAttribute::CustomValue);
// putDirectCustomAccessor(vm, builtinNames.lazyStreamPrototypeMapPrivateName(), JSC::CustomGetterSetter::create(vm, functionLazyLoadStreamPrototypeMap_getter, nullptr), PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly | PropertyAttribute::CustomValue);
// putDirectCustomAccessor(vm, builtinNames.TransformStreamPrivateName(), CustomGetterSetter::create(vm, TransformStream_getter, nullptr), attributesForStructure(static_cast<unsigned>(PropertyAttribute::DontEnum)) | PropertyAttribute::CustomValue);
// putDirectCustomAccessor(vm, builtinNames.TransformStreamDefaultControllerPrivateName(), CustomGetterSetter::create(vm, TransformStreamDefaultController_getter, nullptr), attributesForStructure(static_cast<unsigned>(PropertyAttribute::DontEnum)) | PropertyAttribute::CustomValue);
// putDirectCustomAccessor(vm, builtinNames.ReadableByteStreamControllerPrivateName(), CustomGetterSetter::create(vm, ReadableByteStreamController_getter, nullptr), attributesForStructure(PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly) | PropertyAttribute::CustomValue);
// putDirectCustomAccessor(vm, builtinNames.ReadableStreamPrivateName(), CustomGetterSetter::create(vm, ReadableStream_getter, nullptr), attributesForStructure(PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly) | PropertyAttribute::CustomValue);
// putDirectCustomAccessor(vm, builtinNames.ReadableStreamBYOBReaderPrivateName(), CustomGetterSetter::create(vm, ReadableStreamBYOBReader_getter, nullptr), attributesForStructure(PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly) | PropertyAttribute::CustomValue);
// putDirectCustomAccessor(vm, builtinNames.ReadableStreamBYOBRequestPrivateName(), CustomGetterSetter::create(vm, ReadableStreamBYOBRequest_getter, nullptr), attributesForStructure(PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly) | PropertyAttribute::CustomValue);
// putDirectCustomAccessor(vm, builtinNames.ReadableStreamDefaultControllerPrivateName(), CustomGetterSetter::create(vm, ReadableStreamDefaultController_getter, nullptr), attributesForStructure(PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly) | PropertyAttribute::CustomValue);
// putDirectCustomAccessor(vm, builtinNames.ReadableStreamDefaultReaderPrivateName(), CustomGetterSetter::create(vm, ReadableStreamDefaultReader_getter, nullptr), attributesForStructure(PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly) | PropertyAttribute::CustomValue);
// putDirectCustomAccessor(vm, builtinNames.WritableStreamPrivateName(), CustomGetterSetter::create(vm, WritableStream_getter, nullptr), attributesForStructure(PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly) | PropertyAttribute::CustomValue);
// putDirectCustomAccessor(vm, builtinNames.WritableStreamDefaultControllerPrivateName(), CustomGetterSetter::create(vm, WritableStreamDefaultController_getter, nullptr), attributesForStructure(PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly) | PropertyAttribute::CustomValue);
// putDirectCustomAccessor(vm, builtinNames.WritableStreamDefaultWriterPrivateName(), CustomGetterSetter::create(vm, WritableStreamDefaultWriter_getter, nullptr), attributesForStructure(PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly) | PropertyAttribute::CustomValue);
putDirectCustomAccessor(vm, builtinNames.AbortSignalPrivateName(), CustomGetterSetter::create(vm, AbortSignal_getter, nullptr), PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly | PropertyAttribute::CustomValue);
// ----- Public Properties -----
@@ -3866,6 +3881,11 @@ void GlobalObject::visitChildrenImpl(JSCell* cell, Visitor& visitor)
thisObject->visitGeneratedLazyClasses<Visitor>(thisObject, visitor);
thisObject->visitAdditionalChildren<Visitor>(visitor);
#define VISIT_STREAM_CLASS(ClassName) \
thisObject->streams().m_##ClassName.visit(visitor);
FOR_EACH_WHATWG_STREAM_CLASS_TYPE(VISIT_STREAM_CLASS)
#undef VISIT_STREAM_CLASS
}
extern "C" bool JSGlobalObject__setTimeZone(JSC::JSGlobalObject* globalObject, const ZigString* timeZone)

View File

@@ -53,6 +53,7 @@ class GlobalInternals;
#include "BunCommonStrings.h"
#include "BunHttp2CommonStrings.h"
#include "BunGlobalScope.h"
#include "BunStreamStructures.h"
namespace WebCore {
class WorkerGlobalScope;
@@ -227,6 +228,8 @@ public:
JSC::JSObject* NodeVMScript() const { return m_NodeVMScriptClassStructure.constructorInitializedOnMainThread(this); }
JSC::JSValue NodeVMScriptPrototype() const { return m_NodeVMScriptClassStructure.prototypeInitializedOnMainThread(this); }
JSC::Structure* teeStateStructure() const { return m_teeStateStructure.getInitializedOnMainThread(this); }
JSC::JSMap* readableStreamNativeMap() const { return m_lazyReadableStreamPrototypeMap.getInitializedOnMainThread(this); }
JSC::JSMap* requireMap() const { return m_requireMap.getInitializedOnMainThread(this); }
JSC::JSMap* esmRegistryMap() const { return m_esmRegistryMap.getInitializedOnMainThread(this); }
@@ -339,9 +342,10 @@ public:
};
static constexpr size_t promiseFunctionsSize = 26;
static PromiseFunctions promiseHandlerID(SYSV_ABI EncodedJSValue (*handler)(JSC__JSGlobalObject* arg0, JSC__CallFrame* arg1));
using PromiseHandler = SYSV_ABI EncodedJSValue (*)(JSC__JSGlobalObject* arg0, JSC__CallFrame* arg1);
static PromiseFunctions promiseHandlerID(PromiseHandler handler);
JSFunction* thenable(SYSV_ABI EncodedJSValue (*handler)(JSC__JSGlobalObject* arg0, JSC__CallFrame* arg1))
JSFunction* thenable(PromiseHandler handler)
{
auto& barrier = this->m_thenables[static_cast<size_t>(GlobalObject::promiseHandlerID(handler))];
if (JSFunction* func = barrier.get()) {
@@ -478,6 +482,9 @@ public:
JSObject* JSDOMFileConstructor() const { return m_JSDOMFileConstructor.getInitializedOnMainThread(this); }
Bun::CommonStrings& commonStrings() { return m_commonStrings; }
Bun::Http2CommonStrings& http2CommonStrings() { return m_http2_commongStrings; }
Bun::StreamStructures& streams() { return m_streamStructures; }
#include "ZigGeneratedClasses+lazyStructureHeader.h"
void finishCreation(JSC::VM&);
@@ -522,6 +529,7 @@ public:
LazyClassStructure m_callSiteStructure;
LazyClassStructure m_JSBufferClassStructure;
LazyClassStructure m_NodeVMScriptClassStructure;
LazyClassStructure m_teeStateStructure;
/**
* WARNING: You must update visitChildrenImpl() if you add a new field.
@@ -593,6 +601,8 @@ private:
WTF::Vector<JSC::Strong<JSC::JSPromise>> m_aboutToBeNotifiedRejectedPromises;
WTF::Vector<JSC::Strong<JSC::JSFunction>> m_ffiFunctions;
Bun::StreamStructures m_streamStructures;
};
class EvalGlobalObject : public GlobalObject {

View File

@@ -69,24 +69,21 @@
PerformanceResourceTiming PerformanceResourceTimingConstructorCallback PropertyCallback
PerformanceServerTiming PerformanceServerTimingConstructorCallback PropertyCallback
PerformanceTiming PerformanceTimingConstructorCallback PropertyCallback
ReadableByteStreamController ReadableByteStreamControllerConstructorCallback PropertyCallback
ReadableStream ReadableStreamConstructorCallback PropertyCallback
ReadableStreamBYOBReader ReadableStreamBYOBReaderConstructorCallback PropertyCallback
ReadableStreamBYOBRequest ReadableStreamBYOBRequestConstructorCallback PropertyCallback
ReadableStreamDefaultController ReadableStreamDefaultControllerConstructorCallback PropertyCallback
ReadableStreamDefaultReader ReadableStreamDefaultReaderConstructorCallback PropertyCallback
ReadableStream JSReadableStreamConstructorCallback PropertyCallback
ReadableStreamDefaultController JSReadableStreamDefaultControllerConstructorCallback PropertyCallback
ReadableStreamDefaultReader JSReadableStreamDefaultReaderConstructorCallback PropertyCallback
SubtleCrypto SubtleCryptoConstructorCallback PropertyCallback
TextDecoderStream TextDecoderStreamConstructorCallback PropertyCallback
TextEncoder TextEncoderConstructorCallback PropertyCallback
TextEncoderStream TextEncoderStreamConstructorCallback PropertyCallback
TransformStream TransformStreamConstructorCallback PropertyCallback
TransformStreamDefaultController TransformStreamDefaultControllerConstructorCallback PropertyCallback
TransformStream JSTransformStreamConstructorCallback PropertyCallback
TransformStreamDefaultController JSTransformStreamDefaultControllerConstructorCallback PropertyCallback
URL DOMURLConstructorCallback PropertyCallback
URLSearchParams URLSearchParamsConstructorCallback PropertyCallback
WebSocket WebSocketConstructorCallback PropertyCallback
Worker WorkerConstructorCallback PropertyCallback
WritableStream WritableStreamConstructorCallback PropertyCallback
WritableStreamDefaultController WritableStreamDefaultControllerConstructorCallback PropertyCallback
WritableStreamDefaultWriter WritableStreamDefaultWriterConstructorCallback PropertyCallback
WritableStream JSWritableStreamConstructorCallback PropertyCallback
WritableStreamDefaultController JSWritableStreamDefaultControllerConstructorCallback PropertyCallback
WritableStreamDefaultWriter JSWritableStreamDefaultWriterConstructorCallback PropertyCallback
@end
*/

View File

@@ -130,6 +130,7 @@
#include "ObjectBindings.h"
#include <JavaScriptCore/VMInlines.h>
#include "BunPromiseInlines.h"
#if OS(DARWIN)
#if BUN_DEBUG
@@ -2732,18 +2733,20 @@ static JSC::Identifier jsValueToModuleKey(JSC::JSGlobalObject* lexicalGlobalObje
JSC__JSValue ReadableStream__empty(Zig::GlobalObject* globalObject)
{
auto& vm = globalObject->vm();
auto clientData = WebCore::clientData(vm);
auto* function = globalObject->getDirect(vm, clientData->builtinNames().createEmptyReadableStreamPrivateName()).getObject();
return JSValue::encode(JSC::call(globalObject, function, JSC::ArgList(), "ReadableStream.create"_s));
return JSValue::encode(jsUndefined());
// auto& vm = globalObject->vm();
// auto clientData = WebCore::clientData(vm);
// auto* function = globalObject->getDirect(vm, clientData->builtinNames().createEmptyReadableStreamPrivateName()).getObject();
// return JSValue::encode(JSC::call(globalObject, function, JSC::ArgList(), "ReadableStream.create"_s));
}
JSC__JSValue ReadableStream__used(Zig::GlobalObject* globalObject)
{
auto& vm = globalObject->vm();
auto clientData = WebCore::clientData(vm);
auto* function = globalObject->getDirect(vm, clientData->builtinNames().createUsedReadableStreamPrivateName()).getObject();
return JSValue::encode(JSC::call(globalObject, function, JSC::ArgList(), "ReadableStream.create"_s));
return JSValue::encode(jsUndefined());
// auto& vm = globalObject->vm();
// auto clientData = WebCore::clientData(vm);
// auto* function = globalObject->getDirect(vm, clientData->builtinNames().createUsedReadableStreamPrivateName()).getObject();
// return JSValue::encode(JSC::call(globalObject, function, JSC::ArgList(), "ReadableStream.create"_s));
}
JSC__JSValue JSC__JSValue__createRangeError(const ZigString* message, const ZigString* arg1,
@@ -3266,7 +3269,7 @@ JSC__JSValue JSC__JSPromise__wrap(JSC__JSGlobalObject* globalObject, void* ctx,
return JSValue::encode(JSC::JSPromise::rejectedPromise(globalObject, err));
}
return JSValue::encode(JSC::JSPromise::resolvedPromise(globalObject, result));
return JSValue::encode(Bun::createFulfilledPromise(globalObject, result));
}
void JSC__JSPromise__reject(JSC__JSPromise* arg0, JSC__JSGlobalObject* globalObject,

View File

@@ -58,6 +58,11 @@ public:
std::unique_ptr<GCClient::IsoSubspace> m_clientSubspaceForFunctionTemplate;
std::unique_ptr<GCClient::IsoSubspace> m_clientSubspaceForV8Function;
std::unique_ptr<GCClient::IsoSubspace> m_clientSubspaceForNodeVMGlobalObject;
std::unique_ptr<GCClient::IsoSubspace> m_clientSubspaceForJSReadableStreamDefaultController;
std::unique_ptr<GCClient::IsoSubspace> m_clientSubspaceForJSReadableStreamDefaultReader;
std::unique_ptr<GCClient::IsoSubspace> m_clientSubspaceForJSReadableStreamBYOBReader;
std::unique_ptr<GCClient::IsoSubspace> m_clientSubspaceForJSReadableStream;
std::unique_ptr<GCClient::IsoSubspace> m_clientSubspaceForTeeState;
#include "ZigGeneratedClasses+DOMClientIsoSubspaces.h"
/* --- bun --- */

View File

@@ -58,7 +58,10 @@ public:
std::unique_ptr<IsoSubspace> m_subspaceForFunctionTemplate;
std::unique_ptr<IsoSubspace> m_subspaceForV8Function;
std::unique_ptr<IsoSubspace> m_subspaceForNodeVMGlobalObject;
std::unique_ptr<IsoSubspace> m_subspaceForJSReadableStreamDefaultController;
std::unique_ptr<IsoSubspace> m_subspaceForJSReadableStreamDefaultReader;
std::unique_ptr<IsoSubspace> m_subspaceForJSReadableStreamBYOBReader;
std::unique_ptr<IsoSubspace> m_subspaceForTeeState;
#include "ZigGeneratedClasses+DOMIsoSubspaces.h"
/*-- BUN --*/

View File

@@ -1,167 +0,0 @@
/*
* Copyright (C) 2020-2021 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 CANON 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 CANON 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.
*/
#include "config.h"
#include "InternalWritableStream.h"
#include "Exception.h"
#include "WebCoreJSClientData.h"
namespace WebCore {
static ExceptionOr<JSC::JSValue> invokeWritableStreamFunction(JSC::JSGlobalObject& globalObject, const JSC::Identifier& identifier, const JSC::MarkedArgumentBuffer& arguments)
{
JSC::VM& vm = globalObject.vm();
JSC::JSLockHolder lock(vm);
auto scope = DECLARE_CATCH_SCOPE(vm);
auto function = globalObject.get(&globalObject, identifier);
ASSERT(function.isCallable());
scope.assertNoExceptionExceptTermination();
auto callData = JSC::getCallData(function);
auto result = call(&globalObject, function, callData, JSC::jsUndefined(), arguments);
RETURN_IF_EXCEPTION(scope, Exception { ExistingExceptionError });
return result;
}
ExceptionOr<Ref<InternalWritableStream>> InternalWritableStream::createFromUnderlyingSink(JSDOMGlobalObject& globalObject, JSC::JSValue underlyingSink, JSC::JSValue strategy)
{
auto* clientData = static_cast<JSVMClientData*>(globalObject.vm().clientData);
auto& privateName = clientData->builtinFunctions().writableStreamInternalsBuiltins().createInternalWritableStreamFromUnderlyingSinkPrivateName();
JSC::MarkedArgumentBuffer arguments;
arguments.append(underlyingSink);
arguments.append(strategy);
ASSERT(!arguments.hasOverflowed());
auto result = invokeWritableStreamFunction(globalObject, privateName, arguments);
if (UNLIKELY(result.hasException()))
return result.releaseException();
ASSERT(result.returnValue().isObject());
return adoptRef(*new InternalWritableStream(globalObject, *result.returnValue().toObject(&globalObject)));
}
Ref<InternalWritableStream> InternalWritableStream::fromObject(JSDOMGlobalObject& globalObject, JSC::JSObject& object)
{
return adoptRef(*new InternalWritableStream(globalObject, object));
}
bool InternalWritableStream::locked() const
{
auto* globalObject = this->globalObject();
if (!globalObject)
return false;
auto scope = DECLARE_CATCH_SCOPE(globalObject->vm());
auto* clientData = static_cast<JSVMClientData*>(globalObject->vm().clientData);
auto& privateName = clientData->builtinFunctions().writableStreamInternalsBuiltins().isWritableStreamLockedPrivateName();
JSC::MarkedArgumentBuffer arguments;
arguments.append(guardedObject());
ASSERT(!arguments.hasOverflowed());
auto result = invokeWritableStreamFunction(*globalObject, privateName, arguments);
if (scope.exception())
scope.clearException();
return result.hasException() ? false : result.returnValue().isTrue();
}
void InternalWritableStream::lock()
{
auto* globalObject = this->globalObject();
if (!globalObject)
return;
auto scope = DECLARE_CATCH_SCOPE(globalObject->vm());
auto* clientData = static_cast<JSVMClientData*>(globalObject->vm().clientData);
auto& privateName = clientData->builtinFunctions().writableStreamInternalsBuiltins().acquireWritableStreamDefaultWriterPrivateName();
JSC::MarkedArgumentBuffer arguments;
arguments.append(guardedObject());
ASSERT(!arguments.hasOverflowed());
invokeWritableStreamFunction(*globalObject, privateName, arguments);
if (UNLIKELY(scope.exception()))
scope.clearException();
}
JSC::JSValue InternalWritableStream::abort(JSC::JSGlobalObject& globalObject, JSC::JSValue reason)
{
auto* clientData = static_cast<JSVMClientData*>(globalObject.vm().clientData);
auto& privateName = clientData->builtinFunctions().writableStreamInternalsBuiltins().writableStreamAbortForBindingsPrivateName();
JSC::MarkedArgumentBuffer arguments;
arguments.append(guardedObject());
arguments.append(reason);
ASSERT(!arguments.hasOverflowed());
auto result = invokeWritableStreamFunction(globalObject, privateName, arguments);
if (result.hasException())
return {};
return result.returnValue();
}
JSC::JSValue InternalWritableStream::close(JSC::JSGlobalObject& globalObject)
{
auto* clientData = static_cast<JSVMClientData*>(globalObject.vm().clientData);
auto& privateName = clientData->builtinFunctions().writableStreamInternalsBuiltins().writableStreamCloseForBindingsPrivateName();
JSC::MarkedArgumentBuffer arguments;
arguments.append(guardedObject());
ASSERT(!arguments.hasOverflowed());
auto result = invokeWritableStreamFunction(globalObject, privateName, arguments);
if (result.hasException())
return {};
return result.returnValue();
}
JSC::JSValue InternalWritableStream::getWriter(JSC::JSGlobalObject& globalObject)
{
auto* clientData = static_cast<JSVMClientData*>(globalObject.vm().clientData);
auto& privateName = clientData->builtinFunctions().writableStreamInternalsBuiltins().acquireWritableStreamDefaultWriterPrivateName();
JSC::MarkedArgumentBuffer arguments;
arguments.append(guardedObject());
ASSERT(!arguments.hasOverflowed());
auto result = invokeWritableStreamFunction(globalObject, privateName, arguments);
if (result.hasException())
return {};
return result.returnValue();
}
}

View File

@@ -1,53 +0,0 @@
/*
* Copyright (C) 2020-2021 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 CANON 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 CANON 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.
*/
#pragma once
#include "ExceptionOr.h"
#include "JSDOMGuardedObject.h"
#include <JavaScriptCore/JSObject.h>
namespace WebCore {
class InternalWritableStream final : public DOMGuarded<JSC::JSObject> {
public:
static ExceptionOr<Ref<InternalWritableStream>> createFromUnderlyingSink(JSDOMGlobalObject&, JSC::JSValue underlyingSink, JSC::JSValue strategy);
static Ref<InternalWritableStream> fromObject(JSDOMGlobalObject&, JSC::JSObject&);
operator JSC::JSValue() const { return guarded(); }
bool locked() const;
void lock();
JSC::JSValue abort(JSC::JSGlobalObject&, JSC::JSValue);
JSC::JSValue close(JSC::JSGlobalObject&);
JSC::JSValue getWriter(JSC::JSGlobalObject&);
private:
InternalWritableStream(JSDOMGlobalObject& globalObject, JSC::JSObject& jsObject)
: DOMGuarded<JSC::JSObject>(globalObject, jsObject)
{
}
};
}

View File

@@ -36,13 +36,37 @@ JSC_DEFINE_HOST_FUNCTION(callThrowTypeErrorForJSDOMConstructor, (JSGlobalObject
VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
auto* callee = callframe->jsCallee();
auto* constructor = jsDynamicCast<JSDOMConstructorBase*>(callee);
auto* constructor = jsDynamicCast<InternalFunction*>(callee);
const auto& name = constructor->name();
RETURN_IF_EXCEPTION(scope, {});
Bun::throwError(globalObject, scope, Bun::ErrorCode::ERR_ILLEGAL_CONSTRUCTOR, makeString("Use `new "_s, name, "(...)` instead of `"_s, name, "(...)`"_s));
return {};
}
JSC_DEFINE_HOST_FUNCTION(callThrowTypeErrorForJSDOMConstructorNotConstructable, (JSGlobalObject * globalObject, CallFrame* callframe))
{
VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
auto* callee = callframe->jsCallee();
auto* constructor = jsDynamicCast<InternalFunction*>(callee);
const auto& name = constructor->name();
RETURN_IF_EXCEPTION(scope, {});
Bun::throwError(globalObject, scope, Bun::ErrorCode::ERR_ILLEGAL_CONSTRUCTOR, makeString("Use `new "_s, name, "(...)` instead of `"_s, name, "(...)`"_s));
return {};
}
JSC_DEFINE_HOST_FUNCTION(callThrowTypeErrorForJSDOMConstructorNotCallableOrConstructable, (JSGlobalObject * globalObject, CallFrame* callframe))
{
VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
auto* callee = callframe->jsCallee();
auto* constructor = jsDynamicCast<InternalFunction*>(callee);
const auto& name = constructor->name();
RETURN_IF_EXCEPTION(scope, {});
Bun::throwError(globalObject, scope, Bun::ErrorCode::ERR_ILLEGAL_CONSTRUCTOR, makeString("Constructor for "_s, name, " cannot be constructed directly, but you can use it for instanceof."_s));
return {};
}
JSC::GCClient::IsoSubspace* JSDOMConstructorBase::subspaceForImpl(JSC::VM& vm)
{
return &static_cast<JSVMClientData*>(vm.clientData)->domConstructorSpace();

View File

@@ -27,6 +27,7 @@
namespace WebCore {
JSC_DECLARE_HOST_FUNCTION(callThrowTypeErrorForJSDOMConstructor);
JSC_DECLARE_HOST_FUNCTION(callThrowTypeErrorForJSDOMConstructorNotCallableOrConstructable);
// Base class for all callable constructor objects in the JSC bindings.
class JSDOMConstructorBase : public JSC::InternalFunction {
@@ -53,8 +54,10 @@ public:
protected:
JSDOMConstructorBase(JSC::VM& vm, JSC::Structure* structure, JSC::NativeFunction functionForConstruct, JSC::NativeFunction functionForCall = nullptr)
: Base(vm, structure,
functionForCall ? functionForCall : callThrowTypeErrorForJSDOMConstructor,
functionForConstruct ? functionForConstruct : callThrowTypeErrorForJSDOMConstructor)
!functionForCall && !functionForConstruct ? callThrowTypeErrorForJSDOMConstructorNotCallableOrConstructable : functionForCall ? functionForCall
: callThrowTypeErrorForJSDOMConstructor,
!functionForConstruct ? callThrowTypeErrorForJSDOMConstructorNotCallableOrConstructable : functionForConstruct ? functionForConstruct
: callThrowTypeErrorForJSDOMConstructor)
{
}
};

View File

@@ -28,6 +28,7 @@
#include "IDLTypes.h"
#include "JSDOMConvertBase.h"
#include "JSDOMPromise.h"
#include "BunPromiseInlines.h"
// #include "WorkerGlobalScope.h"
namespace WebCore {
@@ -47,7 +48,7 @@ template<typename T> struct Converter<IDLPromise<T>> : DefaultConverter<IDLPromi
// 1. Let resolve be the original value of %Promise%.resolve.
// 2. Let promise be the result of calling resolve with %Promise% as the this value and V as the single argument value.
auto* promise = JSC::JSPromise::resolvedPromise(globalObject, value);
auto* promise = Bun::createFulfilledPromise(globalObject, value);
if (scope.exception()) {
// auto* scriptExecutionContext = globalObject->scriptExecutionContext();
// if (is<WorkerGlobalScope>(scriptExecutionContext)) {

View File

@@ -1,182 +0,0 @@
/*
This file is part of the WebKit open source project.
This file has been generated by generate-bindings.pl. DO NOT MODIFY!
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "config.h"
#include "JSReadableByteStreamController.h"
#include "ExtendedDOMClientIsoSubspaces.h"
#include "ExtendedDOMIsoSubspaces.h"
#include "JSDOMAttribute.h"
#include "JSDOMBinding.h"
#include "JSDOMBuiltinConstructor.h"
#include "JSDOMExceptionHandling.h"
#include "JSDOMGlobalObjectInlines.h"
#include "JSDOMOperation.h"
#include "JSDOMWrapperCache.h"
#include "WebCoreJSClientData.h"
#include <JavaScriptCore/FunctionPrototype.h>
#include <JavaScriptCore/JSCInlines.h>
#include <JavaScriptCore/JSDestructibleObjectHeapCellType.h>
#include <JavaScriptCore/SlotVisitorMacros.h>
#include <JavaScriptCore/SubspaceInlines.h>
#include <wtf/GetPtr.h>
#include <wtf/PointerPreparations.h>
namespace WebCore {
using namespace JSC;
// Functions
// Attributes
static JSC_DECLARE_CUSTOM_GETTER(jsReadableByteStreamControllerConstructor);
class JSReadableByteStreamControllerPrototype final : public JSC::JSNonFinalObject {
public:
using Base = JSC::JSNonFinalObject;
static JSReadableByteStreamControllerPrototype* create(JSC::VM& vm, JSDOMGlobalObject* globalObject, JSC::Structure* structure)
{
JSReadableByteStreamControllerPrototype* ptr = new (NotNull, JSC::allocateCell<JSReadableByteStreamControllerPrototype>(vm)) JSReadableByteStreamControllerPrototype(vm, globalObject, structure);
ptr->finishCreation(vm);
return ptr;
}
DECLARE_INFO;
template<typename CellType, JSC::SubspaceAccess>
static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm)
{
STATIC_ASSERT_ISO_SUBSPACE_SHARABLE(JSReadableByteStreamControllerPrototype, Base);
return &vm.plainObjectSpace();
}
static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
{
return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info());
}
private:
JSReadableByteStreamControllerPrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure)
: JSC::JSNonFinalObject(vm, structure)
{
}
void finishCreation(JSC::VM&);
};
STATIC_ASSERT_ISO_SUBSPACE_SHARABLE(JSReadableByteStreamControllerPrototype, JSReadableByteStreamControllerPrototype::Base);
using JSReadableByteStreamControllerDOMConstructor = JSDOMBuiltinConstructor<JSReadableByteStreamController>;
template<> const ClassInfo JSReadableByteStreamControllerDOMConstructor::s_info = { "ReadableByteStreamController"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSReadableByteStreamControllerDOMConstructor) };
template<> JSValue JSReadableByteStreamControllerDOMConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject)
{
UNUSED_PARAM(vm);
return globalObject.functionPrototype();
}
template<> void JSReadableByteStreamControllerDOMConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject)
{
putDirect(vm, vm.propertyNames->length, jsNumber(3), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
JSString* nameString = jsNontrivialString(vm, "ReadableByteStreamController"_s);
m_originalName.set(vm, this, nameString);
putDirect(vm, vm.propertyNames->name, nameString, JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
putDirect(vm, vm.propertyNames->prototype, JSReadableByteStreamController::prototype(vm, globalObject), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::DontDelete);
}
template<> FunctionExecutable* JSReadableByteStreamControllerDOMConstructor::initializeExecutable(VM& vm)
{
return readableByteStreamControllerInitializeReadableByteStreamControllerCodeGenerator(vm);
}
/* Hash table for prototype */
static const HashTableValue JSReadableByteStreamControllerPrototypeTableValues[] = {
{ "constructor"_s, static_cast<unsigned>(JSC::PropertyAttribute::DontEnum), NoIntrinsic, { HashTableValue::GetterSetterType, jsReadableByteStreamControllerConstructor, 0 } },
{ "byobRequest"_s, static_cast<unsigned>(JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::Accessor | JSC::PropertyAttribute::Builtin), NoIntrinsic, { HashTableValue::BuiltinAccessorType, readableByteStreamControllerByobRequestCodeGenerator, 0 } },
{ "desiredSize"_s, static_cast<unsigned>(JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::Accessor | JSC::PropertyAttribute::Builtin), NoIntrinsic, { HashTableValue::BuiltinAccessorType, readableByteStreamControllerDesiredSizeCodeGenerator, 0 } },
{ "enqueue"_s, static_cast<unsigned>(JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::Builtin), NoIntrinsic, { HashTableValue::BuiltinGeneratorType, readableByteStreamControllerEnqueueCodeGenerator, 0 } },
{ "close"_s, static_cast<unsigned>(JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::Builtin), NoIntrinsic, { HashTableValue::BuiltinGeneratorType, readableByteStreamControllerCloseCodeGenerator, 0 } },
{ "error"_s, static_cast<unsigned>(JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::Builtin), NoIntrinsic, { HashTableValue::BuiltinGeneratorType, readableByteStreamControllerErrorCodeGenerator, 0 } },
};
const ClassInfo JSReadableByteStreamControllerPrototype::s_info = { "ReadableByteStreamController"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSReadableByteStreamControllerPrototype) };
void JSReadableByteStreamControllerPrototype::finishCreation(VM& vm)
{
Base::finishCreation(vm);
reifyStaticProperties(vm, JSReadableByteStreamController::info(), JSReadableByteStreamControllerPrototypeTableValues, *this);
JSC_TO_STRING_TAG_WITHOUT_TRANSITION();
}
const ClassInfo JSReadableByteStreamController::s_info = { "ReadableByteStreamController"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSReadableByteStreamController) };
JSReadableByteStreamController::JSReadableByteStreamController(Structure* structure, JSDOMGlobalObject& globalObject)
: JSDOMObject(structure, globalObject)
{
}
void JSReadableByteStreamController::finishCreation(VM& vm)
{
Base::finishCreation(vm);
ASSERT(inherits(info()));
}
JSObject* JSReadableByteStreamController::createPrototype(VM& vm, JSDOMGlobalObject& globalObject)
{
auto* structure = JSReadableByteStreamControllerPrototype::createStructure(vm, &globalObject, globalObject.objectPrototype());
structure->setMayBePrototype(true);
return JSReadableByteStreamControllerPrototype::create(vm, &globalObject, structure);
}
JSObject* JSReadableByteStreamController::prototype(VM& vm, JSDOMGlobalObject& globalObject)
{
return getDOMPrototype<JSReadableByteStreamController>(vm, globalObject);
}
JSValue JSReadableByteStreamController::getConstructor(VM& vm, const JSGlobalObject* globalObject)
{
return getDOMConstructor<JSReadableByteStreamControllerDOMConstructor, DOMConstructorID::ReadableByteStreamController>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject));
}
void JSReadableByteStreamController::destroy(JSC::JSCell* cell)
{
JSReadableByteStreamController* thisObject = static_cast<JSReadableByteStreamController*>(cell);
thisObject->JSReadableByteStreamController::~JSReadableByteStreamController();
}
JSC_DEFINE_CUSTOM_GETTER(jsReadableByteStreamControllerConstructor, (JSGlobalObject * lexicalGlobalObject, JSC::EncodedJSValue thisValue, PropertyName))
{
VM& vm = JSC::getVM(lexicalGlobalObject);
auto throwScope = DECLARE_THROW_SCOPE(vm);
auto* prototype = jsDynamicCast<JSReadableByteStreamControllerPrototype*>(JSValue::decode(thisValue));
if (UNLIKELY(!prototype))
return throwVMTypeError(lexicalGlobalObject, throwScope);
return JSValue::encode(JSReadableByteStreamController::getConstructor(JSC::getVM(lexicalGlobalObject), prototype->globalObject()));
}
JSC::GCClient::IsoSubspace* JSReadableByteStreamController::subspaceForImpl(JSC::VM& vm)
{
return WebCore::subspaceForImpl<JSReadableByteStreamController, UseCustomHeapCellType::No>(
vm,
[](auto& spaces) { return spaces.m_clientSubspaceForReadableByteStreamController.get(); },
[](auto& spaces, auto&& space) { spaces.m_clientSubspaceForReadableByteStreamController = std::forward<decltype(space)>(space); },
[](auto& spaces) { return spaces.m_subspaceForReadableByteStreamController.get(); },
[](auto& spaces, auto&& space) { spaces.m_subspaceForReadableByteStreamController = std::forward<decltype(space)>(space); });
}
}

View File

@@ -1,63 +0,0 @@
/*
This file is part of the WebKit open source project.
This file has been generated by generate-bindings.pl. DO NOT MODIFY!
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#pragma once
#include "JSDOMWrapper.h"
namespace WebCore {
class JSReadableByteStreamController : public JSDOMObject {
public:
using Base = JSDOMObject;
static JSReadableByteStreamController* create(JSC::Structure* structure, JSDOMGlobalObject* globalObject)
{
JSReadableByteStreamController* ptr = new (NotNull, JSC::allocateCell<JSReadableByteStreamController>(globalObject->vm())) JSReadableByteStreamController(structure, *globalObject);
ptr->finishCreation(globalObject->vm());
return ptr;
}
static JSC::JSObject* createPrototype(JSC::VM&, JSDOMGlobalObject&);
static JSC::JSObject* prototype(JSC::VM&, JSDOMGlobalObject&);
static void destroy(JSC::JSCell*);
DECLARE_INFO;
static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
{
return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info(), JSC::NonArray);
}
static JSC::JSValue getConstructor(JSC::VM&, const JSC::JSGlobalObject*);
template<typename, JSC::SubspaceAccess mode> static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm)
{
if constexpr (mode == JSC::SubspaceAccess::Concurrently)
return nullptr;
return subspaceForImpl(vm);
}
static JSC::GCClient::IsoSubspace* subspaceForImpl(JSC::VM& vm);
protected:
JSReadableByteStreamController(JSC::Structure*, JSDOMGlobalObject&);
void finishCreation(JSC::VM&);
};
} // namespace WebCore

View File

@@ -1,259 +0,0 @@
/*
This file is part of the WebKit open source project.
This file has been generated by generate-bindings.pl. DO NOT MODIFY!
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "config.h"
#include "JSReadableStream.h"
#include "ExtendedDOMClientIsoSubspaces.h"
#include "ExtendedDOMIsoSubspaces.h"
#include "JSDOMAttribute.h"
#include "JSDOMBinding.h"
#include "JSDOMBuiltinConstructor.h"
#include "JSDOMExceptionHandling.h"
#include "JSDOMGlobalObjectInlines.h"
#include "JSDOMOperation.h"
#include "JSDOMWrapperCache.h"
#include "WebCoreJSClientData.h"
#include <JavaScriptCore/FunctionPrototype.h>
#include <JavaScriptCore/JSCInlines.h>
#include <JavaScriptCore/JSDestructibleObjectHeapCellType.h>
#include <JavaScriptCore/SlotVisitorMacros.h>
#include <JavaScriptCore/SubspaceInlines.h>
#include <wtf/GetPtr.h>
#include <wtf/PointerPreparations.h>
#include "ZigGeneratedClasses.h"
#include "JavaScriptCore/BuiltinNames.h"
namespace WebCore {
using namespace JSC;
extern "C" void ReadableStream__incrementCount(void*, int32_t);
// Functions
// Attributes
static JSC_DECLARE_CUSTOM_GETTER(jsReadableStreamConstructor);
class JSReadableStreamPrototype final : public JSC::JSNonFinalObject {
public:
using Base = JSC::JSNonFinalObject;
static JSReadableStreamPrototype* create(JSC::VM& vm, JSDOMGlobalObject* globalObject, JSC::Structure* structure)
{
JSReadableStreamPrototype* ptr = new (NotNull, JSC::allocateCell<JSReadableStreamPrototype>(vm)) JSReadableStreamPrototype(vm, globalObject, structure);
ptr->finishCreation(vm);
return ptr;
}
DECLARE_INFO;
template<typename CellType, JSC::SubspaceAccess>
static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm)
{
STATIC_ASSERT_ISO_SUBSPACE_SHARABLE(JSReadableStreamPrototype, Base);
return &vm.plainObjectSpace();
}
static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
{
return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info());
}
private:
JSReadableStreamPrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure)
: JSC::JSNonFinalObject(vm, structure)
{
}
void finishCreation(JSC::VM&);
};
STATIC_ASSERT_ISO_SUBSPACE_SHARABLE(JSReadableStreamPrototype, JSReadableStreamPrototype::Base);
using JSReadableStreamDOMConstructor = JSDOMBuiltinConstructor<JSReadableStream>;
template<> const ClassInfo JSReadableStreamDOMConstructor::s_info = { "ReadableStream"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSReadableStreamDOMConstructor) };
template<> JSValue JSReadableStreamDOMConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject)
{
UNUSED_PARAM(vm);
return globalObject.functionPrototype();
}
template<> void JSReadableStreamDOMConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject)
{
putDirect(vm, vm.propertyNames->length, jsNumber(0), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
JSString* nameString = jsNontrivialString(vm, "ReadableStream"_s);
m_originalName.set(vm, this, nameString);
putDirect(vm, vm.propertyNames->name, nameString, JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
putDirect(vm, vm.propertyNames->prototype, JSReadableStream::prototype(vm, globalObject), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::DontDelete);
}
template<> FunctionExecutable* JSReadableStreamDOMConstructor::initializeExecutable(VM& vm)
{
return readableStreamInitializeReadableStreamCodeGenerator(vm);
}
/* Hash table for prototype */
static const HashTableValue JSReadableStreamPrototypeTableValues[] = {
{ "constructor"_s, static_cast<unsigned>(JSC::PropertyAttribute::DontEnum), NoIntrinsic, { HashTableValue::GetterSetterType, jsReadableStreamConstructor, 0 } },
{ "locked"_s, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::Accessor | JSC::PropertyAttribute::Builtin), NoIntrinsic, { HashTableValue::BuiltinAccessorType, readableStreamLockedCodeGenerator, 0 } },
{ "cancel"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function | JSC::PropertyAttribute::Builtin), NoIntrinsic, { HashTableValue::BuiltinGeneratorType, readableStreamCancelCodeGenerator, 0 } },
{ "getReader"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function | JSC::PropertyAttribute::Builtin), NoIntrinsic, { HashTableValue::BuiltinGeneratorType, readableStreamGetReaderCodeGenerator, 0 } },
{ "pipeTo"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function | JSC::PropertyAttribute::Builtin), NoIntrinsic, { HashTableValue::BuiltinGeneratorType, readableStreamPipeToCodeGenerator, 1 } },
{ "pipeThrough"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function | JSC::PropertyAttribute::Builtin), NoIntrinsic, { HashTableValue::BuiltinGeneratorType, readableStreamPipeThroughCodeGenerator, 2 } },
{ "tee"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function | JSC::PropertyAttribute::Builtin), NoIntrinsic, { HashTableValue::BuiltinGeneratorType, readableStreamTeeCodeGenerator, 0 } },
};
const ClassInfo JSReadableStreamPrototype::s_info = { "ReadableStream"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSReadableStreamPrototype) };
static JSC_DEFINE_CUSTOM_SETTER(JSReadableStreamPrototype__nativePtrSetterWrap, (JSC::JSGlobalObject * lexicalGlobalObject, JSC::EncodedJSValue encodedThisValue, JSC::EncodedJSValue encodedJSValue, JSC::PropertyName))
{
JSReadableStream* thisObject = jsCast<JSReadableStream*>(JSValue::decode(encodedThisValue));
thisObject->setNativePtr(lexicalGlobalObject->vm(), JSValue::decode(encodedJSValue));
return true;
}
static JSC_DEFINE_CUSTOM_GETTER(JSReadableStreamPrototype__nativePtrGetterWrap, (JSC::JSGlobalObject * lexicalGlobalObject, JSC::EncodedJSValue encodedThisValue, JSC::PropertyName))
{
JSReadableStream* thisObject = jsCast<JSReadableStream*>(JSValue::decode(encodedThisValue));
// Force it to be locked, even though the value is still really there.
if (thisObject->isNativeTypeTransferred()) {
return JSValue::encode(jsNumber(-1));
}
return JSValue::encode(thisObject->nativePtr());
}
static JSC_DEFINE_CUSTOM_SETTER(JSReadableStreamPrototype__nativeTypeSetterWrap, (JSC::JSGlobalObject * lexicalGlobalObject, JSC::EncodedJSValue encodedThisValue, JSC::EncodedJSValue encodedJSValue, JSC::PropertyName))
{
JSReadableStream* thisObject = jsCast<JSReadableStream*>(JSValue::decode(encodedThisValue));
thisObject->setNativeType(JSValue::decode(encodedJSValue).toInt32(lexicalGlobalObject));
return true;
}
static JSC_DEFINE_CUSTOM_GETTER(JSReadableStreamPrototype__nativeTypeGetterWrap, (JSC::JSGlobalObject * lexicalGlobalObject, JSC::EncodedJSValue encodedThisValue, JSC::PropertyName))
{
JSReadableStream* thisObject = jsCast<JSReadableStream*>(JSValue::decode(encodedThisValue));
return JSValue::encode(jsNumber(thisObject->nativeType()));
}
static JSC_DEFINE_CUSTOM_SETTER(JSReadableStreamPrototype__disturbedSetterWrap, (JSC::JSGlobalObject * lexicalGlobalObject, JSC::EncodedJSValue encodedThisValue, JSC::EncodedJSValue encodedJSValue, JSC::PropertyName))
{
JSReadableStream* thisObject = jsCast<JSReadableStream*>(JSValue::decode(encodedThisValue));
thisObject->setDisturbed(JSValue::decode(encodedJSValue).toBoolean(lexicalGlobalObject));
return true;
}
static JSC_DEFINE_CUSTOM_GETTER(JSReadableStreamPrototype__disturbedGetterWrap, (JSC::JSGlobalObject * lexicalGlobalObject, JSC::EncodedJSValue encodedThisValue, JSC::PropertyName))
{
JSReadableStream* thisObject = jsCast<JSReadableStream*>(JSValue::decode(encodedThisValue));
return JSValue::encode(jsBoolean(thisObject->disturbed()));
}
void JSReadableStreamPrototype::finishCreation(VM& vm)
{
Base::finishCreation(vm);
auto clientData = WebCore::clientData(vm);
this->putDirectCustomAccessor(vm, clientData->builtinNames().bunNativePtrPrivateName(), DOMAttributeGetterSetter::create(vm, JSReadableStreamPrototype__nativePtrGetterWrap, JSReadableStreamPrototype__nativePtrSetterWrap, DOMAttributeAnnotation { JSReadableStream::info(), nullptr }), JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute | PropertyAttribute::DontDelete);
this->putDirectCustomAccessor(vm, clientData->builtinNames().bunNativeTypePrivateName(), DOMAttributeGetterSetter::create(vm, JSReadableStreamPrototype__nativeTypeGetterWrap, JSReadableStreamPrototype__nativeTypeSetterWrap, DOMAttributeAnnotation { JSReadableStream::info(), nullptr }), JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute | PropertyAttribute::DontDelete);
this->putDirectCustomAccessor(vm, clientData->builtinNames().disturbedPrivateName(), DOMAttributeGetterSetter::create(vm, JSReadableStreamPrototype__disturbedGetterWrap, JSReadableStreamPrototype__disturbedSetterWrap, DOMAttributeAnnotation { JSReadableStream::info(), nullptr }), JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute | PropertyAttribute::DontDelete);
reifyStaticProperties(vm, JSReadableStream::info(), JSReadableStreamPrototypeTableValues, *this);
this->putDirectBuiltinFunction(vm, globalObject(), vm.propertyNames->asyncIteratorSymbol, readableStreamLazyAsyncIteratorCodeGenerator(vm), JSC::PropertyAttribute::DontDelete | 0);
this->putDirectBuiltinFunction(vm, globalObject(), vm.propertyNames->builtinNames().valuesPublicName(), readableStreamValuesCodeGenerator(vm), JSC::PropertyAttribute::DontDelete | 0);
JSC_TO_STRING_TAG_WITHOUT_TRANSITION();
}
const ClassInfo JSReadableStream::s_info = { "ReadableStream"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSReadableStream) };
JSReadableStream::JSReadableStream(Structure* structure, JSDOMGlobalObject& globalObject)
: JSDOMObject(structure, globalObject)
{
}
void JSReadableStream::finishCreation(VM& vm)
{
Base::finishCreation(vm);
ASSERT(inherits(info()));
}
void JSReadableStream::setNativePtr(JSC::VM& vm, JSC::JSValue value)
{
this->m_nativePtr.set(vm, this, value);
}
JSObject* JSReadableStream::createPrototype(VM& vm, JSDOMGlobalObject& globalObject)
{
auto* structure = JSReadableStreamPrototype::createStructure(vm, &globalObject, globalObject.objectPrototype());
structure->setMayBePrototype(true);
return JSReadableStreamPrototype::create(vm, &globalObject, structure);
}
JSObject* JSReadableStream::prototype(VM& vm, JSDOMGlobalObject& globalObject)
{
return getDOMPrototype<JSReadableStream>(vm, globalObject);
}
JSValue JSReadableStream::getConstructor(VM& vm, const JSGlobalObject* globalObject)
{
return getDOMConstructor<JSReadableStreamDOMConstructor, DOMConstructorID::ReadableStream>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject));
}
void JSReadableStream::destroy(JSC::JSCell* cell)
{
JSReadableStream* thisObject = static_cast<JSReadableStream*>(cell);
thisObject->JSReadableStream::~JSReadableStream();
}
JSC_DEFINE_CUSTOM_GETTER(jsReadableStreamConstructor, (JSGlobalObject * lexicalGlobalObject, JSC::EncodedJSValue thisValue, PropertyName))
{
VM& vm = JSC::getVM(lexicalGlobalObject);
auto throwScope = DECLARE_THROW_SCOPE(vm);
auto* prototype = jsDynamicCast<JSReadableStreamPrototype*>(JSValue::decode(thisValue));
if (UNLIKELY(!prototype))
return throwVMTypeError(lexicalGlobalObject, throwScope);
return JSValue::encode(JSReadableStream::getConstructor(JSC::getVM(lexicalGlobalObject), prototype->globalObject()));
}
JSC::GCClient::IsoSubspace* JSReadableStream::subspaceForImpl(JSC::VM& vm)
{
return WebCore::subspaceForImpl<JSReadableStream, UseCustomHeapCellType::No>(
vm,
[](auto& spaces) { return spaces.m_clientSubspaceForReadableStream.get(); },
[](auto& spaces, auto&& space) { spaces.m_clientSubspaceForReadableStream = std::forward<decltype(space)>(space); },
[](auto& spaces) { return spaces.m_subspaceForReadableStream.get(); },
[](auto& spaces, auto&& space) { spaces.m_subspaceForReadableStream = std::forward<decltype(space)>(space); });
}
template<typename Visitor>
void JSReadableStream::visitChildrenImpl(JSCell* cell, Visitor& visitor)
{
JSReadableStream* stream = jsCast<JSReadableStream*>(cell);
ASSERT_GC_OBJECT_INHERITS(stream, info());
Base::visitChildren(stream, visitor);
visitor.append(stream->m_nativePtr);
}
DEFINE_VISIT_CHILDREN(JSReadableStream);
}

View File

@@ -1,95 +0,0 @@
/*
This file is part of the WebKit open source project.
This file has been generated by generate-bindings.pl. DO NOT MODIFY!
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#pragma once
#include "JSDOMWrapper.h"
namespace WebCore {
class JSReadableStream : public JSDOMObject {
public:
using Base = JSDOMObject;
static JSReadableStream* create(JSC::Structure* structure, JSDOMGlobalObject* globalObject)
{
JSReadableStream* ptr = new (NotNull, JSC::allocateCell<JSReadableStream>(globalObject->vm())) JSReadableStream(structure, *globalObject);
ptr->finishCreation(globalObject->vm());
return ptr;
}
static JSC::JSObject* createPrototype(JSC::VM&, JSDOMGlobalObject&);
static JSC::JSObject* prototype(JSC::VM&, JSDOMGlobalObject&);
static void destroy(JSC::JSCell*);
DECLARE_INFO;
static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
{
return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info(), JSC::NonArray);
}
static JSC::JSValue getConstructor(JSC::VM&, const JSC::JSGlobalObject*);
template<typename, JSC::SubspaceAccess mode> static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm)
{
if constexpr (mode == JSC::SubspaceAccess::Concurrently)
return nullptr;
return subspaceForImpl(vm);
}
static JSC::GCClient::IsoSubspace* subspaceForImpl(JSC::VM& vm);
int nativeType() const { return this->m_nativeType; }
bool disturbed() const { return this->m_disturbed; }
bool isNativeTypeTransferred() const { return this->m_transferred; }
void setTransferred()
{
this->m_transferred = true;
}
JSC::JSValue nativePtr()
{
return this->m_nativePtr.get();
}
void setNativePtr(JSC::VM&, JSC::JSValue value);
void setNativeType(int value)
{
this->m_nativeType = value;
}
void setDisturbed(bool value)
{
this->m_disturbed = value;
}
DECLARE_VISIT_CHILDREN;
protected:
mutable JSC::WriteBarrier<JSC::Unknown> m_nativePtr;
int m_nativeType { 0 };
bool m_disturbed = false;
bool m_transferred = false;
JSReadableStream(JSC::Structure*, JSDOMGlobalObject&);
void finishCreation(JSC::VM&);
};
} // namespace WebCore

View File

@@ -1,181 +0,0 @@
/*
This file is part of the WebKit open source project.
This file has been generated by generate-bindings.pl. DO NOT MODIFY!
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "config.h"
#include "JSReadableStreamBYOBReader.h"
#include "ExtendedDOMClientIsoSubspaces.h"
#include "ExtendedDOMIsoSubspaces.h"
#include "JSDOMAttribute.h"
#include "JSDOMBinding.h"
#include "JSDOMBuiltinConstructor.h"
#include "JSDOMExceptionHandling.h"
#include "JSDOMGlobalObjectInlines.h"
#include "JSDOMOperation.h"
#include "JSDOMWrapperCache.h"
#include "WebCoreJSClientData.h"
#include <JavaScriptCore/FunctionPrototype.h>
#include <JavaScriptCore/JSCInlines.h>
#include <JavaScriptCore/JSDestructibleObjectHeapCellType.h>
#include <JavaScriptCore/SlotVisitorMacros.h>
#include <JavaScriptCore/SubspaceInlines.h>
#include <wtf/GetPtr.h>
#include <wtf/PointerPreparations.h>
namespace WebCore {
using namespace JSC;
// Functions
// Attributes
static JSC_DECLARE_CUSTOM_GETTER(jsReadableStreamBYOBReaderConstructor);
class JSReadableStreamBYOBReaderPrototype final : public JSC::JSNonFinalObject {
public:
using Base = JSC::JSNonFinalObject;
static JSReadableStreamBYOBReaderPrototype* create(JSC::VM& vm, JSDOMGlobalObject* globalObject, JSC::Structure* structure)
{
JSReadableStreamBYOBReaderPrototype* ptr = new (NotNull, JSC::allocateCell<JSReadableStreamBYOBReaderPrototype>(vm)) JSReadableStreamBYOBReaderPrototype(vm, globalObject, structure);
ptr->finishCreation(vm);
return ptr;
}
DECLARE_INFO;
template<typename CellType, JSC::SubspaceAccess>
static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm)
{
STATIC_ASSERT_ISO_SUBSPACE_SHARABLE(JSReadableStreamBYOBReaderPrototype, Base);
return &vm.plainObjectSpace();
}
static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
{
return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info());
}
private:
JSReadableStreamBYOBReaderPrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure)
: JSC::JSNonFinalObject(vm, structure)
{
}
void finishCreation(JSC::VM&);
};
STATIC_ASSERT_ISO_SUBSPACE_SHARABLE(JSReadableStreamBYOBReaderPrototype, JSReadableStreamBYOBReaderPrototype::Base);
using JSReadableStreamBYOBReaderDOMConstructor = JSDOMBuiltinConstructor<JSReadableStreamBYOBReader>;
template<> const ClassInfo JSReadableStreamBYOBReaderDOMConstructor::s_info = { "ReadableStreamBYOBReader"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSReadableStreamBYOBReaderDOMConstructor) };
template<> JSValue JSReadableStreamBYOBReaderDOMConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject)
{
UNUSED_PARAM(vm);
return globalObject.functionPrototype();
}
template<> void JSReadableStreamBYOBReaderDOMConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject)
{
putDirect(vm, vm.propertyNames->length, jsNumber(1), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
JSString* nameString = jsNontrivialString(vm, "ReadableStreamBYOBReader"_s);
m_originalName.set(vm, this, nameString);
putDirect(vm, vm.propertyNames->name, nameString, JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
putDirect(vm, vm.propertyNames->prototype, JSReadableStreamBYOBReader::prototype(vm, globalObject), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::DontDelete);
}
template<> FunctionExecutable* JSReadableStreamBYOBReaderDOMConstructor::initializeExecutable(VM& vm)
{
return readableStreamBYOBReaderInitializeReadableStreamBYOBReaderCodeGenerator(vm);
}
/* Hash table for prototype */
static const HashTableValue JSReadableStreamBYOBReaderPrototypeTableValues[] = {
{ "constructor"_s, static_cast<unsigned>(JSC::PropertyAttribute::DontEnum), NoIntrinsic, { HashTableValue::GetterSetterType, jsReadableStreamBYOBReaderConstructor, 0 } },
{ "closed"_s, static_cast<unsigned>(JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::Accessor | JSC::PropertyAttribute::Builtin), NoIntrinsic, { HashTableValue::BuiltinAccessorType, readableStreamBYOBReaderClosedCodeGenerator, 0 } },
{ "read"_s, static_cast<unsigned>(JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::Builtin), NoIntrinsic, { HashTableValue::BuiltinGeneratorType, readableStreamBYOBReaderReadCodeGenerator, 0 } },
{ "cancel"_s, static_cast<unsigned>(JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::Builtin), NoIntrinsic, { HashTableValue::BuiltinGeneratorType, readableStreamBYOBReaderCancelCodeGenerator, 0 } },
{ "releaseLock"_s, static_cast<unsigned>(JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::Builtin), NoIntrinsic, { HashTableValue::BuiltinGeneratorType, readableStreamBYOBReaderReleaseLockCodeGenerator, 0 } },
};
const ClassInfo JSReadableStreamBYOBReaderPrototype::s_info = { "ReadableStreamBYOBReader"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSReadableStreamBYOBReaderPrototype) };
void JSReadableStreamBYOBReaderPrototype::finishCreation(VM& vm)
{
Base::finishCreation(vm);
reifyStaticProperties(vm, JSReadableStreamBYOBReader::info(), JSReadableStreamBYOBReaderPrototypeTableValues, *this);
JSC_TO_STRING_TAG_WITHOUT_TRANSITION();
}
const ClassInfo JSReadableStreamBYOBReader::s_info = { "ReadableStreamBYOBReader"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSReadableStreamBYOBReader) };
JSReadableStreamBYOBReader::JSReadableStreamBYOBReader(Structure* structure, JSDOMGlobalObject& globalObject)
: JSDOMObject(structure, globalObject)
{
}
void JSReadableStreamBYOBReader::finishCreation(VM& vm)
{
Base::finishCreation(vm);
ASSERT(inherits(info()));
}
JSObject* JSReadableStreamBYOBReader::createPrototype(VM& vm, JSDOMGlobalObject& globalObject)
{
auto* structure = JSReadableStreamBYOBReaderPrototype::createStructure(vm, &globalObject, globalObject.objectPrototype());
structure->setMayBePrototype(true);
return JSReadableStreamBYOBReaderPrototype::create(vm, &globalObject, structure);
}
JSObject* JSReadableStreamBYOBReader::prototype(VM& vm, JSDOMGlobalObject& globalObject)
{
return getDOMPrototype<JSReadableStreamBYOBReader>(vm, globalObject);
}
JSValue JSReadableStreamBYOBReader::getConstructor(VM& vm, const JSGlobalObject* globalObject)
{
return getDOMConstructor<JSReadableStreamBYOBReaderDOMConstructor, DOMConstructorID::ReadableStreamBYOBReader>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject));
}
void JSReadableStreamBYOBReader::destroy(JSC::JSCell* cell)
{
JSReadableStreamBYOBReader* thisObject = static_cast<JSReadableStreamBYOBReader*>(cell);
thisObject->JSReadableStreamBYOBReader::~JSReadableStreamBYOBReader();
}
JSC_DEFINE_CUSTOM_GETTER(jsReadableStreamBYOBReaderConstructor, (JSGlobalObject * lexicalGlobalObject, JSC::EncodedJSValue thisValue, PropertyName))
{
VM& vm = JSC::getVM(lexicalGlobalObject);
auto throwScope = DECLARE_THROW_SCOPE(vm);
auto* prototype = jsDynamicCast<JSReadableStreamBYOBReaderPrototype*>(JSValue::decode(thisValue));
if (UNLIKELY(!prototype))
return throwVMTypeError(lexicalGlobalObject, throwScope);
return JSValue::encode(JSReadableStreamBYOBReader::getConstructor(JSC::getVM(lexicalGlobalObject), prototype->globalObject()));
}
JSC::GCClient::IsoSubspace* JSReadableStreamBYOBReader::subspaceForImpl(JSC::VM& vm)
{
return WebCore::subspaceForImpl<JSReadableStreamBYOBReader, UseCustomHeapCellType::No>(
vm,
[](auto& spaces) { return spaces.m_clientSubspaceForReadableStreamBYOBReader.get(); },
[](auto& spaces, auto&& space) { spaces.m_clientSubspaceForReadableStreamBYOBReader = std::forward<decltype(space)>(space); },
[](auto& spaces) { return spaces.m_subspaceForReadableStreamBYOBReader.get(); },
[](auto& spaces, auto&& space) { spaces.m_subspaceForReadableStreamBYOBReader = std::forward<decltype(space)>(space); });
}
}

View File

@@ -1,63 +0,0 @@
/*
This file is part of the WebKit open source project.
This file has been generated by generate-bindings.pl. DO NOT MODIFY!
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#pragma once
#include "JSDOMWrapper.h"
namespace WebCore {
class JSReadableStreamBYOBReader : public JSDOMObject {
public:
using Base = JSDOMObject;
static JSReadableStreamBYOBReader* create(JSC::Structure* structure, JSDOMGlobalObject* globalObject)
{
JSReadableStreamBYOBReader* ptr = new (NotNull, JSC::allocateCell<JSReadableStreamBYOBReader>(globalObject->vm())) JSReadableStreamBYOBReader(structure, *globalObject);
ptr->finishCreation(globalObject->vm());
return ptr;
}
static JSC::JSObject* createPrototype(JSC::VM&, JSDOMGlobalObject&);
static JSC::JSObject* prototype(JSC::VM&, JSDOMGlobalObject&);
static void destroy(JSC::JSCell*);
DECLARE_INFO;
static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
{
return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info(), JSC::NonArray);
}
static JSC::JSValue getConstructor(JSC::VM&, const JSC::JSGlobalObject*);
template<typename, JSC::SubspaceAccess mode> static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm)
{
if constexpr (mode == JSC::SubspaceAccess::Concurrently)
return nullptr;
return subspaceForImpl(vm);
}
static JSC::GCClient::IsoSubspace* subspaceForImpl(JSC::VM& vm);
protected:
JSReadableStreamBYOBReader(JSC::Structure*, JSDOMGlobalObject&);
void finishCreation(JSC::VM&);
};
} // namespace WebCore

View File

@@ -1,180 +0,0 @@
/*
This file is part of the WebKit open source project.
This file has been generated by generate-bindings.pl. DO NOT MODIFY!
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "config.h"
#include "JSReadableStreamBYOBRequest.h"
#include "ExtendedDOMClientIsoSubspaces.h"
#include "ExtendedDOMIsoSubspaces.h"
#include "JSDOMAttribute.h"
#include "JSDOMBinding.h"
#include "JSDOMBuiltinConstructor.h"
#include "JSDOMExceptionHandling.h"
#include "JSDOMGlobalObjectInlines.h"
#include "JSDOMOperation.h"
#include "JSDOMWrapperCache.h"
#include "WebCoreJSClientData.h"
#include <JavaScriptCore/FunctionPrototype.h>
#include <JavaScriptCore/JSCInlines.h>
#include <JavaScriptCore/JSDestructibleObjectHeapCellType.h>
#include <JavaScriptCore/SlotVisitorMacros.h>
#include <JavaScriptCore/SubspaceInlines.h>
#include <wtf/GetPtr.h>
#include <wtf/PointerPreparations.h>
namespace WebCore {
using namespace JSC;
// Functions
// Attributes
static JSC_DECLARE_CUSTOM_GETTER(jsReadableStreamBYOBRequestConstructor);
class JSReadableStreamBYOBRequestPrototype final : public JSC::JSNonFinalObject {
public:
using Base = JSC::JSNonFinalObject;
static JSReadableStreamBYOBRequestPrototype* create(JSC::VM& vm, JSDOMGlobalObject* globalObject, JSC::Structure* structure)
{
JSReadableStreamBYOBRequestPrototype* ptr = new (NotNull, JSC::allocateCell<JSReadableStreamBYOBRequestPrototype>(vm)) JSReadableStreamBYOBRequestPrototype(vm, globalObject, structure);
ptr->finishCreation(vm);
return ptr;
}
DECLARE_INFO;
template<typename CellType, JSC::SubspaceAccess>
static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm)
{
STATIC_ASSERT_ISO_SUBSPACE_SHARABLE(JSReadableStreamBYOBRequestPrototype, Base);
return &vm.plainObjectSpace();
}
static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
{
return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info());
}
private:
JSReadableStreamBYOBRequestPrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure)
: JSC::JSNonFinalObject(vm, structure)
{
}
void finishCreation(JSC::VM&);
};
STATIC_ASSERT_ISO_SUBSPACE_SHARABLE(JSReadableStreamBYOBRequestPrototype, JSReadableStreamBYOBRequestPrototype::Base);
using JSReadableStreamBYOBRequestDOMConstructor = JSDOMBuiltinConstructor<JSReadableStreamBYOBRequest>;
template<> const ClassInfo JSReadableStreamBYOBRequestDOMConstructor::s_info = { "ReadableStreamBYOBRequest"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSReadableStreamBYOBRequestDOMConstructor) };
template<> JSValue JSReadableStreamBYOBRequestDOMConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject)
{
UNUSED_PARAM(vm);
return globalObject.functionPrototype();
}
template<> void JSReadableStreamBYOBRequestDOMConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject)
{
putDirect(vm, vm.propertyNames->length, jsNumber(2), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
JSString* nameString = jsNontrivialString(vm, "ReadableStreamBYOBRequest"_s);
m_originalName.set(vm, this, nameString);
putDirect(vm, vm.propertyNames->name, nameString, JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
putDirect(vm, vm.propertyNames->prototype, JSReadableStreamBYOBRequest::prototype(vm, globalObject), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::DontDelete);
}
template<> FunctionExecutable* JSReadableStreamBYOBRequestDOMConstructor::initializeExecutable(VM& vm)
{
return readableStreamBYOBRequestInitializeReadableStreamBYOBRequestCodeGenerator(vm);
}
/* Hash table for prototype */
static const HashTableValue JSReadableStreamBYOBRequestPrototypeTableValues[] = {
{ "constructor"_s, static_cast<unsigned>(JSC::PropertyAttribute::DontEnum), NoIntrinsic, { HashTableValue::GetterSetterType, jsReadableStreamBYOBRequestConstructor, 0 } },
{ "view"_s, static_cast<unsigned>(JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::Accessor | JSC::PropertyAttribute::Builtin), NoIntrinsic, { HashTableValue::BuiltinAccessorType, readableStreamBYOBRequestViewCodeGenerator, 0 } },
{ "respond"_s, static_cast<unsigned>(JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::Builtin), NoIntrinsic, { HashTableValue::BuiltinGeneratorType, readableStreamBYOBRequestRespondCodeGenerator, 0 } },
{ "respondWithNewView"_s, static_cast<unsigned>(JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::Builtin), NoIntrinsic, { HashTableValue::BuiltinGeneratorType, readableStreamBYOBRequestRespondWithNewViewCodeGenerator, 0 } },
};
const ClassInfo JSReadableStreamBYOBRequestPrototype::s_info = { "ReadableStreamBYOBRequest"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSReadableStreamBYOBRequestPrototype) };
void JSReadableStreamBYOBRequestPrototype::finishCreation(VM& vm)
{
Base::finishCreation(vm);
reifyStaticProperties(vm, JSReadableStreamBYOBRequest::info(), JSReadableStreamBYOBRequestPrototypeTableValues, *this);
JSC_TO_STRING_TAG_WITHOUT_TRANSITION();
}
const ClassInfo JSReadableStreamBYOBRequest::s_info = { "ReadableStreamBYOBRequest"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSReadableStreamBYOBRequest) };
JSReadableStreamBYOBRequest::JSReadableStreamBYOBRequest(Structure* structure, JSDOMGlobalObject& globalObject)
: JSDOMObject(structure, globalObject)
{
}
void JSReadableStreamBYOBRequest::finishCreation(VM& vm)
{
Base::finishCreation(vm);
ASSERT(inherits(info()));
}
JSObject* JSReadableStreamBYOBRequest::createPrototype(VM& vm, JSDOMGlobalObject& globalObject)
{
auto* structure = JSReadableStreamBYOBRequestPrototype::createStructure(vm, &globalObject, globalObject.objectPrototype());
structure->setMayBePrototype(true);
return JSReadableStreamBYOBRequestPrototype::create(vm, &globalObject, structure);
}
JSObject* JSReadableStreamBYOBRequest::prototype(VM& vm, JSDOMGlobalObject& globalObject)
{
return getDOMPrototype<JSReadableStreamBYOBRequest>(vm, globalObject);
}
JSValue JSReadableStreamBYOBRequest::getConstructor(VM& vm, const JSGlobalObject* globalObject)
{
return getDOMConstructor<JSReadableStreamBYOBRequestDOMConstructor, DOMConstructorID::ReadableStreamBYOBRequest>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject));
}
void JSReadableStreamBYOBRequest::destroy(JSC::JSCell* cell)
{
JSReadableStreamBYOBRequest* thisObject = static_cast<JSReadableStreamBYOBRequest*>(cell);
thisObject->JSReadableStreamBYOBRequest::~JSReadableStreamBYOBRequest();
}
JSC_DEFINE_CUSTOM_GETTER(jsReadableStreamBYOBRequestConstructor, (JSGlobalObject * lexicalGlobalObject, JSC::EncodedJSValue thisValue, PropertyName))
{
VM& vm = JSC::getVM(lexicalGlobalObject);
auto throwScope = DECLARE_THROW_SCOPE(vm);
auto* prototype = jsDynamicCast<JSReadableStreamBYOBRequestPrototype*>(JSValue::decode(thisValue));
if (UNLIKELY(!prototype))
return throwVMTypeError(lexicalGlobalObject, throwScope);
return JSValue::encode(JSReadableStreamBYOBRequest::getConstructor(JSC::getVM(lexicalGlobalObject), prototype->globalObject()));
}
JSC::GCClient::IsoSubspace* JSReadableStreamBYOBRequest::subspaceForImpl(JSC::VM& vm)
{
return WebCore::subspaceForImpl<JSReadableStreamBYOBRequest, UseCustomHeapCellType::No>(
vm,
[](auto& spaces) { return spaces.m_clientSubspaceForReadableStreamBYOBRequest.get(); },
[](auto& spaces, auto&& space) { spaces.m_clientSubspaceForReadableStreamBYOBRequest = std::forward<decltype(space)>(space); },
[](auto& spaces) { return spaces.m_subspaceForReadableStreamBYOBRequest.get(); },
[](auto& spaces, auto&& space) { spaces.m_subspaceForReadableStreamBYOBRequest = std::forward<decltype(space)>(space); });
}
}

View File

@@ -1,63 +0,0 @@
/*
This file is part of the WebKit open source project.
This file has been generated by generate-bindings.pl. DO NOT MODIFY!
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#pragma once
#include "JSDOMWrapper.h"
namespace WebCore {
class JSReadableStreamBYOBRequest : public JSDOMObject {
public:
using Base = JSDOMObject;
static JSReadableStreamBYOBRequest* create(JSC::Structure* structure, JSDOMGlobalObject* globalObject)
{
JSReadableStreamBYOBRequest* ptr = new (NotNull, JSC::allocateCell<JSReadableStreamBYOBRequest>(globalObject->vm())) JSReadableStreamBYOBRequest(structure, *globalObject);
ptr->finishCreation(globalObject->vm());
return ptr;
}
static JSC::JSObject* createPrototype(JSC::VM&, JSDOMGlobalObject&);
static JSC::JSObject* prototype(JSC::VM&, JSDOMGlobalObject&);
static void destroy(JSC::JSCell*);
DECLARE_INFO;
static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
{
return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info(), JSC::NonArray);
}
static JSC::JSValue getConstructor(JSC::VM&, const JSC::JSGlobalObject*);
template<typename, JSC::SubspaceAccess mode> static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm)
{
if constexpr (mode == JSC::SubspaceAccess::Concurrently)
return nullptr;
return subspaceForImpl(vm);
}
static JSC::GCClient::IsoSubspace* subspaceForImpl(JSC::VM& vm);
protected:
JSReadableStreamBYOBRequest(JSC::Structure*, JSDOMGlobalObject&);
void finishCreation(JSC::VM&);
};
} // namespace WebCore

View File

@@ -1,185 +0,0 @@
/*
This file is part of the WebKit open source project.
This file has been generated by generate-bindings.pl. DO NOT MODIFY!
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "config.h"
#include "JSReadableStreamDefaultController.h"
#include "ExtendedDOMClientIsoSubspaces.h"
#include "ExtendedDOMIsoSubspaces.h"
#include "JSDOMAttribute.h"
#include "JSDOMBinding.h"
#include "JSDOMBuiltinConstructor.h"
#include "JSDOMExceptionHandling.h"
#include "JSDOMGlobalObjectInlines.h"
#include "JSDOMOperation.h"
#include "JSDOMWrapperCache.h"
#include "WebCoreJSClientData.h"
#include <JavaScriptCore/FunctionPrototype.h>
#include <JavaScriptCore/JSCInlines.h>
#include <JavaScriptCore/JSDestructibleObjectHeapCellType.h>
#include <JavaScriptCore/SlotVisitorMacros.h>
#include <JavaScriptCore/SubspaceInlines.h>
#include <wtf/GetPtr.h>
#include <wtf/PointerPreparations.h>
namespace WebCore {
using namespace JSC;
// Functions
// Attributes
static JSC_DECLARE_CUSTOM_GETTER(jsReadableStreamDefaultControllerConstructor);
class JSReadableStreamDefaultControllerPrototype final : public JSC::JSNonFinalObject {
public:
using Base = JSC::JSNonFinalObject;
static JSReadableStreamDefaultControllerPrototype* create(JSC::VM& vm, JSDOMGlobalObject* globalObject, JSC::Structure* structure)
{
JSReadableStreamDefaultControllerPrototype* ptr = new (NotNull, JSC::allocateCell<JSReadableStreamDefaultControllerPrototype>(vm)) JSReadableStreamDefaultControllerPrototype(vm, globalObject, structure);
ptr->finishCreation(vm);
return ptr;
}
DECLARE_INFO;
template<typename CellType, JSC::SubspaceAccess>
static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm)
{
STATIC_ASSERT_ISO_SUBSPACE_SHARABLE(JSReadableStreamDefaultControllerPrototype, Base);
return &vm.plainObjectSpace();
}
static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
{
return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info());
}
private:
JSReadableStreamDefaultControllerPrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure)
: JSC::JSNonFinalObject(vm, structure)
{
}
void finishCreation(JSC::VM&);
};
STATIC_ASSERT_ISO_SUBSPACE_SHARABLE(JSReadableStreamDefaultControllerPrototype, JSReadableStreamDefaultControllerPrototype::Base);
using JSReadableStreamDefaultControllerDOMConstructor = JSDOMBuiltinConstructor<JSReadableStreamDefaultController>;
template<> const ClassInfo JSReadableStreamDefaultControllerDOMConstructor::s_info = { "ReadableStreamDefaultController"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSReadableStreamDefaultControllerDOMConstructor) };
template<> JSValue JSReadableStreamDefaultControllerDOMConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject)
{
UNUSED_PARAM(vm);
return globalObject.functionPrototype();
}
template<> void JSReadableStreamDefaultControllerDOMConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject)
{
putDirect(vm, vm.propertyNames->length, jsNumber(4), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
JSString* nameString = jsNontrivialString(vm, "ReadableStreamDefaultController"_s);
m_originalName.set(vm, this, nameString);
putDirect(vm, vm.propertyNames->name, nameString, JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
putDirect(vm, vm.propertyNames->prototype, JSReadableStreamDefaultController::prototype(vm, globalObject), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::DontDelete);
}
template<> FunctionExecutable* JSReadableStreamDefaultControllerDOMConstructor::initializeExecutable(VM& vm)
{
return readableStreamDefaultControllerInitializeReadableStreamDefaultControllerCodeGenerator(vm);
}
/* Hash table for prototype */
static const HashTableValue JSReadableStreamDefaultControllerPrototypeTableValues[] = {
{ "constructor"_s, static_cast<unsigned>(JSC::PropertyAttribute::DontEnum), NoIntrinsic, { HashTableValue::GetterSetterType, jsReadableStreamDefaultControllerConstructor, 0 } },
{ "desiredSize"_s, static_cast<unsigned>(JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::Accessor | JSC::PropertyAttribute::Builtin), NoIntrinsic, { HashTableValue::BuiltinAccessorType, readableStreamDefaultControllerDesiredSizeCodeGenerator, 0 } },
{ "enqueue"_s, static_cast<unsigned>(JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::Builtin), NoIntrinsic, { HashTableValue::BuiltinGeneratorType, readableStreamDefaultControllerEnqueueCodeGenerator, 0 } },
{ "close"_s, static_cast<unsigned>(JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::Builtin), NoIntrinsic, { HashTableValue::BuiltinGeneratorType, readableStreamDefaultControllerCloseCodeGenerator, 0 } },
{ "error"_s, static_cast<unsigned>(JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::Builtin), NoIntrinsic, { HashTableValue::BuiltinGeneratorType, readableStreamDefaultControllerErrorCodeGenerator, 0 } },
};
const ClassInfo JSReadableStreamDefaultControllerPrototype::s_info = { "ReadableStreamDefaultController"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSReadableStreamDefaultControllerPrototype) };
void JSReadableStreamDefaultControllerPrototype::finishCreation(VM& vm)
{
Base::finishCreation(vm);
reifyStaticProperties(vm, JSReadableStreamDefaultController::info(), JSReadableStreamDefaultControllerPrototypeTableValues, *this);
JSC_TO_STRING_TAG_WITHOUT_TRANSITION();
auto clientData = WebCore::clientData(vm);
this->putDirect(vm, clientData->builtinNames().sinkPublicName(), jsUndefined(), JSC::PropertyAttribute::DontDelete | 0);
}
const ClassInfo JSReadableStreamDefaultController::s_info = { "ReadableStreamDefaultController"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSReadableStreamDefaultController) };
JSReadableStreamDefaultController::JSReadableStreamDefaultController(Structure* structure, JSDOMGlobalObject& globalObject)
: JSDOMObject(structure, globalObject)
{
}
void JSReadableStreamDefaultController::finishCreation(VM& vm)
{
Base::finishCreation(vm);
ASSERT(inherits(info()));
}
JSObject* JSReadableStreamDefaultController::createPrototype(VM& vm, JSDOMGlobalObject& globalObject)
{
auto* structure = JSReadableStreamDefaultControllerPrototype::createStructure(vm, &globalObject, globalObject.objectPrototype());
structure->setMayBePrototype(true);
return JSReadableStreamDefaultControllerPrototype::create(vm, &globalObject, structure);
}
JSObject* JSReadableStreamDefaultController::prototype(VM& vm, JSDOMGlobalObject& globalObject)
{
return getDOMPrototype<JSReadableStreamDefaultController>(vm, globalObject);
}
JSValue JSReadableStreamDefaultController::getConstructor(VM& vm, const JSGlobalObject* globalObject)
{
return getDOMConstructor<JSReadableStreamDefaultControllerDOMConstructor, DOMConstructorID::ReadableStreamDefaultController>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject));
}
void JSReadableStreamDefaultController::destroy(JSC::JSCell* cell)
{
JSReadableStreamDefaultController* thisObject = static_cast<JSReadableStreamDefaultController*>(cell);
thisObject->JSReadableStreamDefaultController::~JSReadableStreamDefaultController();
}
JSC_DEFINE_CUSTOM_GETTER(jsReadableStreamDefaultControllerConstructor, (JSGlobalObject * lexicalGlobalObject, JSC::EncodedJSValue thisValue, PropertyName))
{
VM& vm = JSC::getVM(lexicalGlobalObject);
auto throwScope = DECLARE_THROW_SCOPE(vm);
auto* prototype = jsDynamicCast<JSReadableStreamDefaultControllerPrototype*>(JSValue::decode(thisValue));
if (UNLIKELY(!prototype))
return throwVMTypeError(lexicalGlobalObject, throwScope);
return JSValue::encode(JSReadableStreamDefaultController::getConstructor(JSC::getVM(lexicalGlobalObject), prototype->globalObject()));
}
JSC::GCClient::IsoSubspace* JSReadableStreamDefaultController::subspaceForImpl(JSC::VM& vm)
{
return WebCore::subspaceForImpl<JSReadableStreamDefaultController, UseCustomHeapCellType::No>(
vm,
[](auto& spaces) { return spaces.m_clientSubspaceForReadableStreamDefaultController.get(); },
[](auto& spaces, auto&& space) { spaces.m_clientSubspaceForReadableStreamDefaultController = std::forward<decltype(space)>(space); },
[](auto& spaces) { return spaces.m_subspaceForReadableStreamDefaultController.get(); },
[](auto& spaces, auto&& space) { spaces.m_subspaceForReadableStreamDefaultController = std::forward<decltype(space)>(space); });
}
}

View File

@@ -1,63 +0,0 @@
/*
This file is part of the WebKit open source project.
This file has been generated by generate-bindings.pl. DO NOT MODIFY!
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#pragma once
#include "JSDOMWrapper.h"
namespace WebCore {
class JSReadableStreamDefaultController : public JSDOMObject {
public:
using Base = JSDOMObject;
static JSReadableStreamDefaultController* create(JSC::Structure* structure, JSDOMGlobalObject* globalObject)
{
JSReadableStreamDefaultController* ptr = new (NotNull, JSC::allocateCell<JSReadableStreamDefaultController>(globalObject->vm())) JSReadableStreamDefaultController(structure, *globalObject);
ptr->finishCreation(globalObject->vm());
return ptr;
}
static JSC::JSObject* createPrototype(JSC::VM&, JSDOMGlobalObject&);
static JSC::JSObject* prototype(JSC::VM&, JSDOMGlobalObject&);
static void destroy(JSC::JSCell*);
DECLARE_INFO;
static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
{
return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info(), JSC::NonArray);
}
static JSC::JSValue getConstructor(JSC::VM&, const JSC::JSGlobalObject*);
template<typename, JSC::SubspaceAccess mode> static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm)
{
if constexpr (mode == JSC::SubspaceAccess::Concurrently)
return nullptr;
return subspaceForImpl(vm);
}
static JSC::GCClient::IsoSubspace* subspaceForImpl(JSC::VM& vm);
protected:
JSReadableStreamDefaultController(JSC::Structure*, JSDOMGlobalObject&);
void finishCreation(JSC::VM&);
};
} // namespace WebCore

View File

@@ -1,185 +0,0 @@
/*
This file is part of the WebKit open source project.
This file has been generated by generate-bindings.pl. DO NOT MODIFY!
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "config.h"
#include "JSReadableStreamDefaultReader.h"
#include "ExtendedDOMClientIsoSubspaces.h"
#include "ExtendedDOMIsoSubspaces.h"
#include "JSDOMAttribute.h"
#include "JSDOMBinding.h"
#include "JSDOMBuiltinConstructor.h"
#include "JSDOMExceptionHandling.h"
#include "JSDOMGlobalObjectInlines.h"
#include "JSDOMOperation.h"
#include "JSDOMWrapperCache.h"
#include "WebCoreJSClientData.h"
#include <JavaScriptCore/FunctionPrototype.h>
#include <JavaScriptCore/JSCInlines.h>
#include <JavaScriptCore/JSDestructibleObjectHeapCellType.h>
#include <JavaScriptCore/SlotVisitorMacros.h>
#include <JavaScriptCore/SubspaceInlines.h>
#include <wtf/GetPtr.h>
#include <wtf/PointerPreparations.h>
namespace WebCore {
using namespace JSC;
// Functions
// Attributes
static JSC_DECLARE_CUSTOM_GETTER(jsReadableStreamDefaultReaderConstructor);
class JSReadableStreamDefaultReaderPrototype final : public JSC::JSNonFinalObject {
public:
using Base = JSC::JSNonFinalObject;
static JSReadableStreamDefaultReaderPrototype* create(JSC::VM& vm, JSDOMGlobalObject* globalObject, JSC::Structure* structure)
{
JSReadableStreamDefaultReaderPrototype* ptr = new (NotNull, JSC::allocateCell<JSReadableStreamDefaultReaderPrototype>(vm)) JSReadableStreamDefaultReaderPrototype(vm, globalObject, structure);
ptr->finishCreation(vm);
return ptr;
}
DECLARE_INFO;
template<typename CellType, JSC::SubspaceAccess>
static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm)
{
STATIC_ASSERT_ISO_SUBSPACE_SHARABLE(JSReadableStreamDefaultReaderPrototype, Base);
return &vm.plainObjectSpace();
}
static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
{
return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info());
}
private:
JSReadableStreamDefaultReaderPrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure)
: JSC::JSNonFinalObject(vm, structure)
{
}
void finishCreation(JSC::VM&);
};
STATIC_ASSERT_ISO_SUBSPACE_SHARABLE(JSReadableStreamDefaultReaderPrototype, JSReadableStreamDefaultReaderPrototype::Base);
using JSReadableStreamDefaultReaderDOMConstructor = JSDOMBuiltinConstructor<JSReadableStreamDefaultReader>;
template<> const ClassInfo JSReadableStreamDefaultReaderDOMConstructor::s_info = { "ReadableStreamDefaultReader"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSReadableStreamDefaultReaderDOMConstructor) };
template<> JSValue JSReadableStreamDefaultReaderDOMConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject)
{
UNUSED_PARAM(vm);
return globalObject.functionPrototype();
}
template<> void JSReadableStreamDefaultReaderDOMConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject)
{
putDirect(vm, vm.propertyNames->length, jsNumber(1), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
JSString* nameString = jsNontrivialString(vm, "ReadableStreamDefaultReader"_s);
m_originalName.set(vm, this, nameString);
putDirect(vm, vm.propertyNames->name, nameString, JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
putDirect(vm, vm.propertyNames->prototype, JSReadableStreamDefaultReader::prototype(vm, globalObject), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::DontDelete);
}
template<> FunctionExecutable* JSReadableStreamDefaultReaderDOMConstructor::initializeExecutable(VM& vm)
{
return readableStreamDefaultReaderInitializeReadableStreamDefaultReaderCodeGenerator(vm);
}
/* Hash table for prototype */
static const HashTableValue JSReadableStreamDefaultReaderPrototypeTableValues[] = {
{ "constructor"_s, static_cast<unsigned>(JSC::PropertyAttribute::DontEnum), NoIntrinsic, { HashTableValue::GetterSetterType, jsReadableStreamDefaultReaderConstructor, 0 } },
{ "closed"_s, static_cast<unsigned>(JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::Accessor | JSC::PropertyAttribute::Builtin), NoIntrinsic, { HashTableValue::BuiltinAccessorType, readableStreamDefaultReaderClosedCodeGenerator, 0 } },
{ "read"_s, static_cast<unsigned>(JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::Builtin), NoIntrinsic, { HashTableValue::BuiltinGeneratorType, readableStreamDefaultReaderReadCodeGenerator, 0 } },
{ "readMany"_s, static_cast<unsigned>(JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::Builtin), NoIntrinsic, { HashTableValue::BuiltinGeneratorType, readableStreamDefaultReaderReadManyCodeGenerator, 0 } },
{ "cancel"_s, static_cast<unsigned>(JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::Builtin), NoIntrinsic, { HashTableValue::BuiltinGeneratorType, readableStreamDefaultReaderCancelCodeGenerator, 0 } },
{ "releaseLock"_s, static_cast<unsigned>(JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::Builtin), NoIntrinsic, { HashTableValue::BuiltinGeneratorType, readableStreamDefaultReaderReleaseLockCodeGenerator, 0 } },
};
const ClassInfo JSReadableStreamDefaultReaderPrototype::s_info = { "ReadableStreamDefaultReader"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSReadableStreamDefaultReaderPrototype) };
void JSReadableStreamDefaultReaderPrototype::finishCreation(VM& vm)
{
Base::finishCreation(vm);
reifyStaticProperties(vm, JSReadableStreamDefaultReader::info(), JSReadableStreamDefaultReaderPrototypeTableValues, *this);
JSC_TO_STRING_TAG_WITHOUT_TRANSITION();
// As suggested by https://github.com/tc39/proposal-explicit-resource-management#relation-to-dom-apis
// putDirectWithoutTransition(vm, vm.propertyNames->disposeSymbol, get(globalObject(), PropertyName(Identifier::fromString(vm, "releaseLock"_s))), JSC::PropertyAttribute::DontEnum | 0);
}
const ClassInfo JSReadableStreamDefaultReader::s_info = { "ReadableStreamDefaultReader"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSReadableStreamDefaultReader) };
JSReadableStreamDefaultReader::JSReadableStreamDefaultReader(Structure* structure, JSDOMGlobalObject& globalObject)
: JSDOMObject(structure, globalObject)
{
}
void JSReadableStreamDefaultReader::finishCreation(VM& vm)
{
Base::finishCreation(vm);
ASSERT(inherits(info()));
}
JSObject* JSReadableStreamDefaultReader::createPrototype(VM& vm, JSDOMGlobalObject& globalObject)
{
auto* structure = JSReadableStreamDefaultReaderPrototype::createStructure(vm, &globalObject, globalObject.objectPrototype());
structure->setMayBePrototype(true);
return JSReadableStreamDefaultReaderPrototype::create(vm, &globalObject, structure);
}
JSObject* JSReadableStreamDefaultReader::prototype(VM& vm, JSDOMGlobalObject& globalObject)
{
return getDOMPrototype<JSReadableStreamDefaultReader>(vm, globalObject);
}
JSValue JSReadableStreamDefaultReader::getConstructor(VM& vm, const JSGlobalObject* globalObject)
{
return getDOMConstructor<JSReadableStreamDefaultReaderDOMConstructor, DOMConstructorID::ReadableStreamDefaultReader>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject));
}
void JSReadableStreamDefaultReader::destroy(JSC::JSCell* cell)
{
JSReadableStreamDefaultReader* thisObject = static_cast<JSReadableStreamDefaultReader*>(cell);
thisObject->JSReadableStreamDefaultReader::~JSReadableStreamDefaultReader();
}
JSC_DEFINE_CUSTOM_GETTER(jsReadableStreamDefaultReaderConstructor, (JSGlobalObject * lexicalGlobalObject, JSC::EncodedJSValue thisValue, PropertyName))
{
VM& vm = JSC::getVM(lexicalGlobalObject);
auto throwScope = DECLARE_THROW_SCOPE(vm);
auto* prototype = jsDynamicCast<JSReadableStreamDefaultReaderPrototype*>(JSValue::decode(thisValue));
if (UNLIKELY(!prototype))
return throwVMTypeError(lexicalGlobalObject, throwScope);
return JSValue::encode(JSReadableStreamDefaultReader::getConstructor(JSC::getVM(lexicalGlobalObject), prototype->globalObject()));
}
JSC::GCClient::IsoSubspace* JSReadableStreamDefaultReader::subspaceForImpl(JSC::VM& vm)
{
return WebCore::subspaceForImpl<JSReadableStreamDefaultReader, UseCustomHeapCellType::No>(
vm,
[](auto& spaces) { return spaces.m_clientSubspaceForReadableStreamDefaultReader.get(); },
[](auto& spaces, auto&& space) { spaces.m_clientSubspaceForReadableStreamDefaultReader = std::forward<decltype(space)>(space); },
[](auto& spaces) { return spaces.m_subspaceForReadableStreamDefaultReader.get(); },
[](auto& spaces, auto&& space) { spaces.m_subspaceForReadableStreamDefaultReader = std::forward<decltype(space)>(space); });
}
}

View File

@@ -1,63 +0,0 @@
/*
This file is part of the WebKit open source project.
This file has been generated by generate-bindings.pl. DO NOT MODIFY!
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#pragma once
#include "JSDOMWrapper.h"
namespace WebCore {
class JSReadableStreamDefaultReader : public JSDOMObject {
public:
using Base = JSDOMObject;
static JSReadableStreamDefaultReader* create(JSC::Structure* structure, JSDOMGlobalObject* globalObject)
{
JSReadableStreamDefaultReader* ptr = new (NotNull, JSC::allocateCell<JSReadableStreamDefaultReader>(globalObject->vm())) JSReadableStreamDefaultReader(structure, *globalObject);
ptr->finishCreation(globalObject->vm());
return ptr;
}
static JSC::JSObject* createPrototype(JSC::VM&, JSDOMGlobalObject&);
static JSC::JSObject* prototype(JSC::VM&, JSDOMGlobalObject&);
static void destroy(JSC::JSCell*);
DECLARE_INFO;
static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
{
return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info(), JSC::NonArray);
}
static JSC::JSValue getConstructor(JSC::VM&, const JSC::JSGlobalObject*);
template<typename, JSC::SubspaceAccess mode> static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm)
{
if constexpr (mode == JSC::SubspaceAccess::Concurrently)
return nullptr;
return subspaceForImpl(vm);
}
static JSC::GCClient::IsoSubspace* subspaceForImpl(JSC::VM& vm);
protected:
JSReadableStreamDefaultReader(JSC::Structure*, JSDOMGlobalObject&);
void finishCreation(JSC::VM&);
};
} // namespace WebCore

View File

@@ -1,245 +0,0 @@
/*
This file is part of the WebKit open source project.
This file has been generated by generate-bindings.pl. DO NOT MODIFY!
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "config.h"
#include "JSReadableStreamSink.h"
#include "ActiveDOMObject.h"
#include "ExtendedDOMClientIsoSubspaces.h"
#include "ExtendedDOMIsoSubspaces.h"
#include "IDLTypes.h"
#include "JSDOMBinding.h"
#include "JSDOMConvertBase.h"
#include "JSDOMConvertBufferSource.h"
#include "JSDOMConvertStrings.h"
#include "JSDOMConvertUnion.h"
#include "JSDOMExceptionHandling.h"
#include "JSDOMOperation.h"
#include "JSDOMWrapperCache.h"
#include "ScriptExecutionContext.h"
#include "WebCoreJSClientData.h"
#include <JavaScriptCore/HeapAnalyzer.h>
#include <JavaScriptCore/JSCInlines.h>
#include <JavaScriptCore/JSDestructibleObjectHeapCellType.h>
#include <JavaScriptCore/SlotVisitorMacros.h>
#include <JavaScriptCore/SubspaceInlines.h>
#include <variant>
#include <wtf/GetPtr.h>
#include <wtf/PointerPreparations.h>
#include <wtf/URL.h>
namespace WebCore {
using namespace JSC;
// Functions
static JSC_DECLARE_HOST_FUNCTION(jsReadableStreamSinkPrototypeFunction_enqueue);
static JSC_DECLARE_HOST_FUNCTION(jsReadableStreamSinkPrototypeFunction_close);
static JSC_DECLARE_HOST_FUNCTION(jsReadableStreamSinkPrototypeFunction_error);
class JSReadableStreamSinkPrototype final : public JSC::JSNonFinalObject {
public:
using Base = JSC::JSNonFinalObject;
static JSReadableStreamSinkPrototype* create(JSC::VM& vm, JSDOMGlobalObject* globalObject, JSC::Structure* structure)
{
JSReadableStreamSinkPrototype* ptr = new (NotNull, JSC::allocateCell<JSReadableStreamSinkPrototype>(vm)) JSReadableStreamSinkPrototype(vm, globalObject, structure);
ptr->finishCreation(vm);
return ptr;
}
DECLARE_INFO;
template<typename CellType, JSC::SubspaceAccess>
static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm)
{
STATIC_ASSERT_ISO_SUBSPACE_SHARABLE(JSReadableStreamSinkPrototype, Base);
return &vm.plainObjectSpace();
}
static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
{
return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info());
}
private:
JSReadableStreamSinkPrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure)
: JSC::JSNonFinalObject(vm, structure)
{
}
void finishCreation(JSC::VM&);
};
STATIC_ASSERT_ISO_SUBSPACE_SHARABLE(JSReadableStreamSinkPrototype, JSReadableStreamSinkPrototype::Base);
/* Hash table for prototype */
static const HashTableValue JSReadableStreamSinkPrototypeTableValues[] = {
{ "enqueue"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, jsReadableStreamSinkPrototypeFunction_enqueue, 1 } },
{ "close"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, jsReadableStreamSinkPrototypeFunction_close, 0 } },
{ "error"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, jsReadableStreamSinkPrototypeFunction_error, 1 } },
};
const ClassInfo JSReadableStreamSinkPrototype::s_info = { "ReadableStreamSink"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSReadableStreamSinkPrototype) };
void JSReadableStreamSinkPrototype::finishCreation(VM& vm)
{
Base::finishCreation(vm);
reifyStaticProperties(vm, JSReadableStreamSink::info(), JSReadableStreamSinkPrototypeTableValues, *this);
JSC_TO_STRING_TAG_WITHOUT_TRANSITION();
}
const ClassInfo JSReadableStreamSink::s_info = { "ReadableStreamSink"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSReadableStreamSink) };
JSReadableStreamSink::JSReadableStreamSink(Structure* structure, JSDOMGlobalObject& globalObject, Ref<ReadableStreamSink>&& impl)
: JSDOMWrapper<ReadableStreamSink>(structure, globalObject, WTFMove(impl))
{
}
void JSReadableStreamSink::finishCreation(VM& vm)
{
Base::finishCreation(vm);
ASSERT(inherits(info()));
// static_assert(!std::is_base_of<ActiveDOMObject, ReadableStreamSink>::value, "Interface is not marked as [ActiveDOMObject] even though implementation class subclasses ActiveDOMObject.");
}
JSObject* JSReadableStreamSink::createPrototype(VM& vm, JSDOMGlobalObject& globalObject)
{
auto* structure = JSReadableStreamSinkPrototype::createStructure(vm, &globalObject, globalObject.objectPrototype());
structure->setMayBePrototype(true);
return JSReadableStreamSinkPrototype::create(vm, &globalObject, structure);
}
JSObject* JSReadableStreamSink::prototype(VM& vm, JSDOMGlobalObject& globalObject)
{
return getDOMPrototype<JSReadableStreamSink>(vm, globalObject);
}
void JSReadableStreamSink::destroy(JSC::JSCell* cell)
{
JSReadableStreamSink* thisObject = static_cast<JSReadableStreamSink*>(cell);
thisObject->JSReadableStreamSink::~JSReadableStreamSink();
}
static inline JSC::EncodedJSValue jsReadableStreamSinkPrototypeFunction_enqueueBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation<JSReadableStreamSink>::ClassParameter castedThis)
{
auto& vm = JSC::getVM(lexicalGlobalObject);
auto throwScope = DECLARE_THROW_SCOPE(vm);
UNUSED_PARAM(throwScope);
UNUSED_PARAM(callFrame);
auto& impl = castedThis->wrapped();
if (UNLIKELY(callFrame->argumentCount() < 1))
return throwVMError(lexicalGlobalObject, throwScope, createNotEnoughArgumentsError(lexicalGlobalObject));
EnsureStillAliveScope argument0 = callFrame->uncheckedArgument(0);
auto chunk = convert<IDLUnion<IDLArrayBufferView, IDLArrayBuffer>>(*lexicalGlobalObject, argument0.value());
RETURN_IF_EXCEPTION(throwScope, {});
RELEASE_AND_RETURN(throwScope, JSValue::encode(toJS<IDLUndefined>(*lexicalGlobalObject, throwScope, [&]() -> decltype(auto) { return impl.enqueue(WTFMove(chunk)); })));
}
JSC_DEFINE_HOST_FUNCTION(jsReadableStreamSinkPrototypeFunction_enqueue, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))
{
return IDLOperation<JSReadableStreamSink>::call<jsReadableStreamSinkPrototypeFunction_enqueueBody>(*lexicalGlobalObject, *callFrame, "enqueue");
}
static inline JSC::EncodedJSValue jsReadableStreamSinkPrototypeFunction_closeBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation<JSReadableStreamSink>::ClassParameter castedThis)
{
auto& vm = JSC::getVM(lexicalGlobalObject);
auto throwScope = DECLARE_THROW_SCOPE(vm);
UNUSED_PARAM(throwScope);
UNUSED_PARAM(callFrame);
auto& impl = castedThis->wrapped();
RELEASE_AND_RETURN(throwScope, JSValue::encode(toJS<IDLUndefined>(*lexicalGlobalObject, throwScope, [&]() -> decltype(auto) { return impl.close(); })));
}
JSC_DEFINE_HOST_FUNCTION(jsReadableStreamSinkPrototypeFunction_close, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))
{
return IDLOperation<JSReadableStreamSink>::call<jsReadableStreamSinkPrototypeFunction_closeBody>(*lexicalGlobalObject, *callFrame, "close");
}
static inline JSC::EncodedJSValue jsReadableStreamSinkPrototypeFunction_errorBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation<JSReadableStreamSink>::ClassParameter castedThis)
{
auto& vm = JSC::getVM(lexicalGlobalObject);
auto throwScope = DECLARE_THROW_SCOPE(vm);
UNUSED_PARAM(throwScope);
UNUSED_PARAM(callFrame);
auto& impl = castedThis->wrapped();
if (UNLIKELY(callFrame->argumentCount() < 1))
return throwVMError(lexicalGlobalObject, throwScope, createNotEnoughArgumentsError(lexicalGlobalObject));
EnsureStillAliveScope argument0 = callFrame->uncheckedArgument(0);
auto message = convert<IDLDOMString>(*lexicalGlobalObject, argument0.value());
RETURN_IF_EXCEPTION(throwScope, {});
RELEASE_AND_RETURN(throwScope, JSValue::encode(toJS<IDLUndefined>(*lexicalGlobalObject, throwScope, [&]() -> decltype(auto) { return impl.error(WTFMove(message)); })));
}
JSC_DEFINE_HOST_FUNCTION(jsReadableStreamSinkPrototypeFunction_error, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))
{
return IDLOperation<JSReadableStreamSink>::call<jsReadableStreamSinkPrototypeFunction_errorBody>(*lexicalGlobalObject, *callFrame, "error");
}
JSC::GCClient::IsoSubspace* JSReadableStreamSink::subspaceForImpl(JSC::VM& vm)
{
return WebCore::subspaceForImpl<JSReadableStreamSink, UseCustomHeapCellType::No>(
vm,
[](auto& spaces) { return spaces.m_clientSubspaceForReadableStreamSink.get(); },
[](auto& spaces, auto&& space) { spaces.m_clientSubspaceForReadableStreamSink = std::forward<decltype(space)>(space); },
[](auto& spaces) { return spaces.m_subspaceForReadableStreamSink.get(); },
[](auto& spaces, auto&& space) { spaces.m_subspaceForReadableStreamSink = std::forward<decltype(space)>(space); });
}
void JSReadableStreamSink::analyzeHeap(JSCell* cell, HeapAnalyzer& analyzer)
{
auto* thisObject = jsCast<JSReadableStreamSink*>(cell);
analyzer.setWrappedObjectForCell(cell, &thisObject->wrapped());
if (thisObject->scriptExecutionContext())
analyzer.setLabelForCell(cell, makeString("url "_s, thisObject->scriptExecutionContext()->url().string()));
Base::analyzeHeap(cell, analyzer);
}
bool JSReadableStreamSinkOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, AbstractSlotVisitor& visitor, ASCIILiteral* reason)
{
UNUSED_PARAM(handle);
UNUSED_PARAM(visitor);
UNUSED_PARAM(reason);
return false;
}
void JSReadableStreamSinkOwner::finalize(JSC::Handle<JSC::Unknown> handle, void* context)
{
auto* jsReadableStreamSink = static_cast<JSReadableStreamSink*>(handle.slot()->asCell());
auto& world = *static_cast<DOMWrapperWorld*>(context);
uncacheWrapper(world, &jsReadableStreamSink->wrapped(), jsReadableStreamSink);
}
JSC::JSValue toJSNewlyCreated(JSC::JSGlobalObject*, JSDOMGlobalObject* globalObject, Ref<ReadableStreamSink>&& impl)
{
return createWrapper<ReadableStreamSink>(globalObject, WTFMove(impl));
}
JSC::JSValue toJS(JSC::JSGlobalObject* lexicalGlobalObject, JSDOMGlobalObject* globalObject, ReadableStreamSink& impl)
{
return wrap(lexicalGlobalObject, globalObject, impl);
}
ReadableStreamSink* JSReadableStreamSink::toWrapped(JSC::VM&, JSC::JSValue value)
{
if (auto* wrapper = jsDynamicCast<JSReadableStreamSink*>(value))
return &wrapper->wrapped();
return nullptr;
}
}

View File

@@ -1,93 +0,0 @@
/*
This file is part of the WebKit open source project.
This file has been generated by generate-bindings.pl. DO NOT MODIFY!
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#pragma once
#include "JSDOMWrapper.h"
#include "ReadableStreamSink.h"
#include <wtf/NeverDestroyed.h>
namespace WebCore {
class JSReadableStreamSink : public JSDOMWrapper<ReadableStreamSink> {
public:
using Base = JSDOMWrapper<ReadableStreamSink>;
static JSReadableStreamSink* create(JSC::Structure* structure, JSDOMGlobalObject* globalObject, Ref<ReadableStreamSink>&& impl)
{
JSReadableStreamSink* ptr = new (NotNull, JSC::allocateCell<JSReadableStreamSink>(globalObject->vm())) JSReadableStreamSink(structure, *globalObject, WTFMove(impl));
ptr->finishCreation(globalObject->vm());
return ptr;
}
static JSC::JSObject* createPrototype(JSC::VM&, JSDOMGlobalObject&);
static JSC::JSObject* prototype(JSC::VM&, JSDOMGlobalObject&);
static ReadableStreamSink* toWrapped(JSC::VM&, JSC::JSValue);
static void destroy(JSC::JSCell*);
DECLARE_INFO;
static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
{
return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info(), JSC::NonArray);
}
template<typename, JSC::SubspaceAccess mode> static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm)
{
if constexpr (mode == JSC::SubspaceAccess::Concurrently)
return nullptr;
return subspaceForImpl(vm);
}
static JSC::GCClient::IsoSubspace* subspaceForImpl(JSC::VM& vm);
static void analyzeHeap(JSCell*, JSC::HeapAnalyzer&);
protected:
JSReadableStreamSink(JSC::Structure*, JSDOMGlobalObject&, Ref<ReadableStreamSink>&&);
void finishCreation(JSC::VM&);
};
class JSReadableStreamSinkOwner final : public JSC::WeakHandleOwner {
public:
bool isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown>, void* context, JSC::AbstractSlotVisitor&, ASCIILiteral*) final;
void finalize(JSC::Handle<JSC::Unknown>, void* context) final;
};
inline JSC::WeakHandleOwner* wrapperOwner(DOMWrapperWorld&, ReadableStreamSink*)
{
static NeverDestroyed<JSReadableStreamSinkOwner> owner;
return &owner.get();
}
inline void* wrapperKey(ReadableStreamSink* wrappableObject)
{
return wrappableObject;
}
JSC::JSValue toJS(JSC::JSGlobalObject*, JSDOMGlobalObject*, ReadableStreamSink&);
inline JSC::JSValue toJS(JSC::JSGlobalObject* lexicalGlobalObject, JSDOMGlobalObject* globalObject, ReadableStreamSink* impl) { return impl ? toJS(lexicalGlobalObject, globalObject, *impl) : JSC::jsNull(); }
JSC::JSValue toJSNewlyCreated(JSC::JSGlobalObject*, JSDOMGlobalObject*, Ref<ReadableStreamSink>&&);
inline JSC::JSValue toJSNewlyCreated(JSC::JSGlobalObject* lexicalGlobalObject, JSDOMGlobalObject* globalObject, RefPtr<ReadableStreamSink>&& impl) { return impl ? toJSNewlyCreated(lexicalGlobalObject, globalObject, impl.releaseNonNull()) : JSC::jsNull(); }
template<> struct JSDOMWrapperConverterTraits<ReadableStreamSink> {
using WrapperClass = JSReadableStreamSink;
using ToWrappedReturnType = ReadableStreamSink*;
};
} // namespace WebCore

View File

@@ -1,270 +0,0 @@
/*
This file is part of the WebKit open source project.
This file has been generated by generate-bindings.pl. DO NOT MODIFY!
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "config.h"
#include "JSReadableStreamSource.h"
#include "ActiveDOMObject.h"
#include "ExtendedDOMClientIsoSubspaces.h"
#include "ExtendedDOMIsoSubspaces.h"
#include "IDLTypes.h"
#include "JSDOMAttribute.h"
#include "JSDOMBinding.h"
#include "JSDOMConvertAny.h"
#include "JSDOMConvertBase.h"
#include "JSDOMExceptionHandling.h"
#include "JSDOMOperation.h"
#include "JSDOMOperationReturningPromise.h"
#include "JSDOMWrapperCache.h"
#include "ScriptExecutionContext.h"
#include "WebCoreJSClientData.h"
#include <JavaScriptCore/HeapAnalyzer.h>
#include <JavaScriptCore/JSCInlines.h>
#include <JavaScriptCore/JSDestructibleObjectHeapCellType.h>
#include <JavaScriptCore/SlotVisitorMacros.h>
#include <JavaScriptCore/SubspaceInlines.h>
#include <wtf/GetPtr.h>
#include <wtf/PointerPreparations.h>
#include <wtf/URL.h>
namespace WebCore {
using namespace JSC;
// Functions
static JSC_DECLARE_HOST_FUNCTION(jsReadableStreamSourcePrototypeFunction_start);
static JSC_DECLARE_HOST_FUNCTION(jsReadableStreamSourcePrototypeFunction_pull);
static JSC_DECLARE_HOST_FUNCTION(jsReadableStreamSourcePrototypeFunction_cancel);
// Attributes
static JSC_DECLARE_CUSTOM_GETTER(jsReadableStreamSource_controller);
class JSReadableStreamSourcePrototype final : public JSC::JSNonFinalObject {
public:
using Base = JSC::JSNonFinalObject;
static JSReadableStreamSourcePrototype* create(JSC::VM& vm, JSDOMGlobalObject* globalObject, JSC::Structure* structure)
{
JSReadableStreamSourcePrototype* ptr = new (NotNull, JSC::allocateCell<JSReadableStreamSourcePrototype>(vm)) JSReadableStreamSourcePrototype(vm, globalObject, structure);
ptr->finishCreation(vm);
return ptr;
}
DECLARE_INFO;
template<typename CellType, JSC::SubspaceAccess>
static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm)
{
STATIC_ASSERT_ISO_SUBSPACE_SHARABLE(JSReadableStreamSourcePrototype, Base);
return &vm.plainObjectSpace();
}
static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
{
return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info());
}
private:
JSReadableStreamSourcePrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure)
: JSC::JSNonFinalObject(vm, structure)
{
}
void finishCreation(JSC::VM&);
};
STATIC_ASSERT_ISO_SUBSPACE_SHARABLE(JSReadableStreamSourcePrototype, JSReadableStreamSourcePrototype::Base);
/* Hash table for prototype */
static const HashTableValue JSReadableStreamSourcePrototypeTableValues[] = {
{ "controller"_s, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { HashTableValue::GetterSetterType, jsReadableStreamSource_controller, 0 } },
{ "start"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, jsReadableStreamSourcePrototypeFunction_start, 1 } },
{ "pull"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, jsReadableStreamSourcePrototypeFunction_pull, 1 } },
{ "cancel"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, jsReadableStreamSourcePrototypeFunction_cancel, 1 } },
};
const ClassInfo JSReadableStreamSourcePrototype::s_info = { "ReadableStreamSource"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSReadableStreamSourcePrototype) };
void JSReadableStreamSourcePrototype::finishCreation(VM& vm)
{
Base::finishCreation(vm);
// -- BUN ADDITION --
auto clientData = WebCore::clientData(vm);
this->putDirect(vm, clientData->builtinNames().bunNativePtrPrivateName(), jsNumber(0), JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::DontDelete | 0);
this->putDirect(vm, clientData->builtinNames().bunNativeTypePrivateName(), jsNumber(0), JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::DontDelete | 0);
// -- BUN ADDITION --
reifyStaticProperties(vm, JSReadableStreamSource::info(), JSReadableStreamSourcePrototypeTableValues, *this);
JSC_TO_STRING_TAG_WITHOUT_TRANSITION();
}
const ClassInfo JSReadableStreamSource::s_info = { "ReadableStreamSource"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSReadableStreamSource) };
JSReadableStreamSource::JSReadableStreamSource(Structure* structure, JSDOMGlobalObject& globalObject, Ref<ReadableStreamSource>&& impl)
: JSDOMWrapper<ReadableStreamSource>(structure, globalObject, WTFMove(impl))
{
}
void JSReadableStreamSource::finishCreation(VM& vm)
{
Base::finishCreation(vm);
ASSERT(inherits(info()));
// static_assert(!std::is_base_of<ActiveDOMObject, ReadableStreamSource>::value, "Interface is not marked as [ActiveDOMObject] even though implementation class subclasses ActiveDOMObject.");
}
JSObject* JSReadableStreamSource::createPrototype(VM& vm, JSDOMGlobalObject& globalObject)
{
auto* structure = JSReadableStreamSourcePrototype::createStructure(vm, &globalObject, globalObject.objectPrototype());
structure->setMayBePrototype(true);
return JSReadableStreamSourcePrototype::create(vm, &globalObject, structure);
}
JSObject* JSReadableStreamSource::prototype(VM& vm, JSDOMGlobalObject& globalObject)
{
return getDOMPrototype<JSReadableStreamSource>(vm, globalObject);
}
void JSReadableStreamSource::destroy(JSC::JSCell* cell)
{
JSReadableStreamSource* thisObject = static_cast<JSReadableStreamSource*>(cell);
thisObject->JSReadableStreamSource::~JSReadableStreamSource();
}
static inline JSValue jsReadableStreamSource_controllerGetter(JSGlobalObject& lexicalGlobalObject, JSReadableStreamSource& thisObject)
{
UNUSED_PARAM(lexicalGlobalObject);
return thisObject.controller(lexicalGlobalObject);
}
JSC_DEFINE_CUSTOM_GETTER(jsReadableStreamSource_controller, (JSGlobalObject * lexicalGlobalObject, JSC::EncodedJSValue thisValue, PropertyName attributeName))
{
return IDLAttribute<JSReadableStreamSource>::get<jsReadableStreamSource_controllerGetter, CastedThisErrorBehavior::Assert>(*lexicalGlobalObject, thisValue, attributeName);
}
static inline JSC::EncodedJSValue jsReadableStreamSourcePrototypeFunction_startBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperationReturningPromise<JSReadableStreamSource>::ClassParameter castedThis, Ref<DeferredPromise>&& promise)
{
auto& vm = JSC::getVM(lexicalGlobalObject);
auto throwScope = DECLARE_THROW_SCOPE(vm);
UNUSED_PARAM(throwScope);
UNUSED_PARAM(callFrame);
RELEASE_AND_RETURN(throwScope, (JSValue::encode(castedThis->start(*lexicalGlobalObject, *callFrame, WTFMove(promise)))));
}
JSC_DEFINE_HOST_FUNCTION(jsReadableStreamSourcePrototypeFunction_start, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))
{
return IDLOperationReturningPromise<JSReadableStreamSource>::call<jsReadableStreamSourcePrototypeFunction_startBody>(*lexicalGlobalObject, *callFrame, "start");
}
static inline JSC::EncodedJSValue jsReadableStreamSourcePrototypeFunction_pullBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperationReturningPromise<JSReadableStreamSource>::ClassParameter castedThis, Ref<DeferredPromise>&& promise)
{
auto& vm = JSC::getVM(lexicalGlobalObject);
auto throwScope = DECLARE_THROW_SCOPE(vm);
UNUSED_PARAM(throwScope);
UNUSED_PARAM(callFrame);
RELEASE_AND_RETURN(throwScope, (JSValue::encode(castedThis->pull(*lexicalGlobalObject, *callFrame, WTFMove(promise)))));
}
JSC_DEFINE_HOST_FUNCTION(jsReadableStreamSourcePrototypeFunction_pull, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))
{
return IDLOperationReturningPromise<JSReadableStreamSource>::call<jsReadableStreamSourcePrototypeFunction_pullBody>(*lexicalGlobalObject, *callFrame, "pull");
}
static inline JSC::EncodedJSValue jsReadableStreamSourcePrototypeFunction_cancelBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation<JSReadableStreamSource>::ClassParameter castedThis)
{
auto& vm = JSC::getVM(lexicalGlobalObject);
auto throwScope = DECLARE_THROW_SCOPE(vm);
UNUSED_PARAM(throwScope);
UNUSED_PARAM(callFrame);
auto& impl = castedThis->wrapped();
if (UNLIKELY(callFrame->argumentCount() < 1))
return throwVMError(lexicalGlobalObject, throwScope, createNotEnoughArgumentsError(lexicalGlobalObject));
EnsureStillAliveScope argument0 = callFrame->uncheckedArgument(0);
auto reason = convert<IDLAny>(*lexicalGlobalObject, argument0.value());
RETURN_IF_EXCEPTION(throwScope, {});
RELEASE_AND_RETURN(throwScope, JSValue::encode(toJS<IDLUndefined>(*lexicalGlobalObject, throwScope, [&]() -> decltype(auto) { return impl.cancel(WTFMove(reason)); })));
}
JSC_DEFINE_HOST_FUNCTION(jsReadableStreamSourcePrototypeFunction_cancel, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))
{
return IDLOperation<JSReadableStreamSource>::call<jsReadableStreamSourcePrototypeFunction_cancelBody>(*lexicalGlobalObject, *callFrame, "cancel");
}
JSC::GCClient::IsoSubspace* JSReadableStreamSource::subspaceForImpl(JSC::VM& vm)
{
return WebCore::subspaceForImpl<JSReadableStreamSource, UseCustomHeapCellType::No>(
vm,
[](auto& spaces) { return spaces.m_clientSubspaceForReadableStreamSource.get(); },
[](auto& spaces, auto&& space) { spaces.m_clientSubspaceForReadableStreamSource = std::forward<decltype(space)>(space); },
[](auto& spaces) { return spaces.m_subspaceForReadableStreamSource.get(); },
[](auto& spaces, auto&& space) { spaces.m_subspaceForReadableStreamSource = std::forward<decltype(space)>(space); });
}
template<typename Visitor>
void JSReadableStreamSource::visitChildrenImpl(JSCell* cell, Visitor& visitor)
{
auto* thisObject = jsCast<JSReadableStreamSource*>(cell);
ASSERT_GC_OBJECT_INHERITS(thisObject, info());
Base::visitChildren(thisObject, visitor);
visitor.append(thisObject->m_controller);
}
DEFINE_VISIT_CHILDREN(JSReadableStreamSource);
void JSReadableStreamSource::analyzeHeap(JSCell* cell, HeapAnalyzer& analyzer)
{
auto* thisObject = jsCast<JSReadableStreamSource*>(cell);
analyzer.setWrappedObjectForCell(cell, &thisObject->wrapped());
if (thisObject->scriptExecutionContext())
analyzer.setLabelForCell(cell, makeString("url "_s, thisObject->scriptExecutionContext()->url().string()));
Base::analyzeHeap(cell, analyzer);
}
bool JSReadableStreamSourceOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, AbstractSlotVisitor& visitor, ASCIILiteral* reason)
{
UNUSED_PARAM(handle);
UNUSED_PARAM(visitor);
UNUSED_PARAM(reason);
return false;
}
void JSReadableStreamSourceOwner::finalize(JSC::Handle<JSC::Unknown> handle, void* context)
{
auto* jsReadableStreamSource = static_cast<JSReadableStreamSource*>(handle.slot()->asCell());
auto& world = *static_cast<DOMWrapperWorld*>(context);
uncacheWrapper(world, &jsReadableStreamSource->wrapped(), jsReadableStreamSource);
}
JSC::JSValue toJSNewlyCreated(JSC::JSGlobalObject*, JSDOMGlobalObject* globalObject, Ref<ReadableStreamSource>&& impl)
{
return createWrapper<ReadableStreamSource>(globalObject, WTFMove(impl));
}
JSC::JSValue toJS(JSC::JSGlobalObject* lexicalGlobalObject, JSDOMGlobalObject* globalObject, ReadableStreamSource& impl)
{
return wrap(lexicalGlobalObject, globalObject, impl);
}
ReadableStreamSource* JSReadableStreamSource::toWrapped(JSC::VM&, JSC::JSValue value)
{
if (auto* wrapper = jsDynamicCast<JSReadableStreamSource*>(value))
return &wrapper->wrapped();
return nullptr;
}
}

View File

@@ -1,103 +0,0 @@
/*
This file is part of the WebKit open source project.
This file has been generated by generate-bindings.pl. DO NOT MODIFY!
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#pragma once
#include "JSDOMWrapper.h"
#include "ReadableStreamSource.h"
#include <wtf/NeverDestroyed.h>
namespace WebCore {
class JSReadableStreamSource : public JSDOMWrapper<ReadableStreamSource> {
public:
using Base = JSDOMWrapper<ReadableStreamSource>;
static JSReadableStreamSource* create(JSC::Structure* structure, JSDOMGlobalObject* globalObject, Ref<ReadableStreamSource>&& impl)
{
JSReadableStreamSource* ptr = new (NotNull, JSC::allocateCell<JSReadableStreamSource>(globalObject->vm())) JSReadableStreamSource(structure, *globalObject, WTFMove(impl));
ptr->finishCreation(globalObject->vm());
return ptr;
}
static JSC::JSObject* createPrototype(JSC::VM&, JSDOMGlobalObject&);
static JSC::JSObject* prototype(JSC::VM&, JSDOMGlobalObject&);
static ReadableStreamSource* toWrapped(JSC::VM&, JSC::JSValue);
static void destroy(JSC::JSCell*);
DECLARE_INFO;
static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
{
return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info(), JSC::NonArray);
}
mutable JSC::WriteBarrier<JSC::Unknown> m_controller;
template<typename, JSC::SubspaceAccess mode> static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm)
{
if constexpr (mode == JSC::SubspaceAccess::Concurrently)
return nullptr;
return subspaceForImpl(vm);
}
static JSC::GCClient::IsoSubspace* subspaceForImpl(JSC::VM& vm);
DECLARE_VISIT_CHILDREN;
static void analyzeHeap(JSCell*, JSC::HeapAnalyzer&);
// Custom attributes
JSC::JSValue controller(JSC::JSGlobalObject&) const;
// Custom functions
JSC::JSValue start(JSC::JSGlobalObject&, JSC::CallFrame&, Ref<DeferredPromise>&&);
JSC::JSValue pull(JSC::JSGlobalObject&, JSC::CallFrame&, Ref<DeferredPromise>&&);
protected:
JSReadableStreamSource(JSC::Structure*, JSDOMGlobalObject&, Ref<ReadableStreamSource>&&);
void finishCreation(JSC::VM&);
};
class JSReadableStreamSourceOwner final : public JSC::WeakHandleOwner {
public:
bool isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown>, void* context, JSC::AbstractSlotVisitor&, ASCIILiteral*) final;
void finalize(JSC::Handle<JSC::Unknown>, void* context) final;
};
inline JSC::WeakHandleOwner* wrapperOwner(DOMWrapperWorld&, ReadableStreamSource*)
{
static NeverDestroyed<JSReadableStreamSourceOwner> owner;
return &owner.get();
}
inline void* wrapperKey(ReadableStreamSource* wrappableObject)
{
return wrappableObject;
}
JSC::JSValue toJS(JSC::JSGlobalObject*, JSDOMGlobalObject*, ReadableStreamSource&);
inline JSC::JSValue toJS(JSC::JSGlobalObject* lexicalGlobalObject, JSDOMGlobalObject* globalObject, ReadableStreamSource* impl) { return impl ? toJS(lexicalGlobalObject, globalObject, *impl) : JSC::jsNull(); }
JSC::JSValue toJSNewlyCreated(JSC::JSGlobalObject*, JSDOMGlobalObject*, Ref<ReadableStreamSource>&&);
inline JSC::JSValue toJSNewlyCreated(JSC::JSGlobalObject* lexicalGlobalObject, JSDOMGlobalObject* globalObject, RefPtr<ReadableStreamSource>&& impl) { return impl ? toJSNewlyCreated(lexicalGlobalObject, globalObject, impl.releaseNonNull()) : JSC::jsNull(); }
template<> struct JSDOMWrapperConverterTraits<ReadableStreamSource> {
using WrapperClass = JSReadableStreamSource;
using ToWrappedReturnType = ReadableStreamSource*;
};
} // namespace WebCore

View File

@@ -1,65 +0,0 @@
/*
* 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 required to be 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.
* 3. Neither the name of Canon Inc. nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* 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.
*/
#include "config.h"
#include "JSReadableStreamSource.h"
#include "JSDOMPromiseDeferred.h"
namespace WebCore {
using namespace JSC;
JSValue JSReadableStreamSource::start(JSGlobalObject& lexicalGlobalObject, CallFrame& callFrame, Ref<DeferredPromise>&& promise)
{
VM& vm = lexicalGlobalObject.vm();
// FIXME: Why is it ok to ASSERT the argument count here?
ASSERT(callFrame.argumentCount());
JSReadableStreamDefaultController* controller = jsDynamicCast<JSReadableStreamDefaultController*>(callFrame.uncheckedArgument(0));
ASSERT(controller);
m_controller.set(vm, this, controller);
wrapped().start(ReadableStreamDefaultController(controller), WTFMove(promise));
return jsUndefined();
}
JSValue JSReadableStreamSource::pull(JSGlobalObject&, CallFrame&, Ref<DeferredPromise>&& promise)
{
wrapped().pull(WTFMove(promise));
return jsUndefined();
}
JSValue JSReadableStreamSource::controller(JSGlobalObject&) const
{
ASSERT_NOT_REACHED();
return jsUndefined();
}
}

View File

@@ -1,177 +0,0 @@
/*
This file is part of the WebKit open source project.
This file has been generated by generate-bindings.pl. DO NOT MODIFY!
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "config.h"
#include "JSTransformStream.h"
#include "ExtendedDOMClientIsoSubspaces.h"
#include "ExtendedDOMIsoSubspaces.h"
#include "JSDOMAttribute.h"
#include "JSDOMBinding.h"
#include "JSDOMBuiltinConstructor.h"
#include "JSDOMExceptionHandling.h"
#include "JSDOMGlobalObjectInlines.h"
#include "JSDOMWrapperCache.h"
#include "WebCoreJSClientData.h"
#include <JavaScriptCore/FunctionPrototype.h>
#include <JavaScriptCore/JSCInlines.h>
#include <JavaScriptCore/JSDestructibleObjectHeapCellType.h>
#include <JavaScriptCore/SlotVisitorMacros.h>
#include <JavaScriptCore/SubspaceInlines.h>
#include <wtf/GetPtr.h>
#include <wtf/PointerPreparations.h>
namespace WebCore {
using namespace JSC;
// Attributes
static JSC_DECLARE_CUSTOM_GETTER(jsTransformStreamConstructor);
class JSTransformStreamPrototype final : public JSC::JSNonFinalObject {
public:
using Base = JSC::JSNonFinalObject;
static JSTransformStreamPrototype* create(JSC::VM& vm, JSDOMGlobalObject* globalObject, JSC::Structure* structure)
{
JSTransformStreamPrototype* ptr = new (NotNull, JSC::allocateCell<JSTransformStreamPrototype>(vm)) JSTransformStreamPrototype(vm, globalObject, structure);
ptr->finishCreation(vm);
return ptr;
}
DECLARE_INFO;
template<typename CellType, JSC::SubspaceAccess>
static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm)
{
STATIC_ASSERT_ISO_SUBSPACE_SHARABLE(JSTransformStreamPrototype, Base);
return &vm.plainObjectSpace();
}
static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
{
return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info());
}
private:
JSTransformStreamPrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure)
: JSC::JSNonFinalObject(vm, structure)
{
}
void finishCreation(JSC::VM&);
};
STATIC_ASSERT_ISO_SUBSPACE_SHARABLE(JSTransformStreamPrototype, JSTransformStreamPrototype::Base);
using JSTransformStreamDOMConstructor = JSDOMBuiltinConstructor<JSTransformStream>;
template<> const ClassInfo JSTransformStreamDOMConstructor::s_info = { "TransformStream"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSTransformStreamDOMConstructor) };
template<> JSValue JSTransformStreamDOMConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject)
{
UNUSED_PARAM(vm);
return globalObject.functionPrototype();
}
template<> void JSTransformStreamDOMConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject)
{
putDirect(vm, vm.propertyNames->length, jsNumber(0), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
JSString* nameString = jsNontrivialString(vm, "TransformStream"_s);
m_originalName.set(vm, this, nameString);
putDirect(vm, vm.propertyNames->name, nameString, JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
putDirect(vm, vm.propertyNames->prototype, JSTransformStream::prototype(vm, globalObject), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::DontDelete);
}
template<> FunctionExecutable* JSTransformStreamDOMConstructor::initializeExecutable(VM& vm)
{
return transformStreamInitializeTransformStreamCodeGenerator(vm);
}
/* Hash table for prototype */
static const HashTableValue JSTransformStreamPrototypeTableValues[] = {
{ "constructor"_s, static_cast<unsigned>(JSC::PropertyAttribute::DontEnum), NoIntrinsic, { HashTableValue::GetterSetterType, jsTransformStreamConstructor, 0 } },
{ "readable"_s, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::Accessor | JSC::PropertyAttribute::Builtin), NoIntrinsic, { HashTableValue::BuiltinAccessorType, transformStreamReadableCodeGenerator, 0 } },
{ "writable"_s, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::Accessor | JSC::PropertyAttribute::Builtin), NoIntrinsic, { HashTableValue::BuiltinAccessorType, transformStreamWritableCodeGenerator, 0 } },
};
const ClassInfo JSTransformStreamPrototype::s_info = { "TransformStream"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSTransformStreamPrototype) };
void JSTransformStreamPrototype::finishCreation(VM& vm)
{
Base::finishCreation(vm);
reifyStaticProperties(vm, JSTransformStream::info(), JSTransformStreamPrototypeTableValues, *this);
JSC_TO_STRING_TAG_WITHOUT_TRANSITION();
}
const ClassInfo JSTransformStream::s_info = { "TransformStream"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSTransformStream) };
JSTransformStream::JSTransformStream(Structure* structure, JSDOMGlobalObject& globalObject)
: JSDOMObject(structure, globalObject)
{
}
void JSTransformStream::finishCreation(VM& vm)
{
Base::finishCreation(vm);
ASSERT(inherits(info()));
}
JSObject* JSTransformStream::createPrototype(VM& vm, JSDOMGlobalObject& globalObject)
{
auto* structure = JSTransformStreamPrototype::createStructure(vm, &globalObject, globalObject.objectPrototype());
structure->setMayBePrototype(true);
return JSTransformStreamPrototype::create(vm, &globalObject, structure);
}
JSObject* JSTransformStream::prototype(VM& vm, JSDOMGlobalObject& globalObject)
{
return getDOMPrototype<JSTransformStream>(vm, globalObject);
}
JSValue JSTransformStream::getConstructor(VM& vm, const JSGlobalObject* globalObject)
{
return getDOMConstructor<JSTransformStreamDOMConstructor, DOMConstructorID::TransformStream>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject));
}
void JSTransformStream::destroy(JSC::JSCell* cell)
{
JSTransformStream* thisObject = static_cast<JSTransformStream*>(cell);
thisObject->JSTransformStream::~JSTransformStream();
}
JSC_DEFINE_CUSTOM_GETTER(jsTransformStreamConstructor, (JSGlobalObject * lexicalGlobalObject, JSC::EncodedJSValue thisValue, PropertyName))
{
VM& vm = JSC::getVM(lexicalGlobalObject);
auto throwScope = DECLARE_THROW_SCOPE(vm);
auto* prototype = jsDynamicCast<JSTransformStreamPrototype*>(JSValue::decode(thisValue));
if (UNLIKELY(!prototype))
return throwVMTypeError(lexicalGlobalObject, throwScope);
return JSValue::encode(JSTransformStream::getConstructor(JSC::getVM(lexicalGlobalObject), prototype->globalObject()));
}
JSC::GCClient::IsoSubspace* JSTransformStream::subspaceForImpl(JSC::VM& vm)
{
return WebCore::subspaceForImpl<JSTransformStream, UseCustomHeapCellType::No>(
vm,
[](auto& spaces) { return spaces.m_clientSubspaceForTransformStream.get(); },
[](auto& spaces, auto&& space) { spaces.m_clientSubspaceForTransformStream = std::forward<decltype(space)>(space); },
[](auto& spaces) { return spaces.m_subspaceForTransformStream.get(); },
[](auto& spaces, auto&& space) { spaces.m_subspaceForTransformStream = std::forward<decltype(space)>(space); });
}
}

View File

@@ -1,63 +0,0 @@
/*
This file is part of the WebKit open source project.
This file has been generated by generate-bindings.pl. DO NOT MODIFY!
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#pragma once
#include "JSDOMWrapper.h"
namespace WebCore {
class JSTransformStream : public JSDOMObject {
public:
using Base = JSDOMObject;
static JSTransformStream* create(JSC::Structure* structure, JSDOMGlobalObject* globalObject)
{
JSTransformStream* ptr = new (NotNull, JSC::allocateCell<JSTransformStream>(globalObject->vm())) JSTransformStream(structure, *globalObject);
ptr->finishCreation(globalObject->vm());
return ptr;
}
static JSC::JSObject* createPrototype(JSC::VM&, JSDOMGlobalObject&);
static JSC::JSObject* prototype(JSC::VM&, JSDOMGlobalObject&);
static void destroy(JSC::JSCell*);
DECLARE_INFO;
static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
{
return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info(), JSC::NonArray);
}
static JSC::JSValue getConstructor(JSC::VM&, const JSC::JSGlobalObject*);
template<typename, JSC::SubspaceAccess mode> static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm)
{
if constexpr (mode == JSC::SubspaceAccess::Concurrently)
return nullptr;
return subspaceForImpl(vm);
}
static JSC::GCClient::IsoSubspace* subspaceForImpl(JSC::VM& vm);
protected:
JSTransformStream(JSC::Structure*, JSDOMGlobalObject&);
void finishCreation(JSC::VM&);
};
} // namespace WebCore

View File

@@ -1,181 +0,0 @@
/*
This file is part of the WebKit open source project.
This file has been generated by generate-bindings.pl. DO NOT MODIFY!
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "config.h"
#include "JSTransformStreamDefaultController.h"
#include "ExtendedDOMClientIsoSubspaces.h"
#include "ExtendedDOMIsoSubspaces.h"
#include "JSDOMAttribute.h"
#include "JSDOMBinding.h"
#include "JSDOMBuiltinConstructor.h"
#include "JSDOMExceptionHandling.h"
#include "JSDOMGlobalObjectInlines.h"
#include "JSDOMOperation.h"
#include "JSDOMWrapperCache.h"
#include "WebCoreJSClientData.h"
#include <JavaScriptCore/FunctionPrototype.h>
#include <JavaScriptCore/JSCInlines.h>
#include <JavaScriptCore/JSDestructibleObjectHeapCellType.h>
#include <JavaScriptCore/SlotVisitorMacros.h>
#include <JavaScriptCore/SubspaceInlines.h>
#include <wtf/GetPtr.h>
#include <wtf/PointerPreparations.h>
namespace WebCore {
using namespace JSC;
// Functions
// Attributes
static JSC_DECLARE_CUSTOM_GETTER(jsTransformStreamDefaultControllerConstructor);
class JSTransformStreamDefaultControllerPrototype final : public JSC::JSNonFinalObject {
public:
using Base = JSC::JSNonFinalObject;
static JSTransformStreamDefaultControllerPrototype* create(JSC::VM& vm, JSDOMGlobalObject* globalObject, JSC::Structure* structure)
{
JSTransformStreamDefaultControllerPrototype* ptr = new (NotNull, JSC::allocateCell<JSTransformStreamDefaultControllerPrototype>(vm)) JSTransformStreamDefaultControllerPrototype(vm, globalObject, structure);
ptr->finishCreation(vm);
return ptr;
}
DECLARE_INFO;
template<typename CellType, JSC::SubspaceAccess>
static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm)
{
STATIC_ASSERT_ISO_SUBSPACE_SHARABLE(JSTransformStreamDefaultControllerPrototype, Base);
return &vm.plainObjectSpace();
}
static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
{
return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info());
}
private:
JSTransformStreamDefaultControllerPrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure)
: JSC::JSNonFinalObject(vm, structure)
{
}
void finishCreation(JSC::VM&);
};
STATIC_ASSERT_ISO_SUBSPACE_SHARABLE(JSTransformStreamDefaultControllerPrototype, JSTransformStreamDefaultControllerPrototype::Base);
using JSTransformStreamDefaultControllerDOMConstructor = JSDOMBuiltinConstructor<JSTransformStreamDefaultController>;
template<> const ClassInfo JSTransformStreamDefaultControllerDOMConstructor::s_info = { "TransformStreamDefaultController"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSTransformStreamDefaultControllerDOMConstructor) };
template<> JSValue JSTransformStreamDefaultControllerDOMConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject)
{
UNUSED_PARAM(vm);
return globalObject.functionPrototype();
}
template<> void JSTransformStreamDefaultControllerDOMConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject)
{
putDirect(vm, vm.propertyNames->length, jsNumber(0), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
JSString* nameString = jsNontrivialString(vm, "TransformStreamDefaultController"_s);
m_originalName.set(vm, this, nameString);
putDirect(vm, vm.propertyNames->name, nameString, JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
putDirect(vm, vm.propertyNames->prototype, JSTransformStreamDefaultController::prototype(vm, globalObject), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::DontDelete);
}
template<> FunctionExecutable* JSTransformStreamDefaultControllerDOMConstructor::initializeExecutable(VM& vm)
{
return transformStreamDefaultControllerInitializeTransformStreamDefaultControllerCodeGenerator(vm);
}
/* Hash table for prototype */
static const HashTableValue JSTransformStreamDefaultControllerPrototypeTableValues[] = {
{ "constructor"_s, static_cast<unsigned>(JSC::PropertyAttribute::DontEnum), NoIntrinsic, { HashTableValue::GetterSetterType, jsTransformStreamDefaultControllerConstructor, 0 } },
{ "desiredSize"_s, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::Accessor | JSC::PropertyAttribute::Builtin), NoIntrinsic, { HashTableValue::BuiltinAccessorType, transformStreamDefaultControllerDesiredSizeCodeGenerator, 0 } },
{ "enqueue"_s, static_cast<unsigned>(JSC::PropertyAttribute::Builtin), NoIntrinsic, { HashTableValue::BuiltinGeneratorType, transformStreamDefaultControllerEnqueueCodeGenerator, 0 } },
{ "error"_s, static_cast<unsigned>(JSC::PropertyAttribute::Builtin), NoIntrinsic, { HashTableValue::BuiltinGeneratorType, transformStreamDefaultControllerErrorCodeGenerator, 0 } },
{ "terminate"_s, static_cast<unsigned>(JSC::PropertyAttribute::Builtin), NoIntrinsic, { HashTableValue::BuiltinGeneratorType, transformStreamDefaultControllerTerminateCodeGenerator, 0 } },
};
const ClassInfo JSTransformStreamDefaultControllerPrototype::s_info = { "TransformStreamDefaultController"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSTransformStreamDefaultControllerPrototype) };
void JSTransformStreamDefaultControllerPrototype::finishCreation(VM& vm)
{
Base::finishCreation(vm);
reifyStaticProperties(vm, JSTransformStreamDefaultController::info(), JSTransformStreamDefaultControllerPrototypeTableValues, *this);
JSC_TO_STRING_TAG_WITHOUT_TRANSITION();
}
const ClassInfo JSTransformStreamDefaultController::s_info = { "TransformStreamDefaultController"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSTransformStreamDefaultController) };
JSTransformStreamDefaultController::JSTransformStreamDefaultController(Structure* structure, JSDOMGlobalObject& globalObject)
: JSDOMObject(structure, globalObject)
{
}
void JSTransformStreamDefaultController::finishCreation(VM& vm)
{
Base::finishCreation(vm);
ASSERT(inherits(info()));
}
JSObject* JSTransformStreamDefaultController::createPrototype(VM& vm, JSDOMGlobalObject& globalObject)
{
auto* structure = JSTransformStreamDefaultControllerPrototype::createStructure(vm, &globalObject, globalObject.objectPrototype());
structure->setMayBePrototype(true);
return JSTransformStreamDefaultControllerPrototype::create(vm, &globalObject, structure);
}
JSObject* JSTransformStreamDefaultController::prototype(VM& vm, JSDOMGlobalObject& globalObject)
{
return getDOMPrototype<JSTransformStreamDefaultController>(vm, globalObject);
}
JSValue JSTransformStreamDefaultController::getConstructor(VM& vm, const JSGlobalObject* globalObject)
{
return getDOMConstructor<JSTransformStreamDefaultControllerDOMConstructor, DOMConstructorID::TransformStreamDefaultController>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject));
}
void JSTransformStreamDefaultController::destroy(JSC::JSCell* cell)
{
JSTransformStreamDefaultController* thisObject = static_cast<JSTransformStreamDefaultController*>(cell);
thisObject->JSTransformStreamDefaultController::~JSTransformStreamDefaultController();
}
JSC_DEFINE_CUSTOM_GETTER(jsTransformStreamDefaultControllerConstructor, (JSGlobalObject * lexicalGlobalObject, JSC::EncodedJSValue thisValue, PropertyName))
{
VM& vm = JSC::getVM(lexicalGlobalObject);
auto throwScope = DECLARE_THROW_SCOPE(vm);
auto* prototype = jsDynamicCast<JSTransformStreamDefaultControllerPrototype*>(JSValue::decode(thisValue));
if (UNLIKELY(!prototype))
return throwVMTypeError(lexicalGlobalObject, throwScope);
return JSValue::encode(JSTransformStreamDefaultController::getConstructor(JSC::getVM(lexicalGlobalObject), prototype->globalObject()));
}
JSC::GCClient::IsoSubspace* JSTransformStreamDefaultController::subspaceForImpl(JSC::VM& vm)
{
return WebCore::subspaceForImpl<JSTransformStreamDefaultController, UseCustomHeapCellType::No>(
vm,
[](auto& spaces) { return spaces.m_clientSubspaceForTransformStreamDefaultController.get(); },
[](auto& spaces, auto&& space) { spaces.m_clientSubspaceForTransformStreamDefaultController = std::forward<decltype(space)>(space); },
[](auto& spaces) { return spaces.m_subspaceForTransformStreamDefaultController.get(); },
[](auto& spaces, auto&& space) { spaces.m_subspaceForTransformStreamDefaultController = std::forward<decltype(space)>(space); });
}
}

View File

@@ -1,63 +0,0 @@
/*
This file is part of the WebKit open source project.
This file has been generated by generate-bindings.pl. DO NOT MODIFY!
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#pragma once
#include "JSDOMWrapper.h"
namespace WebCore {
class JSTransformStreamDefaultController : public JSDOMObject {
public:
using Base = JSDOMObject;
static JSTransformStreamDefaultController* create(JSC::Structure* structure, JSDOMGlobalObject* globalObject)
{
JSTransformStreamDefaultController* ptr = new (NotNull, JSC::allocateCell<JSTransformStreamDefaultController>(globalObject->vm())) JSTransformStreamDefaultController(structure, *globalObject);
ptr->finishCreation(globalObject->vm());
return ptr;
}
static JSC::JSObject* createPrototype(JSC::VM&, JSDOMGlobalObject&);
static JSC::JSObject* prototype(JSC::VM&, JSDOMGlobalObject&);
static void destroy(JSC::JSCell*);
DECLARE_INFO;
static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
{
return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info(), JSC::NonArray);
}
static JSC::JSValue getConstructor(JSC::VM&, const JSC::JSGlobalObject*);
template<typename, JSC::SubspaceAccess mode> static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm)
{
if constexpr (mode == JSC::SubspaceAccess::Concurrently)
return nullptr;
return subspaceForImpl(vm);
}
static JSC::GCClient::IsoSubspace* subspaceForImpl(JSC::VM& vm);
protected:
JSTransformStreamDefaultController(JSC::Structure*, JSDOMGlobalObject&);
void finishCreation(JSC::VM&);
};
} // namespace WebCore

View File

@@ -1,313 +0,0 @@
/*
This file is part of the WebKit open source project.
This file has been generated by generate-bindings.pl. DO NOT MODIFY!
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "config.h"
#include "JSWritableStream.h"
#include "ActiveDOMObject.h"
#include "ExtendedDOMClientIsoSubspaces.h"
#include "ExtendedDOMIsoSubspaces.h"
#include "JSDOMAttribute.h"
#include "JSDOMBinding.h"
#include "JSDOMConstructor.h"
#include "JSDOMConvertBoolean.h"
#include "JSDOMConvertInterface.h"
#include "JSDOMConvertObject.h"
#include "JSDOMExceptionHandling.h"
#include "JSDOMGlobalObjectInlines.h"
#include "JSDOMOperation.h"
#include "JSDOMOperationReturningPromise.h"
#include "JSDOMWrapperCache.h"
#include "ScriptExecutionContext.h"
#include "WebCoreJSClientData.h"
#include <JavaScriptCore/FunctionPrototype.h>
#include <JavaScriptCore/HeapAnalyzer.h>
#include <JavaScriptCore/JSCInlines.h>
#include <JavaScriptCore/JSDestructibleObjectHeapCellType.h>
#include <JavaScriptCore/SlotVisitorMacros.h>
#include <JavaScriptCore/SubspaceInlines.h>
#include <wtf/GetPtr.h>
#include <wtf/PointerPreparations.h>
#include <wtf/URL.h>
namespace WebCore {
using namespace JSC;
// Functions
static JSC_DECLARE_HOST_FUNCTION(jsWritableStreamPrototypeFunction_abort);
static JSC_DECLARE_HOST_FUNCTION(jsWritableStreamPrototypeFunction_close);
static JSC_DECLARE_HOST_FUNCTION(jsWritableStreamPrototypeFunction_getWriter);
// Attributes
static JSC_DECLARE_CUSTOM_GETTER(jsWritableStreamConstructor);
static JSC_DECLARE_CUSTOM_GETTER(jsWritableStream_locked);
class JSWritableStreamPrototype final : public JSC::JSNonFinalObject {
public:
using Base = JSC::JSNonFinalObject;
static JSWritableStreamPrototype* create(JSC::VM& vm, JSDOMGlobalObject* globalObject, JSC::Structure* structure)
{
JSWritableStreamPrototype* ptr = new (NotNull, JSC::allocateCell<JSWritableStreamPrototype>(vm)) JSWritableStreamPrototype(vm, globalObject, structure);
ptr->finishCreation(vm);
return ptr;
}
DECLARE_INFO;
template<typename CellType, JSC::SubspaceAccess>
static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm)
{
STATIC_ASSERT_ISO_SUBSPACE_SHARABLE(JSWritableStreamPrototype, Base);
return &vm.plainObjectSpace();
}
static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
{
return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info());
}
private:
JSWritableStreamPrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure)
: JSC::JSNonFinalObject(vm, structure)
{
}
void finishCreation(JSC::VM&);
};
STATIC_ASSERT_ISO_SUBSPACE_SHARABLE(JSWritableStreamPrototype, JSWritableStreamPrototype::Base);
using JSWritableStreamDOMConstructor = JSDOMConstructor<JSWritableStream>;
template<> JSC::EncodedJSValue JSC_HOST_CALL_ATTRIBUTES JSWritableStreamDOMConstructor::construct(JSGlobalObject* lexicalGlobalObject, CallFrame* callFrame)
{
VM& vm = lexicalGlobalObject->vm();
auto throwScope = DECLARE_THROW_SCOPE(vm);
auto* castedThis = jsCast<JSWritableStreamDOMConstructor*>(callFrame->jsCallee());
ASSERT(castedThis);
EnsureStillAliveScope argument0 = callFrame->argument(0);
auto underlyingSink = argument0.value().isUndefined() ? std::optional<Converter<IDLObject>::ReturnType>() : std::optional<Converter<IDLObject>::ReturnType>(convert<IDLObject>(*lexicalGlobalObject, argument0.value()));
RETURN_IF_EXCEPTION(throwScope, {});
EnsureStillAliveScope argument1 = callFrame->argument(1);
auto strategy = argument1.value().isUndefined() ? std::optional<Converter<IDLObject>::ReturnType>() : std::optional<Converter<IDLObject>::ReturnType>(convert<IDLObject>(*lexicalGlobalObject, argument1.value()));
RETURN_IF_EXCEPTION(throwScope, {});
auto object = WritableStream::create(*castedThis->globalObject(), WTFMove(underlyingSink), WTFMove(strategy));
if constexpr (IsExceptionOr<decltype(object)>)
RETURN_IF_EXCEPTION(throwScope, {});
static_assert(TypeOrExceptionOrUnderlyingType<decltype(object)>::isRef);
auto jsValue = toJSNewlyCreated<IDLInterface<WritableStream>>(*lexicalGlobalObject, *castedThis->globalObject(), throwScope, WTFMove(object));
if constexpr (IsExceptionOr<decltype(object)>)
RETURN_IF_EXCEPTION(throwScope, {});
setSubclassStructureIfNeeded<WritableStream>(lexicalGlobalObject, callFrame, asObject(jsValue));
RETURN_IF_EXCEPTION(throwScope, {});
return JSValue::encode(jsValue);
}
JSC_ANNOTATE_HOST_FUNCTION(JSWritableStreamDOMConstructorConstruct, JSWritableStreamDOMConstructor::construct);
template<> const ClassInfo JSWritableStreamDOMConstructor::s_info = { "WritableStream"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSWritableStreamDOMConstructor) };
template<> JSValue JSWritableStreamDOMConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject)
{
UNUSED_PARAM(vm);
return globalObject.functionPrototype();
}
template<> void JSWritableStreamDOMConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject)
{
putDirect(vm, vm.propertyNames->length, jsNumber(0), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
JSString* nameString = jsNontrivialString(vm, "WritableStream"_s);
m_originalName.set(vm, this, nameString);
putDirect(vm, vm.propertyNames->name, nameString, JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
putDirect(vm, vm.propertyNames->prototype, JSWritableStream::prototype(vm, globalObject), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::DontDelete);
}
/* Hash table for prototype */
static const HashTableValue JSWritableStreamPrototypeTableValues[] = {
{ "constructor"_s, static_cast<unsigned>(JSC::PropertyAttribute::DontEnum), NoIntrinsic, { HashTableValue::GetterSetterType, jsWritableStreamConstructor, 0 } },
{ "locked"_s, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { HashTableValue::GetterSetterType, jsWritableStream_locked, 0 } },
{ "abort"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, jsWritableStreamPrototypeFunction_abort, 0 } },
{ "close"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, jsWritableStreamPrototypeFunction_close, 0 } },
{ "getWriter"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, jsWritableStreamPrototypeFunction_getWriter, 0 } },
};
const ClassInfo JSWritableStreamPrototype::s_info = { "WritableStream"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSWritableStreamPrototype) };
void JSWritableStreamPrototype::finishCreation(VM& vm)
{
Base::finishCreation(vm);
reifyStaticProperties(vm, JSWritableStream::info(), JSWritableStreamPrototypeTableValues, *this);
JSC_TO_STRING_TAG_WITHOUT_TRANSITION();
}
const ClassInfo JSWritableStream::s_info = { "WritableStream"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSWritableStream) };
JSWritableStream::JSWritableStream(Structure* structure, JSDOMGlobalObject& globalObject, Ref<WritableStream>&& impl)
: JSDOMWrapper<WritableStream>(structure, globalObject, WTFMove(impl))
{
}
void JSWritableStream::finishCreation(VM& vm)
{
Base::finishCreation(vm);
ASSERT(inherits(info()));
// static_assert(!std::is_base_of<ActiveDOMObject, WritableStream>::value, "Interface is not marked as [ActiveDOMObject] even though implementation class subclasses ActiveDOMObject.");
}
JSObject* JSWritableStream::createPrototype(VM& vm, JSDOMGlobalObject& globalObject)
{
auto* structure = JSWritableStreamPrototype::createStructure(vm, &globalObject, globalObject.objectPrototype());
structure->setMayBePrototype(true);
return JSWritableStreamPrototype::create(vm, &globalObject, structure);
}
JSObject* JSWritableStream::prototype(VM& vm, JSDOMGlobalObject& globalObject)
{
return getDOMPrototype<JSWritableStream>(vm, globalObject);
}
JSValue JSWritableStream::getConstructor(VM& vm, const JSGlobalObject* globalObject)
{
return getDOMConstructor<JSWritableStreamDOMConstructor, DOMConstructorID::WritableStream>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject));
}
void JSWritableStream::destroy(JSC::JSCell* cell)
{
JSWritableStream* thisObject = static_cast<JSWritableStream*>(cell);
thisObject->JSWritableStream::~JSWritableStream();
}
JSC_DEFINE_CUSTOM_GETTER(jsWritableStreamConstructor, (JSGlobalObject * lexicalGlobalObject, JSC::EncodedJSValue thisValue, PropertyName))
{
VM& vm = JSC::getVM(lexicalGlobalObject);
auto throwScope = DECLARE_THROW_SCOPE(vm);
auto* prototype = jsDynamicCast<JSWritableStreamPrototype*>(JSValue::decode(thisValue));
if (UNLIKELY(!prototype))
return throwVMTypeError(lexicalGlobalObject, throwScope);
return JSValue::encode(JSWritableStream::getConstructor(JSC::getVM(lexicalGlobalObject), prototype->globalObject()));
}
static inline JSValue jsWritableStream_lockedGetter(JSGlobalObject& lexicalGlobalObject, JSWritableStream& thisObject)
{
auto& vm = JSC::getVM(&lexicalGlobalObject);
auto throwScope = DECLARE_THROW_SCOPE(vm);
auto& impl = thisObject.wrapped();
RELEASE_AND_RETURN(throwScope, (toJS<IDLBoolean>(lexicalGlobalObject, throwScope, impl.locked())));
}
JSC_DEFINE_CUSTOM_GETTER(jsWritableStream_locked, (JSGlobalObject * lexicalGlobalObject, JSC::EncodedJSValue thisValue, PropertyName attributeName))
{
return IDLAttribute<JSWritableStream>::get<jsWritableStream_lockedGetter, CastedThisErrorBehavior::Assert>(*lexicalGlobalObject, thisValue, attributeName);
}
static inline JSC::EncodedJSValue jsWritableStreamPrototypeFunction_abortBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperationReturningPromise<JSWritableStream>::ClassParameter castedThis)
{
auto& vm = JSC::getVM(lexicalGlobalObject);
auto throwScope = DECLARE_THROW_SCOPE(vm);
UNUSED_PARAM(throwScope);
UNUSED_PARAM(callFrame);
RELEASE_AND_RETURN(throwScope, (JSValue::encode(castedThis->abort(*lexicalGlobalObject, *callFrame))));
}
JSC_DEFINE_HOST_FUNCTION(jsWritableStreamPrototypeFunction_abort, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))
{
return IDLOperationReturningPromise<JSWritableStream>::callReturningOwnPromise<jsWritableStreamPrototypeFunction_abortBody>(*lexicalGlobalObject, *callFrame, "abort");
}
static inline JSC::EncodedJSValue jsWritableStreamPrototypeFunction_closeBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperationReturningPromise<JSWritableStream>::ClassParameter castedThis)
{
auto& vm = JSC::getVM(lexicalGlobalObject);
auto throwScope = DECLARE_THROW_SCOPE(vm);
UNUSED_PARAM(throwScope);
UNUSED_PARAM(callFrame);
RELEASE_AND_RETURN(throwScope, (JSValue::encode(castedThis->close(*lexicalGlobalObject, *callFrame))));
}
JSC_DEFINE_HOST_FUNCTION(jsWritableStreamPrototypeFunction_close, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))
{
return IDLOperationReturningPromise<JSWritableStream>::callReturningOwnPromise<jsWritableStreamPrototypeFunction_closeBody>(*lexicalGlobalObject, *callFrame, "close");
}
static inline JSC::EncodedJSValue jsWritableStreamPrototypeFunction_getWriterBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation<JSWritableStream>::ClassParameter castedThis)
{
auto& vm = JSC::getVM(lexicalGlobalObject);
auto throwScope = DECLARE_THROW_SCOPE(vm);
UNUSED_PARAM(throwScope);
UNUSED_PARAM(callFrame);
RELEASE_AND_RETURN(throwScope, (JSValue::encode(castedThis->getWriter(*lexicalGlobalObject, *callFrame))));
}
JSC_DEFINE_HOST_FUNCTION(jsWritableStreamPrototypeFunction_getWriter, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))
{
return IDLOperation<JSWritableStream>::call<jsWritableStreamPrototypeFunction_getWriterBody>(*lexicalGlobalObject, *callFrame, "getWriter");
}
JSC::GCClient::IsoSubspace* JSWritableStream::subspaceForImpl(JSC::VM& vm)
{
return WebCore::subspaceForImpl<JSWritableStream, UseCustomHeapCellType::No>(
vm,
[](auto& spaces) { return spaces.m_clientSubspaceForWritableStream.get(); },
[](auto& spaces, auto&& space) { spaces.m_clientSubspaceForWritableStream = std::forward<decltype(space)>(space); },
[](auto& spaces) { return spaces.m_subspaceForWritableStream.get(); },
[](auto& spaces, auto&& space) { spaces.m_subspaceForWritableStream = std::forward<decltype(space)>(space); });
}
void JSWritableStream::analyzeHeap(JSCell* cell, HeapAnalyzer& analyzer)
{
auto* thisObject = jsCast<JSWritableStream*>(cell);
analyzer.setWrappedObjectForCell(cell, &thisObject->wrapped());
if (thisObject->scriptExecutionContext())
analyzer.setLabelForCell(cell, makeString("url "_s, thisObject->scriptExecutionContext()->url().string()));
Base::analyzeHeap(cell, analyzer);
}
bool JSWritableStreamOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, AbstractSlotVisitor& visitor, ASCIILiteral* reason)
{
UNUSED_PARAM(handle);
UNUSED_PARAM(visitor);
UNUSED_PARAM(reason);
return false;
}
void JSWritableStreamOwner::finalize(JSC::Handle<JSC::Unknown> handle, void* context)
{
auto* jsWritableStream = static_cast<JSWritableStream*>(handle.slot()->asCell());
auto& world = *static_cast<DOMWrapperWorld*>(context);
uncacheWrapper(world, &jsWritableStream->wrapped(), jsWritableStream);
}
JSC::JSValue toJSNewlyCreated(JSC::JSGlobalObject*, JSDOMGlobalObject* globalObject, Ref<WritableStream>&& impl)
{
return createWrapper<WritableStream>(globalObject, WTFMove(impl));
}
JSC::JSValue toJS(JSC::JSGlobalObject* lexicalGlobalObject, JSDOMGlobalObject* globalObject, WritableStream& impl)
{
return wrap(lexicalGlobalObject, globalObject, impl);
}
WritableStream* JSWritableStream::toWrapped(JSC::VM&, JSC::JSValue value)
{
if (auto* wrapper = jsDynamicCast<JSWritableStream*>(value))
return &wrapper->wrapped();
return nullptr;
}
}

View File

@@ -1,99 +0,0 @@
/*
This file is part of the WebKit open source project.
This file has been generated by generate-bindings.pl. DO NOT MODIFY!
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#pragma once
#include "JSDOMWrapper.h"
#include "WritableStream.h"
#include <wtf/NeverDestroyed.h>
namespace WebCore {
class JSWritableStream : public JSDOMWrapper<WritableStream> {
public:
using Base = JSDOMWrapper<WritableStream>;
static JSWritableStream* create(JSC::Structure* structure, JSDOMGlobalObject* globalObject, Ref<WritableStream>&& impl)
{
JSWritableStream* ptr = new (NotNull, JSC::allocateCell<JSWritableStream>(globalObject->vm())) JSWritableStream(structure, *globalObject, WTFMove(impl));
ptr->finishCreation(globalObject->vm());
return ptr;
}
static JSC::JSObject* createPrototype(JSC::VM&, JSDOMGlobalObject&);
static JSC::JSObject* prototype(JSC::VM&, JSDOMGlobalObject&);
static WritableStream* toWrapped(JSC::VM&, JSC::JSValue);
static void destroy(JSC::JSCell*);
DECLARE_INFO;
static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
{
return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info(), JSC::NonArray);
}
static JSC::JSValue getConstructor(JSC::VM&, const JSC::JSGlobalObject*);
template<typename, JSC::SubspaceAccess mode> static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm)
{
if constexpr (mode == JSC::SubspaceAccess::Concurrently)
return nullptr;
return subspaceForImpl(vm);
}
static JSC::GCClient::IsoSubspace* subspaceForImpl(JSC::VM& vm);
static void analyzeHeap(JSCell*, JSC::HeapAnalyzer&);
// Custom functions
JSC::JSValue abort(JSC::JSGlobalObject&, JSC::CallFrame&);
JSC::JSValue close(JSC::JSGlobalObject&, JSC::CallFrame&);
JSC::JSValue getWriter(JSC::JSGlobalObject&, JSC::CallFrame&);
protected:
JSWritableStream(JSC::Structure*, JSDOMGlobalObject&, Ref<WritableStream>&&);
void finishCreation(JSC::VM&);
};
class JSWritableStreamOwner final : public JSC::WeakHandleOwner {
public:
bool isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown>, void* context, JSC::AbstractSlotVisitor&, ASCIILiteral*) final;
void finalize(JSC::Handle<JSC::Unknown>, void* context) final;
};
inline JSC::WeakHandleOwner* wrapperOwner(DOMWrapperWorld&, WritableStream*)
{
static NeverDestroyed<JSWritableStreamOwner> owner;
return &owner.get();
}
inline void* wrapperKey(WritableStream* wrappableObject)
{
return wrappableObject;
}
JSC::JSValue toJS(JSC::JSGlobalObject*, JSDOMGlobalObject*, WritableStream&);
inline JSC::JSValue toJS(JSC::JSGlobalObject* lexicalGlobalObject, JSDOMGlobalObject* globalObject, WritableStream* impl) { return impl ? toJS(lexicalGlobalObject, globalObject, *impl) : JSC::jsNull(); }
JSC::JSValue toJSNewlyCreated(JSC::JSGlobalObject*, JSDOMGlobalObject*, Ref<WritableStream>&&);
inline JSC::JSValue toJSNewlyCreated(JSC::JSGlobalObject* lexicalGlobalObject, JSDOMGlobalObject* globalObject, RefPtr<WritableStream>&& impl) { return impl ? toJSNewlyCreated(lexicalGlobalObject, globalObject, impl.releaseNonNull()) : JSC::jsNull(); }
template<> struct JSDOMWrapperConverterTraits<WritableStream> {
using WrapperClass = JSWritableStream;
using ToWrappedReturnType = WritableStream*;
};
} // namespace WebCore

Some files were not shown because too many files have changed in this diff Show More