LibWeb: Indicate documents are for fragment parsing during construction

This will allow testing if they are for fragment parsing during methods
invoked from Document::initialize.
This commit is contained in:
Timothy Flynn 2024-07-31 12:02:38 -04:00 committed by Andreas Kling
commit c838ca78c8
Notes: github-actions[bot] 2024-08-01 09:36:56 +00:00
3 changed files with 18 additions and 9 deletions

View file

@ -354,11 +354,17 @@ JS::NonnullGCPtr<Document> Document::create(JS::Realm& realm, URL::URL const& ur
return realm.heap().allocate<Document>(realm, realm, url);
}
Document::Document(JS::Realm& realm, const URL::URL& url)
JS::NonnullGCPtr<Document> Document::create_for_fragment_parsing(JS::Realm& realm)
{
return realm.heap().allocate<Document>(realm, realm, "about:blank"sv, TemporaryDocumentForFragmentParsing::Yes);
}
Document::Document(JS::Realm& realm, const URL::URL& url, TemporaryDocumentForFragmentParsing temporary_document_for_fragment_parsing)
: ParentNode(realm, *this, NodeType::DOCUMENT_NODE)
, m_page(Bindings::host_defined_page(realm))
, m_style_computer(make<CSS::StyleComputer>(*this))
, m_url(url)
, m_temporary_document_for_fragment_parsing(temporary_document_for_fragment_parsing)
{
m_legacy_platform_object_flags = PlatformObject::LegacyPlatformObjectFlags {
.supports_named_properties = true,
@ -5253,7 +5259,7 @@ JS::NonnullGCPtr<Document> Document::parse_html_unsafe(JS::VM& vm, StringView ht
// FIXME: 1. Let compliantHTML to the result of invoking the Get Trusted Type compliant string algorithm with TrustedHTML, this's relevant global object, html, "Document parseHTMLUnsafe", and "script".
// 2. Let document be a new Document, whose content type is "text/html".
JS::NonnullGCPtr<DOM::Document> document = Document::create(realm);
auto document = Document::create_for_fragment_parsing(realm);
document->set_content_type("text/html"_string);
// 3. Set document's allow declarative shadow roots to true.