From d03f88a75c25b2fc3eb09348ed7d71c2bb8492ae Mon Sep 17 00:00:00 2001 From: Jarred Sumner Date: Thu, 19 Dec 2024 20:51:05 -0800 Subject: [PATCH] More --- .../BunReadableStreamDefaultController.cpp | 149 ------------------ ...ReadableStreamDefaultControllerPrototype.h | 5 - 2 files changed, 154 deletions(-) diff --git a/src/bun.js/bindings/BunReadableStreamDefaultController.cpp b/src/bun.js/bindings/BunReadableStreamDefaultController.cpp index cf5eca5514..71e4633b33 100644 --- a/src/bun.js/bindings/BunReadableStreamDefaultController.cpp +++ b/src/bun.js/bindings/BunReadableStreamDefaultController.cpp @@ -30,148 +30,6 @@ JSC::GCClient::IsoSubspace* JSReadableStreamDefaultController::subspaceFor(JSC:: [](auto& spaces) { return spaces.m_subspaceForJSReadableStreamDefaultController.get(); }, [](auto& spaces, auto&& space) { spaces.m_subspaceForJSReadableStreamDefaultController = std::forward(space); }); } - -JSC_DEFINE_HOST_FUNCTION(jsReadableStreamDefaultControllerPrototypeClose, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame)) -{ - VM& vm = globalObject->vm(); - auto scope = DECLARE_THROW_SCOPE(vm); - - JSReadableStreamDefaultController* controller = jsDynamicCast(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, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame)) -{ - VM& vm = globalObject->vm(); - auto scope = DECLARE_THROW_SCOPE(vm); - - JSReadableStreamDefaultController* controller = jsDynamicCast(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(globalObject, chunk)); -} - -JSC_DEFINE_HOST_FUNCTION(jsReadableStreamDefaultControllerPrototypeError, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame)) -{ - VM& vm = globalObject->vm(); - auto scope = DECLARE_THROW_SCOPE(vm); - - JSReadableStreamDefaultController* controller = jsDynamicCast(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, (JSC::JSGlobalObject * globalObject, JSC::EncodedJSValue thisValue, JSC::PropertyName)) -{ - VM& vm = globalObject->vm(); - auto scope = DECLARE_THROW_SCOPE(vm); - - JSReadableStreamDefaultController* controller = jsDynamicCast(JSValue::decode(thisValue)); - if (!controller) - return throwVMTypeError(globalObject, scope, "ReadableStreamDefaultController.prototype.desiredSize called on incompatible object"_s); - - return JSValue::encode(jsDoubleNumber(controller->desiredSize())); -} - -static const JSC::HashTableValue JSReadableStreamDefaultControllerPrototypeTableValues[] = { - { "close"_s, static_cast(JSC::PropertyAttribute::Function), NoIntrinsic, - { HashTableValue::NativeFunctionType, jsReadableStreamDefaultControllerPrototypeClose, 0 } }, - { "enqueue"_s, static_cast(JSC::PropertyAttribute::Function), NoIntrinsic, - { HashTableValue::NativeFunctionType, jsReadableStreamDefaultControllerPrototypeEnqueue, 1 } }, - { "error"_s, static_cast(JSC::PropertyAttribute::Function), NoIntrinsic, - { HashTableValue::NativeFunctionType, jsReadableStreamDefaultControllerPrototypeError, 1 } }, - { "desiredSize"_s, static_cast(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::ReadOnly), NoIntrinsic, - { HashTableValue::GetterSetterType, jsReadableStreamDefaultControllerPrototypeDesiredSizeGetter, nullptr } } -}; - -class JSReadableStreamDefaultControllerConstructor final : public JSC::InternalFunction { -public: - using Base = JSC::InternalFunction; - - static JSReadableStreamDefaultControllerConstructor* create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure, JSObject* prototype) - { - JSReadableStreamDefaultControllerConstructor* ptr = new (NotNull, JSC::allocateCell(vm)) JSReadableStreamDefaultControllerConstructor(vm, structure); - ptr->finishCreation(vm, globalObject, prototype); - return ptr; - } - - DECLARE_INFO; - template - static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm) - { - return &vm.plainObjectSpace(); - } - - static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype) - { - return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::InternalFunctionType, StructureFlags), info()); - } - -private: - JSReadableStreamDefaultControllerConstructor(JSC::VM& vm, JSC::Structure* structure) - : Base(vm, structure, nullptr, nullptr) // nullptr for construct as this isn't constructable - { - } - - void finishCreation(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSObject* prototype) - { - Base::finishCreation(vm, 0, "ReadableStreamDefaultController"_s, PropertyAdditionMode::WithoutStructureTransition); - - putDirectWithoutTransition(vm, vm.propertyNames->prototype, prototype, JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly); - } -}; - -class JSReadableStreamDefaultControllerPrototype final : public JSC::JSNonFinalObject { -public: - using Base = JSC::JSNonFinalObject; - - static JSReadableStreamDefaultControllerPrototype* create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure) - { - JSReadableStreamDefaultControllerPrototype* ptr = new (NotNull, JSC::allocateCell(vm)) JSReadableStreamDefaultControllerPrototype(vm, structure); - ptr->finishCreation(vm, globalObject); - return ptr; - } - - DECLARE_INFO; - template - 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& vm, JSC::Structure* structure) - : Base(vm, structure) - { - } - - void finishCreation(JSC::VM& vm, JSC::JSGlobalObject* globalObject) - { - Base::finishCreation(vm); - reifyStaticProperties(vm, info(), JSReadableStreamDefaultControllerPrototypeTableValues, *this); - - JSC_TO_STRING_TAG_WITHOUT_TRANSITION(); - } -}; - JSReadableStreamDefaultController* JSReadableStreamDefaultController::create(VM& vm, JSGlobalObject* globalObject, Structure* structure, JSReadableStream* stream) { JSReadableStreamDefaultController* controller = new (NotNull, JSC::allocateCell(vm)) JSReadableStreamDefaultController(vm, structure); @@ -179,13 +37,6 @@ JSReadableStreamDefaultController* JSReadableStreamDefaultController::create(VM& return controller; } -JSObject* JSReadableStreamDefaultController::createPrototype(VM& vm, JSGlobalObject* globalObject) -{ - JSReadableStreamDefaultControllerPrototype* prototype = JSReadableStreamDefaultControllerPrototype::create(vm, globalObject, JSReadableStreamDefaultControllerPrototype::createStructure(vm, globalObject, globalObject->objectPrototype())); - - return prototype; -} - JSValue JSReadableStreamDefaultController::desiredSizeValue() { if (!canCloseOrEnqueue()) diff --git a/src/bun.js/bindings/BunReadableStreamDefaultControllerPrototype.h b/src/bun.js/bindings/BunReadableStreamDefaultControllerPrototype.h index fae9ed1859..6d6ce92925 100644 --- a/src/bun.js/bindings/BunReadableStreamDefaultControllerPrototype.h +++ b/src/bun.js/bindings/BunReadableStreamDefaultControllerPrototype.h @@ -33,9 +33,4 @@ private: void finishCreation(JSC::VM&, JSC::JSGlobalObject*); }; -JSC_DECLARE_HOST_FUNCTION(jsReadableStreamDefaultControllerPrototypeClose); -JSC_DECLARE_HOST_FUNCTION(jsReadableStreamDefaultControllerPrototypeEnqueue); -JSC_DECLARE_HOST_FUNCTION(jsReadableStreamDefaultControllerPrototypeError); -JSC_DECLARE_CUSTOM_GETTER(jsReadableStreamDefaultControllerPrototypeDesiredSizeGetter); - } // namespace Bun