aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2022-11-27 08:39:10 -0800
committerGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2022-11-27 08:39:10 -0800
commit740027975bcb836923d99caa31fde4a3b341e3a8 (patch)
treeedeca6616025de5bd33109b2b5e5e60954871c66
parent706406af48aa43e218d9428761acfd1b64ec5be4 (diff)
downloadbun-740027975bcb836923d99caa31fde4a3b341e3a8.tar.gz
bun-740027975bcb836923d99caa31fde4a3b341e3a8.tar.zst
bun-740027975bcb836923d99caa31fde4a3b341e3a8.zip
Handle more cases with printing objects
-rw-r--r--src/bun.js/bindings/bindings.cpp47
-rw-r--r--src/bun.js/bindings/webcore/JSReadableStream.cpp12
-rw-r--r--src/bun.js/builtins/cpp/ReadableStreamBuiltins.cpp4
-rw-r--r--src/bun.js/builtins/cpp/ReadableStreamInternalsBuiltins.cpp5
-rw-r--r--src/bun.js/builtins/js/ReadableStream.js2
5 files changed, 35 insertions, 35 deletions
diff --git a/src/bun.js/bindings/bindings.cpp b/src/bun.js/bindings/bindings.cpp
index f6cb879bf..e0a80c28c 100644
--- a/src/bun.js/bindings/bindings.cpp
+++ b/src/bun.js/bindings/bindings.cpp
@@ -3742,14 +3742,20 @@ void JSC__JSValue__forEachProperty(JSC__JSValue JSValue0, JSC__JSGlobalObject* g
JSC::VM& vm = globalObject->vm();
auto scope = DECLARE_CATCH_SCOPE(vm);
+ size_t prototypeCount = 0;
+
JSC::Structure* structure = object->structure();
bool fast = canPerformFastPropertyEnumerationForIterationBun(structure);
+ JSValue prototypeObject = value;
+
if (fast) {
if (structure->outOfLineSize() == 0 && structure->inlineSize() == 0) {
fast = false;
if (JSValue proto = object->getPrototype(vm, globalObject)) {
- if (structure = proto.structureOrNull()) {
+ if ((structure = proto.structureOrNull())) {
+ prototypeObject = proto;
fast = canPerformFastPropertyEnumerationForIterationBun(structure);
+ prototypeCount = 1;
}
}
}
@@ -3759,14 +3765,14 @@ void JSC__JSValue__forEachProperty(JSC__JSValue JSValue0, JSC__JSGlobalObject* g
if (fast) {
bool anyHits = false;
-
structure->forEachProperty(vm, [&](const PropertyTableEntry& entry) -> bool {
- if (entry.attributes() & PropertyAttribute::DontEnum) {
+ if ((entry.attributes() & PropertyAttribute::Accessor) != 0 && (entry.attributes() & PropertyAttribute::DontEnum) != 0) {
+ return true;
+ }
- if ((entry.attributes() & PropertyAttribute::Accessor) != 0) {
- return true;
- }
- if (!(entry.attributes() & (PropertyAttribute::BuiltinOrFunction | PropertyAttribute::CustomAccessorOrValue))) {
+ if ((entry.attributes() & (PropertyAttribute::Function)) == 0) {
+
+ if (!(entry.attributes() & (PropertyAttribute::Builtin | PropertyAttribute::CustomAccessorOrValue))) {
return true;
}
@@ -3781,7 +3787,7 @@ void JSC__JSValue__forEachProperty(JSC__JSValue JSValue0, JSC__JSGlobalObject* g
ZigString key = toZigString(entry.key());
JSC::JSValue propertyValue = object->getDirect(entry.offset());
- if (!propertyValue) {
+ if (!propertyValue || propertyValue.isGetterSetter()) {
propertyValue = object->get(globalObject, entry.key());
}
@@ -3799,8 +3805,8 @@ void JSC__JSValue__forEachProperty(JSC__JSValue JSValue0, JSC__JSGlobalObject* g
if (anyHits) {
if (scope.exception()) {
scope.clearException();
- return;
}
+
return;
}
}
@@ -3808,16 +3814,14 @@ void JSC__JSValue__forEachProperty(JSC__JSValue JSValue0, JSC__JSGlobalObject* g
JSC::PropertyNameArray properties(vm, PropertyNameMode::StringsAndSymbols, PrivateSymbolMode::Exclude);
{
- auto scope = DECLARE_THROW_SCOPE(vm);
- JSObject* iterating = object;
- unsigned prototypeCount = 0;
+ JSObject* iterating = prototypeObject.getObject();
+
size_t count = 0;
- while (count == 0) {
+ while (count == 0 && iterating && prototypeCount++ < 2) {
iterating->methodTable()->getOwnPropertyNames(iterating, globalObject, properties, DontEnumPropertiesMode::Include);
RETURN_IF_EXCEPTION(scope, void());
-
for (auto& property : properties) {
if (UNLIKELY(property.isEmpty() || property.isNull() || property.isPrivateName()))
continue;
@@ -3868,21 +3872,12 @@ void JSC__JSValue__forEachProperty(JSC__JSValue JSValue0, JSC__JSGlobalObject* g
}
// reuse memory
properties.data()->propertyNameVector().shrink(0);
-
- JSValue prototype = iterating->getPrototype(vm, globalObject);
- RETURN_IF_EXCEPTION(scope, void());
- if (prototype.isNull() || prototype == JSValue(globalObject->functionPrototype()) || prototype == JSValue(globalObject->objectPrototype()) || prototype == JSValue(globalObject->objectPrototype()))
- break;
-
- if (++prototypeCount > 1) {
- break;
- }
-
- iterating = asObject(prototype);
- if (iterating->structure()->typeInfo().overridesAnyFormOfGetOwnPropertyNames())
+ if (iterating->isCallable())
break;
+ iterating = iterating->getPrototype(vm, globalObject).getObject();
}
}
+
properties.releaseData();
if (scope.exception()) {
diff --git a/src/bun.js/bindings/webcore/JSReadableStream.cpp b/src/bun.js/bindings/webcore/JSReadableStream.cpp
index 98ec8694f..5073d583f 100644
--- a/src/bun.js/bindings/webcore/JSReadableStream.cpp
+++ b/src/bun.js/bindings/webcore/JSReadableStream.cpp
@@ -109,12 +109,12 @@ template<> FunctionExecutable* JSReadableStreamDOMConstructor::initializeExecuta
static const HashTableValue JSReadableStreamPrototypeTableValues[] = {
{ "constructor"_s, static_cast<unsigned>(JSC::PropertyAttribute::DontEnum), NoIntrinsic, { HashTableValue::GetterSetterType, jsReadableStreamConstructor, 0 } },
- { "locked"_s, static_cast<unsigned>(JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::Accessor | JSC::PropertyAttribute::Builtin), NoIntrinsic, { HashTableValue::BuiltinGeneratorType, readableStreamLockedCodeGenerator, 0 } },
- { "cancel"_s, static_cast<unsigned>(JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::Builtin), NoIntrinsic, { HashTableValue::BuiltinGeneratorType, readableStreamCancelCodeGenerator, 0 } },
- { "getReader"_s, static_cast<unsigned>(JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::Builtin), NoIntrinsic, { HashTableValue::BuiltinGeneratorType, readableStreamGetReaderCodeGenerator, 0 } },
- { "pipeTo"_s, static_cast<unsigned>(JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::Builtin), NoIntrinsic, { HashTableValue::BuiltinGeneratorType, readableStreamPipeToCodeGenerator, 1 } },
- { "pipeThrough"_s, static_cast<unsigned>(JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::Builtin), NoIntrinsic, { HashTableValue::BuiltinGeneratorType, readableStreamPipeThroughCodeGenerator, 2 } },
- { "tee"_s, static_cast<unsigned>(JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::Builtin), NoIntrinsic, { HashTableValue::BuiltinGeneratorType, readableStreamTeeCodeGenerator, 0 } },
+ { "locked"_s, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::Accessor | JSC::PropertyAttribute::Builtin), NoIntrinsic, { HashTableValue::BuiltinGeneratorType, readableStreamLockedCodeGenerator, 0 } },
+ { "cancel"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function | JSC::PropertyAttribute::Builtin), NoIntrinsic, { HashTableValue::BuiltinGeneratorType, readableStreamCancelCodeGenerator, 0 } },
+ { "getReader"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function | JSC::PropertyAttribute::Builtin), NoIntrinsic, { HashTableValue::BuiltinGeneratorType, readableStreamGetReaderCodeGenerator, 0 } },
+ { "pipeTo"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function | JSC::PropertyAttribute::Builtin), NoIntrinsic, { HashTableValue::BuiltinGeneratorType, readableStreamPipeToCodeGenerator, 1 } },
+ { "pipeThrough"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function | JSC::PropertyAttribute::Builtin), NoIntrinsic, { HashTableValue::BuiltinGeneratorType, readableStreamPipeThroughCodeGenerator, 2 } },
+ { "tee"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function | JSC::PropertyAttribute::Builtin), NoIntrinsic, { HashTableValue::BuiltinGeneratorType, readableStreamTeeCodeGenerator, 0 } },
};
const ClassInfo JSReadableStreamPrototype::s_info = { "ReadableStream"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSReadableStreamPrototype) };
diff --git a/src/bun.js/builtins/cpp/ReadableStreamBuiltins.cpp b/src/bun.js/builtins/cpp/ReadableStreamBuiltins.cpp
index 86d40d4e8..2d50f9cb3 100644
--- a/src/bun.js/builtins/cpp/ReadableStreamBuiltins.cpp
+++ b/src/bun.js/builtins/cpp/ReadableStreamBuiltins.cpp
@@ -480,12 +480,14 @@ const char* const s_readableStreamPipeThroughCode =
const JSC::ConstructAbility s_readableStreamPipeToCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
const JSC::ConstructorKind s_readableStreamPipeToCodeConstructorKind = JSC::ConstructorKind::None;
const JSC::ImplementationVisibility s_readableStreamPipeToCodeImplementationVisibility = JSC::ImplementationVisibility::Public;
-const int s_readableStreamPipeToCodeLength = 1523;
+const int s_readableStreamPipeToCodeLength = 1628;
static const JSC::Intrinsic s_readableStreamPipeToCodeIntrinsic = JSC::NoIntrinsic;
const char* const s_readableStreamPipeToCode =
"(function (destination)\n" \
"{\n" \
" \"use strict\";\n" \
+ " if (!@isReadableStream(readable))\n" \
+ " throw @makeTypeError(\"readable should be ReadableStream\");\n" \
"\n" \
" //\n" \
" //\n" \
diff --git a/src/bun.js/builtins/cpp/ReadableStreamInternalsBuiltins.cpp b/src/bun.js/builtins/cpp/ReadableStreamInternalsBuiltins.cpp
index 753e1a7c2..72231d8b3 100644
--- a/src/bun.js/builtins/cpp/ReadableStreamInternalsBuiltins.cpp
+++ b/src/bun.js/builtins/cpp/ReadableStreamInternalsBuiltins.cpp
@@ -2268,7 +2268,7 @@ const char* const s_readableStreamInternalsReadableStreamDefaultControllerCanClo
const JSC::ConstructAbility s_readableStreamInternalsLazyLoadStreamCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
const JSC::ConstructorKind s_readableStreamInternalsLazyLoadStreamCodeConstructorKind = JSC::ConstructorKind::None;
const JSC::ImplementationVisibility s_readableStreamInternalsLazyLoadStreamCodeImplementationVisibility = JSC::ImplementationVisibility::Public;
-const int s_readableStreamInternalsLazyLoadStreamCodeLength = 3827;
+const int s_readableStreamInternalsLazyLoadStreamCodeLength = 3840;
static const JSC::Intrinsic s_readableStreamInternalsLazyLoadStreamCodeIntrinsic = JSC::NoIntrinsic;
const char* const s_readableStreamInternalsLazyLoadStreamCode =
"(function (stream, autoAllocateChunkSize) {\n" \
@@ -2373,8 +2373,9 @@ const char* const s_readableStreamInternalsLazyLoadStreamCode =
"\n" \
" #cancel(reason) {\n" \
" var tag = this.#tag;\n" \
+ "\n" \
+ " registry && registry.unregister(this.#cancellationToken);\n" \
" setRefOrUnref && setRefOrUnref(tag, false);\n" \
- " registry.unregister(this.#cancellationToken);\n" \
" cancel(tag, reason);\n" \
" }\n" \
" static deinit = deinit;\n" \
diff --git a/src/bun.js/builtins/js/ReadableStream.js b/src/bun.js/builtins/js/ReadableStream.js
index fb4327ec8..6417c8ac1 100644
--- a/src/bun.js/builtins/js/ReadableStream.js
+++ b/src/bun.js/builtins/js/ReadableStream.js
@@ -380,6 +380,8 @@ function pipeThrough(streams, options)
function pipeTo(destination)
{
"use strict";
+ if (!@isReadableStream(readable))
+ throw @makeTypeError("readable should be ReadableStream");
// FIXME: https://bugs.webkit.org/show_bug.cgi?id=159869.
// Built-in generator should be able to parse function signature to compute the function length correctly.