mirror of
https://github.com/RGBCube/serenity
synced 2025-05-28 01:25:09 +00:00
LibJS: Add Array.isArray()
This commit is contained in:
parent
01fd6ce045
commit
ca22476d9d
3 changed files with 42 additions and 0 deletions
|
@ -41,6 +41,9 @@ ArrayConstructor::ArrayConstructor()
|
|||
{
|
||||
put("prototype", interpreter().global_object().array_prototype(), 0);
|
||||
put("length", Value(1), Attribute::Configurable);
|
||||
|
||||
u8 attr = Attribute::Writable | Attribute::Configurable;
|
||||
put_native_function("isArray", is_array, 1, attr);
|
||||
}
|
||||
|
||||
ArrayConstructor::~ArrayConstructor()
|
||||
|
@ -74,4 +77,13 @@ Value ArrayConstructor::construct(Interpreter& interpreter)
|
|||
return call(interpreter);
|
||||
}
|
||||
|
||||
Value ArrayConstructor::is_array(Interpreter& interpreter)
|
||||
{
|
||||
auto value = interpreter.argument(0);
|
||||
if (!value.is_array())
|
||||
return Value(false);
|
||||
// Exclude TypedArray and similar
|
||||
return Value(StringView(value.as_object().class_name()) == "Array");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue