mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 18:42:43 +00:00 
			
		
		
		
	LibJS: Convert has_own_property() to ThrowCompletionOr
This commit is contained in:
		
							parent
							
								
									f38a5957bf
								
							
						
					
					
						commit
						3be26f56db
					
				
					 9 changed files with 23 additions and 23 deletions
				
			
		|  | @ -1680,10 +1680,7 @@ bool @class_name@::is_named_property_exposed_on_object(JS::PropertyName const& p | |||
|     while (prototype) { | ||||
|         // 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)
 | ||||
|         bool prototype_has_own_property_named_p = prototype->has_own_property(property_name); | ||||
|         if (vm.exception()) | ||||
|             return {}; | ||||
| 
 | ||||
|         bool prototype_has_own_property_named_p = TRY_OR_DISCARD(prototype->has_own_property(property_name)); | ||||
|         if (prototype_has_own_property_named_p) | ||||
|             return false; | ||||
| 
 | ||||
|  |  | |||
|  | @ -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()); | ||||
|  |  | |||
|  | @ -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; | ||||
|  |  | |||
|  | @ -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; | ||||
|  |  | |||
|  | @ -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()) | ||||
|  |  | |||
|  | @ -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; | ||||
|  |  | |||
|  | @ -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
 | ||||
|  |  | |||
|  | @ -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
 | ||||
|  |  | |||
|  | @ -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); | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Linus Groh
						Linus Groh