mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 04:48:14 +00:00
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:
parent
cbe506020b
commit
eadce65e04
5 changed files with 641 additions and 44 deletions
|
@ -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();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue