mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-10-18 06:00:27 +00:00
LibJS+LibWeb: Port interned bytecode strings to UTF-16
This was almost a no-op, except we intern JS exception messages. So the bulk of this patch is porting exception messages to UTF-16.
This commit is contained in:
parent
cf61171864
commit
70db474cf0
Notes:
github-actions[bot]
2025-08-14 08:28:16 +00:00
Author: https://github.com/trflynn89
Commit: 70db474cf0
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/5845
Reviewed-by: https://github.com/gmta ✅
162 changed files with 1405 additions and 1422 deletions
|
@ -353,7 +353,7 @@ static WebIDL::ExceptionOr<String> serialize_element_attributes(DOM::Element con
|
|||
});
|
||||
|
||||
if (local_name_set_iterator != local_name_set.end())
|
||||
return WebIDL::InvalidStateError::create(realm, "Element contains two attributes with identical namespaces and local names"_string);
|
||||
return WebIDL::InvalidStateError::create(realm, "Element contains two attributes with identical namespaces and local names"_utf16);
|
||||
}
|
||||
|
||||
// 2. Create a new tuple consisting of attr's namespaceURI attribute and localName attribute, and add it to the localname set.
|
||||
|
@ -406,12 +406,12 @@ static WebIDL::ExceptionOr<String> serialize_element_attributes(DOM::Element con
|
|||
// 2. If the require well-formed flag is set (its value is true), and the value of attr's value attribute matches the XMLNS namespace,
|
||||
// then throw an exception; the serialization of this attribute would produce invalid XML because the XMLNS namespace is reserved and cannot be applied as an element's namespace via XML parsing.
|
||||
if (require_well_formed == RequireWellFormed::Yes && attribute->value() == Namespace::XMLNS)
|
||||
return WebIDL::InvalidStateError::create(realm, "The XMLNS namespace cannot be used as an element's namespace"_string);
|
||||
return WebIDL::InvalidStateError::create(realm, "The XMLNS namespace cannot be used as an element's namespace"_utf16);
|
||||
|
||||
// 3. If the require well-formed flag is set (its value is true), and the value of attr's value attribute is the empty string,
|
||||
// then throw an exception; namespace prefix declarations cannot be used to undeclare a namespace (use a default namespace declaration instead).
|
||||
if (require_well_formed == RequireWellFormed::Yes && attribute->value().is_empty())
|
||||
return WebIDL::InvalidStateError::create(realm, "Attribute's value is empty"_string);
|
||||
return WebIDL::InvalidStateError::create(realm, "Attribute's value is empty"_utf16);
|
||||
|
||||
// 4. [If] the attr's prefix matches the string "xmlns", then let candidate prefix be the string "xmlns".
|
||||
if (attribute->prefix() == "xmlns"sv)
|
||||
|
@ -454,12 +454,12 @@ static WebIDL::ExceptionOr<String> serialize_element_attributes(DOM::Element con
|
|||
// or does not match the XML Name production or equals "xmlns" and attribute namespace is null, then throw an exception; the serialization of this attr would not be a well-formed attribute.
|
||||
if (require_well_formed == RequireWellFormed::Yes) {
|
||||
if (attribute->local_name().bytes_as_string_view().contains(':'))
|
||||
return WebIDL::InvalidStateError::create(realm, "Attribute's local name contains a colon"_string);
|
||||
return WebIDL::InvalidStateError::create(realm, "Attribute's local name contains a colon"_utf16);
|
||||
|
||||
// FIXME: Check attribute's local name against the XML Name production.
|
||||
|
||||
if (attribute->local_name() == "xmlns"sv && !attribute->namespace_uri().has_value())
|
||||
return WebIDL::InvalidStateError::create(realm, "Attribute's local name is 'xmlns' and the attribute has no namespace"_string);
|
||||
return WebIDL::InvalidStateError::create(realm, "Attribute's local name is 'xmlns' and the attribute has no namespace"_utf16);
|
||||
}
|
||||
|
||||
// 9. Append the following strings to result, in the order listed:
|
||||
|
@ -489,7 +489,7 @@ static WebIDL::ExceptionOr<String> serialize_element(DOM::Element const& element
|
|||
// then throw an exception; the serialization of this node would not be a well-formed element.
|
||||
if (require_well_formed == RequireWellFormed::Yes) {
|
||||
if (element.local_name().bytes_as_string_view().contains(':'))
|
||||
return WebIDL::InvalidStateError::create(realm, "Element's local name contains a colon"_string);
|
||||
return WebIDL::InvalidStateError::create(realm, "Element's local name contains a colon"_utf16);
|
||||
|
||||
// FIXME: Check element's local name against the XML Char production.
|
||||
}
|
||||
|
@ -560,7 +560,7 @@ static WebIDL::ExceptionOr<String> serialize_element(DOM::Element const& element
|
|||
if (prefix == "xmlns"sv) {
|
||||
// 1. If the require well-formed flag is set, then throw an error. An Element with prefix "xmlns" will not legally round-trip in a conforming XML parser.
|
||||
if (require_well_formed == RequireWellFormed::Yes)
|
||||
return WebIDL::InvalidStateError::create(realm, "Elements prefix is 'xmlns'"_string);
|
||||
return WebIDL::InvalidStateError::create(realm, "Elements prefix is 'xmlns'"_utf16);
|
||||
|
||||
// 2. Let candidate prefix be the value of prefix.
|
||||
candidate_prefix = prefix;
|
||||
|
@ -727,7 +727,7 @@ static WebIDL::ExceptionOr<String> serialize_document(DOM::Document const& docum
|
|||
// If the require well-formed flag is set (its value is true), and this node has no documentElement (the documentElement attribute's value is null),
|
||||
// then throw an exception; the serialization of this node would not be a well-formed document.
|
||||
if (require_well_formed == RequireWellFormed::Yes && !document.document_element())
|
||||
return WebIDL::InvalidStateError::create(document.realm(), "Document has no document element"_string);
|
||||
return WebIDL::InvalidStateError::create(document.realm(), "Document has no document element"_utf16);
|
||||
|
||||
// Otherwise, run the following steps:
|
||||
// 1. Let serialized document be an empty string.
|
||||
|
@ -751,10 +751,10 @@ static WebIDL::ExceptionOr<String> serialize_comment(DOM::Comment const& comment
|
|||
// FIXME: Check comment's data against the XML Char production.
|
||||
|
||||
if (comment.data().contains("--"sv))
|
||||
return WebIDL::InvalidStateError::create(comment.realm(), "Comment data contains two adjacent hyphens"_string);
|
||||
return WebIDL::InvalidStateError::create(comment.realm(), "Comment data contains two adjacent hyphens"_utf16);
|
||||
|
||||
if (comment.data().ends_with("-"sv))
|
||||
return WebIDL::InvalidStateError::create(comment.realm(), "Comment data ends with a hyphen"_string);
|
||||
return WebIDL::InvalidStateError::create(comment.realm(), "Comment data ends with a hyphen"_utf16);
|
||||
}
|
||||
|
||||
// Otherwise, return the concatenation of "<!--", node's data, and "-->".
|
||||
|
@ -777,7 +777,7 @@ static WebIDL::ExceptionOr<String> serialize_text(DOM::Text const& text, Require
|
|||
if (require_well_formed == RequireWellFormed::Yes) {
|
||||
for (u32 code_point : text.data()) {
|
||||
if (!is_valid_xml_char(code_point))
|
||||
return WebIDL::InvalidStateError::create(text.realm(), "Text contains characters not allowed in XML"_string);
|
||||
return WebIDL::InvalidStateError::create(text.realm(), "Text contains characters not allowed in XML"_utf16);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -823,7 +823,7 @@ static WebIDL::ExceptionOr<String> serialize_document_type(DOM::DocumentType con
|
|||
// both a """ (U+0022 QUOTATION MARK) and a "'" (U+0027 APOSTROPHE), then throw an exception; the serialization of this node would not be a well-formed document type declaration.
|
||||
// FIXME: Check systemId against the XML Char production.
|
||||
if (document_type.system_id().contains('"') && document_type.system_id().contains('\''))
|
||||
return WebIDL::InvalidStateError::create(document_type.realm(), "Document type system ID contains both a quotation mark and an apostrophe"_string);
|
||||
return WebIDL::InvalidStateError::create(document_type.realm(), "Document type system ID contains both a quotation mark and an apostrophe"_utf16);
|
||||
}
|
||||
|
||||
// 3. Let markup be an empty string.
|
||||
|
@ -885,16 +885,16 @@ static WebIDL::ExceptionOr<String> serialize_processing_instruction(DOM::Process
|
|||
// 1. If the require well-formed flag is set (its value is true), and node's target contains a ":" (U+003A COLON) character
|
||||
// or is an ASCII case-insensitive match for the string "xml", then throw an exception; the serialization of this node's target would not be well-formed.
|
||||
if (processing_instruction.target().contains(':'))
|
||||
return WebIDL::InvalidStateError::create(processing_instruction.realm(), "Processing instruction target contains a colon"_string);
|
||||
return WebIDL::InvalidStateError::create(processing_instruction.realm(), "Processing instruction target contains a colon"_utf16);
|
||||
|
||||
if (processing_instruction.target().equals_ignoring_ascii_case("xml"sv))
|
||||
return WebIDL::InvalidStateError::create(processing_instruction.realm(), "Processing instruction target is equal to 'xml'"_string);
|
||||
return WebIDL::InvalidStateError::create(processing_instruction.realm(), "Processing instruction target is equal to 'xml'"_utf16);
|
||||
|
||||
// 2. If the require well-formed flag is set (its value is true), and node's data contains characters that are not matched by the XML Char production or contains
|
||||
// the string "?>" (U+003F QUESTION MARK, U+003E GREATER-THAN SIGN), then throw an exception; the serialization of this node's data would not be well-formed.
|
||||
// FIXME: Check data against the XML Char production.
|
||||
if (processing_instruction.data().contains("?>"sv))
|
||||
return WebIDL::InvalidStateError::create(processing_instruction.realm(), "Processing instruction data contains a terminator"_string);
|
||||
return WebIDL::InvalidStateError::create(processing_instruction.realm(), "Processing instruction data contains a terminator"_utf16);
|
||||
}
|
||||
|
||||
// 3. Let markup be the concatenation of the following, in the order listed:
|
||||
|
@ -923,7 +923,7 @@ static WebIDL::ExceptionOr<String> serialize_processing_instruction(DOM::Process
|
|||
static WebIDL::ExceptionOr<String> serialize_cdata_section(DOM::CDATASection const& cdata_section, RequireWellFormed require_well_formed)
|
||||
{
|
||||
if (require_well_formed == RequireWellFormed::Yes && cdata_section.data().contains("]]>"sv))
|
||||
return WebIDL::InvalidStateError::create(cdata_section.realm(), "CDATA section data contains a CDATA section end delimiter"_string);
|
||||
return WebIDL::InvalidStateError::create(cdata_section.realm(), "CDATA section data contains a CDATA section end delimiter"_utf16);
|
||||
|
||||
StringBuilder markup;
|
||||
markup.append("<![CDATA["sv);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue