From 6a1fc208354d173a66b61060ec5bb79699038006 Mon Sep 17 00:00:00 2001 From: Derrick Farris Date: Thu, 15 Dec 2022 02:25:19 -0600 Subject: fix(stream): make Readable.read work w/o _construct implemented (#1613) * fix(stream): put Readable._readableState.constructed default in spec (true, not false) * cleanup(readable): remove unnecessary _construct methods * test(stream): add test for Readable w/o _construct method --- src/bun.js/bindings/JSReadableState.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'src/bun.js/bindings/JSReadableState.cpp') diff --git a/src/bun.js/bindings/JSReadableState.cpp b/src/bun.js/bindings/JSReadableState.cpp index 682e681f4..5b645e274 100644 --- a/src/bun.js/bindings/JSReadableState.cpp +++ b/src/bun.js/bindings/JSReadableState.cpp @@ -108,6 +108,12 @@ void JSReadableState::finishCreation(JSC::VM& vm, JSC::JSGlobalObject* globalObj m_encoding.set(vm, this, JSC::jsNull()); } } + + // ReadableState.constructed is set to false during construction when a _construct method is implemented + // this is here so that the ReadableState behavior tracks the behavior in node, and that calling Readable.read + // will work when we return early from construct because there is no Readable._construct implemented + // See: https://github.com/nodejs/node/blob/main/lib/internal/streams/readable.js + setBool(JSReadableState::Mask::constructed, true); } const JSC::ClassInfo JSReadableState::s_info = { "ReadableState"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSReadableState) }; @@ -305,9 +311,12 @@ JSReadableState_NULLABLE_BOOLEAN_GETTER_SETTER(paused) #undef JSReadableState_JSVALUE_GETTER_SETTER -#define JSReadableState_GETTER_SETTER_HASH_TABLE_VALUE(NAME) \ - { \ -#NAME ""_s, static_cast < unsigned>(JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { HashTableValue::GetterSetterType, jsReadableState_##NAME, setJSReadableState_##NAME } \ +#define JSReadableState_GETTER_SETTER_HASH_TABLE_VALUE(NAME) \ + { \ +#NAME ""_s, static_cast < unsigned>(JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, \ + { \ + HashTableValue::GetterSetterType, jsReadableState_##NAME, setJSReadableState_##NAME \ + } \ } /* Hash table for prototype */ -- cgit v1.2.3