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
21QT_BEGIN_NAMESPACE
22
23template<typename Number>
24inline bool qIsAtMostUintLimit(Number length, uint limit = std::numeric_limits<uint>::max())
25{
26 // Use the type with the larger positive range to do the comparison.
27
28 Q_ASSERT(length >= 0);
29 if constexpr (sizeof(Number) > sizeof(uint)) {
30 return length <= Number(limit);
31 } else {
32 return uint(length) <= limit;
33 }
34}
35
36template<typename Number>
37inline bool qIsAtMostSizetypeLimit(
38 Number length, qsizetype limit = std::numeric_limits<qsizetype>::max())
39{
40 // Use the type with the larger positive range to do the comparison.
41
42 Q_ASSERT(limit >= 0);
43 if constexpr (sizeof(qsizetype) > sizeof(Number)) {
44 return qsizetype(length) <= limit;
45 } else {
46 return length <= Number(limit);
47 }
48}
49
50namespace QV4 {
51
52namespace Heap {
53
54struct ArrayCtor : FunctionObject {
55 void init(QV4::ExecutionEngine *engine);
56};
57
58}
59
60struct ArrayCtor: FunctionObject
61{
62 V4_OBJECT2(ArrayCtor, FunctionObject)
63
64 static ReturnedValue virtualCallAsConstructor(const FunctionObject *f, const Value *argv, int argc, const Value *newTarget);
65 static ReturnedValue virtualCall(const FunctionObject *f, const Value *thisObject, const Value *argv, int argc);
66};
67
68struct ArrayPrototype: ArrayObject
69{
70 void init(ExecutionEngine *engine, Object *ctor);
71
72 static ReturnedValue method_isArray(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
73 static ReturnedValue method_from(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
74 static ReturnedValue method_of(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
75 static ReturnedValue method_toString(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
76 static ReturnedValue method_toLocaleString(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
77 static ReturnedValue method_concat(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
78 static ReturnedValue method_copyWithin(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
79 static ReturnedValue method_entries(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
80 static ReturnedValue method_find(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
81 static ReturnedValue method_findIndex(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
82 static ReturnedValue method_join(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
83 static ReturnedValue method_pop(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
84 static ReturnedValue method_push(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
85 static ReturnedValue method_reverse(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
86 static ReturnedValue method_shift(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
87 static ReturnedValue method_slice(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
88 static ReturnedValue method_sort(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
89 static ReturnedValue method_splice(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
90 static ReturnedValue method_unshift(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
91 static ReturnedValue method_includes(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
92 static ReturnedValue method_indexOf(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
93 static ReturnedValue method_keys(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
94 static ReturnedValue method_lastIndexOf(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
95 static ReturnedValue method_every(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
96 static ReturnedValue method_fill(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
97 static ReturnedValue method_some(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
98 static ReturnedValue method_forEach(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
99 static ReturnedValue method_map(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
100 static ReturnedValue method_filter(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
101 static ReturnedValue method_reduce(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
102 static ReturnedValue method_reduceRight(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
103 static ReturnedValue method_values(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
104
105 // while this function is implemented here, it's the same for many other JS classes, so the corresponding JS function
106 // is instantiated in the engine, and it can be added to any JS object through Object::addSymbolSpecies()
107 static ReturnedValue method_get_species(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
108};
109
110
111} // namespace QV4
112
113QT_END_NAMESPACE
114
115#endif // QV4ECMAOBJECTS_P_H
116

source code of qtdeclarative/src/qml/jsruntime/qv4arrayobject_p.h