diff options
Diffstat (limited to 'Libraries/LibJS/Runtime/ArrayConstructor.cpp')
-rw-r--r-- | Libraries/LibJS/Runtime/ArrayConstructor.cpp | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/Libraries/LibJS/Runtime/ArrayConstructor.cpp b/Libraries/LibJS/Runtime/ArrayConstructor.cpp index cab2a3f755..003171de39 100644 --- a/Libraries/LibJS/Runtime/ArrayConstructor.cpp +++ b/Libraries/LibJS/Runtime/ArrayConstructor.cpp @@ -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"); +} + } |