![]() |
Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
|
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 25 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 118 of file qjsprimitivevalue.h.
|
delete |
|
constexprdefaultnoexcept |
Creates a QJSPrimitiveValue of type Undefined.
|
inlineconstexprnoexcept |
Creates a QJSPrimitiveValue of value undefined and type Undefined.
Definition at line 133 of file qjsprimitivevalue.h.
|
inlineconstexprnoexcept |
Creates a QJSPrimitiveValue of value null and type Null.
Definition at line 134 of file qjsprimitivevalue.h.
|
inlineconstexprnoexcept |
Creates a QJSPrimitiveValue of value value and type Boolean.
Definition at line 135 of file qjsprimitivevalue.h.
|
inlineconstexprnoexcept |
Creates a QJSPrimitiveValue of value value and type Integer.
Definition at line 136 of file qjsprimitivevalue.h.
|
inlineconstexprnoexcept |
Creates a QJSPrimitiveValue of value value and type Double.
Definition at line 137 of file qjsprimitivevalue.h.
|
inlinenoexcept |
Creates a QJSPrimitiveValue of value value and type String.
Definition at line 138 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 140 of file qjsprimitivevalue.h.
|
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 167 of file qjsprimitivevalue.h.
|
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 194 of file qjsprimitivevalue.h.
|
inlineconstexpr |
Definition at line 202 of file qjsprimitivevalue.h.
|
inlineconstexpr |
Returns a pointer to the contained data as a generic void* that can be written to.
Definition at line 200 of file qjsprimitivevalue.h.
|
inlineconstexpr |
Returns a pointer to the contained value as a generic void* that cannot be written to.
Definition at line 201 of file qjsprimitivevalue.h.
|
inlineconstexpr |
Performs the JavaScript '==' operation on this QJSPrimitiveValue and other, and returns the result.
Definition at line 451 of file qjsprimitivevalue.h.
References Boolean, Double, equals(), Integer, Null, strictlyEquals(), String, type(), and Undefined.
Referenced by equals().
|
inlineconstexpr |
Returns the QMetaType of the value stored in the QJSPrimitiveValue.
Definition at line 199 of file qjsprimitivevalue.h.
|
inline |
Definition at line 401 of file qjsprimitivevalue.h.
Referenced by operator++(), and operator--().
|
inline |
Definition at line 375 of file qjsprimitivevalue.h.
|
inline |
Definition at line 381 of file qjsprimitivevalue.h.
References operator+().
|
inline |
Definition at line 407 of file qjsprimitivevalue.h.
|
inline |
Definition at line 389 of file qjsprimitivevalue.h.
|
inline |
Definition at line 394 of file qjsprimitivevalue.h.
References operator+().
|
inlineconstexpr |
Performs the JavaScript '===' operation on this QJSPrimitiveValue and other, and returns the result.
Definition at line 412 of file qjsprimitivevalue.h.
References Boolean, Double, Integer, Null, strictlyEquals(), type(), and Undefined.
Referenced by equals(), operator!=, operator==, and strictlyEquals().
|
inline |
Coerces the value to the specified type and returns the result as a new QJSPrimitiveValue.
Definition at line 205 of file qjsprimitivevalue.h.
References Boolean, Double, Integer, Null, toBoolean(), toDouble(), toInteger(), and Undefined.
|
inlineconstexpr |
|
inlineconstexpr |
Returns the value coerced to a JavaScript Number by JavaScript rules.
Definition at line 263 of file qjsprimitivevalue.h.
References Boolean, Double, Integer, Null, String, type(), and Undefined.
Referenced by operator%, operator<, and to().
|
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 244 of file qjsprimitivevalue.h.
References Boolean, Integer, Null, String, type(), and Undefined.
Referenced by operator%, and to().
|
inline |
|
inline |
|
inlineconstexpr |
Returns the type of the QJSPrimitiveValue.
Definition at line 127 of file qjsprimitivevalue.h.
Referenced by equals(), operator%, operator<, operator<=, operator>=, strictlyEquals(), toBoolean(), toDouble(), toInteger(), toString(), and toVariant().
|
friend |
Performs the JavaScript '!==' operation on lhs and rhs, and returns the result.
Definition at line 487 of file qjsprimitivevalue.h.
References strictlyEquals().
|
friend |
Definition at line 343 of file qjsprimitivevalue.h.
References Boolean, Double, Integer, Null, String, toDouble(), toInteger(), type(), and Undefined.
|
friend |
Performs the JavaScript '*' operation on lhs and rhs, and returns the result.
Definition at line 331 of file qjsprimitivevalue.h.
|
friend |
Perfoms the JavaScript '+' operation on lhs and rhs, and returns the result.
Definition at line 319 of file qjsprimitivevalue.h.
|
friend |
Performs the JavaScript '-' operation on lhs and rhs, and returns the result.
Definition at line 325 of file qjsprimitivevalue.h.
|
friend |
Performs the JavaScript '/' operation between lhs and rhs, and returns the result.
Definition at line 337 of file qjsprimitivevalue.h.
|
friend |
Performs the JavaScript '<' operation on lhs and rhs, and returns the result.
Definition at line 493 of file qjsprimitivevalue.h.
References Boolean, Double, Integer, Null, String, toDouble(), type(), and Undefined.
Referenced by operator>, and operator>=.
|
friend |
Performs the JavaScript '<=' operation on lhs and rhs, and returns the result.
Definition at line 564 of file qjsprimitivevalue.h.
|
friend |
Performs the JavaScript '===' operation on lhs and rhs, and returns the result.
Definition at line 481 of file qjsprimitivevalue.h.
References strictlyEquals().
|
friend |
Performs the JavaScript '>' operation on lhs and rhs, and returns the result.
Definition at line 559 of file qjsprimitivevalue.h.
References operator<.
Referenced by operator<=.
|
friend |
Performs the JavaScript '>=' operation on lhs and rhs, and returns the result.
Definition at line 580 of file qjsprimitivevalue.h.
|
friend |
Definition at line 597 of file qjsprimitivevalue.h.
|
friend |
Definition at line 598 of file qjsprimitivevalue.h.
|
friend |
Definition at line 599 of file qjsprimitivevalue.h.