2012-10-12 08:12:24 +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$
|
|
|
|
**
|
|
|
|
****************************************************************************/
|
2012-04-16 19:23:25 +00:00
|
|
|
#ifndef QMLJS_OBJECTS_H
|
|
|
|
#define QMLJS_OBJECTS_H
|
|
|
|
|
|
|
|
#include "qmljs_runtime.h"
|
2012-05-20 17:59:47 +00:00
|
|
|
#include "qv4array_p.h"
|
2012-04-16 19:23:25 +00:00
|
|
|
|
|
|
|
#include <QtCore/QString>
|
|
|
|
#include <QtCore/QHash>
|
2012-10-19 21:10:42 +00:00
|
|
|
#include <QtCore/QRegularExpression>
|
2012-06-07 12:28:42 +00:00
|
|
|
#include <cstdio>
|
2012-05-04 13:12:37 +00:00
|
|
|
#include <cassert>
|
2012-04-16 19:23:25 +00:00
|
|
|
|
2012-05-04 13:28:04 +00:00
|
|
|
namespace QQmlJS {
|
2012-05-07 14:05:05 +00:00
|
|
|
|
|
|
|
namespace IR {
|
|
|
|
struct Function;
|
|
|
|
}
|
|
|
|
|
2012-05-04 13:28:04 +00:00
|
|
|
namespace VM {
|
|
|
|
|
2012-04-16 19:23:25 +00:00
|
|
|
struct Value;
|
|
|
|
struct Object;
|
|
|
|
struct BooleanObject;
|
|
|
|
struct NumberObject;
|
|
|
|
struct StringObject;
|
|
|
|
struct ArrayObject;
|
2012-05-18 12:10:02 +00:00
|
|
|
struct DateObject;
|
2012-04-16 19:23:25 +00:00
|
|
|
struct FunctionObject;
|
2012-06-04 13:34:50 +00:00
|
|
|
struct RegExpObject;
|
2012-04-16 19:23:25 +00:00
|
|
|
struct ErrorObject;
|
2012-06-04 14:36:00 +00:00
|
|
|
struct ActivationObject;
|
2012-05-18 12:10:02 +00:00
|
|
|
struct ArgumentsObject;
|
2012-05-14 15:12:25 +00:00
|
|
|
struct Context;
|
|
|
|
struct ExecutionEngine;
|
2012-04-16 19:23:25 +00:00
|
|
|
|
2012-05-25 15:45:15 +00:00
|
|
|
struct ObjectPrototype;
|
|
|
|
struct StringPrototype;
|
|
|
|
struct NumberPrototype;
|
|
|
|
struct BooleanPrototype;
|
|
|
|
struct ArrayPrototype;
|
|
|
|
struct FunctionPrototype;
|
|
|
|
struct DatePrototype;
|
2012-06-04 13:34:50 +00:00
|
|
|
struct RegExpPrototype;
|
2012-05-25 15:45:15 +00:00
|
|
|
|
2012-05-04 13:12:37 +00:00
|
|
|
struct String {
|
2012-04-16 19:23:25 +00:00
|
|
|
String(const QString &text)
|
|
|
|
: _text(text), _hashValue(0) {}
|
|
|
|
|
2012-05-30 10:42:27 +00:00
|
|
|
inline bool isEqualTo(const String *other) const {
|
2012-06-11 07:38:52 +00:00
|
|
|
if (this == other)
|
|
|
|
return true;
|
|
|
|
else if (other && hashValue() == other->hashValue())
|
|
|
|
return toQString() == other->toQString();
|
2012-05-25 10:54:36 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-05-14 14:03:10 +00:00
|
|
|
inline const QString &toQString() const {
|
2012-04-16 19:23:25 +00:00
|
|
|
return _text;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline unsigned hashValue() const {
|
|
|
|
if (! _hashValue)
|
|
|
|
_hashValue = qHash(_text);
|
|
|
|
|
|
|
|
return _hashValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
QString _text;
|
|
|
|
mutable unsigned _hashValue;
|
|
|
|
};
|
|
|
|
|
2012-05-04 13:12:37 +00:00
|
|
|
struct Property {
|
2012-04-16 19:23:25 +00:00
|
|
|
String *name;
|
|
|
|
Value value;
|
2012-05-08 09:13:02 +00:00
|
|
|
PropertyAttributes attributes;
|
2012-04-16 19:23:25 +00:00
|
|
|
Property *next;
|
2012-05-04 13:12:37 +00:00
|
|
|
int index;
|
2012-04-16 19:23:25 +00:00
|
|
|
|
2012-06-07 12:28:42 +00:00
|
|
|
inline Property(String *name, const Value &value, PropertyAttributes flags = NoAttributes)
|
|
|
|
{ init(name, value, flags); }
|
|
|
|
|
|
|
|
inline void init(String *name, const Value &value, PropertyAttributes flags = NoAttributes)
|
|
|
|
{
|
|
|
|
this->name = name;
|
|
|
|
this->value = value;
|
|
|
|
this->attributes = flags;
|
|
|
|
this->next = 0;
|
|
|
|
this->index = -1;
|
|
|
|
}
|
2012-04-16 19:23:25 +00:00
|
|
|
|
2012-05-08 09:13:02 +00:00
|
|
|
inline bool isWritable() const { return attributes & WritableAttribute; }
|
|
|
|
inline bool isEnumerable() const { return attributes & EnumerableAttribute; }
|
|
|
|
inline bool isConfigurable() const { return attributes & ConfigurableAttribute; }
|
2012-04-16 19:23:25 +00:00
|
|
|
|
2012-05-25 10:54:36 +00:00
|
|
|
inline bool hasName(String *n) const { return name->isEqualTo(n); }
|
|
|
|
inline unsigned hashValue() const { return name->hashValue(); }
|
2012-04-16 19:23:25 +00:00
|
|
|
};
|
|
|
|
|
2012-05-04 13:12:37 +00:00
|
|
|
class Table
|
2012-04-16 19:23:25 +00:00
|
|
|
{
|
2012-05-04 13:12:37 +00:00
|
|
|
Q_DISABLE_COPY(Table)
|
2012-04-16 19:23:25 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
Table()
|
|
|
|
: _properties(0)
|
|
|
|
, _buckets(0)
|
2012-06-07 12:28:42 +00:00
|
|
|
, _freeList(0)
|
2012-04-16 19:23:25 +00:00
|
|
|
, _propertyCount(-1)
|
2012-06-04 06:32:06 +00:00
|
|
|
, _bucketCount(0)
|
2012-04-16 19:23:25 +00:00
|
|
|
, _allocated(0) {}
|
|
|
|
|
2012-05-04 13:12:37 +00:00
|
|
|
~Table()
|
|
|
|
{
|
|
|
|
qDeleteAll(_properties, _properties + _propertyCount + 1);
|
|
|
|
delete[] _properties;
|
|
|
|
delete[] _buckets;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool isEmpty() const { return _propertyCount == -1; }
|
2012-04-16 19:23:25 +00:00
|
|
|
|
|
|
|
typedef Property **iterator;
|
2012-05-04 13:12:37 +00:00
|
|
|
inline iterator begin() const { return _properties; }
|
|
|
|
inline iterator end() const { return _properties + (_propertyCount + 1); }
|
2012-04-16 19:23:25 +00:00
|
|
|
|
|
|
|
bool remove(String *name)
|
|
|
|
{
|
2012-06-07 12:28:42 +00:00
|
|
|
if (Property *prop = find(name)) {
|
|
|
|
// ### TODO check if the property can be removed
|
|
|
|
|
|
|
|
Property *bucket = _buckets[prop->hashValue() % _bucketCount];
|
|
|
|
if (bucket == prop) {
|
|
|
|
bucket = bucket->next;
|
|
|
|
} else {
|
|
|
|
for (Property *it = bucket; it; it = it->next) {
|
|
|
|
if (it->next == prop) {
|
|
|
|
it->next = it->next->next;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_properties[prop->index] = 0;
|
|
|
|
prop->next = _freeList;
|
|
|
|
_freeList = prop;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2012-04-16 19:23:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Property *find(String *name) const
|
|
|
|
{
|
2012-05-04 13:12:37 +00:00
|
|
|
if (_properties) {
|
|
|
|
for (Property *prop = _buckets[name->hashValue() % _bucketCount]; prop; prop = prop->next) {
|
2012-06-07 12:28:42 +00:00
|
|
|
if (prop && (prop->name == name || prop->hasName(name)))
|
2012-05-04 13:12:37 +00:00
|
|
|
return prop;
|
|
|
|
}
|
2012-04-16 19:23:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
Property *insert(String *name, const Value &value)
|
|
|
|
{
|
|
|
|
if (Property *prop = find(name)) {
|
|
|
|
prop->value = value;
|
|
|
|
return prop;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (++_propertyCount == _allocated) {
|
|
|
|
if (! _allocated)
|
|
|
|
_allocated = 4;
|
|
|
|
else
|
|
|
|
_allocated *= 2;
|
|
|
|
|
2012-05-04 13:12:37 +00:00
|
|
|
Property **properties = new Property*[_allocated];
|
2012-04-16 19:23:25 +00:00
|
|
|
std::copy(_properties, _properties + _propertyCount, properties);
|
2012-05-04 13:12:37 +00:00
|
|
|
delete[] _properties;
|
2012-04-16 19:23:25 +00:00
|
|
|
_properties = properties;
|
|
|
|
}
|
|
|
|
|
2012-06-07 12:28:42 +00:00
|
|
|
Property *prop;
|
|
|
|
if (_freeList) {
|
|
|
|
prop = _freeList;
|
|
|
|
_freeList = _freeList->next;
|
|
|
|
prop->init(name, value);
|
|
|
|
} else {
|
|
|
|
prop = new Property(name, value);
|
|
|
|
}
|
|
|
|
|
2012-05-04 13:12:37 +00:00
|
|
|
prop->index = _propertyCount;
|
2012-04-16 19:23:25 +00:00
|
|
|
_properties[_propertyCount] = prop;
|
|
|
|
|
|
|
|
if (! _buckets || 3 * _propertyCount >= 2 * _bucketCount) {
|
|
|
|
rehash();
|
|
|
|
} else {
|
|
|
|
Property *&bucket = _buckets[prop->hashValue() % _bucketCount];
|
|
|
|
prop->next = bucket;
|
|
|
|
bucket = prop;
|
|
|
|
}
|
|
|
|
|
|
|
|
return prop;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
void rehash()
|
|
|
|
{
|
|
|
|
if (_bucketCount)
|
|
|
|
_bucketCount *= 2; // ### next prime
|
2012-06-04 06:32:06 +00:00
|
|
|
else
|
|
|
|
_bucketCount = 11;
|
2012-04-16 19:23:25 +00:00
|
|
|
|
2012-06-04 06:32:06 +00:00
|
|
|
delete[] _buckets;
|
2012-05-04 13:12:37 +00:00
|
|
|
_buckets = new Property *[_bucketCount];
|
2012-04-16 19:23:25 +00:00
|
|
|
std::fill(_buckets, _buckets + _bucketCount, (Property *) 0);
|
|
|
|
|
|
|
|
for (int i = 0; i <= _propertyCount; ++i) {
|
|
|
|
Property *prop = _properties[i];
|
2012-05-04 13:12:37 +00:00
|
|
|
Property *&bucket = _buckets[prop->hashValue() % _bucketCount];
|
2012-04-16 19:23:25 +00:00
|
|
|
prop->next = bucket;
|
|
|
|
bucket = prop;
|
|
|
|
}
|
|
|
|
}
|
2012-05-04 13:12:37 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
Property **_properties;
|
|
|
|
Property **_buckets;
|
2012-06-07 12:28:42 +00:00
|
|
|
Property *_freeList;
|
2012-05-04 13:12:37 +00:00
|
|
|
int _propertyCount;
|
|
|
|
int _bucketCount;
|
|
|
|
int _allocated;
|
2012-04-16 19:23:25 +00:00
|
|
|
};
|
|
|
|
|
2012-05-04 13:12:37 +00:00
|
|
|
struct Object {
|
2012-04-16 19:23:25 +00:00
|
|
|
Object *prototype;
|
|
|
|
String *klass;
|
|
|
|
Table *members;
|
|
|
|
bool extensible;
|
|
|
|
|
|
|
|
Object()
|
|
|
|
: prototype(0)
|
|
|
|
, klass(0)
|
|
|
|
, members(0)
|
|
|
|
, extensible(true) {}
|
|
|
|
|
2012-05-04 13:12:37 +00:00
|
|
|
virtual ~Object();
|
2012-04-16 19:23:25 +00:00
|
|
|
|
2012-05-28 19:49:20 +00:00
|
|
|
virtual QString className() { return QStringLiteral("Object"); }
|
2012-05-18 12:10:02 +00:00
|
|
|
virtual BooleanObject *asBooleanObject() { return 0; }
|
|
|
|
virtual NumberObject *asNumberObject() { return 0; }
|
|
|
|
virtual StringObject *asStringObject() { return 0; }
|
|
|
|
virtual DateObject *asDateObject() { return 0; }
|
|
|
|
virtual ArrayObject *asArrayObject() { return 0; }
|
2012-04-16 19:23:25 +00:00
|
|
|
virtual FunctionObject *asFunctionObject() { return 0; }
|
2012-06-04 13:34:50 +00:00
|
|
|
virtual RegExpObject *asRegExpObject() { return 0; }
|
2012-05-18 12:10:02 +00:00
|
|
|
virtual ErrorObject *asErrorObject() { return 0; }
|
2012-06-04 14:36:00 +00:00
|
|
|
virtual ActivationObject *asActivationObject() { return 0; }
|
2012-05-18 12:10:02 +00:00
|
|
|
virtual ArgumentsObject *asArgumentsObject() { return 0; }
|
2012-04-16 19:23:25 +00:00
|
|
|
|
2012-05-28 18:17:13 +00:00
|
|
|
virtual Value getProperty(Context *ctx, String *name, PropertyAttributes *attributes = 0);
|
2012-05-25 10:54:36 +00:00
|
|
|
virtual Value *getOwnProperty(Context *ctx, String *name, PropertyAttributes *attributes = 0);
|
|
|
|
virtual Value *getPropertyDescriptor(Context *ctx, String *name, PropertyAttributes *attributes = 0);
|
|
|
|
virtual void setProperty(Context *ctx, String *name, const Value &value, bool flag = false);
|
|
|
|
virtual bool canSetProperty(Context *ctx, String *name);
|
|
|
|
virtual bool hasProperty(Context *ctx, String *name) const;
|
|
|
|
virtual bool deleteProperty(Context *ctx, String *name, bool flag);
|
|
|
|
virtual void defineOwnProperty(Context *ctx, const Value &getter, const Value &setter, bool flag = false);
|
2012-05-14 14:03:10 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// helpers
|
|
|
|
//
|
|
|
|
void setProperty(Context *ctx, const QString &name, const Value &value);
|
2012-05-14 15:38:53 +00:00
|
|
|
void setProperty(Context *ctx, const QString &name, void (*code)(Context *), int count = 0);
|
2012-04-16 19:23:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct BooleanObject: Object {
|
|
|
|
Value value;
|
|
|
|
BooleanObject(const Value &value): value(value) {}
|
2012-05-28 19:49:20 +00:00
|
|
|
virtual QString className() { return QStringLiteral("Boolean"); }
|
2012-05-18 12:10:02 +00:00
|
|
|
virtual BooleanObject *asBooleanObject() { return this; }
|
2012-04-16 19:23:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct NumberObject: Object {
|
|
|
|
Value value;
|
|
|
|
NumberObject(const Value &value): value(value) {}
|
2012-05-28 19:49:20 +00:00
|
|
|
virtual QString className() { return QStringLiteral("Number"); }
|
2012-05-18 12:10:02 +00:00
|
|
|
virtual NumberObject *asNumberObject() { return this; }
|
2012-04-16 19:23:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct StringObject: Object {
|
|
|
|
Value value;
|
|
|
|
StringObject(const Value &value): value(value) {}
|
2012-05-28 19:49:20 +00:00
|
|
|
virtual QString className() { return QStringLiteral("String"); }
|
2012-05-18 12:10:02 +00:00
|
|
|
virtual StringObject *asStringObject() { return this; }
|
|
|
|
};
|
|
|
|
|
|
|
|
struct DateObject: Object {
|
|
|
|
Value value;
|
|
|
|
DateObject(const Value &value): value(value) {}
|
2012-05-28 19:49:20 +00:00
|
|
|
virtual QString className() { return QStringLiteral("Date"); }
|
2012-05-18 12:10:02 +00:00
|
|
|
virtual DateObject *asDateObject() { return this; }
|
2012-04-16 19:23:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct ArrayObject: Object {
|
2012-05-20 17:59:47 +00:00
|
|
|
Array value;
|
2012-05-25 10:54:36 +00:00
|
|
|
ArrayObject() {}
|
|
|
|
ArrayObject(const Array &value): value(value) {}
|
2012-05-28 19:49:20 +00:00
|
|
|
virtual QString className() { return QStringLiteral("Array"); }
|
2012-05-18 12:10:02 +00:00
|
|
|
virtual ArrayObject *asArrayObject() { return this; }
|
2012-05-25 10:54:36 +00:00
|
|
|
virtual Value getProperty(Context *ctx, String *name, PropertyAttributes *attributes);
|
2012-04-16 19:23:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct FunctionObject: Object {
|
2012-05-13 11:50:55 +00:00
|
|
|
Context *scope;
|
2012-06-11 07:38:52 +00:00
|
|
|
String *name;
|
2012-04-16 19:23:25 +00:00
|
|
|
String **formalParameterList;
|
2012-06-05 08:47:04 +00:00
|
|
|
unsigned int formalParameterCount;
|
2012-05-16 09:58:07 +00:00
|
|
|
String **varList;
|
2012-06-05 08:47:04 +00:00
|
|
|
unsigned int varCount;
|
2012-05-14 12:34:36 +00:00
|
|
|
bool needsActivation;
|
2012-04-16 19:23:25 +00:00
|
|
|
|
2012-05-14 12:34:36 +00:00
|
|
|
FunctionObject(Context *scope)
|
|
|
|
: scope(scope)
|
2012-06-11 07:38:52 +00:00
|
|
|
, name(0)
|
2012-05-14 12:34:36 +00:00
|
|
|
, formalParameterList(0)
|
|
|
|
, formalParameterCount(0)
|
2012-05-16 09:58:07 +00:00
|
|
|
, varList(0)
|
|
|
|
, varCount(0)
|
2012-06-11 07:38:52 +00:00
|
|
|
, needsActivation(false) {}
|
2012-04-16 19:23:25 +00:00
|
|
|
|
2012-05-28 19:49:20 +00:00
|
|
|
virtual QString className() { return QStringLiteral("Function"); }
|
2012-05-18 12:10:02 +00:00
|
|
|
virtual FunctionObject *asFunctionObject() { return this; }
|
2012-05-28 18:17:13 +00:00
|
|
|
virtual bool hasInstance(Context *ctx, const Value &value);
|
2012-05-07 14:05:05 +00:00
|
|
|
virtual void call(Context *ctx);
|
|
|
|
virtual void construct(Context *ctx);
|
|
|
|
};
|
|
|
|
|
2012-05-10 10:14:20 +00:00
|
|
|
struct NativeFunction: FunctionObject {
|
|
|
|
void (*code)(Context *);
|
|
|
|
|
2012-05-13 11:50:55 +00:00
|
|
|
NativeFunction(Context *scope, void (*code)(Context *)): FunctionObject(scope), code(code) {}
|
2012-05-10 10:14:20 +00:00
|
|
|
virtual void call(Context *ctx) { code(ctx); }
|
|
|
|
virtual void construct(Context *ctx) { code(ctx); }
|
|
|
|
};
|
|
|
|
|
2012-05-07 14:05:05 +00:00
|
|
|
struct ScriptFunction: FunctionObject {
|
|
|
|
IR::Function *function;
|
|
|
|
|
2012-05-13 11:50:55 +00:00
|
|
|
ScriptFunction(Context *scope, IR::Function *function);
|
2012-05-08 09:13:02 +00:00
|
|
|
virtual ~ScriptFunction();
|
|
|
|
|
2012-05-07 14:05:05 +00:00
|
|
|
virtual void call(Context *ctx);
|
2012-05-10 10:14:20 +00:00
|
|
|
virtual void construct(Context *ctx);
|
2012-04-16 19:23:25 +00:00
|
|
|
};
|
|
|
|
|
2012-06-04 13:34:50 +00:00
|
|
|
struct RegExpObject: Object {
|
2012-10-19 21:10:42 +00:00
|
|
|
QRegularExpression value;
|
|
|
|
Value lastIndex;
|
|
|
|
bool global;
|
|
|
|
RegExpObject(const QRegularExpression &value, bool global): value(value), lastIndex(Value::fromInt32(0)), global(global) {}
|
2012-06-04 13:34:50 +00:00
|
|
|
virtual QString className() { return QStringLiteral("RegExp"); }
|
|
|
|
virtual RegExpObject *asRegExpObject() { return this; }
|
2012-10-19 21:10:42 +00:00
|
|
|
virtual Value getProperty(Context *ctx, String *name, PropertyAttributes *attributes);
|
2012-06-04 13:34:50 +00:00
|
|
|
};
|
|
|
|
|
2012-04-16 19:23:25 +00:00
|
|
|
struct ErrorObject: Object {
|
2012-05-25 15:45:15 +00:00
|
|
|
Value value;
|
|
|
|
ErrorObject(const Value &message): value(message) {}
|
2012-05-28 19:49:20 +00:00
|
|
|
virtual QString className() { return QStringLiteral("Error"); }
|
2012-05-18 12:10:02 +00:00
|
|
|
virtual ErrorObject *asErrorObject() { return this; }
|
2012-04-16 19:23:25 +00:00
|
|
|
};
|
|
|
|
|
2012-06-04 14:36:00 +00:00
|
|
|
struct ActivationObject: Object {
|
|
|
|
Context *context;
|
|
|
|
Value arguments;
|
|
|
|
ActivationObject(Context *context): context(context), arguments(Value::undefinedValue()) {}
|
|
|
|
virtual QString className() { return QStringLiteral("Activation"); }
|
|
|
|
virtual ActivationObject *asActivationObject() { return this; }
|
|
|
|
virtual Value *getPropertyDescriptor(Context *ctx, String *name, PropertyAttributes *attributes);
|
|
|
|
};
|
|
|
|
|
2012-04-16 19:23:25 +00:00
|
|
|
struct ArgumentsObject: Object {
|
2012-05-07 14:05:05 +00:00
|
|
|
Context *context;
|
|
|
|
ArgumentsObject(Context *context): context(context) {}
|
2012-05-28 19:49:20 +00:00
|
|
|
virtual QString className() { return QStringLiteral("Arguments"); }
|
2012-05-18 12:10:02 +00:00
|
|
|
virtual ArgumentsObject *asArgumentsObject() { return this; }
|
2012-06-04 14:36:00 +00:00
|
|
|
virtual Value getProperty(Context *ctx, String *name, PropertyAttributes *attributes);
|
2012-05-25 10:54:36 +00:00
|
|
|
virtual Value *getPropertyDescriptor(Context *ctx, String *name, PropertyAttributes *attributes);
|
2012-04-16 19:23:25 +00:00
|
|
|
};
|
|
|
|
|
2012-05-14 15:12:25 +00:00
|
|
|
struct ExecutionEngine
|
|
|
|
{
|
|
|
|
Context *rootContext;
|
|
|
|
Value globalObject;
|
|
|
|
|
|
|
|
Value objectCtor;
|
|
|
|
Value stringCtor;
|
|
|
|
Value numberCtor;
|
2012-05-20 17:59:47 +00:00
|
|
|
Value booleanCtor;
|
|
|
|
Value arrayCtor;
|
2012-05-21 12:57:02 +00:00
|
|
|
Value functionCtor;
|
2012-05-18 08:10:36 +00:00
|
|
|
Value dateCtor;
|
2012-06-04 13:34:50 +00:00
|
|
|
Value regExpCtor;
|
2012-05-14 15:12:25 +00:00
|
|
|
|
2012-05-25 15:45:15 +00:00
|
|
|
ObjectPrototype *objectPrototype;
|
|
|
|
StringPrototype *stringPrototype;
|
|
|
|
NumberPrototype *numberPrototype;
|
|
|
|
BooleanPrototype *booleanPrototype;
|
|
|
|
ArrayPrototype *arrayPrototype;
|
|
|
|
FunctionPrototype *functionPrototype;
|
|
|
|
DatePrototype *datePrototype;
|
2012-06-04 13:34:50 +00:00
|
|
|
RegExpPrototype *regExpPrototype;
|
2012-05-14 15:12:25 +00:00
|
|
|
|
|
|
|
QHash<QString, String *> identifiers;
|
|
|
|
|
2012-05-25 10:54:36 +00:00
|
|
|
String *id_length;
|
|
|
|
String *id_prototype;
|
2012-05-28 19:49:20 +00:00
|
|
|
String *id_constructor;
|
2012-06-04 14:36:00 +00:00
|
|
|
String *id_arguments;
|
2012-05-28 18:17:13 +00:00
|
|
|
String *id___proto__;
|
2012-05-25 10:54:36 +00:00
|
|
|
|
2012-05-14 15:12:25 +00:00
|
|
|
ExecutionEngine();
|
|
|
|
|
2012-05-15 08:35:19 +00:00
|
|
|
Context *newContext();
|
|
|
|
|
2012-05-14 15:12:25 +00:00
|
|
|
String *identifier(const QString &s);
|
2012-05-15 08:35:19 +00:00
|
|
|
|
|
|
|
FunctionObject *newNativeFunction(Context *scope, void (*code)(Context *));
|
|
|
|
FunctionObject *newScriptFunction(Context *scope, IR::Function *function);
|
|
|
|
|
|
|
|
Object *newObject();
|
|
|
|
FunctionObject *newObjectCtor(Context *ctx);
|
|
|
|
|
|
|
|
String *newString(const QString &s);
|
|
|
|
Object *newStringObject(const Value &value);
|
|
|
|
FunctionObject *newStringCtor(Context *ctx);
|
|
|
|
|
|
|
|
Object *newNumberObject(const Value &value);
|
|
|
|
FunctionObject *newNumberCtor(Context *ctx);
|
|
|
|
|
|
|
|
Object *newBooleanObject(const Value &value);
|
2012-05-15 09:19:10 +00:00
|
|
|
FunctionObject *newBooleanCtor(Context *ctx);
|
|
|
|
|
2012-05-21 12:57:02 +00:00
|
|
|
Object *newFunctionObject(Context *ctx);
|
|
|
|
FunctionObject *newFunctionCtor(Context *ctx);
|
|
|
|
|
2012-05-20 17:59:47 +00:00
|
|
|
Object *newArrayObject();
|
|
|
|
Object *newArrayObject(const Array &value);
|
|
|
|
FunctionObject *newArrayCtor(Context *ctx);
|
|
|
|
|
2012-05-18 08:10:36 +00:00
|
|
|
Object *newDateObject(const Value &value);
|
|
|
|
FunctionObject *newDateCtor(Context *ctx);
|
|
|
|
|
2012-10-19 21:10:42 +00:00
|
|
|
Object *newRegExpObject(const QString &pattern, int flags);
|
2012-06-04 13:34:50 +00:00
|
|
|
FunctionObject *newRegExpCtor(Context *ctx);
|
|
|
|
|
2012-05-15 08:35:19 +00:00
|
|
|
Object *newErrorObject(const Value &value);
|
|
|
|
Object *newMathObject(Context *ctx);
|
2012-06-04 14:36:00 +00:00
|
|
|
Object *newActivationObject(Context *ctx);
|
2012-05-14 15:12:25 +00:00
|
|
|
};
|
|
|
|
|
2012-05-04 13:28:04 +00:00
|
|
|
} // namespace VM
|
|
|
|
} // namespace QQmlJS
|
|
|
|
|
2012-04-16 19:23:25 +00:00
|
|
|
#endif // QMLJS_OBJECTS_H
|