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:
Timothy Flynn 2024-10-31 12:29:31 -04:00 committed by Alexander Kalenik
commit 663a5e97ca
Notes: github-actions[bot] 2024-10-31 23:36:52 +00:00

View file

@ -28,6 +28,12 @@ public:
static NonnullGCPtr<Array> create_from(Realm&, Vector<Value> const&); static NonnullGCPtr<Array> create_from(Realm&, Vector<Value> const&);
static NonnullGCPtr<Array> create_from(Realm&, ReadonlySpan<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. // Non-standard but equivalent to CreateArrayFromList.
template<typename T> template<typename T>
static NonnullGCPtr<Array> create_from(Realm& realm, ReadonlySpan<T> elements, Function<Value(T const&)> map_fn) static NonnullGCPtr<Array> create_from(Realm& realm, ReadonlySpan<T> elements, Function<Value(T const&)> map_fn)