mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 14:37:45 +00:00
LibJS: Restructure and fully implement BindingPatterns
This commit is contained in:
parent
10372b8118
commit
ce04c2259f
9 changed files with 244 additions and 169 deletions
|
@ -87,6 +87,8 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
ALWAYS_INLINE Type type() const { return m_type; }
|
||||
|
||||
bool is_valid() const { return m_type != Type::Invalid; }
|
||||
bool is_number() const
|
||||
{
|
||||
|
@ -176,6 +178,35 @@ private:
|
|||
u32 m_number { 0 };
|
||||
};
|
||||
|
||||
struct PropertyNameTraits : public Traits<PropertyName> {
|
||||
static unsigned hash(PropertyName const& name)
|
||||
{
|
||||
VERIFY(name.is_valid());
|
||||
if (name.is_string())
|
||||
return name.as_string().hash();
|
||||
if (name.is_number())
|
||||
return int_hash(name.as_number());
|
||||
return ptr_hash(name.as_symbol());
|
||||
}
|
||||
|
||||
static bool equals(PropertyName const& a, PropertyName const& b)
|
||||
{
|
||||
if (a.type() != b.type())
|
||||
return false;
|
||||
|
||||
switch (a.type()) {
|
||||
case PropertyName::Type::Number:
|
||||
return a.as_number() == b.as_number();
|
||||
case PropertyName::Type::String:
|
||||
return a.as_string() == b.as_string();
|
||||
case PropertyName::Type::Symbol:
|
||||
return a.as_symbol() == b.as_symbol();
|
||||
default:
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
namespace AK {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue