1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-28 06:57:45 +00:00

LibWeb: Port LegacyPlatformObject from DeprecatedString to String

This commit is contained in:
Shannon Booth 2023-11-21 12:15:56 +13:00 committed by Tim Flynn
parent 56d10bf198
commit f43313d099
6 changed files with 32 additions and 30 deletions

View file

@ -123,11 +123,11 @@ WebIDL::ExceptionOr<void> LegacyPlatformObject::invoke_indexed_property_setter(J
}
// https://webidl.spec.whatwg.org/#invoke-named-setter
WebIDL::ExceptionOr<void> LegacyPlatformObject::invoke_named_property_setter(DeprecatedString const& property_name, JS::Value value)
WebIDL::ExceptionOr<void> LegacyPlatformObject::invoke_named_property_setter(String const& property_name, JS::Value value)
{
// 1. Let creating be true if P is not a supported property name, and false otherwise.
Vector<String> supported_property_names = this->supported_property_names();
bool creating = !supported_property_names.contains_slow(MUST(String::from_deprecated_string(property_name)));
bool creating = !supported_property_names.contains_slow(property_name);
// FIXME: We do not have this information at this point, so converting the value is left as an exercise to the inheritor of LegacyPlatformObject.
// 2. Let operation be the operation used to declare the indexed property setter.
@ -174,7 +174,7 @@ JS::ThrowCompletionOr<bool> LegacyPlatformObject::internal_set(JS::PropertyKey c
// 2. If O implements an interface with a named property setter and Type(P) is String, then:
if (has_named_property_setter() && property_name.is_string()) {
// 1. Invoke the named property setter on O with P and V.
TRY(throw_dom_exception_if_needed(vm, [&] { return invoke_named_property_setter(property_name.as_string(), value); }));
TRY(throw_dom_exception_if_needed(vm, [&] { return invoke_named_property_setter(MUST(String::from_deprecated_string(property_name.as_string())), value); }));
// 2. Return true.
return true;
@ -236,7 +236,7 @@ JS::ThrowCompletionOr<bool> LegacyPlatformObject::internal_define_own_property(J
return false;
// 2. Invoke the named property setter on O with P and Desc.[[Value]].
TRY(throw_dom_exception_if_needed(vm, [&] { return invoke_named_property_setter(property_name_as_string, property_descriptor.value.value()); }));
TRY(throw_dom_exception_if_needed(vm, [&] { return invoke_named_property_setter(MUST(String::from_deprecated_string(property_name_as_string)), property_descriptor.value.value()); }));
// 3. Return true.
return true;
@ -291,7 +291,7 @@ JS::ThrowCompletionOr<bool> LegacyPlatformObject::internal_delete(JS::PropertyKe
// 4. Otherwise, operation was defined with an identifier:
// 1. Perform method steps of operation with O as this and « P » as the argument values.
// 2. If operation was declared with a return type of boolean and the steps returned false, then return false.
auto did_deletion_fail = TRY(throw_dom_exception_if_needed(vm, [&] { return delete_value(property_name_string); }));
auto did_deletion_fail = TRY(throw_dom_exception_if_needed(vm, [&] { return delete_value(MUST(String::from_deprecated_string(property_name_string))); }));
if (!named_property_deleter_has_identifier())
VERIFY(did_deletion_fail != DidDeletionFail::NotRelevant);
@ -339,7 +339,7 @@ JS::ThrowCompletionOr<JS::MarkedVector<JS::Value>> LegacyPlatformObject::interna
if (supports_indexed_properties()) {
for (u64 index = 0; index <= NumericLimits<u32>::max(); ++index) {
if (is_supported_property_index(index))
keys.append(JS::PrimitiveString::create(vm, DeprecatedString::number(index)));
keys.append(JS::PrimitiveString::create(vm, MUST(String::number(index))));
else
break;
}

View file

@ -42,12 +42,12 @@ public:
// NOTE: These will crash if you make has_named_property_setter return true but do not override these methods.
// NOTE: This is only used if named_property_setter_has_identifier returns false, otherwise set_value_of_named_property is used instead.
virtual WebIDL::ExceptionOr<void> set_value_of_new_named_property(DeprecatedString const&, JS::Value) { VERIFY_NOT_REACHED(); }
virtual WebIDL::ExceptionOr<void> set_value_of_existing_named_property(DeprecatedString const&, JS::Value) { VERIFY_NOT_REACHED(); }
virtual WebIDL::ExceptionOr<void> set_value_of_new_named_property(String const&, JS::Value) { VERIFY_NOT_REACHED(); }
virtual WebIDL::ExceptionOr<void> set_value_of_existing_named_property(String const&, JS::Value) { VERIFY_NOT_REACHED(); }
// NOTE: These will crash if you make has_named_property_setter return true but do not override these methods.
// NOTE: This is only used if you make named_property_setter_has_identifier return true, otherwise set_value_of_{new,existing}_named_property is used instead.
virtual WebIDL::ExceptionOr<void> set_value_of_named_property(DeprecatedString const&, JS::Value) { VERIFY_NOT_REACHED(); }
virtual WebIDL::ExceptionOr<void> set_value_of_named_property(String const&, JS::Value) { VERIFY_NOT_REACHED(); }
// NOTE: These will crash if you make has_indexed_property_setter return true but do not override these methods.
// NOTE: This is only used if indexed_property_setter_has_identifier returns false, otherwise set_value_of_indexed_property is used instead.
@ -67,7 +67,7 @@ public:
};
// NOTE: This will crash if you make has_named_property_deleter return true but do not override this method.
virtual WebIDL::ExceptionOr<DidDeletionFail> delete_value(DeprecatedString const&) { VERIFY_NOT_REACHED(); }
virtual WebIDL::ExceptionOr<DidDeletionFail> delete_value(String const&) { VERIFY_NOT_REACHED(); }
protected:
explicit LegacyPlatformObject(JS::Realm& realm);
@ -90,7 +90,7 @@ protected:
private:
WebIDL::ExceptionOr<void> invoke_indexed_property_setter(JS::PropertyKey const&, JS::Value);
WebIDL::ExceptionOr<void> invoke_named_property_setter(DeprecatedString const&, JS::Value);
WebIDL::ExceptionOr<void> invoke_named_property_setter(String const&, JS::Value);
};
}