Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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#ifndef QV4REGEXPOBJECT_H
4#define QV4REGEXPOBJECT_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 <private/qv4context_p.h>
18#include <private/qv4engine_p.h>
19#include <private/qv4functionobject_p.h>
20#include <private/qv4managed_p.h>
21
22#include <QtCore/qhash.h>
23#include <QtCore/qstring.h>
24
26
27namespace QV4 {
28
29namespace Heap {
30
31#define RegExpObjectMembers(class, Member) \
32 Member(class, Pointer, RegExp *, value)
33
36
37 void init();
38 void init(QV4::RegExp *value);
39#if QT_CONFIG(regularexpression)
40 void init(const QRegularExpression &re);
41#endif
42};
43
44#define RegExpCtorMembers(class, Member) \
45 Member(class, HeapValue, HeapValue, lastMatch) \
46 Member(class, Pointer, String *, lastInput) \
47 Member(class, NoMark, int, lastMatchStart) \
48 Member(class, NoMark, int, lastMatchEnd)
49
56
57}
58
59struct Q_QML_EXPORT RegExpObject: Object {
63 V4_PROTOTYPE(regExpPrototype)
64
65 // needs to be compatible with the flags in qv4compileddata_p.h
66 enum Flags {
67 RegExp_Global = 0x01,
68 RegExp_IgnoreCase = 0x02,
69 RegExp_Multiline = 0x04,
70 RegExp_Unicode = 0x08,
71 RegExp_Sticky = 0x10
72 };
73
74 enum {
75 Index_LastIndex = 0,
76 Index_ArrayIndex = Heap::ArrayObject::LengthPropertyIndex + 1,
77 Index_ArrayInput = Index_ArrayIndex + 1
78 };
79
80 enum { NInlineProperties = 5 };
81
82
83 void initProperties();
84
85 int lastIndex() const {
86 Q_ASSERT(internalClass()->verifyIndex(engine()->id_lastIndex()->propertyKey(), Index_LastIndex));
87 return propertyData(Index_LastIndex)->toInt32();
88 }
89 void setLastIndex(int index) {
90 Q_ASSERT(internalClass()->verifyIndex(engine()->id_lastIndex()->propertyKey(), Index_LastIndex));
91 if (!internalClass()->propertyData[Index_LastIndex].isWritable()) {
92 engine()->throwTypeError();
93 return;
94 }
95 return setProperty(Index_LastIndex, Value::fromInt32(index));
96 }
97
98#if QT_CONFIG(regularexpression)
99 QRegularExpression toQRegularExpression() const;
100#endif
101 QString toString() const;
103 {
104 Scope scope(engine());
105 ScopedValue s(scope, get(scope.engine->id_source()));
106 return s->toQString();
107 }
108
109 // We cannot name Heap::RegExp here since we don't want to include qv4regexp_p.h but we still
110 // want to keep the methods inline. We shift the requirement to name the type to the caller by
111 // making it a template.
112 template<typename RegExp = Heap::RegExp>
113 RegExp *value() const { return d()->value; }
114 template<typename RegExp = Heap::RegExp>
115 uint flags() const { return value<RegExp>()->flags; }
116 template<typename RegExp = Heap::RegExp>
117 bool global() const { return value<RegExp>()->global(); }
118 template<typename RegExp = Heap::RegExp>
119 bool sticky() const { return value<RegExp>()->sticky(); }
120 template<typename RegExp = Heap::RegExp>
121 bool unicode() const { return value<RegExp>()->unicode(); }
122
123 ReturnedValue builtinExec(ExecutionEngine *engine, const String *s);
124};
125
127{
129
130 Value lastMatch() { return d()->lastMatch; }
131 Heap::String *lastInput() { return d()->lastInput; }
132 int lastMatchStart() { return d()->lastMatchStart; }
133 int lastMatchEnd() { return d()->lastMatchEnd; }
134
135 static ReturnedValue virtualCallAsConstructor(const FunctionObject *f, const Value *argv, int argc, const Value *);
136 static ReturnedValue virtualCall(const FunctionObject *f, const Value *thisObject, const Value *argv, int argc);
137};
138
140{
141 void init(ExecutionEngine *engine, Object *ctor);
142
143 static ReturnedValue method_exec(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
144 static ReturnedValue method_get_flags(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
145 static ReturnedValue method_get_global(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
146 static ReturnedValue method_get_ignoreCase(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
147 static ReturnedValue method_match(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
148 static ReturnedValue method_get_multiline(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
149 static ReturnedValue method_replace(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
150 static ReturnedValue method_search(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
151 static ReturnedValue method_get_source(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
152 static ReturnedValue method_split(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
153 static ReturnedValue method_get_sticky(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
154 static ReturnedValue method_test(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
155 static ReturnedValue method_toString(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
156 static ReturnedValue method_get_unicode(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
157
158 // Web extension
159 static ReturnedValue method_compile(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
160
161 // properties on the constructor, web extensions
162 template <uint index>
163 static ReturnedValue method_get_lastMatch_n(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
164 static ReturnedValue method_get_lastParen(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
165 static ReturnedValue method_get_input(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
166 static ReturnedValue method_get_leftContext(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
167 static ReturnedValue method_get_rightContext(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
168
169 static ReturnedValue execFirstMatch(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc);
170
171 static ReturnedValue exec(ExecutionEngine *engine, const Object *o, const String *s);
172};
173
174}
175
177
178#endif // QMLJS_OBJECTS_H
\inmodule QtCore \reentrant
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
Combined button and popup list for selecting options.
quint64 ReturnedValue
static QDBusError::ErrorType get(const char *name)
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
GLboolean GLboolean GLboolean b
GLuint index
[2]
GLfloat GLfloat f
GLdouble s
[6]
Definition qopenglext.h:235
static bool initProperties(QQuickStackElement *element, const QV4::Value &props, QQmlV4FunctionPtr args)
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
static QT_BEGIN_NAMESPACE void init(QTextBoundaryFinder::BoundaryType type, QStringView str, QCharAttributes *attributes)
unsigned int uint
Definition qtypes.h:34
#define Q_MANAGED_TYPE(type)
#define V4_INTERNALCLASS(c)
#define DECLARE_HEAP_OBJECT(name, base)
#define DECLARE_MARKOBJECTS(class)
#define V4_PROTOTYPE(p)
#define V4_OBJECT2(DataClass, superClass)
dialog exec()
char * toString(const MyType &t)
[31]
args<< 1<< 2;QJSValue threeAgain=fun.call(args);QString fileName="helloworld.qs";QFile scriptFile(fileName);if(!scriptFile.open(QIODevice::ReadOnly)) QTextStream stream(&scriptFile);QString contents=stream.readAll();scriptFile.close();myEngine.evaluate(contents, fileName);myEngine.globalObject().setProperty("myNumber", 123);...QJSValue myNumberPlusOne=myEngine.evaluate("myNumber + 1");QJSValue result=myEngine.evaluate(...);if(result.isError()) qDebug()<< "Uncaught exception at line"<< result.property("lineNumber").toInt()<< ":"<< result.toString();QPushButton *button=new QPushButton;QJSValue scriptButton=myEngine.newQObject(button);myEngine.globalObject().setProperty("button", scriptButton);myEngine.evaluate("button.checkable = true");qDebug()<< scriptButton.property("checkable").toBool();scriptButton.property("show").call();QJSEngine engine;QObject *myQObject=new QObject();myQObject- setProperty)("dynamicProperty", 3)
QJSEngine engine
[0]
String * id_source() const
ExecutionEngine * engine() const
Heap::String * lastInput()
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 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)
ExecutionEngine * engine
QV4_NEARLY_ALWAYS_INLINE constexpr quint32 value() const
static constexpr VTable::CallAsConstructor virtualCallAsConstructor
static constexpr VTable::Call virtualCall