mirror of
https://github.com/fergalmoran/ladybird.git
synced 2025-12-26 19:29:16 +00:00
LibJS: Add Array.isArray()
This commit is contained in:
committed by
Andreas Kling
parent
01fd6ce045
commit
ca22476d9d
@@ -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");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user