diff options
author | Andreas Kling <kling@serenityos.org> | 2020-03-09 22:14:51 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-03-09 22:19:06 +0100 |
commit | 386867da9f9d2da3ad39f3f3c550b81d9301809c (patch) | |
tree | 9e6e399f3833fe6a890f6930a143d9fcd788e146 /Libraries | |
parent | 05c80cac201a0046de7558137ccac5815bc38a27 (diff) | |
download | serenity-386867da9f9d2da3ad39f3f3c550b81d9301809c.zip |
LibJS: Add a convenience helper for visiting a JS::Value
We only really care to visit values if they refer to a Cell, but it's
nice to be able to say visit(some_value).
Diffstat (limited to 'Libraries')
-rw-r--r-- | Libraries/LibJS/Cell.cpp | 8 | ||||
-rw-r--r-- | Libraries/LibJS/Cell.h | 2 | ||||
-rw-r--r-- | Libraries/LibJS/Object.cpp | 6 |
3 files changed, 12 insertions, 4 deletions
diff --git a/Libraries/LibJS/Cell.cpp b/Libraries/LibJS/Cell.cpp index 3aedb7cb66..8e0744ea0b 100644 --- a/Libraries/LibJS/Cell.cpp +++ b/Libraries/LibJS/Cell.cpp @@ -26,9 +26,17 @@ #include <AK/LogStream.h> #include <LibJS/Cell.h> +#include <LibJS/Object.h> +#include <LibJS/Value.h> namespace JS { +void Cell::Visitor::visit(Value value) +{ + if (value.is_object()) + visit(value.as_object()); +} + const LogStream& operator<<(const LogStream& stream, const Cell* cell) { if (!cell) diff --git a/Libraries/LibJS/Cell.h b/Libraries/LibJS/Cell.h index d4e347a1af..274e41cb4f 100644 --- a/Libraries/LibJS/Cell.h +++ b/Libraries/LibJS/Cell.h @@ -27,6 +27,7 @@ #pragma once #include <AK/Forward.h> +#include <LibJS/Forward.h> namespace JS { @@ -45,6 +46,7 @@ public: class Visitor { public: virtual void visit(Cell*) = 0; + void visit(Value); }; virtual void visit_children(Visitor&) {} diff --git a/Libraries/LibJS/Object.cpp b/Libraries/LibJS/Object.cpp index 53f010681d..2d4f021a9f 100644 --- a/Libraries/LibJS/Object.cpp +++ b/Libraries/LibJS/Object.cpp @@ -51,10 +51,8 @@ void Object::put(String property_name, Value value) void Object::visit_children(Cell::Visitor& visitor) { Cell::visit_children(visitor); - for (auto& it : m_properties) { - if (it.value.is_object()) - visitor.visit(it.value.as_object()); - } + for (auto& it : m_properties) + visitor.visit(it.value); } } |