mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 12:38:12 +00:00
LibJS: Support array holes, encoded as empty JS::Value
This patch adds a new kind of JS::Value, the empty value. It's what you get when you do JSValue() (or most commonly, {} in C++.) An empty Value signifies the absence of a value, and should never be visible to JavaScript itself. As of right now, it's used for array holes and as a return value when an exception has been thrown and we just want to unwind. This patch is a bit of a mess as I had to fix a whole bunch of code that was relying on JSValue() being undefined, etc.
This commit is contained in:
parent
5495f06af5
commit
bdffc9e7fb
9 changed files with 102 additions and 35 deletions
|
@ -39,6 +39,14 @@
|
|||
|
||||
namespace JS {
|
||||
|
||||
Value::Value()
|
||||
: m_type(Type::Empty)
|
||||
{
|
||||
// dbg() << "Create empty value";
|
||||
// dump_backtrace();
|
||||
}
|
||||
|
||||
|
||||
bool Value::is_array() const
|
||||
{
|
||||
return is_object() && as_object().is_array();
|
||||
|
@ -119,6 +127,9 @@ Object* Value::to_object(Heap& heap) const
|
|||
Value Value::to_number() const
|
||||
{
|
||||
switch (m_type) {
|
||||
case Type::Empty:
|
||||
ASSERT_NOT_REACHED();
|
||||
return {};
|
||||
case Type::Boolean:
|
||||
return Value(m_value.as_bool ? 1 : 0);
|
||||
case Type::Number:
|
||||
|
@ -280,6 +291,9 @@ Value typed_eq(Value lhs, Value rhs)
|
|||
return Value(false);
|
||||
|
||||
switch (lhs.type()) {
|
||||
case Value::Type::Empty:
|
||||
ASSERT_NOT_REACHED();
|
||||
return {};
|
||||
case Value::Type::Undefined:
|
||||
return Value(true);
|
||||
case Value::Type::Null:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue