| 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 |  | 
|---|
| 4 | #ifndef QV4GLOBAL_H | 
|---|
| 5 | #define QV4GLOBAL_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 <QtCore/qglobal.h> | 
|---|
| 19 | #include <private/qv4compilerglobal_p.h> | 
|---|
| 20 | #include <QString> | 
|---|
| 21 |  | 
|---|
| 22 | #include <qtqmlglobal.h> | 
|---|
| 23 | #include <private/qtqmlglobal_p.h> | 
|---|
| 24 |  | 
|---|
| 25 | // Do certain things depending on whether the JIT is enabled or disabled | 
|---|
| 26 |  | 
|---|
| 27 | #if QT_CONFIG(qml_jit) | 
|---|
| 28 | #define ENABLE_YARR_JIT 1 | 
|---|
| 29 | #define ENABLE_JIT 1 | 
|---|
| 30 | #define ENABLE_ASSEMBLER 1 | 
|---|
| 31 | #else | 
|---|
| 32 | #define ENABLE_YARR_JIT 0 | 
|---|
| 33 | #define ENABLE_ASSEMBLER 0 | 
|---|
| 34 | #define ENABLE_JIT 0 | 
|---|
| 35 | #endif | 
|---|
| 36 |  | 
|---|
| 37 | #if defined(Q_OS_QNX) && defined(_CPPLIB_VER) | 
|---|
| 38 | #include <math.h> | 
|---|
| 39 | #undef isnan | 
|---|
| 40 | #undef isfinite | 
|---|
| 41 | #undef isinf | 
|---|
| 42 | #undef signbit | 
|---|
| 43 | #endif | 
|---|
| 44 |  | 
|---|
| 45 | QT_BEGIN_NAMESPACE | 
|---|
| 46 |  | 
|---|
| 47 | namespace QV4 { | 
|---|
| 48 |  | 
|---|
| 49 | namespace Compiler { | 
|---|
| 50 | struct Module; | 
|---|
| 51 | struct Context; | 
|---|
| 52 | struct JSUnitGenerator; | 
|---|
| 53 | class Codegen; | 
|---|
| 54 | } | 
|---|
| 55 |  | 
|---|
| 56 | namespace Moth { | 
|---|
| 57 | class BytecodeGenerator; | 
|---|
| 58 | } | 
|---|
| 59 |  | 
|---|
| 60 | namespace Heap { | 
|---|
| 61 | struct Base; | 
|---|
| 62 | struct MemberData; | 
|---|
| 63 | struct ArrayData; | 
|---|
| 64 |  | 
|---|
| 65 | struct StringOrSymbol; | 
|---|
| 66 | struct String; | 
|---|
| 67 | struct Symbol; | 
|---|
| 68 | struct Object; | 
|---|
| 69 | struct ObjectPrototype; | 
|---|
| 70 |  | 
|---|
| 71 | struct ExecutionContext; | 
|---|
| 72 | struct CallContext; | 
|---|
| 73 | struct QmlContext; | 
|---|
| 74 | struct ScriptFunction; | 
|---|
| 75 | struct InternalClass; | 
|---|
| 76 |  | 
|---|
| 77 | struct BooleanObject; | 
|---|
| 78 | struct NumberObject; | 
|---|
| 79 | struct StringObject; | 
|---|
| 80 | struct ArrayObject; | 
|---|
| 81 | struct DateObject; | 
|---|
| 82 | struct FunctionObject; | 
|---|
| 83 | struct JavaScriptFunctionObject; | 
|---|
| 84 | struct ErrorObject; | 
|---|
| 85 | struct ArgumentsObject; | 
|---|
| 86 | struct QObjectWrapper; | 
|---|
| 87 | struct RegExpObject; | 
|---|
| 88 | struct UrlObject; | 
|---|
| 89 | struct UrlSearchParamsObject; | 
|---|
| 90 | struct RegExp; | 
|---|
| 91 | struct EvalFunction; | 
|---|
| 92 |  | 
|---|
| 93 | struct SharedArrayBuffer; | 
|---|
| 94 | struct ArrayBuffer; | 
|---|
| 95 | struct DataView; | 
|---|
| 96 | struct TypedArray; | 
|---|
| 97 |  | 
|---|
| 98 | struct MapObject; | 
|---|
| 99 | struct SetObject; | 
|---|
| 100 |  | 
|---|
| 101 | struct PromiseObject; | 
|---|
| 102 | struct PromiseCapability; | 
|---|
| 103 |  | 
|---|
| 104 | template <typename T, size_t> struct Pointer; | 
|---|
| 105 | } | 
|---|
| 106 |  | 
|---|
| 107 | struct CppStackFrame; | 
|---|
| 108 | struct JSTypesStackFrame; | 
|---|
| 109 | struct MetaTypesStackFrame; | 
|---|
| 110 | class MemoryManager; | 
|---|
| 111 | class ExecutableAllocator; | 
|---|
| 112 | struct PropertyKey; | 
|---|
| 113 | struct StringOrSymbol; | 
|---|
| 114 | struct String; | 
|---|
| 115 | struct Symbol; | 
|---|
| 116 | struct Object; | 
|---|
| 117 | struct ObjectPrototype; | 
|---|
| 118 | struct ObjectIterator; | 
|---|
| 119 | struct ExecutionContext; | 
|---|
| 120 | struct CallContext; | 
|---|
| 121 | struct QmlContext; | 
|---|
| 122 | struct ScriptFunction; | 
|---|
| 123 | struct InternalClass; | 
|---|
| 124 | struct Property; | 
|---|
| 125 | struct Value; | 
|---|
| 126 | template<size_t> struct HeapValue; | 
|---|
| 127 | template<size_t> struct ValueArray; | 
|---|
| 128 | struct Lookup; | 
|---|
| 129 | struct ArrayData; | 
|---|
| 130 | struct VTable; | 
|---|
| 131 | struct Function; | 
|---|
| 132 |  | 
|---|
| 133 | struct BooleanObject; | 
|---|
| 134 | struct NumberObject; | 
|---|
| 135 | struct StringObject; | 
|---|
| 136 | struct ArrayObject; | 
|---|
| 137 | struct DateObject; | 
|---|
| 138 | struct FunctionObject; | 
|---|
| 139 | struct ErrorObject; | 
|---|
| 140 | struct ArgumentsObject; | 
|---|
| 141 | struct Managed; | 
|---|
| 142 | struct ExecutionEngine; | 
|---|
| 143 | struct QObjectWrapper; | 
|---|
| 144 | struct RegExpObject; | 
|---|
| 145 | struct RegExp; | 
|---|
| 146 | struct EvalFunction; | 
|---|
| 147 |  | 
|---|
| 148 | struct SharedArrayBuffer; | 
|---|
| 149 | struct ArrayBuffer; | 
|---|
| 150 | struct DataView; | 
|---|
| 151 | struct TypedArray; | 
|---|
| 152 |  | 
|---|
| 153 | struct MapObject; | 
|---|
| 154 | struct SetMapObject; | 
|---|
| 155 |  | 
|---|
| 156 | struct PromiseObject; | 
|---|
| 157 | struct PromiseCapability; | 
|---|
| 158 |  | 
|---|
| 159 | struct CallData; | 
|---|
| 160 | struct Scope; | 
|---|
| 161 | struct ScopedValue; | 
|---|
| 162 | template<typename T> struct Scoped; | 
|---|
| 163 | typedef Scoped<String> ScopedString; | 
|---|
| 164 | typedef Scoped<StringOrSymbol> ScopedStringOrSymbol; | 
|---|
| 165 | typedef Scoped<Object> ScopedObject; | 
|---|
| 166 | typedef Scoped<ArrayObject> ScopedArrayObject; | 
|---|
| 167 | typedef Scoped<FunctionObject> ScopedFunctionObject; | 
|---|
| 168 | typedef Scoped<ExecutionContext> ScopedContext; | 
|---|
| 169 |  | 
|---|
| 170 | struct PersistentValueStorage; | 
|---|
| 171 | class PersistentValue; | 
|---|
| 172 | class WeakValue; | 
|---|
| 173 | struct MarkStack; | 
|---|
| 174 |  | 
|---|
| 175 | struct IdentifierTable; | 
|---|
| 176 | class RegExpCache; | 
|---|
| 177 | class MultiplyWrappedQObjectMap; | 
|---|
| 178 |  | 
|---|
| 179 | enum PropertyFlag { | 
|---|
| 180 | Attr_Data = 0, | 
|---|
| 181 | Attr_Accessor = 0x1, | 
|---|
| 182 | Attr_NotWritable = 0x2, | 
|---|
| 183 | Attr_NotEnumerable = 0x4, | 
|---|
| 184 | Attr_NotConfigurable = 0x8, | 
|---|
| 185 | Attr_ReadOnly = Attr_NotWritable|Attr_NotEnumerable|Attr_NotConfigurable, | 
|---|
| 186 | Attr_ReadOnly_ButConfigurable = Attr_NotWritable|Attr_NotEnumerable, | 
|---|
| 187 | Attr_Invalid = 0xff | 
|---|
| 188 | }; | 
|---|
| 189 |  | 
|---|
| 190 | Q_DECLARE_FLAGS(PropertyFlags, PropertyFlag) | 
|---|
| 191 | Q_DECLARE_OPERATORS_FOR_FLAGS(PropertyFlags) | 
|---|
| 192 |  | 
|---|
| 193 | struct PropertyAttributes | 
|---|
| 194 | { | 
|---|
| 195 | QT_WARNING_PUSH | 
|---|
| 196 | QT_WARNING_DISABLE_MSVC(4201) // nonstandard extension used: nameless struct/union | 
|---|
| 197 | union { | 
|---|
| 198 | uchar m_all; | 
|---|
| 199 | struct { | 
|---|
| 200 | uchar m_flags : 4; | 
|---|
| 201 | uchar m_mask : 4; | 
|---|
| 202 | }; | 
|---|
| 203 | struct { | 
|---|
| 204 | uchar m_type : 1; | 
|---|
| 205 | uchar m_writable : 1; | 
|---|
| 206 | uchar m_enumerable : 1; | 
|---|
| 207 | uchar m_configurable : 1; | 
|---|
| 208 | uchar type_set : 1; | 
|---|
| 209 | uchar writable_set : 1; | 
|---|
| 210 | uchar enumerable_set : 1; | 
|---|
| 211 | uchar configurable_set : 1; | 
|---|
| 212 | }; | 
|---|
| 213 | }; | 
|---|
| 214 | QT_WARNING_POP | 
|---|
| 215 |  | 
|---|
| 216 | enum Type { | 
|---|
| 217 | Data = 0, | 
|---|
| 218 | Accessor = 1, | 
|---|
| 219 | Generic = 2 | 
|---|
| 220 | }; | 
|---|
| 221 |  | 
|---|
| 222 | PropertyAttributes() : m_all(0) {} | 
|---|
| 223 | PropertyAttributes(PropertyFlag f) : m_all(0) { | 
|---|
| 224 | if (f != Attr_Invalid) { | 
|---|
| 225 | setType(f & Attr_Accessor ? Accessor : Data); | 
|---|
| 226 | if (!(f & Attr_Accessor)) | 
|---|
| 227 | setWritable(!(f & Attr_NotWritable)); | 
|---|
| 228 | setEnumerable(!(f & Attr_NotEnumerable)); | 
|---|
| 229 | setConfigurable(!(f & Attr_NotConfigurable)); | 
|---|
| 230 | } | 
|---|
| 231 | } | 
|---|
| 232 | PropertyAttributes(PropertyFlags f) : m_all(0) { | 
|---|
| 233 | if (f != Attr_Invalid) { | 
|---|
| 234 | setType(f & Attr_Accessor ? Accessor : Data); | 
|---|
| 235 | if (!(f & Attr_Accessor)) | 
|---|
| 236 | setWritable(!(f & Attr_NotWritable)); | 
|---|
| 237 | setEnumerable(!(f & Attr_NotEnumerable)); | 
|---|
| 238 | setConfigurable(!(f & Attr_NotConfigurable)); | 
|---|
| 239 | } | 
|---|
| 240 | } | 
|---|
| 241 |  | 
|---|
| 242 | void setType(Type t) { m_type = t; type_set = true; } | 
|---|
| 243 | Type type() const { return type_set ? (Type)m_type : Generic; } | 
|---|
| 244 |  | 
|---|
| 245 | bool isData() const { return type() == PropertyAttributes::Data || writable_set; } | 
|---|
| 246 | bool isAccessor() const { return type() == PropertyAttributes::Accessor; } | 
|---|
| 247 | bool isGeneric() const { return type() == PropertyAttributes::Generic && !writable_set; } | 
|---|
| 248 |  | 
|---|
| 249 | bool hasType() const { return type_set; } | 
|---|
| 250 | bool hasWritable() const { return writable_set; } | 
|---|
| 251 | bool hasConfigurable() const { return configurable_set; } | 
|---|
| 252 | bool hasEnumerable() const { return enumerable_set; } | 
|---|
| 253 |  | 
|---|
| 254 | void setWritable(bool b) { m_writable = b; writable_set = true; } | 
|---|
| 255 | void setConfigurable(bool b) { m_configurable = b; configurable_set = true; } | 
|---|
| 256 | void setEnumerable(bool b) { m_enumerable = b; enumerable_set = true; } | 
|---|
| 257 |  | 
|---|
| 258 | void resolve() { m_mask = 0xf; if (m_type == Accessor) { m_writable = false; writable_set = false; } } | 
|---|
| 259 |  | 
|---|
| 260 | bool isWritable() const { return m_type != Data || m_writable; } | 
|---|
| 261 | bool isEnumerable() const { return m_enumerable; } | 
|---|
| 262 | bool isConfigurable() const { return m_configurable; } | 
|---|
| 263 |  | 
|---|
| 264 | void clearType() { m_type = Data; type_set = false; } | 
|---|
| 265 | void clearWritable() { m_writable = false; writable_set = false; } | 
|---|
| 266 | void clearEnumerable() { m_enumerable = false; enumerable_set = false; } | 
|---|
| 267 | void clearConfigurable() { m_configurable = false; configurable_set = false; } | 
|---|
| 268 |  | 
|---|
| 269 | void clear() { m_all = 0; } | 
|---|
| 270 | bool isEmpty() const { return !m_all; } | 
|---|
| 271 |  | 
|---|
| 272 | uint all() const { return m_all; } | 
|---|
| 273 |  | 
|---|
| 274 | bool operator==(PropertyAttributes other) { | 
|---|
| 275 | return m_all == other.m_all; | 
|---|
| 276 | } | 
|---|
| 277 | bool operator!=(PropertyAttributes other) { | 
|---|
| 278 | return m_all != other.m_all; | 
|---|
| 279 | } | 
|---|
| 280 | }; | 
|---|
| 281 |  | 
|---|
| 282 | struct Q_QML_EXPORT StackFrame { | 
|---|
| 283 | QString source; | 
|---|
| 284 | QString function; | 
|---|
| 285 | int line = -1; | 
|---|
| 286 | int column = -1; | 
|---|
| 287 | }; | 
|---|
| 288 | typedef QVector<StackFrame> StackTrace; | 
|---|
| 289 |  | 
|---|
| 290 | namespace JIT { | 
|---|
| 291 |  | 
|---|
| 292 | enum class CallResultDestination { | 
|---|
| 293 | Ignore, | 
|---|
| 294 | InAccumulator, | 
|---|
| 295 | }; | 
|---|
| 296 |  | 
|---|
| 297 | } // JIT namespace | 
|---|
| 298 |  | 
|---|
| 299 | } // QV4 namespace | 
|---|
| 300 |  | 
|---|
| 301 | Q_DECLARE_TYPEINFO(QV4::PropertyAttributes, Q_PRIMITIVE_TYPE); | 
|---|
| 302 |  | 
|---|
| 303 | QT_END_NAMESPACE | 
|---|
| 304 |  | 
|---|
| 305 | #endif // QV4GLOBAL_H | 
|---|
| 306 |  | 
|---|