mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 15:28:11 +00:00
LibJS: Make Object.getOwnPropertyDescriptor() work on String subscripts
String objects are a bit special since the indexed properties are overridden by the contents of the underlying PrimitiveString. getOwnPropertyDescriptor() was not taking this into account, and would instead return undefined when asked about an indexed property in a String object.
This commit is contained in:
parent
25baefdd1e
commit
686213c2b8
3 changed files with 24 additions and 0 deletions
|
@ -39,4 +39,18 @@ void StringObject::visit_edges(Cell::Visitor& visitor)
|
|||
visitor.visit(&m_string);
|
||||
}
|
||||
|
||||
Optional<PropertyDescriptor> StringObject::get_own_property_descriptor(PropertyName const& property_name) const
|
||||
{
|
||||
if (!property_name.is_number() || property_name.as_number() >= m_string.string().length())
|
||||
return Base::get_own_property_descriptor(property_name);
|
||||
|
||||
PropertyDescriptor descriptor;
|
||||
descriptor.value = js_string(heap(), m_string.string().substring(property_name.as_number(), 1));
|
||||
descriptor.attributes.set_has_configurable();
|
||||
descriptor.attributes.set_has_enumerable();
|
||||
descriptor.attributes.set_has_writable();
|
||||
descriptor.attributes.set_enumerable();
|
||||
return descriptor;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue