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$
|
|
|
|
**
|
|
|
|
****************************************************************************/
|
|
|
|
|
2013-01-29 13:20:50 +00:00
|
|
|
#include "qv4global.h"
|
2012-11-29 13:41:26 +00:00
|
|
|
#include "debugging.h"
|
2012-04-16 19:23:25 +00:00
|
|
|
#include "qmljs_runtime.h"
|
2013-01-21 20:54:53 +00:00
|
|
|
#include "qv4object.h"
|
2012-05-13 11:50:55 +00:00
|
|
|
#include "qv4ir_p.h"
|
2013-01-21 21:17:55 +00:00
|
|
|
#include "qv4objectproto.h"
|
2013-01-23 09:07:18 +00:00
|
|
|
#include "qv4globalobject.h"
|
2013-01-29 21:07:48 +00:00
|
|
|
#include "qv4stringobject.h"
|
2012-12-10 23:41:35 +00:00
|
|
|
#include "private/qlocale_tools_p.h"
|
2012-06-05 08:47:04 +00:00
|
|
|
|
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-11-15 15:56:52 +00:00
|
|
|
#include <stdlib.h>
|
2012-04-16 19:23:25 +00:00
|
|
|
|
2013-01-29 13:20:50 +00:00
|
|
|
#include "../3rdparty/double-conversion/double-conversion.h"
|
2013-01-03 15:16:03 +00:00
|
|
|
|
2012-05-04 18:22:04 +00:00
|
|
|
namespace QQmlJS {
|
|
|
|
namespace VM {
|
2012-05-04 13:28:04 +00:00
|
|
|
|
2012-05-18 13:28:59 +00:00
|
|
|
QString numberToString(double num, int radix = 10)
|
|
|
|
{
|
2013-02-08 08:23:58 +00:00
|
|
|
if (isnan(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");
|
|
|
|
}
|
|
|
|
|
2013-01-03 15:16:03 +00:00
|
|
|
if (radix == 10) {
|
|
|
|
char str[100];
|
|
|
|
double_conversion::StringBuilder builder(str, sizeof(str));
|
|
|
|
double_conversion::DoubleToStringConverter::EcmaScriptConverter().ToShortest(num, &builder);
|
|
|
|
return QString::fromLatin1(builder.Finalize());
|
|
|
|
}
|
2012-05-18 13:28:59 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2013-03-04 11:12:21 +00:00
|
|
|
Exception::Exception(ExecutionContext *throwingContext)
|
|
|
|
{
|
|
|
|
this->throwingContext = throwingContext;
|
|
|
|
accepted = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
Exception::~Exception()
|
|
|
|
{
|
|
|
|
assert(accepted);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Exception::accept(ExecutionContext *catchingContext)
|
|
|
|
{
|
|
|
|
assert(!accepted);
|
|
|
|
accepted = true;
|
|
|
|
partiallyUnwindContext(catchingContext);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Exception::partiallyUnwindContext(ExecutionContext *catchingContext)
|
|
|
|
{
|
|
|
|
if (!throwingContext)
|
|
|
|
return;
|
|
|
|
ExecutionContext *context = throwingContext;
|
|
|
|
while (context != catchingContext) {
|
|
|
|
ExecutionContext *parent = context->parent;
|
|
|
|
if (!context->withObject)
|
|
|
|
context->leaveCallContext();
|
|
|
|
context = parent;
|
|
|
|
}
|
|
|
|
throwingContext = context;
|
|
|
|
}
|
|
|
|
|
2012-04-16 19:23:25 +00:00
|
|
|
extern "C" {
|
|
|
|
|
2013-02-14 15:18:01 +00:00
|
|
|
void __qmljs_init_closure(ExecutionContext *ctx, Value *result, VM::Function *clos)
|
2012-05-09 11:51:44 +00:00
|
|
|
{
|
2012-12-11 09:03:40 +00:00
|
|
|
assert(clos);
|
2013-02-14 15:18:01 +00:00
|
|
|
*result = Value::fromObject(ctx->engine->newScriptFunction(ctx, clos));
|
2012-05-09 11:51:44 +00:00
|
|
|
}
|
|
|
|
|
2013-01-16 12:38:35 +00:00
|
|
|
Function *__qmljs_register_function(ExecutionContext *ctx, String *name,
|
|
|
|
bool hasDirectEval,
|
|
|
|
bool usesArgumentsObject, bool isStrict,
|
|
|
|
bool hasNestedFunctions,
|
|
|
|
String **formals, unsigned formalCount,
|
|
|
|
String **locals, unsigned localCount)
|
|
|
|
{
|
|
|
|
Function *f = ctx->engine->newFunction(name ? name->toQString() : QString());
|
|
|
|
|
|
|
|
f->hasDirectEval = hasDirectEval;
|
|
|
|
f->usesArgumentsObject = usesArgumentsObject;
|
|
|
|
f->isStrict = isStrict;
|
|
|
|
f->hasNestedFunctions = hasNestedFunctions;
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < formalCount; ++i)
|
|
|
|
if (formals[i])
|
2013-01-28 15:46:09 +00:00
|
|
|
f->formals.append(formals[i]);
|
2013-01-16 12:38:35 +00:00
|
|
|
for (unsigned i = 0; i < localCount; ++i)
|
|
|
|
if (locals[i])
|
2013-01-28 15:46:09 +00:00
|
|
|
f->locals.append(locals[i]);
|
2013-01-16 12:38:35 +00:00
|
|
|
|
|
|
|
return f;
|
|
|
|
}
|
|
|
|
|
2013-02-14 15:02:40 +00:00
|
|
|
void __qmljs_delete_subscript(ExecutionContext *ctx, Value *result, const Value &base, const Value &index)
|
2012-06-07 12:28:42 +00:00
|
|
|
{
|
2013-01-10 14:11:32 +00:00
|
|
|
if (Object *o = base.asObject()) {
|
2013-01-08 21:52:51 +00:00
|
|
|
uint n = UINT_MAX;
|
2012-10-16 19:08:52 +00:00
|
|
|
if (index.isInteger())
|
|
|
|
n = index.integerValue();
|
|
|
|
else if (index.isDouble())
|
|
|
|
n = index.doubleValue();
|
2013-02-14 15:02:40 +00:00
|
|
|
if (n < UINT_MAX) {
|
|
|
|
Value res = Value::fromBoolean(o->__delete__(ctx, n));
|
|
|
|
if (result)
|
|
|
|
*result = res;
|
|
|
|
return;
|
|
|
|
}
|
2012-06-07 12:28:42 +00:00
|
|
|
}
|
|
|
|
|
2012-10-16 19:08:52 +00:00
|
|
|
String *name = index.toString(ctx);
|
2013-02-14 15:02:40 +00:00
|
|
|
__qmljs_delete_member(ctx, result, base, name);
|
2012-06-07 12:28:42 +00:00
|
|
|
}
|
|
|
|
|
2013-02-14 15:02:40 +00:00
|
|
|
void __qmljs_delete_member(ExecutionContext *ctx, Value *result, const Value &base, String *name)
|
2012-06-07 12:28:42 +00:00
|
|
|
{
|
2013-02-14 20:41:49 +00:00
|
|
|
Object *obj = base.toObject(ctx);
|
|
|
|
Value res = Value::fromBoolean(obj->__delete__(ctx, name));
|
2013-02-14 15:02:40 +00:00
|
|
|
if (result)
|
|
|
|
*result = res;
|
2012-06-07 12:28:42 +00:00
|
|
|
}
|
|
|
|
|
2013-02-14 15:02:40 +00:00
|
|
|
void __qmljs_delete_name(ExecutionContext *ctx, Value *result, String *name)
|
2012-06-07 12:28:42 +00:00
|
|
|
{
|
2013-02-14 15:02:40 +00:00
|
|
|
Value res = Value::fromBoolean(ctx->deleteProperty(name));
|
|
|
|
if (result)
|
|
|
|
*result = res;
|
2012-04-16 19:23:25 +00:00
|
|
|
}
|
|
|
|
|
2013-02-14 09:45:49 +00:00
|
|
|
void __qmljs_add_helper(ExecutionContext *ctx, Value *result, const Value &left, const Value &right)
|
2012-06-06 08:58:49 +00:00
|
|
|
{
|
2013-02-14 09:45:49 +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());
|
2013-02-13 15:22:10 +00:00
|
|
|
*result = Value::fromString(string);
|
|
|
|
return;
|
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);
|
2013-02-13 15:22:10 +00:00
|
|
|
*result = Value::fromDouble(x + y);
|
2012-06-06 08:58:49 +00:00
|
|
|
}
|
|
|
|
|
2013-02-14 09:45:49 +00:00
|
|
|
void __qmljs_instanceof(ExecutionContext *ctx, Value *result, const Value &left, const Value &right)
|
2012-04-16 19:23:25 +00:00
|
|
|
{
|
2013-02-14 09:45:49 +00:00
|
|
|
Object *o = right.asObject();
|
2013-02-14 08:10:30 +00:00
|
|
|
if (!o)
|
2013-02-14 22:04:12 +00:00
|
|
|
ctx->throwTypeError();
|
2012-04-16 19:23:25 +00:00
|
|
|
|
2013-02-14 08:10:30 +00:00
|
|
|
bool r = o->hasInstance(ctx, left);
|
2013-02-13 15:22:10 +00:00
|
|
|
*result = Value::fromBoolean(r);
|
2012-04-16 19:23:25 +00:00
|
|
|
}
|
|
|
|
|
2013-02-14 09:45:49 +00:00
|
|
|
void __qmljs_in(ExecutionContext *ctx, Value *result, const Value &left, const Value &right)
|
2012-04-16 19:23:25 +00:00
|
|
|
{
|
2013-02-14 09:45:49 +00:00
|
|
|
if (!right.isObject())
|
2013-02-14 22:04:12 +00:00
|
|
|
ctx->throwTypeError();
|
2013-02-14 09:45:49 +00:00
|
|
|
String *s = left.toString(ctx);
|
|
|
|
bool r = right.objectValue()->__hasProperty__(ctx, s);
|
2013-02-13 15:22:10 +00:00
|
|
|
*result = Value::fromBoolean(r);
|
2012-04-16 19:23:25 +00:00
|
|
|
}
|
|
|
|
|
2013-02-14 09:45:49 +00:00
|
|
|
void __qmljs_inplace_bit_and_name(ExecutionContext *ctx, String *name, const Value &value)
|
2012-06-07 14:21:21 +00:00
|
|
|
{
|
2013-02-13 20:14:17 +00:00
|
|
|
ctx->inplaceBitOp(name, value, __qmljs_bit_and);
|
2012-06-07 14:21:21 +00:00
|
|
|
}
|
|
|
|
|
2013-02-14 09:45:49 +00:00
|
|
|
void __qmljs_inplace_bit_or_name(ExecutionContext *ctx, String *name, const Value &value)
|
2012-06-07 14:21:21 +00:00
|
|
|
{
|
2013-02-13 20:14:17 +00:00
|
|
|
ctx->inplaceBitOp(name, value, __qmljs_bit_or);
|
2012-06-07 14:21:21 +00:00
|
|
|
}
|
|
|
|
|
2013-02-14 09:45:49 +00:00
|
|
|
void __qmljs_inplace_bit_xor_name(ExecutionContext *ctx, String *name, const Value &value)
|
2012-06-07 14:21:21 +00:00
|
|
|
{
|
2013-02-13 20:14:17 +00:00
|
|
|
ctx->inplaceBitOp(name, value, __qmljs_bit_xor);
|
2012-06-07 14:21:21 +00:00
|
|
|
}
|
|
|
|
|
2013-02-14 09:45:49 +00:00
|
|
|
void __qmljs_inplace_add_name(ExecutionContext *ctx, String *name, const Value &value)
|
2012-06-11 07:38:52 +00:00
|
|
|
{
|
2013-02-13 20:14:17 +00:00
|
|
|
ctx->inplaceBitOp(name, value, __qmljs_add);
|
2012-06-11 07:38:52 +00:00
|
|
|
}
|
|
|
|
|
2013-02-14 09:45:49 +00:00
|
|
|
void __qmljs_inplace_sub_name(ExecutionContext *ctx, String *name, const Value &value)
|
2012-06-11 07:38:52 +00:00
|
|
|
{
|
2013-02-13 20:14:17 +00:00
|
|
|
ctx->inplaceBitOp(name, value, __qmljs_sub);
|
2012-06-11 07:38:52 +00:00
|
|
|
}
|
|
|
|
|
2013-02-14 09:45:49 +00:00
|
|
|
void __qmljs_inplace_mul_name(ExecutionContext *ctx, String *name, const Value &value)
|
2012-06-11 07:38:52 +00:00
|
|
|
{
|
2013-02-13 20:14:17 +00:00
|
|
|
ctx->inplaceBitOp(name, value, __qmljs_mul);
|
2012-06-11 07:38:52 +00:00
|
|
|
}
|
|
|
|
|
2013-02-14 09:45:49 +00:00
|
|
|
void __qmljs_inplace_div_name(ExecutionContext *ctx, String *name, const Value &value)
|
2012-06-11 07:38:52 +00:00
|
|
|
{
|
2013-02-13 20:14:17 +00:00
|
|
|
ctx->inplaceBitOp(name, value, __qmljs_div);
|
2012-06-11 07:38:52 +00:00
|
|
|
}
|
|
|
|
|
2013-02-14 09:45:49 +00:00
|
|
|
void __qmljs_inplace_mod_name(ExecutionContext *ctx, String *name, const Value &value)
|
2012-06-11 07:38:52 +00:00
|
|
|
{
|
2013-02-13 20:14:17 +00:00
|
|
|
ctx->inplaceBitOp(name, value, __qmljs_mod);
|
2012-06-11 07:38:52 +00:00
|
|
|
}
|
|
|
|
|
2013-02-14 09:45:49 +00:00
|
|
|
void __qmljs_inplace_shl_name(ExecutionContext *ctx, String *name, const Value &value)
|
2012-06-11 07:38:52 +00:00
|
|
|
{
|
2013-02-13 20:14:17 +00:00
|
|
|
ctx->inplaceBitOp(name, value, __qmljs_shl);
|
2012-06-11 07:38:52 +00:00
|
|
|
}
|
|
|
|
|
2013-02-14 09:45:49 +00:00
|
|
|
void __qmljs_inplace_shr_name(ExecutionContext *ctx, String *name, const Value &value)
|
2012-06-11 07:38:52 +00:00
|
|
|
{
|
2013-02-13 20:14:17 +00:00
|
|
|
ctx->inplaceBitOp(name, value, __qmljs_shr);
|
2012-06-11 07:38:52 +00:00
|
|
|
}
|
|
|
|
|
2013-02-14 09:45:49 +00:00
|
|
|
void __qmljs_inplace_ushr_name(ExecutionContext *ctx, String *name, const Value &value)
|
2012-06-07 14:21:21 +00:00
|
|
|
{
|
2013-02-13 20:14:17 +00:00
|
|
|
ctx->inplaceBitOp(name, value, __qmljs_ushr);
|
2012-06-07 14:21:21 +00:00
|
|
|
}
|
|
|
|
|
2013-02-14 09:45:49 +00:00
|
|
|
void __qmljs_inplace_bit_and_element(ExecutionContext *ctx, const Value &base, const Value &index, const Value &rhs)
|
2012-06-07 14:21:21 +00:00
|
|
|
{
|
2013-02-14 20:41:49 +00:00
|
|
|
Object *obj = base.toObject(ctx);
|
2013-02-13 20:14:17 +00:00
|
|
|
obj->inplaceBinOp(ctx, __qmljs_bit_and, index, rhs);
|
2012-06-07 14:21:21 +00:00
|
|
|
}
|
|
|
|
|
2013-02-14 09:45:49 +00:00
|
|
|
void __qmljs_inplace_bit_or_element(ExecutionContext *ctx, const Value &base, const Value &index, const Value &rhs)
|
2012-06-07 14:21:21 +00:00
|
|
|
{
|
2013-02-14 20:41:49 +00:00
|
|
|
Object *obj = base.toObject(ctx);
|
2013-02-13 20:14:17 +00:00
|
|
|
obj->inplaceBinOp(ctx, __qmljs_bit_or, index, rhs);
|
2012-06-07 14:21:21 +00:00
|
|
|
}
|
|
|
|
|
2013-02-14 09:45:49 +00:00
|
|
|
void __qmljs_inplace_bit_xor_element(ExecutionContext *ctx, const Value &base, const Value &index, const Value &rhs)
|
2012-06-07 14:21:21 +00:00
|
|
|
{
|
2013-02-14 20:41:49 +00:00
|
|
|
Object *obj = base.toObject(ctx);
|
2013-02-13 20:14:17 +00:00
|
|
|
obj->inplaceBinOp(ctx, __qmljs_bit_xor, index, rhs);
|
2012-06-07 14:21:21 +00:00
|
|
|
}
|
|
|
|
|
2013-02-14 09:45:49 +00:00
|
|
|
void __qmljs_inplace_add_element(ExecutionContext *ctx, const Value &base, const Value &index, const Value &rhs)
|
2012-06-07 14:21:21 +00:00
|
|
|
{
|
2013-02-14 20:41:49 +00:00
|
|
|
Object *obj = base.toObject(ctx);
|
2013-02-13 20:14:17 +00:00
|
|
|
obj->inplaceBinOp(ctx, __qmljs_add, index, rhs);
|
2012-06-07 14:21:21 +00:00
|
|
|
}
|
|
|
|
|
2013-02-14 09:45:49 +00:00
|
|
|
void __qmljs_inplace_sub_element(ExecutionContext *ctx, const Value &base, const Value &index, const Value &rhs)
|
2012-06-07 14:21:21 +00:00
|
|
|
{
|
2013-02-14 20:41:49 +00:00
|
|
|
Object *obj = base.toObject(ctx);
|
2013-02-13 20:14:17 +00:00
|
|
|
obj->inplaceBinOp(ctx, __qmljs_sub, index, rhs);
|
2012-06-07 14:21:21 +00:00
|
|
|
}
|
|
|
|
|
2013-02-14 09:45:49 +00:00
|
|
|
void __qmljs_inplace_mul_element(ExecutionContext *ctx, const Value &base, const Value &index, const Value &rhs)
|
2012-06-07 14:21:21 +00:00
|
|
|
{
|
2013-02-14 20:41:49 +00:00
|
|
|
Object *obj = base.toObject(ctx);
|
2013-02-13 20:14:17 +00:00
|
|
|
obj->inplaceBinOp(ctx, __qmljs_mul, index, rhs);
|
2012-06-07 14:21:21 +00:00
|
|
|
}
|
|
|
|
|
2013-02-14 09:45:49 +00:00
|
|
|
void __qmljs_inplace_div_element(ExecutionContext *ctx, const Value &base, const Value &index, const Value &rhs)
|
2012-06-07 14:21:21 +00:00
|
|
|
{
|
2013-02-14 20:41:49 +00:00
|
|
|
Object *obj = base.toObject(ctx);
|
2013-02-13 20:14:17 +00:00
|
|
|
obj->inplaceBinOp(ctx, __qmljs_div, index, rhs);
|
2012-06-07 14:21:21 +00:00
|
|
|
}
|
|
|
|
|
2013-02-14 09:45:49 +00:00
|
|
|
void __qmljs_inplace_mod_element(ExecutionContext *ctx, const Value &base, const Value &index, const Value &rhs)
|
2012-06-07 14:21:21 +00:00
|
|
|
{
|
2013-02-14 20:41:49 +00:00
|
|
|
Object *obj = base.toObject(ctx);
|
2013-02-13 20:14:17 +00:00
|
|
|
obj->inplaceBinOp(ctx, __qmljs_mod, index, rhs);
|
2012-06-07 14:21:21 +00:00
|
|
|
}
|
|
|
|
|
2013-02-14 09:45:49 +00:00
|
|
|
void __qmljs_inplace_shl_element(ExecutionContext *ctx, const Value &base, const Value &index, const Value &rhs)
|
2012-06-07 14:21:21 +00:00
|
|
|
{
|
2013-02-14 20:41:49 +00:00
|
|
|
Object *obj = base.toObject(ctx);
|
2013-02-13 20:14:17 +00:00
|
|
|
obj->inplaceBinOp(ctx, __qmljs_shl, index, rhs);
|
2012-06-07 14:21:21 +00:00
|
|
|
}
|
|
|
|
|
2013-02-14 09:45:49 +00:00
|
|
|
void __qmljs_inplace_shr_element(ExecutionContext *ctx, const Value &base, const Value &index, const Value &rhs)
|
2012-06-07 14:21:21 +00:00
|
|
|
{
|
2013-02-14 20:41:49 +00:00
|
|
|
Object *obj = base.toObject(ctx);
|
2013-02-13 20:14:17 +00:00
|
|
|
obj->inplaceBinOp(ctx, __qmljs_shr, index, rhs);
|
2012-06-07 14:21:21 +00:00
|
|
|
}
|
|
|
|
|
2013-02-14 09:45:49 +00:00
|
|
|
void __qmljs_inplace_ushr_element(ExecutionContext *ctx, const Value &base, const Value &index, const Value &rhs)
|
2012-06-07 14:21:21 +00:00
|
|
|
{
|
2013-02-14 20:41:49 +00:00
|
|
|
Object *obj = base.toObject(ctx);
|
2013-02-13 20:14:17 +00:00
|
|
|
obj->inplaceBinOp(ctx, __qmljs_ushr, index, rhs);
|
2012-06-07 14:21:21 +00:00
|
|
|
}
|
|
|
|
|
2013-02-14 09:45:49 +00:00
|
|
|
void __qmljs_inplace_bit_and_member(ExecutionContext *ctx, const Value &base, String *name, const Value &rhs)
|
2012-06-07 14:21:21 +00:00
|
|
|
{
|
2013-02-14 20:41:49 +00:00
|
|
|
Object *o = base.toObject(ctx);
|
2013-02-13 20:14:17 +00:00
|
|
|
o->inplaceBinOp(ctx, __qmljs_bit_and, name, rhs);
|
2012-06-07 14:21:21 +00:00
|
|
|
}
|
|
|
|
|
2013-02-14 09:45:49 +00:00
|
|
|
void __qmljs_inplace_bit_or_member(ExecutionContext *ctx, const Value &base, String *name, const Value &rhs)
|
2012-06-11 07:38:52 +00:00
|
|
|
{
|
2013-02-14 20:41:49 +00:00
|
|
|
Object *o = base.toObject(ctx);
|
2013-02-13 20:14:17 +00:00
|
|
|
o->inplaceBinOp(ctx, __qmljs_bit_or, name, rhs);
|
2012-06-11 07:38:52 +00:00
|
|
|
}
|
|
|
|
|
2013-02-14 09:45:49 +00:00
|
|
|
void __qmljs_inplace_bit_xor_member(ExecutionContext *ctx, const Value &base, String *name, const Value &rhs)
|
2012-06-11 07:38:52 +00:00
|
|
|
{
|
2013-02-14 20:41:49 +00:00
|
|
|
Object *o = base.toObject(ctx);
|
2013-02-13 20:14:17 +00:00
|
|
|
o->inplaceBinOp(ctx, __qmljs_bit_xor, name, rhs);
|
2012-06-11 07:38:52 +00:00
|
|
|
}
|
|
|
|
|
2013-02-14 09:45:49 +00:00
|
|
|
void __qmljs_inplace_add_member(ExecutionContext *ctx, const Value &base, String *name, const Value &rhs)
|
2012-06-11 07:38:52 +00:00
|
|
|
{
|
2013-02-14 20:41:49 +00:00
|
|
|
Object *o = base.toObject(ctx);
|
2013-02-13 20:14:17 +00:00
|
|
|
o->inplaceBinOp(ctx, __qmljs_add, name, rhs);
|
2012-06-11 07:38:52 +00:00
|
|
|
}
|
|
|
|
|
2013-02-14 09:45:49 +00:00
|
|
|
void __qmljs_inplace_sub_member(ExecutionContext *ctx, const Value &base, String *name, const Value &rhs)
|
2012-06-11 07:38:52 +00:00
|
|
|
{
|
2013-02-14 20:41:49 +00:00
|
|
|
Object *o = base.toObject(ctx);
|
2013-02-13 20:14:17 +00:00
|
|
|
o->inplaceBinOp(ctx, __qmljs_sub, name, rhs);
|
2012-06-11 07:38:52 +00:00
|
|
|
}
|
|
|
|
|
2013-02-14 09:45:49 +00:00
|
|
|
void __qmljs_inplace_mul_member(ExecutionContext *ctx, const Value &base, String *name, const Value &rhs)
|
2012-06-07 14:21:21 +00:00
|
|
|
{
|
2013-02-14 20:41:49 +00:00
|
|
|
Object *o = base.toObject(ctx);
|
2013-02-13 20:14:17 +00:00
|
|
|
o->inplaceBinOp(ctx, __qmljs_mul, name, rhs);
|
2012-06-07 14:21:21 +00:00
|
|
|
}
|
|
|
|
|
2013-02-14 09:45:49 +00:00
|
|
|
void __qmljs_inplace_div_member(ExecutionContext *ctx, const Value &base, String *name, const Value &rhs)
|
2012-06-07 14:21:21 +00:00
|
|
|
{
|
2013-02-14 20:41:49 +00:00
|
|
|
Object *o = base.toObject(ctx);
|
2013-02-13 20:14:17 +00:00
|
|
|
o->inplaceBinOp(ctx, __qmljs_div, name, rhs);
|
2012-06-07 14:21:21 +00:00
|
|
|
}
|
|
|
|
|
2013-02-14 09:45:49 +00:00
|
|
|
void __qmljs_inplace_mod_member(ExecutionContext *ctx, const Value &base, String *name, const Value &rhs)
|
2012-06-07 14:21:21 +00:00
|
|
|
{
|
2013-02-14 20:41:49 +00:00
|
|
|
Object *o = base.toObject(ctx);
|
2013-02-13 20:14:17 +00:00
|
|
|
o->inplaceBinOp(ctx, __qmljs_mod, name, rhs);
|
2012-06-07 14:21:21 +00:00
|
|
|
}
|
|
|
|
|
2013-02-14 09:45:49 +00:00
|
|
|
void __qmljs_inplace_shl_member(ExecutionContext *ctx, const Value &base, String *name, const Value &rhs)
|
2012-06-07 14:21:21 +00:00
|
|
|
{
|
2013-02-14 20:41:49 +00:00
|
|
|
Object *o = base.toObject(ctx);
|
2013-02-13 20:14:17 +00:00
|
|
|
o->inplaceBinOp(ctx, __qmljs_shl, name, rhs);
|
2012-06-07 14:21:21 +00:00
|
|
|
}
|
|
|
|
|
2013-02-14 09:45:49 +00:00
|
|
|
void __qmljs_inplace_shr_member(ExecutionContext *ctx, const Value &base, String *name, const Value &rhs)
|
2012-06-07 14:21:21 +00:00
|
|
|
{
|
2013-02-14 20:41:49 +00:00
|
|
|
Object *o = base.toObject(ctx);
|
2013-02-13 20:14:17 +00:00
|
|
|
o->inplaceBinOp(ctx, __qmljs_shr, name, rhs);
|
2012-06-07 14:21:21 +00:00
|
|
|
}
|
|
|
|
|
2013-02-14 09:45:49 +00:00
|
|
|
void __qmljs_inplace_ushr_member(ExecutionContext *ctx, const Value &base, String *name, const Value &rhs)
|
2012-06-07 14:21:21 +00:00
|
|
|
{
|
2013-02-14 20:41:49 +00:00
|
|
|
Object *o = base.toObject(ctx);
|
2013-02-13 20:14:17 +00:00
|
|
|
o->inplaceBinOp(ctx, __qmljs_ushr, name, rhs);
|
2012-06-07 14:21:21 +00:00
|
|
|
}
|
|
|
|
|
2012-11-16 22:07:10 +00:00
|
|
|
String *__qmljs_identifier_from_utf8(ExecutionContext *ctx, const char *s)
|
2012-06-07 13:28:45 +00:00
|
|
|
{
|
2013-01-30 13:56:40 +00:00
|
|
|
return ctx->engine->newString(QString::fromUtf8(s));
|
2012-06-07 13:28:45 +00:00
|
|
|
}
|
|
|
|
|
2013-01-11 15:28:05 +00:00
|
|
|
double __qmljs_string_to_number(const String *string)
|
2012-04-16 19:23:25 +00:00
|
|
|
{
|
2012-12-13 00:53:13 +00:00
|
|
|
QString s = string->toQString();
|
|
|
|
s = s.trimmed();
|
2012-06-11 07:38:52 +00:00
|
|
|
if (s.startsWith(QLatin1String("0x")) || s.startsWith(QLatin1String("0X")))
|
|
|
|
return s.toLong(0, 16);
|
2012-12-10 23:41:35 +00:00
|
|
|
bool ok;
|
|
|
|
QByteArray ba = s.toLatin1();
|
|
|
|
const char *begin = ba.constData();
|
|
|
|
const char *end = 0;
|
|
|
|
double d = qstrtod(begin, &end, &ok);
|
2012-12-12 18:18:40 +00:00
|
|
|
if (end - begin != ba.size()) {
|
2012-12-13 00:53:13 +00:00
|
|
|
if (ba == "Infinity" || ba == "+Infinity")
|
2013-02-07 15:52:18 +00:00
|
|
|
d = Q_INFINITY;
|
2012-12-13 00:53:13 +00:00
|
|
|
else if (ba == "-Infinity")
|
2013-02-07 15:52:18 +00:00
|
|
|
d = -Q_INFINITY;
|
2012-12-10 23:41:35 +00:00
|
|
|
else
|
2013-02-08 08:39:25 +00:00
|
|
|
d = std::numeric_limits<double>::quiet_NaN();
|
2012-12-10 23:41:35 +00:00
|
|
|
}
|
2012-11-15 15:56:52 +00:00
|
|
|
return d;
|
2012-04-16 19:23:25 +00:00
|
|
|
}
|
|
|
|
|
2012-11-16 22:07:10 +00:00
|
|
|
Value __qmljs_string_from_number(ExecutionContext *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-11-16 22:07:10 +00:00
|
|
|
Bool __qmljs_string_compare(ExecutionContext *, 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
|
|
|
}
|
|
|
|
|
2012-11-16 22:07:10 +00:00
|
|
|
String *__qmljs_string_concat(ExecutionContext *ctx, String *first, String *second)
|
2012-04-16 19:23:25 +00:00
|
|
|
{
|
2013-03-04 10:47:59 +00:00
|
|
|
const QString &a = first->toQString();
|
|
|
|
const QString &b = second->toQString();
|
|
|
|
QString newStr(a.length() + b.length(), Qt::Uninitialized);
|
|
|
|
QChar *data = newStr.data();
|
|
|
|
memcpy(data, a.constData(), a.length()*sizeof(QChar));
|
|
|
|
data += a.length();
|
|
|
|
memcpy(data, b.constData(), b.length()*sizeof(QChar));
|
|
|
|
|
|
|
|
return ctx->engine->newString(newStr);
|
2012-04-16 19:23:25 +00:00
|
|
|
}
|
|
|
|
|
2012-11-16 22:07:10 +00:00
|
|
|
Value __qmljs_object_default_value(ExecutionContext *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;
|
|
|
|
}
|
|
|
|
|
2013-01-30 13:56:40 +00:00
|
|
|
String *meth1 = ctx->engine->newString("toString");
|
|
|
|
String *meth2 = ctx->engine->newString("valueOf");
|
2012-05-18 13:28:59 +00:00
|
|
|
|
|
|
|
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-10-29 14:37:02 +00:00
|
|
|
Value conv = oo->__get__(ctx, meth1);
|
2013-01-29 12:45:32 +00:00
|
|
|
if (FunctionObject *o = conv.asFunctionObject()) {
|
2012-12-01 19:08:26 +00:00
|
|
|
Value r = o->call(ctx, object, 0, 0);
|
2012-10-24 14:35:15 +00:00
|
|
|
if (r.isPrimitive())
|
|
|
|
return r;
|
2012-05-18 13:28:59 +00:00
|
|
|
}
|
|
|
|
|
2012-10-29 14:37:02 +00:00
|
|
|
conv = oo->__get__(ctx, meth2);
|
2013-01-29 12:45:32 +00:00
|
|
|
if (FunctionObject *o = conv.asFunctionObject()) {
|
2012-12-01 19:08:26 +00:00
|
|
|
Value r = o->call(ctx, object, 0, 0);
|
2012-10-24 14:35:15 +00:00
|
|
|
if (r.isPrimitive())
|
|
|
|
return r;
|
2012-05-18 13:28:59 +00:00
|
|
|
}
|
|
|
|
|
2012-12-12 18:06:19 +00:00
|
|
|
ctx->throwTypeError();
|
2012-10-16 13:47:46 +00:00
|
|
|
return Value::undefinedValue();
|
2012-04-16 19:23:25 +00:00
|
|
|
}
|
|
|
|
|
2013-02-14 22:16:50 +00:00
|
|
|
Bool __qmljs_to_boolean(const Value &value)
|
|
|
|
{
|
|
|
|
return value.toBoolean();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-14 20:41:49 +00:00
|
|
|
Object *__qmljs_convert_to_object(ExecutionContext *ctx, const Value &value)
|
2012-06-07 13:28:45 +00:00
|
|
|
{
|
2013-02-14 20:41:49 +00:00
|
|
|
assert(!value.isObject());
|
|
|
|
switch (value.type()) {
|
|
|
|
case Value::Undefined_Type:
|
|
|
|
case Value::Null_Type:
|
2013-02-14 22:04:12 +00:00
|
|
|
ctx->throwTypeError();
|
2013-02-14 20:41:49 +00:00
|
|
|
case Value::Boolean_Type:
|
|
|
|
return ctx->engine->newBooleanObject(value);
|
|
|
|
case Value::String_Type:
|
|
|
|
return ctx->engine->newStringObject(ctx, value);
|
|
|
|
break;
|
|
|
|
case Value::Object_Type:
|
|
|
|
Q_UNREACHABLE();
|
|
|
|
case Value::Integer_Type:
|
|
|
|
default: // double
|
|
|
|
return ctx->engine->newNumberObject(value);
|
|
|
|
}
|
2012-04-16 19:23:25 +00:00
|
|
|
}
|
|
|
|
|
2013-02-14 22:00:11 +00:00
|
|
|
String *__qmljs_convert_to_string(ExecutionContext *ctx, const Value &value)
|
|
|
|
{
|
|
|
|
switch (value.type()) {
|
|
|
|
case Value::Undefined_Type:
|
|
|
|
return ctx->engine->id_undefined;
|
|
|
|
case Value::Null_Type:
|
|
|
|
return ctx->engine->id_null;
|
|
|
|
case Value::Boolean_Type:
|
|
|
|
if (value.booleanValue())
|
|
|
|
return ctx->engine->id_true;
|
|
|
|
else
|
|
|
|
return ctx->engine->id_false;
|
|
|
|
case Value::String_Type:
|
|
|
|
return value.stringValue();
|
|
|
|
case Value::Object_Type: {
|
|
|
|
Value prim = __qmljs_to_primitive(value, ctx, STRING_HINT);
|
|
|
|
if (prim.isPrimitive())
|
|
|
|
return __qmljs_convert_to_string(ctx, prim);
|
|
|
|
else
|
2013-02-14 22:04:12 +00:00
|
|
|
ctx->throwTypeError();
|
2013-02-14 22:00:11 +00:00
|
|
|
}
|
|
|
|
case Value::Integer_Type:
|
|
|
|
return __qmljs_string_from_number(ctx, value.int_32).stringValue();
|
|
|
|
default: // double
|
|
|
|
return __qmljs_string_from_number(ctx, value.doubleValue()).stringValue();
|
|
|
|
} // switch
|
|
|
|
}
|
2012-04-16 19:23:25 +00:00
|
|
|
|
2013-02-14 09:45:49 +00:00
|
|
|
void __qmljs_set_property(ExecutionContext *ctx, const Value &object, String *name, const Value &value)
|
2012-04-16 19:23:25 +00:00
|
|
|
{
|
2013-02-14 20:41:49 +00:00
|
|
|
Object *o = object.toObject(ctx);
|
2013-02-14 09:45:49 +00:00
|
|
|
o->__put__(ctx, name, value);
|
2012-04-16 19:23:25 +00:00
|
|
|
}
|
|
|
|
|
2013-02-14 19:58:10 +00:00
|
|
|
void __qmljs_get_element(ExecutionContext *ctx, Value *result, const Value &object, const Value &index)
|
2012-05-20 17:59:47 +00:00
|
|
|
{
|
2013-01-11 09:13:02 +00:00
|
|
|
uint idx = index.asArrayIndex();
|
2013-01-16 23:45:11 +00:00
|
|
|
|
2013-02-14 19:58:10 +00:00
|
|
|
Object *o = object.asObject();
|
|
|
|
if (!o) {
|
2013-02-16 22:27:07 +00:00
|
|
|
if (idx < UINT_MAX) {
|
|
|
|
if (String *str = object.asString()) {
|
|
|
|
if (idx >= (uint)str->toQString().length()) {
|
|
|
|
if (result)
|
|
|
|
*result = Value::undefinedValue();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const QString s = str->toQString().mid(idx, 1);
|
2013-02-14 19:58:10 +00:00
|
|
|
if (result)
|
2013-02-16 22:27:07 +00:00
|
|
|
*result = Value::fromString(ctx, s);
|
2013-02-14 19:58:10 +00:00
|
|
|
return;
|
|
|
|
}
|
2013-01-18 12:48:03 +00:00
|
|
|
}
|
2012-10-18 12:39:59 +00:00
|
|
|
|
2013-02-14 20:41:49 +00:00
|
|
|
o = __qmljs_convert_to_object(ctx, object);
|
2013-01-18 12:48:03 +00:00
|
|
|
}
|
2012-10-18 12:39:59 +00:00
|
|
|
|
2013-01-18 12:48:03 +00:00
|
|
|
if (idx < UINT_MAX) {
|
2013-02-03 10:36:55 +00:00
|
|
|
const PropertyDescriptor *p = o->nonSparseArrayAt(idx);
|
2013-02-14 19:58:10 +00:00
|
|
|
if (p && p->type == PropertyDescriptor::Data) {
|
|
|
|
if (result)
|
|
|
|
*result = p->value;
|
|
|
|
return;
|
|
|
|
}
|
2013-01-18 12:48:03 +00:00
|
|
|
|
2013-02-14 19:58:10 +00:00
|
|
|
Value res = o->__get__(ctx, idx);
|
|
|
|
if (result)
|
|
|
|
*result = res;
|
|
|
|
return;
|
2013-01-18 12:48:03 +00:00
|
|
|
}
|
2013-01-11 09:13:02 +00:00
|
|
|
|
|
|
|
String *name = index.toString(ctx);
|
2013-02-14 19:58:10 +00:00
|
|
|
Value res = o->__get__(ctx, name);
|
|
|
|
if (result)
|
|
|
|
*result = res;
|
2012-05-20 17:59:47 +00:00
|
|
|
}
|
|
|
|
|
2013-02-14 19:58:10 +00:00
|
|
|
void __qmljs_set_element(ExecutionContext *ctx, const Value &object, const Value &index, const Value &value)
|
2012-05-20 17:59:47 +00:00
|
|
|
{
|
2013-02-14 20:41:49 +00:00
|
|
|
Object *o = object.toObject(ctx);
|
2013-01-11 09:13:02 +00:00
|
|
|
|
|
|
|
uint idx = index.asArrayIndex();
|
|
|
|
if (idx < UINT_MAX) {
|
2013-02-05 15:15:38 +00:00
|
|
|
PropertyDescriptor *p = o->nonSparseArrayAt(idx);
|
2013-01-18 12:48:03 +00:00
|
|
|
if (p && p->type == PropertyDescriptor::Data && p->isWritable()) {
|
|
|
|
p->value = value;
|
|
|
|
return;
|
|
|
|
}
|
2013-01-11 09:13:02 +00:00
|
|
|
o->__put__(ctx, idx, value);
|
|
|
|
return;
|
2012-10-18 12:39:59 +00:00
|
|
|
}
|
2012-05-20 17:59:47 +00:00
|
|
|
|
2012-10-18 12:39:59 +00:00
|
|
|
String *name = index.toString(ctx);
|
2013-01-11 09:13:02 +00:00
|
|
|
o->__put__(ctx, name, value);
|
2012-05-20 17:59:47 +00:00
|
|
|
}
|
|
|
|
|
2013-02-15 08:54:10 +00:00
|
|
|
void __qmljs_foreach_iterator_object(ExecutionContext *ctx, Value *result, const Value &in)
|
2012-10-28 15:24:06 +00:00
|
|
|
{
|
2013-02-14 20:41:49 +00:00
|
|
|
Object *o = 0;
|
2013-01-14 11:29:45 +00:00
|
|
|
if (!in.isNull() && !in.isUndefined())
|
2013-02-14 20:41:49 +00:00
|
|
|
o = in.toObject(ctx);
|
|
|
|
Object *it = ctx->engine->newForEachIteratorObject(ctx, o);
|
2013-02-15 08:54:10 +00:00
|
|
|
*result = Value::fromObject(it);
|
2012-10-28 15:24:06 +00:00
|
|
|
}
|
|
|
|
|
2013-02-15 08:54:10 +00:00
|
|
|
void __qmljs_foreach_next_property_name(Value *result, const Value &foreach_iterator)
|
2012-10-28 15:24:06 +00:00
|
|
|
{
|
|
|
|
assert(foreach_iterator.isObject());
|
|
|
|
|
|
|
|
ForEachIteratorObject *it = static_cast<ForEachIteratorObject *>(foreach_iterator.objectValue());
|
2013-01-29 13:31:42 +00:00
|
|
|
assert(it->asForeachIteratorObject());
|
2012-10-28 15:24:06 +00:00
|
|
|
|
2013-02-15 08:54:10 +00:00
|
|
|
*result = it->nextPropertyName();
|
2012-10-28 15:24:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-14 09:45:49 +00:00
|
|
|
void __qmljs_set_activation_property(ExecutionContext *ctx, String *name, const Value &value)
|
2012-04-16 19:23:25 +00:00
|
|
|
{
|
2013-02-14 09:45:49 +00:00
|
|
|
ctx->setProperty(name, value);
|
2012-04-16 19:23:25 +00:00
|
|
|
}
|
|
|
|
|
2013-02-14 09:45:49 +00:00
|
|
|
void __qmljs_get_property(ExecutionContext *ctx, Value *result, const Value &object, String *name)
|
2012-04-16 19:23:25 +00:00
|
|
|
{
|
2013-02-13 13:42:56 +00:00
|
|
|
Value res;
|
2013-02-14 09:45:49 +00:00
|
|
|
Object *o = object.asObject();
|
2013-02-13 13:42:56 +00:00
|
|
|
if (o) {
|
|
|
|
res = o->__get__(ctx, name);
|
2013-02-14 09:45:49 +00:00
|
|
|
} else if (object.isString() && name->isEqualTo(ctx->engine->id_length)) {
|
|
|
|
res = Value::fromInt32(object.stringValue()->toQString().length());
|
2012-05-09 09:04:57 +00:00
|
|
|
} else {
|
2013-02-14 20:41:49 +00:00
|
|
|
o = __qmljs_convert_to_object(ctx, object);
|
2013-02-13 13:42:56 +00:00
|
|
|
res = o->__get__(ctx, name);
|
2012-05-09 09:04:57 +00:00
|
|
|
}
|
2013-02-13 13:42:56 +00:00
|
|
|
if (result)
|
|
|
|
*result = res;
|
2012-04-16 19:23:25 +00:00
|
|
|
}
|
|
|
|
|
2013-02-13 13:15:08 +00:00
|
|
|
void __qmljs_get_activation_property(ExecutionContext *ctx, Value *result, String *name)
|
2012-04-16 19:23:25 +00:00
|
|
|
{
|
2013-02-13 13:15:08 +00:00
|
|
|
*result = ctx->getProperty(name);
|
2012-04-16 19:23:25 +00:00
|
|
|
}
|
|
|
|
|
2013-02-14 09:45:49 +00:00
|
|
|
void __qmljs_get_property_lookup(ExecutionContext *ctx, Value *result, const Value &object, int lookupIndex)
|
2013-02-12 15:23:52 +00:00
|
|
|
{
|
2013-02-13 13:42:56 +00:00
|
|
|
Value res;
|
2013-02-12 15:23:52 +00:00
|
|
|
Lookup *l = ctx->lookups + lookupIndex;
|
2013-02-14 09:45:49 +00:00
|
|
|
if (Object *o = object.asObject()) {
|
2013-02-12 21:25:39 +00:00
|
|
|
PropertyDescriptor *p = 0;
|
|
|
|
if (o->internalClass == l->mainClass) {
|
|
|
|
if (!l->protoClass) {
|
|
|
|
p = o->memberData + l->index;
|
|
|
|
} else if (o->prototype && o->prototype->internalClass == l->protoClass) {
|
|
|
|
p = o->prototype->memberData + l->index;
|
|
|
|
}
|
|
|
|
}
|
2013-02-12 15:23:52 +00:00
|
|
|
|
2013-02-12 21:25:39 +00:00
|
|
|
if (!p) {
|
|
|
|
uint idx = o->internalClass->find(l->name);
|
|
|
|
if (idx < UINT_MAX) {
|
|
|
|
l->mainClass = o->internalClass;
|
|
|
|
l->protoClass = 0;
|
|
|
|
l->index = idx;
|
|
|
|
p = o->memberData + idx;
|
|
|
|
} else if (o->prototype) {
|
|
|
|
idx = o->prototype->internalClass->find(l->name);
|
|
|
|
if (idx < UINT_MAX) {
|
|
|
|
l->mainClass = o->internalClass;
|
|
|
|
l->protoClass = o->prototype->internalClass;
|
|
|
|
l->index = idx;
|
|
|
|
p = o->prototype->memberData + idx;
|
|
|
|
}
|
|
|
|
}
|
2013-02-12 15:23:52 +00:00
|
|
|
}
|
|
|
|
|
2013-02-12 21:25:39 +00:00
|
|
|
if (p)
|
2013-02-13 13:42:56 +00:00
|
|
|
res = p->type == PropertyDescriptor::Data ? p->value : o->getValue(ctx, p);
|
2013-02-12 21:25:39 +00:00
|
|
|
else
|
2013-02-13 13:42:56 +00:00
|
|
|
res = o->__get__(ctx, l->name);
|
2013-02-12 15:23:52 +00:00
|
|
|
} else {
|
2013-02-14 09:45:49 +00:00
|
|
|
if (object.isString() && l->name->isEqualTo(ctx->engine->id_length)) {
|
|
|
|
res = Value::fromInt32(object.stringValue()->toQString().length());
|
2013-02-12 15:23:52 +00:00
|
|
|
} else {
|
2013-02-14 20:41:49 +00:00
|
|
|
o = __qmljs_convert_to_object(ctx, object);
|
2013-02-13 13:42:56 +00:00
|
|
|
res = o->__get__(ctx, l->name);
|
2013-02-12 15:23:52 +00:00
|
|
|
}
|
|
|
|
}
|
2013-02-13 13:42:56 +00:00
|
|
|
if (result)
|
|
|
|
*result = res;
|
2013-02-12 15:23:52 +00:00
|
|
|
}
|
|
|
|
|
2013-02-14 09:45:49 +00:00
|
|
|
void __qmljs_set_property_lookup(ExecutionContext *ctx, const Value &object, int lookupIndex, const Value &value)
|
2013-02-12 15:23:52 +00:00
|
|
|
{
|
2013-02-14 20:41:49 +00:00
|
|
|
Object *o = object.toObject(ctx);
|
2013-02-12 15:23:52 +00:00
|
|
|
Lookup *l = ctx->lookups + lookupIndex;
|
|
|
|
|
|
|
|
if (l->index != ArrayObject::LengthPropertyIndex || !o->isArrayObject()) {
|
2013-02-12 21:25:39 +00:00
|
|
|
if (o->internalClass == l->mainClass) {
|
2013-02-14 09:45:49 +00:00
|
|
|
o->putValue(ctx, o->memberData + l->index, value);
|
2013-02-12 15:23:52 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint idx = o->internalClass->find(l->name);
|
|
|
|
if (idx < UINT_MAX) {
|
2013-02-12 21:25:39 +00:00
|
|
|
l->mainClass = o->internalClass;
|
2013-02-12 15:23:52 +00:00
|
|
|
l->index = idx;
|
2013-02-14 09:45:49 +00:00
|
|
|
return o->putValue(ctx, o->memberData + idx, value);
|
2013-02-12 15:23:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-14 09:45:49 +00:00
|
|
|
o->__put__(ctx, l->name, value);
|
2013-02-12 15:23:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-17 21:21:51 +00:00
|
|
|
void __qmljs_get_thisObject(ExecutionContext *ctx, Value *result)
|
2012-04-16 19:23:25 +00:00
|
|
|
{
|
2013-02-17 21:21:51 +00:00
|
|
|
*result = ctx->thisObject;
|
2012-04-16 19:23:25 +00:00
|
|
|
}
|
|
|
|
|
2013-02-14 09:45:49 +00:00
|
|
|
uint __qmljs_equal(const Value &x, const Value &y, ExecutionContext *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-12-17 09:03:37 +00:00
|
|
|
return x.stringValue()->isEqualTo(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;
|
|
|
|
}
|
|
|
|
|
2013-02-13 13:15:08 +00:00
|
|
|
void __qmljs_call_activation_property(ExecutionContext *context, Value *result, String *name, Value *args, int argc)
|
2012-04-16 19:23:25 +00:00
|
|
|
{
|
2013-01-21 15:01:28 +00:00
|
|
|
Object *base;
|
|
|
|
Value func = context->getPropertyAndBase(name, &base);
|
2013-01-29 12:45:32 +00:00
|
|
|
FunctionObject *o = func.asFunctionObject();
|
2012-12-01 19:08:26 +00:00
|
|
|
if (!o)
|
2013-01-21 09:57:09 +00:00
|
|
|
context->throwTypeError();
|
2012-12-01 19:08:26 +00:00
|
|
|
|
2013-01-21 15:01:28 +00:00
|
|
|
Value thisObject = base ? Value::fromObject(base) : Value::undefinedValue();
|
|
|
|
|
2013-02-13 13:15:08 +00:00
|
|
|
if (o == context->engine->evalFunction && name->isEqualTo(context->engine->id_eval)) {
|
|
|
|
Value res = static_cast<EvalFunction *>(o)->evalCall(context, thisObject, args, argc, true);
|
|
|
|
if (result)
|
|
|
|
*result = res;
|
|
|
|
return;
|
|
|
|
}
|
2013-01-23 09:07:18 +00:00
|
|
|
|
2013-02-13 13:15:08 +00:00
|
|
|
Value res = o->call(context, thisObject, args, argc);
|
|
|
|
if (result)
|
|
|
|
*result = res;
|
2012-05-09 10:00:30 +00:00
|
|
|
}
|
|
|
|
|
2013-02-14 12:28:49 +00:00
|
|
|
void __qmljs_call_property(ExecutionContext *context, Value *result, const Value &thatObject, String *name, Value *args, int argc)
|
2012-05-07 14:05:05 +00:00
|
|
|
{
|
2013-02-14 12:28:49 +00:00
|
|
|
Value thisObject = thatObject;
|
2013-01-29 21:07:48 +00:00
|
|
|
Object *baseObject;
|
|
|
|
if (thisObject.isString()) {
|
|
|
|
baseObject = context->engine->stringPrototype;
|
|
|
|
} else {
|
|
|
|
if (!thisObject.isObject())
|
2013-02-14 20:41:49 +00:00
|
|
|
thisObject = Value::fromObject(__qmljs_convert_to_object(context, thisObject));
|
2012-10-24 14:35:15 +00:00
|
|
|
|
2013-01-29 21:07:48 +00:00
|
|
|
assert(thisObject.isObject());
|
2013-02-14 20:41:49 +00:00
|
|
|
baseObject = thisObject.objectValue();
|
2013-01-29 21:07:48 +00:00
|
|
|
}
|
2012-05-09 13:47:55 +00:00
|
|
|
|
2012-12-01 18:57:26 +00:00
|
|
|
Value func = baseObject->__get__(context, name);
|
2013-01-29 12:45:32 +00:00
|
|
|
FunctionObject *o = func.asFunctionObject();
|
2012-12-01 19:08:26 +00:00
|
|
|
if (!o)
|
|
|
|
context->throwTypeError();
|
|
|
|
|
2013-02-14 12:28:49 +00:00
|
|
|
Value res = o->call(context, thisObject, args, argc);
|
|
|
|
if (result)
|
|
|
|
*result = res;
|
2012-10-18 12:39:59 +00:00
|
|
|
}
|
|
|
|
|
2013-02-14 12:28:49 +00:00
|
|
|
void __qmljs_call_property_lookup(ExecutionContext *context, Value *result, const Value &thatObject, uint index, Value *args, int argc)
|
2013-02-12 15:23:52 +00:00
|
|
|
{
|
2013-02-14 12:28:49 +00:00
|
|
|
Value thisObject = thatObject;
|
2013-02-12 15:23:52 +00:00
|
|
|
Lookup *l = context->lookups + index;
|
|
|
|
|
|
|
|
Object *baseObject;
|
|
|
|
if (thisObject.isString()) {
|
|
|
|
baseObject = context->engine->stringPrototype;
|
|
|
|
} else {
|
|
|
|
if (!thisObject.isObject())
|
2013-02-14 20:41:49 +00:00
|
|
|
thisObject = Value::fromObject(__qmljs_convert_to_object(context, thisObject));
|
2013-02-12 15:23:52 +00:00
|
|
|
|
2013-02-14 20:41:49 +00:00
|
|
|
assert(thisObject.isObject());
|
|
|
|
baseObject = thisObject.objectValue();
|
2013-02-12 15:23:52 +00:00
|
|
|
}
|
|
|
|
|
2013-02-12 21:25:39 +00:00
|
|
|
PropertyDescriptor *p = 0;
|
|
|
|
if (baseObject->internalClass == l->mainClass) {
|
|
|
|
if (!l->protoClass) {
|
|
|
|
p = baseObject->memberData + l->index;
|
|
|
|
} else if (baseObject->prototype && baseObject->prototype->internalClass == l->protoClass) {
|
|
|
|
p = baseObject->prototype->memberData + l->index;
|
|
|
|
}
|
|
|
|
}
|
2013-02-12 15:23:52 +00:00
|
|
|
|
2013-02-12 21:25:39 +00:00
|
|
|
if (!p) {
|
2013-02-12 15:23:52 +00:00
|
|
|
uint idx = baseObject->internalClass->find(l->name);
|
|
|
|
if (idx < UINT_MAX) {
|
2013-02-12 21:25:39 +00:00
|
|
|
l->mainClass = baseObject->internalClass;
|
|
|
|
l->protoClass = 0;
|
2013-02-12 15:23:52 +00:00
|
|
|
l->index = idx;
|
2013-02-12 21:25:39 +00:00
|
|
|
p = baseObject->memberData + idx;
|
|
|
|
} else if (baseObject->prototype) {
|
|
|
|
idx = baseObject->prototype->internalClass->find(l->name);
|
|
|
|
if (idx < UINT_MAX) {
|
|
|
|
l->mainClass = baseObject->internalClass;
|
|
|
|
l->protoClass = baseObject->prototype->internalClass;
|
|
|
|
l->index = idx;
|
|
|
|
p = baseObject->prototype->memberData + idx;
|
|
|
|
}
|
2013-02-12 15:23:52 +00:00
|
|
|
}
|
|
|
|
}
|
2013-02-12 21:25:39 +00:00
|
|
|
|
|
|
|
Value func;
|
|
|
|
if (p)
|
2013-02-12 21:50:41 +00:00
|
|
|
func = p->type == PropertyDescriptor::Data ? p->value : baseObject->getValue(context, p);
|
2013-02-12 21:25:39 +00:00
|
|
|
else
|
|
|
|
func = baseObject->__get__(context, l->name);
|
|
|
|
|
2013-02-12 15:23:52 +00:00
|
|
|
FunctionObject *o = func.asFunctionObject();
|
|
|
|
if (!o)
|
|
|
|
context->throwTypeError();
|
|
|
|
|
2013-02-14 12:28:49 +00:00
|
|
|
Value res = o->call(context, thisObject, args, argc);
|
|
|
|
if (result)
|
|
|
|
*result = res;
|
2013-02-12 15:23:52 +00:00
|
|
|
}
|
|
|
|
|
2013-02-14 12:28:49 +00:00
|
|
|
void __qmljs_call_element(ExecutionContext *context, Value *result, const Value &that, const Value &index, Value *args, int argc)
|
2013-01-27 21:39:01 +00:00
|
|
|
{
|
2013-02-14 20:41:49 +00:00
|
|
|
Object *baseObject = that.toObject(context);
|
|
|
|
Value thisObject = Value::fromObject(baseObject);
|
2013-01-27 21:39:01 +00:00
|
|
|
|
|
|
|
Value func = baseObject->__get__(context, index.toString(context));
|
2013-02-14 22:00:11 +00:00
|
|
|
Object *o = func.asObject();
|
2013-01-27 21:39:01 +00:00
|
|
|
if (!o)
|
|
|
|
context->throwTypeError();
|
|
|
|
|
2013-02-14 12:28:49 +00:00
|
|
|
Value res = o->call(context, thisObject, args, argc);
|
|
|
|
if (result)
|
|
|
|
*result = res;
|
2013-01-27 21:39:01 +00:00
|
|
|
}
|
|
|
|
|
2013-02-14 12:28:49 +00:00
|
|
|
void __qmljs_call_value(ExecutionContext *context, Value *result, const Value *thisObject, const Value &func, Value *args, int argc)
|
2012-05-09 13:47:55 +00:00
|
|
|
{
|
2013-02-14 22:00:11 +00:00
|
|
|
Object *o = func.asObject();
|
2012-12-01 19:08:26 +00:00
|
|
|
if (!o)
|
|
|
|
context->throwTypeError();
|
2013-02-14 12:28:49 +00:00
|
|
|
Value res = o->call(context, thisObject ? *thisObject : Value::undefinedValue(), args, argc);
|
|
|
|
if (result)
|
|
|
|
*result = res;
|
2012-05-09 09:04:57 +00:00
|
|
|
}
|
|
|
|
|
2013-02-13 13:15:08 +00:00
|
|
|
void __qmljs_construct_activation_property(ExecutionContext *context, Value *result, String *name, Value *args, int argc)
|
2012-05-09 13:06:30 +00:00
|
|
|
{
|
2012-12-04 21:46:48 +00:00
|
|
|
Value func = context->getProperty(name);
|
2013-02-14 14:47:06 +00:00
|
|
|
__qmljs_construct_value(context, result, func, args, argc);
|
2012-05-13 11:50:55 +00:00
|
|
|
}
|
|
|
|
|
2013-02-14 14:47:06 +00:00
|
|
|
void __qmljs_construct_value(ExecutionContext *context, Value *result, const Value &func, Value *args, int argc)
|
2012-05-13 11:50:55 +00:00
|
|
|
{
|
2013-02-14 22:00:11 +00:00
|
|
|
if (Object *f = func.asObject()) {
|
2013-02-14 14:47:06 +00:00
|
|
|
Value res = f->construct(context, args, argc);
|
|
|
|
if (result)
|
|
|
|
*result = res;
|
|
|
|
return;
|
|
|
|
}
|
2012-11-10 11:45:00 +00:00
|
|
|
|
2012-10-16 13:37:31 +00:00
|
|
|
context->throwTypeError();
|
2012-05-09 13:06:30 +00:00
|
|
|
}
|
|
|
|
|
2013-02-14 14:47:06 +00:00
|
|
|
void __qmljs_construct_property(ExecutionContext *context, Value *result, const Value &base, String *name, Value *args, int argc)
|
2012-05-09 09:04:57 +00:00
|
|
|
{
|
2013-02-14 20:41:49 +00:00
|
|
|
Object *thisObject = base.toObject(context);
|
2012-05-09 13:06:30 +00:00
|
|
|
|
2013-02-14 20:41:49 +00:00
|
|
|
Value func = thisObject->__get__(context, name);
|
2013-02-14 22:00:11 +00:00
|
|
|
if (Object *f = func.asObject()) {
|
2013-02-14 14:47:06 +00:00
|
|
|
Value res = f->construct(context, args, argc);
|
|
|
|
if (result)
|
|
|
|
*result = res;
|
|
|
|
return;
|
|
|
|
}
|
2012-11-10 11:45:00 +00:00
|
|
|
|
2012-10-16 13:37:31 +00:00
|
|
|
context->throwTypeError();
|
2012-05-07 14:05:05 +00:00
|
|
|
}
|
2012-04-16 19:23:25 +00:00
|
|
|
|
2013-02-14 15:15:19 +00:00
|
|
|
void __qmljs_throw(ExecutionContext *context, const Value &value)
|
2012-06-06 13:30:50 +00:00
|
|
|
{
|
2012-11-29 13:41:26 +00:00
|
|
|
if (context->engine->debugger)
|
2013-02-14 15:15:19 +00:00
|
|
|
context->engine->debugger->aboutToThrow(value);
|
2012-11-29 13:41:26 +00:00
|
|
|
|
2012-11-19 21:24:12 +00:00
|
|
|
context->engine->exception = value;
|
2012-10-21 22:18:31 +00:00
|
|
|
|
2013-03-04 11:12:21 +00:00
|
|
|
throw Exception(context);
|
2012-10-21 22:18:31 +00:00
|
|
|
}
|
|
|
|
|
2013-03-04 11:12:21 +00:00
|
|
|
Q_V4_EXPORT void __qmljs_create_exception_handler(ExecutionContext *context)
|
2012-10-21 22:18:31 +00:00
|
|
|
{
|
2012-11-19 21:24:12 +00:00
|
|
|
context->engine->exception = Value::undefinedValue();
|
2012-06-06 13:30:50 +00:00
|
|
|
}
|
|
|
|
|
2013-02-14 15:04:15 +00:00
|
|
|
void __qmljs_get_exception(ExecutionContext *context, Value *result)
|
2012-06-06 13:30:50 +00:00
|
|
|
{
|
2013-02-14 15:04:15 +00:00
|
|
|
*result = context->engine->exception;
|
2012-06-06 13:30:50 +00:00
|
|
|
}
|
|
|
|
|
2013-02-14 11:56:05 +00:00
|
|
|
void __qmljs_builtin_typeof(ExecutionContext *ctx, Value *result, const Value &value)
|
2012-12-08 04:31:19 +00:00
|
|
|
{
|
2013-02-14 11:56:05 +00:00
|
|
|
if (!result)
|
|
|
|
return;
|
2013-02-14 22:00:11 +00:00
|
|
|
String *res = 0;
|
2012-12-08 04:31:19 +00:00
|
|
|
switch (value.type()) {
|
|
|
|
case Value::Undefined_Type:
|
2013-02-14 22:00:11 +00:00
|
|
|
res = ctx->engine->id_undefined;
|
2012-12-08 04:31:19 +00:00
|
|
|
break;
|
|
|
|
case Value::Null_Type:
|
2013-02-14 22:00:11 +00:00
|
|
|
res = ctx->engine->id_object;
|
2012-12-08 04:31:19 +00:00
|
|
|
break;
|
|
|
|
case Value::Boolean_Type:
|
2013-02-14 22:00:11 +00:00
|
|
|
res = ctx->engine->id_boolean;
|
2012-12-08 04:31:19 +00:00
|
|
|
break;
|
|
|
|
case Value::String_Type:
|
2013-02-14 22:00:11 +00:00
|
|
|
res = ctx->engine->id_string;
|
2012-12-08 04:31:19 +00:00
|
|
|
break;
|
|
|
|
case Value::Object_Type:
|
2013-02-14 22:00:11 +00:00
|
|
|
if (value.objectValue()->asFunctionObject())
|
|
|
|
res = ctx->engine->id_function;
|
2012-12-08 04:31:19 +00:00
|
|
|
else
|
2013-02-14 22:00:11 +00:00
|
|
|
res = ctx->engine->id_object; // ### implementation-defined
|
2012-12-08 04:31:19 +00:00
|
|
|
break;
|
|
|
|
default:
|
2013-02-14 22:00:11 +00:00
|
|
|
res = ctx->engine->id_number;
|
2012-12-08 04:31:19 +00:00
|
|
|
break;
|
|
|
|
}
|
2013-02-14 22:00:11 +00:00
|
|
|
*result = Value::fromString(res);
|
2012-12-08 04:31:19 +00:00
|
|
|
}
|
|
|
|
|
2013-02-14 11:56:05 +00:00
|
|
|
void __qmljs_builtin_typeof_name(ExecutionContext *context, Value *result, String *name)
|
2012-12-08 04:31:19 +00:00
|
|
|
{
|
2013-02-14 20:41:49 +00:00
|
|
|
Value res;
|
|
|
|
__qmljs_builtin_typeof(context, &res, context->getPropertyNoThrow(name));
|
2013-02-14 11:56:05 +00:00
|
|
|
if (result)
|
2013-02-14 20:41:49 +00:00
|
|
|
*result = res;
|
2012-12-08 04:31:19 +00:00
|
|
|
}
|
|
|
|
|
2013-02-14 11:16:30 +00:00
|
|
|
void __qmljs_builtin_typeof_member(ExecutionContext *context, Value *result, const Value &base, String *name)
|
2012-12-08 04:31:19 +00:00
|
|
|
{
|
2013-02-14 20:41:49 +00:00
|
|
|
Object *obj = base.toObject(context);
|
|
|
|
Value res;
|
|
|
|
__qmljs_builtin_typeof(context, &res, obj->__get__(context, name));
|
2013-02-14 11:16:30 +00:00
|
|
|
if (result)
|
2013-02-14 20:41:49 +00:00
|
|
|
*result = res;
|
2012-12-08 04:31:19 +00:00
|
|
|
}
|
|
|
|
|
2013-02-14 11:56:05 +00:00
|
|
|
void __qmljs_builtin_typeof_element(ExecutionContext *context, Value *result, const Value &base, const Value &index)
|
2012-05-23 16:48:48 +00:00
|
|
|
{
|
2012-12-08 04:31:19 +00:00
|
|
|
String *name = index.toString(context);
|
2013-02-14 20:41:49 +00:00
|
|
|
Object *obj = base.toObject(context);
|
|
|
|
Value res;
|
|
|
|
__qmljs_builtin_typeof(context, &res, obj->__get__(context, name));
|
2013-02-14 11:56:05 +00:00
|
|
|
if (result)
|
2013-02-14 20:41:49 +00:00
|
|
|
*result = res;
|
2012-05-23 16:48:48 +00:00
|
|
|
}
|
|
|
|
|
2013-02-13 21:13:53 +00:00
|
|
|
void __qmljs_builtin_post_increment(ExecutionContext *ctx, Value *result, Value *val)
|
2013-01-27 20:16:09 +00:00
|
|
|
{
|
|
|
|
if (val->isInteger() && val->integerValue() < INT_MAX) {
|
2013-02-13 21:13:53 +00:00
|
|
|
if (result)
|
|
|
|
*result = *val;
|
2013-01-27 20:16:09 +00:00
|
|
|
val->int_32 += 1;
|
2013-02-13 21:13:53 +00:00
|
|
|
return;
|
2013-01-27 20:16:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
double d = __qmljs_to_number(*val, ctx);
|
|
|
|
*val = Value::fromDouble(d + 1);
|
2013-02-13 21:13:53 +00:00
|
|
|
if (result)
|
|
|
|
*result = Value::fromDouble(d);
|
2013-01-27 20:16:09 +00:00
|
|
|
}
|
|
|
|
|
2013-02-13 21:13:53 +00:00
|
|
|
void __qmljs_builtin_post_increment_name(ExecutionContext *context, Value *result, String *name)
|
2013-01-27 20:16:09 +00:00
|
|
|
{
|
|
|
|
Value v = context->getProperty(name);
|
|
|
|
|
|
|
|
if (v.isInteger() && v.integerValue() < INT_MAX) {
|
2013-02-13 21:13:53 +00:00
|
|
|
if (result)
|
|
|
|
*result = v;
|
2013-01-27 20:16:09 +00:00
|
|
|
v.int_32 += 1;
|
|
|
|
} else {
|
|
|
|
double d = __qmljs_to_number(v, context);
|
2013-02-13 21:13:53 +00:00
|
|
|
if (result)
|
|
|
|
*result = Value::fromDouble(d);
|
2013-01-27 20:16:09 +00:00
|
|
|
v = Value::fromDouble(d + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
context->setProperty(name, v);
|
|
|
|
}
|
|
|
|
|
2013-02-14 09:45:49 +00:00
|
|
|
void __qmljs_builtin_post_increment_member(ExecutionContext *context, Value *result, const Value &base, String *name)
|
2013-01-27 20:16:09 +00:00
|
|
|
{
|
2013-02-14 20:41:49 +00:00
|
|
|
Object *o = base.toObject(context);
|
2013-01-27 20:16:09 +00:00
|
|
|
|
|
|
|
Value v = o->__get__(context, name);
|
|
|
|
|
|
|
|
if (v.isInteger() && v.integerValue() < INT_MAX) {
|
2013-02-13 21:13:53 +00:00
|
|
|
if (result)
|
|
|
|
*result = v;
|
2013-01-27 20:16:09 +00:00
|
|
|
v.int_32 += 1;
|
|
|
|
} else {
|
|
|
|
double d = __qmljs_to_number(v, context);
|
2013-02-13 21:13:53 +00:00
|
|
|
if (result)
|
|
|
|
*result = Value::fromDouble(d);
|
2013-01-27 20:16:09 +00:00
|
|
|
v = Value::fromDouble(d + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
o->__put__(context, name, v);
|
|
|
|
}
|
|
|
|
|
2013-02-14 09:45:49 +00:00
|
|
|
void __qmljs_builtin_post_increment_element(ExecutionContext *context, Value *result, const Value &base, const Value *index)
|
2013-01-27 20:16:09 +00:00
|
|
|
{
|
2013-02-14 20:41:49 +00:00
|
|
|
Object *o = base.toObject(context);
|
2013-01-27 20:16:09 +00:00
|
|
|
|
2013-02-13 21:13:53 +00:00
|
|
|
uint idx = index->asArrayIndex();
|
2013-01-27 20:16:09 +00:00
|
|
|
|
|
|
|
if (idx == UINT_MAX) {
|
2013-02-13 21:13:53 +00:00
|
|
|
String *s = index->toString(context);
|
|
|
|
return __qmljs_builtin_post_increment_member(context, result, base, s);
|
2013-01-27 20:16:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Value v = o->__get__(context, idx);
|
|
|
|
|
|
|
|
if (v.isInteger() && v.integerValue() < INT_MAX) {
|
2013-02-13 21:13:53 +00:00
|
|
|
if (result)
|
|
|
|
*result = v;
|
2013-01-27 20:16:09 +00:00
|
|
|
v.int_32 += 1;
|
|
|
|
} else {
|
|
|
|
double d = __qmljs_to_number(v, context);
|
2013-02-13 21:13:53 +00:00
|
|
|
if (result)
|
|
|
|
*result = Value::fromDouble(d);
|
2013-01-27 20:16:09 +00:00
|
|
|
v = Value::fromDouble(d + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
o->__put__(context, idx, v);
|
|
|
|
}
|
|
|
|
|
2013-02-13 21:13:53 +00:00
|
|
|
void __qmljs_builtin_post_decrement(ExecutionContext *ctx, Value *result, Value *val)
|
2013-01-27 20:16:09 +00:00
|
|
|
{
|
|
|
|
if (val->isInteger() && val->integerValue() > INT_MIN) {
|
2013-02-13 21:13:53 +00:00
|
|
|
if (result)
|
|
|
|
*result = *val;
|
2013-01-27 20:16:09 +00:00
|
|
|
val->int_32 -= 1;
|
2013-02-13 21:13:53 +00:00
|
|
|
return;
|
2013-01-27 20:16:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
double d = __qmljs_to_number(*val, ctx);
|
|
|
|
*val = Value::fromDouble(d - 1);
|
2013-02-13 21:13:53 +00:00
|
|
|
if (result)
|
|
|
|
*result = Value::fromDouble(d);
|
2013-01-27 20:16:09 +00:00
|
|
|
}
|
|
|
|
|
2013-02-13 21:13:53 +00:00
|
|
|
void __qmljs_builtin_post_decrement_name(ExecutionContext *context, Value *result, String *name)
|
2013-01-27 20:16:09 +00:00
|
|
|
{
|
|
|
|
Value v = context->getProperty(name);
|
|
|
|
|
|
|
|
if (v.isInteger() && v.integerValue() > INT_MIN) {
|
2013-02-13 21:13:53 +00:00
|
|
|
if (result)
|
|
|
|
*result = v;
|
2013-01-27 20:16:09 +00:00
|
|
|
v.int_32 -= 1;
|
|
|
|
} else {
|
|
|
|
double d = __qmljs_to_number(v, context);
|
2013-02-13 21:13:53 +00:00
|
|
|
if (result)
|
|
|
|
*result = Value::fromDouble(d);
|
2013-01-27 20:16:09 +00:00
|
|
|
v = Value::fromDouble(d - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
context->setProperty(name, v);
|
|
|
|
}
|
|
|
|
|
2013-02-14 09:45:49 +00:00
|
|
|
void __qmljs_builtin_post_decrement_member(ExecutionContext *context, Value *result, const Value &base, String *name)
|
2013-01-27 20:16:09 +00:00
|
|
|
{
|
2013-02-14 20:41:49 +00:00
|
|
|
Object *o = base.toObject(context);
|
2013-01-27 20:16:09 +00:00
|
|
|
|
|
|
|
Value v = o->__get__(context, name);
|
|
|
|
|
|
|
|
if (v.isInteger() && v.integerValue() > INT_MIN) {
|
2013-02-13 21:13:53 +00:00
|
|
|
if (result)
|
|
|
|
*result = v;
|
2013-01-27 20:16:09 +00:00
|
|
|
v.int_32 -= 1;
|
|
|
|
} else {
|
|
|
|
double d = __qmljs_to_number(v, context);
|
2013-02-13 21:13:53 +00:00
|
|
|
if (result)
|
|
|
|
*result = Value::fromDouble(d);
|
2013-01-27 20:16:09 +00:00
|
|
|
v = Value::fromDouble(d - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
o->__put__(context, name, v);
|
|
|
|
}
|
|
|
|
|
2013-02-14 09:45:49 +00:00
|
|
|
void __qmljs_builtin_post_decrement_element(ExecutionContext *context, Value *result, const Value &base, const Value &index)
|
2013-01-27 20:16:09 +00:00
|
|
|
{
|
2013-02-14 20:41:49 +00:00
|
|
|
Object *o = base.toObject(context);
|
2013-01-27 20:16:09 +00:00
|
|
|
|
2013-02-14 09:45:49 +00:00
|
|
|
uint idx = index.asArrayIndex();
|
2013-01-27 20:16:09 +00:00
|
|
|
|
|
|
|
if (idx == UINT_MAX) {
|
2013-02-14 09:45:49 +00:00
|
|
|
String *s = index.toString(context);
|
2013-02-13 21:13:53 +00:00
|
|
|
return __qmljs_builtin_post_decrement_member(context, result, base, s);
|
2013-01-27 20:16:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Value v = o->__get__(context, idx);
|
|
|
|
|
|
|
|
if (v.isInteger() && v.integerValue() > INT_MIN) {
|
2013-02-13 21:13:53 +00:00
|
|
|
if (result)
|
|
|
|
*result = v;
|
2013-01-27 20:16:09 +00:00
|
|
|
v.int_32 -= 1;
|
|
|
|
} else {
|
|
|
|
double d = __qmljs_to_number(v, context);
|
2013-02-13 21:13:53 +00:00
|
|
|
if (result)
|
|
|
|
*result = Value::fromDouble(d);
|
2013-01-27 20:16:09 +00:00
|
|
|
v = Value::fromDouble(d - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
o->__put__(context, idx, v);
|
|
|
|
}
|
|
|
|
|
2013-02-14 15:15:19 +00:00
|
|
|
void __qmljs_builtin_throw(ExecutionContext *context, const Value &val)
|
2012-05-23 16:48:48 +00:00
|
|
|
{
|
2013-02-14 15:15:19 +00:00
|
|
|
__qmljs_throw(context, val);
|
2012-05-23 16:48:48 +00:00
|
|
|
}
|
|
|
|
|
2013-02-15 08:54:10 +00:00
|
|
|
ExecutionContext *__qmljs_builtin_push_with_scope(const Value &o, ExecutionContext *ctx)
|
2012-11-24 21:07:02 +00:00
|
|
|
{
|
2013-02-14 20:41:49 +00:00
|
|
|
Object *obj = o.toObject(ctx);
|
2013-01-24 11:13:47 +00:00
|
|
|
return ctx->createWithScope(obj);
|
2012-11-24 21:07:02 +00:00
|
|
|
}
|
|
|
|
|
2013-02-08 12:33:50 +00:00
|
|
|
ExecutionContext *__qmljs_builtin_push_catch_scope(String *exceptionVarName, ExecutionContext *ctx)
|
|
|
|
{
|
|
|
|
return ctx->createCatchScope(exceptionVarName);
|
|
|
|
}
|
|
|
|
|
2013-01-24 11:13:47 +00:00
|
|
|
ExecutionContext *__qmljs_builtin_pop_scope(ExecutionContext *ctx)
|
2012-11-24 21:07:02 +00:00
|
|
|
{
|
2013-01-24 11:13:47 +00:00
|
|
|
return ctx->popScope();
|
2012-11-24 21:07:02 +00:00
|
|
|
}
|
|
|
|
|
2012-11-26 22:26:39 +00:00
|
|
|
void __qmljs_builtin_declare_var(ExecutionContext *ctx, bool deletable, String *name)
|
|
|
|
{
|
2012-12-04 21:46:48 +00:00
|
|
|
ctx->createMutableBinding(name, deletable);
|
2012-11-26 22:26:39 +00:00
|
|
|
}
|
2012-10-30 06:29:14 +00:00
|
|
|
|
2013-02-15 08:54:10 +00:00
|
|
|
void __qmljs_builtin_define_property(ExecutionContext *ctx, const Value &object, String *name, Value *val)
|
2013-01-03 21:56:52 +00:00
|
|
|
{
|
|
|
|
Object *o = object.asObject();
|
|
|
|
assert(o);
|
|
|
|
|
2013-03-02 23:50:33 +00:00
|
|
|
uint idx = name->asArrayIndex();
|
|
|
|
PropertyDescriptor *pd = (idx != UINT_MAX) ? o->arrayInsert(idx) : o->insertMember(name);
|
2013-03-01 13:03:04 +00:00
|
|
|
pd->value = val ? *val : Value::undefinedValue();
|
|
|
|
pd->type = PropertyDescriptor::Data;
|
|
|
|
pd->writable = PropertyDescriptor::Enabled;
|
|
|
|
pd->enumberable = PropertyDescriptor::Enabled;
|
|
|
|
pd->configurable = PropertyDescriptor::Enabled;
|
2013-01-03 21:56:52 +00:00
|
|
|
}
|
|
|
|
|
2013-03-01 15:47:07 +00:00
|
|
|
void __qmljs_builtin_define_array(ExecutionContext *ctx, Value *array, Value *values, uint length)
|
|
|
|
{
|
|
|
|
ArrayObject *a = ctx->engine->newArrayObject(ctx);
|
|
|
|
|
|
|
|
// ### FIXME: We need to allocate the array data to avoid crashes other places
|
|
|
|
// This should rather be done when required
|
|
|
|
a->arrayReserve(length);
|
|
|
|
if (length) {
|
|
|
|
PropertyDescriptor *pd = a->arrayData;
|
|
|
|
for (uint i = 0; i < length; ++i) {
|
|
|
|
if (values[i].isUndefined() && values[i].uint_32 == UINT_MAX) {
|
|
|
|
pd->value = Value::undefinedValue();
|
|
|
|
pd->type = PropertyDescriptor::Generic;
|
|
|
|
pd->writable = PropertyDescriptor::Undefined;
|
|
|
|
pd->enumberable = PropertyDescriptor::Undefined;
|
|
|
|
pd->configurable = PropertyDescriptor::Undefined;
|
|
|
|
} else {
|
|
|
|
pd->value = values[i];
|
|
|
|
pd->type = PropertyDescriptor::Data;
|
|
|
|
pd->writable = PropertyDescriptor::Enabled;
|
|
|
|
pd->enumberable = PropertyDescriptor::Enabled;
|
|
|
|
pd->configurable = PropertyDescriptor::Enabled;
|
|
|
|
}
|
|
|
|
++pd;
|
|
|
|
}
|
|
|
|
a->arrayDataLen = length;
|
|
|
|
a->setArrayLengthUnchecked(length);
|
|
|
|
}
|
|
|
|
*array = Value::fromObject(a);
|
2013-01-24 11:53:47 +00:00
|
|
|
}
|
|
|
|
|
2013-02-15 08:54:10 +00:00
|
|
|
void __qmljs_builtin_define_getter_setter(ExecutionContext *ctx, const Value &object, String *name, const Value *getter, const Value *setter)
|
2013-01-03 16:11:22 +00:00
|
|
|
{
|
|
|
|
Object *o = object.asObject();
|
|
|
|
assert(o);
|
|
|
|
|
2013-03-02 23:50:33 +00:00
|
|
|
uint idx = name->asArrayIndex();
|
|
|
|
PropertyDescriptor *pd = (idx != UINT_MAX) ? o->arrayInsert(idx) : o->insertMember(name);
|
|
|
|
pd->get = getter ? getter->asFunctionObject() : 0;
|
|
|
|
pd->set = setter ? setter->asFunctionObject() : 0;
|
|
|
|
pd->type = PropertyDescriptor::Accessor;
|
|
|
|
pd->writable = PropertyDescriptor::Undefined;
|
|
|
|
pd->enumberable = PropertyDescriptor::Enabled;
|
|
|
|
pd->configurable = PropertyDescriptor::Enabled;
|
2013-01-03 16:11:22 +00:00
|
|
|
}
|
|
|
|
|
2013-02-14 15:11:16 +00:00
|
|
|
void __qmljs_increment(ExecutionContext *ctx, Value *result, const Value &value)
|
2012-12-12 21:46:57 +00:00
|
|
|
{
|
|
|
|
TRACE1(value);
|
|
|
|
|
|
|
|
if (value.isInteger())
|
2013-02-14 14:55:43 +00:00
|
|
|
*result = Value::fromInt32(value.integerValue() + 1);
|
|
|
|
else {
|
|
|
|
double d = __qmljs_to_number(value, ctx);
|
|
|
|
*result = Value::fromDouble(d + 1);
|
|
|
|
}
|
2012-12-12 21:46:57 +00:00
|
|
|
}
|
|
|
|
|
2013-02-14 15:11:16 +00:00
|
|
|
void __qmljs_decrement(ExecutionContext *ctx, Value *result, const Value &value)
|
2012-12-12 21:46:57 +00:00
|
|
|
{
|
|
|
|
TRACE1(value);
|
|
|
|
|
|
|
|
if (value.isInteger())
|
2013-02-14 14:55:43 +00:00
|
|
|
*result = Value::fromInt32(value.integerValue() - 1);
|
|
|
|
else {
|
|
|
|
double d = __qmljs_to_number(value, ctx);
|
|
|
|
*result = Value::fromDouble(d - 1);
|
|
|
|
}
|
2012-12-12 21:46:57 +00:00
|
|
|
}
|
|
|
|
|
2012-04-16 19:23:25 +00:00
|
|
|
} // extern "C"
|
2012-05-04 18:22:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
} // namespace VM
|
|
|
|
} // namespace QQmlJS
|