| 1 | /**************************************************************************** | 
|---|
| 2 | ** | 
|---|
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). | 
|---|
| 4 | ** Contact: Qt Software Information (qt-info@nokia.com) | 
|---|
| 5 | ** | 
|---|
| 6 | ** This file is part of the QtScript module of the Qt Toolkit. | 
|---|
| 7 | ** | 
|---|
| 8 | ** $QT_BEGIN_LICENSE:LGPL$ | 
|---|
| 9 | ** Commercial Usage | 
|---|
| 10 | ** Licensees holding valid Qt Commercial licenses may use this file in | 
|---|
| 11 | ** accordance with the Qt Commercial License Agreement provided with the | 
|---|
| 12 | ** Software or, alternatively, in accordance with the terms contained in | 
|---|
| 13 | ** a written agreement between you and Nokia. | 
|---|
| 14 | ** | 
|---|
| 15 | ** GNU Lesser General Public License Usage | 
|---|
| 16 | ** Alternatively, this file may be used under the terms of the GNU Lesser | 
|---|
| 17 | ** General Public License version 2.1 as published by the Free Software | 
|---|
| 18 | ** Foundation and appearing in the file LICENSE.LGPL included in the | 
|---|
| 19 | ** packaging of this file.  Please review the following information to | 
|---|
| 20 | ** ensure the GNU Lesser General Public License version 2.1 requirements | 
|---|
| 21 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | 
|---|
| 22 | ** | 
|---|
| 23 | ** In addition, as a special exception, Nokia gives you certain | 
|---|
| 24 | ** additional rights. These rights are described in the Nokia Qt LGPL | 
|---|
| 25 | ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this | 
|---|
| 26 | ** package. | 
|---|
| 27 | ** | 
|---|
| 28 | ** GNU General Public License Usage | 
|---|
| 29 | ** Alternatively, this file may be used under the terms of the GNU | 
|---|
| 30 | ** General Public License version 3.0 as published by the Free Software | 
|---|
| 31 | ** Foundation and appearing in the file LICENSE.GPL included in the | 
|---|
| 32 | ** packaging of this file.  Please review the following information to | 
|---|
| 33 | ** ensure the GNU General Public License version 3.0 requirements will be | 
|---|
| 34 | ** met: http://www.gnu.org/copyleft/gpl.html. | 
|---|
| 35 | ** | 
|---|
| 36 | ** If you are unsure which license is appropriate for your use, please | 
|---|
| 37 | ** contact the sales department at qt-sales@nokia.com. | 
|---|
| 38 | ** $QT_END_LICENSE$ | 
|---|
| 39 | ** | 
|---|
| 40 | ****************************************************************************/ | 
|---|
| 41 |  | 
|---|
| 42 | #ifndef QSCRIPTCONTEXTFWD_P_H | 
|---|
| 43 | #define QSCRIPTCONTEXTFWD_P_H | 
|---|
| 44 |  | 
|---|
| 45 | // | 
|---|
| 46 | //  W A R N I N G | 
|---|
| 47 | //  ------------- | 
|---|
| 48 | // | 
|---|
| 49 | // This file is not part of the Qt API.  It exists purely as an | 
|---|
| 50 | // implementation detail.  This header file may change from version to | 
|---|
| 51 | // version without notice, or even be removed. | 
|---|
| 52 | // | 
|---|
| 53 | // We mean it. | 
|---|
| 54 | // | 
|---|
| 55 |  | 
|---|
| 56 | #include "qscriptvalueimplfwd_p.h" | 
|---|
| 57 |  | 
|---|
| 58 | #ifndef QT_NO_SCRIPT | 
|---|
| 59 |  | 
|---|
| 60 | #include "qscriptcontext.h" | 
|---|
| 61 |  | 
|---|
| 62 | #include <QtCore/qobjectdefs.h> | 
|---|
| 63 |  | 
|---|
| 64 | #if defined Q_CC_MSVC && !defined Q_CC_MSVC_NET | 
|---|
| 65 | #include <QtCore/qnumeric.h> | 
|---|
| 66 | #endif | 
|---|
| 67 |  | 
|---|
| 68 | QT_BEGIN_NAMESPACE | 
|---|
| 69 |  | 
|---|
| 70 | namespace QScript { | 
|---|
| 71 | namespace AST { | 
|---|
| 72 | class Node; | 
|---|
| 73 | } | 
|---|
| 74 | class Code; | 
|---|
| 75 | } | 
|---|
| 76 |  | 
|---|
| 77 | class QScriptInstruction; | 
|---|
| 78 |  | 
|---|
| 79 | class QScriptContextPrivate | 
|---|
| 80 | { | 
|---|
| 81 | Q_DECLARE_PUBLIC(QScriptContext) | 
|---|
| 82 | public: | 
|---|
| 83 | inline QScriptContextPrivate(); | 
|---|
| 84 |  | 
|---|
| 85 | static inline QScriptContextPrivate *get(QScriptContext *q); | 
|---|
| 86 | static inline const QScriptContextPrivate *get(const QScriptContext *q); | 
|---|
| 87 | static QScriptContext *get(QScriptContextPrivate *d); | 
|---|
| 88 |  | 
|---|
| 89 | static inline QScriptContext *create(); | 
|---|
| 90 |  | 
|---|
| 91 | inline QScriptEnginePrivate *engine() const; | 
|---|
| 92 | inline QScriptContextPrivate *parentContext() const; | 
|---|
| 93 |  | 
|---|
| 94 | inline void init(QScriptContextPrivate *parent); | 
|---|
| 95 | inline QScriptValueImpl argument(int index) const; | 
|---|
| 96 | inline int argumentCount() const; | 
|---|
| 97 | inline QScriptValueImpl argumentsObject() const; | 
|---|
| 98 |  | 
|---|
| 99 | inline void throwException(); | 
|---|
| 100 | inline bool hasUncaughtException() const; | 
|---|
| 101 | const QScriptInstruction *findExceptionHandler(const QScriptInstruction *ip) const; | 
|---|
| 102 | const QScriptInstruction *findExceptionHandlerRecursive( | 
|---|
| 103 | const QScriptInstruction *ip, QScriptContextPrivate **handlerContext) const; | 
|---|
| 104 | QScriptContextPrivate *exceptionHandlerContext() const; | 
|---|
| 105 | inline void recover(); | 
|---|
| 106 | QStringList backtrace() const; | 
|---|
| 107 |  | 
|---|
| 108 | static inline bool isNumerical(const QScriptValueImpl &v); | 
|---|
| 109 |  | 
|---|
| 110 | static inline bool eq_cmp(const QScriptValueImpl &lhs, const QScriptValueImpl &rhs); | 
|---|
| 111 |  | 
|---|
| 112 | static bool eq_cmp_helper(QScriptValueImpl lhs, QScriptValueImpl rhs); | 
|---|
| 113 |  | 
|---|
| 114 | #if defined(Q_CC_GNU) && __GNUC__ <= 3 | 
|---|
| 115 | static bool lt_cmp(QScriptValueImpl lhs, QScriptValueImpl rhs); | 
|---|
| 116 | #else | 
|---|
| 117 | static bool lt_cmp(const QScriptValueImpl &lhs, const QScriptValueImpl &rhs) | 
|---|
| 118 | { | 
|---|
| 119 | if (lhs.type() == rhs.type()) { | 
|---|
| 120 | switch (lhs.type()) { | 
|---|
| 121 | case QScript::UndefinedType: | 
|---|
| 122 | case QScript::NullType: | 
|---|
| 123 | return false; | 
|---|
| 124 |  | 
|---|
| 125 | case QScript::NumberType: | 
|---|
| 126 | #if defined Q_CC_MSVC && !defined Q_CC_MSVC_NET | 
|---|
| 127 | if (qIsNaN(lhs.m_number_value) || qIsNaN(rhs.m_number_value)) | 
|---|
| 128 | return false; | 
|---|
| 129 | #endif | 
|---|
| 130 | return lhs.m_number_value < rhs.m_number_value; | 
|---|
| 131 |  | 
|---|
| 132 | case QScript::IntegerType: | 
|---|
| 133 | return lhs.m_int_value < rhs.m_int_value; | 
|---|
| 134 |  | 
|---|
| 135 | case QScript::BooleanType: | 
|---|
| 136 | return lhs.m_bool_value < rhs.m_bool_value; | 
|---|
| 137 |  | 
|---|
| 138 | default: | 
|---|
| 139 | break; | 
|---|
| 140 | } // switch | 
|---|
| 141 | } | 
|---|
| 142 |  | 
|---|
| 143 | return lt_cmp_helper(lhs, rhs); | 
|---|
| 144 | } | 
|---|
| 145 |  | 
|---|
| 146 | static bool lt_cmp_helper(QScriptValueImpl lhs, QScriptValueImpl rhs); | 
|---|
| 147 | #endif | 
|---|
| 148 |  | 
|---|
| 149 | static bool le_cmp(const QScriptValueImpl &lhs, const QScriptValueImpl &rhs) | 
|---|
| 150 | { | 
|---|
| 151 | if (lhs.type() == rhs.type()) { | 
|---|
| 152 | switch (lhs.type()) { | 
|---|
| 153 | case QScript::UndefinedType: | 
|---|
| 154 | case QScript::NullType: | 
|---|
| 155 | return true; | 
|---|
| 156 |  | 
|---|
| 157 | case QScript::NumberType: | 
|---|
| 158 | return lhs.m_number_value <= rhs.m_number_value; | 
|---|
| 159 |  | 
|---|
| 160 | case QScript::IntegerType: | 
|---|
| 161 | return lhs.m_int_value <= rhs.m_int_value; | 
|---|
| 162 |  | 
|---|
| 163 | case QScript::BooleanType: | 
|---|
| 164 | return lhs.m_bool_value <= rhs.m_bool_value; | 
|---|
| 165 |  | 
|---|
| 166 | default: | 
|---|
| 167 | break; | 
|---|
| 168 | } // switch | 
|---|
| 169 | } | 
|---|
| 170 |  | 
|---|
| 171 | return le_cmp_helper(lhs, rhs); | 
|---|
| 172 | } | 
|---|
| 173 |  | 
|---|
| 174 | static bool le_cmp_helper(QScriptValueImpl lhs, QScriptValueImpl rhs); | 
|---|
| 175 |  | 
|---|
| 176 | static inline bool strict_eq_cmp(const QScriptValueImpl &lhs, const QScriptValueImpl &rhs); | 
|---|
| 177 |  | 
|---|
| 178 | bool resolveField(QScriptEnginePrivate *eng, QScriptValueImpl *stackPtr, | 
|---|
| 179 | QScriptValueImpl *value); | 
|---|
| 180 |  | 
|---|
| 181 | void execute(QScript::Code *code); | 
|---|
| 182 |  | 
|---|
| 183 | QScriptValueImpl throwError(QScriptContext::Error error, const QString &text); | 
|---|
| 184 | QScriptValueImpl throwError(const QString &text); | 
|---|
| 185 |  | 
|---|
| 186 | #ifndef Q_SCRIPT_NO_EVENT_NOTIFY | 
|---|
| 187 | qint64 scriptId() const; | 
|---|
| 188 | #endif | 
|---|
| 189 | QString fileName() const; | 
|---|
| 190 | QString functionName() const; | 
|---|
| 191 | void setDebugInformation(QScriptValueImpl *error) const; | 
|---|
| 192 |  | 
|---|
| 193 | QScriptValueImpl throwNotImplemented(const QString &name); | 
|---|
| 194 | QScriptValueImpl throwNotDefined(const QString &name); | 
|---|
| 195 | QScriptValueImpl throwNotDefined(QScriptNameIdImpl *nameId); | 
|---|
| 196 |  | 
|---|
| 197 | inline QScriptValueImpl throwTypeError(const QString &text); | 
|---|
| 198 | inline QScriptValueImpl throwSyntaxError(const QString &text); | 
|---|
| 199 |  | 
|---|
| 200 | inline QScriptValueImpl thisObject() const; | 
|---|
| 201 | inline void setThisObject(const QScriptValueImpl &object); | 
|---|
| 202 |  | 
|---|
| 203 | inline QScriptValueImpl callee() const; | 
|---|
| 204 | inline bool isCalledAsConstructor() const; | 
|---|
| 205 |  | 
|---|
| 206 | inline QScriptValueImpl returnValue() const; | 
|---|
| 207 | inline void setReturnValue(const QScriptValueImpl &value); | 
|---|
| 208 |  | 
|---|
| 209 | inline QScriptValueImpl activationObject() const; | 
|---|
| 210 | inline void setActivationObject(const QScriptValueImpl &activation); | 
|---|
| 211 |  | 
|---|
| 212 | inline const QScriptInstruction *instructionPointer(); | 
|---|
| 213 | inline void setInstructionPointer(const QScriptInstruction *instructionPointer); | 
|---|
| 214 |  | 
|---|
| 215 | inline const QScriptValueImpl *baseStackPointer() const; | 
|---|
| 216 | inline const QScriptValueImpl *currentStackPointer() const; | 
|---|
| 217 |  | 
|---|
| 218 | inline QScriptContext::ExecutionState state() const; | 
|---|
| 219 |  | 
|---|
| 220 | public: | 
|---|
| 221 | QScriptContextPrivate *previous; | 
|---|
| 222 | int argc; | 
|---|
| 223 | QScriptContext::ExecutionState m_state; | 
|---|
| 224 |  | 
|---|
| 225 | QScriptValueImpl m_activation; | 
|---|
| 226 | QScriptValueImpl m_thisObject; | 
|---|
| 227 | QScriptValueImpl m_result; | 
|---|
| 228 | QScriptValueImpl m_scopeChain; | 
|---|
| 229 | QScriptValueImpl m_callee; | 
|---|
| 230 | QScriptValueImpl m_arguments; | 
|---|
| 231 |  | 
|---|
| 232 | QScriptValueImpl *args; | 
|---|
| 233 | QScriptValueImpl *tempStack; | 
|---|
| 234 | QScriptValueImpl *stackPtr; | 
|---|
| 235 |  | 
|---|
| 236 | QScript::Code *m_code; | 
|---|
| 237 | const QScriptInstruction *iPtr; | 
|---|
| 238 | const QScriptInstruction *firstInstruction; | 
|---|
| 239 | const QScriptInstruction *lastInstruction; | 
|---|
| 240 |  | 
|---|
| 241 | int currentLine; | 
|---|
| 242 | int currentColumn; | 
|---|
| 243 |  | 
|---|
| 244 | int errorLineNumber; | 
|---|
| 245 |  | 
|---|
| 246 | bool catching; | 
|---|
| 247 | bool m_calledAsConstructor; | 
|---|
| 248 |  | 
|---|
| 249 | int calleeMetaIndex; | 
|---|
| 250 |  | 
|---|
| 251 | QScriptContext *q_ptr; | 
|---|
| 252 | }; | 
|---|
| 253 |  | 
|---|
| 254 | QT_END_NAMESPACE | 
|---|
| 255 |  | 
|---|
| 256 | #endif // QT_NO_SCRIPT | 
|---|
| 257 | #endif | 
|---|