Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qv4regexpobject_p.h
Go to the documentation of this file.
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// Qt-Security score:significant
4#ifndef QV4REGEXPOBJECT_H
5#define QV4REGEXPOBJECT_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <private/qv4context_p.h>
19#include <private/qv4engine_p.h>
20#include <private/qv4functionobject_p.h>
21#include <private/qv4managed_p.h>
22
23#include <QtCore/qhash.h>
24#include <QtCore/qstring.h>
25
26QT_BEGIN_NAMESPACE
27
28namespace QV4 {
29
30namespace Heap {
31
32#define RegExpObjectMembers(class, Member)
33 Member(class, Pointer, RegExp *, value)
34
36 DECLARE_MARKOBJECTS(RegExpObject)
37
38 void init();
39 void init(QV4::RegExp *value);
40#if QT_CONFIG(regularexpression)
41 void init(const QRegularExpression &re);
42#endif
43};
44
45#define RegExpCtorMembers(class, Member)
46 Member(class, HeapValue, HeapValue, lastMatch)
47 Member(class, Pointer, String *, lastInput)
48 Member(class, NoMark, int, lastMatchStart)
49 Member(class, NoMark, int, lastMatchEnd)
50
52 DECLARE_MARKOBJECTS(RegExpCtor)
53
54 void init(ExecutionEngine *engine);
55 void clearLastMatch();
56};
57
58}
59
60struct Q_QML_EXPORT RegExpObject: Object {
65
66 // needs to be compatible with the flags in qv4compileddata_p.h
74
75 enum {
77 Index_ArrayIndex = Heap::ArrayObject::LengthPropertyIndex + 1,
79 };
80
81 enum { NInlineProperties = 5 };
82
83
84 void initProperties();
85
86 int lastIndex() const {
87 Q_ASSERT(internalClass()->verifyIndex(engine()->id_lastIndex()->propertyKey(), Index_LastIndex));
88 return propertyData(Index_LastIndex)->toInt32();
89 }
90 void setLastIndex(int index) {
91 Q_ASSERT(internalClass()->verifyIndex(engine()->id_lastIndex()->propertyKey(), Index_LastIndex));
92 if (!internalClass()->propertyData[Index_LastIndex].isWritable()) {
93 engine()->throwTypeError();
94 return;
95 }
96 return setProperty(Index_LastIndex, Value::fromInt32(index));
97 }
98
99#if QT_CONFIG(regularexpression)
101#endif
102 QString toString() const;
104 {
105 Scope scope(engine());
106 ScopedValue s(scope, get(scope.engine->id_source()));
107 return s->toQString();
108 }
109
110 // We cannot name Heap::RegExp here since we don't want to include qv4regexp_p.h but we still
111 // want to keep the methods inline. We shift the requirement to name the type to the caller by
112 // making it a template.
113 template<typename RegExp = Heap::RegExp>
114 RegExp *value() const { return d()->value; }
115 template<typename RegExp = Heap::RegExp>
116 uint flags() const { return value<RegExp>()->flags; }
117 template<typename RegExp = Heap::RegExp>
118 bool global() const { return value<RegExp>()->global(); }
119 template<typename RegExp = Heap::RegExp>
120 bool sticky() const { return value<RegExp>()->sticky(); }
121 template<typename RegExp = Heap::RegExp>
122 bool unicode() const { return value<RegExp>()->unicode(); }
123
124 ReturnedValue builtinExec(ExecutionEngine *engine, const String *s);
125};
126
128{
129 V4_OBJECT2(RegExpCtor, FunctionObject)
130
131 Value lastMatch() { return d()->lastMatch; }
132 Heap::String *lastInput() { return d()->lastInput; }
133 int lastMatchStart() { return d()->lastMatchStart; }
134 int lastMatchEnd() { return d()->lastMatchEnd; }
135
136 static ReturnedValue virtualCallAsConstructor(const FunctionObject *f, const Value *argv, int argc, const Value *);
137 static ReturnedValue virtualCall(const FunctionObject *f, const Value *thisObject, const Value *argv, int argc);
138};
139
141{
142 void init(ExecutionEngine *engine, Object *ctor);
143
144 static ReturnedValue method_exec(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
145 static ReturnedValue method_get_flags(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
146 static ReturnedValue method_get_global(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
147 static ReturnedValue method_get_ignoreCase(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
148 static ReturnedValue method_match(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
149 static ReturnedValue method_get_multiline(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
150 static ReturnedValue method_replace(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
151 static ReturnedValue method_search(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
152 static ReturnedValue method_get_source(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
153 static ReturnedValue method_split(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
154 static ReturnedValue method_get_sticky(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
155 static ReturnedValue method_test(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
156 static ReturnedValue method_toString(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
157 static ReturnedValue method_get_unicode(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
158
159 // Web extension
160 static ReturnedValue method_compile(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
161
162 // properties on the constructor, web extensions
163 template <uint index>
164 static ReturnedValue method_get_lastMatch_n(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
165 static ReturnedValue method_get_lastParen(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
166 static ReturnedValue method_get_input(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
167 static ReturnedValue method_get_leftContext(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
168 static ReturnedValue method_get_rightContext(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
169
170 static ReturnedValue execFirstMatch(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc);
171
172 static ReturnedValue exec(ExecutionEngine *engine, const Object *o, const String *s);
173};
174
175}
176
177QT_END_NAMESPACE
178
179#endif // QMLJS_OBJECTS_H
DECLARE_HEAP_OBJECT(QmlContext, ExecutionContext)
Definition qjsvalue.h:23
static CompiledData::RegExp::Flags parseFlags(Scope &scope, const QV4::Value *f)
DEFINE_OBJECT_VTABLE(RegExpCtor)
static int advanceStringIndex(int index, const QString &str, bool unicode)
DEFINE_OBJECT_VTABLE(RegExpObject)
static bool isRegExp(ExecutionEngine *e, const QV4::Value *arg)
static QString minimalPattern(const QString &pattern)
static void advanceLastIndexOnEmptyMatch(ExecutionEngine *e, bool unicode, QV4::Object *rx, const String *matchString, const QString &str)
#define RETURN_UNDEFINED()
#define RETURN_RESULT(r)
static ReturnedValue virtualCall(const FunctionObject *f, const Value *thisObject, const Value *argv, int argc)
ReturnedValue builtinExec(ExecutionEngine *engine, const String *s)
QString toString() const
QString source() const
RegExp * value() const
void setLastIndex(int index)
static ReturnedValue method_get_leftContext(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_compile(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue execFirstMatch(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_get_sticky(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_get_unicode(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_get_flags(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_get_source(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_get_lastMatch_n(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_split(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_match(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_toString(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_get_multiline(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
void init(ExecutionEngine *engine, Object *ctor)
static ReturnedValue method_exec(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_search(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_get_input(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_get_rightContext(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_get_lastParen(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_replace(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_test(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue exec(ExecutionEngine *engine, const Object *o, const String *s)
static ReturnedValue method_get_ignoreCase(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_get_global(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)