1 | // Copyright (C) 2016 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | #ifndef QV4ARRAYOBJECT_H |
4 | #define QV4ARRAYOBJECT_H |
5 | |
6 | // |
7 | // W A R N I N G |
8 | // ------------- |
9 | // |
10 | // This file is not part of the Qt API. It exists purely as an |
11 | // implementation detail. This header file may change from version to |
12 | // version without notice, or even be removed. |
13 | // |
14 | // We mean it. |
15 | // |
16 | |
17 | #include "qv4object_p.h" |
18 | #include "qv4functionobject_p.h" |
19 | #include <QtCore/qnumeric.h> |
20 | |
21 | QT_BEGIN_NAMESPACE |
22 | |
23 | inline bool qIsAtMostUintLimit(qsizetype length, uint limit = std::numeric_limits<uint>::max()) |
24 | { |
25 | // Use the type with the larger positive range to do the comparison. |
26 | |
27 | Q_ASSERT(length >= 0); |
28 | if constexpr (sizeof(qsizetype) > sizeof(uint)) { |
29 | return length <= qsizetype(limit); |
30 | } else { |
31 | return uint(length) <= limit; |
32 | } |
33 | } |
34 | |
35 | inline bool qIsAtMostSizetypeLimit(uint length, qsizetype limit = std::numeric_limits<qsizetype>::max()) |
36 | { |
37 | // Use the type with the larger positive range to do the comparison. |
38 | |
39 | Q_ASSERT(limit >= 0); |
40 | if constexpr (sizeof(qsizetype) > sizeof(uint)) { |
41 | return qsizetype(length) <= limit; |
42 | } else { |
43 | return length <= uint(limit); |
44 | } |
45 | } |
46 | |
47 | |
48 | namespace QV4 { |
49 | |
50 | namespace Heap { |
51 | |
52 | struct ArrayCtor : FunctionObject { |
53 | void init(QV4::ExecutionContext *scope); |
54 | }; |
55 | |
56 | } |
57 | |
58 | struct ArrayCtor: FunctionObject |
59 | { |
60 | V4_OBJECT2(ArrayCtor, FunctionObject) |
61 | |
62 | static ReturnedValue virtualCallAsConstructor(const FunctionObject *f, const Value *argv, int argc, const Value *newTarget); |
63 | static ReturnedValue virtualCall(const FunctionObject *f, const Value *thisObject, const Value *argv, int argc); |
64 | }; |
65 | |
66 | struct ArrayPrototype: ArrayObject |
67 | { |
68 | void init(ExecutionEngine *engine, Object *ctor); |
69 | |
70 | static ReturnedValue method_isArray(const FunctionObject *, const Value *thisObject, const Value *argv, int argc); |
71 | static ReturnedValue method_from(const FunctionObject *, const Value *thisObject, const Value *argv, int argc); |
72 | static ReturnedValue method_of(const FunctionObject *, const Value *thisObject, const Value *argv, int argc); |
73 | static ReturnedValue method_toString(const FunctionObject *, const Value *thisObject, const Value *argv, int argc); |
74 | static ReturnedValue method_toLocaleString(const FunctionObject *, const Value *thisObject, const Value *argv, int argc); |
75 | static ReturnedValue method_concat(const FunctionObject *, const Value *thisObject, const Value *argv, int argc); |
76 | static ReturnedValue method_copyWithin(const FunctionObject *, const Value *thisObject, const Value *argv, int argc); |
77 | static ReturnedValue method_entries(const FunctionObject *, const Value *thisObject, const Value *argv, int argc); |
78 | static ReturnedValue method_find(const FunctionObject *, const Value *thisObject, const Value *argv, int argc); |
79 | static ReturnedValue method_findIndex(const FunctionObject *, const Value *thisObject, const Value *argv, int argc); |
80 | static ReturnedValue method_join(const FunctionObject *, const Value *thisObject, const Value *argv, int argc); |
81 | static ReturnedValue method_pop(const FunctionObject *, const Value *thisObject, const Value *argv, int argc); |
82 | static ReturnedValue method_push(const FunctionObject *, const Value *thisObject, const Value *argv, int argc); |
83 | static ReturnedValue method_reverse(const FunctionObject *, const Value *thisObject, const Value *argv, int argc); |
84 | static ReturnedValue method_shift(const FunctionObject *, const Value *thisObject, const Value *argv, int argc); |
85 | static ReturnedValue method_slice(const FunctionObject *, const Value *thisObject, const Value *argv, int argc); |
86 | static ReturnedValue method_sort(const FunctionObject *, const Value *thisObject, const Value *argv, int argc); |
87 | static ReturnedValue method_splice(const FunctionObject *, const Value *thisObject, const Value *argv, int argc); |
88 | static ReturnedValue method_unshift(const FunctionObject *, const Value *thisObject, const Value *argv, int argc); |
89 | static ReturnedValue method_includes(const FunctionObject *, const Value *thisObject, const Value *argv, int argc); |
90 | static ReturnedValue method_indexOf(const FunctionObject *, const Value *thisObject, const Value *argv, int argc); |
91 | static ReturnedValue method_keys(const FunctionObject *, const Value *thisObject, const Value *argv, int argc); |
92 | static ReturnedValue method_lastIndexOf(const FunctionObject *, const Value *thisObject, const Value *argv, int argc); |
93 | static ReturnedValue method_every(const FunctionObject *, const Value *thisObject, const Value *argv, int argc); |
94 | static ReturnedValue method_fill(const FunctionObject *, const Value *thisObject, const Value *argv, int argc); |
95 | static ReturnedValue method_some(const FunctionObject *, const Value *thisObject, const Value *argv, int argc); |
96 | static ReturnedValue method_forEach(const FunctionObject *, const Value *thisObject, const Value *argv, int argc); |
97 | static ReturnedValue method_map(const FunctionObject *, const Value *thisObject, const Value *argv, int argc); |
98 | static ReturnedValue method_filter(const FunctionObject *, const Value *thisObject, const Value *argv, int argc); |
99 | static ReturnedValue method_reduce(const FunctionObject *, const Value *thisObject, const Value *argv, int argc); |
100 | static ReturnedValue method_reduceRight(const FunctionObject *, const Value *thisObject, const Value *argv, int argc); |
101 | static ReturnedValue method_values(const FunctionObject *, const Value *thisObject, const Value *argv, int argc); |
102 | |
103 | // while this function is implemented here, it's the same for many other JS classes, so the corresponding JS function |
104 | // is instantiated in the engine, and it can be added to any JS object through Object::addSymbolSpecies() |
105 | static ReturnedValue method_get_species(const FunctionObject *, const Value *thisObject, const Value *argv, int argc); |
106 | }; |
107 | |
108 | |
109 | } // namespace QV4 |
110 | |
111 | QT_END_NAMESPACE |
112 | |
113 | #endif // QV4ECMAOBJECTS_P_H |
114 | |