mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-22 10:19:20 +00:00
LibJS: Add an Array::create_from overload to accept a plain array
This is just a wrapper to easily construct an Array from a span. This avoids creating a Vector of values that are possiby Objects. One such case is in ArrayIteratorPrototype::next.
This commit is contained in:
parent
108b4e7c15
commit
663a5e97ca
Notes:
github-actions[bot]
2024-10-31 23:36:52 +00:00
Author: https://github.com/trflynn89
Commit: 663a5e97ca
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2088
1 changed files with 6 additions and 0 deletions
|
@ -28,6 +28,12 @@ public:
|
|||
static NonnullGCPtr<Array> create_from(Realm&, Vector<Value> const&);
|
||||
static NonnullGCPtr<Array> create_from(Realm&, ReadonlySpan<Value> const&);
|
||||
|
||||
template<size_t N>
|
||||
static NonnullGCPtr<Array> create_from(Realm& realm, Value const (&values)[N])
|
||||
{
|
||||
return create_from(realm, ReadonlySpan<Value> { values, N });
|
||||
}
|
||||
|
||||
// Non-standard but equivalent to CreateArrayFromList.
|
||||
template<typename T>
|
||||
static NonnullGCPtr<Array> create_from(Realm& realm, ReadonlySpan<T> elements, Function<Value(T const&)> map_fn)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue