qtdeclarative/qmljs_objects.cpp

780 lines
24 KiB
C++
Raw Normal View History

/****************************************************************************
**
** 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$
**
****************************************************************************/
2012-04-16 19:23:25 +00:00
#include "qmljs_objects.h"
2012-05-07 14:05:05 +00:00
#include "qv4ir_p.h"
2012-05-14 15:12:25 +00:00
#include "qv4ecmaobjects_p.h"
#include <QtCore/qmath.h>
2012-05-07 14:05:05 +00:00
#include <QtCore/QDebug>
2012-04-16 19:23:25 +00:00
#include <cassert>
#include <typeinfo>
2012-04-16 19:23:25 +00:00
2012-05-04 13:28:04 +00:00
using namespace QQmlJS::VM;
//
// Object
//
2012-05-04 13:12:37 +00:00
Object::~Object()
{
delete members;
}
void Object::__put__(Context *ctx, const QString &name, const Value &value)
2012-05-14 14:03:10 +00:00
{
__put__(ctx, ctx->engine->identifier(name), value);
2012-05-14 14:03:10 +00:00
}
void Object::__put__(Context *ctx, const QString &name, void (*code)(Context *), int count)
2012-05-14 14:03:10 +00:00
{
Q_UNUSED(count);
__put__(ctx, name, Value::fromObject(ctx->engine->newNativeFunction(ctx, code)));
2012-05-28 18:17:13 +00:00
}
Value Object::getValue(Context *ctx, PropertyDescriptor *p) const
{
if (p->isData())
return p->value;
if (!p->get)
return Value::undefinedValue();
p->get->call(ctx, Value::fromObject(const_cast<Object *>(this)), 0, 0);
return ctx->result;
}
bool Object::inplaceBinOp(Value rhs, Context *ctx, String *name, BinOp op)
{
PropertyDescriptor to_fill;
PropertyDescriptor *pd = __getPropertyDescriptor__(ctx, name, &to_fill);
if (!pd)
return false;
Value result = op(getValue(ctx, pd), rhs, ctx);
__put__(ctx, name, result);
return true;
}
bool Object::inplaceBinOp(Value rhs, Value index, BinOp op, Context *ctx)
{
String *name = index.toString(ctx);
assert(name);
return inplaceBinOp(rhs, ctx, name, op);
}
// Section 8.12.1
PropertyDescriptor *Object::__getOwnProperty__(Context *, String *name)
2012-04-16 19:23:25 +00:00
{
if (members)
return members->find(name);
2012-04-16 19:23:25 +00:00
return 0;
}
// Section 8.12.2
PropertyDescriptor *Object::__getPropertyDescriptor__(Context *ctx, String *name, PropertyDescriptor *to_fill)
2012-04-16 19:23:25 +00:00
{
if (PropertyDescriptor *p = __getOwnProperty__(ctx, name))
return p;
if (prototype)
return prototype->__getPropertyDescriptor__(ctx, name, to_fill);
2012-04-16 19:23:25 +00:00
return 0;
}
// Section 8.12.3
Value Object::__get__(Context *ctx, String *name)
2012-04-16 19:23:25 +00:00
{
if (name->isEqualTo(ctx->engine->id___proto__))
return Value::fromObject(prototype);
2012-04-16 19:23:25 +00:00
PropertyDescriptor tmp;
if (PropertyDescriptor *p = __getPropertyDescriptor__(ctx, name, &tmp))
return getValue(ctx, p);
return Value::undefinedValue();
2012-04-16 19:23:25 +00:00
}
// Section 8.12.4
bool Object::__canPut__(Context *ctx, String *name)
2012-04-16 19:23:25 +00:00
{
if (PropertyDescriptor *p = __getOwnProperty__(ctx, name)) {
if (p->isAccessor())
return p->get != 0;
return p->isWritable();
}
if (! prototype)
2012-04-16 19:23:25 +00:00
return extensible;
PropertyDescriptor tmp;
if (PropertyDescriptor *p = prototype->__getPropertyDescriptor__(ctx, name, &tmp)) {
if (p->isAccessor())
return p->get != 0;
if (!extensible)
return false;
return p->isWritable();
2012-04-16 19:23:25 +00:00
} else {
return extensible;
}
return true;
}
// Section 8.12.5
void Object::__put__(Context *ctx, String *name, const Value &value, bool throwException)
2012-04-16 19:23:25 +00:00
{
// clause 1
if (!__canPut__(ctx, name))
goto reject;
2012-04-16 19:23:25 +00:00
if (!members)
members = new PropertyTable();
{
// Clause 2
PropertyDescriptor *pd = __getOwnProperty__(ctx, name);
// Clause 3
if (pd && pd->isData()) {
// spec says to call [[DefineOwnProperty]] with { [[Value]]: value }
// ### to simplify and speed up we should expand the relevant parts here (clauses 6,7,9,10,12,13)
PropertyDescriptor desc = PropertyDescriptor::fromValue(value);
__defineOwnProperty__(ctx, name, &desc, throwException);
return;
}
// clause 4
PropertyDescriptor tmp;
if (prototype)
pd = prototype->__getPropertyDescriptor__(ctx, name, &tmp);
// Clause 5
if (pd && pd->isAccessor()) {
assert(pd->set != 0);
Value args[1];
args[0] = value;
pd->set->call(ctx, Value::fromObject(this), args, 1);
return;
}
PropertyDescriptor *p = members->insert(name);
*p = PropertyDescriptor::fromValue(value);
p->configurable = PropertyDescriptor::Set;
p->enumberable = PropertyDescriptor::Set;
p->writable = PropertyDescriptor::Set;
}
reject:
if (throwException)
__qmljs_throw_type_error(ctx);
2012-04-16 19:23:25 +00:00
}
// Section 8.12.6
bool Object::__hasProperty__(Context *ctx, String *name) const
2012-04-16 19:23:25 +00:00
{
if (members)
return members->find(name) != 0;
2012-04-16 19:23:25 +00:00
return prototype ? prototype->__hasProperty__(ctx, name) : false;
2012-04-16 19:23:25 +00:00
}
// Section 8.12.7
bool Object::__delete__(Context *ctx, String *name, bool throwException)
{
if (members) {
if (PropertyTableEntry *entry = members->findEntry(name)) {
if (entry->descriptor.isConfigurable()) {
members->remove(entry);
return true;
}
if (throwException)
__qmljs_throw_type_error(ctx);
return false;
}
}
return true;
}
// Section 8.12.9
bool Object::__defineOwnProperty__(Context *ctx, String *name, PropertyDescriptor *desc, bool throwException)
2012-05-20 17:59:47 +00:00
{
if (!members)
members = new PropertyTable();
// Clause 1
PropertyDescriptor *current = __getOwnProperty__(ctx, name);
if (!current) {
// clause 3
if (!extensible)
goto reject;
// clause 4
*current = *desc;
current->fullyPopulated();
return true;
}
// clause 5
if (desc->isEmpty())
return true;
// clause 6
if (desc->isSubset(current))
return true;
// clause 7
if (!current->isConfigurable()) {
if (desc->isConfigurable())
goto reject;
if (desc->enumberable != PropertyDescriptor::Unset && desc->enumberable != current->enumberable)
goto reject;
}
// clause 8
if (desc->isGeneric())
goto accept;
// clause 9
if (current->isData() != desc->isData()) {
// 9a
if (!current->isConfigurable())
goto reject;
if (current->isData()) {
// 9b
current->type = PropertyDescriptor::Accessor;
current->writable = PropertyDescriptor::Undefined;
current->get = 0;
current->set = 0;
} else {
// 9c
current->type = PropertyDescriptor::Data;
current->writable = PropertyDescriptor::Unset;
current->value = Value::undefinedValue();
}
} else if (current->isData() && desc->isData()) { // clause 10
if (!current->isConfigurable() && !current->isWritable()) {
if (desc->isWritable() || !current->value.sameValue(desc->value))
goto reject;
}
} else { // clause 10
assert(current->isAccessor() && desc->isAccessor());
if (!current->isConfigurable()) {
if (current->get != desc->get || current->set != desc->set)
goto reject;
}
}
accept:
*current += *desc;
return true;
reject:
if (throwException)
__qmljs_throw_type_error(ctx);
return false;
2012-05-25 10:54:36 +00:00
}
2012-05-20 17:59:47 +00:00
String *ForEachIteratorObject::nextPropertyName()
{
PropertyTableEntry *p = 0;
while (1) {
if (!current)
return 0;
// ### index array data as well
++tableIndex;
if (!current->members || tableIndex > current->members->_propertyCount) {
current = current->prototype;
tableIndex = -1;
continue;
}
p = current->members->_properties[tableIndex];
// ### check that it's not a repeated attribute
if (p && p->descriptor.isEnumerable())
return p->name;
}
}
Value ArrayObject::__get__(Context *ctx, String *name)
2012-05-25 10:54:36 +00:00
{
if (name->isEqualTo(ctx->engine->id_length))
return Value::fromDouble(value.size());
return Object::__get__(ctx, name);
2012-05-20 17:59:47 +00:00
}
bool ArrayObject::inplaceBinOp(Value rhs, Value index, BinOp op, Context *ctx)
{
if (index.isNumber()) {
const quint32 idx = index.toUInt32(ctx);
Value v = value.at(idx);
v = op(v, rhs, ctx);
value.assign(idx, v);
return true;
}
return Object::inplaceBinOp(rhs, index, op, ctx);
}
2012-05-28 18:17:13 +00:00
bool FunctionObject::hasInstance(Context *ctx, const Value &value)
2012-04-16 19:23:25 +00:00
{
2012-05-28 18:17:13 +00:00
if (! value.isObject()) {
ctx->throwTypeError();
return false;
}
Value o = __get__(ctx, ctx->engine->id_prototype);
2012-05-28 18:17:13 +00:00
if (! o.isObject()) {
ctx->throwTypeError();
return false;
}
Object *v = value.objectValue();
2012-05-28 18:17:13 +00:00
while (v) {
v = v->prototype;
if (! v)
break;
else if (o.objectValue() == v)
2012-05-28 18:17:13 +00:00
return true;
}
2012-04-16 19:23:25 +00:00
return false;
}
Value FunctionObject::construct(Context *context, Value *args, int argc)
{
Context k;
Context *ctx = needsActivation ? context->engine->newContext() : &k;
ctx->initConstructorContext(context, 0, this, args, argc);
construct(ctx);
ctx->leaveConstructorContext(this);
return ctx->result;
}
Value FunctionObject::call(Context *context, Value thisObject, Value *args, int argc)
{
Context k;
Context *ctx = needsActivation ? context->engine->newContext() : &k;
const Value *that = thisObject.isUndefined() ? 0 : &thisObject;
ctx->initCallContext(context, that, this, args, argc);
call(ctx);
ctx->leaveCallContext();
return ctx->result;
}
2012-05-07 14:05:05 +00:00
void FunctionObject::call(Context *ctx)
2012-04-16 19:23:25 +00:00
{
2012-05-07 14:05:05 +00:00
Q_UNUSED(ctx);
}
void FunctionObject::construct(Context *ctx)
{
ctx->thisObject = Value::fromObject(ctx->engine->newObject());
2012-05-09 11:30:22 +00:00
call(ctx);
2012-05-07 14:05:05 +00:00
}
2012-04-16 19:23:25 +00:00
2012-05-13 11:50:55 +00:00
ScriptFunction::ScriptFunction(Context *scope, IR::Function *function)
: FunctionObject(scope)
2012-05-09 13:47:55 +00:00
, function(function)
2012-05-07 14:05:05 +00:00
{
if (function->name)
name = scope->engine->identifier(*function->name);
needsActivation = function->needsActivation();
2012-05-08 09:13:02 +00:00
formalParameterCount = function->formals.size();
if (formalParameterCount) {
formalParameterList = new String*[formalParameterCount];
for (unsigned int i = 0; i < formalParameterCount; ++i) {
2012-05-14 15:12:25 +00:00
formalParameterList[i] = scope->engine->identifier(*function->formals.at(i));
2012-05-08 09:13:02 +00:00
}
2012-05-07 14:05:05 +00:00
}
2012-05-16 09:58:07 +00:00
varCount = function->locals.size();
if (varCount) {
varList = new String*[varCount];
for (unsigned int i = 0; i < varCount; ++i) {
2012-05-16 09:58:07 +00:00
varList[i] = scope->engine->identifier(*function->locals.at(i));
}
}
2012-05-08 09:13:02 +00:00
}
ScriptFunction::~ScriptFunction()
{
delete[] formalParameterList;
2012-05-16 09:58:07 +00:00
delete[] varList;
2012-05-08 09:13:02 +00:00
}
void ScriptFunction::call(VM::Context *ctx)
{
2012-06-12 17:13:55 +00:00
function->code(ctx, function->codeData);
2012-04-16 19:23:25 +00:00
}
Value RegExpObject::__get__(Context *ctx, String *name)
{
QString n = name->toQString();
if (n == QLatin1String("source"))
return Value::fromString(ctx, value.pattern());
else if (n == QLatin1String("global"))
return Value::fromBoolean(global);
else if (n == QLatin1String("ignoreCase"))
return Value::fromBoolean(value.patternOptions() & QRegularExpression::CaseInsensitiveOption);
else if (n == QLatin1String("multiline"))
return Value::fromBoolean(value.patternOptions() & QRegularExpression::MultilineOption);
else if (n == QLatin1String("lastIndex"))
return lastIndex;
return Object::__get__(ctx, name);
}
void ScriptFunction::construct(VM::Context *ctx)
{
Object *obj = ctx->engine->newObject();
Value proto = __get__(ctx, ctx->engine->id_prototype);
if (proto.isObject())
obj->prototype = proto.objectValue();
ctx->thisObject = Value::fromObject(obj);
2012-06-12 17:13:55 +00:00
function->code(ctx, function->codeData);
}
PropertyDescriptor *ActivationObject::__getPropertyDescriptor__(Context *ctx, String *name, PropertyDescriptor *to_fill)
2012-04-16 19:23:25 +00:00
{
2012-05-08 09:13:02 +00:00
if (context) {
for (unsigned int i = 0; i < context->varCount; ++i) {
2012-05-16 09:58:07 +00:00
String *var = context->vars[i];
if (__qmljs_string_equal(var, name)) {
*to_fill = PropertyDescriptor::fromValue(context->locals[i]);
to_fill->writable = PropertyDescriptor::Set;
to_fill->enumberable = PropertyDescriptor::Set;
return to_fill;
2012-05-16 09:58:07 +00:00
}
}
for (unsigned int i = 0; i < context->formalCount; ++i) {
2012-05-08 09:13:02 +00:00
String *formal = context->formals[i];
if (__qmljs_string_equal(formal, name)) {
*to_fill = PropertyDescriptor::fromValue(context->arguments[i]);
to_fill->writable = PropertyDescriptor::Set;
to_fill->enumberable = PropertyDescriptor::Set;
return to_fill;
2012-05-08 09:13:02 +00:00
}
}
if (name->isEqualTo(ctx->engine->id_arguments)) {
if (arguments.isUndefined()) {
arguments = Value::fromObject(new ArgumentsObject(ctx));
arguments.objectValue()->prototype = ctx->engine->objectPrototype;
}
*to_fill = PropertyDescriptor::fromValue(arguments);
to_fill->writable = PropertyDescriptor::Unset;
to_fill->enumberable = PropertyDescriptor::Unset;
return to_fill;
}
2012-05-08 09:13:02 +00:00
}
return Object::__getPropertyDescriptor__(ctx, name, to_fill);
2012-04-16 19:23:25 +00:00
}
2012-05-14 15:12:25 +00:00
Value ArgumentsObject::__get__(Context *ctx, String *name)
{
if (name->isEqualTo(ctx->engine->id_length))
return Value::fromDouble(context->argumentCount);
return Object::__get__(ctx, name);
}
PropertyDescriptor *ArgumentsObject::__getPropertyDescriptor__(Context *ctx, String *name, PropertyDescriptor *to_fill)
{
if (context) {
const quint32 i = Value::fromString(name).toUInt32(ctx);
if (i < context->argumentCount) {
*to_fill = PropertyDescriptor::fromValue(context->arguments[i]);
to_fill->writable = PropertyDescriptor::Unset;
to_fill->enumberable = PropertyDescriptor::Unset;
return to_fill;
}
}
return Object::__getPropertyDescriptor__(ctx, name, to_fill);
}
2012-05-14 15:12:25 +00:00
ExecutionEngine::ExecutionEngine()
{
2012-05-15 08:35:19 +00:00
rootContext = newContext();
2012-05-14 15:12:25 +00:00
rootContext->init(this);
2012-05-25 10:54:36 +00:00
id_length = identifier(QStringLiteral("length"));
id_prototype = identifier(QStringLiteral("prototype"));
id_constructor = identifier(QStringLiteral("constructor"));
id_arguments = identifier(QStringLiteral("arguments"));
2012-05-28 18:17:13 +00:00
id___proto__ = identifier(QStringLiteral("__proto__"));
2012-05-25 10:54:36 +00:00
objectPrototype = new ObjectPrototype();
stringPrototype = new StringPrototype(rootContext);
numberPrototype = new NumberPrototype();
booleanPrototype = new BooleanPrototype();
arrayPrototype = new ArrayPrototype();
datePrototype = new DatePrototype();
functionPrototype = new FunctionPrototype(rootContext);
2012-06-04 13:34:50 +00:00
regExpPrototype = new RegExpPrototype();
errorPrototype = new ErrorPrototype();
stringPrototype->prototype = objectPrototype;
numberPrototype->prototype = objectPrototype;
booleanPrototype->prototype = objectPrototype;
arrayPrototype->prototype = objectPrototype;
datePrototype->prototype = objectPrototype;
functionPrototype->prototype = objectPrototype;
2012-06-04 13:34:50 +00:00
regExpPrototype->prototype = objectPrototype;
errorPrototype->prototype = objectPrototype;
2012-06-04 13:34:50 +00:00
objectCtor = Value::fromObject(new ObjectCtor(rootContext));
stringCtor = Value::fromObject(new StringCtor(rootContext));
numberCtor = Value::fromObject(new NumberCtor(rootContext));
booleanCtor = Value::fromObject(new BooleanCtor(rootContext));
arrayCtor = Value::fromObject(new ArrayCtor(rootContext));
functionCtor = Value::fromObject(new FunctionCtor(rootContext));
dateCtor = Value::fromObject(new DateCtor(rootContext));
regExpCtor = Value::fromObject(new RegExpCtor(rootContext));
errorCtor = Value::fromObject(new ErrorCtor(rootContext));
2012-06-04 13:34:50 +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;
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);
2012-06-04 13:34:50 +00:00
regExpPrototype->init(rootContext, regExpCtor);
errorPrototype->init(rootContext, errorCtor);
2012-05-14 15:12:25 +00:00
//
// set up the global object
//
VM::Object *glo = newObject(/*rootContext*/);
globalObject = Value::fromObject(glo);
rootContext->activation = Value::fromObject(glo);
2012-05-14 15:12:25 +00:00
glo->__put__(rootContext, identifier(QStringLiteral("Object")), objectCtor);
glo->__put__(rootContext, identifier(QStringLiteral("String")), stringCtor);
glo->__put__(rootContext, identifier(QStringLiteral("Number")), numberCtor);
glo->__put__(rootContext, identifier(QStringLiteral("Boolean")), booleanCtor);
glo->__put__(rootContext, identifier(QStringLiteral("Array")), arrayCtor);
glo->__put__(rootContext, identifier(QStringLiteral("Function")), functionCtor);
glo->__put__(rootContext, identifier(QStringLiteral("Date")), dateCtor);
glo->__put__(rootContext, identifier(QStringLiteral("RegExp")), regExpCtor);
glo->__put__(rootContext, identifier(QStringLiteral("Error")), errorCtor);
glo->__put__(rootContext, identifier(QStringLiteral("Math")), Value::fromObject(newMathObject(rootContext)));
glo->__put__(rootContext, identifier(QStringLiteral("undefined")), Value::undefinedValue());
glo->__put__(rootContext, identifier(QStringLiteral("NaN")), Value::fromDouble(nan("")));
glo->__put__(rootContext, identifier(QStringLiteral("Infinity")), Value::fromDouble(INFINITY));
2012-05-15 08:35:19 +00:00
}
Context *ExecutionEngine::newContext()
{
return new Context();
2012-05-14 15:12:25 +00:00
}
String *ExecutionEngine::identifier(const QString &s)
{
String *&id = identifiers[s];
if (! id)
2012-05-15 08:35:19 +00:00
id = newString(s);
2012-05-14 15:12:25 +00:00
return id;
}
2012-05-15 08:35:19 +00:00
FunctionObject *ExecutionEngine::newNativeFunction(Context *scope, void (*code)(Context *))
{
NativeFunction *f = new NativeFunction(scope, code);
f->prototype = scope->engine->functionPrototype;
return f;
2012-05-15 08:35:19 +00:00
}
FunctionObject *ExecutionEngine::newScriptFunction(Context *scope, IR::Function *function)
{
ScriptFunction *f = new ScriptFunction(scope, function);
Object *proto = scope->engine->newObject();
proto->__put__(scope, scope->engine->id_constructor, Value::fromObject(f));
f->__put__(scope, scope->engine->id_prototype, Value::fromObject(proto));
f->prototype = scope->engine->functionPrototype;
return f;
2012-05-15 08:35:19 +00:00
}
Object *ExecutionEngine::newObject()
{
Object *object = new Object();
object->prototype = objectPrototype;
return object;
2012-05-15 08:35:19 +00:00
}
FunctionObject *ExecutionEngine::newObjectCtor(Context *ctx)
{
return new ObjectCtor(ctx);
}
String *ExecutionEngine::newString(const QString &s)
{
return new String(s);
}
Object *ExecutionEngine::newStringObject(const Value &value)
{
StringObject *object = new StringObject(value);
object->prototype = stringPrototype;
return object;
2012-05-15 08:35:19 +00:00
}
FunctionObject *ExecutionEngine::newStringCtor(Context *ctx)
{
return new StringCtor(ctx);
}
Object *ExecutionEngine::newNumberObject(const Value &value)
{
NumberObject *object = new NumberObject(value);
object->prototype = numberPrototype;
return object;
2012-05-15 08:35:19 +00:00
}
FunctionObject *ExecutionEngine::newNumberCtor(Context *ctx)
{
return new NumberCtor(ctx);
}
Object *ExecutionEngine::newBooleanObject(const Value &value)
{
Object *object = new BooleanObject(value);
object->prototype = booleanPrototype;
return object;
2012-05-15 08:35:19 +00:00
}
2012-05-15 09:19:10 +00:00
FunctionObject *ExecutionEngine::newBooleanCtor(Context *ctx)
{
return new BooleanCtor(ctx);
}
Object *ExecutionEngine::newFunctionObject(Context *ctx)
{
Object *object = new FunctionObject(ctx);
object->prototype = functionPrototype;
return object;
}
FunctionObject *ExecutionEngine::newFunctionCtor(Context *ctx)
{
return new FunctionCtor(ctx);
}
2012-05-20 17:59:47 +00:00
Object *ExecutionEngine::newArrayObject()
{
ArrayObject *object = new ArrayObject();
object->prototype = arrayPrototype;
2012-05-20 17:59:47 +00:00
return object;
}
Object *ExecutionEngine::newArrayObject(const Array &value)
{
ArrayObject *object = new ArrayObject(value);
object->prototype = arrayPrototype;
2012-05-20 17:59:47 +00:00
return object;
}
FunctionObject *ExecutionEngine::newArrayCtor(Context *ctx)
{
return new ArrayCtor(ctx);
}
Object *ExecutionEngine::newDateObject(const Value &value)
{
Object *object = new DateObject(value);
object->prototype = datePrototype;
return object;
}
FunctionObject *ExecutionEngine::newDateCtor(Context *ctx)
{
return new DateCtor(ctx);
}
Object *ExecutionEngine::newRegExpObject(const QString &pattern, int flags)
2012-06-04 13:34:50 +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;
Object *object = new RegExpObject(QRegularExpression(pattern, options), global);
2012-06-04 13:34:50 +00:00
object->prototype = regExpPrototype;
return object;
}
FunctionObject *ExecutionEngine::newRegExpCtor(Context *ctx)
{
return new RegExpCtor(ctx);
}
2012-05-15 08:35:19 +00:00
Object *ExecutionEngine::newErrorObject(const Value &value)
{
2012-05-25 09:55:50 +00:00
ErrorObject *object = new ErrorObject(value);
object->prototype = objectPrototype;
2012-05-25 09:55:50 +00:00
return object;
2012-05-15 08:35:19 +00:00
}
Object *ExecutionEngine::newMathObject(Context *ctx)
{
2012-05-25 09:55:50 +00:00
MathObject *object = new MathObject(ctx);
object->prototype = objectPrototype;
2012-05-25 09:55:50 +00:00
return object;
2012-05-15 08:35:19 +00:00
}
Object *ExecutionEngine::newActivationObject(Context *ctx)
2012-05-15 08:35:19 +00:00
{
return new ActivationObject(ctx);
2012-05-15 08:35:19 +00:00
}
Object *ExecutionEngine::newForEachIteratorObject(Object *o)
{
return new ForEachIteratorObject(o);
}