mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-05-02 17:28:48 +00:00
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).
This commit is contained in:
parent
05c80cac20
commit
386867da9f
Notes:
sideshowbarker
2024-07-19 08:47:44 +09:00
Author: https://github.com/awesomekling
Commit: 386867da9f
3 changed files with 12 additions and 4 deletions
|
@ -26,9 +26,17 @@
|
||||||
|
|
||||||
#include <AK/LogStream.h>
|
#include <AK/LogStream.h>
|
||||||
#include <LibJS/Cell.h>
|
#include <LibJS/Cell.h>
|
||||||
|
#include <LibJS/Object.h>
|
||||||
|
#include <LibJS/Value.h>
|
||||||
|
|
||||||
namespace JS {
|
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)
|
const LogStream& operator<<(const LogStream& stream, const Cell* cell)
|
||||||
{
|
{
|
||||||
if (!cell)
|
if (!cell)
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <AK/Forward.h>
|
#include <AK/Forward.h>
|
||||||
|
#include <LibJS/Forward.h>
|
||||||
|
|
||||||
namespace JS {
|
namespace JS {
|
||||||
|
|
||||||
|
@ -45,6 +46,7 @@ public:
|
||||||
class Visitor {
|
class Visitor {
|
||||||
public:
|
public:
|
||||||
virtual void visit(Cell*) = 0;
|
virtual void visit(Cell*) = 0;
|
||||||
|
void visit(Value);
|
||||||
};
|
};
|
||||||
|
|
||||||
virtual void visit_children(Visitor&) {}
|
virtual void visit_children(Visitor&) {}
|
||||||
|
|
|
@ -51,10 +51,8 @@ void Object::put(String property_name, Value value)
|
||||||
void Object::visit_children(Cell::Visitor& visitor)
|
void Object::visit_children(Cell::Visitor& visitor)
|
||||||
{
|
{
|
||||||
Cell::visit_children(visitor);
|
Cell::visit_children(visitor);
|
||||||
for (auto& it : m_properties) {
|
for (auto& it : m_properties)
|
||||||
if (it.value.is_object())
|
visitor.visit(it.value);
|
||||||
visitor.visit(it.value.as_object());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue