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-04-15 09:50:16 +00:00
|
|
|
#include <qv4engine_p.h>
|
|
|
|
#include <qv4value_p.h>
|
|
|
|
#include <qv4object_p.h>
|
|
|
|
#include <qv4objectproto_p.h>
|
|
|
|
#include <qv4arrayobject_p.h>
|
|
|
|
#include <qv4booleanobject_p.h>
|
|
|
|
#include <qv4globalobject_p.h>
|
|
|
|
#include <qv4errorobject_p.h>
|
|
|
|
#include <qv4functionobject_p.h>
|
2013-05-08 12:24:30 +00:00
|
|
|
#include "qv4function_p.h"
|
2013-04-15 09:50:16 +00:00
|
|
|
#include <qv4mathobject_p.h>
|
|
|
|
#include <qv4numberobject_p.h>
|
|
|
|
#include <qv4regexpobject_p.h>
|
2013-05-14 00:01:04 +00:00
|
|
|
#include <qv4variantobject_p.h>
|
2013-04-15 09:50:16 +00:00
|
|
|
#include <qv4runtime_p.h>
|
|
|
|
#include "qv4mm_p.h"
|
|
|
|
#include <qv4argumentsobject_p.h>
|
|
|
|
#include <qv4dateobject_p.h>
|
|
|
|
#include <qv4jsonobject_p.h>
|
|
|
|
#include <qv4stringobject_p.h>
|
|
|
|
#include <qv4identifier_p.h>
|
|
|
|
#include <qv4unwindhelper_p.h>
|
|
|
|
#include "qv4debugging_p.h"
|
|
|
|
#include "qv4executableallocator_p.h"
|
2012-11-17 20:54:26 +00:00
|
|
|
|
2013-05-07 09:54:45 +00:00
|
|
|
#ifdef V4_ENABLE_JIT
|
|
|
|
# include "qv4isel_masm_p.h"
|
|
|
|
#else // !V4_ENABLE_JIT
|
|
|
|
# include "qv4isel_moth_p.h"
|
|
|
|
#endif // V4_ENABLE_JIT
|
|
|
|
|
2013-04-19 11:03:42 +00:00
|
|
|
using namespace QV4;
|
2012-11-17 20:54:26 +00:00
|
|
|
|
2013-04-19 11:03:42 +00:00
|
|
|
ExecutionEngine::ExecutionEngine(QQmlJS::EvalISelFactory *factory)
|
|
|
|
: memoryManager(new QV4::MemoryManager)
|
|
|
|
, executableAllocator(new QV4::ExecutableAllocator)
|
2013-05-12 10:07:15 +00:00
|
|
|
, regExpAllocator(new QV4::ExecutableAllocator)
|
2013-04-19 09:47:50 +00:00
|
|
|
, bumperPointerAllocator(new WTF::BumpPointerAllocator)
|
2012-11-29 13:41:26 +00:00
|
|
|
, debugger(0)
|
2013-04-08 07:08:02 +00:00
|
|
|
, globalObject(0)
|
2013-01-28 15:46:09 +00:00
|
|
|
, globalCode(0)
|
2013-03-06 13:01:07 +00:00
|
|
|
, externalResourceComparison(0)
|
2013-03-30 16:43:03 +00:00
|
|
|
, regExpCache(0)
|
2012-11-17 20:54:26 +00:00
|
|
|
{
|
2012-12-04 12:40:18 +00:00
|
|
|
MemoryManager::GCBlocker gcBlocker(memoryManager);
|
|
|
|
|
2013-05-07 09:54:45 +00:00
|
|
|
if (!factory) {
|
|
|
|
#ifdef V4_ENABLE_JIT
|
2013-04-19 11:03:42 +00:00
|
|
|
factory = new QQmlJS::MASM::ISelFactory;
|
2013-05-07 09:54:45 +00:00
|
|
|
#else // !V4_ENABLE_JIT
|
|
|
|
factory = new QQmlJS::Moth::ISelFactory;
|
|
|
|
#endif // V4_ENABLE_JIT
|
|
|
|
}
|
2013-03-05 15:11:22 +00:00
|
|
|
iselFactory.reset(factory);
|
|
|
|
|
2012-12-04 12:40:18 +00:00
|
|
|
memoryManager->setExecutionEngine(this);
|
2012-11-28 12:39:14 +00:00
|
|
|
|
2013-01-30 13:56:40 +00:00
|
|
|
identifierCache = new Identifiers(this);
|
|
|
|
|
2013-05-12 13:00:48 +00:00
|
|
|
emptyClass = new (classPool.allocate(sizeof(InternalClass))) InternalClass(this);
|
|
|
|
|
2013-02-14 22:00:11 +00:00
|
|
|
id_undefined = newIdentifier(QStringLiteral("undefined"));
|
|
|
|
id_null = newIdentifier(QStringLiteral("null"));
|
|
|
|
id_true = newIdentifier(QStringLiteral("true"));
|
|
|
|
id_false = newIdentifier(QStringLiteral("false"));
|
|
|
|
id_boolean = newIdentifier(QStringLiteral("boolean"));
|
|
|
|
id_number = newIdentifier(QStringLiteral("number"));
|
|
|
|
id_string = newIdentifier(QStringLiteral("string"));
|
|
|
|
id_object = newIdentifier(QStringLiteral("object"));
|
|
|
|
id_function = newIdentifier(QStringLiteral("function"));
|
2013-01-30 13:56:40 +00:00
|
|
|
id_length = newIdentifier(QStringLiteral("length"));
|
|
|
|
id_prototype = newIdentifier(QStringLiteral("prototype"));
|
|
|
|
id_constructor = newIdentifier(QStringLiteral("constructor"));
|
|
|
|
id_arguments = newIdentifier(QStringLiteral("arguments"));
|
|
|
|
id_caller = newIdentifier(QStringLiteral("caller"));
|
|
|
|
id_this = newIdentifier(QStringLiteral("this"));
|
|
|
|
id___proto__ = newIdentifier(QStringLiteral("__proto__"));
|
|
|
|
id_enumerable = newIdentifier(QStringLiteral("enumerable"));
|
|
|
|
id_configurable = newIdentifier(QStringLiteral("configurable"));
|
|
|
|
id_writable = newIdentifier(QStringLiteral("writable"));
|
|
|
|
id_value = newIdentifier(QStringLiteral("value"));
|
|
|
|
id_get = newIdentifier(QStringLiteral("get"));
|
|
|
|
id_set = newIdentifier(QStringLiteral("set"));
|
|
|
|
id_eval = newIdentifier(QStringLiteral("eval"));
|
2013-05-03 20:40:58 +00:00
|
|
|
id_uintMax = newIdentifier(QStringLiteral("4294967295"));
|
2013-05-04 08:26:54 +00:00
|
|
|
id_name = newIdentifier(QStringLiteral("name"));
|
2012-11-17 20:54:26 +00:00
|
|
|
|
2013-04-10 08:46:23 +00:00
|
|
|
arrayClass = emptyClass->addMember(id_length, Attr_NotConfigurable|Attr_NotEnumerable);
|
2013-03-14 13:03:04 +00:00
|
|
|
initRootContext();
|
2013-03-04 10:48:49 +00:00
|
|
|
|
2013-02-10 21:22:53 +00:00
|
|
|
objectPrototype = new (memoryManager) ObjectPrototype(this);
|
2013-05-02 19:37:20 +00:00
|
|
|
stringPrototype = new (memoryManager) StringPrototype(this);
|
2013-02-10 21:22:53 +00:00
|
|
|
numberPrototype = new (memoryManager) NumberPrototype(this);
|
|
|
|
booleanPrototype = new (memoryManager) BooleanPrototype(this);
|
2013-01-11 13:33:10 +00:00
|
|
|
arrayPrototype = new (memoryManager) ArrayPrototype(rootContext);
|
2013-02-10 21:22:53 +00:00
|
|
|
datePrototype = new (memoryManager) DatePrototype(this);
|
2012-12-04 12:40:18 +00:00
|
|
|
functionPrototype = new (memoryManager) FunctionPrototype(rootContext);
|
2013-01-17 14:24:58 +00:00
|
|
|
regExpPrototype = new (memoryManager) RegExpPrototype(this);
|
2013-05-02 19:37:20 +00:00
|
|
|
errorPrototype = new (memoryManager) ErrorPrototype(this);
|
|
|
|
evalErrorPrototype = new (memoryManager) EvalErrorPrototype(this);
|
|
|
|
rangeErrorPrototype = new (memoryManager) RangeErrorPrototype(this);
|
|
|
|
referenceErrorPrototype = new (memoryManager) ReferenceErrorPrototype(this);
|
|
|
|
syntaxErrorPrototype = new (memoryManager) SyntaxErrorPrototype(this);
|
|
|
|
typeErrorPrototype = new (memoryManager) TypeErrorPrototype(this);
|
|
|
|
uRIErrorPrototype = new (memoryManager) URIErrorPrototype(this);
|
2012-11-17 20:54:26 +00:00
|
|
|
|
2013-05-14 00:01:04 +00:00
|
|
|
variantPrototype = new (memoryManager) VariantPrototype(this);
|
|
|
|
|
2012-11-17 20:54:26 +00:00
|
|
|
stringPrototype->prototype = objectPrototype;
|
|
|
|
numberPrototype->prototype = objectPrototype;
|
|
|
|
booleanPrototype->prototype = objectPrototype;
|
|
|
|
arrayPrototype->prototype = objectPrototype;
|
|
|
|
datePrototype->prototype = objectPrototype;
|
|
|
|
functionPrototype->prototype = objectPrototype;
|
|
|
|
regExpPrototype->prototype = objectPrototype;
|
|
|
|
errorPrototype->prototype = objectPrototype;
|
2013-01-14 16:13:25 +00:00
|
|
|
evalErrorPrototype->prototype = objectPrototype;
|
|
|
|
rangeErrorPrototype->prototype = objectPrototype;
|
|
|
|
referenceErrorPrototype->prototype = objectPrototype;
|
|
|
|
syntaxErrorPrototype->prototype = objectPrototype;
|
|
|
|
typeErrorPrototype->prototype = objectPrototype;
|
|
|
|
uRIErrorPrototype->prototype = objectPrototype;
|
2012-11-17 20:54:26 +00:00
|
|
|
|
2012-12-04 12:40:18 +00:00
|
|
|
objectCtor = Value::fromObject(new (memoryManager) ObjectCtor(rootContext));
|
2013-05-06 10:52:25 +00:00
|
|
|
stringCtor = Value::fromObject(StringPrototype::newConstructor(rootContext));
|
2012-12-04 12:40:18 +00:00
|
|
|
numberCtor = Value::fromObject(new (memoryManager) NumberCtor(rootContext));
|
2013-05-06 12:07:36 +00:00
|
|
|
booleanCtor = Value::fromObject(BooleanPrototype::newConstructor(rootContext));
|
2012-12-04 12:40:18 +00:00
|
|
|
arrayCtor = Value::fromObject(new (memoryManager) ArrayCtor(rootContext));
|
|
|
|
functionCtor = Value::fromObject(new (memoryManager) FunctionCtor(rootContext));
|
2013-04-27 19:21:44 +00:00
|
|
|
dateCtor = Value::fromObject(DatePrototype::newConstructor(rootContext));
|
2013-05-06 12:12:33 +00:00
|
|
|
regExpCtor = Value::fromObject(RegExpPrototype::newConstructor(rootContext));
|
2012-12-04 12:40:18 +00:00
|
|
|
errorCtor = Value::fromObject(new (memoryManager) ErrorCtor(rootContext));
|
|
|
|
evalErrorCtor = Value::fromObject(new (memoryManager) EvalErrorCtor(rootContext));
|
|
|
|
rangeErrorCtor = Value::fromObject(new (memoryManager) RangeErrorCtor(rootContext));
|
|
|
|
referenceErrorCtor = Value::fromObject(new (memoryManager) ReferenceErrorCtor(rootContext));
|
|
|
|
syntaxErrorCtor = Value::fromObject(new (memoryManager) SyntaxErrorCtor(rootContext));
|
|
|
|
typeErrorCtor = Value::fromObject(new (memoryManager) TypeErrorCtor(rootContext));
|
|
|
|
uRIErrorCtor = Value::fromObject(new (memoryManager) URIErrorCtor(rootContext));
|
2012-11-17 20:54:26 +00:00
|
|
|
|
2013-01-13 22:57:35 +00:00
|
|
|
objectCtor.objectValue()->prototype = functionPrototype;
|
2012-11-17 20:54:26 +00:00
|
|
|
stringCtor.objectValue()->prototype = functionPrototype;
|
|
|
|
numberCtor.objectValue()->prototype = functionPrototype;
|
|
|
|
booleanCtor.objectValue()->prototype = functionPrototype;
|
|
|
|
arrayCtor.objectValue()->prototype = functionPrototype;
|
|
|
|
functionCtor.objectValue()->prototype = functionPrototype;
|
|
|
|
dateCtor.objectValue()->prototype = functionPrototype;
|
|
|
|
regExpCtor.objectValue()->prototype = functionPrototype;
|
|
|
|
errorCtor.objectValue()->prototype = functionPrototype;
|
2013-01-14 13:02:03 +00:00
|
|
|
evalErrorCtor.objectValue()->prototype = functionPrototype;
|
|
|
|
rangeErrorCtor.objectValue()->prototype = functionPrototype;
|
|
|
|
referenceErrorCtor.objectValue()->prototype = functionPrototype;
|
|
|
|
syntaxErrorCtor.objectValue()->prototype = functionPrototype;
|
|
|
|
typeErrorCtor.objectValue()->prototype = functionPrototype;
|
|
|
|
uRIErrorCtor.objectValue()->prototype = functionPrototype;
|
2012-11-17 20:54:26 +00:00
|
|
|
|
|
|
|
objectPrototype->init(rootContext, objectCtor);
|
2013-05-06 10:52:25 +00:00
|
|
|
stringPrototype->initClass(this, stringCtor);
|
2012-11-17 20:54:26 +00:00
|
|
|
numberPrototype->init(rootContext, numberCtor);
|
2013-05-06 12:07:36 +00:00
|
|
|
booleanPrototype->initClass(this, booleanCtor);
|
2012-11-17 20:54:26 +00:00
|
|
|
arrayPrototype->init(rootContext, arrayCtor);
|
|
|
|
datePrototype->init(rootContext, dateCtor);
|
|
|
|
functionPrototype->init(rootContext, functionCtor);
|
2013-05-06 12:12:33 +00:00
|
|
|
regExpPrototype->initClass(this, regExpCtor);
|
2013-05-02 19:37:20 +00:00
|
|
|
errorPrototype->init(this, errorCtor);
|
|
|
|
evalErrorPrototype->init(this, evalErrorCtor);
|
|
|
|
rangeErrorPrototype->init(this, rangeErrorCtor);
|
|
|
|
referenceErrorPrototype->init(this, referenceErrorCtor);
|
|
|
|
syntaxErrorPrototype->init(this, syntaxErrorCtor);
|
|
|
|
typeErrorPrototype->init(this, typeErrorCtor);
|
|
|
|
uRIErrorPrototype->init(this, uRIErrorCtor);
|
2012-11-17 20:54:26 +00:00
|
|
|
|
2013-05-14 00:01:04 +00:00
|
|
|
variantPrototype->initClass(this);
|
|
|
|
|
2012-11-17 20:54:26 +00:00
|
|
|
//
|
|
|
|
// set up the global object
|
|
|
|
//
|
2013-04-08 07:08:02 +00:00
|
|
|
globalObject = newObject(/*rootContext*/);
|
|
|
|
rootContext->global = globalObject;
|
|
|
|
rootContext->thisObject = Value::fromObject(globalObject);
|
|
|
|
|
|
|
|
globalObject->defineDefaultProperty(rootContext, QStringLiteral("Object"), objectCtor);
|
|
|
|
globalObject->defineDefaultProperty(rootContext, QStringLiteral("String"), stringCtor);
|
|
|
|
globalObject->defineDefaultProperty(rootContext, QStringLiteral("Number"), numberCtor);
|
|
|
|
globalObject->defineDefaultProperty(rootContext, QStringLiteral("Boolean"), booleanCtor);
|
|
|
|
globalObject->defineDefaultProperty(rootContext, QStringLiteral("Array"), arrayCtor);
|
|
|
|
globalObject->defineDefaultProperty(rootContext, QStringLiteral("Function"), functionCtor);
|
|
|
|
globalObject->defineDefaultProperty(rootContext, QStringLiteral("Date"), dateCtor);
|
|
|
|
globalObject->defineDefaultProperty(rootContext, QStringLiteral("RegExp"), regExpCtor);
|
|
|
|
globalObject->defineDefaultProperty(rootContext, QStringLiteral("Error"), errorCtor);
|
|
|
|
globalObject->defineDefaultProperty(rootContext, QStringLiteral("EvalError"), evalErrorCtor);
|
|
|
|
globalObject->defineDefaultProperty(rootContext, QStringLiteral("RangeError"), rangeErrorCtor);
|
|
|
|
globalObject->defineDefaultProperty(rootContext, QStringLiteral("ReferenceError"), referenceErrorCtor);
|
|
|
|
globalObject->defineDefaultProperty(rootContext, QStringLiteral("SyntaxError"), syntaxErrorCtor);
|
|
|
|
globalObject->defineDefaultProperty(rootContext, QStringLiteral("TypeError"), typeErrorCtor);
|
|
|
|
globalObject->defineDefaultProperty(rootContext, QStringLiteral("URIError"), uRIErrorCtor);
|
|
|
|
globalObject->defineDefaultProperty(rootContext, QStringLiteral("Math"), Value::fromObject(new (memoryManager) MathObject(rootContext)));
|
|
|
|
globalObject->defineDefaultProperty(rootContext, QStringLiteral("JSON"), Value::fromObject(new (memoryManager) JsonObject(rootContext)));
|
|
|
|
|
|
|
|
globalObject->defineReadonlyProperty(this, QStringLiteral("undefined"), Value::undefinedValue());
|
|
|
|
globalObject->defineReadonlyProperty(this, QStringLiteral("NaN"), Value::fromDouble(std::numeric_limits<double>::quiet_NaN()));
|
|
|
|
globalObject->defineReadonlyProperty(this, QStringLiteral("Infinity"), Value::fromDouble(Q_INFINITY));
|
2012-12-12 23:53:04 +00:00
|
|
|
|
2013-01-23 09:07:18 +00:00
|
|
|
evalFunction = new (memoryManager) EvalFunction(rootContext);
|
2013-04-08 07:08:02 +00:00
|
|
|
globalObject->defineDefaultProperty(rootContext, QStringLiteral("eval"), Value::fromObject(evalFunction));
|
|
|
|
|
|
|
|
globalObject->defineDefaultProperty(rootContext, QStringLiteral("parseInt"), GlobalFunctions::method_parseInt, 2);
|
|
|
|
globalObject->defineDefaultProperty(rootContext, QStringLiteral("parseFloat"), GlobalFunctions::method_parseFloat, 1);
|
|
|
|
globalObject->defineDefaultProperty(rootContext, QStringLiteral("isNaN"), GlobalFunctions::method_isNaN, 1);
|
|
|
|
globalObject->defineDefaultProperty(rootContext, QStringLiteral("isFinite"), GlobalFunctions::method_isFinite, 1);
|
|
|
|
globalObject->defineDefaultProperty(rootContext, QStringLiteral("decodeURI"), GlobalFunctions::method_decodeURI, 1);
|
|
|
|
globalObject->defineDefaultProperty(rootContext, QStringLiteral("decodeURIComponent"), GlobalFunctions::method_decodeURIComponent, 1);
|
|
|
|
globalObject->defineDefaultProperty(rootContext, QStringLiteral("encodeURI"), GlobalFunctions::method_encodeURI, 1);
|
|
|
|
globalObject->defineDefaultProperty(rootContext, QStringLiteral("encodeURIComponent"), GlobalFunctions::method_encodeURIComponent, 1);
|
|
|
|
globalObject->defineDefaultProperty(rootContext, QStringLiteral("escape"), GlobalFunctions::method_escape, 1);
|
|
|
|
globalObject->defineDefaultProperty(rootContext, QStringLiteral("unescape"), GlobalFunctions::method_unescape, 1);
|
2012-11-17 20:54:26 +00:00
|
|
|
}
|
|
|
|
|
2012-12-04 10:30:26 +00:00
|
|
|
ExecutionEngine::~ExecutionEngine()
|
|
|
|
{
|
2013-05-06 11:29:24 +00:00
|
|
|
emptyClass->destroy();
|
2013-04-22 18:00:14 +00:00
|
|
|
delete identifierCache;
|
2013-04-19 09:47:50 +00:00
|
|
|
delete bumperPointerAllocator;
|
2013-03-30 16:43:03 +00:00
|
|
|
delete regExpCache;
|
2013-03-04 14:30:40 +00:00
|
|
|
UnwindHelper::deregisterFunctions(functions);
|
2012-12-11 09:03:40 +00:00
|
|
|
qDeleteAll(functions);
|
2013-01-03 11:26:19 +00:00
|
|
|
delete memoryManager;
|
2013-05-12 10:07:15 +00:00
|
|
|
delete regExpAllocator;
|
2013-03-25 16:31:38 +00:00
|
|
|
delete executableAllocator;
|
2012-12-04 10:30:26 +00:00
|
|
|
}
|
|
|
|
|
2013-03-14 13:03:04 +00:00
|
|
|
void ExecutionEngine::initRootContext()
|
|
|
|
{
|
2013-04-05 11:27:38 +00:00
|
|
|
rootContext = static_cast<GlobalContext *>(memoryManager->allocContext(sizeof(GlobalContext)));
|
2013-03-14 13:03:04 +00:00
|
|
|
current = rootContext;
|
2013-04-07 15:23:36 +00:00
|
|
|
current->parent = 0;
|
2013-05-13 08:25:01 +00:00
|
|
|
rootContext->initGlobalContext(this);
|
2013-03-14 13:03:04 +00:00
|
|
|
}
|
|
|
|
|
2013-05-06 11:29:24 +00:00
|
|
|
InternalClass *ExecutionEngine::newClass(const InternalClass &other)
|
|
|
|
{
|
|
|
|
return new (classPool.allocate(sizeof(InternalClass))) InternalClass(other);
|
|
|
|
}
|
|
|
|
|
2013-04-05 11:27:38 +00:00
|
|
|
WithContext *ExecutionEngine::newWithContext(Object *with)
|
2012-11-17 20:54:26 +00:00
|
|
|
{
|
2013-04-05 11:27:38 +00:00
|
|
|
ExecutionContext *p = current;
|
|
|
|
WithContext *w = static_cast<WithContext *>(memoryManager->allocContext(sizeof(WithContext)));
|
2013-05-13 08:25:01 +00:00
|
|
|
w->initWithContext(p, with);
|
2013-04-07 15:23:36 +00:00
|
|
|
w->parent = current;
|
2013-04-05 11:27:38 +00:00
|
|
|
current = w;
|
|
|
|
return w;
|
2013-03-14 11:59:11 +00:00
|
|
|
}
|
|
|
|
|
2013-04-05 11:27:38 +00:00
|
|
|
CatchContext *ExecutionEngine::newCatchContext(String *exceptionVarName, const Value &exceptionValue)
|
2013-03-14 11:59:11 +00:00
|
|
|
{
|
2013-04-05 11:27:38 +00:00
|
|
|
ExecutionContext *p = current;
|
|
|
|
CatchContext *c = static_cast<CatchContext *>(memoryManager->allocContext(sizeof(CatchContext)));
|
2013-05-13 08:25:01 +00:00
|
|
|
c->initCatchContext(p, exceptionVarName, exceptionValue);
|
2013-04-07 15:23:36 +00:00
|
|
|
c->parent = current;
|
2013-04-05 11:27:38 +00:00
|
|
|
current = c;
|
|
|
|
return c;
|
2013-03-14 11:59:11 +00:00
|
|
|
}
|
|
|
|
|
2013-04-05 11:27:38 +00:00
|
|
|
CallContext *ExecutionEngine::newCallContext(FunctionObject *f, const Value &thisObject, Value *args, int argc)
|
2013-03-14 11:59:11 +00:00
|
|
|
{
|
2013-04-05 11:27:38 +00:00
|
|
|
CallContext *c = static_cast<CallContext *>(memoryManager->allocContext(requiredMemoryForExecutionContect(f, argc)));
|
2013-05-13 08:25:01 +00:00
|
|
|
|
|
|
|
c->initCallContext(this, f, args, argc, thisObject);
|
2013-04-07 15:23:36 +00:00
|
|
|
c->parent = current;
|
2013-04-05 11:27:38 +00:00
|
|
|
current = c;
|
2013-04-03 13:59:17 +00:00
|
|
|
|
2013-04-05 11:27:38 +00:00
|
|
|
return c;
|
2013-03-14 13:03:04 +00:00
|
|
|
}
|
|
|
|
|
2013-04-05 11:27:38 +00:00
|
|
|
CallContext *ExecutionEngine::newCallContext(void *stackSpace, FunctionObject *f, const Value &thisObject, Value *args, int argc)
|
2013-04-03 18:24:38 +00:00
|
|
|
{
|
2013-04-05 11:27:38 +00:00
|
|
|
CallContext *c;
|
2013-04-03 18:24:38 +00:00
|
|
|
uint memory = requiredMemoryForExecutionContect(f, argc);
|
|
|
|
if (f->needsActivation || memory > stackContextSize) {
|
2013-04-05 11:27:38 +00:00
|
|
|
c = static_cast<CallContext *>(memoryManager->allocContext(memory));
|
2013-04-03 18:24:38 +00:00
|
|
|
} else {
|
2013-04-05 11:27:38 +00:00
|
|
|
c = (CallContext *)stackSpace;
|
2013-04-03 18:24:38 +00:00
|
|
|
#ifndef QT_NO_DEBUG
|
2013-04-05 11:27:38 +00:00
|
|
|
c->next = (CallContext *)0x1;
|
2013-04-03 18:24:38 +00:00
|
|
|
#endif
|
|
|
|
}
|
2013-05-13 08:25:01 +00:00
|
|
|
|
|
|
|
c->initCallContext(this, f, args, argc, thisObject);
|
2013-04-07 15:23:36 +00:00
|
|
|
c->parent = current;
|
2013-04-05 11:27:38 +00:00
|
|
|
current = c;
|
2013-04-03 18:24:38 +00:00
|
|
|
|
2013-04-05 11:27:38 +00:00
|
|
|
return c;
|
2013-04-03 18:24:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-14 13:03:04 +00:00
|
|
|
ExecutionContext *ExecutionEngine::pushGlobalContext()
|
|
|
|
{
|
2013-04-07 15:23:36 +00:00
|
|
|
GlobalContext *g = static_cast<GlobalContext *>(memoryManager->allocContext(sizeof(GlobalContext)));
|
|
|
|
*g = *rootContext;
|
|
|
|
g->parent = current;
|
|
|
|
current = g;
|
2013-03-14 13:03:04 +00:00
|
|
|
|
2013-03-14 11:59:11 +00:00
|
|
|
return current;
|
2012-11-17 20:54:26 +00:00
|
|
|
}
|
|
|
|
|
2012-12-11 09:03:40 +00:00
|
|
|
Function *ExecutionEngine::newFunction(const QString &name)
|
|
|
|
{
|
2013-04-19 11:03:42 +00:00
|
|
|
Function *f = new Function(newIdentifier(name));
|
2012-12-11 09:03:40 +00:00
|
|
|
functions.append(f);
|
|
|
|
return f;
|
|
|
|
}
|
|
|
|
|
2013-04-05 19:15:58 +00:00
|
|
|
FunctionObject *ExecutionEngine::newBuiltinFunction(ExecutionContext *scope, String *name, Value (*code)(SimpleCallContext *))
|
2013-01-29 20:23:19 +00:00
|
|
|
{
|
|
|
|
BuiltinFunctionOld *f = new (memoryManager) BuiltinFunctionOld(scope, name, code);
|
|
|
|
return f;
|
|
|
|
}
|
|
|
|
|
2013-04-19 11:03:42 +00:00
|
|
|
FunctionObject *ExecutionEngine::newScriptFunction(ExecutionContext *scope, Function *function)
|
2012-11-17 20:54:26 +00:00
|
|
|
{
|
2012-12-11 09:03:40 +00:00
|
|
|
assert(function);
|
|
|
|
|
2012-12-04 12:40:18 +00:00
|
|
|
ScriptFunction *f = new (memoryManager) ScriptFunction(scope, function);
|
2012-11-17 20:54:26 +00:00
|
|
|
return f;
|
|
|
|
}
|
|
|
|
|
2013-01-13 22:57:35 +00:00
|
|
|
BoundFunction *ExecutionEngine::newBoundFunction(ExecutionContext *scope, FunctionObject *target, Value boundThis, const QVector<Value> &boundArgs)
|
|
|
|
{
|
|
|
|
assert(target);
|
|
|
|
|
|
|
|
BoundFunction *f = new (memoryManager) BoundFunction(scope, target, boundThis, boundArgs);
|
|
|
|
return f;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-11-17 20:54:26 +00:00
|
|
|
Object *ExecutionEngine::newObject()
|
|
|
|
{
|
2013-02-10 21:22:53 +00:00
|
|
|
Object *object = new (memoryManager) Object(this);
|
2012-11-17 20:54:26 +00:00
|
|
|
object->prototype = objectPrototype;
|
|
|
|
return object;
|
|
|
|
}
|
|
|
|
|
2013-04-23 05:31:02 +00:00
|
|
|
Object *ExecutionEngine::newObject(InternalClass *internalClass)
|
|
|
|
{
|
|
|
|
Object *object = new (memoryManager) Object(this, internalClass);
|
|
|
|
object->prototype = objectPrototype;
|
|
|
|
return object;
|
|
|
|
}
|
|
|
|
|
2012-11-17 20:54:26 +00:00
|
|
|
String *ExecutionEngine::newString(const QString &s)
|
|
|
|
{
|
2013-05-06 09:37:53 +00:00
|
|
|
return new (memoryManager) String(this, s);
|
2012-11-17 20:54:26 +00:00
|
|
|
}
|
|
|
|
|
2013-01-30 13:56:40 +00:00
|
|
|
String *ExecutionEngine::newIdentifier(const QString &text)
|
|
|
|
{
|
|
|
|
return identifierCache->insert(text);
|
|
|
|
}
|
|
|
|
|
2013-05-02 19:37:20 +00:00
|
|
|
Object *ExecutionEngine::newStringObject(const Value &value)
|
2012-11-17 20:54:26 +00:00
|
|
|
{
|
2013-05-02 19:37:20 +00:00
|
|
|
StringObject *object = new (memoryManager) StringObject(this, value);
|
2012-11-17 20:54:26 +00:00
|
|
|
object->prototype = stringPrototype;
|
|
|
|
return object;
|
|
|
|
}
|
|
|
|
|
|
|
|
Object *ExecutionEngine::newNumberObject(const Value &value)
|
|
|
|
{
|
2013-02-10 21:22:53 +00:00
|
|
|
NumberObject *object = new (memoryManager) NumberObject(this, value);
|
2012-11-17 20:54:26 +00:00
|
|
|
object->prototype = numberPrototype;
|
|
|
|
return object;
|
|
|
|
}
|
|
|
|
|
|
|
|
Object *ExecutionEngine::newBooleanObject(const Value &value)
|
|
|
|
{
|
2013-02-10 21:22:53 +00:00
|
|
|
Object *object = new (memoryManager) BooleanObject(this, value);
|
2012-11-17 20:54:26 +00:00
|
|
|
object->prototype = booleanPrototype;
|
|
|
|
return object;
|
|
|
|
}
|
|
|
|
|
2013-05-02 20:33:47 +00:00
|
|
|
ArrayObject *ExecutionEngine::newArrayObject()
|
2012-11-17 20:54:26 +00:00
|
|
|
{
|
2013-05-02 20:33:47 +00:00
|
|
|
ArrayObject *object = new (memoryManager) ArrayObject(this);
|
|
|
|
object->prototype = arrayPrototype;
|
2012-11-17 20:54:26 +00:00
|
|
|
return object;
|
|
|
|
}
|
|
|
|
|
2013-05-02 20:33:47 +00:00
|
|
|
ArrayObject *ExecutionEngine::newArrayObject(const QStringList &list)
|
2012-11-17 20:54:26 +00:00
|
|
|
{
|
2013-05-02 20:33:47 +00:00
|
|
|
ArrayObject *object = new (memoryManager) ArrayObject(this, list);
|
2012-11-17 20:54:26 +00:00
|
|
|
object->prototype = arrayPrototype;
|
|
|
|
return object;
|
|
|
|
}
|
|
|
|
|
2013-04-30 21:02:33 +00:00
|
|
|
DateObject *ExecutionEngine::newDateObject(const Value &value)
|
2012-11-17 20:54:26 +00:00
|
|
|
{
|
2013-04-30 21:02:33 +00:00
|
|
|
DateObject *object = new (memoryManager) DateObject(this, value);
|
2012-11-17 20:54:26 +00:00
|
|
|
object->prototype = datePrototype;
|
|
|
|
return object;
|
|
|
|
}
|
|
|
|
|
2013-05-02 20:33:47 +00:00
|
|
|
DateObject *ExecutionEngine::newDateObject(const QDateTime &dt)
|
|
|
|
{
|
|
|
|
DateObject *object = new (memoryManager) DateObject(this, dt);
|
|
|
|
object->prototype = datePrototype;
|
|
|
|
return object;
|
|
|
|
}
|
|
|
|
|
2012-12-12 07:28:08 +00:00
|
|
|
RegExpObject *ExecutionEngine::newRegExpObject(const QString &pattern, int flags)
|
2012-11-17 20:54:26 +00:00
|
|
|
{
|
2013-04-19 11:03:42 +00:00
|
|
|
bool global = (flags & QQmlJS::V4IR::RegExp::RegExp_Global);
|
2013-01-14 15:53:43 +00:00
|
|
|
bool ignoreCase = false;
|
|
|
|
bool multiline = false;
|
2013-04-19 11:03:42 +00:00
|
|
|
if (flags & QQmlJS::V4IR::RegExp::RegExp_IgnoreCase)
|
2013-01-14 15:53:43 +00:00
|
|
|
ignoreCase = true;
|
2013-04-19 11:03:42 +00:00
|
|
|
if (flags & QQmlJS::V4IR::RegExp::RegExp_Multiline)
|
2013-01-14 15:53:43 +00:00
|
|
|
multiline = true;
|
2012-11-17 20:54:26 +00:00
|
|
|
|
2013-01-14 15:53:43 +00:00
|
|
|
return newRegExpObject(RegExp::create(this, pattern, ignoreCase, multiline), global);
|
2012-12-12 07:28:08 +00:00
|
|
|
}
|
|
|
|
|
2013-03-30 16:05:32 +00:00
|
|
|
RegExpObject *ExecutionEngine::newRegExpObject(RegExp* re, bool global)
|
2012-12-12 07:28:08 +00:00
|
|
|
{
|
2013-01-17 14:24:58 +00:00
|
|
|
RegExpObject *object = new (memoryManager) RegExpObject(this, re, global);
|
2012-11-17 20:54:26 +00:00
|
|
|
object->prototype = regExpPrototype;
|
|
|
|
return object;
|
|
|
|
}
|
|
|
|
|
2013-05-02 20:33:47 +00:00
|
|
|
RegExpObject *ExecutionEngine::newRegExpObject(const QRegExp &re)
|
|
|
|
{
|
|
|
|
RegExpObject *object = new (memoryManager) RegExpObject(this, re);
|
|
|
|
object->prototype = regExpPrototype;
|
|
|
|
return object;
|
|
|
|
}
|
|
|
|
|
2012-11-17 20:54:26 +00:00
|
|
|
Object *ExecutionEngine::newErrorObject(const Value &value)
|
|
|
|
{
|
2013-05-02 19:37:20 +00:00
|
|
|
ErrorObject *object = new (memoryManager) ErrorObject(this, value);
|
2012-11-17 20:54:26 +00:00
|
|
|
object->prototype = errorPrototype;
|
|
|
|
return object;
|
|
|
|
}
|
|
|
|
|
2012-11-28 10:00:23 +00:00
|
|
|
Object *ExecutionEngine::newSyntaxErrorObject(ExecutionContext *ctx, DiagnosticMessage *message)
|
|
|
|
{
|
2013-01-14 16:13:25 +00:00
|
|
|
return new (memoryManager) SyntaxErrorObject(ctx, message);
|
2012-11-28 10:00:23 +00:00
|
|
|
}
|
|
|
|
|
2013-05-02 19:37:20 +00:00
|
|
|
Object *ExecutionEngine::newSyntaxErrorObject(const QString &message)
|
2012-12-04 18:50:25 +00:00
|
|
|
{
|
2013-05-02 19:37:20 +00:00
|
|
|
return new (memoryManager) SyntaxErrorObject(this, message);
|
2012-12-04 18:50:25 +00:00
|
|
|
}
|
|
|
|
|
2013-05-02 19:37:20 +00:00
|
|
|
|
|
|
|
Object *ExecutionEngine::newReferenceErrorObject(const QString &message)
|
|
|
|
{
|
|
|
|
return new (memoryManager) ReferenceErrorObject(this, message);
|
|
|
|
}
|
|
|
|
|
|
|
|
Object *ExecutionEngine::newTypeErrorObject(const QString &message)
|
2012-12-04 18:50:25 +00:00
|
|
|
{
|
2013-05-02 19:37:20 +00:00
|
|
|
return new (memoryManager) TypeErrorObject(this, message);
|
2012-12-04 18:50:25 +00:00
|
|
|
}
|
|
|
|
|
2013-05-02 19:37:20 +00:00
|
|
|
Object *ExecutionEngine::newRangeErrorObject(const QString &message)
|
2013-01-11 08:56:56 +00:00
|
|
|
{
|
2013-05-02 19:37:20 +00:00
|
|
|
return new (memoryManager) RangeErrorObject(this, message);
|
2013-01-11 08:56:56 +00:00
|
|
|
}
|
|
|
|
|
2013-05-02 19:37:20 +00:00
|
|
|
Object *ExecutionEngine::newURIErrorObject(Value message)
|
2013-01-22 14:13:15 +00:00
|
|
|
{
|
2013-05-02 19:37:20 +00:00
|
|
|
return new (memoryManager) URIErrorObject(this, message);
|
2013-01-22 14:13:15 +00:00
|
|
|
}
|
|
|
|
|
2013-05-14 00:01:04 +00:00
|
|
|
Object *ExecutionEngine::newVariantObject(const QVariant &v)
|
|
|
|
{
|
|
|
|
return new (memoryManager) VariantObject(this, v);
|
|
|
|
}
|
|
|
|
|
2013-01-10 16:33:06 +00:00
|
|
|
Object *ExecutionEngine::newForEachIteratorObject(ExecutionContext *ctx, Object *o)
|
2012-11-17 20:54:26 +00:00
|
|
|
{
|
2013-01-10 16:33:06 +00:00
|
|
|
return new (memoryManager) ForEachIteratorObject(ctx, o);
|
2013-05-03 14:51:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Object *ExecutionEngine::qmlContextObject() const
|
|
|
|
{
|
|
|
|
ExecutionContext *ctx = current;
|
|
|
|
if (!ctx->outer)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
while (ctx->outer && ctx->outer->type != ExecutionContext::Type_GlobalContext)
|
|
|
|
ctx = ctx->outer;
|
|
|
|
|
|
|
|
assert(ctx);
|
|
|
|
if (ctx->type != ExecutionContext::Type_QmlContext)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return static_cast<CallContext *>(ctx)->activation;
|
2012-11-17 20:54:26 +00:00
|
|
|
}
|
|
|
|
|
2013-01-18 11:47:43 +00:00
|
|
|
void ExecutionEngine::requireArgumentsAccessors(int n)
|
|
|
|
{
|
|
|
|
if (n <= argumentsAccessors.size())
|
|
|
|
return;
|
|
|
|
|
|
|
|
uint oldSize = argumentsAccessors.size();
|
|
|
|
argumentsAccessors.resize(n);
|
|
|
|
for (int i = oldSize; i < n; ++i) {
|
|
|
|
FunctionObject *get = new (memoryManager) ArgumentsGetterFunction(rootContext, i);
|
|
|
|
get->prototype = functionPrototype;
|
|
|
|
FunctionObject *set = new (memoryManager) ArgumentsSetterFunction(rootContext, i);
|
|
|
|
set->prototype = functionPrototype;
|
2013-04-10 08:46:23 +00:00
|
|
|
Property pd = Property::fromAccessor(get, set);
|
2013-01-18 11:47:43 +00:00
|
|
|
argumentsAccessors[i] = pd;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-28 15:46:09 +00:00
|
|
|
void ExecutionEngine::markObjects()
|
|
|
|
{
|
2013-01-30 13:56:40 +00:00
|
|
|
identifierCache->mark();
|
|
|
|
|
2013-04-08 07:08:02 +00:00
|
|
|
globalObject->mark();
|
2013-01-28 15:46:09 +00:00
|
|
|
|
|
|
|
if (globalCode)
|
|
|
|
globalCode->mark();
|
|
|
|
|
|
|
|
for (int i = 0; i < argumentsAccessors.size(); ++i) {
|
2013-04-10 08:46:23 +00:00
|
|
|
const Property &pd = argumentsAccessors.at(i);
|
|
|
|
pd.getter()->mark();
|
|
|
|
pd.setter()->mark();
|
2013-01-28 15:46:09 +00:00
|
|
|
}
|
|
|
|
|
2013-04-07 15:23:36 +00:00
|
|
|
ExecutionContext *c = current;
|
|
|
|
while (c) {
|
|
|
|
c->mark();
|
|
|
|
c = c->parent;
|
|
|
|
}
|
2013-01-28 15:46:09 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < functions.size(); ++i)
|
|
|
|
functions.at(i)->mark();
|
|
|
|
|
|
|
|
id_length->mark();
|
|
|
|
id_prototype->mark();
|
|
|
|
id_constructor->mark();
|
|
|
|
id_arguments->mark();
|
|
|
|
id_caller->mark();
|
|
|
|
id_this->mark();
|
|
|
|
id___proto__->mark();
|
|
|
|
id_enumerable->mark();
|
|
|
|
id_configurable->mark();
|
|
|
|
id_writable->mark();
|
|
|
|
id_value->mark();
|
|
|
|
id_get->mark();
|
|
|
|
id_set->mark();
|
|
|
|
id_eval->mark();
|
2013-05-03 20:40:58 +00:00
|
|
|
id_uintMax->mark();
|
2013-05-04 08:26:54 +00:00
|
|
|
id_name->mark();
|
2013-01-28 15:46:09 +00:00
|
|
|
}
|
|
|
|
|
2013-03-05 15:11:22 +00:00
|
|
|
Value ExecutionEngine::run(Function *function, ExecutionContext *ctx)
|
|
|
|
{
|
|
|
|
if (!ctx)
|
|
|
|
ctx = rootContext;
|
|
|
|
|
2013-05-12 12:36:02 +00:00
|
|
|
TemporaryAssignment<Function*> savedGlobalCode(globalCode, function);
|
2013-03-05 15:11:22 +00:00
|
|
|
|
|
|
|
// ### Would be better to have a SavedExecutionState object that
|
|
|
|
// saves this and restores it in the destructor (to survive an exception).
|
|
|
|
ctx->strictMode = function->isStrict;
|
|
|
|
ctx->lookups = function->lookups;
|
|
|
|
|
|
|
|
if (debugger)
|
|
|
|
debugger->aboutToCall(0, ctx);
|
2013-04-19 11:03:42 +00:00
|
|
|
QV4::Value result = function->code(ctx, function->codeData);
|
2013-03-05 15:11:22 +00:00
|
|
|
if (debugger)
|
|
|
|
debugger->justLeft(ctx);
|
|
|
|
return result;
|
|
|
|
}
|