2012-11-17 21:10:52 +00:00
|
|
|
/****************************************************************************
|
|
|
|
**
|
2013-06-24 11:50:51 +00:00
|
|
|
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
2012-11-17 21:10:52 +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-11-17 21:10:52 +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$
|
|
|
|
**
|
|
|
|
****************************************************************************/
|
|
|
|
#ifndef QMLJS_VALUE_H
|
|
|
|
#define QMLJS_VALUE_H
|
|
|
|
|
2013-04-19 19:24:46 +00:00
|
|
|
#include <cmath> // this HAS to come
|
|
|
|
|
2012-11-17 21:10:52 +00:00
|
|
|
#include <QtCore/QString>
|
|
|
|
#include <QtCore/qnumeric.h>
|
2013-04-15 09:50:16 +00:00
|
|
|
#include "qv4global_p.h"
|
|
|
|
#include "qv4string_p.h"
|
2012-11-17 21:10:52 +00:00
|
|
|
#include <QtCore/QDebug>
|
2013-04-15 09:50:16 +00:00
|
|
|
#include "qv4managed_p.h"
|
2013-08-09 11:28:02 +00:00
|
|
|
#include <private/qtqmlglobal_p.h>
|
2012-11-17 21:10:52 +00:00
|
|
|
|
2013-04-17 16:17:30 +00:00
|
|
|
//#include <wtf/MathExtras.h>
|
2013-02-14 22:16:50 +00:00
|
|
|
|
2013-06-25 12:23:35 +00:00
|
|
|
#include "qv4value_def_p.h"
|
|
|
|
|
2013-01-31 09:00:06 +00:00
|
|
|
QT_BEGIN_NAMESPACE
|
|
|
|
|
2013-04-19 11:03:42 +00:00
|
|
|
namespace QV4 {
|
2012-11-17 21:10:52 +00:00
|
|
|
|
2013-09-15 13:46:36 +00:00
|
|
|
inline bool Value::isString() const
|
|
|
|
{
|
|
|
|
if (!isManaged())
|
|
|
|
return false;
|
|
|
|
return managed() && managed()->type == Managed::Type_String;
|
|
|
|
}
|
|
|
|
inline bool Value::isObject() const
|
|
|
|
{
|
|
|
|
if (!isManaged())
|
|
|
|
return false;
|
|
|
|
return managed() && managed()->type != Managed::Type_String;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool Value::isPrimitive() const
|
|
|
|
{
|
|
|
|
return !isObject();
|
|
|
|
}
|
|
|
|
|
2013-08-26 13:07:38 +00:00
|
|
|
inline Managed *Value::asManaged() const
|
|
|
|
{
|
|
|
|
if (isManaged())
|
|
|
|
return managed();
|
|
|
|
return 0;
|
|
|
|
}
|
2013-05-06 09:37:53 +00:00
|
|
|
|
2013-06-25 12:23:35 +00:00
|
|
|
inline ExecutionEngine *Value::engine() const {
|
|
|
|
Managed *m = asManaged();
|
|
|
|
return m ? m->engine() : 0;
|
|
|
|
}
|
2013-01-28 15:46:09 +00:00
|
|
|
|
2013-06-25 12:23:35 +00:00
|
|
|
inline void Value::mark() const {
|
2013-09-20 13:13:14 +00:00
|
|
|
if (!val)
|
|
|
|
return;
|
2013-06-25 12:23:35 +00:00
|
|
|
Managed *m = asManaged();
|
|
|
|
if (m)
|
|
|
|
m->mark();
|
|
|
|
}
|
2012-11-17 21:10:52 +00:00
|
|
|
|
2013-09-25 10:24:36 +00:00
|
|
|
inline Value Primitive::undefinedValue()
|
2012-11-17 21:10:52 +00:00
|
|
|
{
|
2013-09-25 10:24:36 +00:00
|
|
|
Primitive v;
|
2013-02-21 11:07:17 +00:00
|
|
|
#if QT_POINTER_SIZE == 8
|
2013-09-15 13:46:36 +00:00
|
|
|
v.val = quint64(Undefined_Type) << Tag_Shift;
|
2012-11-17 21:10:52 +00:00
|
|
|
#else
|
2013-09-15 13:46:36 +00:00
|
|
|
v.tag = Undefined_Type;
|
2012-11-17 21:10:52 +00:00
|
|
|
v.int_32 = 0;
|
|
|
|
#endif
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2013-09-25 10:24:36 +00:00
|
|
|
inline Primitive Primitive::nullValue()
|
2012-11-17 21:10:52 +00:00
|
|
|
{
|
2013-09-25 10:24:36 +00:00
|
|
|
Primitive v;
|
2013-02-21 11:07:17 +00:00
|
|
|
#if QT_POINTER_SIZE == 8
|
2012-11-17 21:10:52 +00:00
|
|
|
v.val = quint64(_Null_Type) << Tag_Shift;
|
|
|
|
#else
|
|
|
|
v.tag = _Null_Type;
|
|
|
|
v.int_32 = 0;
|
|
|
|
#endif
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2013-05-07 10:56:58 +00:00
|
|
|
inline Value Value::emptyValue()
|
2013-04-10 08:46:23 +00:00
|
|
|
{
|
2013-04-19 11:03:42 +00:00
|
|
|
Value v;
|
2013-09-15 13:46:36 +00:00
|
|
|
v.tag = Value::Empty_Type;
|
2013-04-10 08:46:23 +00:00
|
|
|
v.uint_32 = 0;
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-25 10:24:36 +00:00
|
|
|
inline Primitive Primitive::fromBoolean(bool b)
|
2012-11-17 21:10:52 +00:00
|
|
|
{
|
2013-09-25 10:24:36 +00:00
|
|
|
Primitive v;
|
2012-11-17 21:10:52 +00:00
|
|
|
v.tag = _Boolean_Type;
|
|
|
|
v.int_32 = (bool)b;
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2013-09-25 10:24:36 +00:00
|
|
|
inline Primitive Primitive::fromDouble(double d)
|
2012-11-17 21:10:52 +00:00
|
|
|
{
|
2013-09-25 10:24:36 +00:00
|
|
|
Primitive v;
|
2013-09-15 13:46:36 +00:00
|
|
|
v.setDouble(d);
|
2012-11-17 21:10:52 +00:00
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2013-09-25 10:24:36 +00:00
|
|
|
inline Primitive Primitive::fromInt32(int i)
|
2012-11-17 21:10:52 +00:00
|
|
|
{
|
2013-09-25 10:24:36 +00:00
|
|
|
Primitive v;
|
2012-11-17 21:10:52 +00:00
|
|
|
v.tag = _Integer_Type;
|
|
|
|
v.int_32 = i;
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2013-09-25 10:24:36 +00:00
|
|
|
inline Primitive Primitive::fromUInt32(uint i)
|
2013-01-11 13:33:10 +00:00
|
|
|
{
|
2013-09-25 10:24:36 +00:00
|
|
|
Primitive v;
|
2013-01-11 13:33:10 +00:00
|
|
|
if (i < INT_MAX) {
|
|
|
|
v.tag = _Integer_Type;
|
|
|
|
v.int_32 = (int)i;
|
|
|
|
} else {
|
2013-09-15 13:46:36 +00:00
|
|
|
v.setDouble(i);
|
2013-01-11 13:33:10 +00:00
|
|
|
}
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2012-11-17 21:10:52 +00:00
|
|
|
inline Value Value::fromString(String *s)
|
|
|
|
{
|
|
|
|
Value v;
|
2013-02-21 11:07:17 +00:00
|
|
|
#if QT_POINTER_SIZE == 8
|
2013-09-15 13:46:36 +00:00
|
|
|
v.s = s;
|
2012-11-17 21:10:52 +00:00
|
|
|
#else
|
2013-09-15 13:46:36 +00:00
|
|
|
v.tag = Managed_Type;
|
2012-11-17 21:10:52 +00:00
|
|
|
v.s = s;
|
|
|
|
#endif
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline Value Value::fromObject(Object *o)
|
|
|
|
{
|
|
|
|
Value v;
|
2013-02-21 11:07:17 +00:00
|
|
|
#if QT_POINTER_SIZE == 8
|
2013-09-15 13:46:36 +00:00
|
|
|
v.o = o;
|
2012-11-17 21:10:52 +00:00
|
|
|
#else
|
2013-09-15 13:46:36 +00:00
|
|
|
v.tag = Managed_Type;
|
2012-11-17 21:10:52 +00:00
|
|
|
v.o = o;
|
|
|
|
#endif
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2013-09-15 13:46:36 +00:00
|
|
|
inline Value Value::fromManaged(Managed *m)
|
|
|
|
{
|
|
|
|
if (!m)
|
2013-09-25 10:24:36 +00:00
|
|
|
return QV4::Primitive::undefinedValue();
|
2013-09-15 13:46:36 +00:00
|
|
|
Value v;
|
|
|
|
#if QT_POINTER_SIZE == 8
|
|
|
|
v.m = m;
|
|
|
|
#else
|
|
|
|
v.tag = Managed_Type;
|
|
|
|
v.m = m;
|
|
|
|
#endif
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2013-09-14 13:08:11 +00:00
|
|
|
inline double Value::toNumber() const
|
|
|
|
{
|
2013-09-15 13:46:36 +00:00
|
|
|
if (integerCompatible())
|
2013-09-14 13:08:11 +00:00
|
|
|
return int_32;
|
|
|
|
if (isDouble())
|
2013-09-15 13:46:36 +00:00
|
|
|
return doubleValue();
|
2013-09-14 13:08:11 +00:00
|
|
|
return toNumberImpl();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline int Value::toInt32() const
|
|
|
|
{
|
2013-09-15 13:46:36 +00:00
|
|
|
if (integerCompatible())
|
2013-09-14 13:08:11 +00:00
|
|
|
return int_32;
|
|
|
|
double d;
|
|
|
|
if (isDouble())
|
2013-09-15 13:46:36 +00:00
|
|
|
d = doubleValue();
|
2013-09-14 13:08:11 +00:00
|
|
|
else
|
|
|
|
d = toNumberImpl();
|
|
|
|
|
|
|
|
const double D32 = 4294967296.0;
|
|
|
|
const double D31 = D32 / 2.0;
|
|
|
|
|
|
|
|
if ((d >= -D31 && d < D31))
|
|
|
|
return static_cast<int>(d);
|
|
|
|
|
|
|
|
return Value::toInt32(d);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline unsigned int Value::toUInt32() const
|
|
|
|
{
|
2013-09-15 13:46:36 +00:00
|
|
|
return (unsigned int)toInt32();
|
2013-09-14 13:08:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-07 20:43:14 +00:00
|
|
|
inline bool Value::toBoolean() const
|
2013-02-14 22:16:50 +00:00
|
|
|
{
|
|
|
|
switch (type()) {
|
|
|
|
case Value::Undefined_Type:
|
|
|
|
case Value::Null_Type:
|
|
|
|
return false;
|
|
|
|
case Value::Boolean_Type:
|
|
|
|
case Value::Integer_Type:
|
|
|
|
return (bool)int_32;
|
2013-09-15 13:46:36 +00:00
|
|
|
case Value::Managed_Type:
|
|
|
|
if (isString())
|
|
|
|
return stringValue()->toQString().length() > 0;
|
2013-02-14 22:16:50 +00:00
|
|
|
return true;
|
|
|
|
default: // double
|
2013-08-09 13:37:39 +00:00
|
|
|
return doubleValue() && !std::isnan(doubleValue());
|
2013-02-14 22:16:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-11 09:13:02 +00:00
|
|
|
inline uint Value::asArrayIndex() const
|
|
|
|
{
|
|
|
|
if (isInteger() && int_32 >= 0)
|
|
|
|
return (uint)int_32;
|
|
|
|
if (!isDouble())
|
|
|
|
return UINT_MAX;
|
2013-09-15 13:46:36 +00:00
|
|
|
double d = doubleValue();
|
|
|
|
uint idx = (uint)d;
|
|
|
|
if (idx != d)
|
2013-01-11 09:13:02 +00:00
|
|
|
return UINT_MAX;
|
|
|
|
return idx;
|
|
|
|
}
|
|
|
|
|
2013-04-14 20:01:20 +00:00
|
|
|
inline uint Value::asArrayLength(bool *ok) const
|
2013-01-11 09:13:02 +00:00
|
|
|
{
|
|
|
|
*ok = true;
|
2013-09-15 13:46:36 +00:00
|
|
|
if (integerCompatible() && int_32 >= 0)
|
2013-01-11 09:13:02 +00:00
|
|
|
return (uint)int_32;
|
2013-01-11 15:28:05 +00:00
|
|
|
if (isDouble()) {
|
2013-09-15 13:46:36 +00:00
|
|
|
double d = doubleValue();
|
|
|
|
uint idx = (uint)d;
|
|
|
|
if (idx != d) {
|
2013-01-11 15:28:05 +00:00
|
|
|
*ok = false;
|
|
|
|
return UINT_MAX;
|
|
|
|
}
|
|
|
|
return idx;
|
|
|
|
}
|
2013-01-11 13:33:10 +00:00
|
|
|
if (isString())
|
|
|
|
return stringValue()->toUInt(ok);
|
|
|
|
|
2013-04-14 20:01:20 +00:00
|
|
|
uint idx = toUInt32();
|
|
|
|
double d = toNumber();
|
2013-01-11 15:28:05 +00:00
|
|
|
if (d != idx) {
|
2013-01-11 09:13:02 +00:00
|
|
|
*ok = false;
|
|
|
|
return UINT_MAX;
|
|
|
|
}
|
|
|
|
return idx;
|
|
|
|
}
|
|
|
|
|
2013-02-16 22:27:07 +00:00
|
|
|
inline String *Value::asString() const
|
|
|
|
{
|
|
|
|
if (isString())
|
|
|
|
return stringValue();
|
|
|
|
return 0;
|
|
|
|
}
|
2013-01-11 09:13:02 +00:00
|
|
|
|
2013-01-25 12:23:58 +00:00
|
|
|
inline Object *Value::asObject() const
|
|
|
|
{
|
|
|
|
return isObject() ? objectValue() : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline FunctionObject *Value::asFunctionObject() const
|
|
|
|
{
|
|
|
|
return isObject() ? managed()->asFunctionObject() : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline BooleanObject *Value::asBooleanObject() const
|
|
|
|
{
|
|
|
|
return isObject() ? managed()->asBooleanObject() : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline NumberObject *Value::asNumberObject() const
|
|
|
|
{
|
|
|
|
return isObject() ? managed()->asNumberObject() : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline StringObject *Value::asStringObject() const
|
|
|
|
{
|
|
|
|
return isObject() ? managed()->asStringObject() : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline DateObject *Value::asDateObject() const
|
|
|
|
{
|
|
|
|
return isObject() ? managed()->asDateObject() : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline ArrayObject *Value::asArrayObject() const
|
|
|
|
{
|
|
|
|
return isObject() ? managed()->asArrayObject() : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline ErrorObject *Value::asErrorObject() const
|
|
|
|
{
|
|
|
|
return isObject() ? managed()->asErrorObject() : 0;
|
|
|
|
}
|
|
|
|
|
2013-09-15 13:46:36 +00:00
|
|
|
template<typename T>
|
|
|
|
inline T *Value::as() const { Managed *m = isObject() ? managed() : 0; return m ? m->as<T>() : 0; }
|
2013-01-25 12:23:58 +00:00
|
|
|
|
2013-08-09 11:28:02 +00:00
|
|
|
struct Q_QML_PRIVATE_EXPORT PersistentValuePrivate
|
2013-04-16 09:36:56 +00:00
|
|
|
{
|
2013-09-23 13:52:10 +00:00
|
|
|
PersistentValuePrivate(ReturnedValue v, ExecutionEngine *engine = 0, bool weak = false);
|
2013-06-14 11:54:36 +00:00
|
|
|
virtual ~PersistentValuePrivate();
|
2013-09-24 13:25:10 +00:00
|
|
|
SafeValue value;
|
2013-05-23 20:13:42 +00:00
|
|
|
uint refcount;
|
2013-09-23 13:52:10 +00:00
|
|
|
bool weak;
|
2013-06-21 13:19:20 +00:00
|
|
|
QV4::ExecutionEngine *engine;
|
2013-05-06 13:11:01 +00:00
|
|
|
PersistentValuePrivate **prev;
|
2013-04-16 09:36:56 +00:00
|
|
|
PersistentValuePrivate *next;
|
|
|
|
|
2013-09-23 13:52:10 +00:00
|
|
|
void init();
|
2013-05-23 20:13:42 +00:00
|
|
|
void removeFromList();
|
2013-04-16 09:36:56 +00:00
|
|
|
void ref() { ++refcount; }
|
|
|
|
void deref();
|
2013-09-23 13:52:10 +00:00
|
|
|
PersistentValuePrivate *detach(const ReturnedValue value, bool weak = false);
|
2013-06-21 13:19:20 +00:00
|
|
|
|
|
|
|
bool checkEngine(QV4::ExecutionEngine *otherEngine) {
|
|
|
|
if (!engine) {
|
|
|
|
Q_ASSERT(!value.isObject());
|
|
|
|
engine = otherEngine;
|
|
|
|
}
|
|
|
|
return (engine == otherEngine);
|
|
|
|
}
|
2013-04-16 09:36:56 +00:00
|
|
|
};
|
|
|
|
|
2013-05-07 10:29:30 +00:00
|
|
|
class Q_QML_EXPORT PersistentValue
|
2013-03-06 19:04:43 +00:00
|
|
|
{
|
|
|
|
public:
|
2013-05-07 11:17:57 +00:00
|
|
|
PersistentValue() : d(0) {}
|
2013-09-23 13:52:10 +00:00
|
|
|
PersistentValue(const PersistentValue &other);
|
|
|
|
PersistentValue &operator=(const PersistentValue &other);
|
2013-09-11 11:55:01 +00:00
|
|
|
|
2013-09-23 13:52:10 +00:00
|
|
|
PersistentValue(const ValueRef val);
|
2013-09-11 11:55:01 +00:00
|
|
|
PersistentValue(ReturnedValue val);
|
2013-09-16 20:02:27 +00:00
|
|
|
template<typename T>
|
|
|
|
PersistentValue(Returned<T> *obj);
|
|
|
|
template<typename T>
|
2013-09-23 13:52:10 +00:00
|
|
|
PersistentValue(const Referenced<T> obj);
|
2013-09-16 20:02:27 +00:00
|
|
|
PersistentValue &operator=(const ValueRef other);
|
2013-09-23 13:52:10 +00:00
|
|
|
PersistentValue &operator =(ReturnedValue other);
|
2013-09-16 20:02:27 +00:00
|
|
|
template<typename T>
|
|
|
|
PersistentValue &operator=(Returned<T> *obj);
|
|
|
|
template<typename T>
|
2013-09-23 13:52:10 +00:00
|
|
|
PersistentValue &operator=(const Referenced<T> obj);
|
2013-03-06 19:04:43 +00:00
|
|
|
~PersistentValue();
|
|
|
|
|
2013-09-23 13:52:10 +00:00
|
|
|
ReturnedValue value() const {
|
2013-09-25 10:24:36 +00:00
|
|
|
return (d ? d->value.asReturnedValue() : Primitive::undefinedValue().asReturnedValue());
|
2013-05-07 11:17:57 +00:00
|
|
|
}
|
2013-03-06 19:04:43 +00:00
|
|
|
|
2013-05-06 09:37:53 +00:00
|
|
|
ExecutionEngine *engine() {
|
2013-05-07 11:17:57 +00:00
|
|
|
if (!d)
|
|
|
|
return 0;
|
2013-09-23 13:52:10 +00:00
|
|
|
if (d->engine)
|
|
|
|
return d->engine;
|
2013-05-06 09:37:53 +00:00
|
|
|
Managed *m = d->value.asManaged();
|
|
|
|
return m ? m->engine() : 0;
|
|
|
|
}
|
|
|
|
|
2013-09-17 16:16:35 +00:00
|
|
|
bool isUndefined() const { return !d || d->value.isUndefined(); }
|
|
|
|
bool isNullOrUndefined() const { return !d || d->value.isNullOrUndefined(); }
|
2013-05-08 11:14:40 +00:00
|
|
|
void clear() {
|
|
|
|
*this = PersistentValue();
|
|
|
|
}
|
2013-03-06 19:04:43 +00:00
|
|
|
|
|
|
|
private:
|
2013-09-09 11:38:10 +00:00
|
|
|
friend struct ValueRef;
|
2013-04-16 09:36:56 +00:00
|
|
|
PersistentValuePrivate *d;
|
2013-03-06 19:04:43 +00:00
|
|
|
};
|
|
|
|
|
2013-05-23 20:13:42 +00:00
|
|
|
class Q_QML_EXPORT WeakValue
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
WeakValue() : d(0) {}
|
2013-09-23 13:52:10 +00:00
|
|
|
WeakValue(const ValueRef val);
|
2013-05-23 20:13:42 +00:00
|
|
|
WeakValue(const WeakValue &other);
|
2013-09-16 20:02:27 +00:00
|
|
|
WeakValue(ReturnedValue val);
|
|
|
|
template<typename T>
|
|
|
|
WeakValue(Returned<T> *obj);
|
2013-05-23 20:13:42 +00:00
|
|
|
WeakValue &operator=(const WeakValue &other);
|
2013-09-23 13:52:10 +00:00
|
|
|
WeakValue &operator=(const ValueRef other);
|
2013-09-16 20:02:27 +00:00
|
|
|
WeakValue &operator =(const ReturnedValue &other);
|
|
|
|
template<typename T>
|
|
|
|
WeakValue &operator=(Returned<T> *obj);
|
|
|
|
|
2013-05-23 20:13:42 +00:00
|
|
|
~WeakValue();
|
|
|
|
|
2013-09-23 13:52:10 +00:00
|
|
|
ReturnedValue value() const {
|
2013-09-25 10:24:36 +00:00
|
|
|
return (d ? d->value.asReturnedValue() : Primitive::undefinedValue().asReturnedValue());
|
2013-05-23 20:13:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ExecutionEngine *engine() {
|
|
|
|
if (!d)
|
|
|
|
return 0;
|
2013-09-23 13:52:10 +00:00
|
|
|
if (d->engine)
|
|
|
|
return d->engine;
|
2013-05-23 20:13:42 +00:00
|
|
|
Managed *m = d->value.asManaged();
|
|
|
|
return m ? m->engine() : 0;
|
|
|
|
}
|
|
|
|
|
2013-09-17 16:16:35 +00:00
|
|
|
bool isUndefined() const { return !d || d->value.isUndefined(); }
|
|
|
|
bool isNullOrUndefined() const { return !d || d->value.isNullOrUndefined(); }
|
2013-05-23 20:13:42 +00:00
|
|
|
void clear() {
|
|
|
|
*this = WeakValue();
|
|
|
|
}
|
|
|
|
|
2013-05-24 15:12:57 +00:00
|
|
|
void markOnce();
|
|
|
|
|
2013-05-23 20:13:42 +00:00
|
|
|
private:
|
2013-09-09 11:38:10 +00:00
|
|
|
friend struct ValueRef;
|
2013-05-23 20:13:42 +00:00
|
|
|
PersistentValuePrivate *d;
|
|
|
|
};
|
|
|
|
|
2013-04-19 11:03:42 +00:00
|
|
|
} // namespace QV4
|
2012-11-17 21:10:52 +00:00
|
|
|
|
2013-01-31 09:00:06 +00:00
|
|
|
QT_END_NAMESPACE
|
|
|
|
|
2012-11-17 21:10:52 +00:00
|
|
|
#endif
|