/**************************************************************************** ** ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal ** ** This file is part of the QtScript module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** Commercial License Usage ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in ** a written agreement between you and Digia. For licensing terms and ** conditions see http://qt.digia.com/licensing. For further information ** use the contact form at http://qt.digia.com/contact-us. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser ** General Public License version 2.1 as published by the Free Software ** Foundation and appearing in the file LICENSE.LGPL included in the ** packaging of this file. Please review the following information to ** ensure the GNU Lesser General Public License version 2.1 requirements ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. ** ** In addition, as a special exception, Digia gives you certain additional ** rights. These rights are described in the Digia Qt LGPL Exception ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. ** ** GNU General Public License Usage ** Alternatively, this file may be used under the terms of the GNU ** General Public License version 3.0 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. Please review the following information to ** ensure the GNU General Public License version 3.0 requirements will be ** met: http://www.gnu.org/copyleft/gpl.html. ** ** ** $QT_END_LICENSE$ ** ****************************************************************************/ #ifndef QSCRIPTENGINEFWD_P_H #define QSCRIPTENGINEFWD_P_H #ifndef QT_NO_QOBJECT #include "private/qobject_p.h" #endif #ifndef QT_NO_SCRIPT #include #include #include #include #include #include #include #include #include "qscriptengine.h" #include "qscriptrepository_p.h" #include "qscriptgc_p.h" #include "qscriptobjectfwd_p.h" #include "qscriptclassinfo_p.h" #include "qscriptstring_p.h" QT_BEGIN_NAMESPACE // // W A R N I N G // ------------- // // This file is not part of the Qt API. It exists purely as an // implementation detail. This header file may change from version to // version without notice, or even be removed. // // We mean it. // class QScriptClass; class QScriptContext; namespace QScript { namespace AST { class Node; } // namespace AST namespace Ecma { class Object; class Number; class Boolean; class String; class Math; class Date; class Function; class Array; class RegExp; class Error; } // namespace Ecma namespace Ext { class Enumeration; class Variant; } // namespace Ext class ExtQObject; class ExtQMetaObject; class Array; class Lexer; class Code; class CompilationUnit; class IdTable; class MemoryPool; class IdTable { public: inline IdTable() : id_constructor(0), id_false(0), id_null(0), id_object(0), id_pointer(0), id_prototype(0), id_arguments(0), id_this(0), id_toString(0), id_true(0), id_undefined(0), id_valueOf(0), id_length(0), id_callee(0), id___proto__(0), id___qt_sender__(0) {} QScriptNameIdImpl *id_constructor; QScriptNameIdImpl *id_false; QScriptNameIdImpl *id_null; QScriptNameIdImpl *id_object; QScriptNameIdImpl *id_pointer; QScriptNameIdImpl *id_prototype; QScriptNameIdImpl *id_arguments; QScriptNameIdImpl *id_this; QScriptNameIdImpl *id_toString; QScriptNameIdImpl *id_true; QScriptNameIdImpl *id_undefined; QScriptNameIdImpl *id_valueOf; QScriptNameIdImpl *id_length; QScriptNameIdImpl *id_callee; QScriptNameIdImpl *id___proto__; QScriptNameIdImpl *id___qt_sender__; }; } // namespace QScript #ifndef QT_NO_QOBJECT class QScriptQObjectData; class QScriptMetaObject; #endif class QScriptCustomTypeInfo { public: QScriptCustomTypeInfo() : signature(0, '\0'), marshal(0), demarshal(0) { prototype.invalidate(); } QByteArray signature; QScriptEngine::MarshalFunction marshal; QScriptEngine::DemarshalFunction demarshal; QScriptValueImpl prototype; }; class QScriptEnginePrivate #ifndef QT_NO_QOBJECT : public QObjectPrivate #endif { Q_DECLARE_PUBLIC(QScriptEngine) enum { DefaultHashSize = 1021 }; public: QScriptEnginePrivate(); virtual ~QScriptEnginePrivate(); void init(); void initStringRepository(); static inline QScriptEnginePrivate *get(QScriptEngine *q); static inline const QScriptEnginePrivate *get(const QScriptEngine *q); static inline QScriptEngine *get(QScriptEnginePrivate *d); QScript::AST::Node *createAbstractSyntaxTree( const QString &source, int lineNumber, QString *errorMessage, int *errorLineNumber); QScript::AST::Node *changeAbstractSyntaxTree(QScript::AST::Node *program); inline QScript::AST::Node *abstractSyntaxTree() const; inline bool hasUncaughtException() const; inline QScriptValueImpl uncaughtException() const; QStringList uncaughtExceptionBacktrace() const; void clearExceptions(); #ifndef QT_NO_QOBJECT void emitSignalHandlerException(); #endif static bool canEvaluate(const QString &program); static QScriptSyntaxCheckResult checkSyntax(const QString &program); inline QScriptContextPrivate *currentContext() const; inline QScriptContextPrivate *pushContext(); inline void popContext(); inline QScript::MemoryPool *nodePool(); inline QScript::Lexer *lexer(); inline QScriptObject *allocObject(); inline void maybeGC(); void maybeGC_helper(bool do_string_gc); inline bool blockGC(bool block); void gc(); bool isCollecting() const; void processMarkStack(int generation); inline void adjustBytesAllocated(int bytes); void markObject(const QScriptValueImpl &object, int generation); void markFrame(QScriptContextPrivate *context, int generation); inline void markString(QScriptNameIdImpl *id, int generation); inline QScriptValueImpl createFunction(QScriptFunction *fun); inline QScriptValueImpl newArray(const QScript::Array &value); inline QScriptValueImpl newArray(uint length = 0); void evaluate(QScriptContextPrivate *context, const QString &contents, int lineNumber, const QString &fileName = QString()); inline void setLexer(QScript::Lexer *lexer); inline void setNodePool(QScript::MemoryPool *pool); inline QScriptClassInfo *registerClass(const QString &pname, int type); inline QScriptClassInfo *registerClass(const QString &name); int registerCustomClassType(); inline QScriptValueImpl createFunction(QScriptInternalFunctionSignature fun, int length, QScriptClassInfo *classInfo, const QString &name = QString()); static inline QString toString(QScriptNameIdImpl *id); inline QString memberName(const QScript::Member &member) const; inline void newReference(QScriptValueImpl *object, int mode); inline void newActivation(QScriptValueImpl *object); inline void newFunction(QScriptValueImpl *object, QScriptFunction *function); inline void newConstructor(QScriptValueImpl *ctor, QScriptFunction *function, QScriptValueImpl &proto); inline void newInteger(QScriptValueImpl *object, int i); inline void newPointer(QScriptValueImpl *object, void *ptr); inline void newNameId(QScriptValueImpl *object, const QString &s); inline void newNameId(QScriptValueImpl *object, QScriptNameIdImpl *id); inline void newString(QScriptValueImpl *object, const QString &s); inline void newArguments(QScriptValueImpl *object, const QScriptValueImpl &activation, uint length, const QScriptValueImpl &callee); static inline QString convertToNativeString(const QScriptValueImpl &value); static QString convertToNativeString_helper(const QScriptValueImpl &value); static inline qsreal convertToNativeDouble(const QScriptValueImpl &value); static qsreal convertToNativeDouble_helper(const QScriptValueImpl &value); static inline bool convertToNativeBoolean(const QScriptValueImpl &value); static bool convertToNativeBoolean_helper(const QScriptValueImpl &value); static inline qint32 convertToNativeInt32(const QScriptValueImpl &value); static inline QScriptFunction *convertToNativeFunction(const QScriptValueImpl &value); inline QScriptValue toPublic(const QScriptValueImpl &value); inline QScriptValueImpl toImpl(const QScriptValue &value); QScriptValueImpl toImpl_helper(const QScriptValue &value); inline QScriptValueImplList toImplList(const QScriptValueList &lst); inline const QScript::IdTable *idTable() const; inline QScriptValueImpl toObject(const QScriptValueImpl &value); QScriptValueImpl toObject_helper(const QScriptValueImpl &value); inline QScriptValueImpl toPrimitive(const QScriptValueImpl &object, QScriptValueImpl::TypeHint hint = QScriptValueImpl::NoTypeHint); QScriptValueImpl toPrimitive_helper(const QScriptValueImpl &object, QScriptValueImpl::TypeHint hint); static const qsreal D16; static const qsreal D32; inline static qsreal toInteger(qsreal n); inline static qint32 toInt32(qsreal m); inline static quint32 toUint32(qsreal n); inline static quint16 toUint16(qsreal n); inline QDateTime toDateTime(const QScriptValueImpl &value) const; inline void newArray(QScriptValueImpl *object, const QScript::Array &value); inline void newObject(QScriptValueImpl *o, const QScriptValueImpl &proto, QScriptClassInfo *oc = 0); inline void newObject(QScriptValueImpl *o, QScriptClassInfo *oc = 0); QScriptValueImpl newObject(QScriptClass *scriptClass, const QScriptValueImpl &data); inline QScriptValueImpl newObject(); inline void newVariant(QScriptValueImpl *out, const QVariant &value, bool setDefaultPrototype = true); #ifndef QT_NO_QOBJECT void newQObject(QScriptValueImpl *out, QObject *object, QScriptEngine::ValueOwnership ownership = QScriptEngine::QtOwnership, const QScriptEngine::QObjectWrapOptions &options = 0, bool setDefaultPrototype = true); # ifndef Q_SCRIPT_NO_QMETAOBJECT_CACHE inline QScriptMetaObject *cachedMetaObject(const QMetaObject *meta); # endif #endif inline QScriptNameIdImpl *nameId(const QString &str, bool persistent = false); inline QScriptNameIdImpl *intern(const QChar *u, int s); QScriptString internedString(const QString &str); QScriptString internedString(QScriptNameIdImpl *nid); void uninternString(QScriptStringPrivate *d); inline QScriptValueImpl valueFromVariant(const QVariant &v); inline QScriptValueImpl undefinedValue(); inline QScriptValueImpl nullValue(); inline QScriptValueImpl defaultPrototype(int metaTypeId) const; inline void setDefaultPrototype(int metaTypeId, const QScriptValueImpl &prototype); QScriptValueImpl call(const QScriptValueImpl &callee, const QScriptValueImpl &thisObject, const QScriptValueImplList &args, bool asConstructor); QScriptValueImpl call(const QScriptValueImpl &callee, const QScriptValueImpl &thisObject, const QScriptValueImpl &args, bool asConstructor); void rehashStringRepository(bool resize = true); inline QScriptNameIdImpl *toStringEntry(const QString &s); QScriptNameIdImpl *insertStringEntry(const QString &s); QScriptValueImpl create(int type, const void *ptr); static bool convert(const QScriptValueImpl &value, int type, void *ptr, QScriptEnginePrivate *eng); QScriptValueImpl arrayFromStringList(const QStringList &lst); static QStringList stringListFromArray(const QScriptValueImpl &arr); QScriptValueImpl arrayFromVariantList(const QVariantList &lst); static QVariantList variantListFromArray(const QScriptValueImpl &arr); QScriptValueImpl objectFromVariantMap(const QVariantMap &vmap); static QVariantMap variantMapFromObject(const QScriptValueImpl &obj); static inline bool lessThan(const QScriptValueImpl &lhs, const QScriptValueImpl &rhs); static inline bool equals(const QScriptValueImpl &lhs, const QScriptValueImpl &rhs); static inline bool strictlyEquals(const QScriptValueImpl &lhs, const QScriptValueImpl &rhs); QScriptValuePrivate *registerValue(const QScriptValueImpl &value); inline void unregisterValue(QScriptValuePrivate *p); inline QScriptValueImpl globalObject() const; QScriptValueImpl objectById(qint64 id) const; QScriptValueImpl importExtension(const QString &extension); QStringList availableExtensions() const; QStringList importedExtensions() const; inline void maybeProcessEvents(); void setupProcessEvents(); void processEvents(); #ifndef QT_NO_QOBJECT QScriptQObjectData *qobjectData(QObject *object); bool scriptConnect(QObject *sender, const char *signal, const QScriptValueImpl &receiver, const QScriptValueImpl &function); bool scriptDisconnect(QObject *sender, const char *signal, const QScriptValueImpl &receiver, const QScriptValueImpl &function); bool scriptConnect(QObject *sender, int index, const QScriptValueImpl &receiver, const QScriptValueImpl &function, const QScriptValueImpl &senderWrapper = QScriptValueImpl()); bool scriptDisconnect(QObject *sender, int index, const QScriptValueImpl &receiver, const QScriptValueImpl &function); bool scriptConnect(const QScriptValueImpl &signal, const QScriptValueImpl &receiver, const QScriptValueImpl &function); bool scriptDisconnect(const QScriptValueImpl &signal, const QScriptValueImpl &receiver, const QScriptValueImpl &function); void _q_objectDestroyed(QObject *object); void disposeQObject(QObject *object); void deletePendingQObjects(); static bool convertToNativeQObject(const QScriptValueImpl &value, const QByteArray &targetType, void **result); #endif void abortEvaluation(const QScriptValueImpl &result); inline bool shouldAbort() const; inline void resetAbortFlag(); void setAgent(QScriptEngineAgent *agent); QScriptEngineAgent *agent() const; void agentDeleted(QScriptEngineAgent *agent); void installTranslatorFunctions(QScriptValueImpl &object); #ifndef Q_SCRIPT_NO_EVENT_NOTIFY qint64 nextScriptId(); inline bool shouldNotify() const; inline void notifyScriptLoad(qint64 id, const QString &program, const QString &fileName, int lineNumber); void notifyScriptLoad_helper(qint64 id, const QString &program, const QString &fileName, int lineNumber); inline void notifyScriptUnload(qint64 id); void notifyScriptUnload_helper(qint64 id); inline void notifyPositionChange(QScriptContextPrivate *ctx); void notifyPositionChange_helper(QScriptContextPrivate *ctx); inline void notifyContextPush(); void notifyContextPush_helper(); inline void notifyContextPop(); void notifyContextPop_helper(); inline void notifyFunctionEntry(QScriptContextPrivate *ctx); void notifyFunctionEntry_helper(QScriptContextPrivate *ctx); inline void notifyFunctionExit(QScriptContextPrivate *ctx); void notifyFunctionExit_helper(QScriptContextPrivate *ctx); inline void notifyException(QScriptContextPrivate *ctx); void notifyException_helper(QScriptContextPrivate *ctx); inline void notifyExceptionCatch(QScriptContextPrivate *ctx); void notifyExceptionCatch_helper(QScriptContextPrivate *ctx); void notifyDebugger(QScriptContextPrivate *ctx); #endif // Q_SCRIPT_NO_EVENT_NOTIFY public: // attributes bool m_evaluating; bool m_abort; int m_callDepth; int m_maxCallDepth; int m_gc_depth; QList m_markStack; QScriptValueImpl m_globalObject; int m_oldStringRepositorySize; int m_oldTempStringRepositorySize; QVector m_stringRepository; int m_newAllocatedStringRepositoryChars; QVector m_tempStringRepository; int m_newAllocatedTempStringRepositoryChars; QScriptNameIdImpl **m_string_hash_base; int m_string_hash_size; QScript::GCAlloc objectAllocator; int m_objectGeneration; QScript::Repository m_frameRepository; QScriptContextPrivate *m_context; QScriptValueImpl *tempStackBegin; QScriptValueImpl *tempStackEnd; QScript::AST::Node *m_abstractSyntaxTree; QScript::Lexer *m_lexer; QScript::MemoryPool *m_pool; QStringList m_exceptionBacktrace; qint64 m_scriptCounter; QScriptValueImpl m_undefinedValue; QScriptValueImpl m_nullValue; QScript::Ecma::Object *objectConstructor; QScript::Ecma::Number *numberConstructor; QScript::Ecma::Boolean *booleanConstructor; QScript::Ecma::String *stringConstructor; QScript::Ecma::Date *dateConstructor; QScript::Ecma::Function *functionConstructor; QScript::Ecma::Array *arrayConstructor; QScript::Ecma::RegExp *regexpConstructor; QScript::Ecma::Error *errorConstructor; QScript::Ext::Enumeration *enumerationConstructor; QScript::Ext::Variant *variantConstructor; QScript::ExtQObject *qobjectConstructor; QScript::ExtQMetaObject *qmetaObjectConstructor; QHash m_customTypes; QScriptFunction *m_evalFunction; QList m_allocated_classes; QScriptClassInfo *m_class_object; QScriptClassInfo *m_class_function; QScriptClassInfo *m_class_with; QScriptClassInfo *m_class_arguments; QScriptClassInfo *m_class_activation; int m_class_prev_id; qint64 m_next_object_id; QScript::Repository m_handleRepository; QHash m_objectHandles; QHash m_stringHandles; QVector m_otherHandles; QScript::Repository m_internedStringRepository; QHash m_internedStrings; QSet visitedArrayElements; #ifndef QT_NO_REGEXP QHash m_regExpLiterals; #endif QScript::IdTable m_id_table; QSet m_importedExtensions; QSet m_extensionsBeingImported; int m_processEventsInterval; int m_nextProcessEvents; int m_processEventIncr; QTime m_processEventTracker; QList m_agents; QScriptEngineAgent *m_agent; #ifndef QT_NO_QOBJECT QList m_qobjectsToBeDeleted; QHash m_qobjectData; # ifndef Q_SCRIPT_NO_QMETAOBJECT_CACHE QHash m_cachedMetaObjects; # endif #endif #ifdef QT_NO_QOBJECT QScriptEngine *q_ptr; #endif }; QT_END_NAMESPACE #endif // QT_NO_SCRIPT #endif