![]() |
Qt 6.x
The Qt SDK
|
The QJSPrimitiveValue class operates on primitive types in JavaScript semantics. More...
#include <qjsprimitivevalue.h>
Public Types | |
enum | Type : quint8 { Undefined , Null , Boolean , Integer , Double , String } |
This enum speicifies the types a QJSPrimitiveValue might contain. More... | |
Public Member Functions | |
constexpr Type | type () const |
Returns the type of the QJSPrimitiveValue. | |
QJSPrimitiveValue (Type)=delete | |
Q_IMPLICIT constexpr | QJSPrimitiveValue () noexcept=default |
Creates a QJSPrimitiveValue of type Undefined. | |
Q_IMPLICIT constexpr | QJSPrimitiveValue (QJSPrimitiveUndefined undefined) noexcept |
Creates a QJSPrimitiveValue of value undefined and type Undefined. | |
Q_IMPLICIT constexpr | QJSPrimitiveValue (QJSPrimitiveNull null) noexcept |
Creates a QJSPrimitiveValue of value null and type Null. | |
Q_IMPLICIT constexpr | QJSPrimitiveValue (bool value) noexcept |
Creates a QJSPrimitiveValue of value value and type Boolean. | |
Q_IMPLICIT constexpr | QJSPrimitiveValue (int value) noexcept |
Creates a QJSPrimitiveValue of value value and type Integer. | |
Q_IMPLICIT constexpr | QJSPrimitiveValue (double value) noexcept |
Creates a QJSPrimitiveValue of value value and type Double. | |
Q_IMPLICIT | QJSPrimitiveValue (QString string) noexcept |
Creates a QJSPrimitiveValue of value value and type String. | |
QJSPrimitiveValue (const QMetaType type, const void *value) noexcept | |
QJSPrimitiveValue (QMetaType type) noexcept | |
QJSPrimitiveValue (const QVariant &variant) noexcept | |
Creates a QJSPrimitiveValue from the contents of value if those contents can be stored in QJSPrimtiveValue. | |
constexpr QMetaType | metaType () const |
constexpr void * | data () |
constexpr const void * | data () const |
constexpr const void * | constData () const |
template<Type type> | |
QJSPrimitiveValue | to () const |
constexpr bool | toBoolean () const |
Returns the value coerced a boolean by JavaScript rules. | |
constexpr int | toInteger () const |
Returns the value coerced to an integral 32bit number by the rules JavaScript would apply when preparing it for a bit shift operation. | |
constexpr double | toDouble () const |
Returns the value coerced to a JavaScript Number by JavaScript rules. | |
QString | toString () const |
Returns the value coerced to a JavaScript String by JavaScript rules. | |
QVariant | toVariant () const |
QJSPrimitiveValue & | operator++ () |
QJSPrimitiveValue | operator++ (int) |
QJSPrimitiveValue & | operator-- () |
QJSPrimitiveValue | operator-- (int) |
QJSPrimitiveValue | operator+ () |
QJSPrimitiveValue | operator- () |
constexpr bool | strictlyEquals (const QJSPrimitiveValue &other) const |
Performs the JavaScript '===' operation on this QJSPrimitiveValue and other, and returns the result. | |
constexpr bool | equals (const QJSPrimitiveValue &other) const |
Performs the JavaScript '==' operation on this QJSPrimitiveValue and other, and returns the result. | |
The QJSPrimitiveValue class operates on primitive types in JavaScript semantics.
\inmodule QtQml
QJSPrimitiveValue supports most of the primitive types defined in the \l{ECMA-262} standard, in particular Undefined, Boolean, Number, and String. Additionally, you can store a JavaScript null in a QJSPrimitiveValue and as a special case of Number, you can store an integer value.
All those values are stored immediately, without interacting with the JavaScript heap. Therefore, you can pass QJSPrimitiveValues between different JavaScript engines. In contrast to QJSManagedValue, there is also no danger in destroying a QJSPrimitiveValue from a different thread than it was created in. On the flip side, QJSPrimitiveValue does not hold a reference to any JavaScript engine.
QJSPrimitiveValue implements the JavaScript arithmetic and comparison operators on the supported types in JavaScript semantics. Types are coerced like the JavaScript engine would coerce them if the operators were written in a JavaScript expression.
The JavaScript Symbol type is not supported as it is of very limited utility regarding arithmetic and comparison operators, the main purpose of QJSPrimitiveValue. In particular, it causes an exception whenever you try to coerce it to a number or a string, and we cannot throw exceptions without a JavaScript Engine.
Definition at line 24 of file qjsprimitivevalue.h.
enum QJSPrimitiveValue::Type : quint8 |
This enum speicifies the types a QJSPrimitiveValue might contain.
\value Undefined The JavaScript Undefined value. \value Null The JavaScript null value. This is in fact not a separate JavaScript type but a special value of the Object type. As it is very common and storable without JavaScript engine, it is still supported. \value Boolean A JavaScript Boolean value. \value Integer An integer. This is a special case of the JavaScript Number type. JavaScript does not have an actual integer type, but the \l{ECMA-262} standard contains rules on how to transform a Number in order to prepare it for certain operators that only make sense on integers, in particular the bit shift operators. QJSPrimitiveValue's Integer type represents the result of such a transformation. \value Double A JavaScript Number value. \value String A JavaScript String value.
Enumerator | |
---|---|
Undefined | |
Null | |
Boolean | |
Integer | |
Double | |
String |
Definition at line 117 of file qjsprimitivevalue.h.
|
delete |
|
constexprdefaultnoexcept |
Creates a QJSPrimitiveValue of type Undefined.
Referenced by equals(), and strictlyEquals().
|
inlineconstexprnoexcept |
Creates a QJSPrimitiveValue of value undefined and type Undefined.
Definition at line 132 of file qjsprimitivevalue.h.
|
inlineconstexprnoexcept |
Creates a QJSPrimitiveValue of value null and type Null.
Definition at line 133 of file qjsprimitivevalue.h.
|
inlineconstexprnoexcept |
Creates a QJSPrimitiveValue of value value and type Boolean.
Definition at line 134 of file qjsprimitivevalue.h.
|
inlineconstexprnoexcept |
Creates a QJSPrimitiveValue of value value and type Integer.
Definition at line 135 of file qjsprimitivevalue.h.
|
inlineconstexprnoexcept |
Creates a QJSPrimitiveValue of value value and type Double.
Definition at line 136 of file qjsprimitivevalue.h.
|
inlinenoexcept |
Creates a QJSPrimitiveValue of value value and type String.
Definition at line 137 of file qjsprimitivevalue.h.
|
inlineexplicitnoexcept |
Creates a QJSPrimitiveValue of type type, and initializes with value if type can be stored in QJSPrimtiveValue. value must not be nullptr in that case. If type cannot be stored this results in a QJSPrimitiveValue of type Undefined.
Note that you have to pass the address of the variable you want stored.
Usually, you never have to use this constructor, use the one taking QVariant instead.
Definition at line 139 of file qjsprimitivevalue.h.
References QMetaType::UnknownType.
|
inlineexplicitnoexcept |
Creates a QJSPrimitiveValue of type type, and initializes with a default-constructed value if type can be stored in QJSPrimtiveValue. If type cannot be stored this results in a QJSPrimitiveValue of type Undefined.
Definition at line 166 of file qjsprimitivevalue.h.
References QMetaType::UnknownType.
|
inlineexplicitnoexcept |
Creates a QJSPrimitiveValue from the contents of value if those contents can be stored in QJSPrimtiveValue.
Otherwise this results in a QJSPrimitiveValue of type Undefined.
Definition at line 193 of file qjsprimitivevalue.h.
|
inlineconstexpr |
Definition at line 201 of file qjsprimitivevalue.h.
|
inlineconstexpr |
Returns a pointer to the contained data as a generic void* that can be written to.
Definition at line 199 of file qjsprimitivevalue.h.
|
inlineconstexpr |
Returns a pointer to the contained value as a generic void* that cannot be written to.
Definition at line 200 of file qjsprimitivevalue.h.
|
inlineconstexpr |
Performs the JavaScript '==' operation on this QJSPrimitiveValue and other, and returns the result.
Definition at line 433 of file qjsprimitivevalue.h.
References QJSPrimitiveValue(), Boolean, Double, Integer, Null, other(), strictlyEquals(), String, type(), and Undefined.
|
inlineconstexpr |
Returns the QMetaType of the value stored in the QJSPrimitiveValue.
Definition at line 198 of file qjsprimitivevalue.h.
|
inline |
Definition at line 383 of file qjsprimitivevalue.h.
|
inline |
Definition at line 357 of file qjsprimitivevalue.h.
|
inline |
Definition at line 363 of file qjsprimitivevalue.h.
References other().
|
inline |
Definition at line 389 of file qjsprimitivevalue.h.
|
inline |
Definition at line 371 of file qjsprimitivevalue.h.
|
inline |
Definition at line 376 of file qjsprimitivevalue.h.
References other().
|
inlineconstexpr |
Performs the JavaScript '===' operation on this QJSPrimitiveValue and other, and returns the result.
Definition at line 394 of file qjsprimitivevalue.h.
References QJSPrimitiveValue(), Boolean, Double, QJSNumberCoercion::equals(), Integer, Null, other(), qIsNull(), strictlyEquals(), String, type(), and Undefined.
Referenced by equals(), and strictlyEquals().
|
inline |
Coerces the value to the specified type and returns the result as a new QJSPrimitiveValue.
Definition at line 204 of file qjsprimitivevalue.h.
References Boolean, Double, Integer, Null, String, toBoolean(), toDouble(), toInteger(), toString(), and Undefined.
|
inlineconstexpr |
Returns the value coerced a boolean by JavaScript rules.
Definition at line 221 of file qjsprimitivevalue.h.
References Boolean, Double, QJSNumberCoercion::equals(), Integer, QString::isEmpty(), Null, String, type(), and Undefined.
Referenced by to().
|
inlineconstexpr |
Returns the value coerced to a JavaScript Number by JavaScript rules.
Definition at line 254 of file qjsprimitivevalue.h.
References Boolean, Double, Integer, Null, String, toDouble(), type(), and Undefined.
Referenced by to(), and toDouble().
|
inlineconstexpr |
Returns the value coerced to an integral 32bit number by the rules JavaScript would apply when preparing it for a bit shift operation.
Definition at line 239 of file qjsprimitivevalue.h.
References Boolean, Double, Integer, Null, String, toInteger(), type(), and Undefined.
Referenced by to(), and toInteger().
|
inline |
Returns the value coerced to a JavaScript String by JavaScript rules.
Definition at line 269 of file qjsprimitivevalue.h.
References Boolean, Double, Integer, Null, QString::number(), QStringLiteral, String, toString(), type(), and Undefined.
Referenced by to(), and toString().
|
inline |
|
inlineconstexpr |
Returns the type of the QJSPrimitiveValue.
Definition at line 126 of file qjsprimitivevalue.h.
Referenced by equals(), QV4::ExecutionEngine::fromData(), strictlyEquals(), toBoolean(), toDouble(), toInteger(), toString(), and toVariant().
|
friend |
Performs the JavaScript '!==' operation on lhs and rhs, and returns the result.
Definition at line 469 of file qjsprimitivevalue.h.
|
friend |
Definition at line 330 of file qjsprimitivevalue.h.
|
friend |
Performs the JavaScript '*' operation on lhs and rhs, and returns the result.
Definition at line 318 of file qjsprimitivevalue.h.
|
friend |
Perfoms the JavaScript '+' operation on lhs and rhs, and returns the result.
Definition at line 306 of file qjsprimitivevalue.h.
|
friend |
Performs the JavaScript '-' operation on lhs and rhs, and returns the result.
Definition at line 312 of file qjsprimitivevalue.h.
|
friend |
Performs the JavaScript '/' operation between lhs and rhs, and returns the result.
Definition at line 324 of file qjsprimitivevalue.h.
|
friend |
Performs the JavaScript '<' operation on lhs and rhs, and returns the result.
Definition at line 475 of file qjsprimitivevalue.h.
|
friend |
Performs the JavaScript '<=' operation on lhs and rhs, and returns the result.
Definition at line 546 of file qjsprimitivevalue.h.
|
friend |
Performs the JavaScript '===' operation on lhs and rhs, and returns the result.
Definition at line 463 of file qjsprimitivevalue.h.
|
friend |
Performs the JavaScript '>' operation on lhs and rhs, and returns the result.
Definition at line 541 of file qjsprimitivevalue.h.
|
friend |
Performs the JavaScript '>=' operation on lhs and rhs, and returns the result.
Definition at line 562 of file qjsprimitivevalue.h.
|
friend |
Definition at line 579 of file qjsprimitivevalue.h.
|
friend |
Definition at line 580 of file qjsprimitivevalue.h.
|
friend |
Definition at line 581 of file qjsprimitivevalue.h.