diff options
author | Linus Groh <mail@linusgroh.de> | 2021-10-03 02:17:33 +0100 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2021-10-03 20:14:03 +0100 |
commit | 3be26f56db0b70c02a361e7ccf797eecfd84ab99 (patch) | |
tree | e219b220a9550a3408bc8050a2a5ad3976563357 /Userland | |
parent | f38a5957bf7c7546181fc098bb27e45a7a21415d (diff) | |
download | serenity-3be26f56db0b70c02a361e7ccf797eecfd84ab99.zip |
LibJS: Convert has_own_property() to ThrowCompletionOr
Diffstat (limited to 'Userland')
8 files changed, 22 insertions, 19 deletions
diff --git a/Userland/Applications/Spreadsheet/Spreadsheet.cpp b/Userland/Applications/Spreadsheet/Spreadsheet.cpp index 85b58501cf..84900d3b66 100644 --- a/Userland/Applications/Spreadsheet/Spreadsheet.cpp +++ b/Userland/Applications/Spreadsheet/Spreadsheet.cpp @@ -656,7 +656,7 @@ JsonObject Sheet::gather_documentation() const return; 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; dbgln("Found '{}'", it.key.to_display_string()); diff --git a/Userland/Libraries/LibJS/Runtime/ArgumentsObject.cpp b/Userland/Libraries/LibJS/Runtime/ArgumentsObject.cpp index 086491697b..66509f627c 100644 --- a/Userland/Libraries/LibJS/Runtime/ArgumentsObject.cpp +++ b/Userland/Libraries/LibJS/Runtime/ArgumentsObject.cpp @@ -39,8 +39,10 @@ ThrowCompletionOr<Value> ArgumentsObject::internal_get(PropertyName const& prope { // 1. Let map be args.[[ParameterMap]]. auto& map = *m_parameter_map; + // 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 if (!is_mapped) { // a. Return ? OrdinaryGet(args, P, Receiver). @@ -65,7 +67,7 @@ ThrowCompletionOr<bool> ArgumentsObject::internal_set(PropertyName const& proper } else { // a. Let map be args.[[ParameterMap]]. // 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 @@ -88,7 +90,7 @@ ThrowCompletionOr<bool> ArgumentsObject::internal_delete(PropertyName const& pro auto& map = parameter_map(); // 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). 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. if (!desc.has_value()) return desc; + // 3. Let map be args.[[ParameterMap]]. // 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 if (is_mapped) { // a. Set desc.[[Value]] to Get(map, P). desc->value = TRY(m_parameter_map->get(property_name)); } + // 6. Return desc. return desc; } @@ -131,7 +136,7 @@ ThrowCompletionOr<bool> ArgumentsObject::internal_define_own_property(PropertyNa auto& map = parameter_map(); // 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. auto new_arg_desc = descriptor; diff --git a/Userland/Libraries/LibJS/Runtime/GlobalEnvironment.cpp b/Userland/Libraries/LibJS/Runtime/GlobalEnvironment.cpp index 5920bd20ed..69ae734d0f 100644 --- a/Userland/Libraries/LibJS/Runtime/GlobalEnvironment.cpp +++ b/Userland/Libraries/LibJS/Runtime/GlobalEnvironment.cpp @@ -98,7 +98,7 @@ bool GlobalEnvironment::delete_binding(GlobalObject& global_object, FlyString co if (m_declarative_record->has_binding(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) { bool status = m_object_record->delete_binding(global_object, name); 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 bool GlobalEnvironment::can_declare_global_var(FlyString const& name) const { - auto& vm = this->vm(); auto& global_object = m_object_record->binding_object(); - bool has_property = global_object.has_own_property(name); - if (vm.exception()) - return {}; + bool has_property = TRY_OR_DISCARD(global_object.has_own_property(name)); if (has_property) return true; 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& global_object = m_object_record->binding_object(); - bool has_property = global_object.has_own_property(name); - if (vm.exception()) + auto has_property_or_error = global_object.has_own_property(name); + if (has_property_or_error.is_error()) return; + auto has_property = has_property_or_error.release_value(); auto extensible_or_error = global_object.is_extensible(); if (extensible_or_error.is_error()) return; diff --git a/Userland/Libraries/LibJS/Runtime/Object.cpp b/Userland/Libraries/LibJS/Runtime/Object.cpp index a177811968..e0e6c4dc29 100644 --- a/Userland/Libraries/LibJS/Runtime/Object.cpp +++ b/Userland/Libraries/LibJS/Runtime/Object.cpp @@ -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 -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. @@ -262,7 +262,7 @@ bool Object::has_own_property(PropertyName const& property_name) const VERIFY(property_name.is_valid()); // 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. if (!descriptor.has_value()) diff --git a/Userland/Libraries/LibJS/Runtime/Object.h b/Userland/Libraries/LibJS/Runtime/Object.h index d2d698d19f..95b33c34fb 100644 --- a/Userland/Libraries/LibJS/Runtime/Object.h +++ b/Userland/Libraries/LibJS/Runtime/Object.h @@ -84,7 +84,7 @@ public: ThrowCompletionOr<bool> define_property_or_throw(PropertyName const&, PropertyDescriptor const&); ThrowCompletionOr<bool> delete_property_or_throw(PropertyName 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 test_integrity_level(IntegrityLevel) const; MarkedValueList enumerable_own_property_names(PropertyKind kind) const; diff --git a/Userland/Libraries/LibJS/Runtime/ObjectConstructor.cpp b/Userland/Libraries/LibJS/Runtime/ObjectConstructor.cpp index 26485d2fec..5890d49697 100644 --- a/Userland/Libraries/LibJS/Runtime/ObjectConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/ObjectConstructor.cpp @@ -442,7 +442,7 @@ JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::has_own) return {}; // 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 diff --git a/Userland/Libraries/LibJS/Runtime/ObjectPrototype.cpp b/Userland/Libraries/LibJS/Runtime/ObjectPrototype.cpp index 909d05f420..9e9b578bf7 100644 --- a/Userland/Libraries/LibJS/Runtime/ObjectPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/ObjectPrototype.cpp @@ -67,7 +67,7 @@ JS_DEFINE_NATIVE_FUNCTION(ObjectPrototype::has_own_property) auto* this_object = vm.this_value(global_object).to_object(global_object); if (!this_object) 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 diff --git a/Userland/Services/WebContent/ConsoleGlobalObject.cpp b/Userland/Services/WebContent/ConsoleGlobalObject.cpp index 308d161775..f3a77e4442 100644 --- a/Userland/Services/WebContent/ConsoleGlobalObject.cpp +++ b/Userland/Services/WebContent/ConsoleGlobalObject.cpp @@ -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 { - 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 Base::internal_get(property_name, receiver); |