2012-11-17 20:54:26 +00:00
|
|
|
/****************************************************************************
|
|
|
|
**
|
2014-08-22 06:13:59 +00:00
|
|
|
** Copyright (C) 2014 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
|
|
|
**
|
2014-08-22 06:13:59 +00:00
|
|
|
** $QT_BEGIN_LICENSE:LGPL21$
|
2012-11-17 20:54:26 +00:00
|
|
|
** 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
|
2014-08-22 06:13:59 +00:00
|
|
|
** a written agreement between you and Digia. For licensing terms and
|
|
|
|
** conditions see http://qt.digia.com/licensing. For further information
|
2012-11-17 20:54:26 +00:00
|
|
|
** 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
|
2014-08-22 06:13:59 +00:00
|
|
|
** General Public License version 2.1 or version 3 as published by the Free
|
|
|
|
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
|
|
|
|
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
|
|
|
|
** following information to ensure the GNU Lesser General Public License
|
|
|
|
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
|
|
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2012-11-17 20:54:26 +00:00
|
|
|
**
|
|
|
|
** In addition, as a special exception, Digia gives you certain additional
|
2014-08-22 06:13:59 +00:00
|
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
2012-11-17 20:54:26 +00:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
**
|
|
|
|
** $QT_END_LICENSE$
|
|
|
|
**
|
|
|
|
****************************************************************************/
|
2013-04-15 09:50:16 +00:00
|
|
|
#include <qv4engine_p.h>
|
2013-11-21 12:15:46 +00:00
|
|
|
#include <qv4context_p.h>
|
2014-01-24 14:07:34 +00:00
|
|
|
#include <qv4value_inl_p.h>
|
2013-04-15 09:50:16 +00:00
|
|
|
#include <qv4object_p.h>
|
|
|
|
#include <qv4objectproto_p.h>
|
2013-09-30 11:48:05 +00:00
|
|
|
#include <qv4objectiterator_p.h>
|
2013-04-15 09:50:16 +00:00
|
|
|
#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-11-21 13:26:08 +00:00
|
|
|
#include <qv4regexp_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>
|
2013-06-27 21:02:45 +00:00
|
|
|
#include <qv4identifiertable_p.h>
|
2013-04-15 09:50:16 +00:00
|
|
|
#include "qv4debugging_p.h"
|
2014-01-22 16:46:20 +00:00
|
|
|
#include "qv4profiling_p.h"
|
2013-04-15 09:50:16 +00:00
|
|
|
#include "qv4executableallocator_p.h"
|
2013-05-21 15:06:36 +00:00
|
|
|
#include "qv4sequenceobject_p.h"
|
2013-06-07 09:21:18 +00:00
|
|
|
#include "qv4qobjectwrapper_p.h"
|
2013-06-20 09:32:45 +00:00
|
|
|
#include "qv4qmlextensions_p.h"
|
2014-03-31 13:48:02 +00:00
|
|
|
#include "qv4memberdata_p.h"
|
2014-09-10 12:50:28 +00:00
|
|
|
#include "qv4arraybuffer_p.h"
|
2014-09-10 14:39:23 +00:00
|
|
|
#include "qv4dataview_p.h"
|
2014-09-11 13:37:31 +00:00
|
|
|
#include "qv4typedarray_p.h"
|
2013-05-28 07:36:04 +00:00
|
|
|
|
2013-12-20 14:38:37 +00:00
|
|
|
#include <QtCore/QTextStream>
|
2014-06-13 12:30:03 +00:00
|
|
|
#include <QDateTime>
|
2013-12-20 14:38:37 +00:00
|
|
|
|
2013-05-07 09:54:45 +00:00
|
|
|
#ifdef V4_ENABLE_JIT
|
2013-07-24 08:29:04 +00:00
|
|
|
#include "qv4isel_masm_p.h"
|
2013-05-07 09:54:45 +00:00
|
|
|
#endif // V4_ENABLE_JIT
|
|
|
|
|
2013-07-24 08:29:04 +00:00
|
|
|
#include "qv4isel_moth_p.h"
|
|
|
|
|
2013-11-11 10:22:24 +00:00
|
|
|
#if USE(PTHREADS)
|
|
|
|
# include <pthread.h>
|
2013-12-17 15:11:19 +00:00
|
|
|
# include <sys/resource.h>
|
2014-01-21 09:55:18 +00:00
|
|
|
#if HAVE(PTHREAD_NP_H)
|
|
|
|
# include <pthread_np.h>
|
|
|
|
#endif
|
2013-11-11 10:22:24 +00:00
|
|
|
#endif
|
|
|
|
|
2013-06-24 13:28:00 +00:00
|
|
|
QT_BEGIN_NAMESPACE
|
|
|
|
|
2013-04-19 11:03:42 +00:00
|
|
|
using namespace QV4;
|
2012-11-17 20:54:26 +00:00
|
|
|
|
2013-06-04 08:05:51 +00:00
|
|
|
static QBasicAtomicInt engineSerial = Q_BASIC_ATOMIC_INITIALIZER(1);
|
|
|
|
|
2013-11-03 14:23:05 +00:00
|
|
|
static ReturnedValue throwTypeError(CallContext *ctx)
|
2013-09-18 07:30:45 +00:00
|
|
|
{
|
2014-07-28 08:07:57 +00:00
|
|
|
return ctx->engine()->throwTypeError();
|
2013-09-18 07:30:45 +00:00
|
|
|
}
|
|
|
|
|
2014-09-11 15:00:06 +00:00
|
|
|
const int MinimumStackSize = 256; // in kbytes
|
|
|
|
|
2013-11-11 10:22:24 +00:00
|
|
|
quintptr getStackLimit()
|
|
|
|
{
|
|
|
|
quintptr stackLimit;
|
2013-11-19 10:29:34 +00:00
|
|
|
#if USE(PTHREADS) && !OS(QNX)
|
2013-11-11 10:22:24 +00:00
|
|
|
# if OS(DARWIN)
|
|
|
|
pthread_t thread_self = pthread_self();
|
|
|
|
void *stackTop = pthread_get_stackaddr_np(thread_self);
|
|
|
|
stackLimit = reinterpret_cast<quintptr>(stackTop);
|
2013-11-20 16:17:01 +00:00
|
|
|
quintptr size = 0;
|
|
|
|
if (pthread_main_np()) {
|
|
|
|
rlimit limit;
|
|
|
|
getrlimit(RLIMIT_STACK, &limit);
|
|
|
|
size = limit.rlim_cur;
|
|
|
|
} else
|
|
|
|
size = pthread_get_stacksize_np(thread_self);
|
|
|
|
stackLimit -= size;
|
2013-11-11 10:22:24 +00:00
|
|
|
# else
|
|
|
|
void* stackBottom = 0;
|
|
|
|
pthread_attr_t attr;
|
2014-01-21 09:55:18 +00:00
|
|
|
#if HAVE(PTHREAD_NP_H) && OS(FREEBSD)
|
|
|
|
if (pthread_attr_get_np(pthread_self(), &attr) == 0) {
|
|
|
|
#else
|
2014-01-13 10:09:34 +00:00
|
|
|
if (pthread_getattr_np(pthread_self(), &attr) == 0) {
|
2014-01-21 09:55:18 +00:00
|
|
|
#endif
|
2014-01-13 10:09:34 +00:00
|
|
|
size_t stackSize = 0;
|
|
|
|
pthread_attr_getstack(&attr, &stackBottom, &stackSize);
|
|
|
|
pthread_attr_destroy(&attr);
|
2013-11-11 10:22:24 +00:00
|
|
|
|
2014-01-13 10:09:34 +00:00
|
|
|
# if defined(Q_OS_ANDROID)
|
|
|
|
// Bionic pretends that the main thread has a tiny stack; work around it
|
|
|
|
if (gettid() == getpid()) {
|
|
|
|
rlimit limit;
|
|
|
|
getrlimit(RLIMIT_STACK, &limit);
|
|
|
|
stackBottom = reinterpret_cast<void*>(reinterpret_cast<quintptr>(stackBottom) + stackSize - limit.rlim_cur);
|
|
|
|
}
|
|
|
|
# endif
|
|
|
|
|
|
|
|
stackLimit = reinterpret_cast<quintptr>(stackBottom);
|
|
|
|
} else {
|
|
|
|
int dummy;
|
|
|
|
// this is inexact, as part of the stack is used when being called here,
|
|
|
|
// but let's simply default to 1MB from where the stack is right now
|
|
|
|
stackLimit = reinterpret_cast<qintptr>(&dummy) - 1024*1024;
|
2013-12-17 15:11:19 +00:00
|
|
|
}
|
|
|
|
|
2013-11-11 10:22:24 +00:00
|
|
|
# endif
|
|
|
|
// This is wrong. StackLimit is the currently committed stack size, not the real end.
|
|
|
|
// only way to get that limit is apparently by using VirtualQuery (Yuck)
|
|
|
|
//#elif OS(WINDOWS)
|
|
|
|
// PNT_TIB tib = (PNT_TIB)NtCurrentTeb();
|
|
|
|
// stackLimit = static_cast<quintptr>(tib->StackLimit);
|
|
|
|
#else
|
|
|
|
int dummy;
|
|
|
|
// this is inexact, as part of the stack is used when being called here,
|
|
|
|
// but let's simply default to 1MB from where the stack is right now
|
|
|
|
stackLimit = reinterpret_cast<qintptr>(&dummy) - 1024*1024;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// 256k slack
|
2014-09-11 15:00:06 +00:00
|
|
|
return stackLimit + MinimumStackSize*1024;
|
2013-11-11 10:22:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-02-14 12:58:40 +00:00
|
|
|
ExecutionEngine::ExecutionEngine(EvalISelFactory *factory)
|
2014-02-05 15:12:16 +00:00
|
|
|
: current(0)
|
|
|
|
, memoryManager(new QV4::MemoryManager)
|
2013-04-19 11:03:42 +00:00
|
|
|
, 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)
|
2013-09-03 10:40:07 +00:00
|
|
|
, jsStack(new WTF::PageAllocation)
|
2012-11-29 13:41:26 +00:00
|
|
|
, debugger(0)
|
2014-01-22 16:46:20 +00:00
|
|
|
, profiler(0)
|
2013-04-08 07:08:02 +00:00
|
|
|
, globalObject(0)
|
2013-01-28 15:46:09 +00:00
|
|
|
, globalCode(0)
|
2013-11-29 13:26:52 +00:00
|
|
|
, v8Engine(0)
|
2014-03-10 14:18:54 +00:00
|
|
|
, argumentsAccessors(0)
|
|
|
|
, nArgumentsAccessors(0)
|
2013-06-04 08:05:51 +00:00
|
|
|
, m_engineId(engineSerial.fetchAndAddOrdered(1))
|
2013-03-30 16:43:03 +00:00
|
|
|
, regExpCache(0)
|
2013-06-04 12:28:13 +00:00
|
|
|
, m_multiplyWrappedQObjects(0)
|
2013-06-20 09:32:45 +00:00
|
|
|
, m_qmlExtensions(0)
|
2012-11-17 20:54:26 +00:00
|
|
|
{
|
2012-12-04 12:40:18 +00:00
|
|
|
MemoryManager::GCBlocker gcBlocker(memoryManager);
|
|
|
|
|
2013-09-23 13:52:10 +00:00
|
|
|
exceptionValue = Encode::undefined();
|
2013-09-11 11:23:21 +00:00
|
|
|
hasException = false;
|
2013-09-23 13:52:10 +00:00
|
|
|
|
2013-05-07 09:54:45 +00:00
|
|
|
if (!factory) {
|
2013-09-09 14:07:01 +00:00
|
|
|
|
2013-08-12 14:45:47 +00:00
|
|
|
#ifdef V4_ENABLE_JIT
|
2013-09-09 14:07:01 +00:00
|
|
|
static const bool forceMoth = !qgetenv("QV4_FORCE_INTERPRETER").isEmpty();
|
|
|
|
if (forceMoth)
|
2014-02-14 12:58:40 +00:00
|
|
|
factory = new Moth::ISelFactory;
|
2013-09-09 14:07:01 +00:00
|
|
|
else
|
2014-02-14 12:58:40 +00:00
|
|
|
factory = new JIT::ISelFactory;
|
2013-05-07 09:54:45 +00:00
|
|
|
#else // !V4_ENABLE_JIT
|
2014-02-14 12:58:40 +00:00
|
|
|
factory = new Moth::ISelFactory;
|
2013-05-07 09:54:45 +00:00
|
|
|
#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-11-11 10:22:24 +00:00
|
|
|
// reserve space for the JS stack
|
|
|
|
// we allow it to grow to 2 times JSStackLimit, as we can overshoot due to garbage collection
|
|
|
|
// and ScopedValues allocated outside of JIT'ed methods.
|
2014-10-22 10:34:47 +00:00
|
|
|
*jsStack = WTF::PageAllocation::allocate(2 * JSStackLimit, WTF::OSAllocator::JSVMStackPages,
|
|
|
|
/* writable */ true, /* executable */ false,
|
|
|
|
/* includesGuardPages */ true);
|
2014-01-24 21:55:39 +00:00
|
|
|
jsStackBase = (Value *)jsStack->base();
|
2013-09-03 10:40:07 +00:00
|
|
|
jsStackTop = jsStackBase;
|
|
|
|
|
2013-11-11 10:22:24 +00:00
|
|
|
// set up stack limits
|
2014-01-24 21:55:39 +00:00
|
|
|
jsStackLimit = jsStackBase + JSStackLimit/sizeof(Value);
|
2013-11-11 10:22:24 +00:00
|
|
|
cStackLimit = getStackLimit();
|
2014-09-11 15:00:06 +00:00
|
|
|
if (!recheckCStackLimits())
|
|
|
|
qFatal("Fatal: Not enough stack space available for QML. Please increase the process stack size to more than %d KBytes.", MinimumStackSize);
|
2013-11-11 10:22:24 +00:00
|
|
|
|
2013-09-26 11:05:25 +00:00
|
|
|
Scope scope(this);
|
|
|
|
|
2013-06-27 06:57:47 +00:00
|
|
|
identifierTable = new IdentifierTable(this);
|
2013-01-30 13:56:40 +00:00
|
|
|
|
2014-04-16 07:36:38 +00:00
|
|
|
classPool = new InternalClassPool;
|
|
|
|
|
|
|
|
emptyClass = new (classPool) InternalClass(this);
|
2014-01-20 12:51:00 +00:00
|
|
|
executionContextClass = InternalClass::create(this, ExecutionContext::staticVTable(), 0);
|
2014-03-26 07:53:59 +00:00
|
|
|
constructClass = InternalClass::create(this, Object::staticVTable(), 0);
|
2014-01-20 12:51:00 +00:00
|
|
|
stringClass = InternalClass::create(this, String::staticVTable(), 0);
|
|
|
|
regExpValueClass = InternalClass::create(this, RegExp::staticVTable(), 0);
|
2013-05-12 13:00:48 +00:00
|
|
|
|
2014-03-17 11:45:41 +00:00
|
|
|
id_empty = newIdentifier(QString());
|
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"));
|
2013-08-16 06:53:47 +00:00
|
|
|
id_callee = newIdentifier(QStringLiteral("callee"));
|
2013-01-30 13:56:40 +00:00
|
|
|
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"));
|
2013-09-02 12:25:15 +00:00
|
|
|
id_index = newIdentifier(QStringLiteral("index"));
|
|
|
|
id_input = newIdentifier(QStringLiteral("input"));
|
2013-09-18 13:34:13 +00:00
|
|
|
id_toString = newIdentifier(QStringLiteral("toString"));
|
2014-02-27 21:59:39 +00:00
|
|
|
id_destroy = newIdentifier(QStringLiteral("destroy"));
|
2013-09-18 13:34:13 +00:00
|
|
|
id_valueOf = newIdentifier(QStringLiteral("valueOf"));
|
2014-09-10 12:50:28 +00:00
|
|
|
id_byteLength = newIdentifier(QStringLiteral("byteLength"));
|
2014-09-10 14:39:23 +00:00
|
|
|
id_byteOffset = newIdentifier(QStringLiteral("byteOffset"));
|
|
|
|
id_buffer = newIdentifier(QStringLiteral("buffer"));
|
2012-11-17 20:54:26 +00:00
|
|
|
|
2014-03-31 13:48:02 +00:00
|
|
|
memberDataClass = InternalClass::create(this, MemberData::staticVTable(), 0);
|
|
|
|
|
2014-06-13 12:30:03 +00:00
|
|
|
ScopedObject objectPrototype(scope, memoryManager->alloc<ObjectPrototype>(InternalClass::create(this, ObjectPrototype::staticVTable(), 0)));
|
2014-01-20 12:51:00 +00:00
|
|
|
objectClass = InternalClass::create(this, Object::staticVTable(), objectPrototype);
|
|
|
|
Q_ASSERT(objectClass->vtable == Object::staticVTable());
|
2013-08-29 12:31:32 +00:00
|
|
|
|
2014-01-20 12:51:00 +00:00
|
|
|
arrayClass = InternalClass::create(this, ArrayObject::staticVTable(), objectPrototype);
|
2013-11-21 13:26:08 +00:00
|
|
|
arrayClass = arrayClass->addMember(id_length, Attr_NotConfigurable|Attr_NotEnumerable);
|
2014-06-13 12:30:03 +00:00
|
|
|
ScopedObject arrayPrototype(scope, memoryManager->alloc<ArrayPrototype>(arrayClass));
|
2013-08-29 12:31:32 +00:00
|
|
|
arrayClass = arrayClass->changePrototype(arrayPrototype);
|
|
|
|
|
2014-03-18 07:28:25 +00:00
|
|
|
simpleArrayDataClass = InternalClass::create(this, SimpleArrayData::staticVTable(), 0);
|
|
|
|
|
2014-01-20 12:51:00 +00:00
|
|
|
InternalClass *argsClass = InternalClass::create(this, ArgumentsObject::staticVTable(), objectPrototype);
|
2013-11-21 12:15:46 +00:00
|
|
|
argsClass = argsClass->addMember(id_length, Attr_NotEnumerable);
|
2013-08-16 06:53:47 +00:00
|
|
|
argumentsObjectClass = argsClass->addMember(id_callee, Attr_Data|Attr_NotEnumerable);
|
|
|
|
strictArgumentsObjectClass = argsClass->addMember(id_callee, Attr_Accessor|Attr_NotConfigurable|Attr_NotEnumerable);
|
|
|
|
strictArgumentsObjectClass = strictArgumentsObjectClass->addMember(id_caller, Attr_Accessor|Attr_NotConfigurable|Attr_NotEnumerable);
|
2014-01-20 12:51:00 +00:00
|
|
|
Q_ASSERT(argumentsObjectClass->vtable == ArgumentsObject::staticVTable());
|
|
|
|
Q_ASSERT(strictArgumentsObjectClass->vtable == ArgumentsObject::staticVTable());
|
2013-11-21 12:15:46 +00:00
|
|
|
|
2013-03-14 13:03:04 +00:00
|
|
|
initRootContext();
|
2013-03-04 10:48:49 +00:00
|
|
|
|
2014-06-13 12:30:03 +00:00
|
|
|
ScopedObject stringPrototype(scope, memoryManager->alloc<StringPrototype>(InternalClass::create(this, StringPrototype::staticVTable(), objectPrototype)));
|
2014-01-20 12:51:00 +00:00
|
|
|
stringObjectClass = InternalClass::create(this, String::staticVTable(), stringPrototype);
|
2013-08-29 19:23:04 +00:00
|
|
|
|
2014-06-13 12:30:03 +00:00
|
|
|
ScopedObject numberPrototype(scope, memoryManager->alloc<NumberPrototype>(InternalClass::create(this, NumberPrototype::staticVTable(), objectPrototype)));
|
2014-01-20 12:51:00 +00:00
|
|
|
numberClass = InternalClass::create(this, NumberObject::staticVTable(), numberPrototype);
|
2013-08-29 19:23:04 +00:00
|
|
|
|
2014-06-13 12:30:03 +00:00
|
|
|
ScopedObject booleanPrototype(scope, memoryManager->alloc<BooleanPrototype>(InternalClass::create(this, BooleanPrototype::staticVTable(), objectPrototype)));
|
2014-01-20 12:51:00 +00:00
|
|
|
booleanClass = InternalClass::create(this, BooleanObject::staticVTable(), booleanPrototype);
|
2013-08-29 19:23:04 +00:00
|
|
|
|
2014-06-13 12:30:03 +00:00
|
|
|
ScopedObject datePrototype(scope, memoryManager->alloc<DatePrototype>(InternalClass::create(this, DatePrototype::staticVTable(), objectPrototype)));
|
2014-01-20 12:51:00 +00:00
|
|
|
dateClass = InternalClass::create(this, DateObject::staticVTable(), datePrototype);
|
2013-08-29 19:23:04 +00:00
|
|
|
|
2014-03-31 13:48:02 +00:00
|
|
|
InternalClass *functionProtoClass = InternalClass::create(this, FunctionObject::staticVTable(), objectPrototype);
|
2013-09-01 19:22:57 +00:00
|
|
|
uint index;
|
2014-03-31 13:48:02 +00:00
|
|
|
functionProtoClass = functionProtoClass->addMember(id_prototype, Attr_NotEnumerable, &index);
|
2014-11-03 02:17:57 +00:00
|
|
|
Q_ASSERT(index == Heap::FunctionObject::Index_Prototype);
|
2014-06-13 12:30:03 +00:00
|
|
|
ScopedObject functionPrototype(scope, memoryManager->alloc<FunctionPrototype>(functionProtoClass));
|
2014-03-31 13:48:02 +00:00
|
|
|
functionClass = InternalClass::create(this, FunctionObject::staticVTable(), functionPrototype);
|
2014-03-05 07:40:11 +00:00
|
|
|
functionClass = functionClass->addMember(id_prototype, Attr_NotEnumerable|Attr_NotConfigurable, &index);
|
2014-11-03 02:17:57 +00:00
|
|
|
Q_ASSERT(index == Heap::FunctionObject::Index_Prototype);
|
2013-09-01 19:22:57 +00:00
|
|
|
protoClass = objectClass->addMember(id_constructor, Attr_NotEnumerable, &index);
|
2014-11-03 02:17:57 +00:00
|
|
|
Q_ASSERT(index == Heap::FunctionObject::Index_ProtoConstructor);
|
2013-08-29 19:23:04 +00:00
|
|
|
|
2014-06-13 12:30:03 +00:00
|
|
|
Scoped<RegExpPrototype> regExpPrototype(scope, memoryManager->alloc<RegExpPrototype>(InternalClass::create(this, RegExpPrototype::staticVTable(), objectPrototype)));
|
2014-05-08 20:27:23 +00:00
|
|
|
regExpClass = InternalClass::create(this, RegExpObject::staticVTable(), regExpPrototype.getPointer());
|
2013-09-02 12:25:15 +00:00
|
|
|
regExpExecArrayClass = arrayClass->addMember(id_index, Attr_Data, &index);
|
|
|
|
Q_ASSERT(index == RegExpObject::Index_ArrayIndex);
|
|
|
|
regExpExecArrayClass = regExpExecArrayClass->addMember(id_input, Attr_Data, &index);
|
|
|
|
Q_ASSERT(index == RegExpObject::Index_ArrayInput);
|
2013-08-29 19:23:04 +00:00
|
|
|
|
2014-06-13 12:30:03 +00:00
|
|
|
ScopedObject errorPrototype(scope, memoryManager->alloc<ErrorPrototype>(InternalClass::create(this, ErrorObject::staticVTable(), objectPrototype)));
|
2014-01-20 12:51:00 +00:00
|
|
|
errorClass = InternalClass::create(this, ErrorObject::staticVTable(), errorPrototype);
|
2014-06-13 12:30:03 +00:00
|
|
|
ScopedObject evalErrorPrototype(scope, memoryManager->alloc<EvalErrorPrototype>(errorClass));
|
2014-01-20 12:51:00 +00:00
|
|
|
evalErrorClass = InternalClass::create(this, EvalErrorObject::staticVTable(), evalErrorPrototype);
|
2014-06-13 12:30:03 +00:00
|
|
|
ScopedObject rangeErrorPrototype(scope, memoryManager->alloc<RangeErrorPrototype>(errorClass));
|
2014-01-20 12:51:00 +00:00
|
|
|
rangeErrorClass = InternalClass::create(this, RangeErrorObject::staticVTable(), rangeErrorPrototype);
|
2014-06-13 12:30:03 +00:00
|
|
|
ScopedObject referenceErrorPrototype(scope, memoryManager->alloc<ReferenceErrorPrototype>(errorClass));
|
2014-01-20 12:51:00 +00:00
|
|
|
referenceErrorClass = InternalClass::create(this, ReferenceErrorObject::staticVTable(), referenceErrorPrototype);
|
2014-06-13 12:30:03 +00:00
|
|
|
ScopedObject syntaxErrorPrototype(scope, memoryManager->alloc<SyntaxErrorPrototype>(errorClass));
|
2014-01-20 12:51:00 +00:00
|
|
|
syntaxErrorClass = InternalClass::create(this, SyntaxErrorObject::staticVTable(), syntaxErrorPrototype);
|
2014-06-13 12:30:03 +00:00
|
|
|
ScopedObject typeErrorPrototype(scope, memoryManager->alloc<TypeErrorPrototype>(errorClass));
|
2014-01-20 12:51:00 +00:00
|
|
|
typeErrorClass = InternalClass::create(this, TypeErrorObject::staticVTable(), typeErrorPrototype);
|
2014-06-13 12:30:03 +00:00
|
|
|
ScopedObject uRIErrorPrototype(scope, memoryManager->alloc<URIErrorPrototype>(errorClass));
|
2014-01-20 12:51:00 +00:00
|
|
|
uriErrorClass = InternalClass::create(this, URIErrorObject::staticVTable(), uRIErrorPrototype);
|
2013-08-29 12:31:32 +00:00
|
|
|
|
2014-06-13 12:30:03 +00:00
|
|
|
ScopedObject variantPrototype(scope, memoryManager->alloc<VariantPrototype>(InternalClass::create(this, VariantPrototype::staticVTable(), objectPrototype)));
|
2014-01-20 12:51:00 +00:00
|
|
|
variantClass = InternalClass::create(this, VariantObject::staticVTable(), variantPrototype);
|
2013-11-21 13:26:08 +00:00
|
|
|
Q_ASSERT(variantClass->prototype == variantPrototype);
|
2014-04-05 18:23:20 +00:00
|
|
|
Q_ASSERT(variantPrototype->internalClass()->prototype == objectPrototype);
|
2013-08-30 09:22:00 +00:00
|
|
|
|
2014-06-13 12:30:03 +00:00
|
|
|
sequencePrototype = ScopedValue(scope, memoryManager->alloc<SequencePrototype>(arrayClass));
|
|
|
|
|
|
|
|
objectCtor = memoryManager->alloc<ObjectCtor>(rootContext);
|
|
|
|
stringCtor = memoryManager->alloc<StringCtor>(rootContext);
|
|
|
|
numberCtor = memoryManager->alloc<NumberCtor>(rootContext);
|
|
|
|
booleanCtor = memoryManager->alloc<BooleanCtor>(rootContext);
|
|
|
|
arrayCtor = memoryManager->alloc<ArrayCtor>(rootContext);
|
|
|
|
functionCtor = memoryManager->alloc<FunctionCtor>(rootContext);
|
|
|
|
dateCtor = memoryManager->alloc<DateCtor>(rootContext);
|
|
|
|
regExpCtor = memoryManager->alloc<RegExpCtor>(rootContext);
|
|
|
|
errorCtor = memoryManager->alloc<ErrorCtor>(rootContext);
|
|
|
|
evalErrorCtor = memoryManager->alloc<EvalErrorCtor>(rootContext);
|
|
|
|
rangeErrorCtor = memoryManager->alloc<RangeErrorCtor>(rootContext);
|
|
|
|
referenceErrorCtor = memoryManager->alloc<ReferenceErrorCtor>(rootContext);
|
|
|
|
syntaxErrorCtor = memoryManager->alloc<SyntaxErrorCtor>(rootContext);
|
|
|
|
typeErrorCtor = memoryManager->alloc<TypeErrorCtor>(rootContext);
|
|
|
|
uRIErrorCtor = memoryManager->alloc<URIErrorCtor>(rootContext);
|
2012-11-17 20:54:26 +00:00
|
|
|
|
2014-05-09 12:14:02 +00:00
|
|
|
static_cast<ObjectPrototype *>(objectPrototype.getPointer())->init(this, objectCtor.asObject());
|
|
|
|
static_cast<StringPrototype *>(stringPrototype.getPointer())->init(this, stringCtor.asObject());
|
|
|
|
static_cast<NumberPrototype *>(numberPrototype.getPointer())->init(this, numberCtor.asObject());
|
|
|
|
static_cast<BooleanPrototype *>(booleanPrototype.getPointer())->init(this, booleanCtor.asObject());
|
|
|
|
static_cast<ArrayPrototype *>(arrayPrototype.getPointer())->init(this, arrayCtor.asObject());
|
|
|
|
static_cast<DatePrototype *>(datePrototype.getPointer())->init(this, dateCtor.asObject());
|
|
|
|
static_cast<FunctionPrototype *>(functionPrototype.getPointer())->init(this, functionCtor.asObject());
|
|
|
|
static_cast<RegExpPrototype *>(regExpPrototype.getPointer())->init(this, regExpCtor.asObject());
|
|
|
|
static_cast<ErrorPrototype *>(errorPrototype.getPointer())->init(this, errorCtor.asObject());
|
|
|
|
static_cast<EvalErrorPrototype *>(evalErrorPrototype.getPointer())->init(this, evalErrorCtor.asObject());
|
|
|
|
static_cast<RangeErrorPrototype *>(rangeErrorPrototype.getPointer())->init(this, rangeErrorCtor.asObject());
|
|
|
|
static_cast<ReferenceErrorPrototype *>(referenceErrorPrototype.getPointer())->init(this, referenceErrorCtor.asObject());
|
|
|
|
static_cast<SyntaxErrorPrototype *>(syntaxErrorPrototype.getPointer())->init(this, syntaxErrorCtor.asObject());
|
|
|
|
static_cast<TypeErrorPrototype *>(typeErrorPrototype.getPointer())->init(this, typeErrorCtor.asObject());
|
|
|
|
static_cast<URIErrorPrototype *>(uRIErrorPrototype.getPointer())->init(this, uRIErrorCtor.asObject());
|
|
|
|
|
|
|
|
static_cast<VariantPrototype *>(variantPrototype.getPointer())->init();
|
2014-07-24 09:53:59 +00:00
|
|
|
sequencePrototype.cast<SequencePrototype>()->init();
|
2013-05-14 00:01:04 +00:00
|
|
|
|
2014-09-10 12:50:28 +00:00
|
|
|
|
|
|
|
// typed arrays
|
|
|
|
|
|
|
|
arrayBufferCtor = memoryManager->alloc<ArrayBufferCtor>(rootContext);
|
2014-09-10 14:39:23 +00:00
|
|
|
Scoped<ArrayBufferPrototype> arrayBufferPrototype(scope, memoryManager->alloc<ArrayBufferPrototype>(objectClass));
|
2014-09-10 12:50:28 +00:00
|
|
|
arrayBufferPrototype->init(this, arrayBufferCtor.asObject());
|
|
|
|
arrayBufferClass = InternalClass::create(this, ArrayBuffer::staticVTable(), arrayBufferPrototype);
|
|
|
|
|
2014-09-10 14:39:23 +00:00
|
|
|
dataViewCtor = memoryManager->alloc<DataViewCtor>(rootContext);
|
|
|
|
Scoped<DataViewPrototype> dataViewPrototype(scope, memoryManager->alloc<DataViewPrototype>(objectClass));
|
|
|
|
dataViewPrototype->init(this, dataViewCtor.asObject());
|
|
|
|
dataViewClass = InternalClass::create(this, DataView::staticVTable(), dataViewPrototype);
|
|
|
|
|
2014-11-06 16:40:48 +00:00
|
|
|
for (int i = 0; i < Heap::TypedArray::NTypes; ++i) {
|
|
|
|
typedArrayCtors[i] = memoryManager->alloc<TypedArrayCtor>(rootContext, Heap::TypedArray::Type(i));
|
|
|
|
Scoped<TypedArrayPrototype> typedArrayPrototype(scope, memoryManager->alloc<TypedArrayPrototype>(this, Heap::TypedArray::Type(i)));
|
2014-09-11 13:37:31 +00:00
|
|
|
typedArrayPrototype->init(this, static_cast<TypedArrayCtor *>(typedArrayCtors[i].asObject()));
|
|
|
|
typedArrayClasses[i] = InternalClass::create(this, TypedArray::staticVTable(), typedArrayPrototype);
|
|
|
|
}
|
|
|
|
|
2012-11-17 20:54:26 +00:00
|
|
|
//
|
|
|
|
// set up the global object
|
|
|
|
//
|
2014-11-11 12:34:18 +00:00
|
|
|
ScopedObject global(scope, newObject());
|
|
|
|
globalObject = global;
|
2014-11-07 02:37:02 +00:00
|
|
|
rootContext->d()->global = globalObject->d();
|
2014-05-06 07:23:59 +00:00
|
|
|
rootContext->d()->callData->thisObject = globalObject;
|
2014-04-05 18:23:20 +00:00
|
|
|
Q_ASSERT(globalObject->internalClass()->vtable);
|
2013-04-08 07:08:02 +00:00
|
|
|
|
2013-09-18 10:31:55 +00:00
|
|
|
globalObject->defineDefaultProperty(QStringLiteral("Object"), objectCtor);
|
|
|
|
globalObject->defineDefaultProperty(QStringLiteral("String"), stringCtor);
|
|
|
|
globalObject->defineDefaultProperty(QStringLiteral("Number"), numberCtor);
|
|
|
|
globalObject->defineDefaultProperty(QStringLiteral("Boolean"), booleanCtor);
|
|
|
|
globalObject->defineDefaultProperty(QStringLiteral("Array"), arrayCtor);
|
|
|
|
globalObject->defineDefaultProperty(QStringLiteral("Function"), functionCtor);
|
|
|
|
globalObject->defineDefaultProperty(QStringLiteral("Date"), dateCtor);
|
|
|
|
globalObject->defineDefaultProperty(QStringLiteral("RegExp"), regExpCtor);
|
|
|
|
globalObject->defineDefaultProperty(QStringLiteral("Error"), errorCtor);
|
|
|
|
globalObject->defineDefaultProperty(QStringLiteral("EvalError"), evalErrorCtor);
|
|
|
|
globalObject->defineDefaultProperty(QStringLiteral("RangeError"), rangeErrorCtor);
|
|
|
|
globalObject->defineDefaultProperty(QStringLiteral("ReferenceError"), referenceErrorCtor);
|
|
|
|
globalObject->defineDefaultProperty(QStringLiteral("SyntaxError"), syntaxErrorCtor);
|
|
|
|
globalObject->defineDefaultProperty(QStringLiteral("TypeError"), typeErrorCtor);
|
|
|
|
globalObject->defineDefaultProperty(QStringLiteral("URIError"), uRIErrorCtor);
|
2014-09-11 13:37:31 +00:00
|
|
|
|
2014-09-10 12:50:28 +00:00
|
|
|
globalObject->defineDefaultProperty(QStringLiteral("ArrayBuffer"), arrayBufferCtor);
|
2014-09-10 14:39:23 +00:00
|
|
|
globalObject->defineDefaultProperty(QStringLiteral("DataView"), dataViewCtor);
|
2014-09-11 13:37:31 +00:00
|
|
|
ScopedString str(scope);
|
2014-11-06 16:40:48 +00:00
|
|
|
for (int i = 0; i < Heap::TypedArray::NTypes; ++i)
|
2014-09-11 13:37:31 +00:00
|
|
|
globalObject->defineDefaultProperty((str = typedArrayCtors[i].asFunctionObject()->name())->toQString(), typedArrayCtors[i]);
|
2013-09-26 11:05:25 +00:00
|
|
|
ScopedObject o(scope);
|
2014-06-13 12:30:03 +00:00
|
|
|
globalObject->defineDefaultProperty(QStringLiteral("Math"), (o = memoryManager->alloc<MathObject>(QV4::InternalClass::create(this, MathObject::staticVTable(), objectPrototype))));
|
|
|
|
globalObject->defineDefaultProperty(QStringLiteral("JSON"), (o = memoryManager->alloc<JsonObject>(QV4::InternalClass::create(this, JsonObject::staticVTable(), objectPrototype))));
|
2013-09-18 10:31:55 +00:00
|
|
|
|
2013-09-25 10:24:36 +00:00
|
|
|
globalObject->defineReadonlyProperty(QStringLiteral("undefined"), Primitive::undefinedValue());
|
|
|
|
globalObject->defineReadonlyProperty(QStringLiteral("NaN"), Primitive::fromDouble(std::numeric_limits<double>::quiet_NaN()));
|
|
|
|
globalObject->defineReadonlyProperty(QStringLiteral("Infinity"), Primitive::fromDouble(Q_INFINITY));
|
2012-12-12 23:53:04 +00:00
|
|
|
|
2014-05-09 10:15:23 +00:00
|
|
|
|
2014-06-13 12:30:03 +00:00
|
|
|
evalFunction = Scoped<EvalFunction>(scope, memoryManager->alloc<EvalFunction>(rootContext));
|
2013-09-26 11:05:25 +00:00
|
|
|
globalObject->defineDefaultProperty(QStringLiteral("eval"), (o = evalFunction));
|
2013-09-18 10:31:55 +00:00
|
|
|
|
|
|
|
globalObject->defineDefaultProperty(QStringLiteral("parseInt"), GlobalFunctions::method_parseInt, 2);
|
|
|
|
globalObject->defineDefaultProperty(QStringLiteral("parseFloat"), GlobalFunctions::method_parseFloat, 1);
|
|
|
|
globalObject->defineDefaultProperty(QStringLiteral("isNaN"), GlobalFunctions::method_isNaN, 1);
|
|
|
|
globalObject->defineDefaultProperty(QStringLiteral("isFinite"), GlobalFunctions::method_isFinite, 1);
|
|
|
|
globalObject->defineDefaultProperty(QStringLiteral("decodeURI"), GlobalFunctions::method_decodeURI, 1);
|
|
|
|
globalObject->defineDefaultProperty(QStringLiteral("decodeURIComponent"), GlobalFunctions::method_decodeURIComponent, 1);
|
|
|
|
globalObject->defineDefaultProperty(QStringLiteral("encodeURI"), GlobalFunctions::method_encodeURI, 1);
|
|
|
|
globalObject->defineDefaultProperty(QStringLiteral("encodeURIComponent"), GlobalFunctions::method_encodeURIComponent, 1);
|
|
|
|
globalObject->defineDefaultProperty(QStringLiteral("escape"), GlobalFunctions::method_escape, 1);
|
|
|
|
globalObject->defineDefaultProperty(QStringLiteral("unescape"), GlobalFunctions::method_unescape, 1);
|
2013-09-18 07:30:45 +00:00
|
|
|
|
|
|
|
Scoped<String> name(scope, newString(QStringLiteral("thrower")));
|
2014-07-28 08:07:57 +00:00
|
|
|
thrower = ScopedFunctionObject(scope, BuiltinFunction::create(rootContext, name.getPointer(), ::throwTypeError)).getPointer();
|
2012-11-17 20:54:26 +00:00
|
|
|
}
|
|
|
|
|
2012-12-04 10:30:26 +00:00
|
|
|
ExecutionEngine::~ExecutionEngine()
|
|
|
|
{
|
2013-07-24 08:29:04 +00:00
|
|
|
delete debugger;
|
2014-06-02 16:33:19 +00:00
|
|
|
debugger = 0;
|
2014-01-22 16:46:20 +00:00
|
|
|
delete profiler;
|
2014-06-02 16:33:19 +00:00
|
|
|
profiler = 0;
|
2013-06-04 12:28:13 +00:00
|
|
|
delete m_multiplyWrappedQObjects;
|
|
|
|
m_multiplyWrappedQObjects = 0;
|
2013-08-12 14:13:37 +00:00
|
|
|
delete identifierTable;
|
2013-05-29 12:58:52 +00:00
|
|
|
delete memoryManager;
|
2013-09-19 07:32:42 +00:00
|
|
|
|
|
|
|
QSet<QV4::CompiledData::CompilationUnit*> remainingUnits;
|
|
|
|
qSwap(compilationUnits, remainingUnits);
|
|
|
|
foreach (QV4::CompiledData::CompilationUnit *unit, remainingUnits)
|
|
|
|
unit->unlink();
|
|
|
|
|
2013-06-20 09:32:45 +00:00
|
|
|
delete m_qmlExtensions;
|
2013-05-06 11:29:24 +00:00
|
|
|
emptyClass->destroy();
|
2014-04-16 07:36:38 +00:00
|
|
|
delete classPool;
|
2013-04-19 09:47:50 +00:00
|
|
|
delete bumperPointerAllocator;
|
2013-03-30 16:43:03 +00:00
|
|
|
delete regExpCache;
|
2013-05-12 10:07:15 +00:00
|
|
|
delete regExpAllocator;
|
2013-03-25 16:31:38 +00:00
|
|
|
delete executableAllocator;
|
2013-09-03 10:40:07 +00:00
|
|
|
jsStack->deallocate();
|
|
|
|
delete jsStack;
|
2014-03-10 14:18:54 +00:00
|
|
|
delete [] argumentsAccessors;
|
2012-12-04 10:30:26 +00:00
|
|
|
}
|
|
|
|
|
2013-07-24 08:29:04 +00:00
|
|
|
void ExecutionEngine::enableDebugger()
|
|
|
|
{
|
|
|
|
Q_ASSERT(!debugger);
|
|
|
|
debugger = new Debugging::Debugger(this);
|
2014-02-14 12:58:40 +00:00
|
|
|
iselFactory.reset(new Moth::ISelFactory);
|
2013-07-24 08:29:04 +00:00
|
|
|
}
|
|
|
|
|
2014-01-22 16:46:20 +00:00
|
|
|
void ExecutionEngine::enableProfiler()
|
|
|
|
{
|
|
|
|
Q_ASSERT(!profiler);
|
2014-06-12 12:33:05 +00:00
|
|
|
profiler = new QV4::Profiling::Profiler(this);
|
2014-01-22 16:46:20 +00:00
|
|
|
}
|
|
|
|
|
2013-03-14 13:03:04 +00:00
|
|
|
void ExecutionEngine::initRootContext()
|
|
|
|
{
|
2014-07-17 13:56:30 +00:00
|
|
|
GlobalContext *r = static_cast<GlobalContext*>(memoryManager->allocManaged(sizeof(GlobalContext::Data) + sizeof(CallData)));
|
|
|
|
new (r->d()) GlobalContext::Data(this);
|
|
|
|
r->d()->callData = reinterpret_cast<CallData *>(r->d() + 1);
|
|
|
|
r->d()->callData->tag = QV4::Value::_Integer_Type;
|
|
|
|
r->d()->callData->argc = 0;
|
|
|
|
r->d()->callData->thisObject = globalObject;
|
|
|
|
r->d()->callData->args[0] = Encode::undefined();
|
|
|
|
|
|
|
|
rootContext = r;
|
2013-03-14 13:03:04 +00:00
|
|
|
}
|
|
|
|
|
2013-05-06 11:29:24 +00:00
|
|
|
InternalClass *ExecutionEngine::newClass(const InternalClass &other)
|
|
|
|
{
|
2014-04-16 07:36:38 +00:00
|
|
|
return new (classPool) InternalClass(other);
|
2013-05-06 11:29:24 +00:00
|
|
|
}
|
|
|
|
|
2013-03-14 13:03:04 +00:00
|
|
|
ExecutionContext *ExecutionEngine::pushGlobalContext()
|
|
|
|
{
|
2014-07-23 11:56:43 +00:00
|
|
|
Scope scope(this);
|
|
|
|
Scoped<GlobalContext> g(scope, memoryManager->alloc<GlobalContext>(this));
|
2014-06-13 12:30:03 +00:00
|
|
|
g->d()->callData = rootContext->d()->callData;
|
2013-03-14 13:03:04 +00:00
|
|
|
|
2014-07-23 11:56:43 +00:00
|
|
|
Q_ASSERT(currentContext() == g.getPointer());
|
|
|
|
return g.getPointer();
|
2012-11-17 20:54:26 +00:00
|
|
|
}
|
|
|
|
|
2013-01-13 22:57:35 +00:00
|
|
|
|
2014-11-11 12:34:18 +00:00
|
|
|
Heap::Object *ExecutionEngine::newObject()
|
2012-11-17 20:54:26 +00:00
|
|
|
{
|
2014-05-09 13:23:18 +00:00
|
|
|
Scope scope(this);
|
2014-06-13 12:30:03 +00:00
|
|
|
ScopedObject object(scope, memoryManager->alloc<Object>(this));
|
2014-11-11 12:34:18 +00:00
|
|
|
return object->d();
|
2012-11-17 20:54:26 +00:00
|
|
|
}
|
|
|
|
|
2014-11-11 12:34:18 +00:00
|
|
|
Heap::Object *ExecutionEngine::newObject(InternalClass *internalClass)
|
2013-04-23 05:31:02 +00:00
|
|
|
{
|
2014-05-09 13:23:18 +00:00
|
|
|
Scope scope(this);
|
2014-06-13 12:30:03 +00:00
|
|
|
ScopedObject object(scope, memoryManager->alloc<Object>(internalClass));
|
2014-11-11 12:34:18 +00:00
|
|
|
return object->d();
|
2013-04-23 05:31:02 +00:00
|
|
|
}
|
|
|
|
|
2013-09-25 13:24:50 +00:00
|
|
|
Returned<String> *ExecutionEngine::newString(const QString &s)
|
2012-11-17 20:54:26 +00:00
|
|
|
{
|
2014-05-09 13:06:29 +00:00
|
|
|
Scope scope(this);
|
2014-06-13 12:30:03 +00:00
|
|
|
return ScopedString(scope, memoryManager->alloc<String>(this, s))->asReturned<String>();
|
2012-11-17 20:54:26 +00:00
|
|
|
}
|
|
|
|
|
2013-01-30 13:56:40 +00:00
|
|
|
String *ExecutionEngine::newIdentifier(const QString &text)
|
|
|
|
{
|
2013-06-27 07:04:11 +00:00
|
|
|
return identifierTable->insertString(text);
|
2013-01-30 13:56:40 +00:00
|
|
|
}
|
|
|
|
|
2014-11-11 12:34:18 +00:00
|
|
|
Heap::Object *ExecutionEngine::newStringObject(const ValueRef value)
|
2012-11-17 20:54:26 +00:00
|
|
|
{
|
2014-05-09 12:14:02 +00:00
|
|
|
Scope scope(this);
|
2014-06-13 12:30:03 +00:00
|
|
|
Scoped<StringObject> object(scope, memoryManager->alloc<StringObject>(this, value));
|
2014-11-11 12:34:18 +00:00
|
|
|
return object->d();
|
2012-11-17 20:54:26 +00:00
|
|
|
}
|
|
|
|
|
2014-11-11 12:34:18 +00:00
|
|
|
Heap::Object *ExecutionEngine::newNumberObject(const ValueRef value)
|
2012-11-17 20:54:26 +00:00
|
|
|
{
|
2014-05-09 12:14:02 +00:00
|
|
|
Scope scope(this);
|
2014-06-13 12:30:03 +00:00
|
|
|
Scoped<NumberObject> object(scope, memoryManager->alloc<NumberObject>(this, value));
|
2014-11-11 12:34:18 +00:00
|
|
|
return object->d();
|
2012-11-17 20:54:26 +00:00
|
|
|
}
|
|
|
|
|
2014-11-11 12:34:18 +00:00
|
|
|
Heap::Object *ExecutionEngine::newBooleanObject(const ValueRef value)
|
2012-11-17 20:54:26 +00:00
|
|
|
{
|
2014-05-09 12:14:02 +00:00
|
|
|
Scope scope(this);
|
2014-06-13 12:30:03 +00:00
|
|
|
ScopedObject object(scope, memoryManager->alloc<BooleanObject>(this, value));
|
2014-11-11 12:34:18 +00:00
|
|
|
return object->d();
|
2012-11-17 20:54:26 +00:00
|
|
|
}
|
|
|
|
|
2014-11-11 12:34:18 +00:00
|
|
|
Heap::ArrayObject *ExecutionEngine::newArrayObject(int count)
|
2012-11-17 20:54:26 +00:00
|
|
|
{
|
2014-05-09 12:14:02 +00:00
|
|
|
Scope scope(this);
|
2014-06-13 12:30:03 +00:00
|
|
|
ScopedArrayObject object(scope, memoryManager->alloc<ArrayObject>(this));
|
2013-05-31 14:40:12 +00:00
|
|
|
|
|
|
|
if (count) {
|
|
|
|
if (count < 0x1000)
|
|
|
|
object->arrayReserve(count);
|
|
|
|
object->setArrayLengthUnchecked(count);
|
|
|
|
}
|
2014-11-11 12:34:18 +00:00
|
|
|
return object->d();
|
2012-11-17 20:54:26 +00:00
|
|
|
}
|
|
|
|
|
2014-11-11 12:34:18 +00:00
|
|
|
Heap::ArrayObject *ExecutionEngine::newArrayObject(const QStringList &list)
|
2012-11-17 20:54:26 +00:00
|
|
|
{
|
2014-05-09 12:14:02 +00:00
|
|
|
Scope scope(this);
|
2014-06-13 12:30:03 +00:00
|
|
|
ScopedArrayObject object(scope, memoryManager->alloc<ArrayObject>(this, list));
|
2014-11-11 12:34:18 +00:00
|
|
|
return object->d();
|
2012-11-17 20:54:26 +00:00
|
|
|
}
|
|
|
|
|
2014-11-11 12:34:18 +00:00
|
|
|
Heap::ArrayObject *ExecutionEngine::newArrayObject(InternalClass *ic)
|
2013-09-02 12:25:15 +00:00
|
|
|
{
|
2014-05-09 12:14:02 +00:00
|
|
|
Scope scope(this);
|
2014-06-13 12:30:03 +00:00
|
|
|
ScopedArrayObject object(scope, memoryManager->alloc<ArrayObject>(ic));
|
2014-11-11 12:34:18 +00:00
|
|
|
return object->d();
|
2013-09-02 12:25:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-11-11 12:34:18 +00:00
|
|
|
Heap::DateObject *ExecutionEngine::newDateObject(const ValueRef value)
|
2012-11-17 20:54:26 +00:00
|
|
|
{
|
2014-05-09 12:14:02 +00:00
|
|
|
Scope scope(this);
|
2014-06-13 12:30:03 +00:00
|
|
|
Scoped<DateObject> object(scope, memoryManager->alloc<DateObject>(this, value));
|
2014-11-11 12:34:18 +00:00
|
|
|
return object->d();
|
2012-11-17 20:54:26 +00:00
|
|
|
}
|
|
|
|
|
2014-11-11 12:34:18 +00:00
|
|
|
Heap::DateObject *ExecutionEngine::newDateObject(const QDateTime &dt)
|
2013-05-02 20:33:47 +00:00
|
|
|
{
|
2014-05-09 12:14:02 +00:00
|
|
|
Scope scope(this);
|
2014-06-13 12:30:03 +00:00
|
|
|
Scoped<DateObject> object(scope, memoryManager->alloc<DateObject>(this, dt));
|
2014-11-11 12:34:18 +00:00
|
|
|
return object->d();
|
2013-05-02 20:33:47 +00:00
|
|
|
}
|
|
|
|
|
2014-11-11 12:34:18 +00:00
|
|
|
Heap::RegExpObject *ExecutionEngine::newRegExpObject(const QString &pattern, int flags)
|
2012-11-17 20:54:26 +00:00
|
|
|
{
|
2014-02-14 12:58:40 +00:00
|
|
|
bool global = (flags & IR::RegExp::RegExp_Global);
|
2013-01-14 15:53:43 +00:00
|
|
|
bool ignoreCase = false;
|
|
|
|
bool multiline = false;
|
2014-02-14 12:58:40 +00:00
|
|
|
if (flags & IR::RegExp::RegExp_IgnoreCase)
|
2013-01-14 15:53:43 +00:00
|
|
|
ignoreCase = true;
|
2014-02-14 12:58:40 +00:00
|
|
|
if (flags & IR::RegExp::RegExp_Multiline)
|
2013-01-14 15:53:43 +00:00
|
|
|
multiline = true;
|
2012-11-17 20:54:26 +00:00
|
|
|
|
2013-10-15 13:00:24 +00:00
|
|
|
Scope scope(this);
|
|
|
|
Scoped<RegExp> re(scope, RegExp::create(this, pattern, ignoreCase, multiline));
|
|
|
|
return newRegExpObject(re, global);
|
2012-12-12 07:28:08 +00:00
|
|
|
}
|
|
|
|
|
2014-11-11 12:34:18 +00:00
|
|
|
Heap::RegExpObject *ExecutionEngine::newRegExpObject(RegExp *re, bool global)
|
2012-12-12 07:28:08 +00:00
|
|
|
{
|
2014-05-08 20:27:23 +00:00
|
|
|
Scope scope(this);
|
2014-06-13 12:30:03 +00:00
|
|
|
Scoped<RegExpObject> object(scope, memoryManager->alloc<RegExpObject>(this, re, global));
|
2014-11-11 12:34:18 +00:00
|
|
|
return object->d();
|
2012-11-17 20:54:26 +00:00
|
|
|
}
|
|
|
|
|
2014-11-11 12:34:18 +00:00
|
|
|
Heap::RegExpObject *ExecutionEngine::newRegExpObject(const QRegExp &re)
|
2013-05-02 20:33:47 +00:00
|
|
|
{
|
2014-05-08 20:27:23 +00:00
|
|
|
Scope scope(this);
|
2014-06-13 12:30:03 +00:00
|
|
|
Scoped<RegExpObject> object(scope, memoryManager->alloc<RegExpObject>(this, re));
|
2014-11-11 12:34:18 +00:00
|
|
|
return object->d();
|
2013-05-02 20:33:47 +00:00
|
|
|
}
|
|
|
|
|
2014-11-11 12:34:18 +00:00
|
|
|
Heap::Object *ExecutionEngine::newErrorObject(const ValueRef value)
|
2012-11-17 20:54:26 +00:00
|
|
|
{
|
2014-05-09 12:14:02 +00:00
|
|
|
Scope scope(this);
|
2014-06-13 12:30:03 +00:00
|
|
|
ScopedObject object(scope, memoryManager->alloc<ErrorObject>(errorClass, value));
|
2014-11-11 12:34:18 +00:00
|
|
|
return object->d();
|
2012-11-17 20:54:26 +00:00
|
|
|
}
|
|
|
|
|
2014-11-11 12:34:18 +00:00
|
|
|
Heap::Object *ExecutionEngine::newSyntaxErrorObject(const QString &message)
|
2012-11-28 10:00:23 +00:00
|
|
|
{
|
2013-09-25 20:42:58 +00:00
|
|
|
Scope scope(this);
|
|
|
|
ScopedString s(scope, newString(message));
|
2014-06-13 12:30:03 +00:00
|
|
|
ScopedObject error(scope, memoryManager->alloc<SyntaxErrorObject>(this, s));
|
2014-11-11 12:34:18 +00:00
|
|
|
return error->d();
|
2012-11-28 10:00:23 +00:00
|
|
|
}
|
|
|
|
|
2014-11-11 12:34:18 +00:00
|
|
|
Heap::Object *ExecutionEngine::newSyntaxErrorObject(const QString &message, const QString &fileName, int line, int column)
|
2012-12-04 18:50:25 +00:00
|
|
|
{
|
2014-05-09 12:14:02 +00:00
|
|
|
Scope scope(this);
|
2014-06-13 12:30:03 +00:00
|
|
|
ScopedObject error(scope, memoryManager->alloc<SyntaxErrorObject>(this, message, fileName, line, column));
|
2014-11-11 12:34:18 +00:00
|
|
|
return error->d();
|
2012-12-04 18:50:25 +00:00
|
|
|
}
|
|
|
|
|
2013-05-02 19:37:20 +00:00
|
|
|
|
2014-11-11 12:34:18 +00:00
|
|
|
Heap::Object *ExecutionEngine::newReferenceErrorObject(const QString &message)
|
2013-05-02 19:37:20 +00:00
|
|
|
{
|
2014-05-09 12:14:02 +00:00
|
|
|
Scope scope(this);
|
2014-06-13 12:30:03 +00:00
|
|
|
ScopedObject o(scope, memoryManager->alloc<ReferenceErrorObject>(this, message));
|
2014-11-11 12:34:18 +00:00
|
|
|
return o->d();
|
2013-05-02 19:37:20 +00:00
|
|
|
}
|
|
|
|
|
2014-11-11 12:34:18 +00:00
|
|
|
Heap::Object *ExecutionEngine::newReferenceErrorObject(const QString &message, const QString &fileName, int lineNumber, int columnNumber)
|
2013-06-14 11:08:13 +00:00
|
|
|
{
|
2014-05-09 12:14:02 +00:00
|
|
|
Scope scope(this);
|
2014-06-13 12:30:03 +00:00
|
|
|
ScopedObject o(scope, memoryManager->alloc<ReferenceErrorObject>(this, message, fileName, lineNumber, columnNumber));
|
2014-11-11 12:34:18 +00:00
|
|
|
return o->d();
|
2013-06-14 11:08:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-11-11 12:34:18 +00:00
|
|
|
Heap::Object *ExecutionEngine::newTypeErrorObject(const QString &message)
|
2012-12-04 18:50:25 +00:00
|
|
|
{
|
2014-05-09 12:14:02 +00:00
|
|
|
Scope scope(this);
|
2014-06-13 12:30:03 +00:00
|
|
|
ScopedObject o(scope, memoryManager->alloc<TypeErrorObject>(this, message));
|
2014-11-11 12:34:18 +00:00
|
|
|
return o->d();
|
2012-12-04 18:50:25 +00:00
|
|
|
}
|
|
|
|
|
2014-11-11 12:34:18 +00:00
|
|
|
Heap::Object *ExecutionEngine::newRangeErrorObject(const QString &message)
|
2013-01-11 08:56:56 +00:00
|
|
|
{
|
2014-05-09 12:14:02 +00:00
|
|
|
Scope scope(this);
|
2014-06-13 12:30:03 +00:00
|
|
|
ScopedObject o(scope, memoryManager->alloc<RangeErrorObject>(this, message));
|
2014-11-11 12:34:18 +00:00
|
|
|
return o->d();
|
2013-01-11 08:56:56 +00:00
|
|
|
}
|
|
|
|
|
2014-11-11 12:34:18 +00:00
|
|
|
Heap::Object *ExecutionEngine::newURIErrorObject(const ValueRef message)
|
2013-01-22 14:13:15 +00:00
|
|
|
{
|
2014-05-09 12:14:02 +00:00
|
|
|
Scope scope(this);
|
2014-06-13 12:30:03 +00:00
|
|
|
ScopedObject o(scope, memoryManager->alloc<URIErrorObject>(this, message));
|
2014-11-11 12:34:18 +00:00
|
|
|
return o->d();
|
2013-01-22 14:13:15 +00:00
|
|
|
}
|
|
|
|
|
2014-11-11 12:34:18 +00:00
|
|
|
Heap::Object *ExecutionEngine::newVariantObject(const QVariant &v)
|
2013-05-14 00:01:04 +00:00
|
|
|
{
|
2014-05-09 12:32:59 +00:00
|
|
|
Scope scope(this);
|
2014-06-13 12:30:03 +00:00
|
|
|
ScopedObject o(scope, memoryManager->alloc<VariantObject>(this, v));
|
2014-11-11 12:34:18 +00:00
|
|
|
return o->d();
|
2013-05-14 00:01:04 +00:00
|
|
|
}
|
|
|
|
|
2014-11-11 12:34:18 +00:00
|
|
|
Heap::Object *ExecutionEngine::newForEachIteratorObject(Object *o)
|
2012-11-17 20:54:26 +00:00
|
|
|
{
|
2014-05-09 13:23:18 +00:00
|
|
|
Scope scope(this);
|
2014-07-25 15:44:14 +00:00
|
|
|
ScopedObject obj(scope, memoryManager->alloc<ForEachIteratorObject>(this, o));
|
2014-11-11 12:34:18 +00:00
|
|
|
return obj->d();
|
2013-05-03 14:51:32 +00:00
|
|
|
}
|
|
|
|
|
2014-11-11 12:34:18 +00:00
|
|
|
Heap::Object *ExecutionEngine::qmlContextObject() const
|
2013-05-03 14:51:32 +00:00
|
|
|
{
|
2014-11-07 04:46:20 +00:00
|
|
|
Heap::ExecutionContext *ctx = currentContext()->d();
|
2013-05-27 18:40:33 +00:00
|
|
|
|
2014-11-07 04:46:20 +00:00
|
|
|
if (ctx->type == Heap::ExecutionContext::Type_SimpleCallContext && !ctx->outer)
|
|
|
|
ctx = ctx->parent;
|
2013-05-27 18:40:33 +00:00
|
|
|
|
2014-11-07 04:46:20 +00:00
|
|
|
if (!ctx->outer)
|
2013-05-03 14:51:32 +00:00
|
|
|
return 0;
|
|
|
|
|
2014-11-07 04:46:20 +00:00
|
|
|
while (ctx->outer && ctx->outer->type != Heap::ExecutionContext::Type_GlobalContext)
|
|
|
|
ctx = ctx->outer;
|
2013-05-03 14:51:32 +00:00
|
|
|
|
2013-11-03 14:23:05 +00:00
|
|
|
Q_ASSERT(ctx);
|
2014-11-07 04:46:20 +00:00
|
|
|
if (ctx->type != Heap::ExecutionContext::Type_QmlContext)
|
2013-05-03 14:51:32 +00:00
|
|
|
return 0;
|
|
|
|
|
2014-11-11 12:34:18 +00:00
|
|
|
Q_ASSERT(static_cast<Heap::CallContext *>(ctx)->activation);
|
|
|
|
return static_cast<Heap::CallContext *>(ctx)->activation;
|
2012-11-17 20:54:26 +00:00
|
|
|
}
|
|
|
|
|
2013-09-11 11:23:21 +00:00
|
|
|
QVector<StackFrame> ExecutionEngine::stackTrace(int frameLimit) const
|
2013-05-22 08:47:36 +00:00
|
|
|
{
|
2014-03-04 12:19:27 +00:00
|
|
|
Scope scope(this->currentContext());
|
|
|
|
ScopedString name(scope);
|
2013-05-22 08:47:36 +00:00
|
|
|
QVector<StackFrame> stack;
|
|
|
|
|
2014-11-07 04:46:20 +00:00
|
|
|
Scoped<ExecutionContext> c(scope, currentContext());
|
2013-05-22 08:47:36 +00:00
|
|
|
while (c && frameLimit) {
|
2013-11-03 14:23:05 +00:00
|
|
|
CallContext *callCtx = c->asCallContext();
|
2014-05-09 14:50:17 +00:00
|
|
|
if (callCtx && callCtx->d()->function) {
|
2013-05-22 08:47:36 +00:00
|
|
|
StackFrame frame;
|
2014-11-07 04:24:24 +00:00
|
|
|
ScopedFunctionObject function(scope, callCtx->d()->function);
|
|
|
|
if (function->function())
|
|
|
|
frame.source = function->function()->sourceFile();
|
|
|
|
name = function->name();
|
2014-03-04 12:19:27 +00:00
|
|
|
frame.function = name->toQString();
|
2013-05-22 08:47:36 +00:00
|
|
|
frame.line = -1;
|
|
|
|
frame.column = -1;
|
2013-05-25 13:31:23 +00:00
|
|
|
|
2014-11-07 04:24:24 +00:00
|
|
|
if (callCtx->d()->function->function)
|
2014-03-06 08:09:05 +00:00
|
|
|
// line numbers can be negative for places where you can't set a real breakpoint
|
2014-05-06 07:23:59 +00:00
|
|
|
frame.line = qAbs(callCtx->d()->lineNumber);
|
2013-05-25 13:31:23 +00:00
|
|
|
|
2013-05-22 08:47:36 +00:00
|
|
|
stack.append(frame);
|
|
|
|
--frameLimit;
|
|
|
|
}
|
2014-05-06 07:23:59 +00:00
|
|
|
c = c->d()->parent;
|
2013-05-22 08:47:36 +00:00
|
|
|
}
|
2013-05-25 13:31:23 +00:00
|
|
|
|
|
|
|
if (frameLimit && globalCode) {
|
|
|
|
StackFrame frame;
|
2013-08-14 14:02:56 +00:00
|
|
|
frame.source = globalCode->sourceFile();
|
2014-03-03 10:51:17 +00:00
|
|
|
frame.function = globalCode->name()->toQString();
|
2014-05-06 07:23:59 +00:00
|
|
|
frame.line = rootContext->d()->lineNumber;
|
2013-05-25 13:31:23 +00:00
|
|
|
frame.column = -1;
|
|
|
|
|
|
|
|
|
|
|
|
stack.append(frame);
|
|
|
|
}
|
2013-05-22 08:47:36 +00:00
|
|
|
return stack;
|
|
|
|
}
|
|
|
|
|
2013-09-11 11:23:21 +00:00
|
|
|
StackFrame ExecutionEngine::currentStackFrame() const
|
2013-05-22 08:47:36 +00:00
|
|
|
{
|
|
|
|
StackFrame frame;
|
|
|
|
frame.line = -1;
|
|
|
|
frame.column = -1;
|
|
|
|
|
2013-05-25 13:31:23 +00:00
|
|
|
QVector<StackFrame> trace = stackTrace(/*limit*/ 1);
|
|
|
|
if (!trace.isEmpty())
|
|
|
|
frame = trace.first();
|
|
|
|
|
2013-05-22 08:47:36 +00:00
|
|
|
return frame;
|
|
|
|
}
|
|
|
|
|
2013-12-20 14:38:37 +00:00
|
|
|
/* Helper and "C" linkage exported function to format a GDBMI stacktrace for
|
|
|
|
* invocation by a debugger.
|
|
|
|
* Sample GDB invocation: print qt_v4StackTrace((void*)0x7fffffffb290)
|
|
|
|
* Sample CDB invocation: .call Qt5Qmld!qt_v4StackTrace(0x7fffffffb290) ; gh
|
|
|
|
* Note: The helper is there to suppress MSVC warning 4190 about anything
|
|
|
|
* with UDT return types in a "C" linkage function. */
|
|
|
|
|
|
|
|
static inline char *v4StackTrace(const ExecutionContext *context)
|
|
|
|
{
|
|
|
|
QString result;
|
|
|
|
QTextStream str(&result);
|
|
|
|
str << "stack=[";
|
2014-05-06 07:23:59 +00:00
|
|
|
if (context && context->d()->engine) {
|
|
|
|
const QVector<StackFrame> stackTrace = context->d()->engine->stackTrace(20);
|
2013-12-20 14:38:37 +00:00
|
|
|
for (int i = 0; i < stackTrace.size(); ++i) {
|
|
|
|
if (i)
|
|
|
|
str << ',';
|
|
|
|
const QUrl url(stackTrace.at(i).source);
|
|
|
|
const QString fileName = url.isLocalFile() ? url.toLocalFile() : url.toString();
|
|
|
|
str << "frame={level=\"" << i << "\",func=\"" << stackTrace.at(i).function
|
|
|
|
<< "\",file=\"" << fileName << "\",fullname=\"" << fileName
|
|
|
|
<< "\",line=\"" << stackTrace.at(i).line << "\",language=\"js\"}";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
str << ']';
|
|
|
|
return qstrdup(result.toLocal8Bit().constData());
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" Q_QML_EXPORT char *qt_v4StackTrace(void *executionContext)
|
|
|
|
{
|
|
|
|
return v4StackTrace(reinterpret_cast<const ExecutionContext *>(executionContext));
|
|
|
|
}
|
|
|
|
|
2013-05-29 07:59:40 +00:00
|
|
|
QUrl ExecutionEngine::resolvedUrl(const QString &file)
|
|
|
|
{
|
|
|
|
QUrl src(file);
|
|
|
|
if (!src.isRelative())
|
|
|
|
return src;
|
|
|
|
|
|
|
|
QUrl base;
|
2014-11-07 04:46:20 +00:00
|
|
|
Scope scope(this);
|
|
|
|
Scoped<ExecutionContext> c(scope, currentContext());
|
2013-05-29 07:59:40 +00:00
|
|
|
while (c) {
|
2013-11-03 14:23:05 +00:00
|
|
|
CallContext *callCtx = c->asCallContext();
|
2014-05-09 14:50:17 +00:00
|
|
|
if (callCtx && callCtx->d()->function) {
|
2014-11-07 04:24:24 +00:00
|
|
|
if (callCtx->d()->function->function)
|
|
|
|
base.setUrl(callCtx->d()->function->function->sourceFile());
|
2013-05-29 07:59:40 +00:00
|
|
|
break;
|
|
|
|
}
|
2014-05-06 07:23:59 +00:00
|
|
|
c = c->d()->parent;
|
2013-05-29 07:59:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (base.isEmpty() && globalCode)
|
2013-08-14 14:02:56 +00:00
|
|
|
base.setUrl(globalCode->sourceFile());
|
2013-05-29 07:59:40 +00:00
|
|
|
|
|
|
|
if (base.isEmpty())
|
|
|
|
return src;
|
|
|
|
|
|
|
|
return base.resolved(src);
|
|
|
|
}
|
|
|
|
|
2013-01-18 11:47:43 +00:00
|
|
|
void ExecutionEngine::requireArgumentsAccessors(int n)
|
|
|
|
{
|
2014-03-10 14:18:54 +00:00
|
|
|
if (n <= nArgumentsAccessors)
|
2013-01-18 11:47:43 +00:00
|
|
|
return;
|
|
|
|
|
2013-10-11 10:26:27 +00:00
|
|
|
Scope scope(this);
|
|
|
|
ScopedFunctionObject get(scope);
|
|
|
|
ScopedFunctionObject set(scope);
|
|
|
|
|
2014-03-10 14:18:54 +00:00
|
|
|
if (n >= nArgumentsAccessors) {
|
|
|
|
Property *oldAccessors = argumentsAccessors;
|
|
|
|
int oldSize = nArgumentsAccessors;
|
|
|
|
nArgumentsAccessors = qMax(8, n);
|
|
|
|
argumentsAccessors = new Property[nArgumentsAccessors];
|
|
|
|
if (oldAccessors) {
|
|
|
|
memcpy(argumentsAccessors, oldAccessors, oldSize*sizeof(Property));
|
|
|
|
delete [] oldAccessors;
|
|
|
|
}
|
|
|
|
for (int i = oldSize; i < nArgumentsAccessors; ++i) {
|
2014-06-13 12:30:03 +00:00
|
|
|
argumentsAccessors[i].value = ScopedValue(scope, memoryManager->alloc<ArgumentsGetterFunction>(rootContext, i));
|
|
|
|
argumentsAccessors[i].set = ScopedValue(scope, memoryManager->alloc<ArgumentsSetterFunction>(rootContext, i));
|
2014-03-10 14:18:54 +00:00
|
|
|
}
|
2013-01-18 11:47:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-28 15:46:09 +00:00
|
|
|
void ExecutionEngine::markObjects()
|
|
|
|
{
|
2013-11-02 15:30:26 +00:00
|
|
|
identifierTable->mark(this);
|
2013-01-30 13:56:40 +00:00
|
|
|
|
2013-11-02 15:30:26 +00:00
|
|
|
globalObject->mark(this);
|
2013-01-28 15:46:09 +00:00
|
|
|
|
2014-03-10 14:18:54 +00:00
|
|
|
for (int i = 0; i < nArgumentsAccessors; ++i) {
|
|
|
|
const Property &pd = argumentsAccessors[i];
|
2013-06-28 10:13:06 +00:00
|
|
|
if (FunctionObject *getter = pd.getter())
|
2013-11-02 15:30:26 +00:00
|
|
|
getter->mark(this);
|
2013-06-28 10:13:06 +00:00
|
|
|
if (FunctionObject *setter = pd.setter())
|
2013-11-02 15:30:26 +00:00
|
|
|
setter->mark(this);
|
2013-01-28 15:46:09 +00:00
|
|
|
}
|
|
|
|
|
2014-11-07 04:46:20 +00:00
|
|
|
Heap::ExecutionContext *c = currentContext()->d();
|
2013-04-07 15:23:36 +00:00
|
|
|
while (c) {
|
2014-11-07 04:46:20 +00:00
|
|
|
Q_ASSERT(c->inUse);
|
|
|
|
if (!c->markBit) {
|
|
|
|
c->markBit = 1;
|
2014-11-07 18:07:54 +00:00
|
|
|
c->internalClass->vtable->markObjects(c, this);
|
2014-07-25 08:13:50 +00:00
|
|
|
}
|
2014-11-07 04:46:20 +00:00
|
|
|
c = c->parent;
|
2013-04-07 15:23:36 +00:00
|
|
|
}
|
2013-01-28 15:46:09 +00:00
|
|
|
|
2014-03-17 11:45:41 +00:00
|
|
|
id_empty->mark(this);
|
|
|
|
id_undefined->mark(this);
|
|
|
|
id_null->mark(this);
|
|
|
|
id_true->mark(this);
|
|
|
|
id_false->mark(this);
|
|
|
|
id_boolean->mark(this);
|
|
|
|
id_number->mark(this);
|
|
|
|
id_string->mark(this);
|
|
|
|
id_object->mark(this);
|
|
|
|
id_function->mark(this);
|
2013-11-02 15:30:26 +00:00
|
|
|
id_length->mark(this);
|
|
|
|
id_prototype->mark(this);
|
|
|
|
id_constructor->mark(this);
|
|
|
|
id_arguments->mark(this);
|
|
|
|
id_caller->mark(this);
|
2014-03-17 11:45:41 +00:00
|
|
|
id_callee->mark(this);
|
2013-11-02 15:30:26 +00:00
|
|
|
id_this->mark(this);
|
|
|
|
id___proto__->mark(this);
|
|
|
|
id_enumerable->mark(this);
|
|
|
|
id_configurable->mark(this);
|
|
|
|
id_writable->mark(this);
|
|
|
|
id_value->mark(this);
|
|
|
|
id_get->mark(this);
|
|
|
|
id_set->mark(this);
|
|
|
|
id_eval->mark(this);
|
|
|
|
id_uintMax->mark(this);
|
|
|
|
id_name->mark(this);
|
|
|
|
id_index->mark(this);
|
|
|
|
id_input->mark(this);
|
|
|
|
id_toString->mark(this);
|
2014-02-27 21:59:39 +00:00
|
|
|
id_destroy->mark(this);
|
2013-11-02 15:30:26 +00:00
|
|
|
id_valueOf->mark(this);
|
2014-09-10 12:50:28 +00:00
|
|
|
id_byteLength->mark(this);
|
2014-09-10 14:39:23 +00:00
|
|
|
id_byteOffset->mark(this);
|
|
|
|
id_buffer->mark(this);
|
2013-11-02 15:30:26 +00:00
|
|
|
|
|
|
|
objectCtor.mark(this);
|
|
|
|
stringCtor.mark(this);
|
|
|
|
numberCtor.mark(this);
|
|
|
|
booleanCtor.mark(this);
|
|
|
|
arrayCtor.mark(this);
|
|
|
|
functionCtor.mark(this);
|
|
|
|
dateCtor.mark(this);
|
|
|
|
regExpCtor.mark(this);
|
|
|
|
errorCtor.mark(this);
|
|
|
|
evalErrorCtor.mark(this);
|
|
|
|
rangeErrorCtor.mark(this);
|
|
|
|
referenceErrorCtor.mark(this);
|
|
|
|
syntaxErrorCtor.mark(this);
|
|
|
|
typeErrorCtor.mark(this);
|
|
|
|
uRIErrorCtor.mark(this);
|
2014-09-10 12:50:28 +00:00
|
|
|
arrayBufferCtor.mark(this);
|
2014-09-10 14:39:23 +00:00
|
|
|
dataViewCtor.mark(this);
|
2014-11-06 16:40:48 +00:00
|
|
|
for (int i = 0; i < Heap::TypedArray::NTypes; ++i)
|
2014-09-11 13:37:31 +00:00
|
|
|
typedArrayCtors[i].mark(this);
|
2013-11-21 13:26:08 +00:00
|
|
|
sequencePrototype.mark(this);
|
2013-11-02 15:30:26 +00:00
|
|
|
|
|
|
|
exceptionValue.mark(this);
|
|
|
|
|
|
|
|
thrower->mark(this);
|
2013-09-18 07:30:45 +00:00
|
|
|
|
2013-06-20 09:32:45 +00:00
|
|
|
if (m_qmlExtensions)
|
2013-11-02 15:30:26 +00:00
|
|
|
m_qmlExtensions->markObjects(this);
|
2013-08-15 12:11:19 +00:00
|
|
|
|
2014-04-16 07:36:38 +00:00
|
|
|
classPool->markObjects(this);
|
2013-08-29 11:24:38 +00:00
|
|
|
|
2013-08-15 12:11:19 +00:00
|
|
|
for (QSet<CompiledData::CompilationUnit*>::ConstIterator it = compilationUnits.constBegin(), end = compilationUnits.constEnd();
|
|
|
|
it != end; ++it)
|
2013-11-02 15:30:26 +00:00
|
|
|
(*it)->markObjects(this);
|
2013-01-28 15:46:09 +00:00
|
|
|
}
|
2013-05-25 13:31:23 +00:00
|
|
|
|
2013-06-20 09:32:45 +00:00
|
|
|
QmlExtensions *ExecutionEngine::qmlExtensions()
|
|
|
|
{
|
|
|
|
if (!m_qmlExtensions)
|
|
|
|
m_qmlExtensions = new QmlExtensions;
|
|
|
|
return m_qmlExtensions;
|
|
|
|
}
|
|
|
|
|
2014-07-28 08:07:57 +00:00
|
|
|
ReturnedValue ExecutionEngine::throwError(const ValueRef value)
|
2013-10-01 14:19:28 +00:00
|
|
|
{
|
2013-10-22 11:26:08 +00:00
|
|
|
// we can get in here with an exception already set, as the runtime
|
|
|
|
// doesn't check after every operation that can throw.
|
|
|
|
// in this case preserve the first exception to give correct error
|
|
|
|
// information
|
|
|
|
if (hasException)
|
|
|
|
return Encode::undefined();
|
|
|
|
|
2013-10-01 14:19:28 +00:00
|
|
|
hasException = true;
|
|
|
|
exceptionValue = value;
|
|
|
|
QV4::Scope scope(this);
|
|
|
|
QV4::Scoped<ErrorObject> error(scope, value);
|
|
|
|
if (!!error)
|
2014-04-29 09:02:35 +00:00
|
|
|
exceptionStackTrace = error->d()->stackTrace;
|
2013-10-01 14:19:28 +00:00
|
|
|
else
|
|
|
|
exceptionStackTrace = stackTrace();
|
|
|
|
|
|
|
|
if (debugger)
|
2013-10-16 10:29:47 +00:00
|
|
|
debugger->aboutToThrow();
|
2013-10-01 14:19:28 +00:00
|
|
|
|
2013-10-21 07:57:58 +00:00
|
|
|
return Encode::undefined();
|
2013-10-01 14:19:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ReturnedValue ExecutionEngine::catchException(ExecutionContext *catchingContext, StackTrace *trace)
|
|
|
|
{
|
2013-10-16 12:03:48 +00:00
|
|
|
Q_ASSERT(hasException);
|
2013-11-21 15:41:32 +00:00
|
|
|
Q_UNUSED(catchingContext);
|
|
|
|
Q_ASSERT(currentContext() == catchingContext);
|
2013-10-01 14:19:28 +00:00
|
|
|
if (trace)
|
|
|
|
*trace = exceptionStackTrace;
|
|
|
|
exceptionStackTrace.clear();
|
|
|
|
hasException = false;
|
|
|
|
ReturnedValue res = exceptionValue.asReturnedValue();
|
2013-10-21 15:07:45 +00:00
|
|
|
exceptionValue = Primitive::emptyValue();
|
2013-10-01 14:19:28 +00:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2014-07-28 08:07:57 +00:00
|
|
|
ReturnedValue ExecutionEngine::throwError(const QString &message)
|
|
|
|
{
|
|
|
|
Scope scope(this);
|
|
|
|
ScopedValue v(scope, newString(message));
|
|
|
|
v = newErrorObject(v);
|
|
|
|
return throwError(v);
|
|
|
|
}
|
|
|
|
|
|
|
|
ReturnedValue ExecutionEngine::throwSyntaxError(const QString &message, const QString &fileName, int line, int column)
|
|
|
|
{
|
|
|
|
Scope scope(this);
|
|
|
|
Scoped<Object> error(scope, newSyntaxErrorObject(message, fileName, line, column));
|
|
|
|
return throwError(error);
|
|
|
|
}
|
|
|
|
|
|
|
|
ReturnedValue ExecutionEngine::throwSyntaxError(const QString &message)
|
|
|
|
{
|
|
|
|
Scope scope(this);
|
|
|
|
Scoped<Object> error(scope, newSyntaxErrorObject(message));
|
|
|
|
return throwError(error);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ReturnedValue ExecutionEngine::throwTypeError()
|
|
|
|
{
|
|
|
|
Scope scope(this);
|
|
|
|
Scoped<Object> error(scope, newTypeErrorObject(QStringLiteral("Type error")));
|
|
|
|
return throwError(error);
|
|
|
|
}
|
|
|
|
|
|
|
|
ReturnedValue ExecutionEngine::throwTypeError(const QString &message)
|
|
|
|
{
|
|
|
|
Scope scope(this);
|
|
|
|
Scoped<Object> error(scope, newTypeErrorObject(message));
|
|
|
|
return throwError(error);
|
|
|
|
}
|
|
|
|
|
|
|
|
ReturnedValue ExecutionEngine::throwReferenceError(const ValueRef value)
|
|
|
|
{
|
|
|
|
Scope scope(this);
|
|
|
|
Scoped<String> s(scope, value->toString(this));
|
|
|
|
QString msg = s->toQString() + QStringLiteral(" is not defined");
|
|
|
|
Scoped<Object> error(scope, newReferenceErrorObject(msg));
|
|
|
|
return throwError(error);
|
|
|
|
}
|
|
|
|
|
|
|
|
ReturnedValue ExecutionEngine::throwReferenceError(const QString &message, const QString &fileName, int line, int column)
|
|
|
|
{
|
|
|
|
Scope scope(this);
|
|
|
|
QString msg = message;
|
|
|
|
Scoped<Object> error(scope, newReferenceErrorObject(msg, fileName, line, column));
|
|
|
|
return throwError(error);
|
|
|
|
}
|
|
|
|
|
|
|
|
ReturnedValue ExecutionEngine::throwRangeError(const QString &message)
|
|
|
|
{
|
|
|
|
Scope scope(this);
|
|
|
|
ScopedObject error(scope, newRangeErrorObject(message));
|
|
|
|
return throwError(error);
|
|
|
|
}
|
|
|
|
|
|
|
|
ReturnedValue ExecutionEngine::throwRangeError(const ValueRef value)
|
|
|
|
{
|
|
|
|
Scope scope(this);
|
|
|
|
ScopedString s(scope, value->toString(this));
|
|
|
|
QString msg = s->toQString() + QStringLiteral(" out of range");
|
|
|
|
ScopedObject error(scope, newRangeErrorObject(msg));
|
|
|
|
return throwError(error);
|
|
|
|
}
|
|
|
|
|
|
|
|
ReturnedValue ExecutionEngine::throwURIError(const ValueRef msg)
|
|
|
|
{
|
|
|
|
Scope scope(this);
|
|
|
|
ScopedObject error(scope, newURIErrorObject(msg));
|
|
|
|
return throwError(error);
|
|
|
|
}
|
|
|
|
|
|
|
|
ReturnedValue ExecutionEngine::throwUnimplemented(const QString &message)
|
|
|
|
{
|
|
|
|
Scope scope(this);
|
|
|
|
ScopedValue v(scope, newString(QStringLiteral("Unimplemented ") + message));
|
|
|
|
v = newErrorObject(v);
|
|
|
|
return throwError(v);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-10-21 07:50:27 +00:00
|
|
|
QQmlError ExecutionEngine::catchExceptionAsQmlError(ExecutionContext *context)
|
2013-10-17 06:56:51 +00:00
|
|
|
{
|
|
|
|
QV4::StackTrace trace;
|
|
|
|
QV4::Scope scope(context);
|
|
|
|
QV4::ScopedValue exception(scope, context->catchException(&trace));
|
|
|
|
QQmlError error;
|
|
|
|
if (!trace.isEmpty()) {
|
|
|
|
QV4::StackFrame frame = trace.first();
|
|
|
|
error.setUrl(QUrl(frame.source));
|
|
|
|
error.setLine(frame.line);
|
|
|
|
error.setColumn(frame.column);
|
|
|
|
}
|
|
|
|
QV4::Scoped<QV4::ErrorObject> errorObj(scope, exception);
|
|
|
|
if (!!errorObj && errorObj->asSyntaxError()) {
|
2013-11-01 11:38:32 +00:00
|
|
|
QV4::ScopedString m(scope, errorObj->engine()->newString(QStringLiteral("message")));
|
2014-05-07 11:33:24 +00:00
|
|
|
QV4::ScopedValue v(scope, errorObj->get(m.getPointer()));
|
2013-10-17 06:56:51 +00:00
|
|
|
error.setDescription(v->toQStringNoThrow());
|
|
|
|
} else
|
|
|
|
error.setDescription(exception->toQStringNoThrow());
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2013-11-11 10:22:24 +00:00
|
|
|
bool ExecutionEngine::recheckCStackLimits()
|
|
|
|
{
|
|
|
|
int dummy;
|
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
// ### this is only required on windows, where we currently use heuristics to get the stack limit
|
|
|
|
if (cStackLimit - reinterpret_cast<quintptr>(&dummy) > 128*1024)
|
|
|
|
// we're more then 128k away from our stack limit, assume the thread has changed, and
|
|
|
|
// call getStackLimit
|
|
|
|
#endif
|
|
|
|
// this can happen after a thread change
|
|
|
|
cStackLimit = getStackLimit();
|
|
|
|
|
|
|
|
return (reinterpret_cast<quintptr>(&dummy) >= cStackLimit);
|
|
|
|
}
|
|
|
|
|
2013-06-24 13:28:00 +00:00
|
|
|
QT_END_NAMESPACE
|