mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 19:58:11 +00:00
LibJS: Handle Proxy with Array target in IsArray() abstract operation
This was missing from Value::is_array(), which is equivalent to the spec's IsArray() abstract operation - it treats a Proxy value with an Array target object as being an Array. It can throw, so needs both the global object and an exception check now.
This commit is contained in:
parent
9b35231453
commit
83be39c91a
11 changed files with 52 additions and 24 deletions
|
@ -26,6 +26,7 @@
|
|||
#include <LibJS/Runtime/NumberObject.h>
|
||||
#include <LibJS/Runtime/Object.h>
|
||||
#include <LibJS/Runtime/PrimitiveString.h>
|
||||
#include <LibJS/Runtime/ProxyObject.h>
|
||||
#include <LibJS/Runtime/RegExpObject.h>
|
||||
#include <LibJS/Runtime/StringObject.h>
|
||||
#include <LibJS/Runtime/Symbol.h>
|
||||
|
@ -196,14 +197,29 @@ static String double_to_string(double d)
|
|||
return builder.to_string();
|
||||
}
|
||||
|
||||
bool Value::is_array() const
|
||||
// 7.2.2 IsArray, https://tc39.es/ecma262/#sec-isarray
|
||||
bool Value::is_array(GlobalObject& global_object) const
|
||||
{
|
||||
return is_object() && as_object().is_array();
|
||||
if (!is_object())
|
||||
return false;
|
||||
auto& object = as_object();
|
||||
if (object.is_array())
|
||||
return true;
|
||||
if (is<ProxyObject>(object)) {
|
||||
auto& proxy = static_cast<ProxyObject const&>(object);
|
||||
if (proxy.is_revoked()) {
|
||||
auto& vm = global_object.vm();
|
||||
vm.throw_exception<TypeError>(global_object, ErrorType::ProxyRevoked);
|
||||
return false;
|
||||
}
|
||||
return Value(&proxy.target()).is_array(global_object);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
Array& Value::as_array()
|
||||
{
|
||||
VERIFY(is_array());
|
||||
VERIFY(is_object() && as_object().is_array());
|
||||
return static_cast<Array&>(*m_value.as_object);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue