mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 10:47:35 +00:00
LibJS: Add private references
This commit is contained in:
parent
d94b5e511f
commit
c7a6572789
2 changed files with 43 additions and 5 deletions
|
@ -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;
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue