![]() |
Qt 6.x
The Qt SDK
|
\inmodule QtQml More...
#include <qjsmanagedvalue.h>
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. | |
QJSManagedValue & | operator= (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. | |
QJSEngine * | engine () 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. | |
QObject * | toQObject () const |
If this QJSManagedValue holds a QObject pointer, returns it. | |
const QMetaObject * | toQMetaObject () 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 |
\inmodule QtQml
\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.
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.
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.
|
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().
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 119 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().
QJSManagedValue::QJSManagedValue | ( | const QJSPrimitiveValue & | value, |
QJSEngine * | engine | ||
) |
Creates a QJSManagedValue from value using the heap of engine.
Definition at line 146 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.
Creates a QJSManagedValue from variant using the heap of engine.
Definition at line 176 of file qjsmanagedvalue.cpp.
References engine(), QV4::ExecutionEngine::fromVariant(), QJSEngine::handle(), and variant.
Creates a QJSManagedValue from string using the heap of engine.
Definition at line 185 of file qjsmanagedvalue.cpp.
References engine(), QJSEngine::handle(), and QV4::ExecutionEngine::newString().
QJSManagedValue::~QJSManagedValue | ( | ) |
Destroys the QJSManagedValue.
Definition at line 198 of file qjsmanagedvalue.cpp.
References QV4::PersistentValueStorage::free().
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 208 of file qjsmanagedvalue.cpp.
References other(), and qSwap().
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 951 of file qjsmanagedvalue.cpp.
References arg, QV4::JSCallArguments::args, arguments, QJSValuePrivate::checkEngine(), QJSValuePrivate::convertToReturnedValue(), engine(), QJSValuePrivate::fromReturnedValue(), functionObjectForCall(), QJSEngine::globalObject(), i, Q_UNLIKELY, QJSValue, qWarning, QList< T >::size(), and QV4::JSCallArguments::thisObject.
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 1023 of file qjsmanagedvalue.cpp.
References arg, QV4::JSCallArguments::args, arguments, QJSValuePrivate::checkEngine(), QJSValuePrivate::convertToReturnedValue(), engine(), QJSValuePrivate::fromReturnedValue(), functionObjectForCall(), i, Q_UNLIKELY, QJSValue, qWarning, and QList< T >::size().
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 983 of file qjsmanagedvalue.cpp.
References arg, QV4::JSCallArguments::args, arguments, QJSValuePrivate::checkEngine(), QJSValuePrivate::convertToReturnedValue(), engine(), QJSValuePrivate::fromReturnedValue(), functionObjectForCall(), i, Q_UNLIKELY, QJSValue, qWarning, QList< T >::size(), and QV4::JSCallArguments::thisObject.
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 798 of file qjsmanagedvalue.cpp.
References QV4::Value::as(), QV4::IdentifierTable::asPropertyKey(), QV4::Scope::engine, and QV4::EngineBase::identifierTable.
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 916 of file qjsmanagedvalue.cpp.
References QV4::Value::as(), and QV4::PropertyKey::fromArrayIndex().
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 269 of file qjsmanagedvalue.cpp.
References QV4::PersistentValueStorage::getEngine().
Referenced by QJSManagedValue(), QJSManagedValue(), QJSManagedValue(), QJSManagedValue(), call(), callAsConstructor(), callWithInstance(), and jsMetaInstantiate().
bool QJSManagedValue::equals | ( | const QJSManagedValue & | other | ) | const |
Invokes the JavaScript '==' operator on this QJSManagedValue and other, and returns the result.
Definition at line 238 of file qjsmanagedvalue.cpp.
References QV4::Runtime::CompareEqual::call(), QV4::StaticValue::isNullOrUndefined(), and other().
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 720 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.
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 842 of file qjsmanagedvalue.cpp.
References QV4::Value::as(), QV4::Attr_Invalid, QV4::PropertyKey::fromArrayIndex(), and QV4::StaticValue::isNullOrUndefined().
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 699 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().
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 817 of file qjsmanagedvalue.cpp.
References QV4::Value::as(), hasProperty(), QV4::StaticValue::isNullOrUndefined(), and prototype().
bool QJSManagedValue::isArray | ( | ) | const |
Returns true
if this value represents a JavaScript Array object, or false
otherwise.
Definition at line 444 of file qjsmanagedvalue.cpp.
References QV4::Value::as().
|
inline |
Returns true
if the type of this QJSManagedValue is boolean
, or false
otherwise.
Definition at line 55 of file qjsmanagedvalue.h.
References Boolean.
bool QJSManagedValue::isDate | ( | ) | const |
Returns true
if this value represents a JavaScript Date object, or false
otherwise.
Definition at line 489 of file qjsmanagedvalue.cpp.
References QV4::Value::as().
bool QJSManagedValue::isError | ( | ) | const |
Returns true
if this value represents a JavaScript Error object, or false
otherwise.
Definition at line 498 of file qjsmanagedvalue.cpp.
References QV4::Value::as().
|
inline |
Returns true
if the type of this QJSManagedValue is function
, false
otherwise.
Definition at line 60 of file qjsmanagedvalue.h.
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 426 of file qjsmanagedvalue.cpp.
References QV4::StaticValue::isInteger().
bool QJSManagedValue::isJsMetaType | ( | ) | const |
Returns true
if this value represents a JavaScript meta type, or false
otherwise.
Definition at line 509 of file qjsmanagedvalue.cpp.
References QV4::Value::as().
bool QJSManagedValue::isNull | ( | ) | const |
Returns true
if this QJSManagedValue holds the JavaScript null
value, or false
otherwise.
Definition at line 415 of file qjsmanagedvalue.cpp.
References QV4::StaticValue::isNull().
|
inline |
Returns true
if the type of this QJSManagedValue is number
, or false
otherwise.
Definition at line 56 of file qjsmanagedvalue.h.
|
inline |
Returns true
if the type of this QJSManagedValue is object
, or false
otherwise.
Definition at line 58 of file qjsmanagedvalue.h.
bool QJSManagedValue::isQMetaObject | ( | ) | const |
Returns true
if this value represents a QMetaObject pointer managed on the JavaScript heap, or false
otherwise.
Definition at line 480 of file qjsmanagedvalue.cpp.
References QV4::Value::as().
bool QJSManagedValue::isQObject | ( | ) | const |
Returns true
if this value represents a QObject pointer managed on the JavaScript heap, or false
otherwise.
Definition at line 471 of file qjsmanagedvalue.cpp.
References QV4::Value::as().
bool QJSManagedValue::isRegularExpression | ( | ) | const |
Returns true
if this value represents a JavaScript regular expression object, or false
otherwise.
Definition at line 435 of file qjsmanagedvalue.cpp.
References QV4::Value::as().
|
inline |
Returns true
if the type of this QJSManagedValue is string
, or false
otherwise.
Definition at line 57 of file qjsmanagedvalue.h.
|
inline |
Returns true
if the type of this QJSManagedValue is symbol
, or false
otherwise.
Definition at line 59 of file qjsmanagedvalue.h.
|
inline |
Returns true
if the type of this QJSManagedValue is undefined
, or false
otherwise.
Definition at line 54 of file qjsmanagedvalue.h.
References Undefined.
bool QJSManagedValue::isUrl | ( | ) | const |
Returns true
if this value represents a JavaScript Url object, or false
otherwise.
Definition at line 453 of file qjsmanagedvalue.cpp.
References QV4::Value::as().
bool QJSManagedValue::isVariant | ( | ) | const |
Returns true
if this value represents a QVariant managed on the JavaScript heap, or false
otherwise.
Definition at line 462 of file qjsmanagedvalue.cpp.
References QV4::Value::as().
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.
Definition at line 1109 of file qjsmanagedvalue.cpp.
References QJSManagedValue(), arg, QV4::Value::as(), QJSValuePrivate::checkEngine(), QJSValuePrivate::convertToReturnedValue(), engine(), i, o, Q_UNLIKELY, qMin(), and qWarning.
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.
Definition at line 1079 of file qjsmanagedvalue.cpp.
References QV4::Value::as(), and i.
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.
Definition at line 1056 of file qjsmanagedvalue.cpp.
References QJSManagedValue(), QV4::Value::as(), and v4Engine().
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.
Definition at line 222 of file qjsmanagedvalue.cpp.
References QV4::PersistentValueStorage::free(), other(), and qSwap().
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 741 of file qjsmanagedvalue.cpp.
References arg, QV4::Value::as(), QV4::IdentifierTable::asPropertyKey(), e, QV4::Scope::engine, QJSValuePrivate::fromReturnedValue(), QV4::EngineBase::identifierTable, QV4::StaticValue::isNullOrUndefined(), property(), prototype(), QJSValue, QStringLiteral, and v4Engine().
Referenced by property(), and property().
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 868 of file qjsmanagedvalue.cpp.
References QV4::Value::as(), QJSValuePrivate::fromReturnedValue(), QV4::StaticValue::isNullOrUndefined(), property(), prototype(), QJSValue, QString::size(), and QString::sliced().
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 283 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().
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 771 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, QV4::ExecutionEngine::throwTypeError(), and v4Engine().
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 896 of file qjsmanagedvalue.cpp.
References QV4::Value::as(), QJSValuePrivate::convertToReturnedValue(), QJSValuePrivate::engine(), Q_UNLIKELY, and qWarning.
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 313 of file qjsmanagedvalue.cpp.
References QV4::Value::as(), Object, prototype(), Q_UNLIKELY, qWarning, type(), and v4Engine().
bool QJSManagedValue::strictlyEquals | ( | const QJSManagedValue & | other | ) | const |
Invokes the JavaScript '===' operator on this QJSManagedValue and other, and returns the result.
Definition at line 254 of file qjsmanagedvalue.cpp.
References QV4::StaticValue::isUndefined(), other(), and QV4::RuntimeHelpers::strictEqual().
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 549 of file qjsmanagedvalue.cpp.
References QV4::Value::toBoolean().
QDateTime QJSManagedValue::toDateTime | ( | ) | const |
If this QJSManagedValue holds a JavaScript Date object, returns an equivalent QDateTime.
Otherwise returns an invalid one.
Definition at line 688 of file qjsmanagedvalue.cpp.
References QV4::Value::as().
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.
Definition at line 571 of file qjsmanagedvalue.cpp.
References QV4::Value::toInt32().
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 610 of file qjsmanagedvalue.cpp.
References QV4::StaticValue::asReturnedValue(), QJSValuePrivate::fromReturnedValue(), and QJSValue.
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.
Definition at line 539 of file qjsmanagedvalue.cpp.
References QV4::Value::toNumber().
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.
Definition at line 587 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().
const QMetaObject * QJSManagedValue::toQMetaObject | ( | ) | const |
If this QJSManagedValue holds a QMetaObject pointer, returns it.
Otherwise returns nullptr.
Definition at line 677 of file qjsmanagedvalue.cpp.
References QV4::Value::as().
QObject * QJSManagedValue::toQObject | ( | ) | const |
If this QJSManagedValue holds a QObject pointer, returns it.
Otherwise returns nullptr.
Definition at line 666 of file qjsmanagedvalue.cpp.
References QV4::Value::as(), and o.
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 644 of file qjsmanagedvalue.cpp.
References QV4::Value::as().
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.
Definition at line 524 of file qjsmanagedvalue.cpp.
References QStringLiteral, and QV4::Value::toQString().
QUrl QJSManagedValue::toUrl | ( | ) | const |
If this QJSManagedValue holds a JavaScript Url object, returns an equivalent QUrl.
Otherwise returns an invalid one.
Definition at line 655 of file qjsmanagedvalue.cpp.
References QV4::Value::as().
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 620 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().
QJSManagedValue::Type QJSManagedValue::type | ( | ) | const |
Returns the JavaScript type of this QJSManagedValue.
Definition at line 345 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().
|
friend |
Definition at line 122 of file qjsmanagedvalue.h.
|
friend |
Definition at line 121 of file qjsmanagedvalue.h.
Referenced by call(), callAsConstructor(), callWithInstance(), property(), property(), and toJSValue().