
This is now a bit closer to the spec's 10.4.2.2 ArrayCreate - it will throw a RangeError if the requested length exceeds 2^32 - 1, so anyone passing in a custom value (defaults to zero for same behaviour as before) will need an exception check at the call site.
33 lines
716 B
C++
33 lines
716 B
C++
/*
|
|
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <LibJS/Runtime/Object.h>
|
|
|
|
namespace JS {
|
|
|
|
class Array : public Object {
|
|
JS_OBJECT(Array, Object);
|
|
|
|
public:
|
|
static Array* create(GlobalObject&, size_t length = 0);
|
|
static Array* create_from(GlobalObject&, const Vector<Value>&);
|
|
|
|
explicit Array(Object& prototype);
|
|
virtual void initialize(GlobalObject&) override;
|
|
virtual ~Array() override;
|
|
|
|
static Array* typed_this(VM&, GlobalObject&);
|
|
|
|
private:
|
|
virtual bool is_array() const override { return true; }
|
|
|
|
JS_DECLARE_NATIVE_GETTER(length_getter);
|
|
JS_DECLARE_NATIVE_SETTER(length_setter);
|
|
};
|
|
|
|
}
|