summaryrefslogtreecommitdiff
path: root/Userland/Libraries
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2022-08-28 22:11:20 +0200
committerAndreas Kling <kling@serenityos.org>2022-08-29 03:24:54 +0200
commit6e973ce69b2205779b9999e15c45d95a015f15b3 (patch)
tree3b5da1efe4c3a4f11e1577c58b2e280ff2afefc9 /Userland/Libraries
parent94f016b363c2ee969637217d73890d8dd5d7f3e5 (diff)
downloadserenity-6e973ce69b2205779b9999e15c45d95a015f15b3.zip
LibJS: Add JS_CELL macro and use it in all JS::Cell subclasses
This is similar to what we already had with JS_OBJECT (and also JS_ENVIRONMENT) but sits at the top of the Cell inheritance hierarchy.
Diffstat (limited to 'Userland/Libraries')
-rw-r--r--Userland/Libraries/LibJS/Heap/Cell.h8
-rw-r--r--Userland/Libraries/LibJS/Heap/HeapBlock.h4
-rw-r--r--Userland/Libraries/LibJS/Runtime/Accessor.h4
-rw-r--r--Userland/Libraries/LibJS/Runtime/Array.h1
-rw-r--r--Userland/Libraries/LibJS/Runtime/BigInt.h4
-rw-r--r--Userland/Libraries/LibJS/Runtime/Environment.h4
-rw-r--r--Userland/Libraries/LibJS/Runtime/Intrinsics.h3
-rw-r--r--Userland/Libraries/LibJS/Runtime/Object.h3
-rw-r--r--Userland/Libraries/LibJS/Runtime/PrimitiveString.h3
-rw-r--r--Userland/Libraries/LibJS/Runtime/PrivateEnvironment.h3
-rw-r--r--Userland/Libraries/LibJS/Runtime/PromiseReaction.h3
-rw-r--r--Userland/Libraries/LibJS/Runtime/PromiseResolvingElementFunctions.h7
-rw-r--r--Userland/Libraries/LibJS/Runtime/PromiseResolvingFunction.h4
-rw-r--r--Userland/Libraries/LibJS/Runtime/Realm.h3
-rw-r--r--Userland/Libraries/LibJS/Runtime/Shape.h3
-rw-r--r--Userland/Libraries/LibJS/Runtime/Symbol.h3
16 files changed, 37 insertions, 23 deletions
diff --git a/Userland/Libraries/LibJS/Heap/Cell.h b/Userland/Libraries/LibJS/Heap/Cell.h
index b467af79be..65170c018e 100644
--- a/Userland/Libraries/LibJS/Heap/Cell.h
+++ b/Userland/Libraries/LibJS/Heap/Cell.h
@@ -14,6 +14,14 @@
namespace JS {
+#define JS_CELL(class_, base_class) \
+public: \
+ using Base = base_class; \
+ virtual StringView class_name() const override \
+ { \
+ return #class_##sv; \
+ }
+
class Cell {
AK_MAKE_NONCOPYABLE(Cell);
AK_MAKE_NONMOVABLE(Cell);
diff --git a/Userland/Libraries/LibJS/Heap/HeapBlock.h b/Userland/Libraries/LibJS/Heap/HeapBlock.h
index 891cc89fed..8e200c5b22 100644
--- a/Userland/Libraries/LibJS/Heap/HeapBlock.h
+++ b/Userland/Libraries/LibJS/Heap/HeapBlock.h
@@ -97,9 +97,9 @@ private:
bool has_lazy_freelist() const { return m_next_lazy_freelist_index < cell_count(); }
struct FreelistEntry final : public Cell {
- FreelistEntry* next { nullptr };
+ JS_CELL(FreelistEntry, Cell);
- virtual StringView class_name() const override { return "FreelistEntry"sv; }
+ FreelistEntry* next { nullptr };
};
Cell* cell(size_t index)
diff --git a/Userland/Libraries/LibJS/Runtime/Accessor.h b/Userland/Libraries/LibJS/Runtime/Accessor.h
index b9efa43594..a665a64e10 100644
--- a/Userland/Libraries/LibJS/Runtime/Accessor.h
+++ b/Userland/Libraries/LibJS/Runtime/Accessor.h
@@ -14,6 +14,8 @@
namespace JS {
class Accessor final : public Cell {
+ JS_CELL(Accessor, Cell);
+
public:
static Accessor* create(VM& vm, FunctionObject* getter, FunctionObject* setter)
{
@@ -39,8 +41,6 @@ public:
}
private:
- StringView class_name() const override { return "Accessor"sv; };
-
FunctionObject* m_getter { nullptr };
FunctionObject* m_setter { nullptr };
};
diff --git a/Userland/Libraries/LibJS/Runtime/Array.h b/Userland/Libraries/LibJS/Runtime/Array.h
index 97550f534d..5ccb0e8d65 100644
--- a/Userland/Libraries/LibJS/Runtime/Array.h
+++ b/Userland/Libraries/LibJS/Runtime/Array.h
@@ -35,7 +35,6 @@ public:
return Array::create_from(realm, values);
}
- explicit Array(Object& prototype);
virtual ~Array() override = default;
virtual ThrowCompletionOr<Optional<PropertyDescriptor>> internal_get_own_property(PropertyKey const&) const override;
diff --git a/Userland/Libraries/LibJS/Runtime/BigInt.h b/Userland/Libraries/LibJS/Runtime/BigInt.h
index 41cf1f0b00..a9ea12d7d6 100644
--- a/Userland/Libraries/LibJS/Runtime/BigInt.h
+++ b/Userland/Libraries/LibJS/Runtime/BigInt.h
@@ -13,6 +13,8 @@
namespace JS {
class BigInt final : public Cell {
+ JS_CELL(BigInt, Cell);
+
public:
explicit BigInt(Crypto::SignedBigInteger);
virtual ~BigInt() override = default;
@@ -21,8 +23,6 @@ public:
const String to_string() const { return String::formatted("{}n", m_big_integer.to_base(10)); }
private:
- virtual StringView class_name() const override { return "BigInt"sv; }
-
Crypto::SignedBigInteger m_big_integer;
};
diff --git a/Userland/Libraries/LibJS/Runtime/Environment.h b/Userland/Libraries/LibJS/Runtime/Environment.h
index 6ff74a4a74..f25753aefa 100644
--- a/Userland/Libraries/LibJS/Runtime/Environment.h
+++ b/Userland/Libraries/LibJS/Runtime/Environment.h
@@ -23,6 +23,8 @@ public: \
virtual StringView class_name() const override { return #class_##sv; }
class Environment : public Cell {
+ JS_CELL(Environment, Cell);
+
public:
virtual bool has_this_binding() const { return false; }
virtual ThrowCompletionOr<Value> get_this_binding(VM&) const { return Value {}; }
@@ -48,8 +50,6 @@ public:
template<typename T>
bool fast_is() const = delete;
- virtual StringView class_name() const override { return "Environment"sv; }
-
// This flag is set on the entire variable environment chain when direct eval() is performed.
// It is used to disable non-local variable access caching.
bool is_permanently_screwed_by_eval() const { return m_permanently_screwed_by_eval; }
diff --git a/Userland/Libraries/LibJS/Runtime/Intrinsics.h b/Userland/Libraries/LibJS/Runtime/Intrinsics.h
index ee57442569..0d0cdb56f3 100644
--- a/Userland/Libraries/LibJS/Runtime/Intrinsics.h
+++ b/Userland/Libraries/LibJS/Runtime/Intrinsics.h
@@ -13,6 +13,8 @@
namespace JS {
class Intrinsics final : public Cell {
+ JS_CELL(Intrinsics, Cell);
+
public:
static Intrinsics* create(Realm&);
@@ -112,7 +114,6 @@ public:
#undef __JS_ENUMERATE
private:
- virtual StringView class_name() const override { return "Intrinsics"sv; }
virtual void visit_edges(Visitor&) override;
void initialize_intrinsics(Realm&);
diff --git a/Userland/Libraries/LibJS/Runtime/Object.h b/Userland/Libraries/LibJS/Runtime/Object.h
index 8dd728acfe..13f6bd9a70 100644
--- a/Userland/Libraries/LibJS/Runtime/Object.h
+++ b/Userland/Libraries/LibJS/Runtime/Object.h
@@ -46,6 +46,8 @@ struct PrivateElement {
};
class Object : public Cell {
+ JS_CELL(Object, Cell);
+
public:
static Object* create(Realm&, Object* prototype);
@@ -174,7 +176,6 @@ public:
bool has_parameter_map() const { return m_has_parameter_map; }
void set_has_parameter_map() { m_has_parameter_map = true; }
- virtual StringView class_name() const override { return "Object"sv; }
virtual void visit_edges(Cell::Visitor&) override;
Value get_direct(size_t index) const { return m_storage[index]; }
diff --git a/Userland/Libraries/LibJS/Runtime/PrimitiveString.h b/Userland/Libraries/LibJS/Runtime/PrimitiveString.h
index 38300c4b3a..755946479d 100644
--- a/Userland/Libraries/LibJS/Runtime/PrimitiveString.h
+++ b/Userland/Libraries/LibJS/Runtime/PrimitiveString.h
@@ -16,6 +16,8 @@
namespace JS {
class PrimitiveString final : public Cell {
+ JS_CELL(PrimitiveString, Cell);
+
public:
explicit PrimitiveString(PrimitiveString&, PrimitiveString&);
explicit PrimitiveString(String);
@@ -37,7 +39,6 @@ public:
Optional<Value> get(VM&, PropertyKey const&) const;
private:
- virtual StringView class_name() const override { return "PrimitiveString"sv; }
virtual void visit_edges(Cell::Visitor&) override;
void resolve_rope_if_needed() const;
diff --git a/Userland/Libraries/LibJS/Runtime/PrivateEnvironment.h b/Userland/Libraries/LibJS/Runtime/PrivateEnvironment.h
index 70ea1ab68d..5bdedd41e5 100644
--- a/Userland/Libraries/LibJS/Runtime/PrivateEnvironment.h
+++ b/Userland/Libraries/LibJS/Runtime/PrivateEnvironment.h
@@ -28,6 +28,8 @@ struct PrivateName {
};
class PrivateEnvironment : public Cell {
+ JS_CELL(PrivateEnvironment, Cell);
+
public:
explicit PrivateEnvironment(PrivateEnvironment* parent);
@@ -36,7 +38,6 @@ public:
void add_private_name(Badge<ClassExpression>, FlyString description);
private:
- virtual StringView class_name() const override { return "PrivateEnvironment"sv; }
virtual void visit_edges(Visitor&) override;
auto find_private_name(FlyString const& description) const
diff --git a/Userland/Libraries/LibJS/Runtime/PromiseReaction.h b/Userland/Libraries/LibJS/Runtime/PromiseReaction.h
index e1719b2a9b..2797766640 100644
--- a/Userland/Libraries/LibJS/Runtime/PromiseReaction.h
+++ b/Userland/Libraries/LibJS/Runtime/PromiseReaction.h
@@ -65,6 +65,8 @@ ThrowCompletionOr<PromiseCapability> new_promise_capability(VM& vm, Value constr
// 27.2.1.2 PromiseReaction Records, https://tc39.es/ecma262/#sec-promisereaction-records
class PromiseReaction final : public Cell {
+ JS_CELL(PromiseReaction, Cell);
+
public:
enum class Type {
Fulfill,
@@ -86,7 +88,6 @@ public:
Optional<JobCallback> const& handler() const { return m_handler; }
private:
- virtual StringView class_name() const override { return "PromiseReaction"sv; }
virtual void visit_edges(Visitor&) override;
Type m_type;
diff --git a/Userland/Libraries/LibJS/Runtime/PromiseResolvingElementFunctions.h b/Userland/Libraries/LibJS/Runtime/PromiseResolvingElementFunctions.h
index 8f7113347d..56c2154601 100644
--- a/Userland/Libraries/LibJS/Runtime/PromiseResolvingElementFunctions.h
+++ b/Userland/Libraries/LibJS/Runtime/PromiseResolvingElementFunctions.h
@@ -13,6 +13,8 @@
namespace JS {
struct RemainingElements final : public Cell {
+ JS_CELL(RemainingElements, Cell);
+
RemainingElements() = default;
explicit RemainingElements(u64 initial_value)
@@ -20,12 +22,12 @@ struct RemainingElements final : public Cell {
{
}
- virtual StringView class_name() const override { return "RemainingElements"sv; }
-
u64 value { 0 };
};
class PromiseValueList final : public Cell {
+ JS_CELL(PromiseValueList, Cell);
+
public:
PromiseValueList()
{
@@ -35,7 +37,6 @@ public:
Vector<Value> const& values() const { return m_values; }
private:
- virtual StringView class_name() const override { return "PromiseValueList"sv; }
virtual void visit_edges(Visitor&) override;
Vector<Value> m_values;
diff --git a/Userland/Libraries/LibJS/Runtime/PromiseResolvingFunction.h b/Userland/Libraries/LibJS/Runtime/PromiseResolvingFunction.h
index f89a30054f..759b9be6b8 100644
--- a/Userland/Libraries/LibJS/Runtime/PromiseResolvingFunction.h
+++ b/Userland/Libraries/LibJS/Runtime/PromiseResolvingFunction.h
@@ -12,9 +12,9 @@
namespace JS {
struct AlreadyResolved final : public Cell {
- bool value { false };
+ JS_CELL(AlreadyResolved, Cell);
- virtual StringView class_name() const override { return "AlreadyResolved"sv; }
+ bool value { false };
protected:
// Allocated cells must be >= sizeof(FreelistEntry), which is 24 bytes -
diff --git a/Userland/Libraries/LibJS/Runtime/Realm.h b/Userland/Libraries/LibJS/Runtime/Realm.h
index ff23af8b92..d1f4fecd73 100644
--- a/Userland/Libraries/LibJS/Runtime/Realm.h
+++ b/Userland/Libraries/LibJS/Runtime/Realm.h
@@ -20,6 +20,8 @@ namespace JS {
class Realm final
: public Cell
, public Weakable<Realm> {
+ JS_CELL(Realm, Cell);
+
public:
struct HostDefined {
virtual ~HostDefined() = default;
@@ -47,7 +49,6 @@ public:
void set_host_defined(OwnPtr<HostDefined> host_defined) { m_host_defined = move(host_defined); }
private:
- virtual StringView class_name() const override { return "Realm"sv; }
virtual void visit_edges(Visitor&) override;
Intrinsics* m_intrinsics { nullptr }; // [[Intrinsics]]
diff --git a/Userland/Libraries/LibJS/Runtime/Shape.h b/Userland/Libraries/LibJS/Runtime/Shape.h
index 01e9a81ff7..f879b37075 100644
--- a/Userland/Libraries/LibJS/Runtime/Shape.h
+++ b/Userland/Libraries/LibJS/Runtime/Shape.h
@@ -37,6 +37,8 @@ struct TransitionKey {
class Shape final
: public Cell
, public Weakable<Shape> {
+ JS_CELL(Shape, Cell);
+
public:
virtual ~Shape() override = default;
@@ -84,7 +86,6 @@ public:
void reconfigure_property_in_unique_shape(StringOrSymbol const& property_key, PropertyAttributes attributes);
private:
- virtual StringView class_name() const override { return "Shape"sv; }
virtual void visit_edges(Visitor&) override;
Shape* get_or_prune_cached_forward_transition(TransitionKey const&);
diff --git a/Userland/Libraries/LibJS/Runtime/Symbol.h b/Userland/Libraries/LibJS/Runtime/Symbol.h
index b4ae8dc148..4fd640370e 100644
--- a/Userland/Libraries/LibJS/Runtime/Symbol.h
+++ b/Userland/Libraries/LibJS/Runtime/Symbol.h
@@ -13,6 +13,7 @@
namespace JS {
class Symbol final : public Cell {
+ JS_CELL(Symbol, Cell);
AK_MAKE_NONCOPYABLE(Symbol);
AK_MAKE_NONMOVABLE(Symbol);
@@ -26,8 +27,6 @@ public:
String to_string() const { return String::formatted("Symbol({})", description()); }
private:
- virtual StringView class_name() const override { return "Symbol"sv; }
-
Optional<String> m_description;
bool m_is_global;
};