mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 10:57:35 +00:00
LibJS: Convert define_properties() to ThrowCompletionOr
This commit is contained in:
parent
0a49a2db60
commit
3b59a4577d
3 changed files with 12 additions and 12 deletions
|
@ -1038,7 +1038,7 @@ void Object::define_native_function(PropertyName const& property_name, Function<
|
||||||
}
|
}
|
||||||
|
|
||||||
// 20.1.2.3.1 ObjectDefineProperties ( O, Properties ), https://tc39.es/ecma262/#sec-objectdefineproperties
|
// 20.1.2.3.1 ObjectDefineProperties ( O, Properties ), https://tc39.es/ecma262/#sec-objectdefineproperties
|
||||||
Object* Object::define_properties(Value properties)
|
ThrowCompletionOr<Object*> Object::define_properties(Value properties)
|
||||||
{
|
{
|
||||||
auto& vm = this->vm();
|
auto& vm = this->vm();
|
||||||
auto& global_object = this->global_object();
|
auto& global_object = this->global_object();
|
||||||
|
@ -1047,11 +1047,11 @@ Object* Object::define_properties(Value properties)
|
||||||
|
|
||||||
// 2. Let props be ? ToObject(Properties).
|
// 2. Let props be ? ToObject(Properties).
|
||||||
auto* props = properties.to_object(global_object);
|
auto* props = properties.to_object(global_object);
|
||||||
if (vm.exception())
|
if (auto* exception = vm.exception())
|
||||||
return {};
|
return throw_completion(exception->value());
|
||||||
|
|
||||||
// 3. Let keys be ? props.[[OwnPropertyKeys]]().
|
// 3. Let keys be ? props.[[OwnPropertyKeys]]().
|
||||||
auto keys = TRY_OR_DISCARD(props->internal_own_property_keys());
|
auto keys = TRY(props->internal_own_property_keys());
|
||||||
|
|
||||||
struct NameAndDescriptor {
|
struct NameAndDescriptor {
|
||||||
PropertyName name;
|
PropertyName name;
|
||||||
|
@ -1066,17 +1066,17 @@ Object* Object::define_properties(Value properties)
|
||||||
auto property_name = PropertyName::from_value(global_object, next_key);
|
auto property_name = PropertyName::from_value(global_object, next_key);
|
||||||
|
|
||||||
// a. Let propDesc be ? props.[[GetOwnProperty]](nextKey).
|
// a. Let propDesc be ? props.[[GetOwnProperty]](nextKey).
|
||||||
auto property_descriptor = TRY_OR_DISCARD(props->internal_get_own_property(property_name));
|
auto property_descriptor = TRY(props->internal_get_own_property(property_name));
|
||||||
|
|
||||||
// b. If propDesc is not undefined and propDesc.[[Enumerable]] is true, then
|
// b. If propDesc is not undefined and propDesc.[[Enumerable]] is true, then
|
||||||
if (property_descriptor.has_value() && *property_descriptor->enumerable) {
|
if (property_descriptor.has_value() && *property_descriptor->enumerable) {
|
||||||
// i. Let descObj be ? Get(props, nextKey).
|
// i. Let descObj be ? Get(props, nextKey).
|
||||||
auto descriptor_object = TRY_OR_DISCARD(props->get(property_name));
|
auto descriptor_object = TRY(props->get(property_name));
|
||||||
|
|
||||||
// ii. Let desc be ? ToPropertyDescriptor(descObj).
|
// ii. Let desc be ? ToPropertyDescriptor(descObj).
|
||||||
auto descriptor = to_property_descriptor(global_object, descriptor_object);
|
auto descriptor = to_property_descriptor(global_object, descriptor_object);
|
||||||
if (vm.exception())
|
if (auto* exception = vm.exception())
|
||||||
return {};
|
return throw_completion(exception->value());
|
||||||
|
|
||||||
// iii. Append the pair (a two element List) consisting of nextKey and desc to the end of descriptors.
|
// iii. Append the pair (a two element List) consisting of nextKey and desc to the end of descriptors.
|
||||||
descriptors.append({ property_name, descriptor });
|
descriptors.append({ property_name, descriptor });
|
||||||
|
@ -1089,7 +1089,7 @@ Object* Object::define_properties(Value properties)
|
||||||
// b. Let desc be the second element of pair.
|
// b. Let desc be the second element of pair.
|
||||||
|
|
||||||
// c. Perform ? DefinePropertyOrThrow(O, P, desc).
|
// c. Perform ? DefinePropertyOrThrow(O, P, desc).
|
||||||
TRY_OR_DISCARD(define_property_or_throw(name, descriptor));
|
TRY(define_property_or_throw(name, descriptor));
|
||||||
}
|
}
|
||||||
|
|
||||||
// 7. Return O.
|
// 7. Return O.
|
||||||
|
|
|
@ -112,7 +112,7 @@ public:
|
||||||
|
|
||||||
// 20.1 Object Objects, https://tc39.es/ecma262/#sec-object-objects
|
// 20.1 Object Objects, https://tc39.es/ecma262/#sec-object-objects
|
||||||
|
|
||||||
Object* define_properties(Value properties);
|
ThrowCompletionOr<Object*> define_properties(Value properties);
|
||||||
|
|
||||||
// Implementation-specific storage abstractions
|
// Implementation-specific storage abstractions
|
||||||
|
|
||||||
|
|
|
@ -354,7 +354,7 @@ JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::define_properties)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. Return ? ObjectDefineProperties(O, Properties).
|
// 2. Return ? ObjectDefineProperties(O, Properties).
|
||||||
return object.as_object().define_properties(properties);
|
return TRY_OR_DISCARD(object.as_object().define_properties(properties));
|
||||||
}
|
}
|
||||||
|
|
||||||
// 20.1.2.13 Object.is ( value1, value2 ), https://tc39.es/ecma262/#sec-object.is
|
// 20.1.2.13 Object.is ( value1, value2 ), https://tc39.es/ecma262/#sec-object.is
|
||||||
|
@ -411,7 +411,7 @@ JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::create)
|
||||||
// 3. If Properties is not undefined, then
|
// 3. If Properties is not undefined, then
|
||||||
if (!properties.is_undefined()) {
|
if (!properties.is_undefined()) {
|
||||||
// a. Return ? ObjectDefineProperties(obj, Properties).
|
// a. Return ? ObjectDefineProperties(obj, Properties).
|
||||||
return object->define_properties(properties);
|
return TRY_OR_DISCARD(object->define_properties(properties));
|
||||||
}
|
}
|
||||||
|
|
||||||
// 4. Return obj.
|
// 4. Return obj.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue