mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 00:37:35 +00:00
LibJS: Provide default hash traits for JS::PropertyKey
Let's not require people to use PropertyNameTraits everywhere when we can just specialize AK::Traits<JS::PropertyKey> instead. :^)
This commit is contained in:
parent
c02e992de2
commit
7ccb8c8609
5 changed files with 15 additions and 14 deletions
|
@ -445,7 +445,7 @@ ThrowCompletionOr<MarkedValueList> Object::enumerable_own_property_names(Propert
|
||||||
}
|
}
|
||||||
|
|
||||||
// 7.3.25 CopyDataProperties ( target, source, excludedItems ), https://tc39.es/ecma262/#sec-copydataproperties
|
// 7.3.25 CopyDataProperties ( target, source, excludedItems ), https://tc39.es/ecma262/#sec-copydataproperties
|
||||||
ThrowCompletionOr<Object*> Object::copy_data_properties(Value source, HashTable<PropertyKey, PropertyNameTraits> const& seen_names, GlobalObject& global_object)
|
ThrowCompletionOr<Object*> Object::copy_data_properties(Value source, HashTable<PropertyKey> const& seen_names, GlobalObject& global_object)
|
||||||
{
|
{
|
||||||
if (source.is_nullish())
|
if (source.is_nullish())
|
||||||
return this;
|
return this;
|
||||||
|
|
|
@ -101,7 +101,7 @@ public:
|
||||||
ThrowCompletionOr<bool> set_integrity_level(IntegrityLevel);
|
ThrowCompletionOr<bool> set_integrity_level(IntegrityLevel);
|
||||||
ThrowCompletionOr<bool> test_integrity_level(IntegrityLevel) const;
|
ThrowCompletionOr<bool> test_integrity_level(IntegrityLevel) const;
|
||||||
ThrowCompletionOr<MarkedValueList> enumerable_own_property_names(PropertyKind kind) const;
|
ThrowCompletionOr<MarkedValueList> enumerable_own_property_names(PropertyKind kind) const;
|
||||||
ThrowCompletionOr<Object*> copy_data_properties(Value source, HashTable<PropertyKey, PropertyNameTraits> const& seen_names, GlobalObject& global_object);
|
ThrowCompletionOr<Object*> copy_data_properties(Value source, HashTable<PropertyKey> const& seen_names, GlobalObject& global_object);
|
||||||
|
|
||||||
PrivateElement* private_element_find(PrivateName const& name);
|
PrivateElement* private_element_find(PrivateName const& name);
|
||||||
ThrowCompletionOr<void> private_field_add(PrivateName const& name, Value value);
|
ThrowCompletionOr<void> private_field_add(PrivateName const& name, Value value);
|
||||||
|
|
|
@ -189,8 +189,13 @@ private:
|
||||||
Symbol* m_symbol { nullptr };
|
Symbol* m_symbol { nullptr };
|
||||||
};
|
};
|
||||||
|
|
||||||
struct PropertyNameTraits : public Traits<PropertyKey> {
|
}
|
||||||
static unsigned hash(PropertyKey const& name)
|
|
||||||
|
namespace AK {
|
||||||
|
|
||||||
|
template<>
|
||||||
|
struct Traits<JS::PropertyKey> : public GenericTraits<JS::PropertyKey> {
|
||||||
|
static unsigned hash(JS::PropertyKey const& name)
|
||||||
{
|
{
|
||||||
VERIFY(name.is_valid());
|
VERIFY(name.is_valid());
|
||||||
if (name.is_string())
|
if (name.is_string())
|
||||||
|
@ -200,17 +205,17 @@ struct PropertyNameTraits : public Traits<PropertyKey> {
|
||||||
return ptr_hash(name.as_symbol());
|
return ptr_hash(name.as_symbol());
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool equals(PropertyKey const& a, PropertyKey const& b)
|
static bool equals(JS::PropertyKey const& a, JS::PropertyKey const& b)
|
||||||
{
|
{
|
||||||
if (a.type() != b.type())
|
if (a.type() != b.type())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
switch (a.type()) {
|
switch (a.type()) {
|
||||||
case PropertyKey::Type::Number:
|
case JS::PropertyKey::Type::Number:
|
||||||
return a.as_number() == b.as_number();
|
return a.as_number() == b.as_number();
|
||||||
case PropertyKey::Type::String:
|
case JS::PropertyKey::Type::String:
|
||||||
return a.as_string() == b.as_string();
|
return a.as_string() == b.as_string();
|
||||||
case PropertyKey::Type::Symbol:
|
case JS::PropertyKey::Type::Symbol:
|
||||||
return a.as_symbol() == b.as_symbol();
|
return a.as_symbol() == b.as_symbol();
|
||||||
default:
|
default:
|
||||||
VERIFY_NOT_REACHED();
|
VERIFY_NOT_REACHED();
|
||||||
|
@ -218,10 +223,6 @@ struct PropertyNameTraits : public Traits<PropertyKey> {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace AK {
|
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct Formatter<JS::PropertyKey> : Formatter<StringView> {
|
struct Formatter<JS::PropertyKey> : Formatter<StringView> {
|
||||||
void format(FormatBuilder& builder, JS::PropertyKey const& property_name)
|
void format(FormatBuilder& builder, JS::PropertyKey const& property_name)
|
||||||
|
|
|
@ -219,7 +219,7 @@ ThrowCompletionOr<void> VM::property_binding_initialization(BindingPattern const
|
||||||
{
|
{
|
||||||
auto* object = TRY(value.to_object(global_object));
|
auto* object = TRY(value.to_object(global_object));
|
||||||
|
|
||||||
HashTable<PropertyKey, PropertyNameTraits> seen_names;
|
HashTable<PropertyKey> seen_names;
|
||||||
for (auto& property : binding.entries) {
|
for (auto& property : binding.entries) {
|
||||||
|
|
||||||
VERIFY(!property.is_elision());
|
VERIFY(!property.is_elision());
|
||||||
|
|
|
@ -279,7 +279,7 @@ private:
|
||||||
|
|
||||||
[[nodiscard]] ThrowCompletionOr<Value> call_internal(FunctionObject&, Value this_value, Optional<MarkedValueList> arguments);
|
[[nodiscard]] ThrowCompletionOr<Value> call_internal(FunctionObject&, Value this_value, Optional<MarkedValueList> arguments);
|
||||||
|
|
||||||
ThrowCompletionOr<Object*> copy_data_properties(Object& rest_object, Object const& source, HashTable<PropertyKey, PropertyNameTraits> const& seen_names, GlobalObject& global_object);
|
ThrowCompletionOr<Object*> copy_data_properties(Object& rest_object, Object const& source, HashTable<PropertyKey> const& seen_names, GlobalObject& global_object);
|
||||||
|
|
||||||
ThrowCompletionOr<void> property_binding_initialization(BindingPattern const& binding, Value value, Environment* environment, GlobalObject& global_object);
|
ThrowCompletionOr<void> property_binding_initialization(BindingPattern const& binding, Value value, Environment* environment, GlobalObject& global_object);
|
||||||
ThrowCompletionOr<void> iterator_binding_initialization(BindingPattern const& binding, Object* iterator, bool& iterator_done, Environment* environment, GlobalObject& global_object);
|
ThrowCompletionOr<void> iterator_binding_initialization(BindingPattern const& binding, Object* iterator, bool& iterator_done, Environment* environment, GlobalObject& global_object);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue