1
Fork 0
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:
Linus Groh 2020-05-08 16:28:35 +01:00 committed by Andreas Kling
parent 01fd6ce045
commit ca22476d9d
3 changed files with 42 additions and 0 deletions

View file

@ -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");
}
}