diff options
Diffstat (limited to 'Userland/Libraries/LibJS/Runtime/Reference.h')
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/Reference.h | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/Reference.h b/Userland/Libraries/LibJS/Runtime/Reference.h index 3999b025ca..39793af82b 100644 --- a/Userland/Libraries/LibJS/Runtime/Reference.h +++ b/Userland/Libraries/LibJS/Runtime/Reference.h @@ -15,6 +15,8 @@ namespace JS { +Reference make_private_reference(VM&, Value base_value, FlyString const& private_identifier); + class Reference { public: enum class BaseType : u8 { @@ -55,6 +57,16 @@ public: { } + Reference(Value base, PrivateName name) + : m_base_type(BaseType::Value) + , m_base_value(base) + , m_this_value(Value {}) + , m_strict(true) + , m_is_private(true) + , m_private_name(move(name)) + { + } + Value base() const { VERIFY(m_base_type == BaseType::Value); @@ -80,9 +92,7 @@ public: return false; if (m_base_type == BaseType::Environment) return false; - if (m_base_value.is_boolean() || m_base_value.is_string() || m_base_value.is_symbol() || m_base_value.is_bigint() || m_base_value.is_number() || m_base_value.is_object()) - return true; - return false; + return true; } // 6.2.4.7 GetThisValue ( V ), https://tc39.es/ecma262/#sec-getthisvalue @@ -100,6 +110,12 @@ public: return !m_this_value.is_empty(); } + // 6.2.4.4 IsPrivateReference ( V ), https://tc39.es/ecma262/#sec-isprivatereference + bool is_private_reference() const + { + return m_is_private; + } + // Note: Non-standard helper. bool is_environment_reference() const { @@ -119,7 +135,7 @@ public: String to_string() const; - bool is_valid_reference() const { return m_name.is_valid(); } + bool is_valid_reference() const { return m_name.is_valid() || m_is_private; } Optional<EnvironmentCoordinate> environment_coordinate() const { return m_environment_coordinate; } @@ -134,6 +150,11 @@ private: PropertyName m_name; Value m_this_value; bool m_strict { false }; + + bool m_is_private { false }; + // FIXME: This can (probably) be an union with m_name. + PrivateName m_private_name { 0, "" }; + Optional<EnvironmentCoordinate> m_environment_coordinate; }; |