aboutsummaryrefslogtreecommitdiff
path: root/src/bun.js/bindings/JSReadableState.cpp
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <jarred@jarredsumner.com> 2023-07-11 19:14:34 -0700
committerGravatar GitHub <noreply@github.com> 2023-07-11 19:14:34 -0700
commitcbb88672f217a90db1aa1eb29cd92d5d9035b22b (patch)
tree43a00501f3cde495967e116f0b660777051551f8 /src/bun.js/bindings/JSReadableState.cpp
parent1f900cff453700b19bca2acadfe26da4468c1282 (diff)
parent34b0e7a2bbd8bf8097341cdb0075d0908283e834 (diff)
downloadbun-cbb88672f217a90db1aa1eb29cd92d5d9035b22b.tar.gz
bun-cbb88672f217a90db1aa1eb29cd92d5d9035b22b.tar.zst
bun-cbb88672f217a90db1aa1eb29cd92d5d9035b22b.zip
Merge branch 'main' into jarred/esm-conditionsjarred/esm-conditions
Diffstat (limited to 'src/bun.js/bindings/JSReadableState.cpp')
-rw-r--r--src/bun.js/bindings/JSReadableState.cpp42
1 files changed, 23 insertions, 19 deletions
diff --git a/src/bun.js/bindings/JSReadableState.cpp b/src/bun.js/bindings/JSReadableState.cpp
index d09e30d44..1f3a36def 100644
--- a/src/bun.js/bindings/JSReadableState.cpp
+++ b/src/bun.js/bindings/JSReadableState.cpp
@@ -26,10 +26,10 @@ int64_t getHighWaterMark(JSC::VM& vm, JSC::JSGlobalObject* globalObject, bool is
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));
+ highWaterMarkVal = options->getIfPropertyExists(globalObject, JSC::Identifier::fromString(vm, "readableObjectMode"_s));
}
- if (!highWaterMarkVal.isUndefinedOrNull()) {
+ if (highWaterMarkVal && highWaterMarkVal.isNumber()) {
return highWaterMarkVal.toInt32(globalObject);
}
}
@@ -42,9 +42,9 @@ void JSReadableState::finishCreation(JSC::VM& vm, JSC::JSGlobalObject* globalObj
Base::finishCreation(vm);
if (options != nullptr) {
- JSC::JSValue objectModeVal = options->getDirect(vm, JSC::Identifier::fromString(vm, "objectMode"_s));
+ JSC::JSValue objectModeVal = options->getIfPropertyExists(globalObject, JSC::Identifier::fromString(vm, "objectMode"_s));
if (isDuplex && !objectModeVal) {
- objectModeVal = options->getDirect(vm, JSC::Identifier::fromString(vm, "readableObjectMode"_s));
+ objectModeVal = options->getIfPropertyExists(globalObject, JSC::Identifier::fromString(vm, "readableObjectMode"_s));
}
if (objectModeVal && objectModeVal.toBoolean(globalObject))
setBool(JSReadableState::Mask::objectMode, true);
@@ -65,13 +65,16 @@ void JSReadableState::finishCreation(JSC::VM& vm, JSC::JSGlobalObject* globalObj
m_pipes.set(vm, this, JSC::constructEmptyArray(globalObject, nullptr, 0));
if (options != nullptr) {
- JSC::JSValue emitCloseVal = options->getDirect(vm, JSC::Identifier::fromString(vm, "emitClose"_s));
- if (!emitCloseVal.isBoolean() || emitCloseVal.toBoolean(globalObject))
+ JSC::JSValue emitCloseVal = options->getIfPropertyExists(globalObject, JSC::Identifier::fromString(vm, "emitClose"_s));
+ if (!emitCloseVal || emitCloseVal.toBoolean(globalObject))
setBool(JSReadableState::Mask::emitClose, true);
// Has it been destroyed.
- JSC::JSValue autoDestroyVal = options->getDirect(vm, JSC::Identifier::fromString(vm, "autoDestroy"_s));
- if (!autoDestroyVal.isBoolean() || autoDestroyVal.toBoolean(globalObject))
+ JSC::JSValue autoDestroyVal = options->getIfPropertyExists(globalObject, JSC::Identifier::fromString(vm, "autoDestroy"_s));
+ if (!autoDestroyVal || autoDestroyVal.toBoolean(globalObject))
setBool(JSReadableState::Mask::autoDestroy, true);
+ } else {
+ setBool(JSReadableState::Mask::emitClose, true);
+ setBool(JSReadableState::Mask::autoDestroy, true);
}
// Indicates whether the stream has finished destroying.
@@ -90,26 +93,25 @@ void JSReadableState::finishCreation(JSC::VM& vm, JSC::JSGlobalObject* globalObj
}
m_awaitDrainWriters.set(vm, this, JSC::jsNull());
+ JSValue decodeValue = JSC::jsNull();
+ JSValue encodingValue = JSC::jsNull();
- if (options == nullptr) {
- m_decoder.set(vm, this, JSC::jsNull());
- m_encoding.set(vm, this, JSC::jsNull());
- } else {
- JSC::JSValue encodingVal = options->getDirect(vm, JSC::Identifier::fromString(vm, "encoding"_s));
+ if (options != nullptr) {
+ JSC::JSValue encodingVal = options->getIfPropertyExists(globalObject, JSC::Identifier::fromString(vm, "encoding"_s));
if (encodingVal && encodingVal.isString()) {
auto constructor = reinterpret_cast<Zig::GlobalObject*>(globalObject)->JSStringDecoder();
auto constructData = JSC::getConstructData(constructor);
MarkedArgumentBuffer args;
args.append(encodingVal);
JSObject* decoder = JSC::construct(globalObject, constructor, constructData, args);
- m_decoder.set(vm, this, decoder);
- m_encoding.set(vm, this, encodingVal);
- } else {
- m_decoder.set(vm, this, JSC::jsNull());
- m_encoding.set(vm, this, JSC::jsNull());
+ decodeValue = decoder;
+ encodingValue = encodingVal;
}
}
+ m_decoder.set(vm, this, decodeValue);
+ m_encoding.set(vm, this, encodingValue);
+
// 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
@@ -403,10 +405,12 @@ JSC::EncodedJSValue JSReadableStateConstructor::construct(JSC::JSGlobalObject* l
return JSValue::encode(jsUndefined());
}
isDuplex = isDuplexVal.toBoolean(lexicalGlobalObject);
+ RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
JSObject* options = nullptr;
- if (optionsVal.toBoolean(lexicalGlobalObject) && optionsVal.isObject()) {
+ if (optionsVal && optionsVal.isObject()) {
options = optionsVal.toObject(lexicalGlobalObject);
}
+ RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
JSReadableState* stringDecoder = JSReadableState::create(
vm, lexicalGlobalObject, reinterpret_cast<Zig::GlobalObject*>(lexicalGlobalObject)->JSReadableStateStructure(), isDuplex, options);