mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 09:58: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:
parent
cc01933840
commit
532d4bc0ab
6 changed files with 126 additions and 82 deletions
|
@ -41,7 +41,6 @@
|
|||
#include <LibJS/Runtime/ScriptFunction.h>
|
||||
#include <LibJS/Runtime/Shape.h>
|
||||
#include <LibJS/Runtime/StringObject.h>
|
||||
#include <LibJS/Runtime/Value.h>
|
||||
#include <stdio.h>
|
||||
|
||||
namespace JS {
|
||||
|
@ -345,13 +344,13 @@ Value BinaryExpression::execute(Interpreter& interpreter) const
|
|||
case BinaryOp::Exponentiation:
|
||||
return exp(interpreter, lhs_result, rhs_result);
|
||||
case BinaryOp::TypedEquals:
|
||||
return typed_eq(interpreter, lhs_result, rhs_result);
|
||||
return Value(strict_eq(interpreter, lhs_result, rhs_result));
|
||||
case BinaryOp::TypedInequals:
|
||||
return Value(!typed_eq(interpreter, lhs_result, rhs_result).as_bool());
|
||||
return Value(!strict_eq(interpreter, lhs_result, rhs_result));
|
||||
case BinaryOp::AbstractEquals:
|
||||
return eq(interpreter, lhs_result, rhs_result);
|
||||
return Value(abstract_eq(interpreter, lhs_result, rhs_result));
|
||||
case BinaryOp::AbstractInequals:
|
||||
return Value(!eq(interpreter, lhs_result, rhs_result).as_bool());
|
||||
return Value(!abstract_eq(interpreter, lhs_result, rhs_result));
|
||||
case BinaryOp::GreaterThan:
|
||||
return greater_than(interpreter, lhs_result, rhs_result);
|
||||
case BinaryOp::GreaterThanEquals:
|
||||
|
@ -1444,7 +1443,7 @@ Value SwitchStatement::execute(Interpreter& interpreter) const
|
|||
auto test_result = switch_case.test()->execute(interpreter);
|
||||
if (interpreter.exception())
|
||||
return {};
|
||||
if (!eq(interpreter, discriminant_result, test_result).to_boolean())
|
||||
if (!strict_eq(interpreter, discriminant_result, test_result))
|
||||
continue;
|
||||
}
|
||||
falling_through = true;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue