mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 12:27:34 +00:00
LibWeb: Port LegacyPlatformObject from DeprecatedString to String
This commit is contained in:
parent
56d10bf198
commit
f43313d099
6 changed files with 32 additions and 30 deletions
|
@ -119,24 +119,26 @@ DeprecatedString DOMStringMap::determine_value_of_named_property(DeprecatedStrin
|
|||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/dom.html#dom-domstringmap-setitem
|
||||
WebIDL::ExceptionOr<void> DOMStringMap::set_value_of_new_named_property(DeprecatedString const& name, JS::Value unconverted_value)
|
||||
WebIDL::ExceptionOr<void> DOMStringMap::set_value_of_new_named_property(String const& name, JS::Value unconverted_value)
|
||||
{
|
||||
// NOTE: Since LegacyPlatformObject does not know the type of value, we must convert it ourselves.
|
||||
// The type of `value` is `DOMString`.
|
||||
auto value = TRY(unconverted_value.to_string(vm()));
|
||||
|
||||
AK::StringBuilder builder;
|
||||
StringBuilder builder;
|
||||
|
||||
// 3. Insert the string data- at the front of name.
|
||||
// NOTE: This is done out of order because StringBuilder doesn't have prepend.
|
||||
builder.append("data-"sv);
|
||||
|
||||
for (size_t character_index = 0; character_index < name.length(); ++character_index) {
|
||||
// 1. If name contains a U+002D HYPHEN-MINUS character (-) followed by an ASCII lower alpha, then throw a "SyntaxError" DOMException.
|
||||
auto current_character = name[character_index];
|
||||
auto name_view = name.bytes_as_string_view();
|
||||
|
||||
if (current_character == '-' && character_index + 1 < name.length()) {
|
||||
auto next_character = name[character_index + 1];
|
||||
for (size_t character_index = 0; character_index < name_view.length(); ++character_index) {
|
||||
// 1. If name contains a U+002D HYPHEN-MINUS character (-) followed by an ASCII lower alpha, then throw a "SyntaxError" DOMException.
|
||||
auto current_character = name_view[character_index];
|
||||
|
||||
if (current_character == '-' && character_index + 1 < name_view.length()) {
|
||||
auto next_character = name_view[character_index + 1];
|
||||
if (is_ascii_lower_alpha(next_character))
|
||||
return WebIDL::SyntaxError::create(realm(), "Name cannot contain a '-' followed by a lowercase character."_fly_string);
|
||||
}
|
||||
|
@ -162,21 +164,21 @@ WebIDL::ExceptionOr<void> DOMStringMap::set_value_of_new_named_property(Deprecat
|
|||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/dom.html#dom-domstringmap-setitem
|
||||
WebIDL::ExceptionOr<void> DOMStringMap::set_value_of_existing_named_property(DeprecatedString const& name, JS::Value value)
|
||||
WebIDL::ExceptionOr<void> DOMStringMap::set_value_of_existing_named_property(String const& name, JS::Value value)
|
||||
{
|
||||
return set_value_of_new_named_property(name, value);
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/dom.html#dom-domstringmap-removeitem
|
||||
WebIDL::ExceptionOr<Bindings::LegacyPlatformObject::DidDeletionFail> DOMStringMap::delete_value(DeprecatedString const& name)
|
||||
WebIDL::ExceptionOr<Bindings::LegacyPlatformObject::DidDeletionFail> DOMStringMap::delete_value(String const& name)
|
||||
{
|
||||
AK::StringBuilder builder;
|
||||
StringBuilder builder;
|
||||
|
||||
// 2. Insert the string data- at the front of name.
|
||||
// NOTE: This is done out of order because StringBuilder doesn't have prepend.
|
||||
builder.append("data-"sv);
|
||||
|
||||
for (auto character : name) {
|
||||
for (auto character : name.bytes_as_string_view()) {
|
||||
// 1. For each ASCII upper alpha in name, insert a U+002D HYPHEN-MINUS character (-) before the character and replace the character with the same character converted to ASCII lowercase.
|
||||
if (is_ascii_upper_alpha(character)) {
|
||||
builder.append('-');
|
||||
|
|
|
@ -24,10 +24,10 @@ public:
|
|||
|
||||
DeprecatedString determine_value_of_named_property(DeprecatedString const&) const;
|
||||
|
||||
virtual WebIDL::ExceptionOr<void> set_value_of_new_named_property(DeprecatedString const&, JS::Value) override;
|
||||
virtual WebIDL::ExceptionOr<void> set_value_of_existing_named_property(DeprecatedString const&, JS::Value) override;
|
||||
virtual WebIDL::ExceptionOr<void> set_value_of_new_named_property(String const&, JS::Value) override;
|
||||
virtual WebIDL::ExceptionOr<void> set_value_of_existing_named_property(String const&, JS::Value) override;
|
||||
|
||||
virtual WebIDL::ExceptionOr<DidDeletionFail> delete_value(DeprecatedString const&) override;
|
||||
virtual WebIDL::ExceptionOr<DidDeletionFail> delete_value(String const&) override;
|
||||
|
||||
private:
|
||||
explicit DOMStringMap(DOM::Element&);
|
||||
|
|
|
@ -167,18 +167,18 @@ WebIDL::ExceptionOr<JS::Value> Storage::named_item_value(FlyString const& name)
|
|||
return JS::PrimitiveString::create(vm(), value.release_value());
|
||||
}
|
||||
|
||||
WebIDL::ExceptionOr<Bindings::LegacyPlatformObject::DidDeletionFail> Storage::delete_value(DeprecatedString const& name)
|
||||
WebIDL::ExceptionOr<Bindings::LegacyPlatformObject::DidDeletionFail> Storage::delete_value(String const& name)
|
||||
{
|
||||
remove_item(name);
|
||||
return DidDeletionFail::NotRelevant;
|
||||
}
|
||||
|
||||
WebIDL::ExceptionOr<void> Storage::set_value_of_named_property(DeprecatedString const& key, JS::Value unconverted_value)
|
||||
WebIDL::ExceptionOr<void> Storage::set_value_of_named_property(String const& key, JS::Value unconverted_value)
|
||||
{
|
||||
// NOTE: Since LegacyPlatformObject does not know the type of value, we must convert it ourselves.
|
||||
// The type of `value` is `DOMString`.
|
||||
auto value = TRY(unconverted_value.to_string(vm()));
|
||||
return set_item(String::from_deprecated_string(key).release_value(), value);
|
||||
return set_item(key, value);
|
||||
}
|
||||
|
||||
void Storage::dump() const
|
||||
|
|
|
@ -39,9 +39,9 @@ private:
|
|||
|
||||
// ^LegacyPlatformObject
|
||||
virtual WebIDL::ExceptionOr<JS::Value> named_item_value(FlyString const&) const override;
|
||||
virtual WebIDL::ExceptionOr<DidDeletionFail> delete_value(DeprecatedString const&) override;
|
||||
virtual WebIDL::ExceptionOr<DidDeletionFail> delete_value(String const&) override;
|
||||
virtual Vector<String> supported_property_names() const override;
|
||||
virtual WebIDL::ExceptionOr<void> set_value_of_named_property(DeprecatedString const& key, JS::Value value) override;
|
||||
virtual WebIDL::ExceptionOr<void> set_value_of_named_property(String const& key, JS::Value value) override;
|
||||
|
||||
virtual bool supports_indexed_properties() const override { return false; }
|
||||
virtual bool supports_named_properties() const override { return true; }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue