mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-01 05:39:11 +00:00
LibJS: Don't directly teach the heap about the javascript VM or Realm
Instead, smuggle it in as a `void*` private data and let Javascript aware code cast out that pointer to a VM&. In order to make this split, rename JS::Cell to JS::CellImpl. Once we have a LibGC, this will become GC::Cell. CellImpl then has no specific knowledge of the VM& and Realm&. That knowledge is instead put into JS::Cell, which inherits from CellImpl. JS::Cell is responsible for JavaScript's realm initialization, as well as converting of the void* private data to what it knows should be the VM&.
This commit is contained in:
parent
ae6d105f41
commit
c2988a7dd5
Notes:
github-actions[bot]
2024-11-14 14:39:37 +00:00
Author: https://github.com/shannonbooth
Commit: c2988a7dd5
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2334
27 changed files with 346 additions and 296 deletions
|
@ -62,7 +62,7 @@ static constexpr auto make_single_ascii_character_strings(IndexSequence<code_poi
|
|||
static constexpr auto single_ascii_character_strings = make_single_ascii_character_strings(MakeIndexSequence<128>());
|
||||
|
||||
VM::VM(OwnPtr<CustomData> custom_data, ErrorMessages error_messages)
|
||||
: m_heap(*this, [this](HashMap<Cell*, JS::HeapRoot>& roots) {
|
||||
: m_heap(this, [this](HashMap<CellImpl*, JS::HeapRoot>& roots) {
|
||||
gather_roots(roots);
|
||||
})
|
||||
, m_error_messages(move(error_messages))
|
||||
|
@ -204,7 +204,7 @@ Bytecode::Interpreter& VM::bytecode_interpreter()
|
|||
}
|
||||
|
||||
struct ExecutionContextRootsCollector : public Cell::Visitor {
|
||||
virtual void visit_impl(Cell& cell) override
|
||||
virtual void visit_impl(CellImpl& cell) override
|
||||
{
|
||||
roots.set(&cell);
|
||||
}
|
||||
|
@ -214,10 +214,10 @@ struct ExecutionContextRootsCollector : public Cell::Visitor {
|
|||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
||||
HashTable<GCPtr<Cell>> roots;
|
||||
HashTable<GCPtr<CellImpl>> roots;
|
||||
};
|
||||
|
||||
void VM::gather_roots(HashMap<Cell*, HeapRoot>& roots)
|
||||
void VM::gather_roots(HashMap<CellImpl*, HeapRoot>& roots)
|
||||
{
|
||||
roots.set(m_empty_string, HeapRoot { .type = HeapRoot::Type::VM });
|
||||
for (auto string : m_single_ascii_character_strings)
|
||||
|
|
|
@ -60,7 +60,7 @@ public:
|
|||
|
||||
void dump_backtrace() const;
|
||||
|
||||
void gather_roots(HashMap<Cell*, HeapRoot>&);
|
||||
void gather_roots(HashMap<CellImpl*, HeapRoot>&);
|
||||
|
||||
#define __JS_ENUMERATE(SymbolName, snake_name) \
|
||||
NonnullGCPtr<Symbol> well_known_symbol_##snake_name() const \
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#include <AK/String.h>
|
||||
#include <AK/Types.h>
|
||||
#include <LibJS/Forward.h>
|
||||
#include <LibJS/Heap/Cell.h>
|
||||
#include <LibJS/Heap/GCPtr.h>
|
||||
#include <LibJS/Heap/Handle.h>
|
||||
#include <LibJS/Heap/NanBoxedValue.h>
|
||||
|
@ -256,6 +257,18 @@ public:
|
|||
{
|
||||
}
|
||||
|
||||
Cell& as_cell()
|
||||
{
|
||||
VERIFY(is_cell());
|
||||
return *extract_pointer<Cell>();
|
||||
}
|
||||
|
||||
Cell& as_cell() const
|
||||
{
|
||||
VERIFY(is_cell());
|
||||
return *extract_pointer<Cell>();
|
||||
}
|
||||
|
||||
double as_double() const
|
||||
{
|
||||
VERIFY(is_number());
|
||||
|
@ -661,14 +674,14 @@ private:
|
|||
{
|
||||
}
|
||||
|
||||
explicit Handle(Value value, Cell* cell, SourceLocation location)
|
||||
explicit Handle(Value value, CellImpl* cell, SourceLocation location)
|
||||
: m_value(value)
|
||||
, m_handle(Handle<Cell>::create(cell, location))
|
||||
, m_handle(Handle<CellImpl>::create(cell, location))
|
||||
{
|
||||
}
|
||||
|
||||
Optional<Value> m_value;
|
||||
Handle<Cell> m_handle;
|
||||
Handle<CellImpl> m_handle;
|
||||
};
|
||||
|
||||
inline Handle<Value> make_handle(Value value, SourceLocation location = SourceLocation::current())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue