LibJS: Implement standard semantics for relational operators (#2417)

Previously, the relational operators where casting any value to double
and comparing the results according to C++ semantics.

This patch makes the relational operators in JS behave according to the
standard specification.

Since we don't have BigInt yet, the implementation doesn't take it into
account. 

Moved PreferredType from Object to Value. Value::to_primitive now
passes preferred_type to Object::to_primitive.
This commit is contained in:
Marcin Gasperowicz 2020-05-28 17:19:59 +02:00 committed by GitHub
commit eadce65e04
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
Notes: sideshowbarker 2024-07-19 06:02:00 +09:00
5 changed files with 641 additions and 44 deletions

View file

@ -618,20 +618,20 @@ bool Object::has_own_property(PropertyName property_name) const
return shape().lookup(property_name.as_string()).has_value();
}
Value Object::to_primitive(PreferredType preferred_type) const
Value Object::to_primitive(Value::PreferredType preferred_type) const
{
Value result = js_undefined();
switch (preferred_type) {
case PreferredType::Default:
case PreferredType::Number: {
case Value::PreferredType::Default:
case Value::PreferredType::Number: {
result = value_of();
if (result.is_object()) {
result = to_string();
}
break;
}
case PreferredType::String: {
case Value::PreferredType::String: {
result = to_string();
if (result.is_object())
result = value_of();