ladybird/Libraries/LibWeb/HTML/Scripting/ImportMapParseResult.h
Praise-Garfield 52ee05cb5d LibWeb: Visit ImportMapParseResult in HTMLScriptElement::visit_edges
The m_result Variant can hold a GC::Ref<ImportMapParseResult> when the
script element has type="importmap", but visit_edges only traced the
GC::Ref<Script> arm. This left the ImportMapParseResult unvisited,
allowing the GC to collect it while the element still held a reference.

ImportMapParseResult inherited from JS::Script::HostDefined, but no
JS::Script or JS::Module ever stored it as host_defined data, so
visit_host_defined_self was dead code. This removes the HostDefined
inheritance entirely and switches m_result visitation to Variant::visit
with a lambda that catches all GC::Ref arms.
2026-02-21 11:14:45 -05:00

48 lines
1.4 KiB
C++

/*
* Copyright (c) 2024, Jamie Mansfield <jmansfield@cadixdev.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <LibJS/Heap/Cell.h>
#include <LibURL/URL.h>
#include <LibWeb/Forward.h>
#include <LibWeb/HTML/Scripting/ImportMap.h>
#include <LibWeb/WebIDL/ExceptionOr.h>
namespace Web::HTML {
// https://html.spec.whatwg.org/multipage/webappapis.html#import-map-parse-result
class ImportMapParseResult : public JS::Cell {
GC_CELL(ImportMapParseResult, JS::Cell);
GC_DECLARE_ALLOCATOR(ImportMapParseResult);
public:
virtual ~ImportMapParseResult() override;
static GC::Ref<ImportMapParseResult> create(JS::Realm& realm, ByteString const& input, URL::URL base_url);
[[nodiscard]] Optional<ImportMap> const& import_map() const { return m_import_map; }
void set_import_map(ImportMap const& value) { m_import_map = value; }
[[nodiscard]] Optional<WebIDL::Exception> const& error_to_rethrow() const { return m_error_to_rethrow; }
void set_error_to_rethrow(WebIDL::Exception const& value) { m_error_to_rethrow = value; }
void register_import_map(Window& global);
protected:
ImportMapParseResult();
virtual void visit_edges(Visitor&) override;
private:
// https://html.spec.whatwg.org/multipage/webappapis.html#impr-import-map
Optional<ImportMap> m_import_map;
// https://html.spec.whatwg.org/multipage/webappapis.html#impr-error-to-rethrow
Optional<WebIDL::Exception> m_error_to_rethrow;
};
}