aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/bun.js/bindings/bindings.cpp12
-rw-r--r--test/js/bun/test/expect.test.js56
2 files changed, 62 insertions, 6 deletions
diff --git a/src/bun.js/bindings/bindings.cpp b/src/bun.js/bindings/bindings.cpp
index be3408555..96fcde303 100644
--- a/src/bun.js/bindings/bindings.cpp
+++ b/src/bun.js/bindings/bindings.cpp
@@ -679,8 +679,8 @@ bool Bun__deepEquals(JSC__JSGlobalObject* globalObject, JSValue v1, JSValue v2,
return false;
}
- JSC::PropertyNameArray a1(vm, PropertyNameMode::Symbols, PrivateSymbolMode::Include);
- JSC::PropertyNameArray a2(vm, PropertyNameMode::Symbols, PrivateSymbolMode::Include);
+ JSC::PropertyNameArray a1(vm, PropertyNameMode::Symbols, PrivateSymbolMode::Exclude);
+ JSC::PropertyNameArray a2(vm, PropertyNameMode::Symbols, PrivateSymbolMode::Exclude);
JSObject::getOwnPropertyNames(o1, globalObject, a1, DontEnumPropertiesMode::Exclude);
JSObject::getOwnPropertyNames(o2, globalObject, a2, DontEnumPropertiesMode::Exclude);
@@ -753,7 +753,7 @@ bool Bun__deepEquals(JSC__JSGlobalObject* globalObject, JSValue v1, JSValue v2,
}
o1Structure->forEachProperty(vm, [&](const PropertyTableEntry& entry) -> bool {
- if (entry.attributes() & PropertyAttribute::DontEnum) {
+ if (entry.attributes() & PropertyAttribute::DontEnum || PropertyName(entry.key()).isPrivateName()) {
return true;
}
count1++;
@@ -787,7 +787,7 @@ bool Bun__deepEquals(JSC__JSGlobalObject* globalObject, JSValue v1, JSValue v2,
if (result && o2Structure->id() != o1Structure->id()) {
size_t remain = count1;
o2Structure->forEachProperty(vm, [&](const PropertyTableEntry& entry) -> bool {
- if (entry.attributes() & PropertyAttribute::DontEnum) {
+ if (entry.attributes() & PropertyAttribute::DontEnum || PropertyName(entry.key()).isPrivateName()) {
return true;
}
@@ -815,8 +815,8 @@ bool Bun__deepEquals(JSC__JSGlobalObject* globalObject, JSValue v1, JSValue v2,
}
}
- JSC::PropertyNameArray a1(vm, PropertyNameMode::StringsAndSymbols, PrivateSymbolMode::Include);
- JSC::PropertyNameArray a2(vm, PropertyNameMode::StringsAndSymbols, PrivateSymbolMode::Include);
+ JSC::PropertyNameArray a1(vm, PropertyNameMode::StringsAndSymbols, PrivateSymbolMode::Exclude);
+ JSC::PropertyNameArray a2(vm, PropertyNameMode::StringsAndSymbols, PrivateSymbolMode::Exclude);
o1->getPropertyNames(globalObject, a1, DontEnumPropertiesMode::Exclude);
o2->getPropertyNames(globalObject, a2, DontEnumPropertiesMode::Exclude);
diff --git a/test/js/bun/test/expect.test.js b/test/js/bun/test/expect.test.js
index e7195d6f8..ed94b7e9a 100644
--- a/test/js/bun/test/expect.test.js
+++ b/test/js/bun/test/expect.test.js
@@ -1335,6 +1335,62 @@ describe("expect()", () => {
expect([1, 2, 3, 4]).not.toEqual([1, 2, 3]);
});
+ test("toEqual() - private class fields", () => {
+ class A {
+ #three = 3;
+ set three(value) {
+ this.#three = value;
+ }
+
+ get three() {
+ return this.#three;
+ }
+ }
+
+ class B {
+ #three = 3;
+ set three(value) {
+ this.#three = value;
+ }
+
+ get three() {
+ return this.#three;
+ }
+ }
+
+ let a1 = new A();
+ let a2 = new A();
+ a1.three = 4;
+ expect(a1).toEqual(a2);
+ expect(a2).toEqual(a1);
+
+ let a3 = new A();
+ let a4 = new A();
+ a3.three = 4;
+ // use indexed properties for slow path
+ a3[1] = 2;
+ a4[1] = 2;
+ expect(a3).toEqual(a4);
+ expect(a4).toEqual(a3);
+
+ let b1 = new B();
+ let a5 = new A();
+ expect(b1).toEqual(a5);
+ expect(a5).toEqual(b1);
+
+ b1.three = 4;
+ expect(b1).toEqual(a5);
+ expect(a5).toEqual(b1);
+
+ b1[1] = 2;
+ expect(b1).not.toEqual(a5);
+ expect(a5).not.toEqual(b1);
+
+ a5[1] = 2;
+ expect(b1).toEqual(a5);
+ expect(a5).toEqual(b1);
+ });
+
test("properties with different circularity are not equal", () => {
const a = {};
a.x = { y: a };