2012-11-17 20:54:26 +00:00
|
|
|
/****************************************************************************
|
|
|
|
**
|
2013-06-24 11:50:51 +00:00
|
|
|
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
2012-11-17 20:54:26 +00:00
|
|
|
** Contact: http://www.qt-project.org/legal
|
|
|
|
**
|
2013-06-24 11:50:51 +00:00
|
|
|
** This file is part of the QtQml module of the Qt Toolkit.
|
2012-11-17 20:54:26 +00:00
|
|
|
**
|
|
|
|
** $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$
|
|
|
|
**
|
|
|
|
****************************************************************************/
|
2013-03-18 10:03:51 +00:00
|
|
|
#ifndef QV4ENGINE_H
|
|
|
|
#define QV4ENGINE_H
|
2012-11-17 20:54:26 +00:00
|
|
|
|
2013-04-15 09:50:16 +00:00
|
|
|
#include "qv4global_p.h"
|
2013-08-08 07:20:52 +00:00
|
|
|
#include "private/qv4isel_p.h"
|
2013-04-15 09:50:16 +00:00
|
|
|
#include "qv4util_p.h"
|
|
|
|
#include "qv4context_p.h"
|
|
|
|
#include "qv4property_p.h"
|
2013-05-14 00:01:04 +00:00
|
|
|
#include <private/qintrusivelist_p.h>
|
2012-11-17 20:54:26 +00:00
|
|
|
|
2013-04-19 09:47:50 +00:00
|
|
|
namespace WTF {
|
|
|
|
class BumpPointerAllocator;
|
|
|
|
}
|
2013-01-14 15:53:43 +00:00
|
|
|
|
2013-01-31 09:00:06 +00:00
|
|
|
QT_BEGIN_NAMESPACE
|
|
|
|
|
2013-06-04 14:00:13 +00:00
|
|
|
class QV8Engine;
|
2013-04-17 16:17:30 +00:00
|
|
|
|
2013-07-24 08:29:04 +00:00
|
|
|
namespace QV4 {
|
2012-11-29 13:41:26 +00:00
|
|
|
namespace Debugging {
|
|
|
|
class Debugger;
|
|
|
|
} // namespace Debugging
|
2013-04-19 11:03:42 +00:00
|
|
|
}
|
2012-11-29 13:41:26 +00:00
|
|
|
|
2013-04-19 11:03:42 +00:00
|
|
|
namespace QV4 {
|
2012-11-17 20:54:26 +00:00
|
|
|
|
2012-12-11 09:03:40 +00:00
|
|
|
struct Function;
|
2012-11-17 20:54:26 +00:00
|
|
|
struct Object;
|
|
|
|
struct BooleanObject;
|
|
|
|
struct NumberObject;
|
|
|
|
struct StringObject;
|
|
|
|
struct ArrayObject;
|
|
|
|
struct DateObject;
|
|
|
|
struct FunctionObject;
|
2013-01-13 22:57:35 +00:00
|
|
|
struct BoundFunction;
|
2012-11-17 20:54:26 +00:00
|
|
|
struct RegExpObject;
|
|
|
|
struct ErrorObject;
|
|
|
|
struct ArgumentsObject;
|
|
|
|
struct ExecutionContext;
|
|
|
|
struct ExecutionEngine;
|
2012-12-04 12:40:18 +00:00
|
|
|
class MemoryManager;
|
2013-02-21 13:30:35 +00:00
|
|
|
class UnwindHelper;
|
2013-03-25 16:31:38 +00:00
|
|
|
class ExecutableAllocator;
|
2012-11-17 20:54:26 +00:00
|
|
|
|
|
|
|
struct ObjectPrototype;
|
|
|
|
struct StringPrototype;
|
|
|
|
struct NumberPrototype;
|
|
|
|
struct BooleanPrototype;
|
|
|
|
struct ArrayPrototype;
|
|
|
|
struct FunctionPrototype;
|
|
|
|
struct DatePrototype;
|
|
|
|
struct RegExpPrototype;
|
|
|
|
struct ErrorPrototype;
|
|
|
|
struct EvalErrorPrototype;
|
|
|
|
struct RangeErrorPrototype;
|
|
|
|
struct ReferenceErrorPrototype;
|
|
|
|
struct SyntaxErrorPrototype;
|
|
|
|
struct TypeErrorPrototype;
|
|
|
|
struct URIErrorPrototype;
|
2013-05-14 00:01:04 +00:00
|
|
|
struct VariantPrototype;
|
2013-05-21 15:06:36 +00:00
|
|
|
struct SequencePrototype;
|
2013-01-23 09:07:18 +00:00
|
|
|
struct EvalFunction;
|
2013-06-27 06:57:47 +00:00
|
|
|
struct IdentifierTable;
|
2013-02-10 21:22:53 +00:00
|
|
|
struct InternalClass;
|
2013-06-04 12:28:13 +00:00
|
|
|
class MultiplyWrappedQObjectMap;
|
2013-01-14 15:53:43 +00:00
|
|
|
class RegExp;
|
2013-03-30 16:43:03 +00:00
|
|
|
class RegExpCache;
|
2013-06-20 09:32:45 +00:00
|
|
|
struct QmlExtensions;
|
2013-01-14 15:53:43 +00:00
|
|
|
|
2013-04-16 15:03:00 +00:00
|
|
|
struct Q_QML_EXPORT ExecutionEngine
|
2012-11-17 20:54:26 +00:00
|
|
|
{
|
2012-12-04 12:40:18 +00:00
|
|
|
MemoryManager *memoryManager;
|
2013-03-25 16:31:38 +00:00
|
|
|
ExecutableAllocator *executableAllocator;
|
2013-05-12 10:07:15 +00:00
|
|
|
ExecutableAllocator *regExpAllocator;
|
2013-04-19 11:03:42 +00:00
|
|
|
QScopedPointer<QQmlJS::EvalISelFactory> iselFactory;
|
2013-03-14 13:03:04 +00:00
|
|
|
|
2012-11-18 22:33:06 +00:00
|
|
|
ExecutionContext *current;
|
2013-04-05 11:27:38 +00:00
|
|
|
GlobalContext *rootContext;
|
2013-03-14 13:03:04 +00:00
|
|
|
|
2013-04-19 09:47:50 +00:00
|
|
|
WTF::BumpPointerAllocator *bumperPointerAllocator; // Used by Yarr Regex engine.
|
2012-11-18 22:33:06 +00:00
|
|
|
|
2013-06-27 06:57:47 +00:00
|
|
|
IdentifierTable *identifierTable;
|
2013-01-30 13:56:40 +00:00
|
|
|
|
2013-07-24 08:29:04 +00:00
|
|
|
QV4::Debugging::Debugger *debugger;
|
2012-11-29 13:41:26 +00:00
|
|
|
|
2013-04-08 07:08:02 +00:00
|
|
|
Object *globalObject;
|
2012-11-17 20:54:26 +00:00
|
|
|
|
2013-04-19 11:03:42 +00:00
|
|
|
Function *globalCode;
|
2013-01-28 15:46:09 +00:00
|
|
|
|
2013-06-04 14:00:13 +00:00
|
|
|
QV8Engine *v8Engine;
|
2013-04-17 16:17:30 +00:00
|
|
|
|
2012-11-17 20:54:26 +00:00
|
|
|
Value objectCtor;
|
|
|
|
Value stringCtor;
|
|
|
|
Value numberCtor;
|
|
|
|
Value booleanCtor;
|
|
|
|
Value arrayCtor;
|
|
|
|
Value functionCtor;
|
|
|
|
Value dateCtor;
|
|
|
|
Value regExpCtor;
|
|
|
|
Value errorCtor;
|
|
|
|
Value evalErrorCtor;
|
|
|
|
Value rangeErrorCtor;
|
|
|
|
Value referenceErrorCtor;
|
|
|
|
Value syntaxErrorCtor;
|
|
|
|
Value typeErrorCtor;
|
|
|
|
Value uRIErrorCtor;
|
|
|
|
|
|
|
|
ObjectPrototype *objectPrototype;
|
|
|
|
StringPrototype *stringPrototype;
|
|
|
|
NumberPrototype *numberPrototype;
|
|
|
|
BooleanPrototype *booleanPrototype;
|
|
|
|
ArrayPrototype *arrayPrototype;
|
|
|
|
FunctionPrototype *functionPrototype;
|
|
|
|
DatePrototype *datePrototype;
|
|
|
|
RegExpPrototype *regExpPrototype;
|
|
|
|
ErrorPrototype *errorPrototype;
|
|
|
|
EvalErrorPrototype *evalErrorPrototype;
|
|
|
|
RangeErrorPrototype *rangeErrorPrototype;
|
|
|
|
ReferenceErrorPrototype *referenceErrorPrototype;
|
|
|
|
SyntaxErrorPrototype *syntaxErrorPrototype;
|
|
|
|
TypeErrorPrototype *typeErrorPrototype;
|
|
|
|
URIErrorPrototype *uRIErrorPrototype;
|
|
|
|
|
2013-05-14 00:01:04 +00:00
|
|
|
VariantPrototype *variantPrototype;
|
2013-05-21 15:06:36 +00:00
|
|
|
SequencePrototype *sequencePrototype;
|
2013-05-14 00:01:04 +00:00
|
|
|
|
2013-05-06 11:29:24 +00:00
|
|
|
QQmlJS::MemoryPool classPool;
|
2013-03-04 10:48:49 +00:00
|
|
|
InternalClass *emptyClass;
|
|
|
|
InternalClass *arrayClass;
|
|
|
|
|
2013-01-23 09:07:18 +00:00
|
|
|
EvalFunction *evalFunction;
|
|
|
|
|
2013-04-10 08:46:23 +00:00
|
|
|
QVector<Property> argumentsAccessors;
|
2013-01-18 11:47:43 +00:00
|
|
|
|
2013-02-14 22:00:11 +00:00
|
|
|
String *id_undefined;
|
|
|
|
String *id_null;
|
|
|
|
String *id_true;
|
|
|
|
String *id_false;
|
|
|
|
String *id_boolean;
|
|
|
|
String *id_number;
|
|
|
|
String *id_string;
|
|
|
|
String *id_object;
|
|
|
|
String *id_function;
|
2012-11-17 20:54:26 +00:00
|
|
|
String *id_length;
|
|
|
|
String *id_prototype;
|
|
|
|
String *id_constructor;
|
|
|
|
String *id_arguments;
|
2013-01-13 22:57:35 +00:00
|
|
|
String *id_caller;
|
2012-12-09 04:16:04 +00:00
|
|
|
String *id_this;
|
2012-11-17 20:54:26 +00:00
|
|
|
String *id___proto__;
|
2012-12-08 07:57:35 +00:00
|
|
|
String *id_enumerable;
|
|
|
|
String *id_configurable;
|
|
|
|
String *id_writable;
|
|
|
|
String *id_value;
|
|
|
|
String *id_get;
|
|
|
|
String *id_set;
|
2013-01-23 09:07:18 +00:00
|
|
|
String *id_eval;
|
2013-05-03 20:40:58 +00:00
|
|
|
String *id_uintMax;
|
2013-05-04 08:26:54 +00:00
|
|
|
String *id_name;
|
2012-11-17 20:54:26 +00:00
|
|
|
|
2013-05-25 13:31:23 +00:00
|
|
|
mutable QVector<Function *> functions;
|
|
|
|
mutable bool functionsNeedSort;
|
2012-11-28 12:39:14 +00:00
|
|
|
|
2013-06-04 08:05:51 +00:00
|
|
|
quint32 m_engineId;
|
|
|
|
|
2013-03-30 16:43:03 +00:00
|
|
|
RegExpCache *regExpCache;
|
|
|
|
|
2013-05-14 00:01:04 +00:00
|
|
|
// Scarce resources are "exceptionally high cost" QVariant types where allowing the
|
|
|
|
// normal JavaScript GC to clean them up is likely to lead to out-of-memory or other
|
|
|
|
// out-of-resource situations. When such a resource is passed into JavaScript we
|
|
|
|
// add it to the scarceResources list and it is destroyed when we return from the
|
|
|
|
// JavaScript execution that created it. The user can prevent this behavior by
|
|
|
|
// calling preserve() on the object which removes it from this scarceResource list.
|
|
|
|
class ScarceResourceData {
|
|
|
|
public:
|
|
|
|
ScarceResourceData(const QVariant &data) : data(data) {}
|
|
|
|
QVariant data;
|
|
|
|
QIntrusiveListNode node;
|
|
|
|
};
|
|
|
|
QIntrusiveList<ScarceResourceData, &ScarceResourceData::node> scarceResources;
|
|
|
|
|
2013-06-04 12:28:13 +00:00
|
|
|
// Normally the JS wrappers for QObjects are stored in the QQmlData/QObjectPrivate,
|
|
|
|
// but any time a QObject is wrapped a second time in another engine, we have to do
|
|
|
|
// bookkeeping.
|
|
|
|
MultiplyWrappedQObjectMap *m_multiplyWrappedQObjects;
|
|
|
|
|
2013-04-19 11:03:42 +00:00
|
|
|
ExecutionEngine(QQmlJS::EvalISelFactory *iselFactory = 0);
|
2012-12-04 10:30:26 +00:00
|
|
|
~ExecutionEngine();
|
2012-11-17 20:54:26 +00:00
|
|
|
|
2013-07-24 08:29:04 +00:00
|
|
|
void enableDebugger();
|
|
|
|
|
2013-04-05 11:27:38 +00:00
|
|
|
WithContext *newWithContext(Object *with);
|
2013-04-19 11:03:42 +00:00
|
|
|
CatchContext *newCatchContext(String* exceptionVarName, const QV4::Value &exceptionValue);
|
|
|
|
CallContext *newCallContext(FunctionObject *f, const QV4::Value &thisObject, QV4::Value *args, int argc);
|
|
|
|
CallContext *newCallContext(void *stackSpace, FunctionObject *f, const QV4::Value &thisObject, QV4::Value *args, int argc);
|
2013-05-22 11:49:27 +00:00
|
|
|
CallContext *newQmlContext(FunctionObject *f, Object *qml);
|
2013-03-14 13:03:04 +00:00
|
|
|
ExecutionContext *pushGlobalContext();
|
2013-04-05 19:15:58 +00:00
|
|
|
void pushContext(SimpleCallContext *context);
|
2013-03-14 11:59:11 +00:00
|
|
|
ExecutionContext *popContext();
|
2012-11-17 20:54:26 +00:00
|
|
|
|
2013-04-19 11:03:42 +00:00
|
|
|
Function *newFunction(const QString &name);
|
2012-12-11 09:03:40 +00:00
|
|
|
|
2013-04-05 19:15:58 +00:00
|
|
|
FunctionObject *newBuiltinFunction(ExecutionContext *scope, String *name, Value (*code)(SimpleCallContext *));
|
2013-04-19 11:03:42 +00:00
|
|
|
FunctionObject *newScriptFunction(ExecutionContext *scope, Function *function);
|
2013-01-13 22:57:35 +00:00
|
|
|
BoundFunction *newBoundFunction(ExecutionContext *scope, FunctionObject *target, Value boundThis, const QVector<Value> &boundArgs);
|
2012-11-17 20:54:26 +00:00
|
|
|
|
|
|
|
Object *newObject();
|
2013-04-23 05:31:02 +00:00
|
|
|
Object *newObject(InternalClass *internalClass);
|
2012-11-17 20:54:26 +00:00
|
|
|
|
|
|
|
String *newString(const QString &s);
|
2013-01-30 13:56:40 +00:00
|
|
|
String *newIdentifier(const QString &text);
|
|
|
|
|
2013-05-02 19:37:20 +00:00
|
|
|
Object *newStringObject(const Value &value);
|
2012-11-17 20:54:26 +00:00
|
|
|
Object *newNumberObject(const Value &value);
|
|
|
|
Object *newBooleanObject(const Value &value);
|
|
|
|
|
2013-05-31 14:40:12 +00:00
|
|
|
ArrayObject *newArrayObject(int count = 0);
|
2013-05-02 20:33:47 +00:00
|
|
|
ArrayObject *newArrayObject(const QStringList &list);
|
2012-11-17 20:54:26 +00:00
|
|
|
|
2013-04-30 21:02:33 +00:00
|
|
|
DateObject *newDateObject(const Value &value);
|
2013-05-02 20:33:47 +00:00
|
|
|
DateObject *newDateObject(const QDateTime &dt);
|
2012-11-17 20:54:26 +00:00
|
|
|
|
2012-12-12 07:28:08 +00:00
|
|
|
RegExpObject *newRegExpObject(const QString &pattern, int flags);
|
2013-03-30 16:05:32 +00:00
|
|
|
RegExpObject *newRegExpObject(RegExp* re, bool global);
|
2013-05-02 20:33:47 +00:00
|
|
|
RegExpObject *newRegExpObject(const QRegExp &re);
|
2012-11-17 20:54:26 +00:00
|
|
|
|
|
|
|
Object *newErrorObject(const Value &value);
|
2012-11-28 10:00:23 +00:00
|
|
|
Object *newSyntaxErrorObject(ExecutionContext *ctx, DiagnosticMessage *message);
|
2013-05-02 19:37:20 +00:00
|
|
|
Object *newSyntaxErrorObject(const QString &message);
|
|
|
|
Object *newReferenceErrorObject(const QString &message);
|
2013-06-14 11:08:13 +00:00
|
|
|
Object *newReferenceErrorObject(const QString &message, const QString &fileName, int lineNumber);
|
2013-05-02 19:37:20 +00:00
|
|
|
Object *newTypeErrorObject(const QString &message);
|
|
|
|
Object *newRangeErrorObject(const QString &message);
|
|
|
|
Object *newURIErrorObject(Value message);
|
2012-12-04 18:50:25 +00:00
|
|
|
|
2013-05-14 00:01:04 +00:00
|
|
|
Object *newVariantObject(const QVariant &v);
|
|
|
|
|
2013-01-10 16:33:06 +00:00
|
|
|
Object *newForEachIteratorObject(ExecutionContext *ctx, Object *o);
|
2013-01-18 11:47:43 +00:00
|
|
|
|
2013-05-03 14:51:32 +00:00
|
|
|
Object *qmlContextObject() const;
|
|
|
|
|
2013-05-22 08:47:36 +00:00
|
|
|
struct StackFrame {
|
2013-05-27 12:19:35 +00:00
|
|
|
QString source;
|
2013-05-22 08:47:36 +00:00
|
|
|
QString function;
|
|
|
|
int line;
|
|
|
|
int column;
|
|
|
|
};
|
2013-05-25 13:31:23 +00:00
|
|
|
typedef QVector<StackFrame> StackTrace;
|
|
|
|
StackTrace stackTrace(int frameLimit = -1) const;
|
2013-05-22 08:47:36 +00:00
|
|
|
StackFrame currentStackFrame() const;
|
2013-05-29 07:59:40 +00:00
|
|
|
QUrl resolvedUrl(const QString &file);
|
2013-05-22 08:47:36 +00:00
|
|
|
|
2013-01-18 11:47:43 +00:00
|
|
|
void requireArgumentsAccessors(int n);
|
2013-01-28 15:46:09 +00:00
|
|
|
|
|
|
|
void markObjects();
|
2013-03-05 15:11:22 +00:00
|
|
|
|
2013-03-14 13:03:04 +00:00
|
|
|
void initRootContext();
|
2013-05-06 11:29:24 +00:00
|
|
|
|
|
|
|
InternalClass *newClass(const InternalClass &other);
|
2013-05-25 13:31:23 +00:00
|
|
|
|
|
|
|
Function *functionForProgramCounter(quintptr pc) const;
|
2013-06-20 09:32:45 +00:00
|
|
|
|
|
|
|
QmlExtensions *qmlExtensions();
|
|
|
|
|
|
|
|
private:
|
|
|
|
QmlExtensions *m_qmlExtensions;
|
2013-03-05 15:11:22 +00:00
|
|
|
};
|
|
|
|
|
2013-04-05 19:15:58 +00:00
|
|
|
inline void ExecutionEngine::pushContext(SimpleCallContext *context)
|
|
|
|
{
|
2013-04-07 15:23:36 +00:00
|
|
|
context->parent = current;
|
2013-04-05 19:15:58 +00:00
|
|
|
current = context;
|
2013-05-13 05:47:05 +00:00
|
|
|
current->currentEvalCode = 0;
|
2013-04-07 15:23:36 +00:00
|
|
|
}
|
2013-04-05 19:15:58 +00:00
|
|
|
|
2013-04-07 15:23:36 +00:00
|
|
|
inline ExecutionContext *ExecutionEngine::popContext()
|
|
|
|
{
|
|
|
|
CallContext *c = current->asCallContext();
|
|
|
|
if (c && !c->needsOwnArguments()) {
|
|
|
|
c->arguments = 0;
|
|
|
|
c->argumentCount = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
current = current->parent;
|
|
|
|
return current;
|
2013-04-05 19:15:58 +00:00
|
|
|
}
|
|
|
|
|
2013-04-19 11:03:42 +00:00
|
|
|
} // namespace QV4
|
2012-11-17 20:54:26 +00:00
|
|
|
|
2013-01-31 09:00:06 +00:00
|
|
|
QT_END_NAMESPACE
|
|
|
|
|
2013-03-18 10:03:51 +00:00
|
|
|
#endif // QV4ENGINE_H
|