1 | /* |
2 | * Copyright (C) 1999-2000 Harri Porten ([email protected]) |
3 | * Copyright (C) 2007-2019 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 | |
26 | namespace JSC { |
27 | |
28 | class ArrayAllocationProfile; |
29 | class ArrayPrototype; |
30 | class JSArray; |
31 | class GetterSetter; |
32 | |
33 | class ArrayConstructor final : public InternalFunction { |
34 | public: |
35 | typedef InternalFunction Base; |
36 | static constexpr 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 | |
52 | protected: |
53 | void finishCreation(VM&, JSGlobalObject*, ArrayPrototype*, GetterSetter* speciesSymbol); |
54 | |
55 | private: |
56 | ArrayConstructor(VM&, Structure*); |
57 | }; |
58 | |
59 | JSArray* constructArrayWithSizeQuirk(JSGlobalObject*, ArrayAllocationProfile*, JSValue length, JSValue prototype = JSValue()); |
60 | |
61 | EncodedJSValue JSC_HOST_CALL arrayConstructorPrivateFuncIsArraySlow(JSGlobalObject*, CallFrame*); |
62 | bool isArraySlow(JSGlobalObject*, ProxyObject* argument); |
63 | |
64 | // ES6 7.2.2 |
65 | // https://tc39.github.io/ecma262/#sec-isarray |
66 | inline bool isArray(JSGlobalObject* globalObject, JSValue argumentValue) |
67 | { |
68 | if (!argumentValue.isObject()) |
69 | return false; |
70 | |
71 | JSObject* argument = jsCast<JSObject*>(argumentValue); |
72 | if (argument->type() == ArrayType || argument->type() == DerivedArrayType) |
73 | return true; |
74 | |
75 | if (argument->type() != ProxyObjectType) |
76 | return false; |
77 | return isArraySlow(globalObject, jsCast<ProxyObject*>(argument)); |
78 | } |
79 | |
80 | } // namespace JSC |
81 | |