diff options
author | 2022-10-21 22:48:55 -0700 | |
---|---|---|
committer | 2022-10-21 22:48:55 -0700 | |
commit | 71b942b5811b8bf4aed8de043aa022ae4102623c (patch) | |
tree | 979a47af7a7f62f0dda3cb6377fe8f3a865e6e2f | |
parent | cd2e9e9dcfcdb609026f9624e478b7e3af314de5 (diff) | |
download | bun-71b942b5811b8bf4aed8de043aa022ae4102623c.tar.gz bun-71b942b5811b8bf4aed8de043aa022ae4102623c.tar.zst bun-71b942b5811b8bf4aed8de043aa022ae4102623c.zip |
Fix bugs in mask boolean values
-rw-r--r-- | src/bun.js/bindings/JSReadableState.cpp | 17 | ||||
-rw-r--r-- | src/bun.js/bindings/JSReadableState.h | 19 |
2 files changed, 21 insertions, 15 deletions
diff --git a/src/bun.js/bindings/JSReadableState.cpp b/src/bun.js/bindings/JSReadableState.cpp index 309a1ea53..682e681f4 100644 --- a/src/bun.js/bindings/JSReadableState.cpp +++ b/src/bun.js/bindings/JSReadableState.cpp @@ -19,7 +19,11 @@ int64_t getHighWaterMark(JSC::VM& vm, JSC::JSGlobalObject* globalObject, bool is { auto throwScope = DECLARE_THROW_SCOPE(vm); - if (JSValue highWaterMarkVal = options->getIfPropertyExists(globalObject, PropertyName(JSC::Identifier::fromString(vm, "highWaterMark"_s)))) { + // We must use getIfPropertyExists because: + // - it might be a getter + // - it might be from a super class + auto* clientData = WebCore::clientData(vm); + if (JSValue highWaterMarkVal = options->getIfPropertyExists(globalObject, clientData->builtinNames().highWaterMarkPublicName())) { if (isDuplex && (highWaterMarkVal.isUndefined() || highWaterMarkVal.isNull())) { highWaterMarkVal = options->getDirect(vm, JSC::Identifier::fromString(vm, "readableObjectMode"_s)); } @@ -45,7 +49,11 @@ void JSReadableState::finishCreation(JSC::VM& vm, JSC::JSGlobalObject* globalObj setBool(JSReadableState::Mask::objectMode, true); } - m_highWaterMark = getBool(JSReadableState::Mask::objectMode) ? 16 : 16 * 1024; // default value + m_highWaterMark = getBool( + JSReadableState::Mask::objectMode) + ? 16 + : 16 * 1024; // default value + if (options != nullptr) { int64_t customHightWaterMark = getHighWaterMark(vm, globalObject, isDuplex, options); if (customHightWaterMark >= 0) @@ -73,8 +81,7 @@ void JSReadableState::finishCreation(JSC::VM& vm, JSC::JSGlobalObject* globalObj if (options == nullptr) { m_defaultEncoding.set(vm, this, JSC::jsString(vm, WTF::String("utf8"_s))); } else { - JSC::JSValue defaultEncodingVal = getDirect(vm, JSC::Identifier::fromString(vm, "defaultEncoding"_s)); - if (defaultEncodingVal) { + if (JSC::JSValue defaultEncodingVal = getIfPropertyExists(globalObject, PropertyName(JSC::Identifier::fromString(vm, "defaultEncoding"_s)))) { m_defaultEncoding.set(vm, this, defaultEncodingVal); } else { m_defaultEncoding.set(vm, this, JSC::jsString(vm, WTF::String("utf8"_s))); @@ -88,7 +95,7 @@ void JSReadableState::finishCreation(JSC::VM& vm, JSC::JSGlobalObject* globalObj m_encoding.set(vm, this, JSC::jsNull()); } else { JSC::JSValue encodingVal = options->getDirect(vm, JSC::Identifier::fromString(vm, "encoding"_s)); - if (encodingVal) { + if (encodingVal && encodingVal.isString()) { auto constructor = reinterpret_cast<Zig::GlobalObject*>(globalObject)->JSStringDecoder(); auto constructData = JSC::getConstructData(constructor); MarkedArgumentBuffer args; diff --git a/src/bun.js/bindings/JSReadableState.h b/src/bun.js/bindings/JSReadableState.h index 544d4b63e..c67baebad 100644 --- a/src/bun.js/bindings/JSReadableState.h +++ b/src/bun.js/bindings/JSReadableState.h @@ -11,7 +11,8 @@ class JSReadableState : public JSC::JSDestructibleObject { public: JSReadableState(JSC::VM& vm, JSC::Structure* structure) - : Base(vm, structure), m_paused(0) + : Base(vm, structure) + , m_paused(0) { } @@ -46,7 +47,7 @@ public: void finishCreation(JSC::VM& vm, JSC::JSGlobalObject* globalObject, bool isDuplex, JSObject* options); static void destroy(JSCell*) {} - enum Mask { + enum Mask : uint32_t { objectMode = 1 << 0, emitClose = 1 << 1, autoDestroy = 1 << 2, @@ -57,7 +58,7 @@ public: sync = 1 << 7, needReadable = 1 << 8, emittedReadable = 1 << 9, - readableListening = 1<< 10, + readableListening = 1 << 10, resumeScheduled = 1 << 11, errorEmitted = 1 << 12, destroyed = 1 << 13, @@ -68,19 +69,17 @@ public: dataEmitted = 1 << 18, }; - bool getBool(Mask mask) { return m_bools & mask; } - void setBool(Mask mask, bool val) { - if (val) - m_bools = m_bools | mask; - else - m_bools = m_bools & mask; + constexpr bool getBool(Mask mask) { return m_bools.contains(mask); } + constexpr void setBool(Mask mask, bool val) + { + m_bools.set(mask, val); } // 0 for null, 1 for true, -1 for false int8_t m_paused = 0; int8_t m_flowing = 0; - uint32_t m_bools = Mask::constructed | Mask::sync; + WTF::OptionSet<Mask> m_bools; int64_t m_length = 0; int64_t m_highWaterMark; |