aboutsummaryrefslogtreecommitdiff
path: root/src/bun.js/bindings/bindings.cpp
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2023-01-17 13:44:13 -0800
committerGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2023-01-17 13:44:13 -0800
commit69875d86cd24b9fd0368c61ed038f96207919a39 (patch)
treeca9fc6c5810158b0d7bed25872cc961a693c572c /src/bun.js/bindings/bindings.cpp
parent5bdc923838da0ccacd30c092b00446f4f503a26f (diff)
downloadbun-69875d86cd24b9fd0368c61ed038f96207919a39.tar.gz
bun-69875d86cd24b9fd0368c61ed038f96207919a39.tar.zst
bun-69875d86cd24b9fd0368c61ed038f96207919a39.zip
Fix console.log printing multiple properties
Diffstat (limited to 'src/bun.js/bindings/bindings.cpp')
-rw-r--r--src/bun.js/bindings/bindings.cpp28
1 files changed, 20 insertions, 8 deletions
diff --git a/src/bun.js/bindings/bindings.cpp b/src/bun.js/bindings/bindings.cpp
index eb0529e40..4b05f542e 100644
--- a/src/bun.js/bindings/bindings.cpp
+++ b/src/bun.js/bindings/bindings.cpp
@@ -3543,6 +3543,8 @@ void JSC__JSValue__forEachProperty(JSC__JSValue JSValue0, JSC__JSGlobalObject* g
}
auto* clientData = WebCore::clientData(vm);
+ WTF::Vector<Identifier, 6> visitedProperties;
+
restart:
if (fast) {
bool anyHits = false;
@@ -3555,24 +3557,30 @@ restart:
if ((entry.attributes() & (PropertyAttribute::Function)) == 0 && (entry.attributes() & (PropertyAttribute::Builtin)) != 0) {
return true;
}
+ auto* prop = entry.key();
+
+ if (prop == vm.propertyNames->constructor
+ || prop == vm.propertyNames->length
+ || prop == vm.propertyNames->underscoreProto
+ || prop == vm.propertyNames->toStringTagSymbol)
+ return true;
- if (entry.key() == vm.propertyNames->constructor
- || entry.key() == vm.propertyNames->length
- || entry.key() == vm.propertyNames->underscoreProto
- || entry.key() == vm.propertyNames->toStringTagSymbol)
+ if (clientData->builtinNames().bunNativePtrPrivateName() == prop)
return true;
- if (clientData->builtinNames().bunNativePtrPrivateName() == entry.key())
+ if (visitedProperties.contains(Identifier::fromUid(vm, prop))) {
return true;
+ }
+ visitedProperties.append(Identifier::fromUid(vm, prop));
- ZigString key = toZigString(entry.key());
+ ZigString key = toZigString(prop);
if (key.len == 0)
return true;
JSC::JSValue propertyValue = objectToUse == object ? objectToUse->getDirect(entry.offset()) : JSValue();
if (!propertyValue || propertyValue.isGetterSetter()) {
- propertyValue = objectToUse->get(globalObject, entry.key());
+ propertyValue = objectToUse->get(globalObject, prop);
}
if (scope.exception())
@@ -3583,7 +3591,7 @@ restart:
anyHits = true;
JSC::EnsureStillAliveScope ensureStillAliveScope(propertyValue);
- iter(globalObject, arg2, &key, JSC::JSValue::encode(propertyValue), entry.key()->isSymbol());
+ iter(globalObject, arg2, &key, JSC::JSValue::encode(propertyValue), prop->isSymbol());
return true;
});
if (scope.exception()) {
@@ -3641,6 +3649,10 @@ restart:
continue;
}
+ if (visitedProperties.contains(property))
+ continue;
+ visitedProperties.append(property);
+
ZigString key = toZigString(property.isSymbol() && !property.isPrivateName() ? property.impl() : property.string());
if (key.len == 0)