summaryrefslogtreecommitdiff
path: root/Libraries/LibJS/Runtime/Shape.h
diff options
context:
space:
mode:
authorMatthew Olsson <matthewcolsson@gmail.com>2020-07-07 21:38:46 -0700
committerAndreas Kling <kling@serenityos.org>2020-07-09 23:33:00 +0200
commit7a1d485b19a43b3538b3ac69040ebc2b3bb14d85 (patch)
tree911f871ab04920383b79d24ae22c9ea80976685c /Libraries/LibJS/Runtime/Shape.h
parent9783a4936cd0677dc3fe12cbf9009eceb47c4d1f (diff)
downloadserenity-7a1d485b19a43b3538b3ac69040ebc2b3bb14d85.zip
LibJS: Integrate Symbols into objects as valid keys
This allows objects properties to be created for symbol keys in addition to just plain strings/numbers
Diffstat (limited to 'Libraries/LibJS/Runtime/Shape.h')
-rw-r--r--Libraries/LibJS/Runtime/Shape.h28
1 files changed, 14 insertions, 14 deletions
diff --git a/Libraries/LibJS/Runtime/Shape.h b/Libraries/LibJS/Runtime/Shape.h
index 17fd34a057..4e7f87391c 100644
--- a/Libraries/LibJS/Runtime/Shape.h
+++ b/Libraries/LibJS/Runtime/Shape.h
@@ -26,12 +26,12 @@
#pragma once
-#include <AK/FlyString.h>
#include <AK/HashMap.h>
#include <AK/OwnPtr.h>
#include <LibJS/Forward.h>
#include <LibJS/Runtime/Cell.h>
#include <LibJS/Runtime/PropertyAttributes.h>
+#include <LibJS/Runtime/StringOrSymbol.h>
#include <LibJS/Runtime/Value.h>
namespace JS {
@@ -42,7 +42,7 @@ struct PropertyMetadata {
};
struct TransitionKey {
- FlyString property_name;
+ StringOrSymbol property_name;
PropertyAttributes attributes { 0 };
bool operator==(const TransitionKey& other) const
@@ -63,11 +63,11 @@ public:
};
explicit Shape(GlobalObject&);
- Shape(Shape& previous_shape, const FlyString& property_name, PropertyAttributes attributes, TransitionType);
+ Shape(Shape& previous_shape, const StringOrSymbol& property_name, PropertyAttributes attributes, TransitionType);
Shape(Shape& previous_shape, Object* new_prototype);
- Shape* create_put_transition(const FlyString& name, PropertyAttributes attributes);
- Shape* create_configure_transition(const FlyString& name, PropertyAttributes attributes);
+ Shape* create_put_transition(const StringOrSymbol&, PropertyAttributes attributes);
+ Shape* create_configure_transition(const StringOrSymbol&, PropertyAttributes attributes);
Shape* create_prototype_transition(Object* new_prototype);
bool is_unique() const { return m_unique; }
@@ -78,12 +78,12 @@ public:
Object* prototype() { return m_prototype; }
const Object* prototype() const { return m_prototype; }
- Optional<PropertyMetadata> lookup(const FlyString&) const;
- const HashMap<FlyString, PropertyMetadata>& property_table() const;
+ Optional<PropertyMetadata> lookup(const StringOrSymbol&) const;
+ const HashMap<StringOrSymbol, PropertyMetadata>& property_table() const;
size_t property_count() const;
struct Property {
- FlyString key;
+ StringOrSymbol key;
PropertyMetadata value;
};
@@ -91,9 +91,9 @@ public:
void set_prototype_without_transition(Object* new_prototype) { m_prototype = new_prototype; }
- void remove_property_from_unique_shape(const FlyString&, size_t offset);
- void add_property_to_unique_shape(const FlyString&, PropertyAttributes attributes);
- void reconfigure_property_in_unique_shape(const FlyString& property_name, PropertyAttributes attributes);
+ void remove_property_from_unique_shape(const StringOrSymbol&, size_t offset);
+ void add_property_to_unique_shape(const StringOrSymbol&, PropertyAttributes attributes);
+ void reconfigure_property_in_unique_shape(const StringOrSymbol& property_name, PropertyAttributes attributes);
private:
virtual const char* class_name() const override { return "Shape"; }
@@ -103,11 +103,11 @@ private:
GlobalObject& m_global_object;
- mutable OwnPtr<HashMap<FlyString, PropertyMetadata>> m_property_table;
+ mutable OwnPtr<HashMap<StringOrSymbol, PropertyMetadata>> m_property_table;
HashMap<TransitionKey, Shape*> m_forward_transitions;
Shape* m_previous { nullptr };
- FlyString m_property_name;
+ StringOrSymbol m_property_name;
PropertyAttributes m_attributes { 0 };
bool m_unique { false };
Object* m_prototype { nullptr };
@@ -120,6 +120,6 @@ template<>
struct AK::Traits<JS::TransitionKey> : public GenericTraits<JS::TransitionKey> {
static unsigned hash(const JS::TransitionKey& key)
{
- return pair_int_hash(key.attributes.bits(), key.property_name.hash());
+ return pair_int_hash(key.attributes.bits(), Traits<JS::StringOrSymbol>::hash(key.property_name));
}
};