summaryrefslogtreecommitdiff
path: root/Libraries/LibJS/Runtime/Value.h
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-04-06 20:24:45 +0200
committerAndreas Kling <kling@serenityos.org>2020-04-06 20:27:44 +0200
commitbdffc9e7fb7b721710d3ef38cc457a5e66f3542a (patch)
tree283ef9d6e1e1fd408d4458977fce315972686055 /Libraries/LibJS/Runtime/Value.h
parent5495f06af55bc371b3f4b3e09960ce0fbbe49590 (diff)
downloadserenity-bdffc9e7fb7b721710d3ef38cc457a5e66f3542a.zip
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.
Diffstat (limited to 'Libraries/LibJS/Runtime/Value.h')
-rw-r--r--Libraries/LibJS/Runtime/Value.h7
1 files changed, 3 insertions, 4 deletions
diff --git a/Libraries/LibJS/Runtime/Value.h b/Libraries/LibJS/Runtime/Value.h
index b6d30c80f1..f6240c316f 100644
--- a/Libraries/LibJS/Runtime/Value.h
+++ b/Libraries/LibJS/Runtime/Value.h
@@ -36,6 +36,7 @@ namespace JS {
class Value {
public:
enum class Type {
+ Empty,
Undefined,
Null,
Number,
@@ -44,6 +45,7 @@ public:
Boolean,
};
+ bool is_empty() const { return m_type == Type::Empty; }
bool is_undefined() const { return m_type == Type::Undefined; }
bool is_null() const { return m_type == Type::Null; }
bool is_number() const { return m_type == Type::Number; }
@@ -56,10 +58,7 @@ public:
bool is_nan() const { return is_number() && __builtin_isnan(as_double()); }
bool is_infinity() const { return is_number() && __builtin_isinf(as_double()); }
- Value()
- : m_type(Type::Undefined)
- {
- }
+ Value();
explicit Value(bool value)
: m_type(Type::Boolean)