LibJS: Make CachedSourceRange GC-allocated
This gets rid of a RefPtr in ExecutionContext, bringing us one step closer to destructor-less ExecutionContext.
This commit is contained in:
parent
583164e412
commit
9ded35f98f
5 changed files with 16 additions and 8 deletions
|
|
@ -164,7 +164,7 @@ struct AsyncGeneratorRequest;
|
|||
class BigInt;
|
||||
class BoundFunction;
|
||||
class BuiltinIterator;
|
||||
struct CachedSourceRange;
|
||||
class CachedSourceRange;
|
||||
class Cell;
|
||||
class ClassExpression;
|
||||
struct ClassFieldDefinition;
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ struct JS_API TracebackFrame {
|
|||
Utf16String function_name;
|
||||
[[nodiscard]] SourceRange const& source_range() const;
|
||||
|
||||
RefPtr<CachedSourceRange> cached_source_range;
|
||||
GC::Root<CachedSourceRange> cached_source_range;
|
||||
};
|
||||
|
||||
enum CompactTraceback {
|
||||
|
|
|
|||
|
|
@ -14,6 +14,8 @@
|
|||
|
||||
namespace JS {
|
||||
|
||||
GC_DEFINE_ALLOCATOR(CachedSourceRange);
|
||||
|
||||
class ExecutionContextAllocator {
|
||||
public:
|
||||
NonnullOwnPtr<ExecutionContext> allocate(u32 registers_and_constants_and_locals_count, u32 arguments_count)
|
||||
|
|
@ -143,6 +145,7 @@ void ExecutionContext::visit_edges(Cell::Visitor& visitor)
|
|||
visitor.visit(lexical_environment);
|
||||
visitor.visit(private_environment);
|
||||
visitor.visit(context_owner);
|
||||
visitor.visit(cached_source_range);
|
||||
if (this_value.has_value())
|
||||
visitor.visit(*this_value);
|
||||
visitor.visit(executable);
|
||||
|
|
|
|||
|
|
@ -21,12 +21,17 @@ namespace JS {
|
|||
|
||||
using ScriptOrModule = Variant<Empty, GC::Ref<Script>, GC::Ref<Module>>;
|
||||
|
||||
struct CachedSourceRange : public RefCounted<CachedSourceRange> {
|
||||
class CachedSourceRange final : public GC::Cell {
|
||||
GC_CELL(CachedSourceRange, GC::Cell);
|
||||
GC_DECLARE_ALLOCATOR(CachedSourceRange);
|
||||
|
||||
public:
|
||||
CachedSourceRange(size_t program_counter, Variant<UnrealizedSourceRange, SourceRange> source_range)
|
||||
: program_counter(program_counter)
|
||||
, source_range(move(source_range))
|
||||
{
|
||||
}
|
||||
|
||||
size_t program_counter { 0 };
|
||||
Variant<UnrealizedSourceRange, SourceRange> source_range;
|
||||
};
|
||||
|
|
@ -70,7 +75,7 @@ public:
|
|||
// FIXME: Move this out of LibJS (e.g. by using the CustomData concept), as it's used exclusively by LibWeb.
|
||||
u32 skip_when_determining_incumbent_counter { 0 };
|
||||
|
||||
mutable RefPtr<CachedSourceRange> cached_source_range;
|
||||
mutable GC::Ptr<CachedSourceRange> cached_source_range;
|
||||
|
||||
Optional<Value> this_value;
|
||||
|
||||
|
|
@ -145,7 +150,7 @@ private:
|
|||
|
||||
struct StackTraceElement {
|
||||
ExecutionContext* execution_context;
|
||||
RefPtr<CachedSourceRange> source_range;
|
||||
GC::Root<CachedSourceRange> source_range;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -753,7 +753,7 @@ void VM::load_imported_module(ImportedModuleReferrer referrer, ModuleRequest con
|
|||
finish_loading_imported_module(referrer, module_request, payload, module);
|
||||
}
|
||||
|
||||
static RefPtr<CachedSourceRange> get_source_range(ExecutionContext const* context)
|
||||
static GC::Ptr<CachedSourceRange> get_source_range(ExecutionContext const* context)
|
||||
{
|
||||
// native function
|
||||
if (!context->executable)
|
||||
|
|
@ -762,9 +762,9 @@ static RefPtr<CachedSourceRange> get_source_range(ExecutionContext const* contex
|
|||
if (!context->cached_source_range
|
||||
|| context->cached_source_range->program_counter != context->program_counter) {
|
||||
auto unrealized_source_range = context->executable->source_range_at(context->program_counter);
|
||||
context->cached_source_range = adopt_ref(*new CachedSourceRange(
|
||||
context->cached_source_range = context->executable->heap().allocate<CachedSourceRange>(
|
||||
context->program_counter,
|
||||
move(unrealized_source_range)));
|
||||
move(unrealized_source_range));
|
||||
}
|
||||
return context->cached_source_range;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue