mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 15:07:45 +00:00
LibJS+LibWeb: Make CyclicModule & GraphLoadingState GC-allocated
This allows them to participate in the ownership graph and fixes a lifetime issue in module loading found by ASAN. Co-Authored-By: networkException <networkexception@serenityos.org>
This commit is contained in:
parent
aa7501a66a
commit
0817d8bda6
6 changed files with 60 additions and 24 deletions
|
@ -25,18 +25,33 @@ enum class ModuleStatus {
|
|||
class CyclicModule;
|
||||
|
||||
// https://tc39.es/ecma262/#graphloadingstate-record
|
||||
struct GraphLoadingState {
|
||||
struct HostDefined {
|
||||
virtual ~HostDefined() = default;
|
||||
struct GraphLoadingState : public Cell {
|
||||
JS_CELL(GraphLoadingState, Cell);
|
||||
|
||||
virtual void visit_edges(Cell::Visitor&) { }
|
||||
public:
|
||||
struct HostDefined : Cell {
|
||||
JS_CELL(HostDefined, Cell);
|
||||
|
||||
public:
|
||||
virtual ~HostDefined() = default;
|
||||
};
|
||||
|
||||
GCPtr<PromiseCapability> promise_capability; // [[PromiseCapability]]
|
||||
bool is_loading { false }; // [[IsLoading]]
|
||||
size_t pending_module_count { 0 }; // [[PendingModulesCount]]
|
||||
HashTable<CyclicModule*> visited; // [[Visited]]
|
||||
Optional<HostDefined> host_defined; // [[HostDefined]]
|
||||
GCPtr<HostDefined> host_defined; // [[HostDefined]]
|
||||
|
||||
private:
|
||||
GraphLoadingState(GCPtr<PromiseCapability> promise_capability, bool is_loading, size_t pending_module_count, HashTable<CyclicModule*> visited, GCPtr<HostDefined> host_defined)
|
||||
: promise_capability(move(promise_capability))
|
||||
, is_loading(is_loading)
|
||||
, pending_module_count(pending_module_count)
|
||||
, visited(move(visited))
|
||||
, host_defined(move(host_defined))
|
||||
{
|
||||
}
|
||||
virtual void visit_edges(Cell::Visitor&) override;
|
||||
};
|
||||
|
||||
// 16.2.1.5 Cyclic Module Records, https://tc39.es/ecma262/#cyclic-module-record
|
||||
|
@ -50,7 +65,7 @@ public:
|
|||
virtual ThrowCompletionOr<void> link(VM& vm) override final;
|
||||
virtual ThrowCompletionOr<Promise*> evaluate(VM& vm) override final;
|
||||
|
||||
virtual PromiseCapability& load_requested_modules(Realm&, Optional<GraphLoadingState::HostDefined>);
|
||||
virtual PromiseCapability& load_requested_modules(Realm&, GCPtr<GraphLoadingState::HostDefined>);
|
||||
virtual void inner_module_loading(GraphLoadingState& state);
|
||||
|
||||
Vector<ModuleRequest> const& requested_modules() const { return m_requested_modules; }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue