mirror of
https://github.com/fergalmoran/ladybird.git
synced 2026-01-07 09:04:30 +00:00
LibJS: Loosen type system
This commits makes effort towards tolerating some of javascript's quirks when it comes to its type system, note that the interpreter's way of handling type coercion is still not mature at all, for example, we still have to implement NaN instead of just crashing when trying to parse a string and failing.
This commit is contained in:
committed by
Andreas Kling
parent
419d57e492
commit
4d22a142f7
@@ -87,4 +87,34 @@ bool Object::has_own_property(const String& property_name) const
|
||||
return m_properties.get(property_name).has_value();
|
||||
}
|
||||
|
||||
Value Object::to_primitive(PreferredType preferred_type) const
|
||||
{
|
||||
Value result = js_undefined();
|
||||
|
||||
switch (preferred_type) {
|
||||
case PreferredType::Default:
|
||||
case PreferredType::Number: {
|
||||
result = value_of();
|
||||
if (result.is_object()) {
|
||||
result = to_string();
|
||||
}
|
||||
break;
|
||||
}
|
||||
case PreferredType::String: {
|
||||
result = to_string();
|
||||
if (result.is_object())
|
||||
result = value_of();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ASSERT(!result.is_object());
|
||||
return result;
|
||||
}
|
||||
|
||||
Value Object::to_string() const
|
||||
{
|
||||
return js_string(heap(), String::format("[object %s]", class_name()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user