1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 07:48:11 +00:00

LibJS: Spec-compliant equality comparisons

The ECMAScript spec defines multiple equality operations which are used
all over the spec; this patch introduces them. Of course, the two
primary equality operations are AbtractEquals ('==') and StrictEquals
('==='), which have been renamed to 'abstract_eq' and 'strict_eq' in
this patch.

In support of the two operations mentioned above, the following have
also been added: SameValue, SameValueZero, and SameValueNonNumeric.
These are important to have, because they are used elsewhere in the spec
aside from the two primary equality comparisons.
This commit is contained in:
Matthew Olsson 2020-05-07 17:09:00 -07:00 committed by Andreas Kling
parent cc01933840
commit 532d4bc0ab
6 changed files with 126 additions and 82 deletions

View file

@ -131,18 +131,7 @@ Value ObjectConstructor::define_property(Interpreter& interpreter)
Value ObjectConstructor::is(Interpreter& interpreter)
{
auto value1 = interpreter.argument(0);
auto value2 = interpreter.argument(1);
if (value1.is_nan() && value2.is_nan())
return Value(true);
if (value1.is_number() && value1.as_double() == 0 && value2.is_number() && value2.as_double() == 0) {
if (value1.is_positive_zero() && value2.is_positive_zero())
return Value(true);
if (value1.is_negative_zero() && value2.is_negative_zero())
return Value(true);
return Value(false);
}
return typed_eq(interpreter, value1, value2);
return Value(same_value(interpreter, interpreter.argument(0), interpreter.argument(1)));
}
Value ObjectConstructor::keys(Interpreter& interpreter)