mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 19:58:11 +00:00
LibWeb: Pass DOM namespace strings as FlyString in more places
This commit is contained in:
parent
b341aeb5c1
commit
6b20a109c6
7 changed files with 32 additions and 33 deletions
|
@ -2432,10 +2432,10 @@ void Document::set_window(HTML::Window& window)
|
|||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/custom-elements.html#look-up-a-custom-element-definition
|
||||
JS::GCPtr<HTML::CustomElementDefinition> Document::lookup_custom_element_definition(DeprecatedFlyString const& namespace_, DeprecatedFlyString const& local_name, Optional<String> const& is) const
|
||||
JS::GCPtr<HTML::CustomElementDefinition> Document::lookup_custom_element_definition(Optional<FlyString> const& namespace_, FlyString const& local_name, Optional<String> const& is) const
|
||||
{
|
||||
// 1. If namespace is not the HTML namespace, return null.
|
||||
if (namespace_ != Namespace::HTML)
|
||||
if (namespace_ != MUST(FlyString::from_deprecated_fly_string(Namespace::HTML)))
|
||||
return nullptr;
|
||||
|
||||
// 2. If document's browsing context is null, return null.
|
||||
|
@ -2446,8 +2446,8 @@ JS::GCPtr<HTML::CustomElementDefinition> Document::lookup_custom_element_definit
|
|||
auto registry = verify_cast<HTML::Window>(relevant_global_object(*this)).custom_elements();
|
||||
|
||||
// 4. If there is custom element definition in registry with name and local name both equal to localName, return that custom element definition.
|
||||
auto converted_local_name = String::from_deprecated_string(local_name).release_value_but_fixme_should_propagate_errors();
|
||||
auto maybe_definition = registry->get_definition_with_name_and_local_name(converted_local_name, converted_local_name);
|
||||
auto converted_local_name = local_name;
|
||||
auto maybe_definition = registry->get_definition_with_name_and_local_name(converted_local_name.to_string(), converted_local_name.to_string());
|
||||
if (maybe_definition)
|
||||
return maybe_definition;
|
||||
|
||||
|
@ -2458,7 +2458,7 @@ JS::GCPtr<HTML::CustomElementDefinition> Document::lookup_custom_element_definit
|
|||
if (!is.has_value())
|
||||
return nullptr;
|
||||
|
||||
return registry->get_definition_with_name_and_local_name(is.value(), converted_local_name);
|
||||
return registry->get_definition_with_name_and_local_name(is.value(), converted_local_name.to_string());
|
||||
}
|
||||
|
||||
CSS::StyleSheetList& Document::style_sheets()
|
||||
|
|
|
@ -435,7 +435,7 @@ public:
|
|||
bool has_active_favicon() const { return m_active_favicon; }
|
||||
void check_favicon_after_loading_link_resource();
|
||||
|
||||
JS::GCPtr<HTML::CustomElementDefinition> lookup_custom_element_definition(DeprecatedFlyString const& namespace_, DeprecatedFlyString const& local_name, Optional<String> const& is) const;
|
||||
JS::GCPtr<HTML::CustomElementDefinition> lookup_custom_element_definition(Optional<FlyString> const& namespace_, FlyString const& local_name, Optional<String> const& is) const;
|
||||
|
||||
void increment_throw_on_dynamic_markup_insertion_counter(Badge<HTML::HTMLParser>);
|
||||
void decrement_throw_on_dynamic_markup_insertion_counter(Badge<HTML::HTMLParser>);
|
||||
|
|
|
@ -647,7 +647,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<ShadowRoot>> Element::attach_shadow(ShadowR
|
|||
// 3. If this’s local name is a valid custom element name, or this’s is value is not null, then:
|
||||
if (HTML::is_valid_custom_element_name(local_name()) || m_is_value.has_value()) {
|
||||
// 1. Let definition be the result of looking up a custom element definition given this’s node document, its namespace, its local name, and its is value.
|
||||
auto definition = document().lookup_custom_element_definition(namespace_(), local_name().to_deprecated_fly_string(), m_is_value);
|
||||
auto definition = document().lookup_custom_element_definition(namespace_uri(), local_name(), m_is_value);
|
||||
|
||||
// 2. If definition is not null and definition’s disable shadow is true, then throw a "NotSupportedError" DOMException.
|
||||
if (definition && definition->disable_shadow())
|
||||
|
@ -1844,7 +1844,7 @@ JS::ThrowCompletionOr<void> Element::upgrade_element(JS::NonnullGCPtr<HTML::Cust
|
|||
void Element::try_to_upgrade()
|
||||
{
|
||||
// 1. Let definition be the result of looking up a custom element definition given element's node document, element's namespace, element's local name, and element's is value.
|
||||
auto definition = document().lookup_custom_element_definition(namespace_(), local_name().to_deprecated_fly_string(), m_is_value);
|
||||
auto definition = document().lookup_custom_element_definition(namespace_uri(), local_name(), m_is_value);
|
||||
|
||||
// 2. If definition is not null, then enqueue a custom element upgrade reaction given element and definition.
|
||||
if (definition)
|
||||
|
|
|
@ -504,8 +504,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<Element>> create_element(Document& document
|
|||
// NOTE: We collapse this into just returning an element where necessary.
|
||||
|
||||
// 4. Let definition be the result of looking up a custom element definition given document, namespace, localName, and is.
|
||||
DeprecatedFlyString deprecated_namespace = namespace_.has_value() ? namespace_.value().to_deprecated_fly_string() : DeprecatedFlyString {};
|
||||
auto definition = document.lookup_custom_element_definition(deprecated_namespace, local_name.to_deprecated_fly_string(), is_value);
|
||||
auto definition = document.lookup_custom_element_definition(namespace_, local_name, is_value);
|
||||
|
||||
// 5. If definition is non-null, and definition’s name is not equal to its local name (i.e., definition represents a customized built-in element), then:
|
||||
if (definition && definition->name() != definition->local_name()) {
|
||||
|
|
|
@ -539,7 +539,7 @@ void HTMLParser::handle_before_html(HTMLToken& token)
|
|||
// -> A start tag whose tag name is "html"
|
||||
if (token.is_start_tag() && token.tag_name() == HTML::TagNames::html) {
|
||||
// Create an element for the token in the HTML namespace, with the Document as the intended parent. Append it to the Document object. Put this element in the stack of open elements.
|
||||
auto element = create_element_for(token, Namespace::HTML, document());
|
||||
auto element = create_element_for(token, MUST(FlyString::from_deprecated_fly_string(Namespace::HTML)), document());
|
||||
MUST(document().append_child(*element));
|
||||
m_stack_of_open_elements.push(move(element));
|
||||
|
||||
|
@ -644,7 +644,7 @@ HTMLParser::AdjustedInsertionLocation HTMLParser::find_appropriate_place_for_ins
|
|||
return adjusted_insertion_location;
|
||||
}
|
||||
|
||||
JS::NonnullGCPtr<DOM::Element> HTMLParser::create_element_for(HTMLToken const& token, DeprecatedFlyString const& namespace_, DOM::Node& intended_parent)
|
||||
JS::NonnullGCPtr<DOM::Element> HTMLParser::create_element_for(HTMLToken const& token, Optional<FlyString> const& namespace_, DOM::Node& intended_parent)
|
||||
{
|
||||
// FIXME: 1. If the active speculative HTML parser is not null, then return the result of creating a speculative mock element given given namespace, the tag name of the given token, and the attributes of the given token.
|
||||
// FIXME: 2. Otherwise, optionally create a speculative mock element given given namespace, the tag name of the given token, and the attributes of the given token.
|
||||
|
@ -662,7 +662,7 @@ JS::NonnullGCPtr<DOM::Element> HTMLParser::create_element_for(HTMLToken const& t
|
|||
is_value = String::from_utf8(is_value_deprecated_string).release_value_but_fixme_should_propagate_errors();
|
||||
|
||||
// 6. Let definition be the result of looking up a custom element definition given document, given namespace, local name, and is.
|
||||
auto definition = document->lookup_custom_element_definition(namespace_, local_name.to_deprecated_fly_string(), is_value);
|
||||
auto definition = document->lookup_custom_element_definition(namespace_, local_name, is_value);
|
||||
|
||||
// 7. If definition is non-null and the parser was not created as part of the HTML fragment parsing algorithm, then let will execute script be true. Otherwise, let it be false.
|
||||
bool will_execute_script = definition && !m_parsing_fragment;
|
||||
|
@ -684,7 +684,7 @@ JS::NonnullGCPtr<DOM::Element> HTMLParser::create_element_for(HTMLToken const& t
|
|||
|
||||
// 9. Let element be the result of creating an element given document, localName, given namespace, null, and is.
|
||||
// If will execute script is true, set the synchronous custom elements flag; otherwise, leave it unset.
|
||||
auto element = create_element(*document, local_name, MUST(FlyString::from_deprecated_fly_string(namespace_)), {}, is_value, will_execute_script).release_value_but_fixme_should_propagate_errors();
|
||||
auto element = create_element(*document, local_name, namespace_, {}, is_value, will_execute_script).release_value_but_fixme_should_propagate_errors();
|
||||
|
||||
// 10. Append each attribute in the given token to element.
|
||||
// FIXME: This isn't the exact `append` the spec is talking about.
|
||||
|
@ -736,7 +736,7 @@ JS::NonnullGCPtr<DOM::Element> HTMLParser::create_element_for(HTMLToken const& t
|
|||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/parsing.html#insert-a-foreign-element
|
||||
JS::NonnullGCPtr<DOM::Element> HTMLParser::insert_foreign_element(HTMLToken const& token, DeprecatedFlyString const& namespace_)
|
||||
JS::NonnullGCPtr<DOM::Element> HTMLParser::insert_foreign_element(HTMLToken const& token, Optional<FlyString> const& namespace_)
|
||||
{
|
||||
auto adjusted_insertion_location = find_appropriate_place_for_inserting_node();
|
||||
|
||||
|
@ -772,7 +772,7 @@ JS::NonnullGCPtr<DOM::Element> HTMLParser::insert_foreign_element(HTMLToken cons
|
|||
|
||||
JS::NonnullGCPtr<DOM::Element> HTMLParser::insert_html_element(HTMLToken const& token)
|
||||
{
|
||||
return insert_foreign_element(token, Namespace::HTML);
|
||||
return insert_foreign_element(token, MUST(FlyString::from_deprecated_fly_string(Namespace::HTML)));
|
||||
}
|
||||
|
||||
void HTMLParser::handle_before_head(HTMLToken& token)
|
||||
|
@ -882,7 +882,7 @@ void HTMLParser::handle_in_head(HTMLToken& token)
|
|||
|
||||
if (token.is_start_tag() && token.tag_name() == HTML::TagNames::script) {
|
||||
auto adjusted_insertion_location = find_appropriate_place_for_inserting_node();
|
||||
auto element = create_element_for(token, Namespace::HTML, *adjusted_insertion_location.parent);
|
||||
auto element = create_element_for(token, MUST(FlyString::from_deprecated_fly_string(Namespace::HTML)), *adjusted_insertion_location.parent);
|
||||
auto& script_element = verify_cast<HTMLScriptElement>(*element);
|
||||
script_element.set_parser_document(Badge<HTMLParser> {}, document());
|
||||
script_element.set_force_async(Badge<HTMLParser> {}, false);
|
||||
|
@ -1383,7 +1383,7 @@ HTMLParser::AdoptionAgencyAlgorithmOutcome HTMLParser::run_the_adoption_agency_a
|
|||
// 6. Create an element for the token for which the element node was created,
|
||||
// in the HTML namespace, with common ancestor as the intended parent;
|
||||
// FIXME: hold onto the real token
|
||||
auto element = create_element_for(HTMLToken::make_start_tag(node->local_name()), Namespace::HTML, *common_ancestor);
|
||||
auto element = create_element_for(HTMLToken::make_start_tag(node->local_name()), MUST(FlyString::from_deprecated_fly_string(Namespace::HTML)), *common_ancestor);
|
||||
// replace the entry for node in the list of active formatting elements with an entry for the new element,
|
||||
m_list_of_active_formatting_elements.replace(*node, *element);
|
||||
// replace the entry for node in the stack of open elements with an entry for the new element,
|
||||
|
@ -1412,7 +1412,7 @@ HTMLParser::AdoptionAgencyAlgorithmOutcome HTMLParser::run_the_adoption_agency_a
|
|||
// 15. Create an element for the token for which formatting element was created,
|
||||
// in the HTML namespace, with furthest block as the intended parent.
|
||||
// FIXME: hold onto the real token
|
||||
auto element = create_element_for(HTMLToken::make_start_tag(formatting_element->local_name()), Namespace::HTML, *furthest_block);
|
||||
auto element = create_element_for(HTMLToken::make_start_tag(formatting_element->local_name()), MUST(FlyString::from_deprecated_fly_string(Namespace::HTML)), *furthest_block);
|
||||
|
||||
// 16. Take all of the child nodes of furthest block and append them to the element created in the last step.
|
||||
for (auto& child : furthest_block->children_as_vector())
|
||||
|
@ -1437,9 +1437,9 @@ HTMLParser::AdoptionAgencyAlgorithmOutcome HTMLParser::run_the_adoption_agency_a
|
|||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/parsing.html#special
|
||||
bool HTMLParser::is_special_tag(FlyString const& tag_name, DeprecatedFlyString const& namespace_)
|
||||
bool HTMLParser::is_special_tag(FlyString const& tag_name, Optional<FlyString> const& namespace_)
|
||||
{
|
||||
if (namespace_ == Namespace::HTML) {
|
||||
if (namespace_ == MUST(FlyString::from_deprecated_fly_string(Namespace::HTML))) {
|
||||
return tag_name.is_one_of(
|
||||
HTML::TagNames::address,
|
||||
HTML::TagNames::applet,
|
||||
|
@ -1523,12 +1523,12 @@ bool HTMLParser::is_special_tag(FlyString const& tag_name, DeprecatedFlyString c
|
|||
HTML::TagNames::ul,
|
||||
HTML::TagNames::wbr,
|
||||
HTML::TagNames::xmp);
|
||||
} else if (namespace_ == Namespace::SVG) {
|
||||
} else if (namespace_ == MUST(FlyString::from_deprecated_fly_string(Namespace::SVG))) {
|
||||
return tag_name.is_one_of(
|
||||
SVG::TagNames::desc,
|
||||
SVG::TagNames::foreignObject,
|
||||
SVG::TagNames::title);
|
||||
} else if (namespace_ == Namespace::MathML) {
|
||||
} else if (namespace_ == MUST(FlyString::from_deprecated_fly_string(Namespace::MathML))) {
|
||||
return tag_name.is_one_of(
|
||||
MathML::TagNames::mi,
|
||||
MathML::TagNames::mo,
|
||||
|
@ -1740,7 +1740,7 @@ void HTMLParser::handle_in_body(HTMLToken& token)
|
|||
break;
|
||||
}
|
||||
|
||||
if (is_special_tag(node->local_name(), node->namespace_()) && !node->local_name().is_one_of(HTML::TagNames::address, HTML::TagNames::div, HTML::TagNames::p))
|
||||
if (is_special_tag(node->local_name(), node->namespace_uri()) && !node->local_name().is_one_of(HTML::TagNames::address, HTML::TagNames::div, HTML::TagNames::p))
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -1771,7 +1771,7 @@ void HTMLParser::handle_in_body(HTMLToken& token)
|
|||
m_stack_of_open_elements.pop_until_an_element_with_tag_name_has_been_popped(HTML::TagNames::dt);
|
||||
break;
|
||||
}
|
||||
if (is_special_tag(node->local_name(), node->namespace_()) && !node->local_name().is_one_of(HTML::TagNames::address, HTML::TagNames::div, HTML::TagNames::p))
|
||||
if (is_special_tag(node->local_name(), node->namespace_uri()) && !node->local_name().is_one_of(HTML::TagNames::address, HTML::TagNames::div, HTML::TagNames::p))
|
||||
break;
|
||||
}
|
||||
if (m_stack_of_open_elements.has_in_button_scope(HTML::TagNames::p))
|
||||
|
@ -2127,7 +2127,7 @@ void HTMLParser::handle_in_body(HTMLToken& token)
|
|||
adjust_mathml_attributes(token);
|
||||
adjust_foreign_attributes(token);
|
||||
|
||||
(void)insert_foreign_element(token, Namespace::MathML);
|
||||
(void)insert_foreign_element(token, MUST(FlyString::from_deprecated_fly_string(Namespace::MathML)));
|
||||
|
||||
if (token.is_self_closing()) {
|
||||
(void)m_stack_of_open_elements.pop();
|
||||
|
@ -2141,7 +2141,7 @@ void HTMLParser::handle_in_body(HTMLToken& token)
|
|||
adjust_svg_attributes(token);
|
||||
adjust_foreign_attributes(token);
|
||||
|
||||
(void)insert_foreign_element(token, Namespace::SVG);
|
||||
(void)insert_foreign_element(token, MUST(FlyString::from_deprecated_fly_string(Namespace::SVG)));
|
||||
|
||||
if (token.is_self_closing()) {
|
||||
(void)m_stack_of_open_elements.pop();
|
||||
|
@ -2178,7 +2178,7 @@ void HTMLParser::handle_in_body(HTMLToken& token)
|
|||
(void)m_stack_of_open_elements.pop();
|
||||
break;
|
||||
}
|
||||
if (is_special_tag(node->local_name(), node->namespace_())) {
|
||||
if (is_special_tag(node->local_name(), node->namespace_uri())) {
|
||||
log_parse_error();
|
||||
return;
|
||||
}
|
||||
|
@ -3508,7 +3508,7 @@ void HTMLParser::process_using_the_rules_for_foreign_content(HTMLToken& token)
|
|||
adjust_foreign_attributes(token);
|
||||
|
||||
// Insert a foreign element for the token, in the same namespace as the adjusted current node.
|
||||
(void)insert_foreign_element(token, adjusted_current_node().namespace_());
|
||||
(void)insert_foreign_element(token, adjusted_current_node().namespace_uri());
|
||||
|
||||
// If the token has its self-closing flag set, then run the appropriate steps from the following list:
|
||||
if (token.is_self_closing()) {
|
||||
|
|
|
@ -68,7 +68,7 @@ public:
|
|||
|
||||
InsertionMode insertion_mode() const { return m_insertion_mode; }
|
||||
|
||||
static bool is_special_tag(FlyString const& tag_name, DeprecatedFlyString const& namespace_);
|
||||
static bool is_special_tag(FlyString const& tag_name, Optional<FlyString> const& namespace_);
|
||||
|
||||
HTMLTokenizer& tokenizer() { return m_tokenizer; }
|
||||
|
||||
|
@ -120,7 +120,7 @@ private:
|
|||
|
||||
void generate_implied_end_tags(FlyString const& exception = {});
|
||||
void generate_all_implied_end_tags_thoroughly();
|
||||
JS::NonnullGCPtr<DOM::Element> create_element_for(HTMLToken const&, DeprecatedFlyString const& namespace_, DOM::Node& intended_parent);
|
||||
JS::NonnullGCPtr<DOM::Element> create_element_for(HTMLToken const&, Optional<FlyString> const& namespace_, DOM::Node& intended_parent);
|
||||
|
||||
struct AdjustedInsertionLocation {
|
||||
JS::GCPtr<DOM::Node> parent;
|
||||
|
@ -131,7 +131,7 @@ private:
|
|||
|
||||
DOM::Text* find_character_insertion_node();
|
||||
void flush_character_insertions();
|
||||
JS::NonnullGCPtr<DOM::Element> insert_foreign_element(HTMLToken const&, DeprecatedFlyString const&);
|
||||
JS::NonnullGCPtr<DOM::Element> insert_foreign_element(HTMLToken const&, Optional<FlyString> const& namespace_);
|
||||
JS::NonnullGCPtr<DOM::Element> insert_html_element(HTMLToken const&);
|
||||
DOM::Element& current_node();
|
||||
DOM::Element& adjusted_current_node();
|
||||
|
|
|
@ -128,7 +128,7 @@ JS::GCPtr<DOM::Element> StackOfOpenElements::topmost_special_node_below(DOM::Ele
|
|||
for (auto& element : m_elements.in_reverse()) {
|
||||
if (element.ptr() == &formatting_element)
|
||||
break;
|
||||
if (HTMLParser::is_special_tag(element->local_name(), element->namespace_()))
|
||||
if (HTMLParser::is_special_tag(element->local_name(), element->namespace_uri()))
|
||||
found_element = element.ptr();
|
||||
}
|
||||
return found_element.ptr();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue