aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/jsruntime
diff options
context:
space:
mode:
Diffstat (limited to 'src/qml/jsruntime')
-rw-r--r--src/qml/jsruntime/jsruntime.pri1
-rw-r--r--src/qml/jsruntime/qv4runtime.cpp15
-rw-r--r--src/qml/jsruntime/qv4scopedvalue_p.h150
3 files changed, 160 insertions, 6 deletions
diff --git a/src/qml/jsruntime/jsruntime.pri b/src/qml/jsruntime/jsruntime.pri
index 9a1325b58a..c504f750e9 100644
--- a/src/qml/jsruntime/jsruntime.pri
+++ b/src/qml/jsruntime/jsruntime.pri
@@ -90,6 +90,7 @@ HEADERS += \
$$PWD/qv4unwindhelper_arm_p.h \
$$PWD/qv4serialize_p.h \
$$PWD/qv4script_p.h \
+ $$PWD/qv4scopedvalue_p.h \
$$PWD/qv4util_p.h \
$$PWD/qv4executableallocator_p.h \
$$PWD/qv4sequenceobject_p.h \
diff --git a/src/qml/jsruntime/qv4runtime.cpp b/src/qml/jsruntime/qv4runtime.cpp
index 33521efb02..77b11a4fa8 100644
--- a/src/qml/jsruntime/qv4runtime.cpp
+++ b/src/qml/jsruntime/qv4runtime.cpp
@@ -51,6 +51,7 @@
#include "qv4function_p.h"
#include "qv4exception_p.h"
#include "private/qlocale_tools_p.h"
+#include "qv4scopedvalue_p.h"
#include <QtCore/qmath.h>
#include <QtCore/qnumeric.h>
@@ -159,14 +160,16 @@ void __qmljs_delete_name(ExecutionContext *ctx, Value *result, String *name)
void __qmljs_add_helper(ExecutionContext *ctx, Value *result, const Value &left, const Value &right)
{
- Value pleft = __qmljs_to_primitive(left, PREFERREDTYPE_HINT);
- Value pright = __qmljs_to_primitive(right, PREFERREDTYPE_HINT);
- if (pleft.isString() || pright.isString()) {
- if (!pleft.isString())
+ ValueScope scope(ctx);
+
+ ScopedValue pleft(scope, __qmljs_to_primitive(left, PREFERREDTYPE_HINT));
+ ScopedValue pright(scope, __qmljs_to_primitive(right, PREFERREDTYPE_HINT));
+ if (pleft->isString() || pright->isString()) {
+ if (!pleft->isString())
pleft = __qmljs_to_string(pleft, ctx);
- if (!pright.isString())
+ if (!pright->isString())
pright = __qmljs_to_string(pright, ctx);
- String *string = __qmljs_string_concat(ctx, pleft.stringValue(), pright.stringValue());
+ String *string = __qmljs_string_concat(ctx, pleft->stringValue(), pright->stringValue());
*result = Value::fromString(string);
return;
}
diff --git a/src/qml/jsruntime/qv4scopedvalue_p.h b/src/qml/jsruntime/qv4scopedvalue_p.h
new file mode 100644
index 0000000000..9d19025d83
--- /dev/null
+++ b/src/qml/jsruntime/qv4scopedvalue_p.h
@@ -0,0 +1,150 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtQml 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$
+**
+****************************************************************************/
+#ifndef QV4SCOPEDVALUE_P_H
+#define QV4SCOPEDVALUE_P_H
+
+#include "qv4engine_p.h"
+#include "qv4value_def_p.h"
+
+QT_BEGIN_NAMESPACE
+
+namespace QV4 {
+
+struct ScopedValueArray {
+ ScopedValueArray(ExecutionEngine *e, int size)
+ : engine(e)
+#ifndef QT_NO_DEBUG
+ , size(size)
+#endif
+ {
+ ptr = e->stackPush(size);
+ }
+
+ ~ScopedValueArray() {
+#ifndef QT_NO_DEBUG
+ engine->stackPop(size);
+ Q_ASSERT(engine->jsStackTop == ptr);
+#else
+ engine->jsStackTop = ptr;
+#endif
+ }
+
+ ExecutionEngine *engine;
+#ifndef QT_NO_DEBUG
+ int size;
+#endif
+ Value *ptr;
+};
+
+struct ScopedValue;
+
+struct ValueScope {
+ ValueScope(ExecutionContext *ctx)
+ : engine(ctx->engine)
+ {
+ mark = ctx->engine->jsStackTop;
+ }
+
+ ValueScope(ExecutionEngine *e)
+ : engine(e)
+ {
+ mark = e->jsStackTop;
+ }
+
+ ~ValueScope() {
+ Q_ASSERT(engine->jsStackTop >= mark);
+ engine->jsStackTop = mark;
+ }
+
+ ExecutionEngine *engine;
+ Value *mark;
+};
+
+struct ScopedValue
+{
+ ScopedValue(ExecutionEngine *engine)
+ {
+ ptr = engine->jsStackTop++;
+ }
+
+ ScopedValue(ExecutionEngine *engine, const Value &v)
+ {
+ ptr = engine->jsStackTop++;
+ *ptr = v;
+ }
+
+ ScopedValue(const ValueScope &scope)
+ {
+ ptr = scope.engine->jsStackTop++;
+ }
+
+ ScopedValue(const ValueScope &scope, const Value &v)
+ {
+ ptr = scope.engine->jsStackTop++;
+ *ptr = v;
+ }
+
+ ScopedValue &operator=(const Value &v) {
+ *ptr = v;
+ return *this;
+ }
+
+ ScopedValue &operator=(const ScopedValue &other) {
+ *ptr = *other.ptr;
+ return *this;
+ }
+
+ Value *operator->() {
+ return ptr;
+ }
+
+ operator const Value &() const {
+ return *ptr;
+ }
+
+ Value *ptr;
+};
+
+}
+
+QT_END_NAMESPACE
+
+#endif