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
|
|
|
|
|
|
|
#include "qmljs_runtime.h"
|
|
|
|
#include "qmljs_objects.h"
|
2012-05-13 11:50:55 +00:00
|
|
|
#include "qv4ir_p.h"
|
2012-06-05 08:47:04 +00:00
|
|
|
#include "qv4ecmaobjects_p.h"
|
|
|
|
|
2012-05-18 13:28:59 +00:00
|
|
|
#include <QtCore/qmath.h>
|
|
|
|
#include <QtCore/qnumeric.h>
|
2012-05-07 14:05:05 +00:00
|
|
|
#include <QtCore/QDebug>
|
2012-04-16 19:23:25 +00:00
|
|
|
#include <cstdio>
|
|
|
|
#include <cassert>
|
2012-05-18 13:28:59 +00:00
|
|
|
#include <typeinfo>
|
2012-04-16 19:23:25 +00:00
|
|
|
|
2012-05-04 18:22:04 +00:00
|
|
|
namespace QQmlJS {
|
|
|
|
namespace VM {
|
2012-05-04 13:28:04 +00:00
|
|
|
|
2012-10-24 14:35:15 +00:00
|
|
|
static inline Value callFunction(Context *context, Value thisObject, FunctionObject *func, Value *args, int argc)
|
|
|
|
{
|
|
|
|
if (func) {
|
|
|
|
Context k;
|
|
|
|
Context *ctx = func->needsActivation ? context->engine->newContext() : &k;
|
|
|
|
const Value *that = thisObject.isUndefined() ? 0 : &thisObject;
|
|
|
|
ctx->initCallContext(context, that, func, args, argc);
|
|
|
|
func->call(ctx);
|
|
|
|
ctx->leaveCallContext();
|
|
|
|
return ctx->result;
|
|
|
|
} else {
|
|
|
|
context->throwTypeError();
|
|
|
|
return Value::undefinedValue();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-18 13:28:59 +00:00
|
|
|
QString numberToString(double num, int radix = 10)
|
|
|
|
{
|
|
|
|
if (qIsNaN(num)) {
|
2012-05-25 10:54:36 +00:00
|
|
|
return QStringLiteral("NaN");
|
2012-05-18 13:28:59 +00:00
|
|
|
} else if (qIsInf(num)) {
|
|
|
|
return QLatin1String(num < 0 ? "-Infinity" : "Infinity");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (radix == 10)
|
|
|
|
return QString::number(num, 'g', 16);
|
|
|
|
|
|
|
|
QString str;
|
|
|
|
bool negative = false;
|
|
|
|
|
|
|
|
if (num < 0) {
|
|
|
|
negative = true;
|
|
|
|
num = -num;
|
|
|
|
}
|
|
|
|
|
|
|
|
double frac = num - ::floor(num);
|
|
|
|
num = Value::toInteger(num);
|
|
|
|
|
|
|
|
do {
|
|
|
|
char c = (char)::fmod(num, radix);
|
|
|
|
c = (c < 10) ? (c + '0') : (c - 10 + 'a');
|
|
|
|
str.prepend(QLatin1Char(c));
|
|
|
|
num = ::floor(num / radix);
|
|
|
|
} while (num != 0);
|
|
|
|
|
|
|
|
if (frac != 0) {
|
|
|
|
str.append(QLatin1Char('.'));
|
|
|
|
do {
|
|
|
|
frac = frac * radix;
|
|
|
|
char c = (char)::floor(frac);
|
|
|
|
c = (c < 10) ? (c + '0') : (c - 10 + 'a');
|
|
|
|
str.append(QLatin1Char(c));
|
|
|
|
frac = frac - ::floor(frac);
|
|
|
|
} while (frac != 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (negative)
|
|
|
|
str.prepend(QLatin1Char('-'));
|
|
|
|
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-05-15 08:53:20 +00:00
|
|
|
Value Value::fromString(Context *ctx, const QString &s)
|
2012-04-16 19:23:25 +00:00
|
|
|
{
|
2012-05-15 08:53:20 +00:00
|
|
|
return fromString(ctx->engine->newString(s));
|
2012-04-16 19:23:25 +00:00
|
|
|
}
|
|
|
|
|
2012-05-14 14:03:10 +00:00
|
|
|
int Value::toInt32(double number)
|
|
|
|
{
|
2012-10-17 20:40:49 +00:00
|
|
|
const double D32 = 4294967296.0;
|
|
|
|
const double D31 = D32 / 2.0;
|
|
|
|
|
|
|
|
if ((number >= -D31 && number < D31))
|
|
|
|
return static_cast<int>(number);
|
|
|
|
|
|
|
|
|
|
|
|
if (!std::isfinite(number))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
double d = ::floor(::fabs(number));
|
|
|
|
if (std::signbit(number))
|
|
|
|
d = -d;
|
|
|
|
|
|
|
|
number = ::fmod(d , D32);
|
|
|
|
|
|
|
|
if (number < -D31)
|
|
|
|
number += D32;
|
|
|
|
else if (number >= D31)
|
|
|
|
number -= D32;
|
|
|
|
|
|
|
|
return int(number);
|
2012-05-14 14:03:10 +00:00
|
|
|
}
|
|
|
|
|
2012-06-05 08:47:04 +00:00
|
|
|
unsigned int Value::toUInt32(double number)
|
2012-05-20 17:59:47 +00:00
|
|
|
{
|
2012-10-17 20:40:49 +00:00
|
|
|
const double D32 = 4294967296.0;
|
|
|
|
if ((number >= 0 && number < D32))
|
2012-10-17 20:52:46 +00:00
|
|
|
return static_cast<uint>(number);
|
2012-10-17 20:40:49 +00:00
|
|
|
|
|
|
|
if (!std::isfinite(number))
|
2012-05-20 17:59:47 +00:00
|
|
|
return +0;
|
2012-10-17 20:40:49 +00:00
|
|
|
|
|
|
|
double d = ::floor(::fabs(number));
|
|
|
|
if (std::signbit(number))
|
|
|
|
d = -d;
|
|
|
|
|
|
|
|
number = ::fmod(d , D32);
|
|
|
|
|
|
|
|
if (number < 0)
|
|
|
|
number += D32;
|
|
|
|
|
|
|
|
return unsigned(number);
|
2012-05-20 17:59:47 +00:00
|
|
|
}
|
|
|
|
|
2012-10-17 20:40:49 +00:00
|
|
|
double Value::toInteger(double number)
|
2012-05-14 14:03:10 +00:00
|
|
|
{
|
2012-10-17 11:24:46 +00:00
|
|
|
if (std::isnan(number))
|
2012-05-14 14:03:10 +00:00
|
|
|
return +0;
|
2012-10-17 11:24:46 +00:00
|
|
|
else if (! number || std::isinf(number))
|
2012-05-14 14:03:10 +00:00
|
|
|
return number;
|
|
|
|
const double v = floor(fabs(number));
|
2012-10-17 11:24:46 +00:00
|
|
|
return std::signbit(number) ? -v : v;
|
2012-05-14 14:03:10 +00:00
|
|
|
}
|
|
|
|
|
2012-05-18 13:28:59 +00:00
|
|
|
Object *Value::asObject() const
|
|
|
|
{
|
2012-09-19 19:08:47 +00:00
|
|
|
return isObject() ? objectValue() : 0;
|
2012-05-18 13:28:59 +00:00
|
|
|
}
|
|
|
|
|
2012-05-18 12:10:02 +00:00
|
|
|
FunctionObject *Value::asFunctionObject() const
|
|
|
|
{
|
2012-09-19 19:08:47 +00:00
|
|
|
return isObject() ? objectValue()->asFunctionObject() : 0;
|
2012-05-18 12:10:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BooleanObject *Value::asBooleanObject() const
|
|
|
|
{
|
2012-09-19 19:08:47 +00:00
|
|
|
return isObject() ? objectValue()->asBooleanObject() : 0;
|
2012-05-18 12:10:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NumberObject *Value::asNumberObject() const
|
|
|
|
{
|
2012-09-19 19:08:47 +00:00
|
|
|
return isObject() ? objectValue()->asNumberObject() : 0;
|
2012-05-18 12:10:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
StringObject *Value::asStringObject() const
|
|
|
|
{
|
2012-09-19 19:08:47 +00:00
|
|
|
return isObject() ? objectValue()->asStringObject() : 0;
|
2012-05-18 12:10:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DateObject *Value::asDateObject() const
|
|
|
|
{
|
2012-09-19 19:08:47 +00:00
|
|
|
return isObject() ? objectValue()->asDateObject() : 0;
|
2012-05-18 12:10:02 +00:00
|
|
|
}
|
|
|
|
|
2012-10-19 21:10:42 +00:00
|
|
|
RegExpObject *Value::asRegExpObject() const
|
|
|
|
{
|
|
|
|
return isObject() ? objectValue()->asRegExpObject() : 0;
|
|
|
|
}
|
|
|
|
|
2012-05-18 12:10:02 +00:00
|
|
|
ArrayObject *Value::asArrayObject() const
|
|
|
|
{
|
2012-09-19 19:08:47 +00:00
|
|
|
return isObject() ? objectValue()->asArrayObject() : 0;
|
2012-05-18 12:10:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ErrorObject *Value::asErrorObject() const
|
|
|
|
{
|
2012-09-19 19:08:47 +00:00
|
|
|
return isObject() ? objectValue()->asErrorObject() : 0;
|
2012-05-18 12:10:02 +00:00
|
|
|
}
|
|
|
|
|
2012-06-04 14:36:00 +00:00
|
|
|
ActivationObject *Value::asArgumentsObject() const
|
2012-05-18 12:10:02 +00:00
|
|
|
{
|
2012-09-19 19:08:47 +00:00
|
|
|
return isObject() ? objectValue()->asActivationObject() : 0;
|
2012-05-18 12:10:02 +00:00
|
|
|
}
|
2012-05-14 14:03:10 +00:00
|
|
|
|
2012-05-25 10:54:36 +00:00
|
|
|
Value Value::property(Context *ctx, String *name) const
|
|
|
|
{
|
2012-09-19 19:08:47 +00:00
|
|
|
return isObject() ? objectValue()->getProperty(ctx, name) : undefinedValue();
|
2012-05-25 10:54:36 +00:00
|
|
|
}
|
|
|
|
|
2012-06-05 08:47:04 +00:00
|
|
|
void Context::init(ExecutionEngine *eng)
|
|
|
|
{
|
|
|
|
engine = eng;
|
|
|
|
parent = 0;
|
|
|
|
arguments = 0;
|
|
|
|
argumentCount = 0;
|
|
|
|
locals = 0;
|
2012-09-19 19:08:47 +00:00
|
|
|
activation = Value::nullValue();
|
|
|
|
thisObject = Value::nullValue();
|
|
|
|
result = Value::undefinedValue();
|
2012-06-05 08:47:04 +00:00
|
|
|
formals = 0;
|
|
|
|
formalCount = 0;
|
|
|
|
vars = 0;
|
|
|
|
varCount = 0;
|
|
|
|
calledAsConstructor = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
Value *Context::lookupPropertyDescriptor(String *name)
|
|
|
|
{
|
|
|
|
for (Context *ctx = this; ctx; ctx = ctx->parent) {
|
2012-10-18 12:52:22 +00:00
|
|
|
if (ctx->activation.isObject()) {
|
2012-10-28 20:56:15 +00:00
|
|
|
PropertyDescriptor tmp;
|
|
|
|
if (PropertyDescriptor *pd = ctx->activation.objectValue()->getPropertyDescriptor(this, name, &tmp)) {
|
|
|
|
return &pd->value;
|
2012-06-05 08:47:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-10-17 11:43:33 +00:00
|
|
|
void Context::throwError(Value value)
|
2012-06-05 08:47:04 +00:00
|
|
|
{
|
|
|
|
result = value;
|
2012-10-21 22:18:31 +00:00
|
|
|
__qmljs_builtin_throw(value, this);
|
2012-06-05 08:47:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Context::throwError(const QString &message)
|
|
|
|
{
|
|
|
|
Value v = Value::fromString(this, message);
|
|
|
|
throwError(Value::fromObject(engine->newErrorObject(v)));
|
|
|
|
}
|
|
|
|
|
|
|
|
void Context::throwTypeError()
|
|
|
|
{
|
|
|
|
Value v = Value::fromString(this, QStringLiteral("Type error"));
|
|
|
|
throwError(Value::fromObject(engine->newErrorObject(v)));
|
|
|
|
}
|
|
|
|
|
|
|
|
void Context::throwUnimplemented(const QString &message)
|
|
|
|
{
|
|
|
|
Value v = Value::fromString(this, QStringLiteral("Unimplemented ") + message);
|
|
|
|
throwError(Value::fromObject(engine->newErrorObject(v)));
|
|
|
|
}
|
|
|
|
|
2012-10-17 11:43:33 +00:00
|
|
|
void Context::throwReferenceError(Value value)
|
2012-06-05 08:47:04 +00:00
|
|
|
{
|
|
|
|
String *s = value.toString(this);
|
|
|
|
QString msg = s->toQString() + QStringLiteral(" is not defined");
|
|
|
|
throwError(Value::fromObject(engine->newErrorObject(Value::fromString(this, msg))));
|
|
|
|
}
|
|
|
|
|
2012-10-21 22:18:31 +00:00
|
|
|
void Context::initCallContext(Context *parent, const Value *object, FunctionObject *f, Value *args, unsigned argc)
|
2012-06-05 08:47:04 +00:00
|
|
|
{
|
2012-10-21 22:18:31 +00:00
|
|
|
engine = parent->engine;
|
|
|
|
this->parent = f->scope;
|
|
|
|
assert(this->parent == f->scope);
|
2012-10-11 14:39:17 +00:00
|
|
|
result = Value::undefinedValue();
|
2012-06-05 08:47:04 +00:00
|
|
|
|
|
|
|
if (f->needsActivation)
|
2012-10-18 06:52:40 +00:00
|
|
|
activation = Value::fromObject(engine->newActivationObject(this));
|
2012-06-05 08:47:04 +00:00
|
|
|
else
|
2012-10-11 14:39:17 +00:00
|
|
|
activation = Value::nullValue();
|
2012-06-05 08:47:04 +00:00
|
|
|
|
|
|
|
if (object)
|
|
|
|
thisObject = *object;
|
|
|
|
else
|
2012-10-11 14:39:17 +00:00
|
|
|
thisObject = Value::nullValue();
|
2012-06-05 08:47:04 +00:00
|
|
|
|
|
|
|
formals = f->formalParameterList;
|
|
|
|
formalCount = f->formalParameterCount;
|
|
|
|
arguments = args;
|
|
|
|
argumentCount = argc;
|
2012-06-11 07:38:52 +00:00
|
|
|
if (f->needsActivation || argc < formalCount){
|
|
|
|
arguments = new Value[qMax(argc, formalCount)];
|
|
|
|
if (argc)
|
|
|
|
std::copy(args, args + argc, arguments);
|
|
|
|
if (argc < formalCount)
|
|
|
|
std::fill(arguments + argc, arguments + formalCount, Value::undefinedValue());
|
2012-06-05 08:47:04 +00:00
|
|
|
}
|
|
|
|
vars = f->varList;
|
|
|
|
varCount = f->varCount;
|
|
|
|
locals = varCount ? new Value[varCount] : 0;
|
|
|
|
calledAsConstructor = false;
|
|
|
|
if (varCount)
|
|
|
|
std::fill(locals, locals + varCount, Value::undefinedValue());
|
|
|
|
}
|
|
|
|
|
2012-10-21 22:18:31 +00:00
|
|
|
void Context::leaveCallContext()
|
2012-06-05 08:47:04 +00:00
|
|
|
{
|
2012-10-21 22:18:31 +00:00
|
|
|
if (!activation.isNull()) {
|
2012-06-05 08:47:04 +00:00
|
|
|
delete[] locals;
|
|
|
|
locals = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-21 22:18:31 +00:00
|
|
|
void Context::initConstructorContext(Context *parent, Value *object, FunctionObject *f, Value *args, unsigned argc)
|
2012-06-05 08:47:04 +00:00
|
|
|
{
|
2012-10-21 22:18:31 +00:00
|
|
|
initCallContext(parent, object, f, args, argc);
|
2012-06-05 08:47:04 +00:00
|
|
|
calledAsConstructor = true;
|
|
|
|
}
|
|
|
|
|
2012-10-16 13:37:31 +00:00
|
|
|
void Context::leaveConstructorContext(FunctionObject *f)
|
2012-06-05 08:47:04 +00:00
|
|
|
{
|
2012-10-18 19:48:57 +00:00
|
|
|
assert(thisObject.isObject());
|
2012-06-05 08:47:04 +00:00
|
|
|
result = thisObject;
|
|
|
|
|
|
|
|
Value proto = f->getProperty(this, engine->id_prototype);
|
2012-09-19 19:08:47 +00:00
|
|
|
thisObject.objectValue()->prototype = proto.objectValue();
|
2012-06-05 08:47:04 +00:00
|
|
|
if (! thisObject.isObject())
|
2012-09-19 19:08:47 +00:00
|
|
|
thisObject.objectValue()->prototype = engine->objectPrototype;
|
2012-06-05 08:47:04 +00:00
|
|
|
|
2012-10-21 22:18:31 +00:00
|
|
|
leaveCallContext();
|
2012-06-05 08:47:04 +00:00
|
|
|
}
|
|
|
|
|
2012-04-16 19:23:25 +00:00
|
|
|
extern "C" {
|
|
|
|
|
2012-10-16 11:40:02 +00:00
|
|
|
Value __qmljs_init_closure(IR::Function *clos, Context *ctx)
|
2012-05-09 11:51:44 +00:00
|
|
|
{
|
2012-10-18 06:52:40 +00:00
|
|
|
return Value::fromObject(ctx->engine->newScriptFunction(ctx, clos));
|
2012-05-09 11:51:44 +00:00
|
|
|
}
|
|
|
|
|
2012-10-16 11:40:02 +00:00
|
|
|
Value __qmljs_init_native_function(void (*code)(Context *), Context *ctx)
|
2012-06-06 12:59:42 +00:00
|
|
|
{
|
2012-10-18 06:52:40 +00:00
|
|
|
return Value::fromObject(ctx->engine->newNativeFunction(ctx, code));
|
2012-06-06 12:59:42 +00:00
|
|
|
}
|
|
|
|
|
2012-10-16 11:13:44 +00:00
|
|
|
Value __qmljs_string_literal_undefined(Context *ctx)
|
2012-04-16 19:23:25 +00:00
|
|
|
{
|
2012-10-16 11:13:44 +00:00
|
|
|
return Value::fromString(ctx->engine->identifier(QStringLiteral("undefined")));
|
2012-04-16 19:23:25 +00:00
|
|
|
}
|
|
|
|
|
2012-10-16 11:13:44 +00:00
|
|
|
Value __qmljs_string_literal_null(Context *ctx)
|
2012-04-16 19:23:25 +00:00
|
|
|
{
|
2012-10-16 11:13:44 +00:00
|
|
|
return Value::fromString(ctx->engine->identifier(QStringLiteral("null")));
|
2012-04-16 19:23:25 +00:00
|
|
|
}
|
|
|
|
|
2012-10-16 11:13:44 +00:00
|
|
|
Value __qmljs_string_literal_true(Context *ctx)
|
2012-04-16 19:23:25 +00:00
|
|
|
{
|
2012-10-16 11:13:44 +00:00
|
|
|
return Value::fromString(ctx->engine->identifier(QStringLiteral("true")));
|
2012-04-16 19:23:25 +00:00
|
|
|
}
|
|
|
|
|
2012-10-16 11:13:44 +00:00
|
|
|
Value __qmljs_string_literal_false(Context *ctx)
|
2012-04-16 19:23:25 +00:00
|
|
|
{
|
2012-10-16 11:13:44 +00:00
|
|
|
return Value::fromString(ctx->engine->identifier(QStringLiteral("false")));
|
2012-04-16 19:23:25 +00:00
|
|
|
}
|
|
|
|
|
2012-10-16 11:13:44 +00:00
|
|
|
Value __qmljs_string_literal_object(Context *ctx)
|
2012-04-16 19:23:25 +00:00
|
|
|
{
|
2012-10-16 11:13:44 +00:00
|
|
|
return Value::fromString(ctx->engine->identifier(QStringLiteral("object")));
|
2012-04-16 19:23:25 +00:00
|
|
|
}
|
|
|
|
|
2012-10-16 11:13:44 +00:00
|
|
|
Value __qmljs_string_literal_boolean(Context *ctx)
|
2012-04-16 19:23:25 +00:00
|
|
|
{
|
2012-10-16 11:13:44 +00:00
|
|
|
return Value::fromString(ctx->engine->identifier(QStringLiteral("boolean")));
|
2012-04-16 19:23:25 +00:00
|
|
|
}
|
|
|
|
|
2012-10-16 11:13:44 +00:00
|
|
|
Value __qmljs_string_literal_number(Context *ctx)
|
2012-04-16 19:23:25 +00:00
|
|
|
{
|
2012-10-16 11:13:44 +00:00
|
|
|
return Value::fromString(ctx->engine->identifier(QStringLiteral("number")));
|
2012-04-16 19:23:25 +00:00
|
|
|
}
|
|
|
|
|
2012-10-16 11:13:44 +00:00
|
|
|
Value __qmljs_string_literal_string(Context *ctx)
|
2012-04-16 19:23:25 +00:00
|
|
|
{
|
2012-10-16 11:13:44 +00:00
|
|
|
return Value::fromString(ctx->engine->identifier(QStringLiteral("string")));
|
2012-04-16 19:23:25 +00:00
|
|
|
}
|
|
|
|
|
2012-10-16 11:13:44 +00:00
|
|
|
Value __qmljs_string_literal_function(Context *ctx)
|
2012-04-16 19:23:25 +00:00
|
|
|
{
|
2012-10-16 11:13:44 +00:00
|
|
|
return Value::fromString(ctx->engine->identifier(QStringLiteral("function")));
|
2012-04-16 19:23:25 +00:00
|
|
|
}
|
|
|
|
|
2012-10-16 19:08:52 +00:00
|
|
|
Value __qmljs_delete_subscript(Context *ctx, Value base, Value index)
|
2012-06-07 12:28:42 +00:00
|
|
|
{
|
2012-10-16 19:08:52 +00:00
|
|
|
if (ArrayObject *a = base.asArrayObject()) {
|
2012-10-11 14:39:17 +00:00
|
|
|
int n = -1;
|
2012-10-16 19:08:52 +00:00
|
|
|
if (index.isInteger())
|
|
|
|
n = index.integerValue();
|
|
|
|
else if (index.isDouble())
|
|
|
|
n = index.doubleValue();
|
2012-10-11 14:39:17 +00:00
|
|
|
if (n >= 0) {
|
2012-10-18 08:57:00 +00:00
|
|
|
if (n < (int) a->value.size()) {
|
2012-06-07 12:28:42 +00:00
|
|
|
a->value.assign(n, Value::undefinedValue());
|
2012-10-16 19:08:52 +00:00
|
|
|
return Value::fromBoolean(true);
|
2012-06-07 12:28:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-16 19:08:52 +00:00
|
|
|
String *name = index.toString(ctx);
|
|
|
|
return __qmljs_delete_member(ctx, base, name);
|
2012-06-07 12:28:42 +00:00
|
|
|
}
|
|
|
|
|
2012-10-16 19:08:52 +00:00
|
|
|
Value __qmljs_delete_member(Context *ctx, Value base, String *name)
|
2012-06-07 12:28:42 +00:00
|
|
|
{
|
2012-10-16 19:08:52 +00:00
|
|
|
Value obj = base.toObject(ctx);
|
|
|
|
return Value::fromBoolean(obj.objectValue()->deleteProperty(ctx, name, true));
|
2012-06-07 12:28:42 +00:00
|
|
|
}
|
|
|
|
|
2012-10-16 19:08:52 +00:00
|
|
|
Value __qmljs_delete_property(Context *ctx, String *name)
|
2012-06-07 12:28:42 +00:00
|
|
|
{
|
|
|
|
Value obj = ctx->activation;
|
|
|
|
if (! obj.isObject())
|
|
|
|
obj = ctx->engine->globalObject;
|
2012-10-16 19:08:52 +00:00
|
|
|
return Value::fromBoolean(obj.objectValue()->deleteProperty(ctx, name, true));
|
2012-06-07 12:28:42 +00:00
|
|
|
}
|
|
|
|
|
2012-10-16 19:08:52 +00:00
|
|
|
Value __qmljs_delete_value(Context *ctx, Value value)
|
2012-04-16 19:23:25 +00:00
|
|
|
{
|
2012-06-07 12:28:42 +00:00
|
|
|
Q_UNUSED(value);
|
2012-10-16 19:08:52 +00:00
|
|
|
return __qmljs_throw_type_error(ctx); // ### throw syntax error
|
2012-04-16 19:23:25 +00:00
|
|
|
}
|
|
|
|
|
2012-10-17 11:43:33 +00:00
|
|
|
Value __qmljs_add_helper(Value left, Value right, Context *ctx)
|
2012-06-06 08:58:49 +00:00
|
|
|
{
|
2012-10-17 11:38:50 +00:00
|
|
|
Value pleft = __qmljs_to_primitive(left, ctx, PREFERREDTYPE_HINT);
|
|
|
|
Value pright = __qmljs_to_primitive(right, ctx, PREFERREDTYPE_HINT);
|
2012-09-19 19:08:47 +00:00
|
|
|
if (pleft.isString() || pright.isString()) {
|
|
|
|
if (!pleft.isString())
|
2012-10-17 11:38:50 +00:00
|
|
|
pleft = __qmljs_to_string(pleft, ctx);
|
2012-09-19 19:08:47 +00:00
|
|
|
if (!pright.isString())
|
2012-10-17 11:38:50 +00:00
|
|
|
pright = __qmljs_to_string(pright, ctx);
|
2012-09-19 19:08:47 +00:00
|
|
|
String *string = __qmljs_string_concat(ctx, pleft.stringValue(), pright.stringValue());
|
2012-10-16 20:00:49 +00:00
|
|
|
return Value::fromString(string);
|
2012-06-06 08:58:49 +00:00
|
|
|
}
|
2012-10-16 20:00:49 +00:00
|
|
|
double x = __qmljs_to_number(pleft, ctx);
|
|
|
|
double y = __qmljs_to_number(pright, ctx);
|
|
|
|
return Value::fromDouble(x + y);
|
2012-06-06 08:58:49 +00:00
|
|
|
}
|
|
|
|
|
2012-10-17 11:43:33 +00:00
|
|
|
Value __qmljs_instanceof(Value left, Value right, Context *ctx)
|
2012-04-16 19:23:25 +00:00
|
|
|
{
|
2012-10-16 20:00:49 +00:00
|
|
|
if (FunctionObject *function = right.asFunctionObject()) {
|
|
|
|
bool r = function->hasInstance(ctx, left);
|
|
|
|
return Value::fromBoolean(r);
|
2012-04-16 19:23:25 +00:00
|
|
|
}
|
|
|
|
|
2012-10-16 20:00:49 +00:00
|
|
|
return __qmljs_throw_type_error(ctx);
|
2012-04-16 19:23:25 +00:00
|
|
|
}
|
|
|
|
|
2012-10-17 11:43:33 +00:00
|
|
|
Value __qmljs_in(Value left, Value right, Context *ctx)
|
2012-04-16 19:23:25 +00:00
|
|
|
{
|
2012-10-16 20:00:49 +00:00
|
|
|
if (right.isObject()) {
|
2012-10-17 11:38:50 +00:00
|
|
|
Value s = __qmljs_to_string(left, ctx);
|
2012-10-16 20:00:49 +00:00
|
|
|
bool r = right.objectValue()->hasProperty(ctx, s.stringValue());
|
|
|
|
return Value::fromBoolean(r);
|
2012-04-16 19:23:25 +00:00
|
|
|
} else {
|
2012-10-16 20:00:49 +00:00
|
|
|
return __qmljs_throw_type_error(ctx);
|
2012-04-16 19:23:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-17 11:43:33 +00:00
|
|
|
void __qmljs_inplace_bit_and_name(Value value, String *name, Context *ctx)
|
2012-06-07 14:21:21 +00:00
|
|
|
{
|
2012-10-17 11:38:50 +00:00
|
|
|
if (Value *prop = ctx->lookupPropertyDescriptor(name))
|
|
|
|
*prop = __qmljs_bit_and(*prop, value, ctx);
|
|
|
|
else
|
|
|
|
ctx->throwReferenceError(Value::fromString(name));
|
2012-06-07 14:21:21 +00:00
|
|
|
}
|
|
|
|
|
2012-10-17 11:43:33 +00:00
|
|
|
void __qmljs_inplace_bit_or_name(Value value, String *name, Context *ctx)
|
2012-06-07 14:21:21 +00:00
|
|
|
{
|
2012-10-17 11:38:50 +00:00
|
|
|
if (Value *prop = ctx->lookupPropertyDescriptor(name))
|
|
|
|
*prop = __qmljs_bit_or(*prop, value, ctx);
|
|
|
|
else
|
|
|
|
ctx->throwReferenceError(Value::fromString(name));
|
2012-06-07 14:21:21 +00:00
|
|
|
}
|
|
|
|
|
2012-10-17 11:43:33 +00:00
|
|
|
void __qmljs_inplace_bit_xor_name(Value value, String *name, Context *ctx)
|
2012-06-07 14:21:21 +00:00
|
|
|
{
|
2012-10-17 11:38:50 +00:00
|
|
|
if (Value *prop = ctx->lookupPropertyDescriptor(name))
|
|
|
|
*prop = __qmljs_bit_xor(*prop, value, ctx);
|
|
|
|
else
|
|
|
|
ctx->throwReferenceError(Value::fromString(name));
|
2012-06-07 14:21:21 +00:00
|
|
|
}
|
|
|
|
|
2012-10-17 11:43:33 +00:00
|
|
|
void __qmljs_inplace_add_name(Value value, String *name, Context *ctx)
|
2012-06-11 07:38:52 +00:00
|
|
|
{
|
|
|
|
if (Value *prop = ctx->lookupPropertyDescriptor(name))
|
2012-10-17 11:38:50 +00:00
|
|
|
*prop = __qmljs_add(*prop, value, ctx);
|
2012-06-11 07:38:52 +00:00
|
|
|
else
|
|
|
|
ctx->throwReferenceError(Value::fromString(name));
|
|
|
|
}
|
|
|
|
|
2012-10-17 11:43:33 +00:00
|
|
|
void __qmljs_inplace_sub_name(Value value, String *name, Context *ctx)
|
2012-06-11 07:38:52 +00:00
|
|
|
{
|
2012-10-17 11:38:50 +00:00
|
|
|
if (Value *prop = ctx->lookupPropertyDescriptor(name))
|
|
|
|
*prop = __qmljs_sub(*prop, value, ctx);
|
|
|
|
else
|
|
|
|
ctx->throwReferenceError(Value::fromString(name));
|
2012-06-11 07:38:52 +00:00
|
|
|
}
|
|
|
|
|
2012-10-17 11:43:33 +00:00
|
|
|
void __qmljs_inplace_mul_name(Value value, String *name, Context *ctx)
|
2012-06-11 07:38:52 +00:00
|
|
|
{
|
2012-10-17 11:38:50 +00:00
|
|
|
if (Value *prop = ctx->lookupPropertyDescriptor(name))
|
|
|
|
*prop = __qmljs_mul(*prop, value, ctx);
|
|
|
|
else
|
|
|
|
ctx->throwReferenceError(Value::fromString(name));
|
2012-06-11 07:38:52 +00:00
|
|
|
}
|
|
|
|
|
2012-10-17 11:43:33 +00:00
|
|
|
void __qmljs_inplace_div_name(Value value, String *name, Context *ctx)
|
2012-06-11 07:38:52 +00:00
|
|
|
{
|
2012-10-17 11:38:50 +00:00
|
|
|
if (Value *prop = ctx->lookupPropertyDescriptor(name))
|
|
|
|
*prop = __qmljs_div(*prop, value, ctx);
|
|
|
|
else
|
|
|
|
ctx->throwReferenceError(Value::fromString(name));
|
2012-06-11 07:38:52 +00:00
|
|
|
}
|
|
|
|
|
2012-10-17 11:43:33 +00:00
|
|
|
void __qmljs_inplace_mod_name(Value value, String *name, Context *ctx)
|
2012-06-11 07:38:52 +00:00
|
|
|
{
|
2012-10-17 11:38:50 +00:00
|
|
|
if (Value *prop = ctx->lookupPropertyDescriptor(name))
|
|
|
|
*prop = __qmljs_mod(*prop, value, ctx);
|
|
|
|
else
|
|
|
|
ctx->throwReferenceError(Value::fromString(name));
|
2012-06-11 07:38:52 +00:00
|
|
|
}
|
|
|
|
|
2012-10-17 11:43:33 +00:00
|
|
|
void __qmljs_inplace_shl_name(Value value, String *name, Context *ctx)
|
2012-06-11 07:38:52 +00:00
|
|
|
{
|
2012-10-17 11:38:50 +00:00
|
|
|
if (Value *prop = ctx->lookupPropertyDescriptor(name))
|
|
|
|
*prop = __qmljs_shl(*prop, value, ctx);
|
|
|
|
else
|
|
|
|
ctx->throwReferenceError(Value::fromString(name));
|
2012-06-11 07:38:52 +00:00
|
|
|
}
|
|
|
|
|
2012-10-17 11:43:33 +00:00
|
|
|
void __qmljs_inplace_shr_name(Value value, String *name, Context *ctx)
|
2012-06-11 07:38:52 +00:00
|
|
|
{
|
2012-10-17 11:38:50 +00:00
|
|
|
if (Value *prop = ctx->lookupPropertyDescriptor(name))
|
|
|
|
*prop = __qmljs_shr(*prop, value, ctx);
|
|
|
|
else
|
|
|
|
ctx->throwReferenceError(Value::fromString(name));
|
2012-06-11 07:38:52 +00:00
|
|
|
}
|
|
|
|
|
2012-10-17 11:43:33 +00:00
|
|
|
void __qmljs_inplace_ushr_name(Value value, String *name, Context *ctx)
|
2012-06-07 14:21:21 +00:00
|
|
|
{
|
2012-10-17 11:38:50 +00:00
|
|
|
if (Value *prop = ctx->lookupPropertyDescriptor(name))
|
|
|
|
*prop = __qmljs_ushr(*prop, value, ctx);
|
|
|
|
else
|
|
|
|
ctx->throwReferenceError(Value::fromString(name));
|
2012-06-07 14:21:21 +00:00
|
|
|
}
|
|
|
|
|
2012-10-17 11:38:59 +00:00
|
|
|
void __qmljs_inplace_bit_and_element(Value base, Value index, Value value, Context *ctx)
|
2012-06-07 14:21:21 +00:00
|
|
|
{
|
2012-10-17 12:19:05 +00:00
|
|
|
Object *obj = base.toObject(ctx).objectValue();
|
|
|
|
if (ArrayObject *a = obj->asArrayObject()) {
|
|
|
|
if (index.isNumber()) {
|
|
|
|
const quint32 idx = index.toUInt32(ctx);
|
|
|
|
Value v = a->value.at(idx);
|
|
|
|
v = __qmljs_bit_and(v, value, ctx);
|
|
|
|
a->value.assign(idx, v);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2012-06-07 14:21:21 +00:00
|
|
|
ctx->throwUnimplemented(QLatin1String(Q_FUNC_INFO));
|
|
|
|
}
|
|
|
|
|
2012-10-17 11:38:59 +00:00
|
|
|
void __qmljs_inplace_bit_or_element(Value base, Value index, Value value, Context *ctx)
|
2012-06-07 14:21:21 +00:00
|
|
|
{
|
2012-10-17 11:38:59 +00:00
|
|
|
Object *obj = base.toObject(ctx).objectValue();
|
2012-06-11 07:38:52 +00:00
|
|
|
if (ArrayObject *a = obj->asArrayObject()) {
|
2012-10-17 11:38:59 +00:00
|
|
|
if (index.isNumber()) {
|
|
|
|
const quint32 idx = index.toUInt32(ctx);
|
2012-06-11 07:38:52 +00:00
|
|
|
Value v = a->value.at(idx);
|
2012-10-17 11:38:59 +00:00
|
|
|
v = __qmljs_bit_or(v, value, ctx);
|
2012-06-11 07:38:52 +00:00
|
|
|
a->value.assign(idx, v);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2012-06-07 14:21:21 +00:00
|
|
|
ctx->throwUnimplemented(QLatin1String(Q_FUNC_INFO));
|
|
|
|
}
|
|
|
|
|
2012-10-17 11:38:59 +00:00
|
|
|
void __qmljs_inplace_bit_xor_element(Value base, Value index, Value value, Context *ctx)
|
2012-06-07 14:21:21 +00:00
|
|
|
{
|
2012-10-17 11:38:59 +00:00
|
|
|
Object *obj = base.toObject(ctx).objectValue();
|
2012-06-11 07:38:52 +00:00
|
|
|
if (ArrayObject *a = obj->asArrayObject()) {
|
2012-10-17 11:38:59 +00:00
|
|
|
if (index.isNumber()) {
|
|
|
|
const quint32 idx = index.toUInt32(ctx);
|
2012-06-11 07:38:52 +00:00
|
|
|
Value v = a->value.at(idx);
|
2012-10-17 11:38:59 +00:00
|
|
|
v = __qmljs_bit_xor(v, value, ctx);
|
2012-06-11 07:38:52 +00:00
|
|
|
a->value.assign(idx, v);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2012-06-07 14:21:21 +00:00
|
|
|
ctx->throwUnimplemented(QLatin1String(Q_FUNC_INFO));
|
|
|
|
}
|
|
|
|
|
2012-10-17 11:38:59 +00:00
|
|
|
void __qmljs_inplace_add_element(Value base, Value index, Value value, Context *ctx)
|
2012-06-07 14:21:21 +00:00
|
|
|
{
|
2012-10-17 11:38:59 +00:00
|
|
|
Object *obj = base.toObject(ctx).objectValue();
|
2012-06-11 07:38:52 +00:00
|
|
|
if (ArrayObject *a = obj->asArrayObject()) {
|
2012-10-17 11:38:59 +00:00
|
|
|
if (index.isNumber()) {
|
|
|
|
const quint32 idx = index.toUInt32(ctx);
|
2012-06-11 07:38:52 +00:00
|
|
|
Value v = a->value.at(idx);
|
2012-10-17 11:38:59 +00:00
|
|
|
v = __qmljs_add(v, value, ctx);
|
2012-06-11 07:38:52 +00:00
|
|
|
a->value.assign(idx, v);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2012-06-07 14:21:21 +00:00
|
|
|
ctx->throwUnimplemented(QLatin1String(Q_FUNC_INFO));
|
|
|
|
}
|
|
|
|
|
2012-10-17 11:38:59 +00:00
|
|
|
void __qmljs_inplace_sub_element(Value base, Value index, Value value, Context *ctx)
|
2012-06-07 14:21:21 +00:00
|
|
|
{
|
2012-10-17 11:38:59 +00:00
|
|
|
Object *obj = base.toObject(ctx).objectValue();
|
2012-06-11 07:38:52 +00:00
|
|
|
if (ArrayObject *a = obj->asArrayObject()) {
|
2012-10-17 11:38:59 +00:00
|
|
|
if (index.isNumber()) {
|
|
|
|
const quint32 idx = index.toUInt32(ctx);
|
2012-06-11 07:38:52 +00:00
|
|
|
Value v = a->value.at(idx);
|
2012-10-17 11:38:59 +00:00
|
|
|
v = __qmljs_sub(v, value, ctx);
|
2012-06-11 07:38:52 +00:00
|
|
|
a->value.assign(idx, v);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2012-06-07 14:21:21 +00:00
|
|
|
ctx->throwUnimplemented(QLatin1String(Q_FUNC_INFO));
|
|
|
|
}
|
|
|
|
|
2012-10-17 11:38:59 +00:00
|
|
|
void __qmljs_inplace_mul_element(Value base, Value index, Value value, Context *ctx)
|
2012-06-07 14:21:21 +00:00
|
|
|
{
|
2012-10-17 12:19:05 +00:00
|
|
|
Object *obj = base.toObject(ctx).objectValue();
|
|
|
|
if (ArrayObject *a = obj->asArrayObject()) {
|
|
|
|
if (index.isNumber()) {
|
|
|
|
const quint32 idx = index.toUInt32(ctx);
|
|
|
|
Value v = a->value.at(idx);
|
|
|
|
v = __qmljs_mul(v, value, ctx);
|
|
|
|
a->value.assign(idx, v);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2012-06-07 14:21:21 +00:00
|
|
|
ctx->throwUnimplemented(QLatin1String(Q_FUNC_INFO));
|
|
|
|
}
|
|
|
|
|
2012-10-17 11:38:59 +00:00
|
|
|
void __qmljs_inplace_div_element(Value base, Value index, Value value, Context *ctx)
|
2012-06-07 14:21:21 +00:00
|
|
|
{
|
2012-10-17 12:19:05 +00:00
|
|
|
Object *obj = base.toObject(ctx).objectValue();
|
|
|
|
if (ArrayObject *a = obj->asArrayObject()) {
|
|
|
|
if (index.isNumber()) {
|
|
|
|
const quint32 idx = index.toUInt32(ctx);
|
|
|
|
Value v = a->value.at(idx);
|
|
|
|
v = __qmljs_div(v, value, ctx);
|
|
|
|
a->value.assign(idx, v);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2012-06-07 14:21:21 +00:00
|
|
|
ctx->throwUnimplemented(QLatin1String(Q_FUNC_INFO));
|
|
|
|
}
|
|
|
|
|
2012-10-17 11:38:59 +00:00
|
|
|
void __qmljs_inplace_mod_element(Value base, Value index, Value value, Context *ctx)
|
2012-06-07 14:21:21 +00:00
|
|
|
{
|
2012-10-17 12:19:05 +00:00
|
|
|
Object *obj = base.toObject(ctx).objectValue();
|
|
|
|
if (ArrayObject *a = obj->asArrayObject()) {
|
|
|
|
if (index.isNumber()) {
|
|
|
|
const quint32 idx = index.toUInt32(ctx);
|
|
|
|
Value v = a->value.at(idx);
|
|
|
|
v = __qmljs_mod(v, value, ctx);
|
|
|
|
a->value.assign(idx, v);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2012-06-07 14:21:21 +00:00
|
|
|
ctx->throwUnimplemented(QLatin1String(Q_FUNC_INFO));
|
|
|
|
}
|
|
|
|
|
2012-10-17 11:38:59 +00:00
|
|
|
void __qmljs_inplace_shl_element(Value base, Value index, Value value, Context *ctx)
|
2012-06-07 14:21:21 +00:00
|
|
|
{
|
2012-10-17 12:19:05 +00:00
|
|
|
Object *obj = base.toObject(ctx).objectValue();
|
|
|
|
if (ArrayObject *a = obj->asArrayObject()) {
|
|
|
|
if (index.isNumber()) {
|
|
|
|
const quint32 idx = index.toUInt32(ctx);
|
|
|
|
Value v = a->value.at(idx);
|
|
|
|
v = __qmljs_shl(v, value, ctx);
|
|
|
|
a->value.assign(idx, v);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2012-06-07 14:21:21 +00:00
|
|
|
ctx->throwUnimplemented(QLatin1String(Q_FUNC_INFO));
|
|
|
|
}
|
|
|
|
|
2012-10-17 11:38:59 +00:00
|
|
|
void __qmljs_inplace_shr_element(Value base, Value index, Value value, Context *ctx)
|
2012-06-07 14:21:21 +00:00
|
|
|
{
|
2012-10-17 12:19:05 +00:00
|
|
|
Object *obj = base.toObject(ctx).objectValue();
|
|
|
|
if (ArrayObject *a = obj->asArrayObject()) {
|
|
|
|
if (index.isNumber()) {
|
|
|
|
const quint32 idx = index.toUInt32(ctx);
|
|
|
|
Value v = a->value.at(idx);
|
|
|
|
v = __qmljs_shr(v, value, ctx);
|
|
|
|
a->value.assign(idx, v);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2012-06-07 14:21:21 +00:00
|
|
|
ctx->throwUnimplemented(QLatin1String(Q_FUNC_INFO));
|
|
|
|
}
|
|
|
|
|
2012-10-17 11:38:59 +00:00
|
|
|
void __qmljs_inplace_ushr_element(Value base, Value index, Value value, Context *ctx)
|
2012-06-07 14:21:21 +00:00
|
|
|
{
|
2012-10-17 12:19:05 +00:00
|
|
|
Object *obj = base.toObject(ctx).objectValue();
|
|
|
|
if (ArrayObject *a = obj->asArrayObject()) {
|
|
|
|
if (index.isNumber()) {
|
|
|
|
const quint32 idx = index.toUInt32(ctx);
|
|
|
|
Value v = a->value.at(idx);
|
|
|
|
v = __qmljs_ushr(v, value, ctx);
|
|
|
|
a->value.assign(idx, v);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2012-06-07 14:21:21 +00:00
|
|
|
ctx->throwUnimplemented(QLatin1String(Q_FUNC_INFO));
|
|
|
|
}
|
|
|
|
|
2012-10-17 11:38:59 +00:00
|
|
|
void __qmljs_inplace_bit_and_member(Value value, Value base, String *name, Context *ctx)
|
2012-06-07 14:21:21 +00:00
|
|
|
{
|
2012-10-17 11:38:59 +00:00
|
|
|
Object *o = base.objectValue();
|
|
|
|
Value prop = o->getProperty(ctx, name);
|
|
|
|
prop = __qmljs_bit_and(prop, value, ctx);
|
|
|
|
o->setProperty(ctx, name, prop);
|
2012-06-07 14:21:21 +00:00
|
|
|
}
|
|
|
|
|
2012-10-17 11:38:59 +00:00
|
|
|
void __qmljs_inplace_bit_or_member(Value value, Value base, String *name, Context *ctx)
|
2012-06-11 07:38:52 +00:00
|
|
|
{
|
2012-10-17 11:38:59 +00:00
|
|
|
Object *o = base.objectValue();
|
|
|
|
Value prop = o->getProperty(ctx, name);
|
|
|
|
prop = __qmljs_bit_or(prop, value, ctx);
|
|
|
|
o->setProperty(ctx, name, prop);
|
2012-06-11 07:38:52 +00:00
|
|
|
}
|
|
|
|
|
2012-10-17 11:38:59 +00:00
|
|
|
void __qmljs_inplace_bit_xor_member(Value value, Value base, String *name, Context *ctx)
|
2012-06-11 07:38:52 +00:00
|
|
|
{
|
2012-10-17 11:38:59 +00:00
|
|
|
Object *o = base.objectValue();
|
|
|
|
Value prop = o->getProperty(ctx, name);
|
|
|
|
prop = __qmljs_bit_xor(prop, value, ctx);
|
|
|
|
o->setProperty(ctx, name, prop);
|
2012-06-11 07:38:52 +00:00
|
|
|
}
|
|
|
|
|
2012-10-17 11:38:59 +00:00
|
|
|
void __qmljs_inplace_add_member(Value value, Value base, String *name, Context *ctx)
|
2012-06-11 07:38:52 +00:00
|
|
|
{
|
2012-10-17 11:38:59 +00:00
|
|
|
Object *o = base.objectValue();
|
|
|
|
Value prop = o->getProperty(ctx, name);
|
|
|
|
prop = __qmljs_add(prop, value, ctx);
|
|
|
|
o->setProperty(ctx, name, prop);
|
2012-06-11 07:38:52 +00:00
|
|
|
}
|
|
|
|
|
2012-10-17 11:38:59 +00:00
|
|
|
void __qmljs_inplace_sub_member(Value value, Value base, String *name, Context *ctx)
|
2012-06-11 07:38:52 +00:00
|
|
|
{
|
2012-10-17 11:38:59 +00:00
|
|
|
Object *o = base.objectValue();
|
|
|
|
Value prop = o->getProperty(ctx, name);
|
|
|
|
prop = __qmljs_sub(prop, value, ctx);
|
|
|
|
o->setProperty(ctx, name, prop);
|
2012-06-11 07:38:52 +00:00
|
|
|
}
|
|
|
|
|
2012-10-17 11:38:59 +00:00
|
|
|
void __qmljs_inplace_mul_member(Value value, Value base, String *name, Context *ctx)
|
2012-06-07 14:21:21 +00:00
|
|
|
{
|
2012-10-17 11:38:59 +00:00
|
|
|
Object *o = base.objectValue();
|
|
|
|
Value prop = o->getProperty(ctx, name);
|
|
|
|
prop = __qmljs_mul(prop, value, ctx);
|
|
|
|
o->setProperty(ctx, name, prop);
|
2012-06-07 14:21:21 +00:00
|
|
|
}
|
|
|
|
|
2012-10-17 11:38:59 +00:00
|
|
|
void __qmljs_inplace_div_member(Value value, Value base, String *name, Context *ctx)
|
2012-06-07 14:21:21 +00:00
|
|
|
{
|
2012-10-17 11:38:59 +00:00
|
|
|
Object *o = base.objectValue();
|
|
|
|
Value prop = o->getProperty(ctx, name);
|
|
|
|
prop = __qmljs_div(prop, value, ctx);
|
|
|
|
o->setProperty(ctx, name, prop);
|
2012-06-07 14:21:21 +00:00
|
|
|
}
|
|
|
|
|
2012-10-17 11:38:59 +00:00
|
|
|
void __qmljs_inplace_mod_member(Value value, Value base, String *name, Context *ctx)
|
2012-06-07 14:21:21 +00:00
|
|
|
{
|
2012-10-17 11:38:59 +00:00
|
|
|
Object *o = base.objectValue();
|
|
|
|
Value prop = o->getProperty(ctx, name);
|
|
|
|
prop = __qmljs_mod(prop, value, ctx);
|
|
|
|
o->setProperty(ctx, name, prop);
|
2012-06-07 14:21:21 +00:00
|
|
|
}
|
|
|
|
|
2012-10-17 11:38:59 +00:00
|
|
|
void __qmljs_inplace_shl_member(Value value, Value base, String *name, Context *ctx)
|
2012-06-07 14:21:21 +00:00
|
|
|
{
|
2012-10-17 11:38:59 +00:00
|
|
|
Object *o = base.objectValue();
|
|
|
|
Value prop = o->getProperty(ctx, name);
|
|
|
|
prop = __qmljs_shl(prop, value, ctx);
|
|
|
|
o->setProperty(ctx, name, prop);
|
2012-06-07 14:21:21 +00:00
|
|
|
}
|
|
|
|
|
2012-10-17 11:38:59 +00:00
|
|
|
void __qmljs_inplace_shr_member(Value value, Value base, String *name, Context *ctx)
|
2012-06-07 14:21:21 +00:00
|
|
|
{
|
2012-10-17 11:38:59 +00:00
|
|
|
Object *o = base.objectValue();
|
|
|
|
Value prop = o->getProperty(ctx, name);
|
|
|
|
prop = __qmljs_shr(prop, value, ctx);
|
|
|
|
o->setProperty(ctx, name, prop);
|
2012-06-07 14:21:21 +00:00
|
|
|
}
|
|
|
|
|
2012-10-17 11:38:59 +00:00
|
|
|
void __qmljs_inplace_ushr_member(Value value, Value base, String *name, Context *ctx)
|
2012-06-07 14:21:21 +00:00
|
|
|
{
|
2012-10-17 11:38:59 +00:00
|
|
|
Object *o = base.objectValue();
|
|
|
|
Value prop = o->getProperty(ctx, name);
|
|
|
|
prop = __qmljs_ushr(prop, value, ctx);
|
|
|
|
o->setProperty(ctx, name, prop);
|
2012-06-07 14:21:21 +00:00
|
|
|
}
|
|
|
|
|
2012-06-05 10:15:41 +00:00
|
|
|
String *__qmljs_string_from_utf8(Context *ctx, const char *s)
|
|
|
|
{
|
|
|
|
return ctx->engine->newString(QString::fromUtf8(s));
|
|
|
|
}
|
|
|
|
|
2012-06-07 13:28:45 +00:00
|
|
|
String *__qmljs_identifier_from_utf8(Context *ctx, const char *s)
|
|
|
|
{
|
|
|
|
return ctx->engine->identifier(QString::fromUtf8(s));
|
|
|
|
}
|
|
|
|
|
2012-04-16 19:23:25 +00:00
|
|
|
int __qmljs_string_length(Context *, String *string)
|
|
|
|
{
|
2012-05-14 14:03:10 +00:00
|
|
|
return string->toQString().length();
|
2012-04-16 19:23:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
double __qmljs_string_to_number(Context *, String *string)
|
|
|
|
{
|
2012-06-11 07:38:52 +00:00
|
|
|
const QString s = string->toQString();
|
|
|
|
if (s.startsWith(QLatin1String("0x")) || s.startsWith(QLatin1String("0X")))
|
|
|
|
return s.toLong(0, 16);
|
|
|
|
bool ok = false;
|
2012-05-14 14:03:10 +00:00
|
|
|
return string->toQString().toDouble(&ok); // ### TODO
|
2012-04-16 19:23:25 +00:00
|
|
|
}
|
|
|
|
|
2012-10-16 12:17:36 +00:00
|
|
|
Value __qmljs_string_from_number(Context *ctx, double number)
|
2012-04-16 19:23:25 +00:00
|
|
|
{
|
2012-05-18 13:28:59 +00:00
|
|
|
String *string = ctx->engine->newString(numberToString(number, 10));
|
2012-10-16 12:17:36 +00:00
|
|
|
return Value::fromString(string);
|
2012-04-16 19:23:25 +00:00
|
|
|
}
|
|
|
|
|
2012-10-16 18:43:43 +00:00
|
|
|
Bool __qmljs_string_compare(Context *, String *left, String *right)
|
2012-04-16 19:23:25 +00:00
|
|
|
{
|
2012-05-14 14:03:10 +00:00
|
|
|
return left->toQString() < right->toQString();
|
2012-04-16 19:23:25 +00:00
|
|
|
}
|
|
|
|
|
2012-10-29 11:26:40 +00:00
|
|
|
Bool __qmljs_string_equal(String *left, String *right)
|
2012-04-16 19:23:25 +00:00
|
|
|
{
|
2012-10-29 11:26:40 +00:00
|
|
|
return left->isEqualTo(right);
|
2012-04-16 19:23:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
String *__qmljs_string_concat(Context *ctx, String *first, String *second)
|
|
|
|
{
|
2012-05-15 08:58:22 +00:00
|
|
|
return ctx->engine->newString(first->toQString() + second->toQString());
|
2012-04-16 19:23:25 +00:00
|
|
|
}
|
|
|
|
|
2012-10-17 11:43:33 +00:00
|
|
|
Bool __qmljs_is_function(Value value)
|
2012-04-16 19:23:25 +00:00
|
|
|
{
|
2012-10-16 12:17:36 +00:00
|
|
|
return value.objectValue()->asFunctionObject() != 0;
|
2012-04-16 19:23:25 +00:00
|
|
|
}
|
|
|
|
|
2012-10-17 11:43:33 +00:00
|
|
|
Value __qmljs_object_default_value(Context *ctx, Value object, int typeHint)
|
2012-04-16 19:23:25 +00:00
|
|
|
{
|
2012-05-18 13:28:59 +00:00
|
|
|
if (typeHint == PREFERREDTYPE_HINT) {
|
2012-10-25 07:15:11 +00:00
|
|
|
if (object.asDateObject())
|
2012-05-18 13:28:59 +00:00
|
|
|
typeHint = STRING_HINT;
|
|
|
|
else
|
|
|
|
typeHint = NUMBER_HINT;
|
|
|
|
}
|
|
|
|
|
|
|
|
String *meth1 = ctx->engine->identifier("toString");
|
|
|
|
String *meth2 = ctx->engine->identifier("valueOf");
|
|
|
|
|
|
|
|
if (typeHint == NUMBER_HINT)
|
|
|
|
qSwap(meth1, meth2);
|
|
|
|
|
2012-10-18 12:39:59 +00:00
|
|
|
assert(object.isObject());
|
|
|
|
Object *oo = object.objectValue();
|
2012-05-25 15:45:15 +00:00
|
|
|
|
2012-05-25 10:54:36 +00:00
|
|
|
Value conv = oo->getProperty(ctx, meth1);
|
2012-10-24 14:35:15 +00:00
|
|
|
if (FunctionObject *f = conv.asFunctionObject()) {
|
|
|
|
Value r = callFunction(ctx, object, f, 0, 0);
|
|
|
|
if (r.isPrimitive())
|
|
|
|
return r;
|
2012-05-18 13:28:59 +00:00
|
|
|
}
|
|
|
|
|
2012-05-25 10:54:36 +00:00
|
|
|
conv = oo->getProperty(ctx, meth2);
|
2012-10-24 14:35:15 +00:00
|
|
|
if (FunctionObject *f = conv.asFunctionObject()) {
|
|
|
|
Value r = callFunction(ctx, object, f, 0, 0);
|
|
|
|
if (r.isPrimitive())
|
|
|
|
return r;
|
2012-05-18 13:28:59 +00:00
|
|
|
}
|
|
|
|
|
2012-10-16 13:47:46 +00:00
|
|
|
return Value::undefinedValue();
|
2012-04-16 19:23:25 +00:00
|
|
|
}
|
|
|
|
|
2012-10-16 14:21:00 +00:00
|
|
|
Value __qmljs_throw_type_error(Context *ctx)
|
2012-04-16 19:23:25 +00:00
|
|
|
{
|
2012-05-24 08:01:17 +00:00
|
|
|
ctx->throwTypeError();
|
2012-10-16 14:21:00 +00:00
|
|
|
return ctx->result;
|
2012-04-16 19:23:25 +00:00
|
|
|
}
|
|
|
|
|
2012-10-16 14:21:00 +00:00
|
|
|
Value __qmljs_new_object(Context *ctx)
|
2012-06-07 13:28:45 +00:00
|
|
|
{
|
2012-10-18 06:52:40 +00:00
|
|
|
return Value::fromObject(ctx->engine->newObject());
|
2012-06-07 13:28:45 +00:00
|
|
|
}
|
|
|
|
|
2012-10-16 14:21:00 +00:00
|
|
|
Value __qmljs_new_boolean_object(Context *ctx, bool boolean)
|
2012-04-16 19:23:25 +00:00
|
|
|
{
|
2012-10-11 14:50:37 +00:00
|
|
|
Value value = Value::fromBoolean(boolean);
|
2012-10-18 06:52:40 +00:00
|
|
|
return Value::fromObject(ctx->engine->newBooleanObject(value));
|
2012-04-16 19:23:25 +00:00
|
|
|
}
|
|
|
|
|
2012-10-16 14:21:00 +00:00
|
|
|
Value __qmljs_new_number_object(Context *ctx, double number)
|
2012-04-16 19:23:25 +00:00
|
|
|
{
|
2012-10-11 14:50:37 +00:00
|
|
|
Value value = Value::fromDouble(number);
|
2012-10-18 06:52:40 +00:00
|
|
|
return Value::fromObject(ctx->engine->newNumberObject(value));
|
2012-04-16 19:23:25 +00:00
|
|
|
}
|
|
|
|
|
2012-10-16 14:21:00 +00:00
|
|
|
Value __qmljs_new_string_object(Context *ctx, String *string)
|
2012-04-16 19:23:25 +00:00
|
|
|
{
|
2012-10-11 19:19:08 +00:00
|
|
|
Value value = Value::fromString(string);
|
2012-10-18 06:52:40 +00:00
|
|
|
return Value::fromObject(ctx->engine->newStringObject(value));
|
2012-04-16 19:23:25 +00:00
|
|
|
}
|
|
|
|
|
2012-10-16 14:21:00 +00:00
|
|
|
void __qmljs_set_property(Context *ctx, Value object, String *name, Value value)
|
2012-04-16 19:23:25 +00:00
|
|
|
{
|
2012-10-16 14:21:00 +00:00
|
|
|
object.objectValue()->setProperty(ctx, name, value, /*flags*/ 0);
|
2012-04-16 19:23:25 +00:00
|
|
|
}
|
|
|
|
|
2012-10-11 14:50:37 +00:00
|
|
|
void __qmljs_set_property_boolean(Context *ctx, Value *object, String *name, bool b)
|
2012-05-03 16:06:23 +00:00
|
|
|
{
|
2012-10-11 14:50:37 +00:00
|
|
|
Value value = Value::fromBoolean(b);
|
2012-09-19 19:08:47 +00:00
|
|
|
object->objectValue()->setProperty(ctx, name, value, /*flag*/ 0);
|
2012-05-03 16:06:23 +00:00
|
|
|
}
|
|
|
|
|
2012-04-16 19:23:25 +00:00
|
|
|
void __qmljs_set_property_number(Context *ctx, Value *object, String *name, double number)
|
|
|
|
{
|
2012-05-16 14:19:55 +00:00
|
|
|
Q_UNUSED(ctx);
|
2012-10-11 14:50:37 +00:00
|
|
|
Value value = Value::fromDouble(number);
|
2012-09-19 19:08:47 +00:00
|
|
|
object->objectValue()->setProperty(ctx, name, value, /*flag*/ 0);
|
2012-04-16 19:23:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void __qmljs_set_property_string(Context *ctx, Value *object, String *name, String *s)
|
|
|
|
{
|
2012-05-16 14:19:55 +00:00
|
|
|
Q_UNUSED(ctx);
|
2012-10-11 19:19:08 +00:00
|
|
|
Value value = Value::fromString(s);
|
2012-09-19 19:08:47 +00:00
|
|
|
object->objectValue()->setProperty(ctx, name, value, /*flag*/ 0);
|
2012-04-16 19:23:25 +00:00
|
|
|
}
|
|
|
|
|
2012-05-09 09:28:57 +00:00
|
|
|
void __qmljs_set_property_closure(Context *ctx, Value *object, String *name, IR::Function *function)
|
|
|
|
{
|
2012-10-16 11:40:02 +00:00
|
|
|
Value value = __qmljs_init_closure(function, ctx);
|
2012-09-19 19:08:47 +00:00
|
|
|
object->objectValue()->setProperty(ctx, name, value, /*flag*/ 0);
|
2012-05-09 09:28:57 +00:00
|
|
|
}
|
|
|
|
|
2012-10-16 15:02:28 +00:00
|
|
|
Value __qmljs_get_element(Context *ctx, Value object, Value index)
|
2012-05-20 17:59:47 +00:00
|
|
|
{
|
2012-10-18 12:39:59 +00:00
|
|
|
if (index.isNumber()) {
|
|
|
|
if (object.isString()) {
|
|
|
|
const QString s = object.stringValue()->toQString().mid(index.toUInt32(ctx), 1);
|
|
|
|
if (s.isNull())
|
|
|
|
return Value::undefinedValue();
|
|
|
|
else
|
|
|
|
return Value::fromString(ctx, s);
|
|
|
|
}
|
2012-05-20 17:59:47 +00:00
|
|
|
|
2012-10-18 12:39:59 +00:00
|
|
|
if (ArrayObject *a = object.asArrayObject())
|
|
|
|
return a->value.at(index.toUInt32(ctx));
|
2012-05-20 17:59:47 +00:00
|
|
|
}
|
2012-10-18 12:39:59 +00:00
|
|
|
|
|
|
|
String *name = index.toString(ctx);
|
|
|
|
|
|
|
|
if (! object.isObject())
|
|
|
|
object = __qmljs_to_object(object, ctx);
|
|
|
|
|
2012-10-18 12:52:22 +00:00
|
|
|
return object.objectValue()->getProperty(ctx, name);
|
2012-05-20 17:59:47 +00:00
|
|
|
}
|
|
|
|
|
2012-10-16 15:02:28 +00:00
|
|
|
void __qmljs_set_element(Context *ctx, Value object, Value index, Value value)
|
2012-05-20 17:59:47 +00:00
|
|
|
{
|
2012-10-18 12:39:59 +00:00
|
|
|
if (index.isNumber()) {
|
|
|
|
if (ArrayObject *a = object.asArrayObject()) {
|
|
|
|
a->value.assign(index.toUInt32(ctx), value);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2012-05-20 17:59:47 +00:00
|
|
|
|
2012-10-18 12:39:59 +00:00
|
|
|
String *name = index.toString(ctx);
|
2012-05-20 17:59:47 +00:00
|
|
|
|
2012-10-18 12:39:59 +00:00
|
|
|
if (! object.isObject())
|
|
|
|
object = __qmljs_to_object(object, ctx);
|
2012-05-20 17:59:47 +00:00
|
|
|
|
2012-10-18 12:39:59 +00:00
|
|
|
object.objectValue()->setProperty(ctx, name, value, /*flags*/ 0);
|
2012-05-20 17:59:47 +00:00
|
|
|
}
|
|
|
|
|
2012-10-28 15:24:06 +00:00
|
|
|
Value __qmljs_foreach_iterator_object(Value in, Context *ctx)
|
|
|
|
{
|
|
|
|
in = __qmljs_to_object(in, ctx);
|
|
|
|
Object *it = ctx->engine->newForEachIteratorObject(in.objectValue());
|
|
|
|
return Value::fromObject(it);
|
|
|
|
}
|
|
|
|
|
|
|
|
Value __qmljs_foreach_next_property_name(Value foreach_iterator)
|
|
|
|
{
|
|
|
|
assert(foreach_iterator.isObject());
|
|
|
|
|
|
|
|
ForEachIteratorObject *it = static_cast<ForEachIteratorObject *>(foreach_iterator.objectValue());
|
|
|
|
assert(it->className() == QLatin1String("__ForEachIteratorObject"));
|
|
|
|
|
|
|
|
String *s = it->nextPropertyName();
|
|
|
|
if (!s)
|
|
|
|
return Value::nullValue();
|
|
|
|
return Value::fromString(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-10-16 14:21:00 +00:00
|
|
|
void __qmljs_set_activation_property(Context *ctx, String *name, Value value)
|
2012-04-16 19:23:25 +00:00
|
|
|
{
|
2012-10-16 14:21:00 +00:00
|
|
|
if (Value *prop = ctx->lookupPropertyDescriptor(name))
|
|
|
|
*prop = value;
|
|
|
|
else
|
|
|
|
ctx->engine->globalObject.objectValue()->setProperty(ctx, name, value);
|
2012-04-16 19:23:25 +00:00
|
|
|
}
|
|
|
|
|
2012-05-13 11:50:55 +00:00
|
|
|
void __qmljs_set_activation_property_boolean(Context *ctx, String *name, bool b)
|
2012-05-03 16:06:23 +00:00
|
|
|
{
|
2012-10-11 14:50:37 +00:00
|
|
|
Value value = Value::fromBoolean(b);
|
2012-10-16 14:21:00 +00:00
|
|
|
__qmljs_set_activation_property(ctx, name, value);
|
2012-05-03 16:06:23 +00:00
|
|
|
}
|
|
|
|
|
2012-05-13 11:50:55 +00:00
|
|
|
void __qmljs_set_activation_property_number(Context *ctx, String *name, double number)
|
2012-04-16 19:23:25 +00:00
|
|
|
{
|
2012-10-11 14:39:17 +00:00
|
|
|
Value value = Value::fromDouble(number);
|
2012-10-16 14:21:00 +00:00
|
|
|
__qmljs_set_activation_property(ctx, name, value);
|
2012-04-16 19:23:25 +00:00
|
|
|
}
|
|
|
|
|
2012-05-13 11:50:55 +00:00
|
|
|
void __qmljs_set_activation_property_string(Context *ctx, String *name, String *string)
|
2012-04-16 19:23:25 +00:00
|
|
|
{
|
2012-10-11 19:19:08 +00:00
|
|
|
Value value = Value::fromString(string);
|
2012-10-16 14:21:00 +00:00
|
|
|
__qmljs_set_activation_property(ctx, name, value);
|
2012-04-16 19:23:25 +00:00
|
|
|
}
|
|
|
|
|
2012-05-13 11:50:55 +00:00
|
|
|
void __qmljs_set_activation_property_closure(Context *ctx, String *name, IR::Function *clos)
|
2012-05-09 09:28:57 +00:00
|
|
|
{
|
2012-10-16 11:40:02 +00:00
|
|
|
Value value = __qmljs_init_closure(clos, ctx);
|
2012-10-16 14:21:00 +00:00
|
|
|
__qmljs_set_activation_property(ctx, name, value);
|
2012-05-09 09:28:57 +00:00
|
|
|
}
|
|
|
|
|
2012-10-16 15:02:28 +00:00
|
|
|
Value __qmljs_get_property(Context *ctx, Value object, String *name)
|
2012-04-16 19:23:25 +00:00
|
|
|
{
|
2012-10-16 15:02:28 +00:00
|
|
|
if (object.isObject()) {
|
2012-10-18 12:39:59 +00:00
|
|
|
return object.objectValue()->getProperty(ctx, name);
|
2012-10-16 15:02:28 +00:00
|
|
|
} else if (object.isString() && name->isEqualTo(ctx->engine->id_length)) {
|
2012-10-18 12:39:59 +00:00
|
|
|
return Value::fromInt32(object.stringValue()->toQString().length());
|
2012-05-09 09:04:57 +00:00
|
|
|
} else {
|
2012-10-17 11:38:50 +00:00
|
|
|
object = __qmljs_to_object(object, ctx);
|
2012-05-28 19:49:20 +00:00
|
|
|
|
2012-10-16 18:38:11 +00:00
|
|
|
if (object.isObject()) {
|
2012-10-18 12:39:59 +00:00
|
|
|
return object.objectValue()->getProperty(ctx, name);
|
2012-10-16 15:02:28 +00:00
|
|
|
} else {
|
2012-10-24 14:35:15 +00:00
|
|
|
ctx->throwTypeError();
|
2012-10-16 15:02:28 +00:00
|
|
|
return Value::undefinedValue();
|
|
|
|
}
|
2012-05-09 09:04:57 +00:00
|
|
|
}
|
2012-04-16 19:23:25 +00:00
|
|
|
}
|
|
|
|
|
2012-10-16 15:02:28 +00:00
|
|
|
Value __qmljs_get_activation_property(Context *ctx, String *name)
|
2012-04-16 19:23:25 +00:00
|
|
|
{
|
2012-05-25 10:54:36 +00:00
|
|
|
if (Value *prop = ctx->lookupPropertyDescriptor(name))
|
2012-10-16 15:02:28 +00:00
|
|
|
return *prop;
|
|
|
|
ctx->throwReferenceError(Value::fromString(name));
|
|
|
|
return Value::undefinedValue();
|
2012-04-16 19:23:25 +00:00
|
|
|
}
|
|
|
|
|
2012-10-16 15:02:28 +00:00
|
|
|
Value __qmljs_get_thisObject(Context *ctx)
|
2012-04-16 19:23:25 +00:00
|
|
|
{
|
2012-05-28 19:49:20 +00:00
|
|
|
if (ctx->thisObject.isObject())
|
2012-10-16 15:02:28 +00:00
|
|
|
return ctx->thisObject;
|
|
|
|
return ctx->engine->globalObject;
|
2012-04-16 19:23:25 +00:00
|
|
|
}
|
|
|
|
|
2012-10-17 11:43:33 +00:00
|
|
|
uint __qmljs_equal(Value x, Value y, Context *ctx)
|
2012-04-16 19:23:25 +00:00
|
|
|
{
|
2012-10-16 19:08:52 +00:00
|
|
|
if (x.type() == y.type()) {
|
|
|
|
switch (x.type()) {
|
2012-09-19 19:08:47 +00:00
|
|
|
case Value::Undefined_Type:
|
2012-04-16 19:23:25 +00:00
|
|
|
return true;
|
2012-09-19 19:08:47 +00:00
|
|
|
case Value::Null_Type:
|
2012-04-16 19:23:25 +00:00
|
|
|
return true;
|
2012-09-19 19:08:47 +00:00
|
|
|
case Value::Boolean_Type:
|
2012-10-16 19:08:52 +00:00
|
|
|
return x.booleanValue() == y.booleanValue();
|
2012-04-16 19:23:25 +00:00
|
|
|
break;
|
2012-10-12 06:48:33 +00:00
|
|
|
case Value::Integer_Type:
|
2012-10-16 19:08:52 +00:00
|
|
|
return x.integerValue() == y.integerValue();
|
2012-09-19 19:08:47 +00:00
|
|
|
case Value::String_Type:
|
2012-10-29 11:26:40 +00:00
|
|
|
return __qmljs_string_equal(x.stringValue(), y.stringValue());
|
2012-09-19 19:08:47 +00:00
|
|
|
case Value::Object_Type:
|
2012-10-16 19:08:52 +00:00
|
|
|
return x.objectValue() == y.objectValue();
|
2012-09-19 19:08:47 +00:00
|
|
|
default: // double
|
2012-10-16 19:08:52 +00:00
|
|
|
return x.doubleValue() == y.doubleValue();
|
2012-04-16 19:23:25 +00:00
|
|
|
}
|
|
|
|
// unreachable
|
|
|
|
} else {
|
2012-10-16 19:08:52 +00:00
|
|
|
if (x.isNumber() && y.isNumber())
|
|
|
|
return x.asDouble() == y.asDouble();
|
|
|
|
if (x.isNull() && y.isUndefined()) {
|
2012-04-16 19:23:25 +00:00
|
|
|
return true;
|
2012-10-16 19:08:52 +00:00
|
|
|
} else if (x.isUndefined() && y.isNull()) {
|
2012-04-16 19:23:25 +00:00
|
|
|
return true;
|
2012-10-16 19:08:52 +00:00
|
|
|
} else if (x.isNumber() && y.isString()) {
|
|
|
|
Value ny = Value::fromDouble(__qmljs_to_number(y, ctx));
|
2012-10-17 11:38:50 +00:00
|
|
|
return __qmljs_equal(x, ny, ctx);
|
2012-10-16 19:08:52 +00:00
|
|
|
} else if (x.isString() && y.isNumber()) {
|
|
|
|
Value nx = Value::fromDouble(__qmljs_to_number(x, ctx));
|
2012-10-17 11:38:50 +00:00
|
|
|
return __qmljs_equal(nx, y, ctx);
|
2012-10-16 19:08:52 +00:00
|
|
|
} else if (x.isBoolean()) {
|
|
|
|
Value nx = Value::fromDouble((double) x.booleanValue());
|
2012-10-17 11:38:50 +00:00
|
|
|
return __qmljs_equal(nx, y, ctx);
|
2012-10-16 19:08:52 +00:00
|
|
|
} else if (y.isBoolean()) {
|
|
|
|
Value ny = Value::fromDouble((double) y.booleanValue());
|
2012-10-17 11:38:50 +00:00
|
|
|
return __qmljs_equal(x, ny, ctx);
|
2012-10-16 19:08:52 +00:00
|
|
|
} else if ((x.isNumber() || x.isString()) && y.isObject()) {
|
2012-10-17 11:38:50 +00:00
|
|
|
Value py = __qmljs_to_primitive(y, ctx, PREFERREDTYPE_HINT);
|
|
|
|
return __qmljs_equal(x, py, ctx);
|
2012-10-16 19:08:52 +00:00
|
|
|
} else if (x.isObject() && (y.isNumber() || y.isString())) {
|
2012-10-17 11:38:50 +00:00
|
|
|
Value px = __qmljs_to_primitive(x, ctx, PREFERREDTYPE_HINT);
|
|
|
|
return __qmljs_equal(px, y, ctx);
|
2012-04-16 19:23:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-10-24 15:04:29 +00:00
|
|
|
// TODO: remove this function. Backends should just generate a __qmljs_get_activation_property followed by a __qmljs_call_value
|
2012-10-16 12:17:36 +00:00
|
|
|
Value __qmljs_call_activation_property(Context *context, String *name, Value *args, int argc)
|
2012-04-16 19:23:25 +00:00
|
|
|
{
|
2012-10-24 14:35:15 +00:00
|
|
|
Value func = __qmljs_get_activation_property(context, name);
|
|
|
|
if (FunctionObject *f = func.asFunctionObject()) {
|
|
|
|
return callFunction(context, Value::undefinedValue(), f, args, argc);
|
|
|
|
} else {
|
2012-05-25 09:55:50 +00:00
|
|
|
context->throwReferenceError(Value::fromString(name));
|
2012-10-16 12:17:36 +00:00
|
|
|
return Value::undefinedValue();
|
|
|
|
}
|
2012-05-09 10:00:30 +00:00
|
|
|
}
|
|
|
|
|
2012-10-17 11:43:33 +00:00
|
|
|
Value __qmljs_call_property(Context *context, Value base, String *name, Value *args, int argc)
|
2012-05-07 14:05:05 +00:00
|
|
|
{
|
2012-05-09 15:04:25 +00:00
|
|
|
Value baseObject;
|
|
|
|
Value thisObject;
|
2012-10-24 14:35:15 +00:00
|
|
|
|
|
|
|
if (base.isUndefined()) {
|
|
|
|
baseObject = context->activation;
|
|
|
|
thisObject = Value::nullValue();
|
|
|
|
} else {
|
2012-10-16 13:10:47 +00:00
|
|
|
baseObject = base;
|
2012-09-19 19:08:47 +00:00
|
|
|
if (!baseObject.isObject())
|
2012-10-17 11:38:50 +00:00
|
|
|
baseObject = __qmljs_to_object(baseObject, context);
|
2012-09-19 19:08:47 +00:00
|
|
|
assert(baseObject.isObject());
|
2012-05-09 15:04:25 +00:00
|
|
|
thisObject = baseObject;
|
2012-05-09 13:47:55 +00:00
|
|
|
}
|
|
|
|
|
2012-10-24 14:35:15 +00:00
|
|
|
Value func = baseObject.property(context, name);
|
|
|
|
return callFunction(context, thisObject, func.asFunctionObject(), args, argc);
|
2012-10-18 12:39:59 +00:00
|
|
|
}
|
|
|
|
|
2012-10-17 11:43:33 +00:00
|
|
|
Value __qmljs_call_value(Context *context, Value thisObject, Value func, Value *args, int argc)
|
2012-05-09 13:47:55 +00:00
|
|
|
{
|
2012-10-24 14:35:15 +00:00
|
|
|
return callFunction(context, thisObject, func.asFunctionObject(), args, argc);
|
2012-05-09 09:04:57 +00:00
|
|
|
}
|
|
|
|
|
2012-10-16 12:17:36 +00:00
|
|
|
Value __qmljs_construct_activation_property(Context *context, String *name, Value *args, int argc)
|
2012-05-09 13:06:30 +00:00
|
|
|
{
|
2012-05-25 10:54:36 +00:00
|
|
|
Value *func = context->lookupPropertyDescriptor(name);
|
2012-10-16 12:17:36 +00:00
|
|
|
if (! func) {
|
2012-05-25 09:55:50 +00:00
|
|
|
context->throwReferenceError(Value::fromString(name));
|
2012-10-16 12:17:36 +00:00
|
|
|
return Value::undefinedValue();
|
|
|
|
}
|
2012-10-16 13:37:31 +00:00
|
|
|
return __qmljs_construct_value(context, *func, args, argc);
|
2012-05-13 11:50:55 +00:00
|
|
|
}
|
|
|
|
|
2012-10-17 11:43:33 +00:00
|
|
|
Value __qmljs_construct_value(Context *context, Value func, Value *args, int argc)
|
2012-05-13 11:50:55 +00:00
|
|
|
{
|
2012-10-16 13:37:31 +00:00
|
|
|
if (FunctionObject *f = func.asFunctionObject()) {
|
2012-05-25 10:54:36 +00:00
|
|
|
Context k;
|
|
|
|
Context *ctx = f->needsActivation ? context->engine->newContext() : &k;
|
2012-10-21 22:18:31 +00:00
|
|
|
ctx->initConstructorContext(context, 0, f, args, argc);
|
2012-05-25 10:54:36 +00:00
|
|
|
f->construct(ctx);
|
2012-10-16 13:37:31 +00:00
|
|
|
ctx->leaveConstructorContext(f);
|
|
|
|
return ctx->result;
|
2012-05-13 11:50:55 +00:00
|
|
|
}
|
2012-10-16 13:37:31 +00:00
|
|
|
context->throwTypeError();
|
|
|
|
return Value::undefinedValue();
|
2012-05-09 13:06:30 +00:00
|
|
|
}
|
|
|
|
|
2012-10-17 11:43:33 +00:00
|
|
|
Value __qmljs_construct_property(Context *context, Value base, String *name, Value *args, int argc)
|
2012-05-09 09:04:57 +00:00
|
|
|
{
|
2012-10-16 13:37:31 +00:00
|
|
|
Value thisObject = base;
|
2012-09-19 19:08:47 +00:00
|
|
|
if (!thisObject.isObject())
|
2012-10-17 11:38:50 +00:00
|
|
|
thisObject = __qmljs_to_object(base, context);
|
2012-05-09 13:06:30 +00:00
|
|
|
|
2012-10-18 12:52:22 +00:00
|
|
|
Value func = thisObject.objectValue()->getProperty(context, name);
|
2012-05-25 10:54:36 +00:00
|
|
|
if (FunctionObject *f = func.asFunctionObject()) {
|
|
|
|
Context k;
|
|
|
|
Context *ctx = f->needsActivation ? context->engine->newContext() : &k;
|
2012-10-21 22:18:31 +00:00
|
|
|
ctx->initConstructorContext(context, 0, f, args, argc);
|
2012-05-25 10:54:36 +00:00
|
|
|
ctx->calledAsConstructor = true;
|
|
|
|
f->construct(ctx);
|
2012-10-16 13:37:31 +00:00
|
|
|
ctx->leaveConstructorContext(f);
|
|
|
|
return ctx->result;
|
2012-05-07 14:05:05 +00:00
|
|
|
}
|
2012-10-16 13:37:31 +00:00
|
|
|
context->throwTypeError();
|
|
|
|
return Value::undefinedValue();
|
2012-05-07 14:05:05 +00:00
|
|
|
}
|
2012-04-16 19:23:25 +00:00
|
|
|
|
2012-10-17 11:38:50 +00:00
|
|
|
void __qmljs_throw(Value value, Context *context)
|
2012-06-06 13:30:50 +00:00
|
|
|
{
|
2012-10-21 22:18:31 +00:00
|
|
|
assert(!context->engine->unwindStack.isEmpty());
|
|
|
|
|
|
|
|
ExecutionEngine::ExceptionHandler handler = context->engine->unwindStack.last();
|
|
|
|
|
|
|
|
// clean up call contexts
|
|
|
|
while (context != handler.context) {
|
|
|
|
context->leaveCallContext();
|
|
|
|
context = context->parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
handler.context->result = value;
|
|
|
|
|
|
|
|
longjmp(handler.stackFrame, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void *__qmljs_create_exception_handler(Context *context)
|
|
|
|
{
|
|
|
|
context->engine->unwindStack.append(ExecutionEngine::ExceptionHandler());
|
|
|
|
ExecutionEngine::ExceptionHandler *handler = &context->engine->unwindStack.last();
|
|
|
|
handler->context = context;
|
|
|
|
return handler->stackFrame;
|
|
|
|
}
|
|
|
|
|
|
|
|
void __qmljs_delete_exception_handler(Context *context)
|
|
|
|
{
|
|
|
|
assert(!context->engine->unwindStack.isEmpty());
|
|
|
|
|
|
|
|
context->engine->unwindStack.pop_back();
|
2012-06-06 13:30:50 +00:00
|
|
|
}
|
|
|
|
|
2012-10-21 22:18:31 +00:00
|
|
|
Value __qmljs_get_exception(Context *context)
|
2012-06-06 13:30:50 +00:00
|
|
|
{
|
2012-10-16 13:37:31 +00:00
|
|
|
return context->result;
|
2012-06-06 13:30:50 +00:00
|
|
|
}
|
|
|
|
|
2012-10-17 15:31:53 +00:00
|
|
|
Value __qmljs_builtin_typeof(Value val, Context *context)
|
2012-05-23 16:48:48 +00:00
|
|
|
{
|
2012-10-17 15:31:53 +00:00
|
|
|
return __qmljs_typeof(val, context);
|
2012-05-23 16:48:48 +00:00
|
|
|
}
|
|
|
|
|
2012-10-17 15:31:53 +00:00
|
|
|
void __qmljs_builtin_throw(Value val, Context *context)
|
2012-05-23 16:48:48 +00:00
|
|
|
{
|
2012-10-17 15:31:53 +00:00
|
|
|
__qmljs_throw(val, context);
|
2012-05-23 16:48:48 +00:00
|
|
|
}
|
|
|
|
|
2012-04-16 19:23:25 +00:00
|
|
|
} // extern "C"
|
2012-05-04 18:22:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
} // namespace VM
|
|
|
|
} // namespace QQmlJS
|