Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
QJSPrimitiveValue Class Reference

The QJSPrimitiveValue class operates on primitive types in JavaScript semantics. More...

#include <qjsprimitivevalue.h>

+ Collaboration diagram for QJSPrimitiveValue:

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 voiddata ()
 
constexpr const voiddata () const
 
constexpr const voidconstData () 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
 
QJSPrimitiveValueoperator++ ()
 
QJSPrimitiveValue operator++ (int)
 
QJSPrimitiveValueoperator-- ()
 
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.
 

Friends

class QJSManagedValue
 
class QJSValue
 
struct QV4::ExecutionEngine
 
QJSPrimitiveValue operator+ (const QJSPrimitiveValue &lhs, const QJSPrimitiveValue &rhs)
 
QJSPrimitiveValue operator- (const QJSPrimitiveValue &lhs, const QJSPrimitiveValue &rhs)
 
QJSPrimitiveValue operator* (const QJSPrimitiveValue &lhs, const QJSPrimitiveValue &rhs)
 
QJSPrimitiveValue operator/ (const QJSPrimitiveValue &lhs, const QJSPrimitiveValue &rhs)
 
QJSPrimitiveValue operator% (const QJSPrimitiveValue &lhs, const QJSPrimitiveValue &rhs)
 
constexpr bool operator== (const QJSPrimitiveValue &lhs, const QJSPrimitiveValue &rhs)
 
constexpr bool operator!= (const QJSPrimitiveValue &lhs, const QJSPrimitiveValue &rhs)
 
constexpr bool operator< (const QJSPrimitiveValue &lhs, const QJSPrimitiveValue &rhs)
 
constexpr bool operator> (const QJSPrimitiveValue &lhs, const QJSPrimitiveValue &rhs)
 
constexpr bool operator<= (const QJSPrimitiveValue &lhs, const QJSPrimitiveValue &rhs)
 
constexpr bool operator>= (const QJSPrimitiveValue &lhs, const QJSPrimitiveValue &rhs)
 

Detailed Description

The QJSPrimitiveValue class operates on primitive types in JavaScript semantics.

Since
6.1

\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.

Member Enumeration Documentation

◆ Type

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.

Constructor & Destructor Documentation

◆ QJSPrimitiveValue() [1/11]

QJSPrimitiveValue::QJSPrimitiveValue ( Type )
delete

◆ QJSPrimitiveValue() [2/11]

QJSPrimitiveValue::QJSPrimitiveValue ( )
constexprdefaultnoexcept

Creates a QJSPrimitiveValue of type Undefined.

Referenced by equals(), and strictlyEquals().

+ Here is the caller graph for this function:

◆ QJSPrimitiveValue() [3/11]

QJSPrimitiveValue::QJSPrimitiveValue ( QJSPrimitiveUndefined undefined)
inlineconstexprnoexcept

Creates a QJSPrimitiveValue of value undefined and type Undefined.

Definition at line 132 of file qjsprimitivevalue.h.

◆ QJSPrimitiveValue() [4/11]

QJSPrimitiveValue::QJSPrimitiveValue ( QJSPrimitiveNull null)
inlineconstexprnoexcept

Creates a QJSPrimitiveValue of value null and type Null.

Definition at line 133 of file qjsprimitivevalue.h.

◆ QJSPrimitiveValue() [5/11]

QJSPrimitiveValue::QJSPrimitiveValue ( bool value)
inlineconstexprnoexcept

Creates a QJSPrimitiveValue of value value and type Boolean.

Definition at line 134 of file qjsprimitivevalue.h.

◆ QJSPrimitiveValue() [6/11]

QJSPrimitiveValue::QJSPrimitiveValue ( int value)
inlineconstexprnoexcept

Creates a QJSPrimitiveValue of value value and type Integer.

Definition at line 135 of file qjsprimitivevalue.h.

◆ QJSPrimitiveValue() [7/11]

QJSPrimitiveValue::QJSPrimitiveValue ( double value)
inlineconstexprnoexcept

Creates a QJSPrimitiveValue of value value and type Double.

Definition at line 136 of file qjsprimitivevalue.h.

◆ QJSPrimitiveValue() [8/11]

QJSPrimitiveValue::QJSPrimitiveValue ( QString string)
inlinenoexcept

Creates a QJSPrimitiveValue of value value and type String.

Definition at line 137 of file qjsprimitivevalue.h.

◆ QJSPrimitiveValue() [9/11]

QJSPrimitiveValue::QJSPrimitiveValue ( const QMetaType type,
const void * value )
inlineexplicitnoexcept
Since
6.4

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.

◆ QJSPrimitiveValue() [10/11]

QJSPrimitiveValue::QJSPrimitiveValue ( QMetaType type)
inlineexplicitnoexcept
Since
6.6

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.

◆ QJSPrimitiveValue() [11/11]

QJSPrimitiveValue::QJSPrimitiveValue ( const QVariant & value)
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.

Member Function Documentation

◆ constData()

const void * QJSPrimitiveValue::constData ( ) const
inlineconstexpr

Definition at line 201 of file qjsprimitivevalue.h.

◆ data() [1/2]

const void * QJSPrimitiveValue::data ( )
inlineconstexpr
Since
6.6

Returns a pointer to the contained data as a generic void* that can be written to.

Definition at line 199 of file qjsprimitivevalue.h.

◆ data() [2/2]

const void * QJSPrimitiveValue::data ( ) const
inlineconstexpr
Since
6.6

Returns a pointer to the contained value as a generic void* that cannot be written to.

Definition at line 200 of file qjsprimitivevalue.h.

◆ equals()

bool QJSPrimitiveValue::equals ( const QJSPrimitiveValue & other) const
inlineconstexpr

Performs the JavaScript '==' operation on this QJSPrimitiveValue and other, and returns the result.

Definition at line 445 of file qjsprimitivevalue.h.

References QJSPrimitiveValue(), Boolean, Double, Integer, Null, other(), strictlyEquals(), String, type(), and Undefined.

+ Here is the call graph for this function:

◆ metaType()

QMetaType QJSPrimitiveValue::metaType ( ) const
inlineconstexpr
Since
6.6

Returns the QMetaType of the value stored in the QJSPrimitiveValue.

Definition at line 198 of file qjsprimitivevalue.h.

Referenced by QV4::ExactMatch().

+ Here is the caller graph for this function:

◆ operator+()

QJSPrimitiveValue QJSPrimitiveValue::operator+ ( )
inline

Definition at line 395 of file qjsprimitivevalue.h.

◆ operator++() [1/2]

QJSPrimitiveValue & QJSPrimitiveValue::operator++ ( )
inline

Definition at line 369 of file qjsprimitivevalue.h.

◆ operator++() [2/2]

QJSPrimitiveValue QJSPrimitiveValue::operator++ ( int )
inline

Definition at line 375 of file qjsprimitivevalue.h.

References other().

+ Here is the call graph for this function:

◆ operator-()

QJSPrimitiveValue QJSPrimitiveValue::operator- ( )
inline

Definition at line 401 of file qjsprimitivevalue.h.

◆ operator--() [1/2]

QJSPrimitiveValue & QJSPrimitiveValue::operator-- ( )
inline

Definition at line 383 of file qjsprimitivevalue.h.

◆ operator--() [2/2]

QJSPrimitiveValue QJSPrimitiveValue::operator-- ( int )
inline

Definition at line 388 of file qjsprimitivevalue.h.

References other().

+ Here is the call graph for this function:

◆ strictlyEquals()

bool QJSPrimitiveValue::strictlyEquals ( const QJSPrimitiveValue & other) const
inlineconstexpr

Performs the JavaScript '===' operation on this QJSPrimitiveValue and other, and returns the result.

Definition at line 406 of file qjsprimitivevalue.h.

References QJSPrimitiveValue(), Boolean, Double, QJSNumberCoercion::equals(), Integer, Null, other(), qIsNull(), strictlyEquals(), String, type(), and Undefined.

Referenced by equals(), and strictlyEquals().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ to()

template<Type type>
template< QJSPrimitiveValue::Type type > QJSPrimitiveValue QJSPrimitiveValue::to ( ) const
inline
Since
6.6

Coerces the value to the specified type and returns the result as a new QJSPrimitiveValue.

See also
toBoolean(), toInteger(), toDouble(), toString()

Definition at line 204 of file qjsprimitivevalue.h.

References Boolean, Double, Integer, Null, String, toBoolean(), toDouble(), toInteger(), toString(), and Undefined.

+ Here is the call graph for this function:

◆ toBoolean()

bool QJSPrimitiveValue::toBoolean ( ) const
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().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ toDouble()

double QJSPrimitiveValue::toDouble ( ) const
inlineconstexpr

Returns the value coerced to a JavaScript Number by JavaScript rules.

Definition at line 262 of file qjsprimitivevalue.h.

References Boolean, Double, Integer, Null, String, type(), and Undefined.

Referenced by to().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ toInteger()

int QJSPrimitiveValue::toInteger ( ) const
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 243 of file qjsprimitivevalue.h.

References Boolean, Double, Integer, Null, String, type(), and Undefined.

Referenced by to().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ toString()

QString QJSPrimitiveValue::toString ( ) const
inline

Returns the value coerced to a JavaScript String by JavaScript rules.

Definition at line 281 of file qjsprimitivevalue.h.

References Boolean, Double, Integer, Null, QString::number(), QStringLiteral, String, toString(), type(), and Undefined.

Referenced by to(), and toString().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ toVariant()

QVariant QJSPrimitiveValue::toVariant ( ) const
inline

Definition at line 304 of file qjsprimitivevalue.h.

References Boolean, Double, Integer, Null, String, type(), and Undefined.

+ Here is the call graph for this function:

◆ type()

Type QJSPrimitiveValue::type ( ) const
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().

+ Here is the caller graph for this function:

Friends And Related Symbol Documentation

◆ operator!=

bool QJSPrimitiveValue::operator!= ( const QJSPrimitiveValue & lhs,
const QJSPrimitiveValue & rhs )
friend
Since
6.1

Performs the JavaScript '!==' operation on lhs and rhs, and returns the result.

Definition at line 481 of file qjsprimitivevalue.h.

◆ operator%

QJSPrimitiveValue operator% ( const QJSPrimitiveValue & lhs,
const QJSPrimitiveValue & rhs )
friend

Definition at line 342 of file qjsprimitivevalue.h.

◆ operator*

QJSPrimitiveValue QJSPrimitiveValue::operator* ( const QJSPrimitiveValue & lhs,
const QJSPrimitiveValue & rhs )
friend
Since
6.1

Performs the JavaScript '*' operation on lhs and rhs, and returns the result.

Definition at line 330 of file qjsprimitivevalue.h.

◆ operator+

QJSPrimitiveValue QJSPrimitiveValue::operator+ ( const QJSPrimitiveValue & lhs,
const QJSPrimitiveValue & rhs )
friend
Since
6.1

Perfoms the JavaScript '+' operation on lhs and rhs, and returns the result.

Definition at line 318 of file qjsprimitivevalue.h.

◆ operator-

QJSPrimitiveValue QJSPrimitiveValue::operator- ( const QJSPrimitiveValue & lhs,
const QJSPrimitiveValue & rhs )
friend
Since
6.1

Performs the JavaScript '-' operation on lhs and rhs, and returns the result.

Definition at line 324 of file qjsprimitivevalue.h.

◆ operator/

QJSPrimitiveValue QJSPrimitiveValue::operator/ ( const QJSPrimitiveValue & lhs,
const QJSPrimitiveValue & rhs )
friend
Since
6.1

Performs the JavaScript '/' operation between lhs and rhs, and returns the result.

Definition at line 336 of file qjsprimitivevalue.h.

◆ operator<

bool QJSPrimitiveValue::operator< ( const QJSPrimitiveValue & lhs,
const QJSPrimitiveValue & rhs )
friend
Since
6.1

Performs the JavaScript '<' operation on lhs and rhs, and returns the result.

Definition at line 487 of file qjsprimitivevalue.h.

◆ operator<=

bool QJSPrimitiveValue::operator<= ( const QJSPrimitiveValue & lhs,
const QJSPrimitiveValue & rhs )
friend
Since
6.1

Performs the JavaScript '<=' operation on lhs and rhs, and returns the result.

Definition at line 558 of file qjsprimitivevalue.h.

◆ operator==

bool QJSPrimitiveValue::operator== ( const QJSPrimitiveValue & lhs,
const QJSPrimitiveValue & rhs )
friend
Since
6.1

Performs the JavaScript '===' operation on lhs and rhs, and returns the result.

Definition at line 475 of file qjsprimitivevalue.h.

◆ operator>

bool QJSPrimitiveValue::operator> ( const QJSPrimitiveValue & lhs,
const QJSPrimitiveValue & rhs )
friend
Since
6.1

Performs the JavaScript '>' operation on lhs and rhs, and returns the result.

Definition at line 553 of file qjsprimitivevalue.h.

◆ operator>=

bool QJSPrimitiveValue::operator>= ( const QJSPrimitiveValue & lhs,
const QJSPrimitiveValue & rhs )
friend
Since
6.1

Performs the JavaScript '>=' operation on lhs and rhs, and returns the result.

Definition at line 574 of file qjsprimitivevalue.h.

◆ QJSManagedValue

friend class QJSManagedValue
friend

Definition at line 591 of file qjsprimitivevalue.h.

◆ QJSValue

friend class QJSValue
friend

Definition at line 592 of file qjsprimitivevalue.h.

◆ QV4::ExecutionEngine

friend struct QV4::ExecutionEngine
friend

Definition at line 593 of file qjsprimitivevalue.h.


The documentation for this class was generated from the following files: