mirror of
https://github.com/RGBCube/serenity
synced 2025-05-28 08:35:09 +00:00
LibJS: Add Array.of()
This commit is contained in:
parent
ca22476d9d
commit
e333b60064
3 changed files with 47 additions and 0 deletions
|
@ -44,6 +44,7 @@ ArrayConstructor::ArrayConstructor()
|
|||
|
||||
u8 attr = Attribute::Writable | Attribute::Configurable;
|
||||
put_native_function("isArray", is_array, 1, attr);
|
||||
put_native_function("of", of, 0, attr);
|
||||
}
|
||||
|
||||
ArrayConstructor::~ArrayConstructor()
|
||||
|
@ -86,4 +87,12 @@ Value ArrayConstructor::is_array(Interpreter& interpreter)
|
|||
return Value(StringView(value.as_object().class_name()) == "Array");
|
||||
}
|
||||
|
||||
Value ArrayConstructor::of(Interpreter& interpreter)
|
||||
{
|
||||
auto* array = Array::create(interpreter.global_object());
|
||||
for (size_t i = 0; i < interpreter.argument_count(); ++i)
|
||||
array->elements().append(interpreter.argument(i));
|
||||
return array;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue