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