mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-05-11 09:27:00 +02:00
When the HTML parser blocks on a synchronous external script, run a separate tokenizer over the unparsed input and issue speculative fetches for the resources it finds (script src, link rel=stylesheet|preload, img src), with <base href> tracking and template/foreign-content skipping. Also fills in the previously-stubbed "consume a preloaded resource" algorithm and the document's "map of preloaded resources", so that <link rel="preload"> followed by a matching consumer deduplicates to a single fetch.
39 lines
1.2 KiB
C++
39 lines
1.2 KiB
C++
/*
|
|
* Copyright (c) 2026, Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#include <LibWeb/HTML/Parser/SpeculativeMockElement.h>
|
|
|
|
namespace Web::HTML {
|
|
|
|
Optional<String> SpeculativeMockElement::attribute(FlyString const& name) const
|
|
{
|
|
for (auto const& attribute : attribute_list) {
|
|
if (attribute.local_name == name)
|
|
return attribute.value;
|
|
}
|
|
return {};
|
|
}
|
|
|
|
// https://html.spec.whatwg.org/multipage/parsing.html#create-a-speculative-mock-element
|
|
SpeculativeMockElement create_a_speculative_mock_element(FlyString tag_name, Vector<HTMLToken::Attribute> attributes)
|
|
{
|
|
// 1. Let element be a new speculative mock element.
|
|
// 2. FIXME: Set element's namespace to namespace.
|
|
// 3. Set element's local name to tagName.
|
|
// 4. Set element's attribute list to attributes.
|
|
// 5. FIXME: Set element's children to a new empty list.
|
|
// 6. Optionally, perform a speculative fetch for element.
|
|
// The speculative fetch is performed by the caller (see SpeculativeHTMLParser::process_start_tag).
|
|
|
|
// 7. Return element.
|
|
return SpeculativeMockElement {
|
|
.local_name = move(tag_name),
|
|
.attribute_list = move(attributes),
|
|
};
|
|
}
|
|
|
|
}
|