1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 19:28:12 +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:
Marcin Gasperowicz 2020-05-28 17:19:59 +02:00 committed by GitHub
parent cbe506020b
commit eadce65e04
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 641 additions and 44 deletions

View file

@ -97,14 +97,8 @@ public:
void set_prototype(Object*);
bool has_prototype(const Object* prototype) const;
enum class PreferredType {
Default,
String,
Number,
};
virtual Value value_of() const { return Value(const_cast<Object*>(this)); }
virtual Value to_primitive(PreferredType preferred_type = PreferredType::Default) const;
virtual Value to_primitive(Value::PreferredType preferred_type = Value::PreferredType::Default) const;
virtual Value to_string() const;
Value get_direct(size_t index) const { return m_storage[index]; }