2020-03-08 19:23:58 +01:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
|
|
* list of conditions and the following disclaimer.
|
|
|
|
*
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer in the documentation
|
|
|
|
* and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
|
|
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
|
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2020-12-06 16:55:19 +00:00
|
|
|
#include <AK/Format.h>
|
2020-03-08 19:23:58 +01:00
|
|
|
#include <AK/Forward.h>
|
2020-04-02 14:55:29 +02:00
|
|
|
#include <AK/Noncopyable.h>
|
2020-12-06 16:55:19 +00:00
|
|
|
#include <AK/String.h>
|
2021-01-01 17:46:39 +01:00
|
|
|
#include <AK/TypeCasts.h>
|
2020-03-09 22:14:51 +01:00
|
|
|
#include <LibJS/Forward.h>
|
2020-03-08 19:23:58 +01:00
|
|
|
|
|
|
|
namespace JS {
|
|
|
|
|
|
|
|
class Cell {
|
2020-04-02 14:55:29 +02:00
|
|
|
AK_MAKE_NONCOPYABLE(Cell);
|
|
|
|
AK_MAKE_NONMOVABLE(Cell);
|
|
|
|
|
2020-03-08 19:23:58 +01:00
|
|
|
public:
|
2020-07-22 17:50:18 +02:00
|
|
|
virtual void initialize(GlobalObject&) { }
|
2020-06-20 15:40:48 +02:00
|
|
|
virtual ~Cell() { }
|
2020-03-08 19:23:58 +01:00
|
|
|
|
|
|
|
bool is_marked() const { return m_mark; }
|
|
|
|
void set_marked(bool b) { m_mark = b; }
|
|
|
|
|
|
|
|
bool is_live() const { return m_live; }
|
|
|
|
void set_live(bool b) { m_live = b; }
|
|
|
|
|
|
|
|
virtual const char* class_name() const = 0;
|
|
|
|
|
|
|
|
class Visitor {
|
|
|
|
public:
|
2020-04-16 16:07:50 +02:00
|
|
|
void visit(Cell*);
|
2020-03-09 22:14:51 +01:00
|
|
|
void visit(Value);
|
2020-04-16 16:07:50 +02:00
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual void visit_impl(Cell*) = 0;
|
2020-03-08 19:23:58 +01:00
|
|
|
};
|
|
|
|
|
2020-11-28 14:33:36 +01:00
|
|
|
virtual void visit_edges(Visitor&) { }
|
2020-03-08 19:23:58 +01:00
|
|
|
|
2020-03-16 00:19:41 +02:00
|
|
|
Heap& heap() const;
|
2020-09-21 15:30:14 +02:00
|
|
|
VM& vm() const;
|
2020-03-13 11:01:44 +01:00
|
|
|
|
2020-04-02 14:55:29 +02:00
|
|
|
protected:
|
2020-06-20 15:40:48 +02:00
|
|
|
Cell() { }
|
2020-04-02 14:55:29 +02:00
|
|
|
|
2020-03-08 19:23:58 +01:00
|
|
|
private:
|
|
|
|
bool m_mark { false };
|
|
|
|
bool m_live { true };
|
|
|
|
};
|
|
|
|
|
2020-12-06 16:55:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template<>
|
2021-01-09 01:00:22 +01:00
|
|
|
struct AK::Formatter<JS::Cell> : AK::Formatter<FormatString> {
|
2020-12-30 12:14:15 +01:00
|
|
|
void format(FormatBuilder& builder, const JS::Cell* cell)
|
2020-12-06 16:55:19 +00:00
|
|
|
{
|
|
|
|
if (!cell)
|
2021-01-09 01:00:22 +01:00
|
|
|
Formatter<FormatString>::format(builder, "Cell{nullptr}");
|
2020-12-06 16:55:19 +00:00
|
|
|
else
|
2021-01-09 01:00:22 +01:00
|
|
|
Formatter<FormatString>::format(builder, "{}({})", cell->class_name(), cell);
|
2020-12-06 16:55:19 +00:00
|
|
|
}
|
|
|
|
};
|