aboutsummaryrefslogtreecommitdiff
path: root/src/bun.js
diff options
context:
space:
mode:
authorGravatar Derrick Farris <mr.dcfarris@gmail.com> 2022-12-15 02:25:19 -0600
committerGravatar GitHub <noreply@github.com> 2022-12-15 00:25:19 -0800
commit6a1fc208354d173a66b61060ec5bb79699038006 (patch)
treeab5af3660f1ce2d8b2ac8eee154ba21221a0acd4 /src/bun.js
parent95c747f598ff0a57335f2cb35c008132b7a3ac2b (diff)
downloadbun-6a1fc208354d173a66b61060ec5bb79699038006.tar.gz
bun-6a1fc208354d173a66b61060ec5bb79699038006.tar.zst
bun-6a1fc208354d173a66b61060ec5bb79699038006.zip
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
Diffstat (limited to 'src/bun.js')
-rw-r--r--src/bun.js/bindings/JSReadableState.cpp15
-rw-r--r--src/bun.js/builtins/js/ProcessObjectInternals.js5
-rw-r--r--src/bun.js/streams.exports.js11
3 files changed, 12 insertions, 19 deletions
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 */
diff --git a/src/bun.js/builtins/js/ProcessObjectInternals.js b/src/bun.js/builtins/js/ProcessObjectInternals.js
index 87bb07b95..2353f6b7e 100644
--- a/src/bun.js/builtins/js/ProcessObjectInternals.js
+++ b/src/bun.js/builtins/js/ProcessObjectInternals.js
@@ -462,11 +462,6 @@ function getStdinStream(fd, rawRequire, Bun) {
return fd_;
}
- // TODO: investigate https://github.com/oven-sh/bun/issues/1608
- _construct(callback) {
- callback();
- }
-
constructor() {
super({ readable: true, writable: true });
}
diff --git a/src/bun.js/streams.exports.js b/src/bun.js/streams.exports.js
index 9a21e5d44..988666388 100644
--- a/src/bun.js/streams.exports.js
+++ b/src/bun.js/streams.exports.js
@@ -2814,13 +2814,6 @@ var require_readable = __commonJS({
globalThis.reportError(error);
}
}
-
- // NOTE(Derrick): For whatever reason this seems to be necessary to make this work
- // I couldn't find out why .constructed was getting set to false
- // even though construct() was getting called
- _construct() {
- this._readableState.constructed = true;
- }
}
/**
@@ -6080,10 +6073,6 @@ function createNativeStreamReadable(nativeType, Readable) {
}
}
- _construct(cb) {
- this._readableState.constructed = true;
- cb();
- }
_destroy(error, callback) {
var ptr = this.#ptr;
if (ptr === 0) {