qjsvalue.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /****************************************************************************
  2. **
  3. ** Copyright (C) 2016 The Qt Company Ltd.
  4. ** Contact: https://www.qt.io/licensing/
  5. **
  6. ** This file is part of the QtQml module of the Qt Toolkit.
  7. **
  8. ** $QT_BEGIN_LICENSE:LGPL$
  9. ** Commercial License Usage
  10. ** Licensees holding valid commercial Qt licenses may use this file in
  11. ** accordance with the commercial license agreement provided with the
  12. ** Software or, alternatively, in accordance with the terms contained in
  13. ** a written agreement between you and The Qt Company. For licensing terms
  14. ** and conditions see https://www.qt.io/terms-conditions. For further
  15. ** information use the contact form at https://www.qt.io/contact-us.
  16. **
  17. ** GNU Lesser General Public License Usage
  18. ** Alternatively, this file may be used under the terms of the GNU Lesser
  19. ** General Public License version 3 as published by the Free Software
  20. ** Foundation and appearing in the file LICENSE.LGPL3 included in the
  21. ** packaging of this file. Please review the following information to
  22. ** ensure the GNU Lesser General Public License version 3 requirements
  23. ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
  24. **
  25. ** GNU General Public License Usage
  26. ** Alternatively, this file may be used under the terms of the GNU
  27. ** General Public License version 2.0 or (at your option) the GNU General
  28. ** Public license version 3 or any later version approved by the KDE Free
  29. ** Qt Foundation. The licenses are as published by the Free Software
  30. ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
  31. ** included in the packaging of this file. Please review the following
  32. ** information to ensure the GNU General Public License requirements will
  33. ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
  34. ** https://www.gnu.org/licenses/gpl-3.0.html.
  35. **
  36. ** $QT_END_LICENSE$
  37. **
  38. ****************************************************************************/
  39. #ifndef QJSVALUE_H
  40. #define QJSVALUE_H
  41. #include <QtQml/qtqmlglobal.h>
  42. #include <QtCore/qstring.h>
  43. #include <QtCore/qlist.h>
  44. #include <QtCore/qmetatype.h>
  45. QT_BEGIN_NAMESPACE
  46. class QJSValue;
  47. class QJSEngine;
  48. class QVariant;
  49. class QObject;
  50. struct QMetaObject;
  51. class QDateTime;
  52. typedef QList<QJSValue> QJSValueList;
  53. namespace QV4 {
  54. struct ExecutionEngine;
  55. struct Value;
  56. }
  57. class Q_QML_EXPORT QJSValue
  58. {
  59. public:
  60. enum SpecialValue {
  61. NullValue,
  62. UndefinedValue
  63. };
  64. public:
  65. QJSValue(SpecialValue value = UndefinedValue);
  66. ~QJSValue();
  67. QJSValue(const QJSValue &other);
  68. #ifdef Q_COMPILER_RVALUE_REFS
  69. inline QJSValue(QJSValue && other) : d(other.d) { other.d = 0; }
  70. inline QJSValue &operator=(QJSValue &&other)
  71. { qSwap(d, other.d); return *this; }
  72. #endif
  73. QJSValue(bool value);
  74. QJSValue(int value);
  75. QJSValue(uint value);
  76. QJSValue(double value);
  77. QJSValue(const QString &value);
  78. QJSValue(const QLatin1String &value);
  79. #ifndef QT_NO_CAST_FROM_ASCII
  80. QT_ASCII_CAST_WARN QJSValue(const char *str);
  81. #endif
  82. QJSValue &operator=(const QJSValue &other);
  83. bool isBool() const;
  84. bool isNumber() const;
  85. bool isNull() const;
  86. bool isString() const;
  87. bool isUndefined() const;
  88. bool isVariant() const;
  89. bool isQObject() const;
  90. bool isObject() const;
  91. bool isDate() const;
  92. bool isRegExp() const;
  93. bool isArray() const;
  94. bool isError() const;
  95. QString toString() const;
  96. double toNumber() const;
  97. qint32 toInt() const;
  98. quint32 toUInt() const;
  99. bool toBool() const;
  100. QVariant toVariant() const;
  101. QObject *toQObject() const;
  102. QDateTime toDateTime() const;
  103. bool equals(const QJSValue &other) const;
  104. bool strictlyEquals(const QJSValue &other) const;
  105. QJSValue prototype() const;
  106. void setPrototype(const QJSValue &prototype);
  107. QJSValue property(const QString &name) const;
  108. void setProperty(const QString &name, const QJSValue &value);
  109. bool hasProperty(const QString &name) const;
  110. bool hasOwnProperty(const QString &name) const;
  111. QJSValue property(quint32 arrayIndex) const;
  112. void setProperty(quint32 arrayIndex, const QJSValue &value);
  113. bool deleteProperty(const QString &name);
  114. bool isCallable() const;
  115. QJSValue call(const QJSValueList &args = QJSValueList());
  116. QJSValue callWithInstance(const QJSValue &instance, const QJSValueList &args = QJSValueList());
  117. QJSValue callAsConstructor(const QJSValueList &args = QJSValueList());
  118. #ifdef QT_DEPRECATED
  119. QT_DEPRECATED QJSEngine *engine() const;
  120. #endif
  121. QJSValue(QV4::ExecutionEngine *e, quint64 val);
  122. private:
  123. friend class QJSValuePrivate;
  124. // force compile error, prevent QJSValue(bool) to be called
  125. QJSValue(void *) Q_DECL_EQ_DELETE;
  126. mutable quintptr d;
  127. };
  128. QT_END_NAMESPACE
  129. Q_DECLARE_METATYPE(QJSValue)
  130. #endif