1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 13:17:35 +00:00

LibJS: Convert has_own_property() to ThrowCompletionOr

This commit is contained in:
Linus Groh 2021-10-03 02:17:33 +01:00
parent f38a5957bf
commit 3be26f56db
9 changed files with 23 additions and 23 deletions

View file

@ -1680,10 +1680,7 @@ bool @class_name@::is_named_property_exposed_on_object(JS::PropertyName const& p
while (prototype) { while (prototype) {
// FIXME: 1. If prototype is not a named properties object, and prototype has an own property named P, then return false. // FIXME: 1. If prototype is not a named properties object, and prototype has an own property named P, then return false.
// (It currently does not check for named property objects) // (It currently does not check for named property objects)
bool prototype_has_own_property_named_p = prototype->has_own_property(property_name); bool prototype_has_own_property_named_p = TRY_OR_DISCARD(prototype->has_own_property(property_name));
if (vm.exception())
return {};
if (prototype_has_own_property_named_p) if (prototype_has_own_property_named_p)
return false; return false;

View file

@ -656,7 +656,7 @@ JsonObject Sheet::gather_documentation() const
return; return;
auto& value_object = value.is_object() ? value.as_object() : value.as_function(); auto& value_object = value.is_object() ? value.as_object() : value.as_function();
if (!value_object.has_own_property(doc_name)) if (!value_object.has_own_property(doc_name).release_value())
return; return;
dbgln("Found '{}'", it.key.to_display_string()); dbgln("Found '{}'", it.key.to_display_string());

View file

@ -39,8 +39,10 @@ ThrowCompletionOr<Value> ArgumentsObject::internal_get(PropertyName const& prope
{ {
// 1. Let map be args.[[ParameterMap]]. // 1. Let map be args.[[ParameterMap]].
auto& map = *m_parameter_map; auto& map = *m_parameter_map;
// 2. Let isMapped be ! HasOwnProperty(map, P). // 2. Let isMapped be ! HasOwnProperty(map, P).
bool is_mapped = m_parameter_map->has_own_property(property_name); bool is_mapped = MUST(m_parameter_map->has_own_property(property_name));
// 3. If isMapped is false, then // 3. If isMapped is false, then
if (!is_mapped) { if (!is_mapped) {
// a. Return ? OrdinaryGet(args, P, Receiver). // a. Return ? OrdinaryGet(args, P, Receiver).
@ -65,7 +67,7 @@ ThrowCompletionOr<bool> ArgumentsObject::internal_set(PropertyName const& proper
} else { } else {
// a. Let map be args.[[ParameterMap]]. // a. Let map be args.[[ParameterMap]].
// b. Let isMapped be ! HasOwnProperty(map, P). // b. Let isMapped be ! HasOwnProperty(map, P).
is_mapped = parameter_map().has_own_property(property_name); is_mapped = MUST(parameter_map().has_own_property(property_name));
} }
// 3. If isMapped is true, then // 3. If isMapped is true, then
@ -88,7 +90,7 @@ ThrowCompletionOr<bool> ArgumentsObject::internal_delete(PropertyName const& pro
auto& map = parameter_map(); auto& map = parameter_map();
// 2. Let isMapped be ! HasOwnProperty(map, P). // 2. Let isMapped be ! HasOwnProperty(map, P).
bool is_mapped = map.has_own_property(property_name); bool is_mapped = MUST(map.has_own_property(property_name));
// 3. Let result be ? OrdinaryDelete(args, P). // 3. Let result be ? OrdinaryDelete(args, P).
bool result = TRY(Object::internal_delete(property_name)); bool result = TRY(Object::internal_delete(property_name));
@ -112,14 +114,17 @@ ThrowCompletionOr<Optional<PropertyDescriptor>> ArgumentsObject::internal_get_ow
// 2. If desc is undefined, return desc. // 2. If desc is undefined, return desc.
if (!desc.has_value()) if (!desc.has_value())
return desc; return desc;
// 3. Let map be args.[[ParameterMap]]. // 3. Let map be args.[[ParameterMap]].
// 4. Let isMapped be ! HasOwnProperty(map, P). // 4. Let isMapped be ! HasOwnProperty(map, P).
bool is_mapped = m_parameter_map->has_own_property(property_name); bool is_mapped = MUST(m_parameter_map->has_own_property(property_name));
// 5. If isMapped is true, then // 5. If isMapped is true, then
if (is_mapped) { if (is_mapped) {
// a. Set desc.[[Value]] to Get(map, P). // a. Set desc.[[Value]] to Get(map, P).
desc->value = TRY(m_parameter_map->get(property_name)); desc->value = TRY(m_parameter_map->get(property_name));
} }
// 6. Return desc. // 6. Return desc.
return desc; return desc;
} }
@ -131,7 +136,7 @@ ThrowCompletionOr<bool> ArgumentsObject::internal_define_own_property(PropertyNa
auto& map = parameter_map(); auto& map = parameter_map();
// 2. Let isMapped be HasOwnProperty(map, P). // 2. Let isMapped be HasOwnProperty(map, P).
bool is_mapped = map.has_own_property(property_name); bool is_mapped = MUST(map.has_own_property(property_name));
// 3. Let newArgDesc be Desc. // 3. Let newArgDesc be Desc.
auto new_arg_desc = descriptor; auto new_arg_desc = descriptor;

View file

@ -98,7 +98,7 @@ bool GlobalEnvironment::delete_binding(GlobalObject& global_object, FlyString co
if (m_declarative_record->has_binding(name)) if (m_declarative_record->has_binding(name))
return m_declarative_record->delete_binding(global_object, name); return m_declarative_record->delete_binding(global_object, name);
bool existing_prop = m_object_record->binding_object().has_own_property(name); bool existing_prop = TRY_OR_DISCARD(m_object_record->binding_object().has_own_property(name));
if (existing_prop) { if (existing_prop) {
bool status = m_object_record->delete_binding(global_object, name); bool status = m_object_record->delete_binding(global_object, name);
if (status) { if (status) {
@ -136,11 +136,8 @@ bool GlobalEnvironment::has_restricted_global_property(FlyString const& name) co
// 9.1.1.4.15 CanDeclareGlobalVar ( N ), https://tc39.es/ecma262/#sec-candeclareglobalvar // 9.1.1.4.15 CanDeclareGlobalVar ( N ), https://tc39.es/ecma262/#sec-candeclareglobalvar
bool GlobalEnvironment::can_declare_global_var(FlyString const& name) const bool GlobalEnvironment::can_declare_global_var(FlyString const& name) const
{ {
auto& vm = this->vm();
auto& global_object = m_object_record->binding_object(); auto& global_object = m_object_record->binding_object();
bool has_property = global_object.has_own_property(name); bool has_property = TRY_OR_DISCARD(global_object.has_own_property(name));
if (vm.exception())
return {};
if (has_property) if (has_property)
return true; return true;
return TRY_OR_DISCARD(global_object.is_extensible()); return TRY_OR_DISCARD(global_object.is_extensible());
@ -165,9 +162,10 @@ void GlobalEnvironment::create_global_var_binding(FlyString const& name, bool ca
{ {
auto& vm = this->vm(); auto& vm = this->vm();
auto& global_object = m_object_record->binding_object(); auto& global_object = m_object_record->binding_object();
bool has_property = global_object.has_own_property(name); auto has_property_or_error = global_object.has_own_property(name);
if (vm.exception()) if (has_property_or_error.is_error())
return; return;
auto has_property = has_property_or_error.release_value();
auto extensible_or_error = global_object.is_extensible(); auto extensible_or_error = global_object.is_extensible();
if (extensible_or_error.is_error()) if (extensible_or_error.is_error())
return; return;

View file

@ -254,7 +254,7 @@ ThrowCompletionOr<bool> Object::has_property(PropertyName const& property_name)
} }
// 7.3.12 HasOwnProperty ( O, P ), https://tc39.es/ecma262/#sec-hasownproperty // 7.3.12 HasOwnProperty ( O, P ), https://tc39.es/ecma262/#sec-hasownproperty
bool Object::has_own_property(PropertyName const& property_name) const ThrowCompletionOr<bool> Object::has_own_property(PropertyName const& property_name) const
{ {
// 1. Assert: Type(O) is Object. // 1. Assert: Type(O) is Object.
@ -262,7 +262,7 @@ bool Object::has_own_property(PropertyName const& property_name) const
VERIFY(property_name.is_valid()); VERIFY(property_name.is_valid());
// 3. Let desc be ? O.[[GetOwnProperty]](P). // 3. Let desc be ? O.[[GetOwnProperty]](P).
auto descriptor = TRY_OR_DISCARD(internal_get_own_property(property_name)); auto descriptor = TRY(internal_get_own_property(property_name));
// 4. If desc is undefined, return false. // 4. If desc is undefined, return false.
if (!descriptor.has_value()) if (!descriptor.has_value())

View file

@ -84,7 +84,7 @@ public:
ThrowCompletionOr<bool> define_property_or_throw(PropertyName const&, PropertyDescriptor const&); ThrowCompletionOr<bool> define_property_or_throw(PropertyName const&, PropertyDescriptor const&);
ThrowCompletionOr<bool> delete_property_or_throw(PropertyName const&); ThrowCompletionOr<bool> delete_property_or_throw(PropertyName const&);
ThrowCompletionOr<bool> has_property(PropertyName const&) const; ThrowCompletionOr<bool> has_property(PropertyName const&) const;
bool has_own_property(PropertyName const&) const; ThrowCompletionOr<bool> has_own_property(PropertyName const&) const;
bool set_integrity_level(IntegrityLevel); bool set_integrity_level(IntegrityLevel);
bool test_integrity_level(IntegrityLevel) const; bool test_integrity_level(IntegrityLevel) const;
MarkedValueList enumerable_own_property_names(PropertyKind kind) const; MarkedValueList enumerable_own_property_names(PropertyKind kind) const;

View file

@ -442,7 +442,7 @@ JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::has_own)
return {}; return {};
// 3. Return ? HasOwnProperty(obj, key). // 3. Return ? HasOwnProperty(obj, key).
return Value(object->has_own_property(key)); return Value(TRY_OR_DISCARD(object->has_own_property(key)));
} }
// 20.1.2.1 Object.assign ( target, ...sources ), https://tc39.es/ecma262/#sec-object.assign // 20.1.2.1 Object.assign ( target, ...sources ), https://tc39.es/ecma262/#sec-object.assign

View file

@ -67,7 +67,7 @@ JS_DEFINE_NATIVE_FUNCTION(ObjectPrototype::has_own_property)
auto* this_object = vm.this_value(global_object).to_object(global_object); auto* this_object = vm.this_value(global_object).to_object(global_object);
if (!this_object) if (!this_object)
return {}; return {};
return Value(this_object->has_own_property(property_key)); return Value(TRY_OR_DISCARD(this_object->has_own_property(property_key)));
} }
// 20.1.3.6 Object.prototype.toString ( ), https://tc39.es/ecma262/#sec-object.prototype.tostring // 20.1.3.6 Object.prototype.toString ( ), https://tc39.es/ecma262/#sec-object.prototype.tostring

View file

@ -77,7 +77,7 @@ JS::ThrowCompletionOr<bool> ConsoleGlobalObject::internal_has_property(JS::Prope
JS::ThrowCompletionOr<JS::Value> ConsoleGlobalObject::internal_get(JS::PropertyName const& property_name, JS::Value receiver) const JS::ThrowCompletionOr<JS::Value> ConsoleGlobalObject::internal_get(JS::PropertyName const& property_name, JS::Value receiver) const
{ {
if (m_window_object->has_own_property(property_name)) if (TRY(m_window_object->has_own_property(property_name)))
return m_window_object->internal_get(property_name, (receiver == this) ? m_window_object : receiver); return m_window_object->internal_get(property_name, (receiver == this) ? m_window_object : receiver);
return Base::internal_get(property_name, receiver); return Base::internal_get(property_name, receiver);