1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2016 The Qt Company Ltd. |
4 | ** Contact: https://www.qt.io/licensing/ |
5 | ** |
6 | ** This file is part of the QtQml module of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:LGPL$ |
9 | ** Commercial License Usage |
10 | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | ** accordance with the commercial license agreement provided with the |
12 | ** Software or, alternatively, in accordance with the terms contained in |
13 | ** a written agreement between you and The Qt Company. For licensing terms |
14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at https://www.qt.io/contact-us. |
16 | ** |
17 | ** GNU Lesser General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
19 | ** General Public License version 3 as published by the Free Software |
20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the |
21 | ** packaging of this file. Please review the following information to |
22 | ** ensure the GNU Lesser General Public License version 3 requirements |
23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. |
24 | ** |
25 | ** GNU General Public License Usage |
26 | ** Alternatively, this file may be used under the terms of the GNU |
27 | ** General Public License version 2.0 or (at your option) the GNU General |
28 | ** Public license version 3 or any later version approved by the KDE Free |
29 | ** Qt Foundation. The licenses are as published by the Free Software |
30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
31 | ** included in the packaging of this file. Please review the following |
32 | ** information to ensure the GNU General Public License requirements will |
33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
34 | ** https://www.gnu.org/licenses/gpl-3.0.html. |
35 | ** |
36 | ** $QT_END_LICENSE$ |
37 | ** |
38 | ****************************************************************************/ |
39 | #ifndef QV4STRINGOBJECT_P_H |
40 | #define QV4STRINGOBJECT_P_H |
41 | |
42 | // |
43 | // W A R N I N G |
44 | // ------------- |
45 | // |
46 | // This file is not part of the Qt API. It exists purely as an |
47 | // implementation detail. This header file may change from version to |
48 | // version without notice, or even be removed. |
49 | // |
50 | // We mean it. |
51 | // |
52 | |
53 | #include "qv4object_p.h" |
54 | #include "qv4functionobject_p.h" |
55 | #include <QtCore/qnumeric.h> |
56 | |
57 | QT_BEGIN_NAMESPACE |
58 | |
59 | namespace QV4 { |
60 | |
61 | namespace Heap { |
62 | |
63 | #define StringObjectMembers(class, Member) \ |
64 | Member(class, Pointer, String *, string) |
65 | |
66 | DECLARE_HEAP_OBJECT(StringObject, Object) { |
67 | DECLARE_MARKOBJECTS(StringObject); |
68 | |
69 | enum { |
70 | LengthPropertyIndex = 0 |
71 | }; |
72 | |
73 | void init(bool /*don't init*/) |
74 | { Object::init(); } |
75 | void init(); |
76 | void init(const QV4::String *string); |
77 | |
78 | Heap::String *getIndex(uint index) const; |
79 | uint length() const; |
80 | }; |
81 | |
82 | struct StringCtor : FunctionObject { |
83 | void init(QV4::ExecutionContext *scope); |
84 | }; |
85 | |
86 | } |
87 | |
88 | struct StringObject: Object { |
89 | V4_OBJECT2(StringObject, Object) |
90 | Q_MANAGED_TYPE(StringObject) |
91 | V4_INTERNALCLASS(StringObject) |
92 | V4_PROTOTYPE(stringPrototype) |
93 | |
94 | Heap::String *getIndex(uint index) const { |
95 | return d()->getIndex(index); |
96 | } |
97 | uint length() const { |
98 | return d()->length(); |
99 | } |
100 | |
101 | using Object::getOwnProperty; |
102 | protected: |
103 | static bool virtualDeleteProperty(Managed *m, PropertyKey id); |
104 | static OwnPropertyKeyIterator *virtualOwnPropertyKeys(const Object *m, Value *target); |
105 | static PropertyAttributes virtualGetOwnProperty(const Managed *m, PropertyKey id, Property *p); |
106 | }; |
107 | |
108 | struct StringCtor: FunctionObject |
109 | { |
110 | V4_OBJECT2(StringCtor, FunctionObject) |
111 | |
112 | static ReturnedValue virtualCallAsConstructor(const FunctionObject *f, const Value *argv, int argc, const Value *); |
113 | static ReturnedValue virtualCall(const FunctionObject *, const Value *thisObject, const Value *argv, int argc); |
114 | |
115 | static ReturnedValue method_fromCharCode(const FunctionObject *, const Value *thisObject, const Value *argv, int argc); |
116 | static ReturnedValue method_fromCodePoint(const FunctionObject *, const Value *thisObject, const Value *argv, int argc); |
117 | static ReturnedValue method_raw(const FunctionObject *, const Value *thisObject, const Value *argv, int argc); |
118 | }; |
119 | |
120 | struct StringPrototype: StringObject |
121 | { |
122 | V4_PROTOTYPE(objectPrototype) |
123 | void init(ExecutionEngine *engine, Object *ctor); |
124 | |
125 | static ReturnedValue method_toString(const FunctionObject *, const Value *thisObject, const Value *argv, int argc); |
126 | static ReturnedValue method_charAt(const FunctionObject *, const Value *thisObject, const Value *argv, int argc); |
127 | static ReturnedValue method_charCodeAt(const FunctionObject *, const Value *thisObject, const Value *argv, int argc); |
128 | static ReturnedValue method_codePointAt(const FunctionObject *, const Value *thisObject, const Value *argv, int argc); |
129 | static ReturnedValue method_concat(const FunctionObject *, const Value *thisObject, const Value *argv, int argc); |
130 | static ReturnedValue method_endsWith(const FunctionObject *, const Value *thisObject, const Value *argv, int argc); |
131 | static ReturnedValue method_indexOf(const FunctionObject *, const Value *thisObject, const Value *argv, int argc); |
132 | static ReturnedValue method_includes(const FunctionObject *, const Value *thisObject, const Value *argv, int argc); |
133 | static ReturnedValue method_lastIndexOf(const FunctionObject *, const Value *thisObject, const Value *argv, int argc); |
134 | static ReturnedValue method_localeCompare(const FunctionObject *, const Value *thisObject, const Value *argv, int argc); |
135 | static ReturnedValue method_match(const FunctionObject *, const Value *thisObject, const Value *argv, int argc); |
136 | static ReturnedValue method_normalize(const FunctionObject *, const Value *thisObject, const Value *argv, int argc); |
137 | static ReturnedValue method_padEnd(const FunctionObject *f, const Value *thisObject, const Value *argv, int argc); |
138 | static ReturnedValue method_padStart(const FunctionObject *f, const Value *thisObject, const Value *argv, int argc); |
139 | static ReturnedValue method_repeat(const FunctionObject *, const Value *thisObject, const Value *argv, int argc); |
140 | static ReturnedValue method_replace(const FunctionObject *, const Value *thisObject, const Value *argv, int argc); |
141 | static ReturnedValue method_search(const FunctionObject *, const Value *thisObject, const Value *argv, int argc); |
142 | static ReturnedValue method_slice(const FunctionObject *, const Value *thisObject, const Value *argv, int argc); |
143 | static ReturnedValue method_split(const FunctionObject *, const Value *thisObject, const Value *argv, int argc); |
144 | static ReturnedValue method_startsWith(const FunctionObject *, const Value *thisObject, const Value *argv, int argc); |
145 | static ReturnedValue method_substr(const FunctionObject *, const Value *thisObject, const Value *argv, int argc); |
146 | static ReturnedValue method_substring(const FunctionObject *, const Value *thisObject, const Value *argv, int argc); |
147 | static ReturnedValue method_toLowerCase(const FunctionObject *, const Value *thisObject, const Value *argv, int argc); |
148 | static ReturnedValue method_toLocaleLowerCase(const FunctionObject *, const Value *thisObject, const Value *argv, int argc); |
149 | static ReturnedValue method_toUpperCase(const FunctionObject *, const Value *thisObject, const Value *argv, int argc); |
150 | static ReturnedValue method_toLocaleUpperCase(const FunctionObject *, const Value *thisObject, const Value *argv, int argc); |
151 | static ReturnedValue method_trim(const FunctionObject *, const Value *thisObject, const Value *argv, int argc); |
152 | static ReturnedValue method_iterator(const FunctionObject *, const Value *thisObject, const Value *argv, int argc); |
153 | }; |
154 | |
155 | } |
156 | |
157 | QT_END_NAMESPACE |
158 | |
159 | #endif // QV4ECMAOBJECTS_P_H |
160 | |