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
QJSManagedValue Class Reference

\inmodule QtQml More...

#include <qjsmanagedvalue.h>

+ Collaboration diagram for QJSManagedValue:

Public Types

enum  Type {
  Undefined , Boolean , Number , String ,
  Object , Symbol , Function
}
 This enum represents the JavaScript native types, as specified by \l{ECMA-262}. More...
 

Public Member Functions

 QJSManagedValue ()=default
 Creates a QJSManagedValue that represents the JavaScript undefined value.
 
 QJSManagedValue (QJSValue value, QJSEngine *engine)
 Creates a QJSManagedValue from value, using the heap of engine.
 
 QJSManagedValue (const QJSPrimitiveValue &value, QJSEngine *engine)
 Creates a QJSManagedValue from value using the heap of engine.
 
 QJSManagedValue (const QVariant &variant, QJSEngine *engine)
 Creates a QJSManagedValue from variant using the heap of engine.
 
 QJSManagedValue (const QString &string, QJSEngine *engine)
 Creates a QJSManagedValue from string using the heap of engine.
 
 ~QJSManagedValue ()
 Destroys the QJSManagedValue.
 
 QJSManagedValue (QJSManagedValue &&other)
 Move-constructs a QJSManagedValue from other.
 
QJSManagedValueoperator= (QJSManagedValue &&other)
 Move-assigns a QJSManagedValue from other.
 
bool equals (const QJSManagedValue &other) const
 Invokes the JavaScript '==' operator on this QJSManagedValue and other, and returns the result.
 
bool strictlyEquals (const QJSManagedValue &other) const
 Invokes the JavaScript '===' operator on this QJSManagedValue and other, and returns the result.
 
QJSEngineengine () const
 Returns the QJSEngine this QJSManagedValue belongs to.
 
QJSManagedValue prototype () const
 Returns the prototype for this QJSManagedValue.
 
void setPrototype (const QJSManagedValue &prototype)
 Sets the prototype of this QJSManagedValue to prototype.
 
Type type () const
 Returns the JavaScript type of this QJSManagedValue.
 
bool isUndefined () const
 Returns true if the type of this QJSManagedValue is undefined, or false otherwise.
 
bool isBoolean () const
 Returns true if the type of this QJSManagedValue is boolean, or false otherwise.
 
bool isNumber () const
 Returns true if the type of this QJSManagedValue is number, or false otherwise.
 
bool isString () const
 Returns true if the type of this QJSManagedValue is string, or false otherwise.
 
bool isObject () const
 Returns true if the type of this QJSManagedValue is object, or false otherwise.
 
bool isSymbol () const
 Returns true if the type of this QJSManagedValue is symbol, or false otherwise.
 
bool isFunction () const
 Returns true if the type of this QJSManagedValue is function, false otherwise.
 
bool isInteger () const
 Returns true if this QJSManagedValue holds an integer value, or false otherwise.
 
bool isNull () const
 Returns true if this QJSManagedValue holds the JavaScript null value, or false otherwise.
 
bool isRegularExpression () const
 Returns true if this value represents a JavaScript regular expression object, or false otherwise.
 
bool isArray () const
 Returns true if this value represents a JavaScript Array object, or false otherwise.
 
bool isUrl () const
 Returns true if this value represents a JavaScript Url object, or false otherwise.
 
bool isVariant () const
 Returns true if this value represents a QVariant managed on the JavaScript heap, or false otherwise.
 
bool isQObject () const
 Returns true if this value represents a QObject pointer managed on the JavaScript heap, or false otherwise.
 
bool isQMetaObject () const
 Returns true if this value represents a QMetaObject pointer managed on the JavaScript heap, or false otherwise.
 
bool isDate () const
 Returns true if this value represents a JavaScript Date object, or false otherwise.
 
bool isError () const
 Returns true if this value represents a JavaScript Error object, or false otherwise.
 
bool isJsMetaType () const
 
QString toString () const
 Converts the manged value to a string.
 
double toNumber () const
 Converts the manged value to a number.
 
bool toBoolean () const
 Converts the manged value to a boolean.
 
QJSPrimitiveValue toPrimitive () const
 Converts the manged value to a QJSPrimitiveValue.
 
QJSValue toJSValue () const
 Copies this QJSManagedValue into a new QJSValue.
 
QVariant toVariant () const
 Copies this QJSManagedValue into a new QVariant.
 
int toInteger () const
 Converts the manged value to an integer.
 
QRegularExpression toRegularExpression () const
 If this QJSManagedValue holds a JavaScript regular expression object, returns an equivalent QRegularExpression.
 
QUrl toUrl () const
 If this QJSManagedValue holds a JavaScript Url object, returns an equivalent QUrl.
 
QObjecttoQObject () const
 If this QJSManagedValue holds a QObject pointer, returns it.
 
const QMetaObjecttoQMetaObject () const
 If this QJSManagedValue holds a QMetaObject pointer, returns it.
 
QDateTime toDateTime () const
 If this QJSManagedValue holds a JavaScript Date object, returns an equivalent QDateTime.
 
bool hasProperty (const QString &name) const
 Returns true if this QJSManagedValue has a property name, otherwise returns false.
 
bool hasOwnProperty (const QString &name) const
 Returns true if this QJSManagedValue has a property name, otherwise returns false.
 
QJSValue property (const QString &name) const
 Returns the property name of this QJSManagedValue.
 
void setProperty (const QString &name, const QJSValue &value)
 Sets the property name to value on this QJSManagedValue.
 
bool deleteProperty (const QString &name)
 Deletes the property name from this QJSManagedValue.
 
bool hasProperty (quint32 arrayIndex) const
 Returns true if this QJSManagedValue has an array index arrayIndex, otherwise returns false.
 
bool hasOwnProperty (quint32 arrayIndex) const
 Returns true if this QJSManagedValue has an array index arrayIndex, otherwise returns false.
 
QJSValue property (quint32 arrayIndex) const
 Returns the property stored at arrayIndex of this QJSManagedValue.
 
void setProperty (quint32 arrayIndex, const QJSValue &value)
 Stores the value at arrayIndex in this QJSManagedValue.
 
bool deleteProperty (quint32 arrayIndex)
 Deletes the value stored at arrayIndex from this QJSManagedValue.
 
QJSValue call (const QJSValueList &arguments={}) const
 If this QJSManagedValue represents a JavaScript FunctionObject, calls it with the given arguments, and returns the result.
 
QJSValue callWithInstance (const QJSValue &instance, const QJSValueList &arguments={}) const
 If this QJSManagedValue represents a JavaScript FunctionObject, calls it on instance with the given arguments, and returns the result.
 
QJSValue callAsConstructor (const QJSValueList &arguments={}) const
 If this QJSManagedValue represents a JavaScript FunctionObject, calls it as constructor with the given arguments, and returns the result.
 
QJSManagedValue jsMetaType () const
 
QStringList jsMetaMembers () const
 
QJSManagedValue jsMetaInstantiate (const QJSValueList &values={}) const
 

Friends

class QJSValue
 
class QJSEngine
 

Detailed Description

\inmodule QtQml

Since
6.1

\inmodule QtQml

QJSManagedValue represents a value on the JavaScript heap belonging to a QJSEngine.

The QJSManagedValue class allows interaction with JavaScript values in most ways you can interact with them from JavaScript itself. You can get and set properties and prototypes, and you can access arrays. Additionally, you can transform the value into the Qt counterparts of JavaScript objects. For example, a Url object may be transformed into a QUrl.

A QJSManagedValue is always bound to a particular QJSEngine. You cannot use it independently. This means that you cannot have a QJSManagedValue from one engine be a property or a proptotype of a QJSManagedValue from a different engine.

In contrast to QJSValue, almost all values held by QJSManagedValue live on the JavaScript heap. There is no inline or unmanaged storage. Therefore, you can get the prototype of a primitive value, and you can get the length property of a string.

Only default-constructed or moved-from QJSManagedValues do not hold a value on the JavaScript heap. They represent undefined, which doesn't have any properties or prototypes.

Also in contrast to QJSValue, QJSManagedValue does not catch any JavaScript exceptions. If an operation on a QJSManagedValue causes an error, it will generally return an undefined value and QJSEngine::hasError() will return true afterwards. You can then catch the exception using QJSEngine::catchError(), or pass it up the stack, at your own discretion.

Note
As the reference to the value on the JavaScript heap has to be freed on destruction, you cannot move a QJSManagedValue to a different thread. The destruction would take place in the new thread, which would create a race condition with the garbage collector on the original thread. This also means that you cannot hold a QJSManagedValue beyond the lifespan of its engine.

The recommended way of working with a QJSManagedValue is creating it on the stack, possibly by moving a QJSValue and adding an engine, then performing the necessary operations on it, and finally moving it back into a QJSValue for storage. Moving between QJSManagedValue and QJSValue is fast.

Definition at line 19 of file qjsmanagedvalue.h.

Member Enumeration Documentation

◆ Type

This enum represents the JavaScript native types, as specified by \l{ECMA-262}.

\value Undefined The undefined type \value Boolean The boolean type \value Number The number type \value String The string type \value Object The object type \value Symbol The symbol type \value Function The function type

Note that the null value is not a type of itself but rather a special kind of object. You can query a QJSManagedValue for this condition using the isNull() method. Furthermore, JavaScript has no integer type, but it knows a special treatment of numbers in preparation for integer only operations. You can query a QJSManagedValue to find out whether it holds the result of such a treatment by using the isInteger() method.

Enumerator
Undefined 
Boolean 
Number 
String 
Object 
Symbol 
Function 

Definition at line 23 of file qjsmanagedvalue.h.

Constructor & Destructor Documentation

◆ QJSManagedValue() [1/6]

QJSManagedValue::QJSManagedValue ( )
default

Creates a QJSManagedValue that represents the JavaScript undefined value.

This is the only value not stored on the JavaScript heap. Calling engine() on a default-constructed QJSManagedValue will return nullptr.

Referenced by jsMetaInstantiate(), jsMetaType(), and prototype().

+ Here is the caller graph for this function:

◆ QJSManagedValue() [2/6]

QJSManagedValue::QJSManagedValue ( QJSValue value,
QJSEngine * engine )

Creates a QJSManagedValue from value, using the heap of engine.

If value is itself managed and the engine it belongs to is not engine, the result is an undefined value, and a warning is generated.

Definition at line 120 of file qjsmanagedvalue.cpp.

References QV4::PersistentValueStorage::allocate(), QJSValuePrivate::asQString(), QJSValuePrivate::asReturnedValue(), engine(), QV4::PersistentValueStorage::free(), QJSEngine::handle(), QV4::MemoryManager::m_persistentValues, QV4::EngineBase::memoryManager, QV4::ExecutionEngine::newString(), Q_UNLIKELY, qWarning, QJSValuePrivate::takeManagedValue(), and v4Engine().

+ Here is the call graph for this function:

◆ QJSManagedValue() [3/6]

QJSManagedValue::QJSManagedValue ( const QJSPrimitiveValue & value,
QJSEngine * engine )

Creates a QJSManagedValue from value using the heap of engine.

Definition at line 147 of file qjsmanagedvalue.cpp.

References QJSPrimitiveValue::Boolean, QJSPrimitiveValue::Double, engine(), QJSEngine::handle(), QJSPrimitiveValue::Integer, QV4::ExecutionEngine::newString(), QV4::Encode::null(), QJSPrimitiveValue::Null, QJSPrimitiveValue::String, QV4::Encode::undefined(), and QJSPrimitiveValue::Undefined.

+ Here is the call graph for this function:

◆ QJSManagedValue() [4/6]

QJSManagedValue::QJSManagedValue ( const QVariant & variant,
QJSEngine * engine )

Creates a QJSManagedValue from variant using the heap of engine.

Definition at line 177 of file qjsmanagedvalue.cpp.

References engine(), QV4::ExecutionEngine::fromVariant(), QJSEngine::handle(), and variant.

+ Here is the call graph for this function:

◆ QJSManagedValue() [5/6]

QJSManagedValue::QJSManagedValue ( const QString & string,
QJSEngine * engine )

Creates a QJSManagedValue from string using the heap of engine.

Definition at line 186 of file qjsmanagedvalue.cpp.

References engine(), QJSEngine::handle(), and QV4::ExecutionEngine::newString().

+ Here is the call graph for this function:

◆ ~QJSManagedValue()

QJSManagedValue::~QJSManagedValue ( )

Destroys the QJSManagedValue.

Note
This frees the memory slot it holds on the JavaScript heap. You must not destroy a QJSManagedValue from a different thread than the one where the QJSEngine it belongs to lives.

Definition at line 199 of file qjsmanagedvalue.cpp.

References QV4::PersistentValueStorage::free().

+ Here is the call graph for this function:

◆ QJSManagedValue() [6/6]

QJSManagedValue::QJSManagedValue ( QJSManagedValue && other)

Move-constructs a QJSManagedValue from other.

This leaves other in the default-constructed state where it represents undefined and does not belong to any engine.

Definition at line 209 of file qjsmanagedvalue.cpp.

References other(), and qSwap().

+ Here is the call graph for this function:

Member Function Documentation

◆ call()

QJSValue QJSManagedValue::call ( const QJSValueList & arguments = {}) const

If this QJSManagedValue represents a JavaScript FunctionObject, calls it with the given arguments, and returns the result.

Otherwise returns a JavaScript undefined value.

The arguments have to be either primitive values or belong to the same QJSEngine as this QJSManagedValue. Otherwise the call is not carried out and a JavaScript undefined value is returned.

Definition at line 952 of file qjsmanagedvalue.cpp.

References arg, arguments, QJSValuePrivate::checkEngine(), QJSValuePrivate::convertToReturnedValue(), engine(), QJSValuePrivate::fromReturnedValue(), functionObjectForCall(), QJSEngine::globalObject(), i, Q_UNLIKELY, QJSValue, qWarning, and QList< T >::size().

+ Here is the call graph for this function:

◆ callAsConstructor()

QJSValue QJSManagedValue::callAsConstructor ( const QJSValueList & arguments = {}) const

If this QJSManagedValue represents a JavaScript FunctionObject, calls it as constructor with the given arguments, and returns the result.

Otherwise returns a JavaScript undefined value.

The arguments have to be either primitive values or belong to the same QJSEngine as this QJSManagedValue. Otherwise the call is not carried out and a JavaScript undefined value is returned.

Definition at line 1024 of file qjsmanagedvalue.cpp.

References arg, arguments, QJSValuePrivate::checkEngine(), QJSValuePrivate::convertToReturnedValue(), engine(), QJSValuePrivate::fromReturnedValue(), functionObjectForCall(), i, Q_UNLIKELY, QJSValue, qWarning, and QList< T >::size().

+ Here is the call graph for this function:

◆ callWithInstance()

QJSValue QJSManagedValue::callWithInstance ( const QJSValue & instance,
const QJSValueList & arguments = {} ) const

If this QJSManagedValue represents a JavaScript FunctionObject, calls it on instance with the given arguments, and returns the result.

Otherwise returns a JavaScript undefined value.

The arguments and the instance have to be either primitive values or belong to the same QJSEngine as this QJSManagedValue. Otherwise the call is not carried out and a JavaScript undefined value is returned.

Definition at line 984 of file qjsmanagedvalue.cpp.

References arg, arguments, QJSValuePrivate::checkEngine(), QJSValuePrivate::convertToReturnedValue(), engine(), QJSValuePrivate::fromReturnedValue(), functionObjectForCall(), i, Q_UNLIKELY, QJSValue, qWarning, and QList< T >::size().

+ Here is the call graph for this function:

◆ deleteProperty() [1/2]

bool QJSManagedValue::deleteProperty ( const QString & name)

Deletes the property name from this QJSManagedValue.

Returns true if the deletion succeeded, or false otherwise.

Definition at line 799 of file qjsmanagedvalue.cpp.

References QV4::Value::as(), QV4::IdentifierTable::asPropertyKey(), QV4::Scope::engine, and QV4::EngineBase::identifierTable.

+ Here is the call graph for this function:

◆ deleteProperty() [2/2]

bool QJSManagedValue::deleteProperty ( quint32 arrayIndex)

Deletes the value stored at arrayIndex from this QJSManagedValue.

Returns true if the deletion succeeded, or false otherwise.

Definition at line 917 of file qjsmanagedvalue.cpp.

References QV4::Value::as(), and QV4::PropertyKey::fromArrayIndex().

+ Here is the call graph for this function:

◆ engine()

QJSEngine * QJSManagedValue::engine ( ) const

Returns the QJSEngine this QJSManagedValue belongs to.

Mind that the engine is always valid, unless the QJSManagedValue is default-constructed or moved from. In the latter case a nullptr is returned.

Definition at line 270 of file qjsmanagedvalue.cpp.

References QV4::PersistentValueStorage::getEngine().

Referenced by QJSManagedValue(), QJSManagedValue(), QJSManagedValue(), QJSManagedValue(), call(), callAsConstructor(), callWithInstance(), QJSValuePrivate::encode(), and jsMetaInstantiate().

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

◆ equals()

bool QJSManagedValue::equals ( const QJSManagedValue & other) const

Invokes the JavaScript '==' operator on this QJSManagedValue and other, and returns the result.

See also
strictlyEquals

Definition at line 239 of file qjsmanagedvalue.cpp.

References QV4::Runtime::CompareEqual::call(), QV4::StaticValue::isNullOrUndefined(), and other().

+ Here is the call graph for this function:

◆ hasOwnProperty() [1/2]

bool QJSManagedValue::hasOwnProperty ( const QString & name) const

Returns true if this QJSManagedValue has a property name, otherwise returns false.

The properties of the prototype chain are not considered.

Definition at line 721 of file qjsmanagedvalue.cpp.

References QV4::Value::as(), QV4::IdentifierTable::asPropertyKey(), QV4::Attr_Invalid, QV4::Scope::engine, QV4::EngineBase::identifierTable, QV4::StaticValue::isNullOrUndefined(), QV4::Value::isString(), and QStringLiteral.

+ Here is the call graph for this function:

◆ hasOwnProperty() [2/2]

bool QJSManagedValue::hasOwnProperty ( quint32 arrayIndex) const

Returns true if this QJSManagedValue has an array index arrayIndex, otherwise returns false.

The properties of the prototype chain are not considered.

Definition at line 843 of file qjsmanagedvalue.cpp.

References QV4::Value::as(), QV4::Attr_Invalid, QV4::PropertyKey::fromArrayIndex(), and QV4::StaticValue::isNullOrUndefined().

+ Here is the call graph for this function:

◆ hasProperty() [1/2]

bool QJSManagedValue::hasProperty ( const QString & name) const

Returns true if this QJSManagedValue has a property name, otherwise returns false.

The properties of the prototype chain are considered.

Definition at line 700 of file qjsmanagedvalue.cpp.

References QV4::Value::as(), QV4::IdentifierTable::asPropertyKey(), QV4::Scope::engine, hasProperty(), QV4::EngineBase::identifierTable, QV4::StaticValue::isNullOrUndefined(), QV4::Value::isString(), prototype(), and QStringLiteral.

Referenced by hasProperty(), and hasProperty().

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

◆ hasProperty() [2/2]

bool QJSManagedValue::hasProperty ( quint32 arrayIndex) const

Returns true if this QJSManagedValue has an array index arrayIndex, otherwise returns false.

The properties of the prototype chain are considered.

Definition at line 818 of file qjsmanagedvalue.cpp.

References QV4::Value::as(), hasProperty(), QV4::StaticValue::isNullOrUndefined(), and prototype().

+ Here is the call graph for this function:

◆ isArray()

bool QJSManagedValue::isArray ( ) const

Returns true if this value represents a JavaScript Array object, or false otherwise.

Definition at line 445 of file qjsmanagedvalue.cpp.

References QV4::Value::as().

+ Here is the call graph for this function:

◆ isBoolean()

QJSManagedValue::isBoolean ( ) const
inline

Returns true if the type of this QJSManagedValue is boolean, or false otherwise.

Definition at line 55 of file qjsmanagedvalue.h.

◆ isDate()

bool QJSManagedValue::isDate ( ) const

Returns true if this value represents a JavaScript Date object, or false otherwise.

Definition at line 490 of file qjsmanagedvalue.cpp.

References QV4::Value::as().

+ Here is the call graph for this function:

◆ isError()

bool QJSManagedValue::isError ( ) const

Returns true if this value represents a JavaScript Error object, or false otherwise.

Definition at line 499 of file qjsmanagedvalue.cpp.

References QV4::Value::as().

+ Here is the call graph for this function:

◆ isFunction()

QJSManagedValue::isFunction ( ) const
inline

Returns true if the type of this QJSManagedValue is function, false otherwise.

Definition at line 60 of file qjsmanagedvalue.h.

◆ isInteger()

bool QJSManagedValue::isInteger ( ) const

Returns true if this QJSManagedValue holds an integer value, or false otherwise.

The storage format of a number does not affect the result of any operations performed on it, but if an integer is stored, many operations are faster.

Definition at line 427 of file qjsmanagedvalue.cpp.

References QV4::StaticValue::isInteger().

+ Here is the call graph for this function:

◆ isJsMetaType()

bool QJSManagedValue::isJsMetaType ( ) const

Returns true if this value represents a JavaScript meta type, or false otherwise.

Definition at line 510 of file qjsmanagedvalue.cpp.

References QV4::Value::as().

+ Here is the call graph for this function:

◆ isNull()

bool QJSManagedValue::isNull ( ) const

Returns true if this QJSManagedValue holds the JavaScript null value, or false otherwise.

Definition at line 416 of file qjsmanagedvalue.cpp.

References QV4::StaticValue::isNull().

+ Here is the call graph for this function:

◆ isNumber()

QJSManagedValue::isNumber ( ) const
inline

Returns true if the type of this QJSManagedValue is number, or false otherwise.

Definition at line 56 of file qjsmanagedvalue.h.

◆ isObject()

QJSManagedValue::isObject ( ) const
inline

Returns true if the type of this QJSManagedValue is object, or false otherwise.

Definition at line 58 of file qjsmanagedvalue.h.

◆ isQMetaObject()

bool QJSManagedValue::isQMetaObject ( ) const

Returns true if this value represents a QMetaObject pointer managed on the JavaScript heap, or false otherwise.

Definition at line 481 of file qjsmanagedvalue.cpp.

References QV4::Value::as().

+ Here is the call graph for this function:

◆ isQObject()

bool QJSManagedValue::isQObject ( ) const

Returns true if this value represents a QObject pointer managed on the JavaScript heap, or false otherwise.

Definition at line 472 of file qjsmanagedvalue.cpp.

References QV4::Value::as().

+ Here is the call graph for this function:

◆ isRegularExpression()

bool QJSManagedValue::isRegularExpression ( ) const

Returns true if this value represents a JavaScript regular expression object, or false otherwise.

Definition at line 436 of file qjsmanagedvalue.cpp.

References QV4::Value::as().

+ Here is the call graph for this function:

◆ isString()

QJSManagedValue::isString ( ) const
inline

Returns true if the type of this QJSManagedValue is string, or false otherwise.

Definition at line 57 of file qjsmanagedvalue.h.

◆ isSymbol()

QJSManagedValue::isSymbol ( ) const
inline

Returns true if the type of this QJSManagedValue is symbol, or false otherwise.

Definition at line 59 of file qjsmanagedvalue.h.

◆ isUndefined()

QJSManagedValue::isUndefined ( ) const
inline

Returns true if the type of this QJSManagedValue is undefined, or false otherwise.

Definition at line 54 of file qjsmanagedvalue.h.

References Undefined.

◆ isUrl()

bool QJSManagedValue::isUrl ( ) const

Returns true if this value represents a JavaScript Url object, or false otherwise.

Definition at line 454 of file qjsmanagedvalue.cpp.

References QV4::Value::as().

+ Here is the call graph for this function:

◆ isVariant()

bool QJSManagedValue::isVariant ( ) const

Returns true if this value represents a QVariant managed on the JavaScript heap, or false otherwise.

Definition at line 463 of file qjsmanagedvalue.cpp.

References QV4::Value::as().

+ Here is the call graph for this function:

◆ jsMetaInstantiate()

QJSManagedValue QJSManagedValue::jsMetaInstantiate ( const QJSValueList & values = {}) const

If this value is a JavaScript meta type, instantiates it using the values, and returns the result. Otherwise returns undefined.

The values are expected in the same order as the keys in the return value of members(), and that is the order in which properties were added to the object this meta type originally belongs to.

See also
members(), metaType(), isMetaType().

Definition at line 1113 of file qjsmanagedvalue.cpp.

References QJSManagedValue(), arg, QV4::Value::as(), QJSValuePrivate::checkEngine(), QJSValuePrivate::convertToReturnedValue(), engine(), i, o, Q_UNLIKELY, qMin(), and qWarning.

+ Here is the call graph for this function:

◆ jsMetaMembers()

QStringList QJSManagedValue::jsMetaMembers ( ) const

If this value is a JavaScript meta type, retrieves the names of its members The ordering of the names corresponds to the ordering of the values to be passed to instantiate().

If the value is not a meta type, an empty list is returned.

See also
isMetaType(), metaType(), instantiate()

Definition at line 1080 of file qjsmanagedvalue.cpp.

References QV4::Value::as(), and i.

+ Here is the call graph for this function:

◆ jsMetaType()

QJSManagedValue QJSManagedValue::jsMetaType ( ) const

Retrieves the JavaScript meta type of this value. The JavaScript meta type represents the layout of members in an object. Instantiating a meta type is faster than re-constructing the same object using a sequence of setProperty() calls on a new object.

See also
members(), instantiate()

Definition at line 1057 of file qjsmanagedvalue.cpp.

References QJSManagedValue(), QV4::Value::as(), and v4Engine().

+ Here is the call graph for this function:

◆ operator=()

QJSManagedValue & QJSManagedValue::operator= ( QJSManagedValue && other)

Move-assigns a QJSManagedValue from other.

This leaves other in the default-constructed state where it represents undefined and does not belong to any engine.

Note
This frees the memory slot this QJSManagedValue holds on the JavaScript heap. You must not move-assign a QJSManagedValue on a different thread than the one where the QJSEngine it belongs to lives.

Definition at line 223 of file qjsmanagedvalue.cpp.

References QV4::PersistentValueStorage::free(), other(), and qSwap().

+ Here is the call graph for this function:

◆ property() [1/2]

QJSValue QJSManagedValue::property ( const QString & name) const

Returns the property name of this QJSManagedValue.

The prototype chain is searched if the property is not found on the actual object.

Definition at line 742 of file qjsmanagedvalue.cpp.

References arg, QV4::Value::as(), QV4::IdentifierTable::asPropertyKey(), QV4::Scope::engine, QJSValuePrivate::fromReturnedValue(), QV4::EngineBase::identifierTable, QV4::StaticValue::isNullOrUndefined(), property(), prototype(), QJSValue, QStringLiteral, QV4::ExecutionEngine::throwTypeError(), and v4Engine().

Referenced by property(), and property().

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

◆ property() [2/2]

QJSValue QJSManagedValue::property ( quint32 arrayIndex) const

Returns the property stored at arrayIndex of this QJSManagedValue.

The prototype chain is searched if the property is not found on the actual object.

Definition at line 869 of file qjsmanagedvalue.cpp.

References QV4::Value::as(), QJSValuePrivate::fromReturnedValue(), QV4::StaticValue::isNullOrUndefined(), property(), prototype(), QJSValue, and QString::sliced().

+ Here is the call graph for this function:

◆ prototype()

QJSManagedValue QJSManagedValue::prototype ( ) const

Returns the prototype for this QJSManagedValue.

This works on any value. You can, for example retrieve the JavaScript boolean prototype from a boolean value.

Definition at line 284 of file qjsmanagedvalue.cpp.

References QJSManagedValue(), QV4::Value::as(), QV4::ExecutionEngine::booleanPrototype(), QV4::StaticValue::isBoolean(), QV4::StaticValue::isNumber(), managed(), QV4::Encode::null(), QV4::ExecutionEngine::numberPrototype(), prototype(), and v4Engine().

Referenced by hasProperty(), hasProperty(), property(), property(), prototype(), and setPrototype().

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

◆ setProperty() [1/2]

void QJSManagedValue::setProperty ( const QString & name,
const QJSValue & value )

Sets the property name to value on this QJSManagedValue.

This can only be done on JavaScript values of type object. Furhermore, value has to be either a primitive or belong to the same engine as this value.

Definition at line 772 of file qjsmanagedvalue.cpp.

References QV4::Value::as(), QV4::IdentifierTable::asPropertyKey(), QJSValuePrivate::convertToReturnedValue(), QJSValuePrivate::engine(), QV4::Scope::engine, QV4::EngineBase::identifierTable, QV4::StaticValue::isNullOrUndefined(), Q_UNLIKELY, QStringLiteral, qWarning, and v4Engine().

+ Here is the call graph for this function:

◆ setProperty() [2/2]

void QJSManagedValue::setProperty ( quint32 arrayIndex,
const QJSValue & value )

Stores the value at arrayIndex in this QJSManagedValue.

This can only be done on JavaScript values of type object, and it's not recommended if the value is not an array. Furhermore, value has to be either a primitive or belong to the same engine as this value.

Definition at line 897 of file qjsmanagedvalue.cpp.

References QV4::Value::as(), QJSValuePrivate::convertToReturnedValue(), QJSValuePrivate::engine(), Q_UNLIKELY, and qWarning.

+ Here is the call graph for this function:

◆ setPrototype()

void QJSManagedValue::setPrototype ( const QJSManagedValue & prototype)

Sets the prototype of this QJSManagedValue to prototype.

A precondition is that prototype belongs to the same QJSEngine as this QJSManagedValue and is an object (including null). Furthermore, this QJSManagedValue has to be an object (excluding null), too, and you cannot create prototype cycles.

Definition at line 314 of file qjsmanagedvalue.cpp.

References QV4::Value::as(), Object, prototype(), Q_UNLIKELY, qWarning, type(), and v4Engine().

+ Here is the call graph for this function:

◆ strictlyEquals()

bool QJSManagedValue::strictlyEquals ( const QJSManagedValue & other) const

Invokes the JavaScript '===' operator on this QJSManagedValue and other, and returns the result.

See also
equals

Definition at line 255 of file qjsmanagedvalue.cpp.

References QV4::StaticValue::isUndefined(), other(), and QV4::RuntimeHelpers::strictEqual().

+ Here is the call graph for this function:

◆ toBoolean()

bool QJSManagedValue::toBoolean ( ) const

Converts the manged value to a boolean.

If the managed value holds a boolean, that one is returned. Otherwise a boolean coercion by JavaScript rules is performed.

Definition at line 550 of file qjsmanagedvalue.cpp.

References QV4::Value::toBoolean().

+ Here is the call graph for this function:

◆ toDateTime()

QDateTime QJSManagedValue::toDateTime ( ) const

If this QJSManagedValue holds a JavaScript Date object, returns an equivalent QDateTime.

Otherwise returns an invalid one.

Definition at line 689 of file qjsmanagedvalue.cpp.

References QV4::Value::as().

+ Here is the call graph for this function:

◆ toInteger()

int QJSManagedValue::toInteger ( ) const

Converts the manged value to an integer.

This first converts the value to a number by the rules of toNumber(), and then clamps it into the integer range by the rules given for coercing the arguments to JavaScript bit shift operators into 32bit integers.

Internally, the value may already be stored as an integer, in which case a fast path is taken.

Note
Conversion of a managed value to a number can throw an exception. In particular, symbols cannot be coerced into numbers, or a custom valueOf() method may throw. In this case the result is 0 and the engine carries an error after the conversion.
The JavaScript rules for coercing numbers into 32bit integers are unintuitive.

Definition at line 572 of file qjsmanagedvalue.cpp.

References QV4::Value::toInt32().

+ Here is the call graph for this function:

◆ toJSValue()

QJSValue QJSManagedValue::toJSValue ( ) const

Copies this QJSManagedValue into a new QJSValue.

This is less efficient than move-constructing a QJSValue from a QJSManagedValue, but retains the QJSManagedValue.

Definition at line 611 of file qjsmanagedvalue.cpp.

References QV4::StaticValue::asReturnedValue(), QJSValuePrivate::fromReturnedValue(), and QJSValue.

+ Here is the call graph for this function:

◆ toNumber()

double QJSManagedValue::toNumber ( ) const

Converts the manged value to a number.

If the managed value holds a number, that one is returned. Otherwise a number coercion by JavaScript rules is performed.

Note
Conversion of a managed value to a number can throw an exception. In particular, symbols cannot be coerced into numbers, or a custom valueOf() method may throw. In this case the result is 0 and the engine carries an error after the conversion.

Definition at line 540 of file qjsmanagedvalue.cpp.

References QV4::Value::toNumber().

+ Here is the call graph for this function:

◆ toPrimitive()

QJSPrimitiveValue QJSManagedValue::toPrimitive ( ) const

Converts the manged value to a QJSPrimitiveValue.

If the managed value holds a type supported by QJSPrimitiveValue, the value is copied. Otherwise the value is converted to a string, and the string is stored in QJSPrimitiveValue.

Note
Conversion of a managed value to a string can throw an exception. In particular, symbols cannot be coerced into strings, or a custom toString() method may throw. In this case the result is the undefined value and the engine carries an error after the conversion.

Definition at line 588 of file qjsmanagedvalue.cpp.

References QV4::StaticValue::booleanValue(), QV4::StaticValue::doubleValue(), QV4::StaticValue::integerValue(), QV4::StaticValue::isBoolean(), QV4::StaticValue::isInteger(), QV4::StaticValue::isNull(), QV4::StaticValue::isNumber(), QV4::StaticValue::isUndefined(), ok, and QV4::Value::toQString().

+ Here is the call graph for this function:

◆ toQMetaObject()

const QMetaObject * QJSManagedValue::toQMetaObject ( ) const

If this QJSManagedValue holds a QMetaObject pointer, returns it.

Otherwise returns nullptr.

Definition at line 678 of file qjsmanagedvalue.cpp.

References QV4::Value::as().

+ Here is the call graph for this function:

◆ toQObject()

QObject * QJSManagedValue::toQObject ( ) const

If this QJSManagedValue holds a QObject pointer, returns it.

Otherwise returns nullptr.

Definition at line 667 of file qjsmanagedvalue.cpp.

References QV4::Value::as(), and o.

+ Here is the call graph for this function:

◆ toRegularExpression()

QRegularExpression QJSManagedValue::toRegularExpression ( ) const

If this QJSManagedValue holds a JavaScript regular expression object, returns an equivalent QRegularExpression.

Otherwise returns an invalid one.

Definition at line 645 of file qjsmanagedvalue.cpp.

References QV4::Value::as().

+ Here is the call graph for this function:

◆ toString()

QString QJSManagedValue::toString ( ) const

Converts the manged value to a string.

If the managed value holds a string, that one is returned. Otherwise a string coercion by JavaScript rules is performed.

Note
Conversion of a managed value to a string can throw an exception. In particular, symbols cannot be coerced into strings, or a custom toString() method may throw. In this case the result is an empty string and the engine carries an error after the conversion.

Definition at line 525 of file qjsmanagedvalue.cpp.

References QStringLiteral, and QV4::Value::toQString().

+ Here is the call graph for this function:

◆ toUrl()

QUrl QJSManagedValue::toUrl ( ) const

If this QJSManagedValue holds a JavaScript Url object, returns an equivalent QUrl.

Otherwise returns an invalid one.

Definition at line 656 of file qjsmanagedvalue.cpp.

References QV4::Value::as().

+ Here is the call graph for this function:

◆ toVariant()

QVariant QJSManagedValue::toVariant ( ) const

Copies this QJSManagedValue into a new QVariant.

This also creates a useful QVariant if QJSManagedValue::isVariant() returns false. QVariant can hold all types supported by QJSManagedValue.

Definition at line 621 of file qjsmanagedvalue.cpp.

References QV4::Value::as(), QV4::StaticValue::booleanValue(), QV4::StaticValue::doubleValue(), QV4::StaticValue::integerValue(), QV4::StaticValue::isBoolean(), QV4::StaticValue::isInteger(), QV4::StaticValue::isNull(), QV4::StaticValue::isNumber(), QV4::Value::isString(), QV4::StaticValue::isUndefined(), QV4::Value::toQString(), and QV4::ExecutionEngine::toVariant().

+ Here is the call graph for this function:

◆ type()

QJSManagedValue::Type QJSManagedValue::type ( ) const

Returns the JavaScript type of this QJSManagedValue.

Definition at line 346 of file qjsmanagedvalue.cpp.

References Boolean, Function, QV4::StaticValue::isBoolean(), QV4::Value::isFunctionObject(), QV4::StaticValue::isNumber(), QV4::Value::isString(), QV4::Value::isSymbol(), QV4::StaticValue::isUndefined(), Number, Object, String, Symbol, and Undefined.

Referenced by setPrototype().

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

Friends And Related Symbol Documentation

◆ QJSEngine

friend class QJSEngine
friend

Definition at line 122 of file qjsmanagedvalue.h.

◆ QJSValue

friend class QJSValue
friend

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