2012-10-12 08:12:24 +00:00
|
|
|
/****************************************************************************
|
|
|
|
**
|
2013-06-24 11:50:51 +00:00
|
|
|
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
2012-10-12 08:12:24 +00:00
|
|
|
** Contact: http://www.qt-project.org/legal
|
|
|
|
**
|
2013-06-24 11:50:51 +00:00
|
|
|
** This file is part of the QtQml module of the Qt Toolkit.
|
2012-10-12 08:12:24 +00:00
|
|
|
**
|
|
|
|
** $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-04-15 09:50:16 +00:00
|
|
|
#include "qv4global_p.h"
|
|
|
|
#include "qv4runtime_p.h"
|
|
|
|
#include "qv4object_p.h"
|
2013-03-05 11:49:35 +00:00
|
|
|
#include "qv4jsir_p.h"
|
2013-04-15 09:50:16 +00:00
|
|
|
#include "qv4objectproto_p.h"
|
|
|
|
#include "qv4globalobject_p.h"
|
|
|
|
#include "qv4stringobject_p.h"
|
2013-08-16 10:54:30 +00:00
|
|
|
#include "qv4argumentsobject_p.h"
|
2013-04-15 09:50:16 +00:00
|
|
|
#include "qv4lookup_p.h"
|
2013-05-08 12:24:30 +00:00
|
|
|
#include "qv4function_p.h"
|
2012-12-10 23:41:35 +00:00
|
|
|
#include "private/qlocale_tools_p.h"
|
2013-09-04 14:05:34 +00:00
|
|
|
#include "qv4scopedvalue_p.h"
|
2013-10-23 14:24:58 +00:00
|
|
|
#include <private/qqmlcontextwrapper_p.h>
|
|
|
|
#include "qv4qobjectwrapper_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-04-16 15:03:00 +00:00
|
|
|
#include "../../../3rdparty/double-conversion/double-conversion.h"
|
2013-01-03 15:16:03 +00:00
|
|
|
|
2013-06-24 13:28:00 +00:00
|
|
|
QT_BEGIN_NAMESPACE
|
2013-04-19 11:03:42 +00:00
|
|
|
|
2013-06-24 13:28:00 +00:00
|
|
|
namespace QV4 {
|
2012-05-04 13:28:04 +00:00
|
|
|
|
2013-08-29 17:42:50 +00:00
|
|
|
#ifdef QV4_COUNT_RUNTIME_FUNCTIONS
|
|
|
|
struct RuntimeCounters::Data {
|
|
|
|
enum Type {
|
|
|
|
None = 0,
|
|
|
|
Undefined = 1,
|
|
|
|
Null = 2,
|
|
|
|
Boolean = 3,
|
|
|
|
Integer = 4,
|
2013-09-15 13:46:36 +00:00
|
|
|
Managed = 5,
|
2013-08-29 17:42:50 +00:00
|
|
|
Double = 7
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char *pretty(Type t) {
|
|
|
|
switch (t) {
|
|
|
|
case None: return "";
|
|
|
|
case Undefined: return "Undefined";
|
|
|
|
case Null: return "Null";
|
|
|
|
case Boolean: return "Boolean";
|
|
|
|
case Integer: return "Integer";
|
2013-09-15 13:46:36 +00:00
|
|
|
case Managed: return "Managed";
|
2013-08-29 17:42:50 +00:00
|
|
|
case Double: return "Double";
|
|
|
|
default: return "Unknown";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned mangle(unsigned tag) {
|
|
|
|
switch (tag) {
|
|
|
|
case Value::Undefined_Type: return Undefined;
|
|
|
|
case Value::Null_Type: return Null;
|
|
|
|
case Value::Boolean_Type: return Boolean;
|
|
|
|
case Value::Integer_Type: return Integer;
|
2013-09-15 13:46:36 +00:00
|
|
|
case Value::Managed_Type: return Managed;
|
2013-08-29 17:42:50 +00:00
|
|
|
default: return Double;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned mangle(unsigned tag1, unsigned tag2) {
|
|
|
|
return (mangle(tag1) << 3) | mangle(tag2);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void unmangle(unsigned signature, Type &tag1, Type &tag2) {
|
|
|
|
tag1 = Type((signature >> 3) & 7);
|
|
|
|
tag2 = Type(signature & 7);
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef QVector<quint64> Counters;
|
|
|
|
QHash<const char *, Counters> counters;
|
|
|
|
|
2013-10-09 08:47:11 +00:00
|
|
|
inline void count(const char *func) {
|
|
|
|
QVector<quint64> &cnt = counters[func];
|
|
|
|
if (cnt.isEmpty())
|
|
|
|
cnt.resize(64);
|
|
|
|
cnt[0] += 1;
|
|
|
|
}
|
|
|
|
|
2013-08-29 17:42:50 +00:00
|
|
|
inline void count(const char *func, unsigned tag) {
|
|
|
|
QVector<quint64> &cnt = counters[func];
|
|
|
|
if (cnt.isEmpty())
|
|
|
|
cnt.resize(64);
|
|
|
|
cnt[mangle(tag)] += 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void count(const char *func, unsigned tag1, unsigned tag2) {
|
|
|
|
QVector<quint64> &cnt = counters[func];
|
|
|
|
if (cnt.isEmpty())
|
|
|
|
cnt.resize(64);
|
|
|
|
cnt[mangle(tag1, tag2)] += 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct Line {
|
|
|
|
const char *func;
|
|
|
|
Type tag1, tag2;
|
|
|
|
quint64 count;
|
|
|
|
|
|
|
|
static bool less(const Line &line1, const Line &line2) {
|
|
|
|
return line1.count > line2.count;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
void dump() const {
|
2013-10-04 14:06:16 +00:00
|
|
|
QTextStream outs(stderr, QIODevice::WriteOnly);
|
2013-08-29 17:42:50 +00:00
|
|
|
QList<Line> lines;
|
|
|
|
foreach (const char *func, counters.keys()) {
|
|
|
|
const Counters &fCount = counters[func];
|
|
|
|
for (int i = 0, ei = fCount.size(); i != ei; ++i) {
|
|
|
|
quint64 count = fCount[i];
|
|
|
|
if (!count)
|
|
|
|
continue;
|
|
|
|
Line line;
|
|
|
|
line.func = func;
|
|
|
|
unmangle(i, line.tag1, line.tag2);
|
|
|
|
line.count = count;
|
|
|
|
lines.append(line);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
qSort(lines.begin(), lines.end(), Line::less);
|
2013-10-04 14:06:16 +00:00
|
|
|
outs << lines.size() << " counters:" << endl;
|
2013-08-29 17:42:50 +00:00
|
|
|
foreach (const Line &line, lines)
|
2013-10-04 14:06:16 +00:00
|
|
|
outs << qSetFieldWidth(10) << line.count << qSetFieldWidth(0)
|
|
|
|
<< " | " << line.func
|
|
|
|
<< " | " << pretty(line.tag1)
|
|
|
|
<< " | " << pretty(line.tag2)
|
|
|
|
<< endl;
|
2013-08-29 17:42:50 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
RuntimeCounters *RuntimeCounters::instance = 0;
|
|
|
|
static RuntimeCounters runtimeCountersInstance;
|
|
|
|
RuntimeCounters::RuntimeCounters()
|
|
|
|
: d(new Data)
|
|
|
|
{
|
|
|
|
if (!instance)
|
|
|
|
instance = this;
|
|
|
|
}
|
|
|
|
|
|
|
|
RuntimeCounters::~RuntimeCounters()
|
|
|
|
{
|
|
|
|
d->dump();
|
2013-10-04 14:06:16 +00:00
|
|
|
delete d;
|
2013-08-29 17:42:50 +00:00
|
|
|
}
|
|
|
|
|
2013-10-09 08:47:11 +00:00
|
|
|
void RuntimeCounters::count(const char *func)
|
|
|
|
{
|
|
|
|
d->count(func);
|
|
|
|
}
|
|
|
|
|
2013-08-29 17:42:50 +00:00
|
|
|
void RuntimeCounters::count(const char *func, uint tag)
|
|
|
|
{
|
|
|
|
d->count(func, tag);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RuntimeCounters::count(const char *func, uint tag1, uint tag2)
|
|
|
|
{
|
|
|
|
d->count(func, tag1, tag2);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // QV4_COUNT_RUNTIME_FUNCTIONS
|
|
|
|
|
2013-04-24 12:28:52 +00:00
|
|
|
void __qmljs_numberToString(QString *result, double num, int radix)
|
2012-05-18 13:28:59 +00:00
|
|
|
{
|
2013-04-24 12:28:52 +00:00
|
|
|
Q_ASSERT(result);
|
|
|
|
|
2013-04-16 15:03:00 +00:00
|
|
|
if (std::isnan(num)) {
|
2013-04-24 12:28:52 +00:00
|
|
|
*result = QStringLiteral("NaN");
|
|
|
|
return;
|
2012-05-18 13:28:59 +00:00
|
|
|
} else if (qIsInf(num)) {
|
2013-04-24 12:28:52 +00:00
|
|
|
*result = QLatin1String(num < 0 ? "-Infinity" : "Infinity");
|
|
|
|
return;
|
2012-05-18 13:28:59 +00:00
|
|
|
}
|
|
|
|
|
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);
|
2013-04-24 12:28:52 +00:00
|
|
|
*result = QString::fromLatin1(builder.Finalize());
|
|
|
|
return;
|
2013-01-03 15:16:03 +00:00
|
|
|
}
|
2012-05-18 13:28:59 +00:00
|
|
|
|
2013-04-24 12:28:52 +00:00
|
|
|
result->clear();
|
2012-05-18 13:28:59 +00:00
|
|
|
bool negative = false;
|
|
|
|
|
|
|
|
if (num < 0) {
|
|
|
|
negative = true;
|
|
|
|
num = -num;
|
|
|
|
}
|
|
|
|
|
|
|
|
double frac = num - ::floor(num);
|
2013-09-25 11:52:15 +00:00
|
|
|
num = Primitive::toInteger(num);
|
2012-05-18 13:28:59 +00:00
|
|
|
|
|
|
|
do {
|
|
|
|
char c = (char)::fmod(num, radix);
|
|
|
|
c = (c < 10) ? (c + '0') : (c - 10 + 'a');
|
2013-04-24 12:28:52 +00:00
|
|
|
result->prepend(QLatin1Char(c));
|
2012-05-18 13:28:59 +00:00
|
|
|
num = ::floor(num / radix);
|
|
|
|
} while (num != 0);
|
|
|
|
|
|
|
|
if (frac != 0) {
|
2013-04-24 12:28:52 +00:00
|
|
|
result->append(QLatin1Char('.'));
|
2012-05-18 13:28:59 +00:00
|
|
|
do {
|
|
|
|
frac = frac * radix;
|
|
|
|
char c = (char)::floor(frac);
|
|
|
|
c = (c < 10) ? (c + '0') : (c - 10 + 'a');
|
2013-04-24 12:28:52 +00:00
|
|
|
result->append(QLatin1Char(c));
|
2012-05-18 13:28:59 +00:00
|
|
|
frac = frac - ::floor(frac);
|
|
|
|
} while (frac != 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (negative)
|
2013-04-24 12:28:52 +00:00
|
|
|
result->prepend(QLatin1Char('-'));
|
2012-05-18 13:28:59 +00:00
|
|
|
}
|
|
|
|
|
2013-09-09 20:34:47 +00:00
|
|
|
ReturnedValue __qmljs_init_closure(ExecutionContext *ctx, int functionId)
|
2012-05-09 11:51:44 +00:00
|
|
|
{
|
2013-08-17 10:08:21 +00:00
|
|
|
QV4::Function *clos = ctx->compilationUnit->runtimeFunctions[functionId];
|
2013-09-09 20:34:47 +00:00
|
|
|
Q_ASSERT(clos);
|
2013-09-15 13:46:36 +00:00
|
|
|
FunctionObject *f = FunctionObject::creatScriptFunction(ctx, clos);
|
|
|
|
return f->asReturnedValue();
|
2012-05-09 11:51:44 +00:00
|
|
|
}
|
|
|
|
|
2013-09-09 19:35:37 +00:00
|
|
|
ReturnedValue __qmljs_delete_subscript(ExecutionContext *ctx, const ValueRef base, const ValueRef index)
|
2012-06-07 12:28:42 +00:00
|
|
|
{
|
2013-09-19 10:05:18 +00:00
|
|
|
Scope scope(ctx);
|
|
|
|
ScopedObject o(scope, base);
|
|
|
|
if (o) {
|
2013-09-09 11:38:10 +00:00
|
|
|
uint n = index->asArrayIndex();
|
2013-02-14 15:02:40 +00:00
|
|
|
if (n < UINT_MAX) {
|
2013-09-26 20:07:27 +00:00
|
|
|
return Encode((bool)o->deleteIndexedProperty(n));
|
2013-02-14 15:02:40 +00:00
|
|
|
}
|
2012-06-07 12:28:42 +00:00
|
|
|
}
|
|
|
|
|
2013-09-19 10:05:18 +00:00
|
|
|
ScopedString name(scope, index->toString(ctx));
|
2013-09-09 19:35:37 +00:00
|
|
|
return __qmljs_delete_member(ctx, base, name);
|
2012-06-07 12:28:42 +00:00
|
|
|
}
|
|
|
|
|
2013-09-19 10:05:18 +00:00
|
|
|
ReturnedValue __qmljs_delete_member(ExecutionContext *ctx, const ValueRef base, const StringRef name)
|
2012-06-07 12:28:42 +00:00
|
|
|
{
|
2013-09-19 07:58:50 +00:00
|
|
|
Scope scope(ctx);
|
|
|
|
ScopedObject obj(scope, base->toObject(ctx));
|
2013-10-21 07:57:58 +00:00
|
|
|
if (scope.engine->hasException)
|
|
|
|
return Encode::undefined();
|
2013-09-19 10:05:18 +00:00
|
|
|
return Encode(obj->deleteProperty(name));
|
2012-06-07 12:28:42 +00:00
|
|
|
}
|
|
|
|
|
2013-09-19 10:05:18 +00:00
|
|
|
ReturnedValue __qmljs_delete_name(ExecutionContext *ctx, const StringRef name)
|
2012-06-07 12:28:42 +00:00
|
|
|
{
|
2013-09-19 07:58:50 +00:00
|
|
|
Scope scope(ctx);
|
2013-09-19 10:05:18 +00:00
|
|
|
return Encode(ctx->deleteProperty(name));
|
2012-04-16 19:23:25 +00:00
|
|
|
}
|
|
|
|
|
2013-09-09 20:23:10 +00:00
|
|
|
QV4::ReturnedValue __qmljs_add_helper(ExecutionContext *ctx, const ValueRef left, const ValueRef right)
|
2012-06-06 08:58:49 +00:00
|
|
|
{
|
2013-09-11 12:47:34 +00:00
|
|
|
Scope scope(ctx);
|
2013-09-04 14:05:34 +00:00
|
|
|
|
2013-09-09 11:38:10 +00:00
|
|
|
ScopedValue pleft(scope, __qmljs_to_primitive(left, PREFERREDTYPE_HINT));
|
|
|
|
ScopedValue pright(scope, __qmljs_to_primitive(right, PREFERREDTYPE_HINT));
|
2013-09-04 14:05:34 +00:00
|
|
|
if (pleft->isString() || pright->isString()) {
|
|
|
|
if (!pleft->isString())
|
2012-10-17 11:38:50 +00:00
|
|
|
pleft = __qmljs_to_string(pleft, ctx);
|
2013-09-04 14:05:34 +00:00
|
|
|
if (!pright->isString())
|
2012-10-17 11:38:50 +00:00
|
|
|
pright = __qmljs_to_string(pright, ctx);
|
2013-09-13 14:19:22 +00:00
|
|
|
return __qmljs_string_concat(ctx, pleft->stringValue(), pright->stringValue())->asReturnedValue();
|
2012-06-06 08:58:49 +00:00
|
|
|
}
|
2013-04-14 20:01:20 +00:00
|
|
|
double x = __qmljs_to_number(pleft);
|
|
|
|
double y = __qmljs_to_number(pright);
|
2013-09-26 20:07:27 +00:00
|
|
|
return Encode(x + y);
|
2012-06-06 08:58:49 +00:00
|
|
|
}
|
|
|
|
|
2013-09-09 20:23:10 +00:00
|
|
|
QV4::ReturnedValue __qmljs_instanceof(ExecutionContext *ctx, const ValueRef left, const ValueRef right)
|
2012-04-16 19:23:25 +00:00
|
|
|
{
|
2013-09-09 11:38:10 +00:00
|
|
|
Object *o = right->asObject();
|
2013-02-14 08:10:30 +00:00
|
|
|
if (!o)
|
2013-10-21 07:57:58 +00:00
|
|
|
return ctx->throwTypeError();
|
2012-04-16 19:23:25 +00:00
|
|
|
|
2013-09-19 07:58:50 +00:00
|
|
|
bool r = o->hasInstance(left);
|
2013-09-26 20:07:27 +00:00
|
|
|
return Encode(r);
|
2012-04-16 19:23:25 +00:00
|
|
|
}
|
|
|
|
|
2013-09-09 20:23:10 +00:00
|
|
|
QV4::ReturnedValue __qmljs_in(ExecutionContext *ctx, const ValueRef left, const ValueRef right)
|
2012-04-16 19:23:25 +00:00
|
|
|
{
|
2013-09-09 11:38:10 +00:00
|
|
|
if (!right->isObject())
|
2013-10-21 07:57:58 +00:00
|
|
|
return ctx->throwTypeError();
|
2013-09-18 12:30:53 +00:00
|
|
|
Scope scope(ctx);
|
|
|
|
ScopedString s(scope, left->toString(ctx));
|
2013-10-21 07:57:58 +00:00
|
|
|
if (scope.hasException())
|
|
|
|
return Encode::undefined();
|
2013-09-09 11:38:10 +00:00
|
|
|
bool r = right->objectValue()->__hasProperty__(s);
|
2013-09-26 20:07:27 +00:00
|
|
|
return Encode(r);
|
2012-04-16 19:23:25 +00:00
|
|
|
}
|
|
|
|
|
2013-04-17 16:17:30 +00:00
|
|
|
double __qmljs_string_to_number(const QString &string)
|
2012-04-16 19:23:25 +00:00
|
|
|
{
|
2013-04-17 16:17:30 +00:00
|
|
|
QString s = string.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
|
|
|
}
|
|
|
|
|
2013-09-13 14:19:22 +00:00
|
|
|
Returned<String> *__qmljs_string_from_number(ExecutionContext *ctx, double number)
|
2012-04-16 19:23:25 +00:00
|
|
|
{
|
2013-04-24 12:28:52 +00:00
|
|
|
QString qstr;
|
|
|
|
__qmljs_numberToString(&qstr, number, 10);
|
2013-09-25 13:24:50 +00:00
|
|
|
return ctx->engine->newString(qstr);
|
2012-04-16 19:23:25 +00:00
|
|
|
}
|
|
|
|
|
2013-09-13 14:19:22 +00:00
|
|
|
Returned<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));
|
|
|
|
|
2013-09-25 13:24:50 +00:00
|
|
|
return ctx->engine->newString(newStr);
|
2012-04-16 19:23:25 +00:00
|
|
|
}
|
|
|
|
|
2013-09-09 12:33:28 +00:00
|
|
|
ReturnedValue __qmljs_object_default_value(Object *object, int typeHint)
|
2012-04-16 19:23:25 +00:00
|
|
|
{
|
2012-05-18 13:28:59 +00:00
|
|
|
if (typeHint == PREFERREDTYPE_HINT) {
|
2013-04-14 20:01:20 +00:00
|
|
|
if (object->asDateObject())
|
2012-05-18 13:28:59 +00:00
|
|
|
typeHint = STRING_HINT;
|
|
|
|
else
|
|
|
|
typeHint = NUMBER_HINT;
|
|
|
|
}
|
|
|
|
|
2013-04-14 20:01:20 +00:00
|
|
|
ExecutionEngine *engine = object->internalClass->engine;
|
2013-10-21 07:57:58 +00:00
|
|
|
if (engine->hasException)
|
|
|
|
return Encode::undefined();
|
|
|
|
|
2013-09-18 13:34:13 +00:00
|
|
|
SafeString *meth1 = &engine->id_toString;
|
|
|
|
SafeString *meth2 = &engine->id_valueOf;
|
2012-05-18 13:28:59 +00:00
|
|
|
|
|
|
|
if (typeHint == NUMBER_HINT)
|
|
|
|
qSwap(meth1, meth2);
|
|
|
|
|
2013-04-14 20:01:20 +00:00
|
|
|
ExecutionContext *ctx = engine->current;
|
2013-09-11 12:47:34 +00:00
|
|
|
Scope scope(ctx);
|
2013-09-11 12:36:01 +00:00
|
|
|
ScopedCallData callData(scope, 0);
|
2013-09-26 20:07:27 +00:00
|
|
|
callData->thisObject = object;
|
2012-05-25 15:45:15 +00:00
|
|
|
|
2013-09-18 13:34:13 +00:00
|
|
|
ScopedValue conv(scope, object->get(*meth1));
|
2013-09-11 12:36:01 +00:00
|
|
|
if (FunctionObject *o = conv->asFunctionObject()) {
|
2013-09-26 20:07:27 +00:00
|
|
|
ScopedValue r(scope, o->call(callData));
|
|
|
|
if (r->isPrimitive())
|
|
|
|
return r->asReturnedValue();
|
2012-05-18 13:28:59 +00:00
|
|
|
}
|
|
|
|
|
2013-10-21 07:57:58 +00:00
|
|
|
if (engine->hasException)
|
|
|
|
return Encode::undefined();
|
|
|
|
|
2013-09-18 13:34:13 +00:00
|
|
|
conv = object->get(*meth2);
|
2013-09-11 12:36:01 +00:00
|
|
|
if (FunctionObject *o = conv->asFunctionObject()) {
|
2013-09-26 20:07:27 +00:00
|
|
|
ScopedValue r(scope, o->call(callData));
|
|
|
|
if (r->isPrimitive())
|
|
|
|
return r->asReturnedValue();
|
2012-05-18 13:28:59 +00:00
|
|
|
}
|
|
|
|
|
2013-10-21 07:57:58 +00:00
|
|
|
return ctx->throwTypeError();
|
2012-04-16 19:23:25 +00:00
|
|
|
}
|
|
|
|
|
2013-09-09 11:38:10 +00:00
|
|
|
Bool __qmljs_to_boolean(const ValueRef value)
|
2013-02-14 22:16:50 +00:00
|
|
|
{
|
2013-09-09 11:38:10 +00:00
|
|
|
return value->toBoolean();
|
2013-02-14 22:16:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-13 12:11:55 +00:00
|
|
|
Returned<Object> *__qmljs_convert_to_object(ExecutionContext *ctx, const ValueRef value)
|
2012-06-07 13:28:45 +00:00
|
|
|
{
|
2013-09-09 11:38:10 +00:00
|
|
|
assert(!value->isObject());
|
|
|
|
switch (value->type()) {
|
2013-02-14 20:41:49 +00:00
|
|
|
case Value::Undefined_Type:
|
|
|
|
case Value::Null_Type:
|
2013-02-14 22:04:12 +00:00
|
|
|
ctx->throwTypeError();
|
2013-10-21 07:57:58 +00:00
|
|
|
return 0;
|
2013-02-14 20:41:49 +00:00
|
|
|
case Value::Boolean_Type:
|
2013-09-19 11:17:55 +00:00
|
|
|
return ctx->engine->newBooleanObject(value);
|
2013-09-15 13:46:36 +00:00
|
|
|
case Value::Managed_Type:
|
|
|
|
Q_ASSERT(value->isString());
|
2013-09-25 13:24:50 +00:00
|
|
|
return ctx->engine->newStringObject(value);
|
2013-02-14 20:41:49 +00:00
|
|
|
case Value::Integer_Type:
|
|
|
|
default: // double
|
2013-09-19 11:17:55 +00:00
|
|
|
return ctx->engine->newNumberObject(value);
|
2013-02-14 20:41:49 +00:00
|
|
|
}
|
2012-04-16 19:23:25 +00:00
|
|
|
}
|
|
|
|
|
2013-09-13 14:19:22 +00:00
|
|
|
Returned<String> *__qmljs_convert_to_string(ExecutionContext *ctx, const ValueRef value)
|
2013-02-14 22:00:11 +00:00
|
|
|
{
|
2013-09-09 11:38:10 +00:00
|
|
|
switch (value->type()) {
|
2013-09-16 13:27:16 +00:00
|
|
|
case Value::Empty_Type:
|
2013-09-17 16:16:35 +00:00
|
|
|
Q_ASSERT(!"empty Value encountered");
|
|
|
|
case Value::Undefined_Type:
|
2013-10-01 14:11:55 +00:00
|
|
|
return ctx->engine->id_undefined.ret();
|
2013-02-14 22:00:11 +00:00
|
|
|
case Value::Null_Type:
|
2013-10-01 14:11:55 +00:00
|
|
|
return ctx->engine->id_null.ret();
|
2013-02-14 22:00:11 +00:00
|
|
|
case Value::Boolean_Type:
|
2013-09-09 11:38:10 +00:00
|
|
|
if (value->booleanValue())
|
2013-10-01 14:11:55 +00:00
|
|
|
return ctx->engine->id_true.ret();
|
2013-02-14 22:00:11 +00:00
|
|
|
else
|
2013-10-01 14:11:55 +00:00
|
|
|
return ctx->engine->id_false.ret();
|
2013-09-15 13:46:36 +00:00
|
|
|
case Value::Managed_Type:
|
|
|
|
if (value->isString())
|
|
|
|
return value->stringValue()->asReturned<String>();
|
|
|
|
{
|
|
|
|
Scope scope(ctx);
|
|
|
|
ScopedValue prim(scope, __qmljs_to_primitive(value, STRING_HINT));
|
|
|
|
return __qmljs_convert_to_string(ctx, prim);
|
|
|
|
}
|
2013-09-13 14:19:22 +00:00
|
|
|
case Value::Integer_Type:
|
|
|
|
return __qmljs_string_from_number(ctx, value->int_32);
|
|
|
|
default: // double
|
|
|
|
return __qmljs_string_from_number(ctx, value->doubleValue());
|
2013-02-14 22:00:11 +00:00
|
|
|
} // switch
|
|
|
|
}
|
2012-04-16 19:23:25 +00:00
|
|
|
|
2013-09-19 10:05:18 +00:00
|
|
|
void __qmljs_set_property(ExecutionContext *ctx, const ValueRef object, const StringRef name, const ValueRef value)
|
2012-04-16 19:23:25 +00:00
|
|
|
{
|
2013-09-18 14:36:02 +00:00
|
|
|
Scope scope(ctx);
|
|
|
|
ScopedObject o(scope, object->toObject(ctx));
|
2013-09-19 10:05:18 +00:00
|
|
|
o->put(name, value);
|
2012-04-16 19:23:25 +00:00
|
|
|
}
|
|
|
|
|
2013-09-09 19:17:01 +00:00
|
|
|
ReturnedValue __qmljs_get_element(ExecutionContext *ctx, const ValueRef object, const ValueRef index)
|
2012-05-20 17:59:47 +00:00
|
|
|
{
|
2013-09-13 12:11:55 +00:00
|
|
|
Scope scope(ctx);
|
2013-09-09 11:38:10 +00:00
|
|
|
uint idx = index->asArrayIndex();
|
2013-01-16 23:45:11 +00:00
|
|
|
|
2013-09-13 12:11:55 +00:00
|
|
|
Scoped<Object> o(scope, object);
|
2013-02-14 19:58:10 +00:00
|
|
|
if (!o) {
|
2013-02-16 22:27:07 +00:00
|
|
|
if (idx < UINT_MAX) {
|
2013-09-09 11:38:10 +00:00
|
|
|
if (String *str = object->asString()) {
|
2013-02-16 22:27:07 +00:00
|
|
|
if (idx >= (uint)str->toQString().length()) {
|
2013-09-26 20:07:27 +00:00
|
|
|
return Encode::undefined();
|
2013-02-16 22:27:07 +00:00
|
|
|
}
|
|
|
|
const QString s = str->toQString().mid(idx, 1);
|
2013-09-26 10:04:52 +00:00
|
|
|
return scope.engine->newString(s)->asReturnedValue();
|
2013-02-14 19:58:10 +00:00
|
|
|
}
|
2013-01-18 12:48:03 +00:00
|
|
|
}
|
2012-10-18 12:39:59 +00:00
|
|
|
|
2013-09-09 11:38:10 +00:00
|
|
|
if (object->isNullOrUndefined()) {
|
2013-09-09 12:33:28 +00:00
|
|
|
QString message = QStringLiteral("Cannot read property '%1' of %2").arg(index->toQStringNoThrow()).arg(object->toQStringNoThrow());
|
2013-10-21 07:57:58 +00:00
|
|
|
return ctx->throwTypeError(message);
|
2013-06-05 07:59:18 +00:00
|
|
|
}
|
|
|
|
|
2013-02-14 20:41:49 +00:00
|
|
|
o = __qmljs_convert_to_object(ctx, object);
|
2013-10-21 07:57:58 +00:00
|
|
|
if (!o) // type error
|
|
|
|
return Encode::undefined();
|
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-04-10 08:46:23 +00:00
|
|
|
uint pidx = o->propertyIndexFromArrayIndex(idx);
|
|
|
|
if (pidx < UINT_MAX) {
|
|
|
|
if (!o->arrayAttributes || o->arrayAttributes[pidx].isData()) {
|
2013-10-13 20:08:59 +00:00
|
|
|
if (!o->arrayData[pidx].value.isEmpty())
|
|
|
|
return o->arrayData[pidx].value.asReturnedValue();
|
2013-04-10 08:46:23 +00:00
|
|
|
}
|
2013-02-14 19:58:10 +00:00
|
|
|
}
|
2013-01-18 12:48:03 +00:00
|
|
|
|
2013-09-11 19:48:23 +00:00
|
|
|
return o->getIndexed(idx);
|
2013-01-18 12:48:03 +00:00
|
|
|
}
|
2013-01-11 09:13:02 +00:00
|
|
|
|
2013-09-18 13:34:13 +00:00
|
|
|
ScopedString name(scope, index->toString(ctx));
|
2013-10-21 07:57:58 +00:00
|
|
|
if (scope.hasException())
|
|
|
|
return Encode::undefined();
|
2013-09-11 14:28:17 +00:00
|
|
|
return o->get(name);
|
2012-05-20 17:59:47 +00:00
|
|
|
}
|
|
|
|
|
2013-09-09 11:38:10 +00:00
|
|
|
void __qmljs_set_element(ExecutionContext *ctx, const ValueRef object, const ValueRef index, const ValueRef value)
|
2012-05-20 17:59:47 +00:00
|
|
|
{
|
2013-09-11 12:47:34 +00:00
|
|
|
Scope scope(ctx);
|
2013-09-18 14:36:02 +00:00
|
|
|
ScopedObject o(scope, object->toObject(ctx));
|
2013-10-21 07:57:58 +00:00
|
|
|
if (scope.engine->hasException)
|
|
|
|
return;
|
2013-01-11 09:13:02 +00:00
|
|
|
|
2013-09-09 11:38:10 +00:00
|
|
|
uint idx = index->asArrayIndex();
|
2013-01-11 09:13:02 +00:00
|
|
|
if (idx < UINT_MAX) {
|
2013-04-10 08:46:23 +00:00
|
|
|
uint pidx = o->propertyIndexFromArrayIndex(idx);
|
|
|
|
if (pidx < UINT_MAX) {
|
|
|
|
if (o->arrayAttributes && !o->arrayAttributes[pidx].isEmpty() && !o->arrayAttributes[pidx].isWritable()) {
|
|
|
|
if (ctx->strictMode)
|
|
|
|
ctx->throwTypeError();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Property *p = o->arrayData + pidx;
|
|
|
|
if (!o->arrayAttributes || o->arrayAttributes[pidx].isData()) {
|
2013-09-09 11:38:10 +00:00
|
|
|
p->value = *value;
|
2013-04-10 08:46:23 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (o->arrayAttributes[pidx].isAccessor()) {
|
|
|
|
FunctionObject *setter = p->setter();
|
|
|
|
if (!setter) {
|
|
|
|
if (ctx->strictMode)
|
|
|
|
ctx->throwTypeError();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-09-11 12:36:01 +00:00
|
|
|
ScopedCallData callData(scope, 1);
|
2013-09-18 14:36:02 +00:00
|
|
|
callData->thisObject = o;
|
2013-09-09 11:38:10 +00:00
|
|
|
callData->args[0] = *value;
|
2013-09-05 11:22:23 +00:00
|
|
|
setter->call(callData);
|
2013-04-10 08:46:23 +00:00
|
|
|
return;
|
|
|
|
}
|
2013-01-18 12:48:03 +00:00
|
|
|
}
|
2013-09-19 07:10:42 +00:00
|
|
|
o->putIndexed(idx, value);
|
2013-01-11 09:13:02 +00:00
|
|
|
return;
|
2012-10-18 12:39:59 +00:00
|
|
|
}
|
2012-05-20 17:59:47 +00:00
|
|
|
|
2013-09-18 14:36:02 +00:00
|
|
|
ScopedString name(scope, index->toString(ctx));
|
|
|
|
o->put(name, value);
|
2012-05-20 17:59:47 +00:00
|
|
|
}
|
|
|
|
|
2013-09-09 19:17:01 +00:00
|
|
|
ReturnedValue __qmljs_foreach_iterator_object(ExecutionContext *ctx, const ValueRef in)
|
2012-10-28 15:24:06 +00:00
|
|
|
{
|
2013-09-14 09:25:02 +00:00
|
|
|
Scope scope(ctx);
|
|
|
|
Scoped<Object> o(scope, (Object *)0);
|
2013-09-09 11:38:10 +00:00
|
|
|
if (!in->isNullOrUndefined())
|
2013-09-14 09:25:02 +00:00
|
|
|
o = in;
|
2013-09-30 11:48:05 +00:00
|
|
|
Scoped<Object> it(scope, ctx->engine->newForEachIteratorObject(ctx, o));
|
2013-09-14 09:25:02 +00:00
|
|
|
return it.asReturnedValue();
|
2012-10-28 15:24:06 +00:00
|
|
|
}
|
|
|
|
|
2013-09-09 19:17:01 +00:00
|
|
|
ReturnedValue __qmljs_foreach_next_property_name(const ValueRef foreach_iterator)
|
2012-10-28 15:24:06 +00:00
|
|
|
{
|
2013-09-09 19:17:01 +00:00
|
|
|
Q_ASSERT(foreach_iterator->isObject());
|
2012-10-28 15:24:06 +00:00
|
|
|
|
2013-09-09 11:38:10 +00:00
|
|
|
ForEachIteratorObject *it = static_cast<ForEachIteratorObject *>(foreach_iterator->objectValue());
|
2013-09-09 19:17:01 +00:00
|
|
|
Q_ASSERT(it->as<ForEachIteratorObject>());
|
2012-10-28 15:24:06 +00:00
|
|
|
|
2013-09-12 20:37:41 +00:00
|
|
|
return it->nextPropertyName();
|
2012-10-28 15:24:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-19 10:05:18 +00:00
|
|
|
void __qmljs_set_activation_property(ExecutionContext *ctx, const StringRef name, const ValueRef value)
|
2012-04-16 19:23:25 +00:00
|
|
|
{
|
2013-09-18 14:36:02 +00:00
|
|
|
ctx->setProperty(name, value);
|
2012-04-16 19:23:25 +00:00
|
|
|
}
|
|
|
|
|
2013-09-19 10:05:18 +00:00
|
|
|
ReturnedValue __qmljs_get_property(ExecutionContext *ctx, const ValueRef object, const StringRef name)
|
2012-04-16 19:23:25 +00:00
|
|
|
{
|
2013-09-13 12:11:55 +00:00
|
|
|
Scope scope(ctx);
|
|
|
|
|
|
|
|
Scoped<Object> o(scope, object);
|
|
|
|
if (o)
|
|
|
|
return o->get(name);
|
2013-06-05 07:59:18 +00:00
|
|
|
|
2013-09-09 19:17:01 +00:00
|
|
|
if (object->isNullOrUndefined()) {
|
|
|
|
QString message = QStringLiteral("Cannot read property '%1' of %2").arg(name->toQString()).arg(object->toQStringNoThrow());
|
2013-10-21 07:57:58 +00:00
|
|
|
return ctx->throwTypeError(message);
|
2012-05-09 09:04:57 +00:00
|
|
|
}
|
2013-09-09 19:17:01 +00:00
|
|
|
|
2013-09-13 12:11:55 +00:00
|
|
|
o = __qmljs_convert_to_object(ctx, object);
|
2013-10-21 07:57:58 +00:00
|
|
|
if (!o) // type error
|
|
|
|
return Encode::undefined();
|
2013-09-13 12:11:55 +00:00
|
|
|
return o->get(name);
|
2012-04-16 19:23:25 +00:00
|
|
|
}
|
|
|
|
|
2013-09-19 10:05:18 +00:00
|
|
|
ReturnedValue __qmljs_get_activation_property(ExecutionContext *ctx, const StringRef name)
|
2012-04-16 19:23:25 +00:00
|
|
|
{
|
2013-09-11 11:10:42 +00:00
|
|
|
return ctx->getProperty(name);
|
2012-04-16 19:23:25 +00:00
|
|
|
}
|
|
|
|
|
2013-09-09 11:38:10 +00:00
|
|
|
uint __qmljs_equal_helper(const ValueRef x, const ValueRef y)
|
2013-08-06 20:55:09 +00:00
|
|
|
{
|
2013-09-15 13:46:36 +00:00
|
|
|
Q_ASSERT(x->type() != y->type() || (x->isManaged() && (x->isString() != y->isString())));
|
2013-08-06 20:55:09 +00:00
|
|
|
|
2013-09-09 11:38:10 +00:00
|
|
|
if (x->isNumber() && y->isNumber())
|
|
|
|
return x->asDouble() == y->asDouble();
|
|
|
|
if (x->isNull() && y->isUndefined()) {
|
2013-08-06 20:55:09 +00:00
|
|
|
return true;
|
2013-09-09 11:38:10 +00:00
|
|
|
} else if (x->isUndefined() && y->isNull()) {
|
2013-08-06 20:55:09 +00:00
|
|
|
return true;
|
2013-09-09 11:38:10 +00:00
|
|
|
} else if (x->isNumber() && y->isString()) {
|
2013-08-06 20:55:09 +00:00
|
|
|
double dy = __qmljs_to_number(y);
|
2013-09-09 11:38:10 +00:00
|
|
|
return x->asDouble() == dy;
|
|
|
|
} else if (x->isString() && y->isNumber()) {
|
2013-08-06 20:55:09 +00:00
|
|
|
double dx = __qmljs_to_number(x);
|
2013-09-09 11:38:10 +00:00
|
|
|
return dx == y->asDouble();
|
|
|
|
} else if (x->isBoolean()) {
|
2013-09-26 20:07:27 +00:00
|
|
|
return __qmljs_cmp_eq(Primitive::fromDouble((double) x->booleanValue()), y);
|
2013-09-09 11:38:10 +00:00
|
|
|
} else if (y->isBoolean()) {
|
2013-09-26 20:07:27 +00:00
|
|
|
return __qmljs_cmp_eq(x, Primitive::fromDouble((double) y->booleanValue()));
|
2013-09-09 11:38:10 +00:00
|
|
|
} else if ((x->isNumber() || x->isString()) && y->isObject()) {
|
2013-09-11 12:47:34 +00:00
|
|
|
Scope scope(y->objectValue()->engine());
|
2013-09-09 12:33:28 +00:00
|
|
|
ScopedValue py(scope, __qmljs_to_primitive(y, PREFERREDTYPE_HINT));
|
|
|
|
return __qmljs_cmp_eq(x, py);
|
2013-09-09 11:38:10 +00:00
|
|
|
} else if (x->isObject() && (y->isNumber() || y->isString())) {
|
2013-09-11 12:47:34 +00:00
|
|
|
Scope scope(x->objectValue()->engine());
|
2013-09-09 12:33:28 +00:00
|
|
|
ScopedValue px(scope, __qmljs_to_primitive(x, PREFERREDTYPE_HINT));
|
|
|
|
return __qmljs_cmp_eq(px, y);
|
2012-04-16 19:23:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-09-09 11:38:10 +00:00
|
|
|
Bool __qmljs_strict_equal(const ValueRef x, const ValueRef y)
|
2013-03-06 13:01:07 +00:00
|
|
|
{
|
|
|
|
TRACE2(x, y);
|
|
|
|
|
2013-09-09 11:38:10 +00:00
|
|
|
if (x->rawValue() == y->rawValue())
|
2013-08-05 20:48:35 +00:00
|
|
|
// NaN != NaN
|
2013-09-15 13:46:36 +00:00
|
|
|
return !x->isNaN();
|
2013-08-05 20:48:35 +00:00
|
|
|
|
2013-09-09 11:38:10 +00:00
|
|
|
if (x->isNumber())
|
|
|
|
return y->isNumber() && x->asDouble() == y->asDouble();
|
|
|
|
if (x->isString())
|
|
|
|
return y->isString() && x->stringValue()->isEqualTo(y->stringValue());
|
2013-03-06 13:01:07 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-09-09 12:33:28 +00:00
|
|
|
QV4::Bool __qmljs_cmp_gt(const QV4::ValueRef l, const QV4::ValueRef r)
|
|
|
|
{
|
|
|
|
TRACE2(l, r);
|
|
|
|
if (QV4::Value::integerCompatible(*l, *r))
|
|
|
|
return l->integerValue() > r->integerValue();
|
|
|
|
if (QV4::Value::bothDouble(*l, *r))
|
|
|
|
return l->doubleValue() > r->doubleValue();
|
|
|
|
if (l->isString() && r->isString())
|
|
|
|
return r->stringValue()->compare(l->stringValue());
|
|
|
|
|
|
|
|
if (l->isObject() || r->isObject()) {
|
|
|
|
QV4::ExecutionEngine *e = (l->isObject() ? l->objectValue() : r->objectValue())->engine();
|
2013-09-11 12:47:34 +00:00
|
|
|
QV4::Scope scope(e);
|
2013-09-09 12:33:28 +00:00
|
|
|
QV4::ScopedValue pl(scope, __qmljs_to_primitive(l, QV4::NUMBER_HINT));
|
|
|
|
QV4::ScopedValue pr(scope, __qmljs_to_primitive(r, QV4::NUMBER_HINT));
|
|
|
|
return __qmljs_cmp_gt(pl, pr);
|
|
|
|
}
|
|
|
|
|
|
|
|
double dl = __qmljs_to_number(l);
|
|
|
|
double dr = __qmljs_to_number(r);
|
|
|
|
return dl > dr;
|
|
|
|
}
|
|
|
|
|
|
|
|
QV4::Bool __qmljs_cmp_lt(const QV4::ValueRef l, const QV4::ValueRef r)
|
|
|
|
{
|
|
|
|
TRACE2(l, r);
|
|
|
|
if (QV4::Value::integerCompatible(*l, *r))
|
|
|
|
return l->integerValue() < r->integerValue();
|
|
|
|
if (QV4::Value::bothDouble(*l, *r))
|
|
|
|
return l->doubleValue() < r->doubleValue();
|
|
|
|
if (l->isString() && r->isString())
|
|
|
|
return l->stringValue()->compare(r->stringValue());
|
|
|
|
|
|
|
|
if (l->isObject() || r->isObject()) {
|
|
|
|
QV4::ExecutionEngine *e = (l->isObject() ? l->objectValue() : r->objectValue())->engine();
|
2013-09-11 12:47:34 +00:00
|
|
|
QV4::Scope scope(e);
|
2013-09-09 12:33:28 +00:00
|
|
|
QV4::ScopedValue pl(scope, __qmljs_to_primitive(l, QV4::NUMBER_HINT));
|
|
|
|
QV4::ScopedValue pr(scope, __qmljs_to_primitive(r, QV4::NUMBER_HINT));
|
|
|
|
return __qmljs_cmp_lt(pl, pr);
|
|
|
|
}
|
|
|
|
|
|
|
|
double dl = __qmljs_to_number(l);
|
|
|
|
double dr = __qmljs_to_number(r);
|
|
|
|
return dl < dr;
|
|
|
|
}
|
|
|
|
|
|
|
|
QV4::Bool __qmljs_cmp_ge(const QV4::ValueRef l, const QV4::ValueRef r)
|
|
|
|
{
|
|
|
|
TRACE2(l, r);
|
|
|
|
if (QV4::Value::integerCompatible(*l, *r))
|
|
|
|
return l->integerValue() >= r->integerValue();
|
|
|
|
if (QV4::Value::bothDouble(*l, *r))
|
|
|
|
return l->doubleValue() >= r->doubleValue();
|
|
|
|
if (l->isString() && r->isString())
|
|
|
|
return !l->stringValue()->compare(r->stringValue());
|
|
|
|
|
|
|
|
if (l->isObject() || r->isObject()) {
|
|
|
|
QV4::ExecutionEngine *e = (l->isObject() ? l->objectValue() : r->objectValue())->engine();
|
2013-09-11 12:47:34 +00:00
|
|
|
QV4::Scope scope(e);
|
2013-09-09 12:33:28 +00:00
|
|
|
QV4::ScopedValue pl(scope, __qmljs_to_primitive(l, QV4::NUMBER_HINT));
|
|
|
|
QV4::ScopedValue pr(scope, __qmljs_to_primitive(r, QV4::NUMBER_HINT));
|
|
|
|
return __qmljs_cmp_ge(pl, pr);
|
|
|
|
}
|
|
|
|
|
|
|
|
double dl = __qmljs_to_number(l);
|
|
|
|
double dr = __qmljs_to_number(r);
|
|
|
|
return dl >= dr;
|
|
|
|
}
|
|
|
|
|
|
|
|
QV4::Bool __qmljs_cmp_le(const QV4::ValueRef l, const QV4::ValueRef r)
|
|
|
|
{
|
|
|
|
TRACE2(l, r);
|
|
|
|
if (QV4::Value::integerCompatible(*l, *r))
|
|
|
|
return l->integerValue() <= r->integerValue();
|
|
|
|
if (QV4::Value::bothDouble(*l, *r))
|
|
|
|
return l->doubleValue() <= r->doubleValue();
|
|
|
|
if (l->isString() && r->isString())
|
|
|
|
return !r->stringValue()->compare(l->stringValue());
|
|
|
|
|
|
|
|
if (l->isObject() || r->isObject()) {
|
|
|
|
QV4::ExecutionEngine *e = (l->isObject() ? l->objectValue() : r->objectValue())->engine();
|
2013-09-11 12:47:34 +00:00
|
|
|
QV4::Scope scope(e);
|
2013-09-09 12:33:28 +00:00
|
|
|
QV4::ScopedValue pl(scope, __qmljs_to_primitive(l, QV4::NUMBER_HINT));
|
|
|
|
QV4::ScopedValue pr(scope, __qmljs_to_primitive(r, QV4::NUMBER_HINT));
|
|
|
|
return __qmljs_cmp_le(pl, pr);
|
|
|
|
}
|
|
|
|
|
|
|
|
double dl = __qmljs_to_number(l);
|
|
|
|
double dr = __qmljs_to_number(r);
|
|
|
|
return dl <= dr;
|
|
|
|
}
|
|
|
|
|
2013-04-14 10:17:11 +00:00
|
|
|
|
2013-09-09 13:10:03 +00:00
|
|
|
ReturnedValue __qmljs_call_global_lookup(ExecutionContext *context, uint index, CallDataRef callData)
|
2013-04-14 10:17:11 +00:00
|
|
|
{
|
2013-09-11 20:45:47 +00:00
|
|
|
Scope scope(context);
|
2013-09-05 12:49:55 +00:00
|
|
|
Q_ASSERT(callData->thisObject.isUndefined());
|
|
|
|
|
2013-04-14 10:17:11 +00:00
|
|
|
Lookup *l = context->lookups + index;
|
2013-09-11 20:45:47 +00:00
|
|
|
Scoped<FunctionObject> o(scope, l->globalGetter(l, context));
|
2013-04-14 10:17:11 +00:00
|
|
|
if (!o)
|
2013-10-21 07:57:58 +00:00
|
|
|
return context->throwTypeError();
|
2013-04-14 10:17:11 +00:00
|
|
|
|
2013-10-01 14:11:55 +00:00
|
|
|
if (o.getPointer() == context->engine->evalFunction && l->name->equals(context->engine->id_eval))
|
2013-09-26 10:08:03 +00:00
|
|
|
return static_cast<EvalFunction *>(o.getPointer())->evalCall(callData, true);
|
2013-04-14 10:17:11 +00:00
|
|
|
|
2013-09-11 11:55:01 +00:00
|
|
|
return o->call(callData);
|
2013-04-14 10:17:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-19 10:05:18 +00:00
|
|
|
ReturnedValue __qmljs_call_activation_property(ExecutionContext *context, const StringRef name, CallDataRef callData)
|
2012-04-16 19:23:25 +00:00
|
|
|
{
|
2013-09-05 12:49:55 +00:00
|
|
|
Q_ASSERT(callData->thisObject.isUndefined());
|
2013-09-11 12:47:34 +00:00
|
|
|
Scope scope(context);
|
2013-09-05 12:49:55 +00:00
|
|
|
|
2013-09-27 15:04:42 +00:00
|
|
|
ScopedObject base(scope);
|
|
|
|
ScopedValue func(scope, context->getPropertyAndBase(name, base));
|
2013-10-18 13:42:17 +00:00
|
|
|
if (context->engine->hasException)
|
|
|
|
return Encode::undefined();
|
|
|
|
|
2013-09-05 12:49:55 +00:00
|
|
|
if (base)
|
2013-09-26 20:07:27 +00:00
|
|
|
callData->thisObject = base;
|
2013-09-05 12:49:55 +00:00
|
|
|
|
2013-09-11 11:10:42 +00:00
|
|
|
FunctionObject *o = func->asFunctionObject();
|
2013-06-03 11:27:38 +00:00
|
|
|
if (!o) {
|
|
|
|
QString objectAsString = QStringLiteral("[null]");
|
2013-09-27 15:04:42 +00:00
|
|
|
if (base)
|
|
|
|
objectAsString = ScopedValue(scope, base.asReturnedValue())->toQStringNoThrow();
|
2013-06-03 11:27:38 +00:00
|
|
|
QString msg = QStringLiteral("Property '%1' of object %2 is not a function").arg(name->toQString()).arg(objectAsString);
|
2013-10-21 07:57:58 +00:00
|
|
|
return context->throwTypeError(msg);
|
2013-06-03 11:27:38 +00:00
|
|
|
}
|
2012-12-01 19:08:26 +00:00
|
|
|
|
2013-10-01 14:11:55 +00:00
|
|
|
if (o == context->engine->evalFunction && name->equals(context->engine->id_eval)) {
|
2013-09-26 10:08:03 +00:00
|
|
|
return static_cast<EvalFunction *>(o)->evalCall(callData, true);
|
2013-02-13 13:15:08 +00:00
|
|
|
}
|
2013-01-23 09:07:18 +00:00
|
|
|
|
2013-09-11 11:55:01 +00:00
|
|
|
return o->call(callData);
|
2012-05-09 10:00:30 +00:00
|
|
|
}
|
|
|
|
|
2013-09-19 10:05:18 +00:00
|
|
|
ReturnedValue __qmljs_call_property(ExecutionContext *context, const StringRef name, CallDataRef callData)
|
2012-05-07 14:05:05 +00:00
|
|
|
{
|
2013-09-11 14:28:17 +00:00
|
|
|
Scope scope(context);
|
2013-09-13 12:11:55 +00:00
|
|
|
Scoped<Object> baseObject(scope, callData->thisObject);
|
2013-03-07 12:41:21 +00:00
|
|
|
if (!baseObject) {
|
2013-09-17 16:16:35 +00:00
|
|
|
Q_ASSERT(!callData->thisObject.isEmpty());
|
|
|
|
if (callData->thisObject.isNullOrUndefined()) {
|
2013-09-09 12:33:28 +00:00
|
|
|
QString message = QStringLiteral("Cannot call method '%1' of %2").arg(name->toQString()).arg(callData->thisObject.toQStringNoThrow());
|
2013-10-21 07:57:58 +00:00
|
|
|
return context->throwTypeError(message);
|
2013-06-23 13:08:13 +00:00
|
|
|
}
|
|
|
|
|
2013-09-09 11:38:10 +00:00
|
|
|
baseObject = __qmljs_convert_to_object(context, ValueRef(&callData->thisObject));
|
2013-10-21 07:57:58 +00:00
|
|
|
if (!baseObject) // type error
|
|
|
|
return Encode::undefined();
|
2013-09-30 20:41:12 +00:00
|
|
|
callData->thisObject = baseObject.asReturnedValue();
|
2013-01-29 21:07:48 +00:00
|
|
|
}
|
2012-05-09 13:47:55 +00:00
|
|
|
|
2013-09-11 14:28:17 +00:00
|
|
|
Scoped<FunctionObject> o(scope, baseObject->get(name));
|
2013-06-05 23:38:16 +00:00
|
|
|
if (!o) {
|
2013-09-09 12:33:28 +00:00
|
|
|
QString error = QString("Property '%1' of object %2 is not a function").arg(name->toQString(), callData->thisObject.toQStringNoThrow());
|
2013-10-21 07:57:58 +00:00
|
|
|
return context->throwTypeError(error);
|
2013-06-05 23:38:16 +00:00
|
|
|
}
|
2012-12-01 19:08:26 +00:00
|
|
|
|
2013-09-11 11:55:01 +00:00
|
|
|
return o->call(callData);
|
2012-10-18 12:39:59 +00:00
|
|
|
}
|
|
|
|
|
2013-09-09 13:10:03 +00:00
|
|
|
ReturnedValue __qmljs_call_property_lookup(ExecutionContext *context, uint index, CallDataRef callData)
|
2013-02-12 15:23:52 +00:00
|
|
|
{
|
2013-09-11 20:45:47 +00:00
|
|
|
Scope scope(context);
|
2013-02-12 15:23:52 +00:00
|
|
|
|
2013-08-30 12:39:40 +00:00
|
|
|
Lookup *l = context->lookups + index;
|
2013-09-11 20:45:47 +00:00
|
|
|
Scoped<Object> o(scope, l->getter(l, callData->thisObject));
|
2013-02-12 15:23:52 +00:00
|
|
|
if (!o)
|
2013-10-21 07:57:58 +00:00
|
|
|
return context->throwTypeError();
|
2013-02-12 15:23:52 +00:00
|
|
|
|
2013-09-11 11:55:01 +00:00
|
|
|
return o->call(callData);
|
2013-02-12 15:23:52 +00:00
|
|
|
}
|
|
|
|
|
2013-09-09 13:10:03 +00:00
|
|
|
ReturnedValue __qmljs_call_element(ExecutionContext *context, const ValueRef index, CallDataRef callData)
|
2013-01-27 21:39:01 +00:00
|
|
|
{
|
2013-09-11 14:28:17 +00:00
|
|
|
Scope scope(context);
|
2013-09-26 20:07:27 +00:00
|
|
|
ScopedObject baseObject(scope, callData->thisObject.toObject(context));
|
2013-10-21 07:57:58 +00:00
|
|
|
ScopedString s(scope, index->toString(context));
|
|
|
|
|
|
|
|
if (scope.engine->hasException)
|
|
|
|
return Encode::undefined();
|
2013-09-26 20:07:27 +00:00
|
|
|
callData->thisObject = baseObject;
|
2013-01-27 21:39:01 +00:00
|
|
|
|
2013-09-26 20:07:27 +00:00
|
|
|
ScopedObject o(scope, baseObject->get(s));
|
2013-01-27 21:39:01 +00:00
|
|
|
if (!o)
|
2013-10-21 07:57:58 +00:00
|
|
|
return context->throwTypeError();
|
2013-01-27 21:39:01 +00:00
|
|
|
|
2013-09-11 11:55:01 +00:00
|
|
|
return o->call(callData);
|
2013-01-27 21:39:01 +00:00
|
|
|
}
|
|
|
|
|
2013-09-09 13:10:03 +00:00
|
|
|
ReturnedValue __qmljs_call_value(ExecutionContext *context, const ValueRef func, CallDataRef callData)
|
2012-05-09 13:47:55 +00:00
|
|
|
{
|
2013-09-09 09:07:21 +00:00
|
|
|
Object *o = func->asObject();
|
2012-12-01 19:08:26 +00:00
|
|
|
if (!o)
|
2013-10-21 07:57:58 +00:00
|
|
|
return context->throwTypeError();
|
2013-09-05 11:22:23 +00:00
|
|
|
|
2013-09-11 11:55:01 +00:00
|
|
|
return o->call(callData);
|
2012-05-09 09:04:57 +00:00
|
|
|
}
|
|
|
|
|
2013-04-14 21:08:01 +00:00
|
|
|
|
2013-09-09 19:17:01 +00:00
|
|
|
ReturnedValue __qmljs_construct_global_lookup(ExecutionContext *context, uint index, CallDataRef callData)
|
2013-04-14 21:08:01 +00:00
|
|
|
{
|
2013-09-11 20:45:47 +00:00
|
|
|
Scope scope(context);
|
2013-09-05 12:49:55 +00:00
|
|
|
Q_ASSERT(callData->thisObject.isUndefined());
|
|
|
|
|
2013-08-30 12:39:40 +00:00
|
|
|
Lookup *l = context->lookups + index;
|
2013-09-11 20:45:47 +00:00
|
|
|
Scoped<Object> f(scope, l->globalGetter(l, context));
|
2013-08-30 12:39:40 +00:00
|
|
|
if (!f)
|
2013-10-21 07:57:58 +00:00
|
|
|
return context->throwTypeError();
|
2013-04-14 21:08:01 +00:00
|
|
|
|
2013-09-11 13:09:25 +00:00
|
|
|
return f->construct(callData);
|
2013-04-14 21:08:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-19 10:05:18 +00:00
|
|
|
ReturnedValue __qmljs_construct_activation_property(ExecutionContext *context, const StringRef name, CallDataRef callData)
|
2012-05-09 13:06:30 +00:00
|
|
|
{
|
2013-09-11 12:47:34 +00:00
|
|
|
Scope scope(context);
|
2013-09-11 11:10:42 +00:00
|
|
|
ScopedValue func(scope, context->getProperty(name));
|
2013-10-18 13:42:17 +00:00
|
|
|
if (context->engine->hasException)
|
|
|
|
return Encode::undefined();
|
|
|
|
|
2013-09-11 11:10:42 +00:00
|
|
|
Object *f = func->asObject();
|
2013-09-05 12:49:55 +00:00
|
|
|
if (!f)
|
2013-10-21 07:57:58 +00:00
|
|
|
return context->throwTypeError();
|
2013-09-05 12:49:55 +00:00
|
|
|
|
2013-09-11 13:09:25 +00:00
|
|
|
return f->construct(callData);
|
2012-05-13 11:50:55 +00:00
|
|
|
}
|
|
|
|
|
2013-09-09 18:32:01 +00:00
|
|
|
ReturnedValue __qmljs_construct_value(ExecutionContext *context, const ValueRef func, CallDataRef callData)
|
2012-05-13 11:50:55 +00:00
|
|
|
{
|
2013-09-09 09:07:21 +00:00
|
|
|
Object *f = func->asObject();
|
2013-09-05 12:49:55 +00:00
|
|
|
if (!f)
|
2013-10-21 07:57:58 +00:00
|
|
|
return context->throwTypeError();
|
2012-11-10 11:45:00 +00:00
|
|
|
|
2013-09-11 13:09:25 +00:00
|
|
|
return f->construct(callData);
|
2012-05-09 13:06:30 +00:00
|
|
|
}
|
|
|
|
|
2013-09-19 10:05:18 +00:00
|
|
|
ReturnedValue __qmljs_construct_property(ExecutionContext *context, const ValueRef base, const StringRef name, CallDataRef callData)
|
2012-05-09 09:04:57 +00:00
|
|
|
{
|
2013-09-11 14:28:17 +00:00
|
|
|
Scope scope(context);
|
2013-09-18 13:34:13 +00:00
|
|
|
ScopedObject thisObject(scope, base->toObject(context));
|
2013-10-21 07:57:58 +00:00
|
|
|
if (scope.engine->hasException)
|
|
|
|
return Encode::undefined();
|
2012-05-09 13:06:30 +00:00
|
|
|
|
2013-09-11 14:28:17 +00:00
|
|
|
Scoped<Object> f(scope, thisObject->get(name));
|
2013-09-05 12:49:55 +00:00
|
|
|
if (!f)
|
2013-10-21 07:57:58 +00:00
|
|
|
return context->throwTypeError();
|
2012-11-10 11:45:00 +00:00
|
|
|
|
2013-09-11 13:09:25 +00:00
|
|
|
return f->construct(callData);
|
2012-05-07 14:05:05 +00:00
|
|
|
}
|
2012-04-16 19:23:25 +00:00
|
|
|
|
2013-09-09 11:38:10 +00:00
|
|
|
void __qmljs_throw(ExecutionContext *context, const ValueRef value)
|
2012-06-06 13:30:50 +00:00
|
|
|
{
|
2013-10-21 15:07:45 +00:00
|
|
|
if (!value->isEmpty())
|
|
|
|
context->throwError(value);
|
2012-06-06 13:30:50 +00:00
|
|
|
}
|
|
|
|
|
2013-09-09 18:32:01 +00:00
|
|
|
ReturnedValue __qmljs_builtin_typeof(ExecutionContext *ctx, const ValueRef value)
|
2012-12-08 04:31:19 +00:00
|
|
|
{
|
2013-09-25 13:24:50 +00:00
|
|
|
Scope scope(ctx);
|
|
|
|
ScopedString res(scope);
|
2013-09-09 09:07:21 +00:00
|
|
|
switch (value->type()) {
|
2012-12-08 04:31:19 +00:00
|
|
|
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;
|
2013-09-15 13:46:36 +00:00
|
|
|
case Value::Managed_Type:
|
|
|
|
if (value->isString())
|
|
|
|
res = ctx->engine->id_string;
|
|
|
|
else if (value->objectValue()->asFunctionObject())
|
2013-02-14 22:00:11 +00:00
|
|
|
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-09-25 13:24:50 +00:00
|
|
|
return res.asReturnedValue();
|
2012-12-08 04:31:19 +00:00
|
|
|
}
|
|
|
|
|
2013-09-19 10:05:18 +00:00
|
|
|
QV4::ReturnedValue __qmljs_builtin_typeof_name(ExecutionContext *context, const StringRef name)
|
2012-12-08 04:31:19 +00:00
|
|
|
{
|
2013-09-11 12:47:34 +00:00
|
|
|
Scope scope(context);
|
2013-10-18 13:42:17 +00:00
|
|
|
ScopedValue prop(scope, context->getProperty(name));
|
|
|
|
// typeof doesn't throw. clear any possible exception
|
|
|
|
context->engine->hasException = false;
|
2013-09-09 18:32:01 +00:00
|
|
|
return __qmljs_builtin_typeof(context, prop);
|
2012-12-08 04:31:19 +00:00
|
|
|
}
|
|
|
|
|
2013-09-19 10:05:18 +00:00
|
|
|
QV4::ReturnedValue __qmljs_builtin_typeof_member(ExecutionContext *context, const ValueRef base, const StringRef name)
|
2012-12-08 04:31:19 +00:00
|
|
|
{
|
2013-09-11 12:47:34 +00:00
|
|
|
Scope scope(context);
|
2013-09-18 13:34:13 +00:00
|
|
|
ScopedObject obj(scope, base->toObject(context));
|
2013-10-21 07:57:58 +00:00
|
|
|
if (scope.engine->hasException)
|
|
|
|
return Encode::undefined();
|
2013-09-09 09:07:21 +00:00
|
|
|
ScopedValue prop(scope, obj->get(name));
|
2013-09-09 18:32:01 +00:00
|
|
|
return __qmljs_builtin_typeof(context, prop);
|
2012-12-08 04:31:19 +00:00
|
|
|
}
|
|
|
|
|
2013-09-09 18:32:01 +00:00
|
|
|
QV4::ReturnedValue __qmljs_builtin_typeof_element(ExecutionContext *context, const ValueRef base, const ValueRef index)
|
2012-05-23 16:48:48 +00:00
|
|
|
{
|
2013-09-11 12:47:34 +00:00
|
|
|
Scope scope(context);
|
2013-09-18 13:34:13 +00:00
|
|
|
ScopedString name(scope, index->toString(context));
|
|
|
|
ScopedObject obj(scope, base->toObject(context));
|
2013-10-21 07:57:58 +00:00
|
|
|
if (scope.engine->hasException)
|
|
|
|
return Encode::undefined();
|
2013-09-09 09:07:21 +00:00
|
|
|
ScopedValue prop(scope, obj->get(name));
|
2013-09-09 18:32:01 +00:00
|
|
|
return __qmljs_builtin_typeof(context, prop);
|
2012-05-23 16:48:48 +00:00
|
|
|
}
|
|
|
|
|
2013-09-09 11:38:10 +00:00
|
|
|
ExecutionContext *__qmljs_builtin_push_with_scope(const ValueRef o, ExecutionContext *ctx)
|
2012-11-24 21:07:02 +00:00
|
|
|
{
|
2013-09-27 15:04:42 +00:00
|
|
|
Scope scope(ctx);
|
|
|
|
ScopedObject obj(scope, o->toObject(ctx));
|
2013-08-21 13:00:09 +00:00
|
|
|
return ctx->newWithContext(obj);
|
2012-11-24 21:07:02 +00:00
|
|
|
}
|
|
|
|
|
2013-10-21 15:07:45 +00:00
|
|
|
ReturnedValue __qmljs_builtin_unwind_exception(ExecutionContext *ctx)
|
|
|
|
{
|
|
|
|
if (!ctx->engine->hasException)
|
|
|
|
return Primitive::emptyValue().asReturnedValue();
|
|
|
|
return ctx->engine->catchException(ctx, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
ExecutionContext *__qmljs_builtin_push_catch_scope(ExecutionContext *ctx, const StringRef exceptionVarName)
|
2013-02-08 12:33:50 +00:00
|
|
|
{
|
2013-10-18 13:42:17 +00:00
|
|
|
Scope scope(ctx);
|
|
|
|
ScopedValue v(scope, ctx->engine->catchException(ctx, 0));
|
|
|
|
return ctx->newCatchContext(exceptionVarName, v);
|
2013-02-08 12:33:50 +00:00
|
|
|
}
|
|
|
|
|
2013-01-24 11:13:47 +00:00
|
|
|
ExecutionContext *__qmljs_builtin_pop_scope(ExecutionContext *ctx)
|
2012-11-24 21:07:02 +00:00
|
|
|
{
|
2013-03-14 11:59:11 +00:00
|
|
|
return ctx->engine->popContext();
|
2012-11-24 21:07:02 +00:00
|
|
|
}
|
|
|
|
|
2013-09-19 10:05:18 +00:00
|
|
|
void __qmljs_builtin_declare_var(ExecutionContext *ctx, bool deletable, const StringRef name)
|
2012-11-26 22:26:39 +00:00
|
|
|
{
|
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-09-19 10:05:18 +00:00
|
|
|
void __qmljs_builtin_define_property(ExecutionContext *ctx, const ValueRef object, const StringRef name, ValueRef val)
|
2013-01-03 21:56:52 +00:00
|
|
|
{
|
2013-09-18 09:00:38 +00:00
|
|
|
Scope scope(ctx);
|
|
|
|
ScopedObject o(scope, object->asObject());
|
2013-01-03 21:56:52 +00:00
|
|
|
assert(o);
|
|
|
|
|
2013-03-02 23:50:33 +00:00
|
|
|
uint idx = name->asArrayIndex();
|
2013-09-19 10:05:18 +00:00
|
|
|
Property *pd = (idx != UINT_MAX) ? o->arrayInsert(idx) : o->insertMember(name, Attr_Data);
|
2013-09-25 10:24:36 +00:00
|
|
|
pd->value = val ? *val : Primitive::undefinedValue();
|
2013-01-03 21:56:52 +00:00
|
|
|
}
|
|
|
|
|
2013-09-09 19:17:01 +00:00
|
|
|
ReturnedValue __qmljs_builtin_define_array(ExecutionContext *ctx, Value *values, uint length)
|
2013-03-01 15:47:07 +00:00
|
|
|
{
|
2013-09-14 09:25:02 +00:00
|
|
|
Scope scope(ctx);
|
|
|
|
Scoped<ArrayObject> a(scope, ctx->engine->newArrayObject());
|
2013-03-01 15:47:07 +00:00
|
|
|
|
|
|
|
// ### 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) {
|
2013-04-10 08:46:23 +00:00
|
|
|
a->arrayDataLen = length;
|
|
|
|
Property *pd = a->arrayData;
|
2013-03-01 15:47:07 +00:00
|
|
|
for (uint i = 0; i < length; ++i) {
|
2013-10-13 20:08:59 +00:00
|
|
|
pd->value = values[i];
|
2013-03-01 15:47:07 +00:00
|
|
|
++pd;
|
|
|
|
}
|
|
|
|
a->setArrayLengthUnchecked(length);
|
|
|
|
}
|
2013-09-14 09:25:02 +00:00
|
|
|
return a.asReturnedValue();
|
2013-01-24 11:53:47 +00:00
|
|
|
}
|
|
|
|
|
2013-09-19 10:05:18 +00:00
|
|
|
void __qmljs_builtin_define_getter_setter(ExecutionContext *ctx, const ValueRef object, const StringRef name, const ValueRef getter, const ValueRef setter)
|
2013-01-03 16:11:22 +00:00
|
|
|
{
|
2013-09-18 09:00:38 +00:00
|
|
|
Scope scope(ctx);
|
|
|
|
ScopedObject o(scope, object->asObject());
|
|
|
|
Q_ASSERT(!!o);
|
2013-01-03 16:11:22 +00:00
|
|
|
|
2013-03-02 23:50:33 +00:00
|
|
|
uint idx = name->asArrayIndex();
|
2013-09-19 10:05:18 +00:00
|
|
|
Property *pd = (idx != UINT_MAX) ? o->arrayInsert(idx, Attr_Accessor) : o->insertMember(name, Attr_Accessor);
|
2013-04-10 08:46:23 +00:00
|
|
|
pd->setGetter(getter ? getter->asFunctionObject() : 0);
|
|
|
|
pd->setSetter(setter ? setter->asFunctionObject() : 0);
|
2013-01-03 16:11:22 +00:00
|
|
|
}
|
|
|
|
|
2013-09-09 19:17:01 +00:00
|
|
|
ReturnedValue __qmljs_builtin_define_object_literal(QV4::ExecutionContext *ctx, const QV4::Value *args, int classId)
|
2013-04-23 05:31:02 +00:00
|
|
|
{
|
2013-09-16 20:02:27 +00:00
|
|
|
Scope scope(ctx);
|
2013-08-17 10:08:21 +00:00
|
|
|
QV4::InternalClass *klass = ctx->compilationUnit->runtimeClasses[classId];
|
2013-09-16 20:02:27 +00:00
|
|
|
Scoped<Object> o(scope, ctx->engine->newObject(klass));
|
2013-04-23 05:31:02 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < klass->size; ++i) {
|
|
|
|
if (klass->propertyData[i].isData())
|
|
|
|
o->memberData[i].value = *args++;
|
|
|
|
else {
|
|
|
|
o->memberData[i].setGetter(args->asFunctionObject());
|
|
|
|
args++;
|
|
|
|
o->memberData[i].setSetter(args->asFunctionObject());
|
|
|
|
args++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-16 20:02:27 +00:00
|
|
|
return o.asReturnedValue();
|
2013-04-23 05:31:02 +00:00
|
|
|
}
|
|
|
|
|
2013-09-09 19:17:01 +00:00
|
|
|
QV4::ReturnedValue __qmljs_builtin_setup_arguments_object(ExecutionContext *ctx)
|
2013-08-16 10:54:30 +00:00
|
|
|
{
|
|
|
|
assert(ctx->type >= ExecutionContext::Type_CallContext);
|
|
|
|
CallContext *c = static_cast<CallContext *>(ctx);
|
2013-09-25 13:24:50 +00:00
|
|
|
return (new (c->engine->memoryManager) ArgumentsObject(c))->asReturnedValue();
|
2013-08-16 10:54:30 +00:00
|
|
|
}
|
|
|
|
|
2013-09-09 19:35:37 +00:00
|
|
|
QV4::ReturnedValue __qmljs_increment(const QV4::ValueRef value)
|
2012-12-12 21:46:57 +00:00
|
|
|
{
|
|
|
|
TRACE1(value);
|
|
|
|
|
2013-09-26 20:07:27 +00:00
|
|
|
if (value->isInteger() && value->integerValue() < INT_MAX)
|
|
|
|
return Encode(value->integerValue() + 1);
|
2013-02-14 14:55:43 +00:00
|
|
|
else {
|
2013-09-09 11:38:10 +00:00
|
|
|
double d = value->toNumber();
|
2013-09-26 20:07:27 +00:00
|
|
|
return Encode(d + 1.);
|
2013-02-14 14:55:43 +00:00
|
|
|
}
|
2012-12-12 21:46:57 +00:00
|
|
|
}
|
|
|
|
|
2013-09-09 19:35:37 +00:00
|
|
|
QV4::ReturnedValue __qmljs_decrement(const QV4::ValueRef value)
|
2012-12-12 21:46:57 +00:00
|
|
|
{
|
|
|
|
TRACE1(value);
|
|
|
|
|
2013-09-26 20:07:27 +00:00
|
|
|
if (value->isInteger() && value->integerValue() > INT_MIN)
|
|
|
|
return Encode(value->integerValue() - 1);
|
2013-02-14 14:55:43 +00:00
|
|
|
else {
|
2013-09-09 11:38:10 +00:00
|
|
|
double d = value->toNumber();
|
2013-09-26 20:07:27 +00:00
|
|
|
return Encode(d - 1.);
|
2013-02-14 14:55:43 +00:00
|
|
|
}
|
2012-12-12 21:46:57 +00:00
|
|
|
}
|
|
|
|
|
2013-09-13 12:11:55 +00:00
|
|
|
QV4::ReturnedValue __qmljs_to_string(const QV4::ValueRef value, QV4::ExecutionContext *ctx)
|
|
|
|
{
|
|
|
|
if (value->isString())
|
|
|
|
return value.asReturnedValue();
|
|
|
|
return __qmljs_convert_to_string(ctx, value)->asReturnedValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
QV4::ReturnedValue __qmljs_to_object(QV4::ExecutionContext *ctx, const QV4::ValueRef value)
|
|
|
|
{
|
|
|
|
if (value->isObject())
|
|
|
|
return value.asReturnedValue();
|
2013-10-21 07:57:58 +00:00
|
|
|
|
|
|
|
Returned<Object> *o = __qmljs_convert_to_object(ctx, value);
|
|
|
|
if (!o) // type error
|
|
|
|
return Encode::undefined();
|
|
|
|
|
|
|
|
return Encode(o);
|
2013-09-13 12:11:55 +00:00
|
|
|
}
|
|
|
|
|
2013-09-15 13:46:36 +00:00
|
|
|
ReturnedValue __qmljs_value_to_double(const ValueRef value)
|
2013-08-21 11:45:24 +00:00
|
|
|
{
|
2013-10-09 08:47:11 +00:00
|
|
|
TRACE1(value);
|
2013-09-15 13:46:36 +00:00
|
|
|
return Encode(value->toNumber());
|
2013-08-21 11:45:24 +00:00
|
|
|
}
|
|
|
|
|
2013-09-09 11:38:10 +00:00
|
|
|
int __qmljs_value_to_int32(const ValueRef value)
|
2013-07-30 14:53:03 +00:00
|
|
|
{
|
2013-10-09 08:47:11 +00:00
|
|
|
TRACE1(value);
|
2013-09-09 11:38:10 +00:00
|
|
|
return value->toInt32();
|
2013-07-30 14:53:03 +00:00
|
|
|
}
|
|
|
|
|
2013-08-23 13:10:36 +00:00
|
|
|
int __qmljs_double_to_int32(const double &d)
|
2013-07-30 14:53:03 +00:00
|
|
|
{
|
2013-10-09 08:47:11 +00:00
|
|
|
TRACE0();
|
2013-09-25 11:52:15 +00:00
|
|
|
return Primitive::toInt32(d);
|
2013-07-30 14:53:03 +00:00
|
|
|
}
|
|
|
|
|
2013-09-09 11:38:10 +00:00
|
|
|
unsigned __qmljs_value_to_uint32(const ValueRef value)
|
2013-07-30 14:53:03 +00:00
|
|
|
{
|
2013-10-09 08:47:11 +00:00
|
|
|
TRACE1(value);
|
2013-09-09 11:38:10 +00:00
|
|
|
return value->toUInt32();
|
2013-07-30 14:53:03 +00:00
|
|
|
}
|
|
|
|
|
2013-08-23 13:10:36 +00:00
|
|
|
unsigned __qmljs_double_to_uint32(const double &d)
|
2013-07-30 14:53:03 +00:00
|
|
|
{
|
2013-10-09 08:47:11 +00:00
|
|
|
TRACE0();
|
2013-09-25 11:52:15 +00:00
|
|
|
return Primitive::toUInt32(d);
|
2013-07-30 14:53:03 +00:00
|
|
|
}
|
2013-08-16 10:54:30 +00:00
|
|
|
|
2013-09-09 19:17:01 +00:00
|
|
|
ReturnedValue __qmljs_value_from_string(String *string)
|
2013-08-14 08:17:37 +00:00
|
|
|
{
|
2013-10-09 08:47:11 +00:00
|
|
|
TRACE0();
|
2013-09-25 13:24:50 +00:00
|
|
|
return string->asReturnedValue();
|
2013-08-14 08:17:37 +00:00
|
|
|
}
|
|
|
|
|
2013-09-09 19:17:01 +00:00
|
|
|
ReturnedValue __qmljs_lookup_runtime_regexp(ExecutionContext *ctx, int id)
|
2013-08-15 13:54:36 +00:00
|
|
|
{
|
2013-09-11 09:28:27 +00:00
|
|
|
return ctx->compilationUnit->runtimeRegularExpressions[id].asReturnedValue();
|
2013-08-15 13:54:36 +00:00
|
|
|
}
|
|
|
|
|
2013-10-23 14:24:58 +00:00
|
|
|
ReturnedValue __qmljs_get_id_object(ExecutionContext *ctx, int id)
|
|
|
|
{
|
|
|
|
QQmlContextData *context = QmlContextWrapper::callingContext(ctx->engine);
|
|
|
|
return QObjectWrapper::wrap(ctx->engine, context->idValues[id].data());
|
|
|
|
}
|
|
|
|
|
2013-10-24 12:51:02 +00:00
|
|
|
ReturnedValue __qmljs_get_context_object(ExecutionContext *ctx)
|
|
|
|
{
|
|
|
|
QQmlContextData *context = QmlContextWrapper::callingContext(ctx->engine);
|
|
|
|
return QObjectWrapper::wrap(ctx->engine, context->contextObject);
|
|
|
|
}
|
|
|
|
|
|
|
|
ReturnedValue __qmljs_get_scope_object(ExecutionContext *ctx)
|
|
|
|
{
|
|
|
|
Scope scope(ctx);
|
|
|
|
QV4::Scoped<QmlContextWrapper> c(scope, ctx->engine->qmlContextObject()->getPointer()->as<QmlContextWrapper>());
|
|
|
|
return QObjectWrapper::wrap(ctx->engine, c->getScopeObject());
|
|
|
|
}
|
|
|
|
|
|
|
|
ReturnedValue __qmljs_get_qobject_property(ExecutionContext *ctx, const ValueRef object, int propertyIndex)
|
|
|
|
{
|
|
|
|
Scope scope(ctx);
|
|
|
|
QV4::Scoped<QObjectWrapper> wrapper(scope, object);
|
|
|
|
if (!wrapper) {
|
|
|
|
ctx->throwTypeError(QStringLiteral("Cannot read property of null"));
|
|
|
|
return Encode::undefined();
|
|
|
|
}
|
|
|
|
return wrapper->getProperty(ctx, propertyIndex);
|
|
|
|
}
|
|
|
|
|
2013-10-28 14:18:31 +00:00
|
|
|
void __qmljs_set_qobject_property(ExecutionContext *ctx, const ValueRef object, int propertyIndex, const ValueRef value)
|
|
|
|
{
|
|
|
|
Scope scope(ctx);
|
|
|
|
QV4::Scoped<QObjectWrapper> wrapper(scope, object);
|
|
|
|
if (!wrapper) {
|
|
|
|
ctx->throwTypeError(QStringLiteral("Cannot write property of null"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
wrapper->setProperty(ctx, propertyIndex, value);
|
|
|
|
}
|
|
|
|
|
2013-06-24 13:28:00 +00:00
|
|
|
} // namespace QV4
|
|
|
|
|
|
|
|
QT_END_NAMESPACE
|