1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 03:57:44 +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:
Andreas Kling 2020-04-06 20:24:45 +02:00
parent 5495f06af5
commit bdffc9e7fb
9 changed files with 102 additions and 35 deletions

View file

@ -33,10 +33,13 @@ namespace JS {
class PropertyName {
public:
enum class Type {
Invalid,
Number,
String,
};
PropertyName() {}
explicit PropertyName(i32 index)
: m_type(Type::Number)
, m_number(index)
@ -50,6 +53,7 @@ public:
{
}
bool is_valid() const { return m_type != Type::Invalid; }
bool is_number() const { return m_type == Type::Number; }
bool is_string() const { return m_type == Type::String; }
@ -57,7 +61,7 @@ public:
const FlyString& as_string() const { return m_string; }
private:
Type m_type;
Type m_type { Type::Invalid };
FlyString m_string;
i32 m_number { 0 };
};