1/*
2 * Copyright (C) 1999-2000 Harri Porten (porten@kde.org)
3 * Copyright (C) 2007-2008, 2011, 2016 Apple Inc. All rights reserved.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 *
19 */
20
21#pragma once
22
23#include "InternalFunction.h"
24#include "ProxyObject.h"
25
26namespace JSC {
27
28class ArrayAllocationProfile;
29class ArrayPrototype;
30class JSArray;
31class GetterSetter;
32
33class ArrayConstructor final : public InternalFunction {
34public:
35 typedef InternalFunction Base;
36 static const unsigned StructureFlags = Base::StructureFlags | HasStaticPropertyTable;
37
38 static ArrayConstructor* create(VM& vm, JSGlobalObject* globalObject, Structure* structure, ArrayPrototype* arrayPrototype, GetterSetter* speciesSymbol)
39 {
40 ArrayConstructor* constructor = new (NotNull, allocateCell<ArrayConstructor>(vm.heap)) ArrayConstructor(vm, structure);
41 constructor->finishCreation(vm, globalObject, arrayPrototype, speciesSymbol);
42 return constructor;
43 }
44
45 DECLARE_INFO;
46
47 static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
48 {
49 return Structure::create(vm, globalObject, prototype, TypeInfo(InternalFunctionType, StructureFlags), info());
50 }
51
52protected:
53 void finishCreation(VM&, JSGlobalObject*, ArrayPrototype*, GetterSetter* speciesSymbol);
54
55private:
56 ArrayConstructor(VM&, Structure*);
57};
58
59JSArray* constructArrayWithSizeQuirk(ExecState*, ArrayAllocationProfile*, JSGlobalObject*, JSValue length, JSValue prototype = JSValue());
60
61EncodedJSValue JSC_HOST_CALL arrayConstructorPrivateFuncIsArrayConstructor(ExecState*);
62EncodedJSValue JSC_HOST_CALL arrayConstructorPrivateFuncIsArraySlow(ExecState*);
63bool isArraySlow(ExecState*, ProxyObject* argument);
64
65// ES6 7.2.2
66// https://tc39.github.io/ecma262/#sec-isarray
67inline bool isArray(ExecState* exec, JSValue argumentValue)
68{
69 if (!argumentValue.isObject())
70 return false;
71
72 JSObject* argument = jsCast<JSObject*>(argumentValue);
73 if (argument->type() == ArrayType || argument->type() == DerivedArrayType)
74 return true;
75
76 if (argument->type() != ProxyObjectType)
77 return false;
78 return isArraySlow(exec, jsCast<ProxyObject*>(argument));
79}
80
81} // namespace JSC
82