1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 19:37:35 +00:00

LibJS: Add JSON.stringify

This commit is contained in:
Matthew Olsson 2020-06-10 11:01:00 -07:00 committed by Andreas Kling
parent b4577ffcf3
commit 39576b2238
19 changed files with 678 additions and 10 deletions

View file

@ -81,6 +81,12 @@ bool Value::is_array() const
return is_object() && as_object().is_array();
}
Array& Value::as_array()
{
ASSERT(is_array());
return static_cast<Array&>(*m_value.as_object);
}
bool Value::is_function() const
{
return is_object() && as_object().is_function();
@ -940,4 +946,13 @@ TriState abstract_relation(Interpreter& interpreter, bool left_first, Value lhs,
return TriState::False;
}
size_t length_of_array_like(Interpreter& interpreter, Value value)
{
ASSERT(value.is_object());
auto result = value.as_object().get("length");
if (interpreter.exception())
return 0;
return result.to_size_t(interpreter);
}
}