Skip to content

Commit

Permalink
Fix equality between objects and undefined or null
Browse files Browse the repository at this point in the history
  • Loading branch information
HalidOdat committed Feb 27, 2022
1 parent 60e2294 commit 9279606
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions boa_engine/src/value/equality.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,34 @@ impl JsValue {

// 10. If Type(x) is either String, Number, BigInt, or Symbol and Type(y) is Object, return the result
// of the comparison x == ? ToPrimitive(y).
(Self::Object(_), _) => {
(
Self::Object(_),
Self::String(_)
| Self::Rational(_)
| Self::Integer(_)
| Self::BigInt(_)
| Self::Symbol(_),
) => {
let primitive = self.to_primitive(context, PreferredType::Default)?;
return primitive.equals(other, context);
return Ok(primitive
.equals(other, context)
.expect("should not fail according to spec"));
}

// 11. If Type(x) is Object and Type(y) is either String, Number, BigInt, or Symbol, return the result
// of the comparison ? ToPrimitive(x) == y.
(_, Self::Object(_)) => {
(
Self::String(_)
| Self::Rational(_)
| Self::Integer(_)
| Self::BigInt(_)
| Self::Symbol(_),
Self::Object(_),
) => {
let primitive = other.to_primitive(context, PreferredType::Default)?;
return primitive.equals(self, context);
return Ok(primitive
.equals(self, context)
.expect("should not fail according to spec"));
}

// 12. If Type(x) is BigInt and Type(y) is Number, or if Type(x) is Number and Type(y) is BigInt, then
Expand Down

0 comments on commit 9279606

Please sign in to comment.