mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 23:07:35 +00:00
LibJS: Implement spec-compliant OrdinaryToPrimitive
This renames Object::to_primitive() to Object::ordinary_to_primitive() for two reasons: - No confusion with Value::to_primitive() - To match the spec's name Also change existing uses of Object::to_primitive() to Value::to_primitive() when the spec uses the latter (which will still call Object::ordinary_to_primitive()). Object::to_string() has been removed as it's not needed anymore (and nothing the spec uses). This makes it possible to overwrite an object's toString and valueOf and have them provide results for anything that uses to_primitive() - e.g.: const o = { toString: undefined, valueOf: () => 42 }; Number(o) // 42, previously NaN ["foo", o].toString(); // "foo,42", previously "foo,[object Object]" ++o // 43, previously NaN etc.
This commit is contained in:
parent
e163db248d
commit
fb89c324c5
4 changed files with 50 additions and 42 deletions
|
@ -140,8 +140,7 @@ public:
|
|||
virtual bool prevent_extensions();
|
||||
|
||||
virtual Value value_of() const { return Value(const_cast<Object*>(this)); }
|
||||
virtual Value to_primitive(Value::PreferredType preferred_type = Value::PreferredType::Default) const;
|
||||
virtual Value to_string() const;
|
||||
virtual Value ordinary_to_primitive(Value::PreferredType preferred_type) const;
|
||||
|
||||
Value get_direct(size_t index) const { return m_storage[index]; }
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue