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$
|
|
|
|
**
|
|
|
|
****************************************************************************/
|
|
|
|
#include <qmljs_engine.h>
|
|
|
|
#include <qmljs_objects.h>
|
|
|
|
#include <qv4ecmaobjects_p.h>
|
2013-01-13 22:57:35 +00:00
|
|
|
#include <qmljs_runtime.h>
|
2012-12-04 12:40:18 +00:00
|
|
|
#include "qv4mm.h"
|
2012-11-17 20:54:26 +00:00
|
|
|
|
|
|
|
namespace QQmlJS {
|
|
|
|
namespace VM {
|
|
|
|
|
2012-12-13 14:11:21 +00:00
|
|
|
class StringPool
|
2012-11-28 12:39:14 +00:00
|
|
|
{
|
|
|
|
QHash<QString, String*> strings;
|
2012-12-13 14:11:21 +00:00
|
|
|
public:
|
2012-12-04 12:40:18 +00:00
|
|
|
~StringPool()
|
2012-12-13 14:11:21 +00:00
|
|
|
{
|
|
|
|
qDeleteAll(strings);
|
|
|
|
}
|
2012-12-04 12:40:18 +00:00
|
|
|
|
2012-11-28 12:39:14 +00:00
|
|
|
String *newString(const QString &s)
|
|
|
|
{
|
|
|
|
QHash<QString, String*>::const_iterator it = strings.find(s);
|
|
|
|
if (it != strings.end())
|
|
|
|
return it.value();
|
|
|
|
String *str = new String(s);
|
|
|
|
strings.insert(s, str);
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-01-03 11:26:19 +00:00
|
|
|
ExecutionEngine::ExecutionEngine(EvalISelFactory *factory)
|
|
|
|
: memoryManager(new QQmlJS::VM::MemoryManager)
|
2012-12-04 12:40:18 +00:00
|
|
|
, iselFactory(factory)
|
2012-11-29 13:41:26 +00:00
|
|
|
, debugger(0)
|
2012-12-04 12:40:18 +00:00
|
|
|
, globalObject(Value::nullValue())
|
|
|
|
, exception(Value::nullValue())
|
2012-11-17 20:54:26 +00:00
|
|
|
{
|
2012-12-04 12:40:18 +00:00
|
|
|
MemoryManager::GCBlocker gcBlocker(memoryManager);
|
|
|
|
|
2012-12-13 09:46:31 +00:00
|
|
|
stringPool.reset(new StringPool);
|
2012-12-04 12:40:18 +00:00
|
|
|
memoryManager->setExecutionEngine(this);
|
2012-11-28 12:39:14 +00:00
|
|
|
|
2012-11-17 20:54:26 +00:00
|
|
|
rootContext = newContext();
|
|
|
|
rootContext->init(this);
|
2012-12-14 08:55:10 +00:00
|
|
|
current = rootContext;
|
2012-11-17 20:54:26 +00:00
|
|
|
|
|
|
|
id_length = identifier(QStringLiteral("length"));
|
|
|
|
id_prototype = identifier(QStringLiteral("prototype"));
|
|
|
|
id_constructor = identifier(QStringLiteral("constructor"));
|
|
|
|
id_arguments = identifier(QStringLiteral("arguments"));
|
2013-01-13 22:57:35 +00:00
|
|
|
id_caller = identifier(QStringLiteral("caller"));
|
2012-12-09 04:16:04 +00:00
|
|
|
id_this = identifier(QStringLiteral("this"));
|
2012-11-17 20:54:26 +00:00
|
|
|
id___proto__ = identifier(QStringLiteral("__proto__"));
|
2012-12-08 07:57:35 +00:00
|
|
|
id_enumerable = identifier(QStringLiteral("enumerable"));
|
|
|
|
id_configurable = identifier(QStringLiteral("configurable"));
|
|
|
|
id_writable = identifier(QStringLiteral("writable"));
|
|
|
|
id_value = identifier(QStringLiteral("value"));
|
|
|
|
id_get = identifier(QStringLiteral("get"));
|
|
|
|
id_set = identifier(QStringLiteral("set"));
|
2012-11-17 20:54:26 +00:00
|
|
|
|
2012-12-04 12:40:18 +00:00
|
|
|
objectPrototype = new (memoryManager) ObjectPrototype();
|
|
|
|
stringPrototype = new (memoryManager) StringPrototype(rootContext);
|
|
|
|
numberPrototype = new (memoryManager) NumberPrototype();
|
|
|
|
booleanPrototype = new (memoryManager) BooleanPrototype();
|
2013-01-11 13:33:10 +00:00
|
|
|
arrayPrototype = new (memoryManager) ArrayPrototype(rootContext);
|
2012-12-04 12:40:18 +00:00
|
|
|
datePrototype = new (memoryManager) DatePrototype();
|
|
|
|
functionPrototype = new (memoryManager) FunctionPrototype(rootContext);
|
|
|
|
regExpPrototype = new (memoryManager) RegExpPrototype();
|
|
|
|
errorPrototype = new (memoryManager) ErrorPrototype();
|
|
|
|
evalErrorPrototype = new (memoryManager) EvalErrorPrototype(rootContext);
|
|
|
|
rangeErrorPrototype = new (memoryManager) RangeErrorPrototype(rootContext);
|
|
|
|
referenceErrorPrototype = new (memoryManager) ReferenceErrorPrototype(rootContext);
|
|
|
|
syntaxErrorPrototype = new (memoryManager) SyntaxErrorPrototype(rootContext);
|
|
|
|
typeErrorPrototype = new (memoryManager) TypeErrorPrototype(rootContext);
|
|
|
|
uRIErrorPrototype = new (memoryManager) URIErrorPrototype(rootContext);
|
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;
|
|
|
|
evalErrorPrototype->prototype = errorPrototype;
|
|
|
|
rangeErrorPrototype->prototype = errorPrototype;
|
|
|
|
referenceErrorPrototype->prototype = errorPrototype;
|
|
|
|
syntaxErrorPrototype->prototype = errorPrototype;
|
|
|
|
typeErrorPrototype->prototype = errorPrototype;
|
|
|
|
uRIErrorPrototype->prototype = errorPrototype;
|
|
|
|
|
2012-12-04 12:40:18 +00:00
|
|
|
objectCtor = Value::fromObject(new (memoryManager) ObjectCtor(rootContext));
|
|
|
|
stringCtor = Value::fromObject(new (memoryManager) StringCtor(rootContext));
|
|
|
|
numberCtor = Value::fromObject(new (memoryManager) NumberCtor(rootContext));
|
|
|
|
booleanCtor = Value::fromObject(new (memoryManager) BooleanCtor(rootContext));
|
|
|
|
arrayCtor = Value::fromObject(new (memoryManager) ArrayCtor(rootContext));
|
|
|
|
functionCtor = Value::fromObject(new (memoryManager) FunctionCtor(rootContext));
|
|
|
|
dateCtor = Value::fromObject(new (memoryManager) DateCtor(rootContext));
|
|
|
|
regExpCtor = Value::fromObject(new (memoryManager) RegExpCtor(rootContext));
|
|
|
|
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);
|
|
|
|
stringPrototype->init(rootContext, stringCtor);
|
|
|
|
numberPrototype->init(rootContext, numberCtor);
|
|
|
|
booleanPrototype->init(rootContext, booleanCtor);
|
|
|
|
arrayPrototype->init(rootContext, arrayCtor);
|
|
|
|
datePrototype->init(rootContext, dateCtor);
|
|
|
|
functionPrototype->init(rootContext, functionCtor);
|
|
|
|
regExpPrototype->init(rootContext, regExpCtor);
|
|
|
|
errorPrototype->init(rootContext, errorCtor);
|
|
|
|
evalErrorPrototype->init(rootContext, evalErrorCtor);
|
|
|
|
rangeErrorPrototype->init(rootContext, rangeErrorCtor);
|
|
|
|
referenceErrorPrototype->init(rootContext, referenceErrorCtor);
|
|
|
|
syntaxErrorPrototype->init(rootContext, syntaxErrorCtor);
|
|
|
|
typeErrorPrototype->init(rootContext, typeErrorCtor);
|
|
|
|
uRIErrorPrototype->init(rootContext, uRIErrorCtor);
|
|
|
|
|
|
|
|
//
|
|
|
|
// set up the global object
|
|
|
|
//
|
|
|
|
VM::Object *glo = newObject(/*rootContext*/);
|
|
|
|
globalObject = Value::fromObject(glo);
|
2012-12-01 13:05:07 +00:00
|
|
|
rootContext->activation = glo;
|
2012-12-10 18:30:08 +00:00
|
|
|
rootContext->thisObject = Value::fromObject(glo);
|
2012-11-17 20:54:26 +00:00
|
|
|
|
2012-12-12 23:53:04 +00:00
|
|
|
glo->defineDefaultProperty(rootContext, QStringLiteral("Object"), objectCtor);
|
|
|
|
glo->defineDefaultProperty(rootContext, QStringLiteral("String"), stringCtor);
|
|
|
|
glo->defineDefaultProperty(rootContext, QStringLiteral("Number"), numberCtor);
|
|
|
|
glo->defineDefaultProperty(rootContext, QStringLiteral("Boolean"), booleanCtor);
|
|
|
|
glo->defineDefaultProperty(rootContext, QStringLiteral("Array"), arrayCtor);
|
|
|
|
glo->defineDefaultProperty(rootContext, QStringLiteral("Function"), functionCtor);
|
|
|
|
glo->defineDefaultProperty(rootContext, QStringLiteral("Date"), dateCtor);
|
|
|
|
glo->defineDefaultProperty(rootContext, QStringLiteral("RegExp"), regExpCtor);
|
|
|
|
glo->defineDefaultProperty(rootContext, QStringLiteral("Error"), errorCtor);
|
|
|
|
glo->defineDefaultProperty(rootContext, QStringLiteral("EvalError"), evalErrorCtor);
|
|
|
|
glo->defineDefaultProperty(rootContext, QStringLiteral("RangeError"), rangeErrorCtor);
|
|
|
|
glo->defineDefaultProperty(rootContext, QStringLiteral("ReferenceError"), referenceErrorCtor);
|
|
|
|
glo->defineDefaultProperty(rootContext, QStringLiteral("SyntaxError"), syntaxErrorCtor);
|
|
|
|
glo->defineDefaultProperty(rootContext, QStringLiteral("TypeError"), typeErrorCtor);
|
|
|
|
glo->defineDefaultProperty(rootContext, QStringLiteral("URIError"), uRIErrorCtor);
|
|
|
|
glo->defineDefaultProperty(rootContext, QStringLiteral("Math"), Value::fromObject(newMathObject(rootContext)));
|
|
|
|
|
|
|
|
glo->defineReadonlyProperty(this, QStringLiteral("undefined"), Value::undefinedValue());
|
|
|
|
glo->defineReadonlyProperty(this, QStringLiteral("NaN"), Value::fromDouble(nan("")));
|
|
|
|
glo->defineReadonlyProperty(this, QStringLiteral("Infinity"), Value::fromDouble(INFINITY));
|
|
|
|
|
|
|
|
glo->defineDefaultProperty(rootContext, QStringLiteral("eval"), Value::fromObject(new (memoryManager) EvalFunction(rootContext)));
|
2012-11-17 20:54:26 +00:00
|
|
|
|
2013-01-09 13:37:55 +00:00
|
|
|
glo->defineDefaultProperty(rootContext, QStringLiteral("parseInt"), Value::fromObject(new (memoryManager) ParseIntFunction(rootContext)));
|
|
|
|
glo->defineDefaultProperty(rootContext, QStringLiteral("parseFloat"), Value::fromObject(new (memoryManager) ParseFloatFunction(rootContext)));
|
2012-12-12 23:53:04 +00:00
|
|
|
glo->defineDefaultProperty(rootContext, QStringLiteral("isNaN"), Value::fromObject(new (memoryManager) IsNaNFunction(rootContext)));
|
|
|
|
glo->defineDefaultProperty(rootContext, QStringLiteral("isFinite"), Value::fromObject(new (memoryManager) IsFiniteFunction(rootContext)));
|
2012-11-17 20:54:26 +00:00
|
|
|
}
|
|
|
|
|
2012-12-04 10:30:26 +00:00
|
|
|
ExecutionEngine::~ExecutionEngine()
|
|
|
|
{
|
|
|
|
delete globalObject.asObject();
|
|
|
|
delete rootContext;
|
2012-12-11 09:03:40 +00:00
|
|
|
qDeleteAll(functions);
|
2013-01-03 11:26:19 +00:00
|
|
|
delete memoryManager;
|
2012-12-04 10:30:26 +00:00
|
|
|
}
|
|
|
|
|
2012-11-17 20:54:26 +00:00
|
|
|
ExecutionContext *ExecutionEngine::newContext()
|
|
|
|
{
|
|
|
|
return new ExecutionContext();
|
|
|
|
}
|
|
|
|
|
|
|
|
String *ExecutionEngine::identifier(const QString &s)
|
|
|
|
{
|
2012-12-13 15:12:53 +00:00
|
|
|
return stringPool->newString(s);
|
2012-11-17 20:54:26 +00:00
|
|
|
}
|
|
|
|
|
2012-12-11 09:03:40 +00:00
|
|
|
Function *ExecutionEngine::newFunction(const QString &name)
|
|
|
|
{
|
|
|
|
VM::Function *f = new VM::Function(name);
|
|
|
|
functions.append(f);
|
|
|
|
return f;
|
|
|
|
}
|
|
|
|
|
2012-11-29 13:39:19 +00:00
|
|
|
FunctionObject *ExecutionEngine::newNativeFunction(ExecutionContext *scope, String *name, Value (*code)(ExecutionContext *))
|
2012-11-17 20:54:26 +00:00
|
|
|
{
|
2012-12-04 12:40:18 +00:00
|
|
|
NativeFunction *f = new (memoryManager) NativeFunction(scope, name, code);
|
2012-11-17 20:54:26 +00:00
|
|
|
f->prototype = scope->engine->functionPrototype;
|
|
|
|
return f;
|
|
|
|
}
|
|
|
|
|
2012-12-11 09:03:40 +00:00
|
|
|
FunctionObject *ExecutionEngine::newScriptFunction(ExecutionContext *scope, VM::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()
|
|
|
|
{
|
2012-12-04 12:40:18 +00:00
|
|
|
Object *object = new (memoryManager) Object();
|
2012-11-17 20:54:26 +00:00
|
|
|
object->prototype = objectPrototype;
|
|
|
|
return object;
|
|
|
|
}
|
|
|
|
|
|
|
|
FunctionObject *ExecutionEngine::newObjectCtor(ExecutionContext *ctx)
|
|
|
|
{
|
2012-12-04 12:40:18 +00:00
|
|
|
return new (memoryManager) ObjectCtor(ctx);
|
2012-11-17 20:54:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
String *ExecutionEngine::newString(const QString &s)
|
|
|
|
{
|
2012-11-28 12:39:14 +00:00
|
|
|
return stringPool->newString(s);
|
2012-11-17 20:54:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Object *ExecutionEngine::newStringObject(const Value &value)
|
|
|
|
{
|
2012-12-04 12:40:18 +00:00
|
|
|
StringObject *object = new (memoryManager) StringObject(value);
|
2012-11-17 20:54:26 +00:00
|
|
|
object->prototype = stringPrototype;
|
|
|
|
return object;
|
|
|
|
}
|
|
|
|
|
|
|
|
FunctionObject *ExecutionEngine::newStringCtor(ExecutionContext *ctx)
|
|
|
|
{
|
2012-12-04 12:40:18 +00:00
|
|
|
return new (memoryManager) StringCtor(ctx);
|
2012-11-17 20:54:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Object *ExecutionEngine::newNumberObject(const Value &value)
|
|
|
|
{
|
2012-12-04 12:40:18 +00:00
|
|
|
NumberObject *object = new (memoryManager) NumberObject(value);
|
2012-11-17 20:54:26 +00:00
|
|
|
object->prototype = numberPrototype;
|
|
|
|
return object;
|
|
|
|
}
|
|
|
|
|
|
|
|
FunctionObject *ExecutionEngine::newNumberCtor(ExecutionContext *ctx)
|
|
|
|
{
|
2012-12-04 12:40:18 +00:00
|
|
|
return new (memoryManager) NumberCtor(ctx);
|
2012-11-17 20:54:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Object *ExecutionEngine::newBooleanObject(const Value &value)
|
|
|
|
{
|
2012-12-04 12:40:18 +00:00
|
|
|
Object *object = new (memoryManager) BooleanObject(value);
|
2012-11-17 20:54:26 +00:00
|
|
|
object->prototype = booleanPrototype;
|
|
|
|
return object;
|
|
|
|
}
|
|
|
|
|
|
|
|
FunctionObject *ExecutionEngine::newBooleanCtor(ExecutionContext *ctx)
|
|
|
|
{
|
2012-12-04 12:40:18 +00:00
|
|
|
return new (memoryManager) BooleanCtor(ctx);
|
2012-11-17 20:54:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Object *ExecutionEngine::newFunctionObject(ExecutionContext *ctx)
|
|
|
|
{
|
2012-12-04 12:40:18 +00:00
|
|
|
Object *object = new (memoryManager) FunctionObject(ctx);
|
2012-11-17 20:54:26 +00:00
|
|
|
object->prototype = functionPrototype;
|
|
|
|
return object;
|
|
|
|
}
|
|
|
|
|
2013-01-11 13:33:10 +00:00
|
|
|
ArrayObject *ExecutionEngine::newArrayObject(ExecutionContext *ctx)
|
2012-11-17 20:54:26 +00:00
|
|
|
{
|
2013-01-11 13:33:10 +00:00
|
|
|
ArrayObject *object = new (memoryManager) ArrayObject(ctx);
|
2012-11-17 20:54:26 +00:00
|
|
|
object->prototype = arrayPrototype;
|
|
|
|
return object;
|
|
|
|
}
|
|
|
|
|
2013-01-11 13:33:10 +00:00
|
|
|
ArrayObject *ExecutionEngine::newArrayObject(ExecutionContext *ctx, const Array &value)
|
2012-11-17 20:54:26 +00:00
|
|
|
{
|
2013-01-11 13:33:10 +00:00
|
|
|
ArrayObject *object = new (memoryManager) ArrayObject(ctx, value);
|
2012-11-17 20:54:26 +00:00
|
|
|
object->prototype = arrayPrototype;
|
|
|
|
return object;
|
|
|
|
}
|
|
|
|
|
|
|
|
FunctionObject *ExecutionEngine::newArrayCtor(ExecutionContext *ctx)
|
|
|
|
{
|
2012-12-04 12:40:18 +00:00
|
|
|
return new (memoryManager) ArrayCtor(ctx);
|
2012-11-17 20:54:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Object *ExecutionEngine::newDateObject(const Value &value)
|
|
|
|
{
|
2012-12-04 12:40:18 +00:00
|
|
|
Object *object = new (memoryManager) DateObject(value);
|
2012-11-17 20:54:26 +00:00
|
|
|
object->prototype = datePrototype;
|
|
|
|
return object;
|
|
|
|
}
|
|
|
|
|
|
|
|
FunctionObject *ExecutionEngine::newDateCtor(ExecutionContext *ctx)
|
|
|
|
{
|
2012-12-04 12:40:18 +00:00
|
|
|
return new (memoryManager) DateCtor(ctx);
|
2012-11-17 20:54:26 +00:00
|
|
|
}
|
|
|
|
|
2012-12-12 07:28:08 +00:00
|
|
|
RegExpObject *ExecutionEngine::newRegExpObject(const QString &pattern, int flags)
|
2012-11-17 20:54:26 +00:00
|
|
|
{
|
|
|
|
bool global = (flags & IR::RegExp::RegExp_Global);
|
|
|
|
QRegularExpression::PatternOptions options = 0;
|
|
|
|
if (flags & IR::RegExp::RegExp_IgnoreCase)
|
|
|
|
options |= QRegularExpression::CaseInsensitiveOption;
|
|
|
|
if (flags & IR::RegExp::RegExp_Multiline)
|
|
|
|
options |= QRegularExpression::MultilineOption;
|
|
|
|
|
2012-12-12 07:28:08 +00:00
|
|
|
QRegularExpression re(pattern, options);
|
|
|
|
return newRegExpObject(re, global);
|
|
|
|
}
|
|
|
|
|
|
|
|
RegExpObject *ExecutionEngine::newRegExpObject(const QRegularExpression &re, bool global)
|
|
|
|
{
|
|
|
|
RegExpObject *object = new (memoryManager) RegExpObject(re, global);
|
2012-11-17 20:54:26 +00:00
|
|
|
object->prototype = regExpPrototype;
|
|
|
|
return object;
|
|
|
|
}
|
|
|
|
|
|
|
|
FunctionObject *ExecutionEngine::newRegExpCtor(ExecutionContext *ctx)
|
|
|
|
{
|
2012-12-04 12:40:18 +00:00
|
|
|
return new (memoryManager) RegExpCtor(ctx);
|
2012-11-17 20:54:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Object *ExecutionEngine::newErrorObject(const Value &value)
|
|
|
|
{
|
2012-12-04 12:40:18 +00:00
|
|
|
ErrorObject *object = new (memoryManager) ErrorObject(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)
|
|
|
|
{
|
2012-12-04 12:40:18 +00:00
|
|
|
SyntaxErrorObject *object = new (memoryManager) SyntaxErrorObject(ctx, message);
|
2012-11-28 10:00:23 +00:00
|
|
|
object->prototype = syntaxErrorPrototype;
|
|
|
|
return object;
|
|
|
|
}
|
|
|
|
|
2012-12-04 18:50:25 +00:00
|
|
|
Object *ExecutionEngine::newReferenceErrorObject(ExecutionContext *ctx, const QString &message)
|
|
|
|
{
|
2012-12-04 12:40:18 +00:00
|
|
|
ReferenceErrorObject *object = new (memoryManager) ReferenceErrorObject(ctx, message);
|
2012-12-04 18:50:25 +00:00
|
|
|
object->prototype = referenceErrorPrototype;
|
|
|
|
return object;
|
|
|
|
}
|
|
|
|
|
|
|
|
Object *ExecutionEngine::newTypeErrorObject(ExecutionContext *ctx, const QString &message)
|
|
|
|
{
|
2012-12-04 12:40:18 +00:00
|
|
|
TypeErrorObject *object = new (memoryManager) TypeErrorObject(ctx, message);
|
2012-12-04 18:50:25 +00:00
|
|
|
object->prototype = typeErrorPrototype;
|
|
|
|
return object;
|
|
|
|
}
|
|
|
|
|
2013-01-11 08:56:56 +00:00
|
|
|
Object *ExecutionEngine::newRangeErrorObject(ExecutionContext *ctx, const QString &message)
|
|
|
|
{
|
|
|
|
RangeErrorObject *object = new (memoryManager) RangeErrorObject(ctx, message);
|
|
|
|
object->prototype = rangeErrorPrototype;
|
|
|
|
return object;
|
|
|
|
}
|
|
|
|
|
2012-11-17 20:54:26 +00:00
|
|
|
Object *ExecutionEngine::newMathObject(ExecutionContext *ctx)
|
|
|
|
{
|
2012-12-04 12:40:18 +00:00
|
|
|
MathObject *object = new (memoryManager) MathObject(ctx);
|
2012-11-17 20:54:26 +00:00
|
|
|
object->prototype = objectPrototype;
|
|
|
|
return object;
|
|
|
|
}
|
|
|
|
|
2012-12-04 21:46:48 +00:00
|
|
|
Object *ExecutionEngine::newActivationObject()
|
2012-11-17 20:54:26 +00:00
|
|
|
{
|
2012-12-04 12:40:18 +00:00
|
|
|
return new (memoryManager) Object();
|
2012-11-17 20:54:26 +00:00
|
|
|
}
|
|
|
|
|
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);
|
2012-11-17 20:54:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace VM
|
|
|
|
} // namespace QQmlJS
|