2012-11-17 20:54:26 +00:00
|
|
|
/****************************************************************************
|
|
|
|
**
|
|
|
|
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
|
|
|
|
** Contact: http://www.qt-project.org/legal
|
|
|
|
**
|
|
|
|
** This file is part of the V4VM 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$
|
|
|
|
**
|
|
|
|
****************************************************************************/
|
2013-03-18 10:03:51 +00:00
|
|
|
#ifndef QV4ENGINE_H
|
|
|
|
#define QV4ENGINE_H
|
2012-11-17 20:54:26 +00:00
|
|
|
|
2013-01-29 13:20:50 +00:00
|
|
|
#include "qv4global.h"
|
|
|
|
#include "qv4isel_p.h"
|
|
|
|
#include "qv4object.h"
|
2013-03-18 10:03:51 +00:00
|
|
|
#include "qv4util.h"
|
2013-03-14 11:43:27 +00:00
|
|
|
#include "qv4context.h"
|
2012-11-17 20:54:26 +00:00
|
|
|
#include <setjmp.h>
|
|
|
|
|
2013-01-14 15:53:43 +00:00
|
|
|
#include <wtf/BumpPointerAllocator.h>
|
|
|
|
|
2013-01-31 09:00:06 +00:00
|
|
|
QT_BEGIN_NAMESPACE
|
|
|
|
|
2012-11-17 20:54:26 +00:00
|
|
|
namespace QQmlJS {
|
2012-11-29 13:41:26 +00:00
|
|
|
|
|
|
|
namespace Debugging {
|
|
|
|
class Debugger;
|
|
|
|
} // namespace Debugging
|
|
|
|
|
2012-11-17 20:54:26 +00:00
|
|
|
namespace VM {
|
|
|
|
|
|
|
|
struct Value;
|
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-01-23 09:07:18 +00:00
|
|
|
struct EvalFunction;
|
2013-01-30 13:56:40 +00:00
|
|
|
struct Identifiers;
|
2013-02-10 21:22:53 +00:00
|
|
|
struct InternalClass;
|
2012-11-17 20:54:26 +00:00
|
|
|
|
2013-01-14 15:53:43 +00:00
|
|
|
class RegExp;
|
2013-03-30 16:43:03 +00:00
|
|
|
class RegExpCache;
|
2013-01-14 15:53:43 +00:00
|
|
|
|
2013-03-06 13:01:07 +00:00
|
|
|
typedef bool (*ExternalResourceComparison)(const VM::Value &a, const VM::Value &b);
|
|
|
|
|
2013-01-29 13:20:50 +00:00
|
|
|
struct Q_V4_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-03-05 15:11:22 +00:00
|
|
|
QScopedPointer<EvalISelFactory> iselFactory;
|
2013-03-14 13:03:04 +00:00
|
|
|
|
|
|
|
ExecutionContext **contextStack;
|
|
|
|
int contextStackPosition;
|
|
|
|
int contextStackSize;
|
|
|
|
|
2012-11-18 22:33:06 +00:00
|
|
|
ExecutionContext *current;
|
2012-11-17 20:54:26 +00:00
|
|
|
ExecutionContext *rootContext;
|
2013-03-14 13:03:04 +00:00
|
|
|
|
2013-01-14 15:53:43 +00:00
|
|
|
WTF::BumpPointerAllocator bumperPointerAllocator; // Used by Yarr Regex engine.
|
2012-11-18 22:33:06 +00:00
|
|
|
|
2013-01-30 13:56:40 +00:00
|
|
|
Identifiers *identifierCache;
|
|
|
|
|
2012-11-29 13:41:26 +00:00
|
|
|
Debugging::Debugger *debugger;
|
|
|
|
|
2012-11-17 20:54:26 +00:00
|
|
|
Value globalObject;
|
|
|
|
|
2013-01-28 15:46:09 +00:00
|
|
|
VM::Function *globalCode;
|
|
|
|
|
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-03-04 10:48:49 +00:00
|
|
|
InternalClass *emptyClass;
|
|
|
|
InternalClass *arrayClass;
|
|
|
|
|
2013-01-23 09:07:18 +00:00
|
|
|
EvalFunction *evalFunction;
|
|
|
|
|
2013-01-18 11:47:43 +00:00
|
|
|
QVector<PropertyDescriptor> argumentsAccessors;
|
|
|
|
|
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;
|
2012-11-17 20:54:26 +00:00
|
|
|
|
2012-12-11 09:03:40 +00:00
|
|
|
QVector<Function *> functions;
|
2012-11-28 12:39:14 +00:00
|
|
|
|
2013-03-06 13:01:07 +00:00
|
|
|
ExternalResourceComparison externalResourceComparison;
|
|
|
|
|
2013-03-30 16:43:03 +00:00
|
|
|
RegExpCache *regExpCache;
|
|
|
|
|
2013-03-05 15:11:22 +00:00
|
|
|
ExecutionEngine(EvalISelFactory *iselFactory = 0);
|
2012-12-04 10:30:26 +00:00
|
|
|
~ExecutionEngine();
|
2012-11-17 20:54:26 +00:00
|
|
|
|
2013-03-14 11:59:11 +00:00
|
|
|
ExecutionContext *newWithContext(Object *with);
|
|
|
|
ExecutionContext *newCatchContext(String* exceptionVarName, const QQmlJS::VM::Value &exceptionValue);
|
|
|
|
ExecutionContext *newCallContext(FunctionObject *f, const QQmlJS::VM::Value &thisObject, QQmlJS::VM::Value *args, int argc);
|
2013-04-03 18:24:38 +00:00
|
|
|
ExecutionContext *newCallContext(void *stackSpace, FunctionObject *f, const QQmlJS::VM::Value &thisObject, QQmlJS::VM::Value *args, int argc);
|
2013-03-14 13:03:04 +00:00
|
|
|
ExecutionContext *pushGlobalContext();
|
2013-03-14 11:59:11 +00:00
|
|
|
ExecutionContext *popContext();
|
2012-11-17 20:54:26 +00:00
|
|
|
|
2012-12-11 09:03:40 +00:00
|
|
|
VM::Function *newFunction(const QString &name);
|
|
|
|
|
2013-01-16 10:41:23 +00:00
|
|
|
FunctionObject *newBuiltinFunction(ExecutionContext *scope, String *name, Value (*code)(ExecutionContext *));
|
2013-01-29 20:23:19 +00:00
|
|
|
FunctionObject *newBuiltinFunction(ExecutionContext *scope, String *name, Value (*code)(ExecutionContext *, Value, Value *, int));
|
2012-12-11 09:03:40 +00:00
|
|
|
FunctionObject *newScriptFunction(ExecutionContext *scope, VM::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();
|
|
|
|
|
|
|
|
String *newString(const QString &s);
|
2013-01-30 13:56:40 +00:00
|
|
|
String *newIdentifier(const QString &text);
|
|
|
|
|
2013-01-14 13:51:53 +00:00
|
|
|
Object *newStringObject(ExecutionContext *ctx, const Value &value);
|
2012-11-17 20:54:26 +00:00
|
|
|
Object *newNumberObject(const Value &value);
|
|
|
|
Object *newBooleanObject(const Value &value);
|
|
|
|
Object *newFunctionObject(ExecutionContext *ctx);
|
|
|
|
|
2013-01-11 13:33:10 +00:00
|
|
|
ArrayObject *newArrayObject(ExecutionContext *ctx);
|
2012-11-17 20:54:26 +00:00
|
|
|
|
|
|
|
Object *newDateObject(const Value &value);
|
|
|
|
|
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);
|
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);
|
2012-12-04 18:50:25 +00:00
|
|
|
Object *newReferenceErrorObject(ExecutionContext *ctx, const QString &message);
|
|
|
|
Object *newTypeErrorObject(ExecutionContext *ctx, const QString &message);
|
2013-01-11 08:56:56 +00:00
|
|
|
Object *newRangeErrorObject(ExecutionContext *ctx, const QString &message);
|
2013-01-22 14:13:15 +00:00
|
|
|
Object *newURIErrorObject(ExecutionContext *ctx, Value message);
|
2012-12-04 18:50:25 +00:00
|
|
|
|
2013-01-10 16:33:06 +00:00
|
|
|
Object *newForEachIteratorObject(ExecutionContext *ctx, Object *o);
|
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
|
|
|
|
|
|
|
Value run(VM::Function *function, ExecutionContext *ctx = 0);
|
2013-03-14 13:03:04 +00:00
|
|
|
|
|
|
|
void initRootContext();
|
|
|
|
void ensureContextStackSize();
|
2013-03-05 15:11:22 +00:00
|
|
|
};
|
|
|
|
|
2012-11-17 20:54:26 +00:00
|
|
|
} // namespace VM
|
|
|
|
} // namespace QQmlJS
|
|
|
|
|
2013-01-31 09:00:06 +00:00
|
|
|
QT_END_NAMESPACE
|
|
|
|
|
2013-03-18 10:03:51 +00:00
|
|
|
#endif // QV4ENGINE_H
|