mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 04:37:34 +00:00
LibJS: Convert PropertyKey::from_value() to ThrowCompletionOr
Lots of MUST() - perhaps we'll eventually come up with a better API for the common case where it can't fail.
This commit is contained in:
parent
62356cff40
commit
29e96eceeb
7 changed files with 23 additions and 25 deletions
|
@ -296,7 +296,7 @@ ThrowCompletionOr<bool> Object::set_integrity_level(IntegrityLevel level)
|
|||
if (level == IntegrityLevel::Sealed) {
|
||||
// a. For each element k of keys, do
|
||||
for (auto& key : keys) {
|
||||
auto property_name = PropertyKey::from_value(global_object, key);
|
||||
auto property_name = MUST(PropertyKey::from_value(global_object, key));
|
||||
|
||||
// i. Perform ? DefinePropertyOrThrow(O, k, PropertyDescriptor { [[Configurable]]: false }).
|
||||
TRY(define_property_or_throw(property_name, { .configurable = false }));
|
||||
|
@ -308,7 +308,7 @@ ThrowCompletionOr<bool> Object::set_integrity_level(IntegrityLevel level)
|
|||
|
||||
// b. For each element k of keys, do
|
||||
for (auto& key : keys) {
|
||||
auto property_name = PropertyKey::from_value(global_object, key);
|
||||
auto property_name = MUST(PropertyKey::from_value(global_object, key));
|
||||
|
||||
// i. Let currentDesc be ? O.[[GetOwnProperty]](k).
|
||||
auto current_descriptor = TRY(internal_get_own_property(property_name));
|
||||
|
@ -360,7 +360,7 @@ ThrowCompletionOr<bool> Object::test_integrity_level(IntegrityLevel level) const
|
|||
|
||||
// 7. For each element k of keys, do
|
||||
for (auto& key : keys) {
|
||||
auto property_name = PropertyKey::from_value(global_object(), key);
|
||||
auto property_name = MUST(PropertyKey::from_value(global_object(), key));
|
||||
|
||||
// a. Let currentDesc be ? O.[[GetOwnProperty]](k).
|
||||
auto current_descriptor = TRY(internal_get_own_property(property_name));
|
||||
|
@ -405,7 +405,7 @@ ThrowCompletionOr<MarkedValueList> Object::enumerable_own_property_names(Propert
|
|||
// a. If Type(key) is String, then
|
||||
if (!key.is_string())
|
||||
continue;
|
||||
auto property_name = PropertyKey::from_value(global_object, key);
|
||||
auto property_name = MUST(PropertyKey::from_value(global_object, key));
|
||||
|
||||
// i. Let desc be ? O.[[GetOwnProperty]](key).
|
||||
auto descriptor = TRY(internal_get_own_property(property_name));
|
||||
|
@ -453,7 +453,7 @@ ThrowCompletionOr<Object*> Object::copy_data_properties(Value source, HashTable<
|
|||
auto* from_object = MUST(source.to_object(global_object));
|
||||
|
||||
for (auto& next_key_value : TRY(from_object->internal_own_property_keys())) {
|
||||
auto next_key = PropertyKey::from_value(global_object, next_key_value);
|
||||
auto next_key = MUST(PropertyKey::from_value(global_object, next_key_value));
|
||||
if (seen_names.contains(next_key))
|
||||
continue;
|
||||
|
||||
|
@ -1151,7 +1151,7 @@ ThrowCompletionOr<Object*> Object::define_properties(Value properties)
|
|||
|
||||
// 5. For each element nextKey of keys, do
|
||||
for (auto& next_key : keys) {
|
||||
auto property_name = PropertyKey::from_value(global_object, next_key);
|
||||
auto property_name = MUST(PropertyKey::from_value(global_object, next_key));
|
||||
|
||||
// a. Let propDesc be ? props.[[GetOwnProperty]](nextKey).
|
||||
auto property_descriptor = TRY(props->internal_get_own_property(property_name));
|
||||
|
|
|
@ -277,7 +277,7 @@ JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::get_own_property_descriptors)
|
|||
|
||||
// 4. For each element key of ownKeys, do
|
||||
for (auto& key : own_keys) {
|
||||
auto property_name = PropertyKey::from_value(global_object, key);
|
||||
auto property_name = MUST(PropertyKey::from_value(global_object, key));
|
||||
|
||||
// a. Let desc be ? obj.[[GetOwnProperty]](key).
|
||||
auto desc = TRY(object->internal_get_own_property(property_name));
|
||||
|
@ -411,7 +411,7 @@ JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::assign)
|
|||
|
||||
// iii. For each element nextKey of keys, do
|
||||
for (auto& next_key : keys) {
|
||||
auto property_name = PropertyKey::from_value(global_object, next_key);
|
||||
auto property_name = MUST(PropertyKey::from_value(global_object, next_key));
|
||||
|
||||
// 1. Let desc be ? from.[[GetOwnProperty]](nextKey).
|
||||
auto desc = TRY(from->internal_get_own_property(property_name));
|
||||
|
|
|
@ -26,15 +26,15 @@ public:
|
|||
No,
|
||||
};
|
||||
|
||||
static PropertyKey from_value(GlobalObject& global_object, Value value)
|
||||
static ThrowCompletionOr<PropertyKey> from_value(GlobalObject& global_object, Value value)
|
||||
{
|
||||
if (value.is_empty())
|
||||
return {};
|
||||
return PropertyKey {};
|
||||
if (value.is_symbol())
|
||||
return value.as_symbol();
|
||||
return PropertyKey { value.as_symbol() };
|
||||
if (value.is_integral_number() && value.as_double() >= 0 && value.as_double() < NumericLimits<u32>::max())
|
||||
return value.as_u32();
|
||||
return TRY_OR_DISCARD(value.to_string(global_object));
|
||||
return TRY(value.to_string(global_object));
|
||||
}
|
||||
|
||||
PropertyKey() { }
|
||||
|
|
|
@ -699,8 +699,10 @@ ThrowCompletionOr<MarkedValueList> ProxyObject::internal_own_property_keys() con
|
|||
|
||||
// 16. For each element key of targetKeys, do
|
||||
for (auto& key : target_keys) {
|
||||
auto property_key = MUST(PropertyKey::from_value(global_object, key));
|
||||
|
||||
// a. Let desc be ? target.[[GetOwnProperty]](key).
|
||||
auto descriptor = TRY(m_target.internal_get_own_property(PropertyKey::from_value(global_object, key)));
|
||||
auto descriptor = TRY(m_target.internal_get_own_property(property_key));
|
||||
|
||||
// b. If desc is not undefined and desc.[[Configurable]] is false, then
|
||||
if (descriptor.has_value() && !*descriptor->configurable) {
|
||||
|
|
|
@ -810,7 +810,7 @@ ThrowCompletionOr<Object*> merge_largest_unit_option(GlobalObject& global_object
|
|||
|
||||
// 3. For each element nextKey of keys, do
|
||||
for (auto& key : keys) {
|
||||
auto next_key = PropertyKey::from_value(global_object, key);
|
||||
auto next_key = MUST(PropertyKey::from_value(global_object, key));
|
||||
|
||||
// a. Let propValue be ? Get(options, nextKey).
|
||||
auto prop_value = TRY(options.get(next_key));
|
||||
|
|
|
@ -995,7 +995,7 @@ ThrowCompletionOr<Object*> default_merge_fields(GlobalObject& global_object, Obj
|
|||
for (auto& next_key : original_keys) {
|
||||
// a. If nextKey is not "month" or "monthCode", then
|
||||
if (next_key.as_string().string() != vm.names.month.as_string() && next_key.as_string().string() != vm.names.monthCode.as_string()) {
|
||||
auto property_name = PropertyKey::from_value(global_object, next_key);
|
||||
auto property_name = MUST(PropertyKey::from_value(global_object, next_key));
|
||||
|
||||
// i. Let propValue be ? Get(fields, nextKey).
|
||||
auto prop_value = TRY(fields.get(property_name));
|
||||
|
@ -1016,7 +1016,7 @@ ThrowCompletionOr<Object*> default_merge_fields(GlobalObject& global_object, Obj
|
|||
|
||||
// 5. For each element nextKey of newKeys, do
|
||||
for (auto& next_key : new_keys) {
|
||||
auto property_name = PropertyKey::from_value(global_object, next_key);
|
||||
auto property_name = MUST(PropertyKey::from_value(global_object, next_key));
|
||||
|
||||
// a. Let propValue be ? Get(additionalFields, nextKey).
|
||||
auto prop_value = TRY(additional_fields.get(property_name));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue