Qt 4.8
Public Types | Public Functions | Private Functions | Properties | Friends | Related Functions | List of all members
QScriptValue Class Reference

The QScriptValue class acts as a container for the Qt Script data types. More...

#include <qscriptvalue.h>

Public Types

enum  PropertyFlag {
  ReadOnly = 0x00000001, Undeletable = 0x00000002, SkipInEnumeration = 0x00000004, PropertyGetter = 0x00000008,
  PropertySetter = 0x00000010, QObjectMember = 0x00000020, KeepExistingFlags = 0x00000800, UserRange = 0xff000000
}
 This enum describes the attributes of a property. More...
 
enum  ResolveFlag { ResolveLocal = 0x00, ResolvePrototype = 0x01, ResolveScope = 0x02, ResolveFull = ResolvePrototype | ResolveScope }
 This enum specifies how to look up a property of an object. More...
 
enum  SpecialValue { NullValue, UndefinedValue }
 This enum is used to specify a single-valued type. More...
 

Public Functions

QScriptValue call (const QScriptValue &thisObject=QScriptValue(), const QScriptValueList &args=QScriptValueList())
 Calls this QScriptValue as a function, using thisObject as the `this' object in the function call, and passing args as arguments to the function. More...
 
QScriptValue call (const QScriptValue &thisObject, const QScriptValue &arguments)
 Calls this QScriptValue as a function, using thisObject as the `this' object in the function call, and passing arguments as arguments to the function. More...
 
QScriptValue construct (const QScriptValueList &args=QScriptValueList())
 Creates a new Object and calls this QScriptValue as a constructor, using the created object as the `this' object and passing args as arguments. More...
 
QScriptValue construct (const QScriptValue &arguments)
 Creates a new Object and calls this QScriptValue as a constructor, using the created object as the `this' object and passing arguments as arguments. More...
 
QScriptValue data () const
 Returns the internal data of this QScriptValue object. More...
 
QScriptEngineengine () const
 Returns the QScriptEngine that created this QScriptValue, or 0 if this QScriptValue is invalid or the value is not associated with a particular engine. More...
 
bool equals (const QScriptValue &other) const
 Returns true if this QScriptValue is equal to other, otherwise returns false. More...
 
bool instanceOf (const QScriptValue &other) const
 Returns true if this QScriptValue is an instance of other; otherwise returns false. More...
 
bool isArray () const
 Returns true if this QScriptValue is an object of the Array class; otherwise returns false. More...
 
bool isBool () const
 Returns true if this QScriptValue is of the primitive type Boolean; otherwise returns false. More...
 
bool isBoolean () const
 Use isBool() instead. More...
 
bool isDate () const
 Returns true if this QScriptValue is an object of the Date class; otherwise returns false. More...
 
bool isError () const
 Returns true if this QScriptValue is an object of the Error class; otherwise returns false. More...
 
bool isFunction () const
 Returns true if this QScriptValue is a function; otherwise returns false. More...
 
bool isNull () const
 Returns true if this QScriptValue is of the primitive type Null; otherwise returns false. More...
 
bool isNumber () const
 Returns true if this QScriptValue is of the primitive type Number; otherwise returns false. More...
 
bool isObject () const
 Returns true if this QScriptValue is of the Object type; otherwise returns false. More...
 
bool isQMetaObject () const
 Returns true if this QScriptValue is a QMetaObject; otherwise returns false. More...
 
bool isQObject () const
 Returns true if this QScriptValue is a QObject; otherwise returns false. More...
 
bool isRegExp () const
 Returns true if this QScriptValue is an object of the RegExp class; otherwise returns false. More...
 
bool isString () const
 Returns true if this QScriptValue is of the primitive type String; otherwise returns false. More...
 
bool isUndefined () const
 Returns true if this QScriptValue is of the primitive type Undefined; otherwise returns false. More...
 
bool isValid () const
 Returns true if this QScriptValue is valid; otherwise returns false. More...
 
bool isVariant () const
 Returns true if this QScriptValue is a variant value; otherwise returns false. More...
 
bool lessThan (const QScriptValue &other) const
 Returns true if this QScriptValue is less than other, otherwise returns false. More...
 
qint64 objectId () const
 Returns the ID of this object, or -1 if this QScriptValue is not an object. More...
 
QScriptValueoperator= (const QScriptValue &other)
 Assigns the other value to this QScriptValue. More...
 
QScriptValue property (const QString &name, const ResolveFlags &mode=ResolvePrototype) const
 Returns the value of this QScriptValue's property with the given name, using the given mode to resolve the property. More...
 
QScriptValue property (quint32 arrayIndex, const ResolveFlags &mode=ResolvePrototype) const
 Returns the property at the given arrayIndex, using the given mode to resolve the property. More...
 
QScriptValue property (const QScriptString &name, const ResolveFlags &mode=ResolvePrototype) const
 Returns the value of this QScriptValue's property with the given name, using the given mode to resolve the property. More...
 
QScriptValue::PropertyFlags propertyFlags (const QString &name, const ResolveFlags &mode=ResolvePrototype) const
 Returns the flags of the property with the given name, using the given mode to resolve the property. More...
 
QScriptValue::PropertyFlags propertyFlags (const QScriptString &name, const ResolveFlags &mode=ResolvePrototype) const
 Returns the flags of the property with the given name, using the given mode to resolve the property. More...
 
QScriptValue prototype () const
 If this QScriptValue is an object, returns the internal prototype (__proto__ property) of this object; otherwise returns an invalid QScriptValue. More...
 
 QScriptValue ()
 Constructs an invalid QScriptValue. More...
 
 QScriptValue (const QScriptValue &other)
 Constructs a new QScriptValue that is a copy of other. More...
 
 QScriptValue (QScriptEngine *engine, SpecialValue val)
 Constructs a new QScriptValue with the special value and registers it with the script engine. More...
 
 QScriptValue (QScriptEngine *engine, bool val)
 
 QScriptValue (QScriptEngine *engine, int val)
 
 QScriptValue (QScriptEngine *engine, uint val)
 
 QScriptValue (QScriptEngine *engine, qsreal val)
 
 QScriptValue (QScriptEngine *engine, const QString &val)
 
QT_ASCII_CAST_WARN_CONSTRUCTOR QScriptValue (QScriptEngine *engine, const char *val)
 
 QScriptValue (SpecialValue value)
 Constructs a new QScriptValue with a special value. More...
 
 QScriptValue (bool value)
 Constructs a new QScriptValue with a boolean value. More...
 
 QScriptValue (int value)
 Constructs a new QScriptValue with a number value. More...
 
 QScriptValue (uint value)
 Constructs a new QScriptValue with a number value. More...
 
 QScriptValue (qsreal value)
 Constructs a new QScriptValue with a number value. More...
 
 QScriptValue (const QString &value)
 Constructs a new QScriptValue with a string value. More...
 
 QScriptValue (const QLatin1String &value)
 Constructs a new QScriptValue with a string value. More...
 
QT_ASCII_CAST_WARN_CONSTRUCTOR QScriptValue (const char *value)
 Constructs a new QScriptValue with a string value. More...
 
QScriptValue scope () const
 
QScriptClassscriptClass () const
 Returns the custom script class that this script object is an instance of, or 0 if the object is not of a custom class. More...
 
void setData (const QScriptValue &data)
 Sets the internal data of this QScriptValue object. More...
 
void setProperty (const QString &name, const QScriptValue &value, const PropertyFlags &flags=KeepExistingFlags)
 Sets the value of this QScriptValue's property with the given name to the given value. More...
 
void setProperty (quint32 arrayIndex, const QScriptValue &value, const PropertyFlags &flags=KeepExistingFlags)
 Sets the property at the given arrayIndex to the given value. More...
 
void setProperty (const QScriptString &name, const QScriptValue &value, const PropertyFlags &flags=KeepExistingFlags)
 Sets the value of this QScriptValue's property with the given name to the given value. More...
 
void setPrototype (const QScriptValue &prototype)
 If this QScriptValue is an object, sets the internal prototype (__proto__ property) of this object to be prototype; otherwise does nothing. More...
 
void setScope (const QScriptValue &scope)
 
void setScriptClass (QScriptClass *scriptClass)
 Sets the custom script class of this script object to scriptClass. More...
 
bool strictlyEquals (const QScriptValue &other) const
 Returns true if this QScriptValue is equal to other using strict comparison (no conversion), otherwise returns false. More...
 
bool toBool () const
 Returns the boolean value of this QScriptValue, using the conversion rules described in ECMA-262 section 9. More...
 
bool toBoolean () const
 Use toBool() instead. More...
 
QDateTime toDateTime () const
 Returns a QDateTime representation of this value, in local time. More...
 
qint32 toInt32 () const
 Returns the signed 32-bit integer value of this QScriptValue, using the conversion rules described in ECMA-262 section 9.5, "ToInt32". More...
 
qsreal toInteger () const
 Returns the integer value of this QScriptValue, using the conversion rules described in ECMA-262 section 9.4, "ToInteger". More...
 
qsreal toNumber () const
 Returns the number value of this QScriptValue, as defined in ECMA-262 section 9.3, "ToNumber". More...
 
QScriptValue toObject () const
 This function is obsolete; use QScriptEngine::toObject() instead. More...
 
const QMetaObjecttoQMetaObject () const
 If this QScriptValue is a QMetaObject, returns the QMetaObject pointer that the QScriptValue represents; otherwise, returns 0. More...
 
QObjecttoQObject () const
 If this QScriptValue is a QObject, returns the QObject pointer that the QScriptValue represents; otherwise, returns 0. More...
 
QRegExp toRegExp () const
 Returns the QRegExp representation of this value. More...
 
QString toString () const
 Returns the string value of this QScriptValue, as defined in ECMA-262 section 9.8, "ToString". More...
 
quint16 toUInt16 () const
 Returns the unsigned 16-bit integer value of this QScriptValue, using the conversion rules described in ECMA-262 section 9.7, "ToUint16". More...
 
quint32 toUInt32 () const
 Returns the unsigned 32-bit integer value of this QScriptValue, using the conversion rules described in ECMA-262 section 9.6, "ToUint32". More...
 
QVariant toVariant () const
 Returns the QVariant value of this QScriptValue, if it can be converted to a QVariant; otherwise returns an invalid QVariant. More...
 
 ~QScriptValue ()
 Destroys this QScriptValue. More...
 

Private Functions

 QScriptValue (void *)
 
 QScriptValue (QScriptEngine *, void *)
 
 QScriptValue (QScriptValuePrivate *)
 

Properties

QExplicitlySharedDataPointer< QScriptValuePrivated_ptr
 

Friends

class QScriptEnginePrivate
 

Related Functions

(Note that these are not member functions.)

qscriptvalue_cast (const QScriptValue &value)
 Returns the given value converted to the template type T. More...
 

Detailed Description

The QScriptValue class acts as a container for the Qt Script data types.

Since
4.3

QScriptValue supports the types defined in the ECMA-262 standard: The primitive types, which are Undefined, Null, Boolean, Number, and String; and the Object type. Additionally, Qt Script has built-in support for QVariant, QObject and QMetaObject.

For the object-based types (including Date and RegExp), use the newT() functions in QScriptEngine (e.g. QScriptEngine::newObject()) to create a QScriptValue of the desired type. For the primitive types, use one of the QScriptValue constructor overloads.

The methods named isT() (e.g. isBool(), isUndefined()) can be used to test if a value is of a certain type. The methods named toT() (e.g. toBool(), toString()) can be used to convert a QScriptValue to another type. You can also use the generic qscriptvalue_cast() function.

Object values have zero or more properties which are themselves QScriptValues. Use setProperty() to set a property of an object, and call property() to retrieve the value of a property.

QScriptEngine myEngine;
QScriptValue myObject = myEngine.newObject();
QScriptValue myOtherObject = myEngine.newObject();
myObject.setProperty("myChild", myOtherObject);
myObject.setProperty("name", "John Doe");

Each property can have a set of attributes; these are specified as the third (optional) argument to setProperty(). The attributes of a property can be queried by calling the propertyFlags() function. The following code snippet creates a property that cannot be modified by script code:

QScriptValue val(&myEngine, 123);
myObject.setProperty("myReadOnlyProperty", val, QScriptValue::ReadOnly);

If you want to iterate over the properties of a script object, use the QScriptValueIterator class.

Object values have an internal prototype property, which can be accessed with prototype() and setPrototype(). Properties added to a prototype are shared by all objects having that prototype; this is referred to as prototype-based inheritance. In practice, it means that (by default) the property() function will automatically attempt to look up look the property in the prototype() (and in the prototype of the prototype(), and so on), if the object itself does not have the requested property. Note that this prototype-based lookup is not performed by setProperty(); setProperty() will always create the property in the script object itself. For more information, see the QtScript documentation.

Function objects (objects for which isFunction() returns true) can be invoked by calling call(). Constructor functions can be used to construct new objects by calling construct().

Use equals(), strictlyEquals() and lessThan() to compare a QScriptValue to another.

Object values can have custom data associated with them; see the setData() and data() functions. By default, this data is not accessible to scripts; it can be used to store any data you want to associate with the script object. Typically this is used by custom class objects (see QScriptClass) to store a C++ type that contains the "native" object data.

Note that a QScriptValue for which isObject() is true only carries a reference to an actual object; copying the QScriptValue will only copy the object reference, not the object itself. If you want to clone an object (i.e. copy an object's properties to another object), you can do so with the help of a for-in statement in script code, or QScriptValueIterator in C++.

See also
QScriptEngine, QScriptValueIterator

Definition at line 57 of file qscriptvalue.h.

Enumerations

◆ PropertyFlag

This enum describes the attributes of a property.

  • ReadOnly The property is read-only. Attempts by Qt Script code to write to the property will be ignored.
  • Undeletable Attempts by Qt Script code to delete the property will be ignored.
  • SkipInEnumeration The property is not to be enumerated by a for-in enumeration.
  • PropertyGetter The property is defined by a function which will be called to get the property value.
  • PropertySetter The property is defined by a function which will be called to set the property value.
  • QObjectMember This flag is used to indicate that an existing property is a QObject member (a property or method).
  • KeepExistingFlags This value is used to indicate to setProperty() that the property's flags should be left unchanged. If the property doesn't exist, the default flags (0) will be used.
  • UserRange Flags in this range are not used by Qt Script, and can be used for custom purposes.
Enumerator
ReadOnly 
Undeletable 
SkipInEnumeration 
PropertyGetter 
PropertySetter 
QObjectMember 
KeepExistingFlags 
UserRange 

Definition at line 69 of file qscriptvalue.h.

69  {
70  ReadOnly = 0x00000001,
71  Undeletable = 0x00000002,
72  SkipInEnumeration = 0x00000004,
73 
74  PropertyGetter = 0x00000008,
75  PropertySetter = 0x00000010,
76 
77  QObjectMember = 0x00000020,
78 
79  KeepExistingFlags = 0x00000800,
80 
81  UserRange = 0xff000000 // Users may use these as they see fit.
82  };

◆ ResolveFlag

This enum specifies how to look up a property of an object.

  • ResolveLocal Only check the object's own properties.
  • ResolvePrototype Check the object's own properties first, then search the prototype chain. This is the default.
  • ResolveScope Check the object's own properties first, then search the scope chain.
  • ResolveFull Check the object's own properties first, then search the prototype chain, and finally search the scope chain.
Enumerator
ResolveLocal 
ResolvePrototype 
ResolveScope 
ResolveFull 

Definition at line 60 of file qscriptvalue.h.

◆ SpecialValue

This enum is used to specify a single-valued type.

  • UndefinedValue An undefined value.
  • NullValue A null value.
Enumerator
NullValue 
UndefinedValue 

Definition at line 85 of file qscriptvalue.h.

Constructors and Destructors

◆ QScriptValue() [1/20]

QScriptValue::QScriptValue ( )

Constructs an invalid QScriptValue.

Definition at line 201 of file qscriptvalue.cpp.

Referenced by call(), construct(), data(), property(), prototype(), scope(), and toObject().

202  : d_ptr(0)
203 {
204 }
QExplicitlySharedDataPointer< QScriptValuePrivate > d_ptr
Definition: qscriptvalue.h:209

◆ ~QScriptValue()

QScriptValue::~QScriptValue ( )

Destroys this QScriptValue.

Definition at line 209 of file qscriptvalue.cpp.

210 {
211 }

◆ QScriptValue() [2/20]

QScriptValue::QScriptValue ( const QScriptValue other)

Constructs a new QScriptValue that is a copy of other.

Note that if other is an object (i.e., isObject() would return true), then only a reference to the underlying object is copied into the new script value (i.e., the object itself is not copied).

Definition at line 220 of file qscriptvalue.cpp.

221  : d_ptr(other.d_ptr)
222 {
223 }
QExplicitlySharedDataPointer< QScriptValuePrivate > d_ptr
Definition: qscriptvalue.h:209

◆ QScriptValue() [3/20]

QScriptValue::QScriptValue ( QScriptEngine engine,
QScriptValue::SpecialValue  value 
)

Constructs a new QScriptValue with the special value and registers it with the script engine.

Definition at line 234 of file qscriptvalue.cpp.

236 {
237  switch (value) {
238  case NullValue:
239  d_ptr->initFrom(JSC::jsNull());
240  break;
241  case UndefinedValue:
242  d_ptr->initFrom(JSC::jsUndefined());
243  break;
244  }
245 }
QExplicitlySharedDataPointer< QScriptValuePrivate > d_ptr
Definition: qscriptvalue.h:209
static QScriptEnginePrivate * get(QScriptEngine *q)
void initFrom(JSC::JSValue value)

◆ QScriptValue() [4/20]

QScriptValue::QScriptValue ( QScriptEngine engine,
bool  value 
)

Constructs a new QScriptValue with the boolean value and registers it with the script engine.

Definition at line 255 of file qscriptvalue.cpp.

257 {
258  d_ptr->initFrom(JSC::jsBoolean(val));
259 }
QExplicitlySharedDataPointer< QScriptValuePrivate > d_ptr
Definition: qscriptvalue.h:209
static QScriptEnginePrivate * get(QScriptEngine *q)
void initFrom(JSC::JSValue value)

◆ QScriptValue() [5/20]

QScriptValue::QScriptValue ( QScriptEngine engine,
int  value 
)

Constructs a new QScriptValue with the integer value and registers it with the script engine.

Definition at line 268 of file qscriptvalue.cpp.

270 {
271  if (engine) {
273  JSC::ExecState *exec = d_ptr->engine->currentFrame;
274  d_ptr->initFrom(JSC::jsNumber(exec, val));
275  } else
276  d_ptr->initFrom(val);
277 }
QExplicitlySharedDataPointer< QScriptValuePrivate > d_ptr
Definition: qscriptvalue.h:209
static QScriptEnginePrivate * get(QScriptEngine *q)
JSC::ExecState * currentFrame
void initFrom(JSC::JSValue value)
QScriptEnginePrivate * engine

◆ QScriptValue() [6/20]

QScriptValue::QScriptValue ( QScriptEngine engine,
uint  value 
)

Constructs a new QScriptValue with the unsigned integer value and registers it with the script engine.

Definition at line 286 of file qscriptvalue.cpp.

288 {
289  if (engine) {
291  JSC::ExecState *exec = d_ptr->engine->currentFrame;
292  d_ptr->initFrom(JSC::jsNumber(exec, val));
293  } else
294  d_ptr->initFrom(val);
295 }
QExplicitlySharedDataPointer< QScriptValuePrivate > d_ptr
Definition: qscriptvalue.h:209
static QScriptEnginePrivate * get(QScriptEngine *q)
JSC::ExecState * currentFrame
void initFrom(JSC::JSValue value)
QScriptEnginePrivate * engine

◆ QScriptValue() [7/20]

QScriptValue::QScriptValue ( QScriptEngine engine,
qsreal  value 
)

Constructs a new QScriptValue with the qsreal value and registers it with the script engine.

Definition at line 304 of file qscriptvalue.cpp.

306 {
307  if (engine) {
309  JSC::ExecState *exec = d_ptr->engine->currentFrame;
310  d_ptr->initFrom(JSC::jsNumber(exec, val));
311  } else
312  d_ptr->initFrom(val);
313 }
QExplicitlySharedDataPointer< QScriptValuePrivate > d_ptr
Definition: qscriptvalue.h:209
static QScriptEnginePrivate * get(QScriptEngine *q)
JSC::ExecState * currentFrame
void initFrom(JSC::JSValue value)
QScriptEnginePrivate * engine

◆ QScriptValue() [8/20]

QScriptValue::QScriptValue ( QScriptEngine engine,
const QString value 
)

Constructs a new QScriptValue with the string value and registers it with the script engine.

Definition at line 322 of file qscriptvalue.cpp.

324 {
325  if (engine) {
327  JSC::ExecState *exec = d_ptr->engine->currentFrame;
328  d_ptr->initFrom(JSC::jsString(exec, val));
329  } else {
330  d_ptr->initFrom(val);
331  }
332 }
QExplicitlySharedDataPointer< QScriptValuePrivate > d_ptr
Definition: qscriptvalue.h:209
static QScriptEnginePrivate * get(QScriptEngine *q)
JSC::ExecState * currentFrame
void initFrom(JSC::JSValue value)
QScriptEnginePrivate * engine

◆ QScriptValue() [9/20]

QScriptValue::QScriptValue ( QScriptEngine engine,
const char *  value 
)

Constructs a new QScriptValue with the string value and registers it with the script engine.

Definition at line 343 of file qscriptvalue.cpp.

345 {
346  if (engine) {
348  JSC::ExecState *exec = d_ptr->engine->currentFrame;
349  d_ptr->initFrom(JSC::jsString(exec, val));
350  } else {
352  }
353 }
QExplicitlySharedDataPointer< QScriptValuePrivate > d_ptr
Definition: qscriptvalue.h:209
static QString fromAscii(const char *, int size=-1)
Returns a QString initialized with the first size characters from the string str. ...
Definition: qstring.cpp:4276
static QScriptEnginePrivate * get(QScriptEngine *q)
JSC::ExecState * currentFrame
void initFrom(JSC::JSValue value)
QScriptEnginePrivate * engine

◆ QScriptValue() [10/20]

QScriptValue::QScriptValue ( SpecialValue  value)

Constructs a new QScriptValue with a special value.

Since
4.5

Definition at line 364 of file qscriptvalue.cpp.

365  : d_ptr(new (/*engine=*/0)QScriptValuePrivate(/*engine=*/0))
366 {
367  switch (value) {
368  case NullValue:
369  d_ptr->initFrom(JSC::jsNull());
370  break;
371  case UndefinedValue:
372  d_ptr->initFrom(JSC::jsUndefined());
373  break;
374  }
375 }
QExplicitlySharedDataPointer< QScriptValuePrivate > d_ptr
Definition: qscriptvalue.h:209
void initFrom(JSC::JSValue value)

◆ QScriptValue() [11/20]

QScriptValue::QScriptValue ( bool  value)

Constructs a new QScriptValue with a boolean value.

Since
4.5

Definition at line 385 of file qscriptvalue.cpp.

386  : d_ptr(new (/*engine=*/0)QScriptValuePrivate(/*engine=*/0))
387 {
388  d_ptr->initFrom(JSC::jsBoolean(value));
389 }
QExplicitlySharedDataPointer< QScriptValuePrivate > d_ptr
Definition: qscriptvalue.h:209
void initFrom(JSC::JSValue value)

◆ QScriptValue() [12/20]

QScriptValue::QScriptValue ( int  value)

Constructs a new QScriptValue with a number value.

Since
4.5

Definition at line 399 of file qscriptvalue.cpp.

400  : d_ptr(new (/*engine=*/0)QScriptValuePrivate(/*engine=*/0))
401 {
402  d_ptr->initFrom(value);
403 }
QExplicitlySharedDataPointer< QScriptValuePrivate > d_ptr
Definition: qscriptvalue.h:209
void initFrom(JSC::JSValue value)

◆ QScriptValue() [13/20]

QScriptValue::QScriptValue ( uint  value)

Constructs a new QScriptValue with a number value.

Since
4.5

Definition at line 413 of file qscriptvalue.cpp.

414  : d_ptr(new (/*engine=*/0)QScriptValuePrivate(/*engine=*/0))
415 {
416  d_ptr->initFrom(value);
417 }
QExplicitlySharedDataPointer< QScriptValuePrivate > d_ptr
Definition: qscriptvalue.h:209
void initFrom(JSC::JSValue value)

◆ QScriptValue() [14/20]

QScriptValue::QScriptValue ( qsreal  value)

Constructs a new QScriptValue with a number value.

Since
4.5

Definition at line 427 of file qscriptvalue.cpp.

428  : d_ptr(new (/*engine=*/0)QScriptValuePrivate(/*engine=*/0))
429 {
430  d_ptr->initFrom(value);
431 }
QExplicitlySharedDataPointer< QScriptValuePrivate > d_ptr
Definition: qscriptvalue.h:209
void initFrom(JSC::JSValue value)

◆ QScriptValue() [15/20]

QScriptValue::QScriptValue ( const QString value)

Constructs a new QScriptValue with a string value.

Since
4.5

Definition at line 441 of file qscriptvalue.cpp.

442  : d_ptr(new (/*engine=*/0)QScriptValuePrivate(/*engine=*/0))
443 {
444  d_ptr->initFrom(value);
445 }
QExplicitlySharedDataPointer< QScriptValuePrivate > d_ptr
Definition: qscriptvalue.h:209
void initFrom(JSC::JSValue value)

◆ QScriptValue() [16/20]

QScriptValue::QScriptValue ( const QLatin1String value)

Constructs a new QScriptValue with a string value.

Since
4.5

Definition at line 455 of file qscriptvalue.cpp.

456  : d_ptr(new (/*engine=*/0)QScriptValuePrivate(/*engine=*/0))
457 {
458  d_ptr->initFrom(value);
459 }
QExplicitlySharedDataPointer< QScriptValuePrivate > d_ptr
Definition: qscriptvalue.h:209
void initFrom(JSC::JSValue value)

◆ QScriptValue() [17/20]

QScriptValue::QScriptValue ( const char *  value)

Constructs a new QScriptValue with a string value.

Since
4.5

Definition at line 471 of file qscriptvalue.cpp.

472  : d_ptr(new (/*engine=*/0)QScriptValuePrivate(/*engine=*/0))
473 {
475 }
QExplicitlySharedDataPointer< QScriptValuePrivate > d_ptr
Definition: qscriptvalue.h:209
static QString fromAscii(const char *, int size=-1)
Returns a QString initialized with the first size characters from the string str. ...
Definition: qstring.cpp:4276
void initFrom(JSC::JSValue value)

◆ QScriptValue() [18/20]

QScriptValue::QScriptValue ( void *  )
private

◆ QScriptValue() [19/20]

QScriptValue::QScriptValue ( QScriptEngine ,
void *   
)
private

◆ QScriptValue() [20/20]

QScriptValue::QScriptValue ( QScriptValuePrivate d)
private
Warning
This function is not part of the public interface.

Definition at line 193 of file qscriptvalue.cpp.

194  : d_ptr(d)
195 {
196 }
QExplicitlySharedDataPointer< QScriptValuePrivate > d_ptr
Definition: qscriptvalue.h:209

Functions

◆ call() [1/2]

QScriptValue QScriptValue::call ( const QScriptValue thisObject = QScriptValue(),
const QScriptValueList args = QScriptValueList() 
)

Calls this QScriptValue as a function, using thisObject as the `this' object in the function call, and passing args as arguments to the function.

Returns the value returned from the function.

If this QScriptValue is not a function, call() does nothing and returns an invalid QScriptValue.

Note that if thisObject is not an object, the global object (see QScriptEngine::globalObject()) will be used as the `this' object.

Calling call() can cause an exception to occur in the script engine; in that case, call() returns the value that was thrown (typically an Error object). You can call QScriptEngine::hasUncaughtException() to determine if an exception occurred.

engine.evaluate("function fullName() { return this.firstName + ' ' + this.lastName; }");
engine.evaluate("somePerson = { firstName: 'John', lastName: 'Doe' }");
QScriptValue global = engine.globalObject();
QScriptValue fullName = global.property("fullName");
QScriptValue who = global.property("somePerson");
qDebug() << fullName.call(who).toString(); // "John Doe"
engine.evaluate("function cube(x) { return x * x * x; }");
QScriptValue cube = global.property("cube");
args << 3;
qDebug() << cube.call(QScriptValue(), args).toNumber(); // 27
See also
construct()

Definition at line 1621 of file qscriptvalue.cpp.

Referenced by QDeclarativeInclude::callback(), QDeclarativeXMLHttpRequest::dispatchCallback(), QDeclarativeQtScriptExpression::eval(), QScriptEngine::importExtension(), QDeclarativeVMEMetaObject::metaCall(), QDeclarativeWorkerScriptEnginePrivate::processMessage(), qmlsqldatabase_change_version(), and qmlsqldatabase_open_sync().

1623 {
1624  Q_D(const QScriptValue);
1625  if (!d || !d->isObject())
1626  return QScriptValue();
1627  QScript::APIShim shim(d->engine);
1628  JSC::JSValue callee = d->jscValue;
1629  JSC::CallData callData;
1630  JSC::CallType callType = callee.getCallData(callData);
1631  if (callType == JSC::CallTypeNone)
1632  return QScriptValue();
1633 
1634  if (QScriptValuePrivate::getEngine(thisObject)
1635  && (QScriptValuePrivate::getEngine(thisObject) != d->engine)) {
1636  qWarning("QScriptValue::call() failed: "
1637  "cannot call function with thisObject created in "
1638  "a different engine");
1639  return QScriptValue();
1640  }
1641 
1642  JSC::ExecState *exec = d->engine->currentFrame;
1643 
1644  JSC::JSValue jscThisObject = d->engine->scriptValueToJSCValue(thisObject);
1645  if (!jscThisObject || !jscThisObject.isObject())
1646  jscThisObject = d->engine->globalObject();
1647 
1648  QVarLengthArray<JSC::JSValue, 8> argsVector(args.size());
1649  for (int i = 0; i < args.size(); ++i) {
1650  const QScriptValue &arg = args.at(i);
1651  if (!arg.isValid()) {
1652  argsVector[i] = JSC::jsUndefined();
1653  } else if (QScriptValuePrivate::getEngine(arg)
1654  && (QScriptValuePrivate::getEngine(arg) != d->engine)) {
1655  qWarning("QScriptValue::call() failed: "
1656  "cannot call function with argument created in "
1657  "a different engine");
1658  return QScriptValue();
1659  } else {
1660  argsVector[i] = d->engine->scriptValueToJSCValue(arg);
1661  }
1662  }
1663  JSC::ArgList jscArgs(argsVector.data(), argsVector.size());
1664 
1665  JSC::JSValue savedException;
1666  QScriptEnginePrivate::saveException(exec, &savedException);
1667  JSC::JSValue result = JSC::call(exec, callee, callType, callData, jscThisObject, jscArgs);
1668  if (exec->hadException()) {
1669  result = exec->exception();
1670  } else {
1671  QScriptEnginePrivate::restoreException(exec, savedException);
1672  }
1673  return d->engine->scriptValueFromJSCValue(result);
1674 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
static QScriptEnginePrivate * getEngine(const QScriptValue &q)
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
QScriptValue()
Constructs an invalid QScriptValue.
Q_CORE_EXPORT void qWarning(const char *,...)
static void restoreException(JSC::ExecState *, JSC::JSValue)
static void saveException(JSC::ExecState *, JSC::JSValue *)
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57
bool isValid() const
Returns true if this QScriptValue is valid; otherwise returns false.

◆ call() [2/2]

QScriptValue QScriptValue::call ( const QScriptValue thisObject,
const QScriptValue arguments 
)

Calls this QScriptValue as a function, using thisObject as the `this' object in the function call, and passing arguments as arguments to the function.

Returns the value returned from the function.

If this QScriptValue is not a function, call() does nothing and returns an invalid QScriptValue.

arguments can be an arguments object, an array, null or undefined; any other type will cause a TypeError to be thrown.

Note that if thisObject is not an object, the global object (see QScriptEngine::globalObject()) will be used as the `this' object.

One common usage of this function is to forward native function calls to another function:

{
QScriptValue otherFunction = ...;
return otherFunction.call(ctx->thisObject(), ctx->argumentsObject());
}
See also
construct(), QScriptContext::argumentsObject()

Definition at line 1699 of file qscriptvalue.cpp.

1701 {
1702  Q_D(QScriptValue);
1703  if (!d || !d->isObject())
1704  return QScriptValue();
1705  QScript::APIShim shim(d->engine);
1706  JSC::JSValue callee = d->jscValue;
1707  JSC::CallData callData;
1708  JSC::CallType callType = callee.getCallData(callData);
1709  if (callType == JSC::CallTypeNone)
1710  return QScriptValue();
1711 
1712  if (QScriptValuePrivate::getEngine(thisObject)
1713  && (QScriptValuePrivate::getEngine(thisObject) != d->engine)) {
1714  qWarning("QScriptValue::call() failed: "
1715  "cannot call function with thisObject created in "
1716  "a different engine");
1717  return QScriptValue();
1718  }
1719 
1720  JSC::ExecState *exec = d->engine->currentFrame;
1721 
1722  JSC::JSValue jscThisObject = d->engine->scriptValueToJSCValue(thisObject);
1723  if (!jscThisObject || !jscThisObject.isObject())
1724  jscThisObject = d->engine->globalObject();
1725 
1726  JSC::JSValue array = d->engine->scriptValueToJSCValue(arguments);
1727  // copied from runtime/FunctionPrototype.cpp, functionProtoFuncApply()
1728  JSC::MarkedArgumentBuffer applyArgs;
1729  if (!array.isUndefinedOrNull()) {
1730  if (!array.isObject()) {
1731  return d->engine->scriptValueFromJSCValue(JSC::throwError(exec, JSC::TypeError, "Arguments must be an array"));
1732  }
1733  if (JSC::asObject(array)->classInfo() == &JSC::Arguments::info)
1734  JSC::asArguments(array)->fillArgList(exec, applyArgs);
1735  else if (JSC::isJSArray(&exec->globalData(), array))
1736  JSC::asArray(array)->fillArgList(exec, applyArgs);
1737  else if (JSC::asObject(array)->inherits(&JSC::JSArray::info)) {
1738  unsigned length = JSC::asArray(array)->get(exec, exec->propertyNames().length).toUInt32(exec);
1739  for (unsigned i = 0; i < length; ++i)
1740  applyArgs.append(JSC::asArray(array)->get(exec, i));
1741  } else {
1742  return d->engine->scriptValueFromJSCValue(JSC::throwError(exec, JSC::TypeError, "Arguments must be an array"));
1743  }
1744  }
1745 
1746  JSC::JSValue savedException;
1747  QScriptEnginePrivate::saveException(exec, &savedException);
1748  JSC::JSValue result = JSC::call(exec, callee, callType, callData, jscThisObject, applyArgs);
1749  if (exec->hadException()) {
1750  result = exec->exception();
1751  } else {
1752  QScriptEnginePrivate::restoreException(exec, savedException);
1753  }
1754  return d->engine->scriptValueFromJSCValue(result);
1755 }
double d
Definition: qnumeric_p.h:62
static mach_timebase_info_data_t info
#define Q_D(Class)
Definition: qglobal.h:2482
static QScriptEnginePrivate * getEngine(const QScriptValue &q)
QScriptValue()
Constructs an invalid QScriptValue.
Q_CORE_EXPORT void qWarning(const char *,...)
static void restoreException(JSC::ExecState *, JSC::JSValue)
quint32 toUInt32() const
Returns the unsigned 32-bit integer value of this QScriptValue, using the conversion rules described ...
static void saveException(JSC::ExecState *, JSC::JSValue *)
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57

◆ construct() [1/2]

QScriptValue QScriptValue::construct ( const QScriptValueList args = QScriptValueList())

Creates a new Object and calls this QScriptValue as a constructor, using the created object as the `this' object and passing args as arguments.

If the return value from the constructor call is an object, then that object is returned; otherwise the default constructed object is returned.

If this QScriptValue is not a function, construct() does nothing and returns an invalid QScriptValue.

Calling construct() can cause an exception to occur in the script engine; in that case, construct() returns the value that was thrown (typically an Error object). You can call QScriptEngine::hasUncaughtException() to determine if an exception occurred.

See also
call(), QScriptEngine::newObject()

Definition at line 1775 of file qscriptvalue.cpp.

1776 {
1777  Q_D(const QScriptValue);
1778  if (!d || !d->isObject())
1779  return QScriptValue();
1780  QScript::APIShim shim(d->engine);
1781  JSC::JSValue callee = d->jscValue;
1782  JSC::ConstructData constructData;
1783  JSC::ConstructType constructType = callee.getConstructData(constructData);
1784  if (constructType == JSC::ConstructTypeNone)
1785  return QScriptValue();
1786 
1787  JSC::ExecState *exec = d->engine->currentFrame;
1788 
1789  QVarLengthArray<JSC::JSValue, 8> argsVector(args.size());
1790  for (int i = 0; i < args.size(); ++i) {
1791  QScriptValue arg = args.at(i);
1792  if (QScriptValuePrivate::getEngine(arg) != d->engine && QScriptValuePrivate::getEngine(arg)) {
1793  qWarning("QScriptValue::construct() failed: "
1794  "cannot construct function with argument created in "
1795  "a different engine");
1796  return QScriptValue();
1797  }
1798  if (!arg.isValid())
1799  argsVector[i] = JSC::jsUndefined();
1800  else
1801  argsVector[i] = d->engine->scriptValueToJSCValue(args.at(i));
1802  }
1803 
1804  JSC::ArgList jscArgs(argsVector.data(), argsVector.size());
1805 
1806  JSC::JSValue savedException;
1807  QScriptEnginePrivate::saveException(exec, &savedException);
1808  JSC::JSValue result;
1809  JSC::JSObject *newObject = JSC::construct(exec, callee, constructType, constructData, jscArgs);
1810  if (exec->hadException()) {
1811  result = exec->exception();
1812  } else {
1813  result = newObject;
1814  QScriptEnginePrivate::restoreException(exec, savedException);
1815  }
1816  return d->engine->scriptValueFromJSCValue(result);
1817 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
static QScriptEnginePrivate * getEngine(const QScriptValue &q)
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
QScriptValue()
Constructs an invalid QScriptValue.
Q_CORE_EXPORT void qWarning(const char *,...)
static void restoreException(JSC::ExecState *, JSC::JSValue)
static void saveException(JSC::ExecState *, JSC::JSValue *)
static void construct(QVariant::Private *x, const void *copy)
Definition: qvariant.cpp:75
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57
bool isValid() const
Returns true if this QScriptValue is valid; otherwise returns false.

◆ construct() [2/2]

QScriptValue QScriptValue::construct ( const QScriptValue arguments)

Creates a new Object and calls this QScriptValue as a constructor, using the created object as the `this' object and passing arguments as arguments.

If the return value from the constructor call is an object, then that object is returned; otherwise the default constructed object is returned.

If this QScriptValue is not a function, construct() does nothing and returns an invalid QScriptValue.

arguments can be an arguments object, an array, null or undefined. Any other type will cause a TypeError to be thrown.

See also
call(), QScriptEngine::newObject(), QScriptContext::argumentsObject()

Definition at line 1834 of file qscriptvalue.cpp.

1835 {
1836  Q_D(QScriptValue);
1837  if (!d || !d->isObject())
1838  return QScriptValue();
1839  QScript::APIShim shim(d->engine);
1840  JSC::JSValue callee = d->jscValue;
1841  JSC::ConstructData constructData;
1842  JSC::ConstructType constructType = callee.getConstructData(constructData);
1843  if (constructType == JSC::ConstructTypeNone)
1844  return QScriptValue();
1845 
1846  JSC::ExecState *exec = d->engine->currentFrame;
1847 
1848  if (QScriptValuePrivate::getEngine(arguments) != d->engine && QScriptValuePrivate::getEngine(arguments)) {
1849  qWarning("QScriptValue::construct() failed: "
1850  "cannot construct function with argument created in "
1851  "a different engine");
1852  return QScriptValue();
1853  }
1854  JSC::JSValue array = d->engine->scriptValueToJSCValue(arguments);
1855  // copied from runtime/FunctionPrototype.cpp, functionProtoFuncApply()
1856  JSC::MarkedArgumentBuffer applyArgs;
1857  if (!array.isUndefinedOrNull()) {
1858  if (!array.isObject()) {
1859  return d->engine->scriptValueFromJSCValue(JSC::throwError(exec, JSC::TypeError, "Arguments must be an array"));
1860  }
1861  if (JSC::asObject(array)->classInfo() == &JSC::Arguments::info)
1862  JSC::asArguments(array)->fillArgList(exec, applyArgs);
1863  else if (JSC::isJSArray(&exec->globalData(), array))
1864  JSC::asArray(array)->fillArgList(exec, applyArgs);
1865  else if (JSC::asObject(array)->inherits(&JSC::JSArray::info)) {
1866  unsigned length = JSC::asArray(array)->get(exec, exec->propertyNames().length).toUInt32(exec);
1867  for (unsigned i = 0; i < length; ++i)
1868  applyArgs.append(JSC::asArray(array)->get(exec, i));
1869  } else {
1870  return d->engine->scriptValueFromJSCValue(JSC::throwError(exec, JSC::TypeError, "Arguments must be an array"));
1871  }
1872  }
1873 
1874  JSC::JSValue savedException;
1875  QScriptEnginePrivate::saveException(exec, &savedException);
1876  JSC::JSValue result;
1877  JSC::JSObject *newObject = JSC::construct(exec, callee, constructType, constructData, applyArgs);
1878  if (exec->hadException()) {
1879  result = exec->exception();
1880  } else {
1881  result = newObject;
1882  QScriptEnginePrivate::restoreException(exec, savedException);
1883  }
1884  return d->engine->scriptValueFromJSCValue(result);
1885 }
double d
Definition: qnumeric_p.h:62
static mach_timebase_info_data_t info
#define Q_D(Class)
Definition: qglobal.h:2482
static QScriptEnginePrivate * getEngine(const QScriptValue &q)
QScriptValue()
Constructs an invalid QScriptValue.
Q_CORE_EXPORT void qWarning(const char *,...)
static void restoreException(JSC::ExecState *, JSC::JSValue)
quint32 toUInt32() const
Returns the unsigned 32-bit integer value of this QScriptValue, using the conversion rules described ...
static void saveException(JSC::ExecState *, JSC::JSValue *)
static void construct(QVariant::Private *x, const void *copy)
Definition: qvariant.cpp:75
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57

◆ data()

QScriptValue QScriptValue::data ( ) const

Returns the internal data of this QScriptValue object.

Since
4.4

QtScript uses this property to store the primitive value of Date, String, Number and Boolean objects. For other types of object, custom data may be stored using setData().

Definition at line 2094 of file qscriptvalue.cpp.

Referenced by NamedNodeMap::length(), NodeList::length(), QDeclarativeWorkerScriptEnginePrivate::onMessage(), QScript::FunctionWrapper::proxyCall(), QScript::FunctionWithArgWrapper::proxyCall(), QScript::FunctionWrapper::proxyConstruct(), QScript::FunctionWithArgWrapper::proxyConstruct(), qmlsqldatabase_item(), qmlxmlhttprequest_abort(), qmlxmlhttprequest_getAllResponseHeaders(), qmlxmlhttprequest_getResponseHeader(), qmlxmlhttprequest_onreadystatechange(), qmlxmlhttprequest_open(), qmlxmlhttprequest_readyState(), qmlxmlhttprequest_responseText(), qmlxmlhttprequest_responseXML(), qmlxmlhttprequest_send(), qmlxmlhttprequest_setRequestHeader(), qmlxmlhttprequest_status(), qmlxmlhttprequest_statusText(), QDeclarativeWorkerScriptEnginePrivate::sendMessage(), QScriptDebuggerBackendPrivate::trace(), and QDeclarativeInclude::worker_include().

2095 {
2096  Q_D(const QScriptValue);
2097  if (!d || !d->isObject())
2098  return QScriptValue();
2099  if (d->jscValue.inherits(&QScriptObject::info)) {
2100  QScriptObject *scriptObject = static_cast<QScriptObject*>(JSC::asObject(d->jscValue));
2101  return d->engine->scriptValueFromJSCValue(scriptObject->data());
2102  } else {
2103  // ### make hidden property
2104  return property(QLatin1String("__qt_data__"), QScriptValue::ResolveLocal);
2105  }
2106 }
double d
Definition: qnumeric_p.h:62
QScriptValue property(const QString &name, const ResolveFlags &mode=ResolvePrototype) const
Returns the value of this QScriptValue&#39;s property with the given name, using the given mode to resolv...
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
static const JSC::ClassInfo info
#define Q_D(Class)
Definition: qglobal.h:2482
JSC::JSValue data() const
QScriptValue()
Constructs an invalid QScriptValue.
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57

◆ engine()

QScriptEngine * QScriptValue::engine ( ) const

Returns the QScriptEngine that created this QScriptValue, or 0 if this QScriptValue is invalid or the value is not associated with a particular engine.

Definition at line 1892 of file qscriptvalue.cpp.

Referenced by QScriptValueIteratorPrivate::engine(), QDeclarativeItem::mapFromItem(), QDeclarativeItem::mapToItem(), QDeclarativeObjectScriptClass::newQObject(), QDeclarativeXMLHttpRequest::printError(), QScriptEngine::qScriptConnect(), QScriptEngine::qScriptDisconnect(), QScriptContext::setActivationObject(), QScriptContext::setThisObject(), and toObject().

1893 {
1894  Q_D(const QScriptValue);
1895  if (!d)
1896  return 0;
1897  return QScriptEnginePrivate::get(d->engine);
1898 }
double d
Definition: qnumeric_p.h:62
static QScriptEnginePrivate * get(QScriptEngine *q)
#define Q_D(Class)
Definition: qglobal.h:2482
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57

◆ equals()

bool QScriptValue::equals ( const QScriptValue other) const

Returns true if this QScriptValue is equal to other, otherwise returns false.

The comparison follows the behavior described in ECMA-262 section 11.9.3, "The Abstract Equality Comparison Algorithm".

This function can return true even if the type of this QScriptValue is different from the type of the other value; i.e. the comparison is not strict. For example, comparing the number 9 to the string "9" returns true; comparing an undefined value to a null value returns true; comparing a Number object whose primitive value is 6 to a String object whose primitive value is "6" returns true; and comparing the number 1 to the boolean value true returns true. If you want to perform a comparison without such implicit value conversion, use strictlyEquals().

Note that if this QScriptValue or the other value are objects, calling this function has side effects on the script engine, since the engine will call the object's valueOf() function (and possibly toString()) in an attempt to convert the object to a primitive value (possibly resulting in an uncaught script exception).

See also
strictlyEquals(), lessThan()

Definition at line 883 of file qscriptvalue.cpp.

884 {
885  Q_D(const QScriptValue);
886  if (!d || !other.d_ptr)
887  return (d_ptr == other.d_ptr);
888  if (QScriptValuePrivate::getEngine(other) && d->engine
889  && (QScriptValuePrivate::getEngine(other) != d->engine)) {
890  qWarning("QScriptValue::equals: "
891  "cannot compare to a value created in "
892  "a different engine");
893  return false;
894  }
895  if (d->isJSC() && other.d_ptr->isJSC()) {
896  QScriptEnginePrivate *eng_p = d->engine;
897  if (!eng_p)
898  eng_p = other.d_ptr->engine;
899  if (eng_p) {
900  QScript::APIShim shim(eng_p);
901  JSC::ExecState *exec = eng_p->currentFrame;
902  JSC::JSValue savedException;
903  QScriptEnginePrivate::saveException(exec, &savedException);
904  bool result = JSC::JSValue::equal(exec, d->jscValue, other.d_ptr->jscValue);
905  QScriptEnginePrivate::restoreException(exec, savedException);
906  return result;
907  }
908  }
909  return QScript::Equals(*this, other);
910 }
QExplicitlySharedDataPointer< QScriptValuePrivate > d_ptr
Definition: qscriptvalue.h:209
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
JSC::ExecState * currentFrame
static QScriptEnginePrivate * getEngine(const QScriptValue &q)
Q_CORE_EXPORT void qWarning(const char *,...)
static void restoreException(JSC::ExecState *, JSC::JSValue)
static void saveException(JSC::ExecState *, JSC::JSValue *)
static bool Equals(QScriptValue lhs, QScriptValue rhs)
JSC::JSValue jscValue
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57
QScriptEnginePrivate * engine
static bool equal(const QChar *a, int l, const char *b)
Definition: qurl.cpp:3270

◆ instanceOf()

bool QScriptValue::instanceOf ( const QScriptValue other) const

Returns true if this QScriptValue is an instance of other; otherwise returns false.

This QScriptValue is considered to be an instance of other if other is a function and the value of the prototype property of other is in the prototype chain of this QScriptValue.

Definition at line 662 of file qscriptvalue.cpp.

663 {
664  Q_D(const QScriptValue);
665  if (!d || !d->isObject() || !other.isObject())
666  return false;
667  if (QScriptValuePrivate::getEngine(other) != d->engine) {
668  qWarning("QScriptValue::instanceof: "
669  "cannot perform operation on a value created in "
670  "a different engine");
671  return false;
672  }
673  JSC::JSValue jscProto = d->engine->scriptValueToJSCValue(other.property(QLatin1String("prototype")));
674  if (!jscProto)
675  jscProto = JSC::jsUndefined();
676  JSC::ExecState *exec = d->engine->currentFrame;
677  JSC::JSValue jscOther = d->engine->scriptValueToJSCValue(other);
678  return JSC::asObject(jscOther)->hasInstance(exec, d->jscValue, jscProto);
679 }
double d
Definition: qnumeric_p.h:62
QScriptValue property(const QString &name, const ResolveFlags &mode=ResolvePrototype) const
Returns the value of this QScriptValue&#39;s property with the given name, using the given mode to resolv...
#define Q_D(Class)
Definition: qglobal.h:2482
static QScriptEnginePrivate * getEngine(const QScriptValue &q)
Q_CORE_EXPORT void qWarning(const char *,...)
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57
bool isObject() const
Returns true if this QScriptValue is of the Object type; otherwise returns false. ...

◆ isArray()

bool QScriptValue::isArray ( ) const

◆ isBool()

bool QScriptValue::isBool ( ) const

Returns true if this QScriptValue is of the primitive type Boolean; otherwise returns false.

Since
4.5
See also
toBool()

Definition at line 1925 of file qscriptvalue.cpp.

Referenced by QScript::Equals(), fromScriptValue(), QScript::IsNumerical(), and QDeclarativeWorkerScriptEnginePrivate::scriptValueToVariant().

1926 {
1927  Q_D(const QScriptValue);
1928  return d && d->isJSC() && d->jscValue.isBoolean();
1929 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57

◆ isBoolean()

bool QScriptValue::isBoolean ( ) const

Use isBool() instead.

Definition at line 1908 of file qscriptvalue.cpp.

Referenced by QDeclarativeObjectMethodScriptClass::matchScore(), QScriptDebuggerValue::QScriptDebuggerValue(), and QScript::type().

1909 {
1910  Q_D(const QScriptValue);
1911  return d && d->isJSC() && d->jscValue.isBoolean();
1912 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57

◆ isDate()

bool QScriptValue::isDate ( ) const

Returns true if this QScriptValue is an object of the Date class; otherwise returns false.

See also
QScriptEngine::newDate()

Definition at line 525 of file qscriptvalue.cpp.

Referenced by FlatListModel::addValue(), QDeclarativeEnginePrivate::formatTime(), fromScriptValue(), QDeclarativeObjectMethodScriptClass::matchScore(), QDeclarativeWorkerScriptEnginePrivate::scriptValueToVariant(), and FlatListScriptClass::setProperty().

526 {
527  Q_D(const QScriptValue);
528  if (!d || !d->isJSC())
529  return false;
530  return QScriptEnginePrivate::isDate(d->jscValue);
531 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
static bool isDate(JSC::JSValue)
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57

◆ isError()

bool QScriptValue::isError ( ) const

Returns true if this QScriptValue is an object of the Error class; otherwise returns false.

See also
QScriptContext::throwError()

Definition at line 497 of file qscriptvalue.cpp.

Referenced by QDeclarativeXMLHttpRequest::abort(), QDeclarativeXMLHttpRequest::downloadProgress(), QDeclarativeXMLHttpRequest::error(), QScriptEnginePrivate::evaluateHelper(), QDeclarativeExpressionPrivate::exceptionToError(), QDeclarativeXMLHttpRequest::finished(), fromScriptValue(), QScriptDebuggerScriptedConsoleCommandJob::handleResponse(), QScriptDebuggerAgent::positionChange(), QScriptDebuggerScriptedConsoleCommandJob::start(), and QScriptEngine::uncaughtExceptionBacktrace().

498 {
499  Q_D(const QScriptValue);
500  if (!d || !d->isJSC())
501  return false;
502  return QScriptEnginePrivate::isError(d->jscValue);
503 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
static bool isError(JSC::JSValue)
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57

◆ isFunction()

bool QScriptValue::isFunction ( ) const

Returns true if this QScriptValue is a function; otherwise returns false.

See also
call()

Definition at line 1981 of file qscriptvalue.cpp.

Referenced by expandObject(), fromScriptValue(), QScriptEngine::importExtension(), QDeclarativeInclude::include(), QDeclarativeWorkerScriptEnginePrivate::processMessage(), qmlsqldatabase_change_version(), qmlsqldatabase_open_sync(), QDeclarativeValueTypeScriptClass::setProperty(), QDeclarativeObjectScriptClass::setProperty(), QDeclarativeBinding::update(), and QDeclarativeInclude::worker_include().

1982 {
1983  Q_D(const QScriptValue);
1984  if (!d || !d->isJSC())
1985  return false;
1986  return QScript::isFunction(d->jscValue);
1987 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
bool isFunction(JSC::JSValue value)
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57

◆ isNull()

bool QScriptValue::isNull ( ) const

Returns true if this QScriptValue is of the primitive type Null; otherwise returns false.

See also
QScriptEngine::nullValue()

Definition at line 1995 of file qscriptvalue.cpp.

Referenced by QScript::Equals(), fromScriptValue(), QDeclarativeItem::mapFromItem(), QDeclarativeItem::mapToItem(), QDeclarativeObjectMethodScriptClass::matchScore(), QDeclarativeObjectMethodScriptClass::property(), QScriptDebuggerValue::QScriptDebuggerValue(), QDeclarativeObjectScriptClass::setProperty(), QScript::type(), and QDeclarativeBinding::update().

1996 {
1997  Q_D(const QScriptValue);
1998  return d && d->isJSC() && d->jscValue.isNull();
1999 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57

◆ isNumber()

bool QScriptValue::isNumber ( ) const

Returns true if this QScriptValue is of the primitive type Number; otherwise returns false.

See also
toNumber()

Definition at line 1937 of file qscriptvalue.cpp.

Referenced by _q_equal(), QScriptDebuggerBackendPrivate::exception(), QDeclarativeEnginePrivate::formatDate(), QDeclarativeEnginePrivate::formatDateTime(), QDeclarativeEnginePrivate::formatTime(), fromScriptValue(), QScript::IsNumerical(), QDeclarativeObjectMethodScriptClass::matchScore(), QScriptDebuggerValue::QScriptDebuggerValue(), QDeclarativeWorkerScriptEnginePrivate::scriptValueToVariant(), QDeclarativeObjectScriptClass::setProperty(), and QScript::type().

1938 {
1939  Q_D(const QScriptValue);
1940  if (!d)
1941  return false;
1942  switch (d->type) {
1944  return d->jscValue.isNumber();
1946  return true;
1948  return false;
1949  }
1950  return false;
1951 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57

◆ isObject()

bool QScriptValue::isObject ( ) const

Returns true if this QScriptValue is of the Object type; otherwise returns false.

Note that function values, variant values, and QObject values are objects, so this function returns true for such values.

See also
toObject(), QScriptEngine::newObject()

Definition at line 2022 of file qscriptvalue.cpp.

Referenced by FlatListModel::addValue(), QDeclarativeListModel::append(), QScript::ClassObjectDelegate::construct(), QDeclarativeComponent::createObject(), QDeclarativeComponentPrivate::createObject(), QScript::Equals(), QScriptDebuggerCommandExecutor::execute(), fromScriptValue(), QJSDebuggerAgentPrivate::getLocals(), QDeclarativeListModel::insert(), instanceOf(), QScript::LessThan(), QScriptEngine::newQObject(), QScript::FunctionWrapper::proxyConstruct(), QScript::FunctionWithArgWrapper::proxyConstruct(), qmlsqldatabase_executeSql(), QScriptEngine::qScriptConnect(), QScriptDebuggerValue::QScriptDebuggerValue(), QScriptEngine::qScriptDisconnect(), QDeclarativeWorkerScriptEnginePrivate::scriptValueToVariant(), QDeclarativeListModel::set(), QScriptContext::setActivationObject(), ModelNode::setListValue(), FlatListScriptClass::setProperty(), QScriptContext::setThisObject(), QScript::ToPrimitive(), and QScript::type().

2023 {
2024  Q_D(const QScriptValue);
2025  return d && d->isObject();
2026 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57

◆ isQMetaObject()

bool QScriptValue::isQMetaObject ( ) const

Returns true if this QScriptValue is a QMetaObject; otherwise returns false.

See also
toQMetaObject(), QScriptEngine::newQMetaObject()

Definition at line 2065 of file qscriptvalue.cpp.

2066 {
2067  Q_D(const QScriptValue);
2068  if (!d || !d->isJSC())
2069  return false;
2070  return QScriptEnginePrivate::isQMetaObject(d->jscValue);
2071 }
static bool isQMetaObject(JSC::JSValue)
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57

◆ isQObject()

bool QScriptValue::isQObject ( ) const

Returns true if this QScriptValue is a QObject; otherwise returns false.

Note: This function returns true even if the QObject that this QScriptValue wraps has been deleted.

See also
toQObject(), QScriptEngine::newQObject()

Definition at line 2051 of file qscriptvalue.cpp.

Referenced by QScript::Equals(), fromScriptValue(), QDeclarativeObjectMethodScriptClass::matchScore(), QScriptEngine::newQObject(), QDeclarativeObjectMethodScriptClass::property(), and QDeclarativeWorkerScriptEnginePrivate::scriptValueToVariant().

2052 {
2053  Q_D(const QScriptValue);
2054  if (!d || !d->isJSC())
2055  return false;
2056  return QScriptEnginePrivate::isQObject(d->jscValue);
2057 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
static bool isQObject(JSC::JSValue)
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57

◆ isRegExp()

bool QScriptValue::isRegExp ( ) const

Returns true if this QScriptValue is an object of the RegExp class; otherwise returns false.

See also
QScriptEngine::newRegExp()

Definition at line 539 of file qscriptvalue.cpp.

Referenced by FlatListModel::addValue(), fromScriptValue(), QDeclarativeObjectMethodScriptClass::matchScore(), QDeclarativeWorkerScriptEnginePrivate::scriptValueToVariant(), QDeclarativeValueTypeScriptClass::setProperty(), FlatListScriptClass::setProperty(), QDeclarativeObjectScriptClass::setProperty(), and QDeclarativeBinding::update().

540 {
541  Q_D(const QScriptValue);
542  if (!d || !d->isJSC())
543  return false;
544  return QScriptEnginePrivate::isRegExp(d->jscValue);
545 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
static bool isRegExp(JSC::JSValue)
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57

◆ isString()

bool QScriptValue::isString ( ) const

Returns true if this QScriptValue is of the primitive type String; otherwise returns false.

See also
toString()

Definition at line 1959 of file qscriptvalue.cpp.

Referenced by QScript::Equals(), QScriptDebuggerBackendPrivate::exception(), QDeclarativeEnginePrivate::formatDate(), QDeclarativeEnginePrivate::formatDateTime(), QDeclarativeEnginePrivate::formatTime(), fromScriptValue(), QScript::LessThan(), QDeclarativeObjectMethodScriptClass::matchScore(), QScriptDebuggerScriptedConsoleCommand::parse(), QScriptDebuggerValue::QScriptDebuggerValue(), QDeclarativeWorkerScriptEnginePrivate::scriptValueToVariant(), QDeclarativeObjectScriptClass::setProperty(), QScriptContext::toString(), and QScript::type().

1960 {
1961  Q_D(const QScriptValue);
1962  if (!d)
1963  return false;
1964  switch (d->type) {
1966  return d->jscValue.isString();
1968  return false;
1970  return true;
1971  }
1972  return false;
1973 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57

◆ isUndefined()

bool QScriptValue::isUndefined ( ) const

Returns true if this QScriptValue is of the primitive type Undefined; otherwise returns false.

See also
QScriptEngine::undefinedValue()

Definition at line 2007 of file qscriptvalue.cpp.

Referenced by QScriptDebuggerBackend::doPendingEvaluate(), QScript::Equals(), QDeclarativeQtScriptExpression::eval(), fromScriptValue(), QDeclarativeObjectMethodScriptClass::property(), QScriptDebuggerValue::QScriptDebuggerValue(), QDeclarativeObjectScriptClass::setProperty(), QScriptDebuggerBackendPrivate::stepped(), and QScript::type().

2008 {
2009  Q_D(const QScriptValue);
2010  return d && d->isJSC() && d->jscValue.isUndefined();
2011 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57

◆ isValid()

bool QScriptValue::isValid ( ) const

◆ isVariant()

bool QScriptValue::isVariant ( ) const

Returns true if this QScriptValue is a variant value; otherwise returns false.

See also
toVariant(), QScriptEngine::newVariant()

Definition at line 2034 of file qscriptvalue.cpp.

Referenced by FlatListModel::addValue(), QScript::Equals(), fromScriptValue(), QDeclarativeObjectMethodScriptClass::matchScore(), qscriptvalue_cast(), and FlatListScriptClass::setProperty().

2035 {
2036  Q_D(const QScriptValue);
2037  if (!d || !d->isJSC())
2038  return false;
2039  return QScriptEnginePrivate::isVariant(d->jscValue);
2040 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
static bool isVariant(JSC::JSValue)
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57

◆ lessThan()

bool QScriptValue::lessThan ( const QScriptValue other) const

Returns true if this QScriptValue is less than other, otherwise returns false.

The comparison follows the behavior described in ECMA-262 section 11.8.5, "The Abstract Relational Comparison Algorithm".

Note that if this QScriptValue or the other value are objects, calling this function has side effects on the script engine, since the engine will call the object's valueOf() function (and possibly toString()) in an attempt to convert the object to a primitive value (possibly resulting in an uncaught script exception).

See also
equals()

Definition at line 843 of file qscriptvalue.cpp.

844 {
845  Q_D(const QScriptValue);
846  // no equivalent function in JSC? There's a jsLess() in VM/Machine.cpp
847  if (!isValid() || !other.isValid())
848  return false;
849  if (QScriptValuePrivate::getEngine(other) && d->engine
850  && (QScriptValuePrivate::getEngine(other) != d->engine)) {
851  qWarning("QScriptValue::lessThan: "
852  "cannot compare to a value created in "
853  "a different engine");
854  return false;
855  }
856  return QScript::LessThan(*this, other);
857 }
double d
Definition: qnumeric_p.h:62
static bool LessThan(QScriptValue lhs, QScriptValue rhs)
#define Q_D(Class)
Definition: qglobal.h:2482
static QScriptEnginePrivate * getEngine(const QScriptValue &q)
Q_CORE_EXPORT void qWarning(const char *,...)
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57
bool isValid() const
Returns true if this QScriptValue is valid; otherwise returns false.

◆ objectId()

qint64 QScriptValue::objectId ( ) const

Returns the ID of this object, or -1 if this QScriptValue is not an object.

Warning
This function is not part of the public interface.
See also
QScriptEngine::objectById()

Definition at line 2216 of file qscriptvalue.cpp.

Referenced by fromScriptValue(), QJSDebuggerAgentPrivate::getLocals(), and QScriptDebuggerValue::QScriptDebuggerValue().

2217 {
2218  return d_ptr?d_ptr->objectId():-1;
2219 }
QExplicitlySharedDataPointer< QScriptValuePrivate > d_ptr
Definition: qscriptvalue.h:209

◆ operator=()

QScriptValue & QScriptValue::operator= ( const QScriptValue other)

Assigns the other value to this QScriptValue.

Note that if other is an object (isObject() returns true), only a reference to the underlying object will be assigned; the object itself will not be copied.

Definition at line 485 of file qscriptvalue.cpp.

486 {
487  d_ptr = other.d_ptr;
488  return *this;
489 }
QExplicitlySharedDataPointer< QScriptValuePrivate > d_ptr
Definition: qscriptvalue.h:209

◆ property() [1/3]

QScriptValue QScriptValue::property ( const QString name,
const ResolveFlags &  mode = ResolvePrototype 
) const

Returns the value of this QScriptValue's property with the given name, using the given mode to resolve the property.

If no such property exists, an invalid QScriptValue is returned.

If the property is implemented using a getter function (i.e. has the PropertyGetter flag set), calling property() has side-effects on the script engine, since the getter function will be called (possibly resulting in an uncaught script exception). If an exception occurred, property() returns the value that was thrown (typically an Error object).

See also
setProperty(), propertyFlags(), QScriptValueIterator

Definition at line 1432 of file qscriptvalue.cpp.

Referenced by QScript::__setupPackage__(), QScriptContext::argument(), QScriptDebuggerBackend::attachTo(), breakpointDataFromScriptValue(), QDeclarativeComponentPrivate::createObject(), data(), debuggerScriptValuePropertyFromScriptValue(), QDeclarativeXMLHttpRequest::dispatchCallback(), do_dbus_call(), QScriptDebuggerBackendPrivate::exception(), QScriptEngineAgentPrivate::exceptionThrow(), QDeclarativeExpressionPrivate::exceptionToError(), QScriptDebuggerCommandExecutor::execute(), fromScriptValue(), QScriptEngine::importExtension(), QDeclarativeEnginePrivate::init(), instanceOf(), QScriptDebuggerScriptedConsoleCommand::parse(), QDeclarativeObjectMethodScriptClass::property(), QDBusConnectionConstructor::QDBusConnectionConstructor(), qmlsqldatabase_change_version(), qmlsqldatabase_executeSql(), qmlxmlhttprequest_onreadystatechange(), qScriptValueToSequence(), scriptDataFromScriptValue(), scriptValueToMessage(), QDeclarativeWorkerScriptEnginePrivate::scriptValueToVariant(), QDeclarativeEnginePrivate::scriptValueToVariant(), ModelNode::setListValue(), QScriptExtensionPlugin::setupPackage(), QScriptEngine::uncaughtExceptionBacktrace(), and QScriptEngine::uncaughtExceptionLineNumber().

1434 {
1435  Q_D(const QScriptValue);
1436  if (!d || !d->isObject())
1437  return QScriptValue();
1438  QScript::APIShim shim(d->engine);
1439  return d->engine->scriptValueFromJSCValue(d->property(name, mode));
1440 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
QScriptValue()
Constructs an invalid QScriptValue.
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57

◆ property() [2/3]

QScriptValue QScriptValue::property ( quint32  arrayIndex,
const ResolveFlags &  mode = ResolvePrototype 
) const

Returns the property at the given arrayIndex, using the given mode to resolve the property.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

This function is provided for convenience and performance when working with array objects.

If this QScriptValue is not an Array object, this function behaves as if property() was called with the string representation of arrayIndex.

Definition at line 1458 of file qscriptvalue.cpp.

1460 {
1461  Q_D(const QScriptValue);
1462  if (!d || !d->isObject())
1463  return QScriptValue();
1464  QScript::APIShim shim(d->engine);
1465  return d->engine->scriptValueFromJSCValue(d->property(arrayIndex, mode));
1466 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
QScriptValue()
Constructs an invalid QScriptValue.
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57

◆ property() [3/3]

QScriptValue QScriptValue::property ( const QScriptString name,
const ResolveFlags &  mode = ResolvePrototype 
) const

Returns the value of this QScriptValue's property with the given name, using the given mode to resolve the property.

Since
4.4

This overload of property() is useful when you need to look up the same property repeatedly, since the lookup can be performed faster when the name is represented as an interned string.

See also
QScriptEngine::toStringHandle(), setProperty()

Definition at line 1515 of file qscriptvalue.cpp.

1517 {
1518  Q_D(const QScriptValue);
1519  if (!d || !d->isObject() || !QScriptStringPrivate::isValid(name))
1520  return QScriptValue();
1521  QScript::APIShim shim(d->engine);
1522  return d->engine->scriptValueFromJSCValue(d->property(name.d_ptr->identifier, mode));
1523 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
QScriptValue()
Constructs an invalid QScriptValue.
JSC::Identifier identifier
QExplicitlySharedDataPointer< QScriptStringPrivate > d_ptr
Definition: qscriptstring.h:58
static bool isValid(const QScriptString &q)
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57

◆ propertyFlags() [1/2]

QScriptValue::PropertyFlags QScriptValue::propertyFlags ( const QString name,
const ResolveFlags &  mode = ResolvePrototype 
) const

Returns the flags of the property with the given name, using the given mode to resolve the property.

See also
property()

Definition at line 1566 of file qscriptvalue.cpp.

Referenced by QScriptClassPropertyIterator::flags().

1568 {
1569  Q_D(const QScriptValue);
1570  if (!d || !d->isObject())
1571  return 0;
1572  QScript::APIShim shim(d->engine);
1573  JSC::ExecState *exec = d->engine->currentFrame;
1574  return d->propertyFlags(JSC::Identifier(exec, name), mode);
1575 
1576 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57

◆ propertyFlags() [2/2]

QScriptValue::PropertyFlags QScriptValue::propertyFlags ( const QScriptString name,
const ResolveFlags &  mode = ResolvePrototype 
) const

Returns the flags of the property with the given name, using the given mode to resolve the property.

Since
4.4
See also
property()

Definition at line 1589 of file qscriptvalue.cpp.

1591 {
1592  Q_D(const QScriptValue);
1593  if (!d || !d->isObject() || !QScriptStringPrivate::isValid(name))
1594  return 0;
1595  return d->propertyFlags(name.d_ptr->identifier, mode);
1596 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
JSC::Identifier identifier
QExplicitlySharedDataPointer< QScriptStringPrivate > d_ptr
Definition: qscriptstring.h:58
static bool isValid(const QScriptString &q)
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57

◆ prototype()

QScriptValue QScriptValue::prototype ( ) const

If this QScriptValue is an object, returns the internal prototype (__proto__ property) of this object; otherwise returns an invalid QScriptValue.

See also
setPrototype(), isObject()

Definition at line 554 of file qscriptvalue.cpp.

Referenced by QScriptDebuggerCommandExecutor::execute().

555 {
556  Q_D(const QScriptValue);
557  if (!d || !d->isObject())
558  return QScriptValue();
559  return d->engine->scriptValueFromJSCValue(JSC::asObject(d->jscValue)->prototype());
560 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
QScriptValue()
Constructs an invalid QScriptValue.
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57

◆ scope()

QScriptValue QScriptValue::scope ( ) const
Warning
This function is not part of the public interface.

Definition at line 616 of file qscriptvalue.cpp.

617 {
618  Q_D(const QScriptValue);
619  if (!d || !d->isObject())
620  return QScriptValue();
621  QScript::APIShim shim(d->engine);
622  // ### make hidden property
623  JSC::JSValue result = d->property("__qt_scope__", QScriptValue::ResolveLocal);
624  return d->engine->scriptValueFromJSCValue(result);
625 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
QScriptValue()
Constructs an invalid QScriptValue.
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57

◆ scriptClass()

QScriptClass * QScriptValue::scriptClass ( ) const

Returns the custom script class that this script object is an instance of, or 0 if the object is not of a custom class.

Since
4.4
See also
setScriptClass()

Definition at line 2154 of file qscriptvalue.cpp.

2155 {
2156  Q_D(const QScriptValue);
2157  if (!d || !d->isJSC() || !d->jscValue.inherits(&QScriptObject::info))
2158  return 0;
2159  QScriptObject *scriptObject = static_cast<QScriptObject*>(JSC::asObject(d->jscValue));
2160  QScriptObjectDelegate *delegate = scriptObject->delegate();
2161  if (!delegate || (delegate->type() != QScriptObjectDelegate::ClassObject))
2162  return 0;
2163  return static_cast<QScript::ClassObjectDelegate*>(delegate)->scriptClass();
2164 }
double d
Definition: qnumeric_p.h:62
virtual Type type() const =0
QScriptObjectDelegate * delegate() const
static const JSC::ClassInfo info
#define Q_D(Class)
Definition: qglobal.h:2482
QScriptClass * scriptClass() const
Returns the custom script class that this script object is an instance of, or 0 if the object is not ...
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57

◆ setData()

void QScriptValue::setData ( const QScriptValue data)

Sets the internal data of this QScriptValue object.

Since
4.4

You can use this function to set object-specific data that won't be directly accessible to scripts, but may be retrieved in C++ using the data() function.

See also
QScriptEngine::reportAdditionalMemoryCost()

Definition at line 2121 of file qscriptvalue.cpp.

Referenced by NamedNodeMap::create(), NodeList::create(), QDeclarativeWorkerScriptEnginePrivate::getWorker(), QScriptEngine::newObject(), QDeclarativeWorkerScriptEnginePrivate::processLoad(), qmlsqldatabase_executeSql(), qmlxmlhttprequest_new(), QScriptDebuggerBackend::traceFunction(), QDeclarativeWorkerScriptEnginePrivate::variantToScriptValue(), and QDeclarativeInclude::worker_include().

2122 {
2123  Q_D(QScriptValue);
2124  if (!d || !d->isObject())
2125  return;
2126  QScript::APIShim shim(d->engine);
2127  JSC::JSValue other = d->engine->scriptValueToJSCValue(data);
2128  if (d->jscValue.inherits(&QScriptObject::info)) {
2129  QScriptObject *scriptObject = static_cast<QScriptObject*>(JSC::asObject(d->jscValue));
2130  scriptObject->setData(other);
2131  } else {
2132  JSC::ExecState *exec = d->engine->currentFrame;
2133  JSC::Identifier id = JSC::Identifier(exec, "__qt_data__");
2134  if (!data.isValid()) {
2135  JSC::asObject(d->jscValue)->removeDirect(id);
2136  } else {
2137  // ### make hidden property
2138  JSC::asObject(d->jscValue)->putDirect(id, other);
2139  }
2140  }
2141 }
double d
Definition: qnumeric_p.h:62
static const JSC::ClassInfo info
#define Q_D(Class)
Definition: qglobal.h:2482
void setData(JSC::JSValue data)
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57
bool isValid() const
Returns true if this QScriptValue is valid; otherwise returns false.

◆ setProperty() [1/3]

void QScriptValue::setProperty ( const QString name,
const QScriptValue value,
const PropertyFlags flags = KeepExistingFlags 
)

Sets the value of this QScriptValue's property with the given name to the given value.

If this QScriptValue is not an object, this function does nothing.

If this QScriptValue does not already have a property with name name, a new property is created; the given flags then specify how this property may be accessed by script code.

If value is invalid, the property is removed.

If the property is implemented using a setter function (i.e. has the PropertySetter flag set), calling setProperty() has side-effects on the script engine, since the setter function will be called with the given value as argument (possibly resulting in an uncaught script exception).

Note that you cannot specify custom getter or setter functions for built-in properties, such as the length property of Array objects or meta properties of QObject objects.

See also
property()

Definition at line 1399 of file qscriptvalue.cpp.

Referenced by QScript::__setupPackage__(), QScriptDebuggerBackend::attachTo(), breakpointDataToScriptValue(), breakpointMapToScriptValue(), QDeclarativeInclude::callback(), consoleCommandGroupDataToScriptValue(), consoleCommandGroupMapToScriptValue(), consoleCommandToScriptValue(), contextInfoToScriptValue(), QDeclarativeComponentPrivate::createObject(), QDeclarativeEnginePrivate::createQmlObject(), debuggerResponseToScriptValue(), debuggerScriptValuePropertyToScriptValue(), QScriptDebuggerBackend::detach(), QScriptDebuggerCommandExecutor::execute(), QDeclarativeGlobalScriptClass::explicitSetProperty(), QDeclarativeInclude::finished(), QDeclarativeXmlListModel::get(), QDeclarativeWorkerScriptEnginePrivate::getWorker(), QScriptEngine::importExtension(), QDeclarativeInclude::include(), QDeclarativeEnginePrivate::init(), QtDBusScriptPlugin::initialize(), QDeclarativeItem::mapFromItem(), QDeclarativeItem::mapToItem(), messageToScriptValue(), QScriptEngine::newFunction(), QScriptDebuggerScriptedConsoleCommand::parse(), QDeclarativeWorkerScriptEnginePrivate::processMessage(), QDeclarativeObjectMethodScriptClass::property(), ModelNodeMetaObject::propertyWritten(), NamedNodeMap::prototype(), NodeList::prototype(), Node::prototype(), Element::prototype(), Attr::prototype(), CharacterData::prototype(), Text::prototype(), Document::prototype(), QDBusConnectionConstructor::QDBusConnectionConstructor(), qDBusErrorToScriptValue(), qDBusReplyToScriptValue(), QDeclarativeGlobalScriptClass::QDeclarativeGlobalScriptClass(), QDeclarativeScriptEngine::QDeclarativeScriptEngine(), qmlsqldatabase_change_version(), qmlsqldatabase_executeSql(), qmlsqldatabase_item(), qmlsqldatabase_open_sync(), qmlsqldatabase_transaction_shared(), qmlxmlhttprequest_onreadystatechange(), QScriptDebuggerBackendPrivate::qsassert(), QScriptDBusInterfaceConstructor::QScriptDBusInterfaceConstructor(), QScriptDBusMessageConstructor::QScriptDBusMessageConstructor(), qScriptValueFromSequence(), qt_add_qmlsqldatabase(), qt_add_qmlxmlhttprequest(), QDeclarativeInclude::resultValue(), scriptDataToScriptValue(), scriptMapToScriptValue(), QDeclarativeEnginePrivate::scriptValueFromVariant(), QJSDebuggerAgent::setProperty(), setupDBusInterface(), QScriptExtensionPlugin::setupPackage(), QDeclarativeWorkerScriptEnginePrivate::variantToScriptValue(), and QDeclarativeInclude::worker_include().

1401 {
1402  Q_D(QScriptValue);
1403  if (!d || !d->isObject())
1404  return;
1405  QScript::APIShim shim(d->engine);
1407  if (valueEngine && (valueEngine != d->engine)) {
1408  qWarning("QScriptValue::setProperty(%s) failed: "
1409  "cannot set value created in a different engine",
1410  qPrintable(name));
1411  return;
1412  }
1413  JSC::JSValue jsValue = d->engine->scriptValueToJSCValue(value);
1414  d->setProperty(name, jsValue, flags);
1415 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
static QScriptEnginePrivate * getEngine(const QScriptValue &q)
Q_CORE_EXPORT void qWarning(const char *,...)
#define qPrintable(string)
Definition: qglobal.h:1750
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57

◆ setProperty() [2/3]

void QScriptValue::setProperty ( quint32  arrayIndex,
const QScriptValue value,
const PropertyFlags flags = KeepExistingFlags 
)

Sets the property at the given arrayIndex to the given value.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

This function is provided for convenience and performance when working with array objects.

If this QScriptValue is not an Array object, this function behaves as if setProperty() was called with the string representation of arrayIndex.

Definition at line 1483 of file qscriptvalue.cpp.

1485 {
1486  Q_D(QScriptValue);
1487  if (!d || !d->isObject())
1488  return;
1490  && (QScriptValuePrivate::getEngine(value) != d->engine)) {
1491  qWarning("QScriptValue::setProperty() failed: "
1492  "cannot set value created in a different engine");
1493  return;
1494  }
1495  QScript::APIShim shim(d->engine);
1496  JSC::JSValue jsValue = d->engine->scriptValueToJSCValue(value);
1497  d->setProperty(arrayIndex, jsValue, flags);
1498 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
static QScriptEnginePrivate * getEngine(const QScriptValue &q)
Q_CORE_EXPORT void qWarning(const char *,...)
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57

◆ setProperty() [3/3]

void QScriptValue::setProperty ( const QScriptString name,
const QScriptValue value,
const PropertyFlags flags = KeepExistingFlags 
)

Sets the value of this QScriptValue's property with the given name to the given value.

Since
4.4

The given flags specify how this property may be accessed by script code.

This overload of setProperty() is useful when you need to set the same property repeatedly, since the operation can be performed faster when the name is represented as an interned string.

See also
QScriptEngine::toStringHandle()

Definition at line 1541 of file qscriptvalue.cpp.

1544 {
1545  Q_D(QScriptValue);
1546  if (!d || !d->isObject() || !QScriptStringPrivate::isValid(name))
1547  return;
1549  if (valueEngine && (valueEngine != d->engine)) {
1550  qWarning("QScriptValue::setProperty(%s) failed: "
1551  "cannot set value created in a different engine",
1552  qPrintable(name.toString()));
1553  return;
1554  }
1555  QScript::APIShim shim(d->engine);
1556  JSC::JSValue jsValue = d->engine->scriptValueToJSCValue(value);
1557  d->setProperty(name.d_ptr->identifier, jsValue, flags);
1558 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
static QScriptEnginePrivate * getEngine(const QScriptValue &q)
Q_CORE_EXPORT void qWarning(const char *,...)
JSC::Identifier identifier
QExplicitlySharedDataPointer< QScriptStringPrivate > d_ptr
Definition: qscriptstring.h:58
static bool isValid(const QScriptString &q)
QString toString() const
Returns the string that this QScriptString represents, or a null string if this QScriptString is not ...
#define qPrintable(string)
Definition: qglobal.h:1750
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57

◆ setPrototype()

void QScriptValue::setPrototype ( const QScriptValue prototype)

If this QScriptValue is an object, sets the internal prototype (__proto__ property) of this object to be prototype; otherwise does nothing.

The internal prototype should not be confused with the public property with name "prototype"; the public prototype is usually only set on functions that act as constructors.

See also
prototype(), isObject()

Definition at line 573 of file qscriptvalue.cpp.

Referenced by NamedNodeMap::create(), NodeList::create(), Node::create(), Document::load(), QScriptEngine::newObject(), Element::prototype(), Attr::prototype(), CharacterData::prototype(), Text::prototype(), CDATA::prototype(), Document::prototype(), and QDBusConnectionConstructor::QDBusConnectionConstructor().

574 {
575  Q_D(QScriptValue);
576  if (!d || !d->isObject())
577  return;
578 
579  JSC::JSValue other = d->engine->scriptValueToJSCValue(prototype);
580  if (!other || !(other.isObject() || other.isNull()))
581  return;
582 
583  if (QScriptValuePrivate::getEngine(prototype)
584  && (QScriptValuePrivate::getEngine(prototype) != d->engine)) {
585  qWarning("QScriptValue::setPrototype() failed: "
586  "cannot set a prototype created in "
587  "a different engine");
588  return;
589  }
590  JSC::JSObject *thisObject = JSC::asObject(d->jscValue);
591 
592  // check for cycle
593  JSC::JSValue nextPrototypeValue = other;
594  while (nextPrototypeValue && nextPrototypeValue.isObject()) {
595  JSC::JSObject *nextPrototype = JSC::asObject(nextPrototypeValue);
596  if (nextPrototype == thisObject) {
597  qWarning("QScriptValue::setPrototype() failed: cyclic prototype value");
598  return;
599  }
600  nextPrototypeValue = nextPrototype->prototype();
601  }
602 
603  thisObject->setPrototype(other);
604 
605  // Sync the internal Global Object prototype if appropriate.
606  if (((thisObject == d->engine->originalGlobalObjectProxy)
607  && !d->engine->customGlobalObject())
608  || (thisObject == d->engine->customGlobalObject())) {
609  d->engine->originalGlobalObject()->setPrototype(other);
610  }
611 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
static QScriptEnginePrivate * getEngine(const QScriptValue &q)
Q_CORE_EXPORT void qWarning(const char *,...)
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57

◆ setScope()

void QScriptValue::setScope ( const QScriptValue scope)
Warning
This function is not part of the public interface.

Definition at line 630 of file qscriptvalue.cpp.

631 {
632  Q_D(QScriptValue);
633  if (!d || !d->isObject())
634  return;
635  if (scope.isValid() && QScriptValuePrivate::getEngine(scope)
636  && (QScriptValuePrivate::getEngine(scope) != d->engine)) {
637  qWarning("QScriptValue::setScope() failed: "
638  "cannot set a scope object created in "
639  "a different engine");
640  return;
641  }
642  JSC::JSValue other = d->engine->scriptValueToJSCValue(scope);
643  JSC::ExecState *exec = d->engine->currentFrame;
644  JSC::Identifier id = JSC::Identifier(exec, "__qt_scope__");
645  if (!scope.isValid()) {
646  JSC::asObject(d->jscValue)->removeDirect(id);
647  } else {
648  // ### make hidden property
649  JSC::asObject(d->jscValue)->putDirect(id, other);
650  }
651 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
static QScriptEnginePrivate * getEngine(const QScriptValue &q)
Q_CORE_EXPORT void qWarning(const char *,...)
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57
bool isValid() const
Returns true if this QScriptValue is valid; otherwise returns false.

◆ setScriptClass()

void QScriptValue::setScriptClass ( QScriptClass scriptClass)

Sets the custom script class of this script object to scriptClass.

Since
4.4

This can be used to "promote" a plain script object (e.g. created by the "new" operator in a script, or by QScriptEngine::newObject() in C++) to an object of a custom type.

If scriptClass is 0, the object will be demoted to a plain script object.

See also
scriptClass(), setData()

Definition at line 2182 of file qscriptvalue.cpp.

Referenced by NamedNodeMap::create(), NodeList::create(), QDeclarativeGlobalScriptClass::explicitSetProperty(), and QDeclarativeGlobalScriptClass::QDeclarativeGlobalScriptClass().

2183 {
2184  Q_D(QScriptValue);
2185  if (!d || !d->isObject())
2186  return;
2187  if (!d->jscValue.inherits(&QScriptObject::info)) {
2188  qWarning("QScriptValue::setScriptClass() failed: "
2189  "cannot change class of non-QScriptObject");
2190  return;
2191  }
2192  QScriptObject *scriptObject = static_cast<QScriptObject*>(JSC::asObject(d->jscValue));
2193  if (!scriptClass) {
2194  scriptObject->setDelegate(0);
2195  } else {
2196  QScriptObjectDelegate *delegate = scriptObject->delegate();
2197  if (!delegate || (delegate->type() != QScriptObjectDelegate::ClassObject)) {
2198  delegate = new QScript::ClassObjectDelegate(scriptClass);
2199  scriptObject->setDelegate(delegate);
2200  }
2201  static_cast<QScript::ClassObjectDelegate*>(delegate)->setScriptClass(scriptClass);
2202  }
2203 }
double d
Definition: qnumeric_p.h:62
virtual Type type() const =0
QScriptObjectDelegate * delegate() const
static const JSC::ClassInfo info
#define Q_D(Class)
Definition: qglobal.h:2482
Q_CORE_EXPORT void qWarning(const char *,...)
void setScriptClass(QScriptClass *scriptClass)
Sets the custom script class of this script object to scriptClass.
void setDelegate(QScriptObjectDelegate *delegate)
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57

◆ strictlyEquals()

bool QScriptValue::strictlyEquals ( const QScriptValue other) const

Returns true if this QScriptValue is equal to other using strict comparison (no conversion), otherwise returns false.

The comparison follows the behavior described in ECMA-262 section 11.9.6, "The Strict Equality Comparison Algorithm".

If the type of this QScriptValue is different from the type of the other value, this function returns false. If the types are equal, the result depends on the type, as shown in the following table:

Type Result
Undefined true
Null true
Boolean true if both values are true, false otherwise
Number false if either value is NaN (Not-a-Number); true if values are equal, false otherwise
String true if both values are exactly the same sequence of characters, false otherwise
Object true if both values refer to the same object, false otherwise
See also
equals()

Definition at line 934 of file qscriptvalue.cpp.

Referenced by _q_equal(), and QScript::Equals().

935 {
936  Q_D(const QScriptValue);
937  if (!d || !other.d_ptr)
938  return (d_ptr == other.d_ptr);
939  if (QScriptValuePrivate::getEngine(other) && d->engine
940  && (QScriptValuePrivate::getEngine(other) != d->engine)) {
941  qWarning("QScriptValue::strictlyEquals: "
942  "cannot compare to a value created in "
943  "a different engine");
944  return false;
945  }
946 
947  if (d->type != other.d_ptr->type) {
948  if (d->type == QScriptValuePrivate::JavaScriptCore) {
949  QScriptEnginePrivate *eng_p = d->engine ? d->engine : other.d_ptr->engine;
950  if (eng_p)
951  return JSC::JSValue::strictEqual(eng_p->currentFrame, d->jscValue, eng_p->scriptValueToJSCValue(other));
952  } else if (other.d_ptr->type == QScriptValuePrivate::JavaScriptCore) {
953  QScriptEnginePrivate *eng_p = other.d_ptr->engine ? other.d_ptr->engine : d->engine;
954  if (eng_p)
955  return JSC::JSValue::strictEqual(eng_p->currentFrame, eng_p->scriptValueToJSCValue(*this), other.d_ptr->jscValue);
956  }
957 
958  return false;
959  }
960  switch (d->type) {
962  QScriptEnginePrivate *eng_p = d->engine ? d->engine : other.d_ptr->engine;
963  JSC::ExecState *exec = eng_p ? eng_p->currentFrame : 0;
964  return JSC::JSValue::strictEqual(exec, d->jscValue, other.d_ptr->jscValue);
965  }
967  return (d->numberValue == other.d_ptr->numberValue);
969  return (d->stringValue == other.d_ptr->stringValue);
970  }
971  return false;
972 }
QExplicitlySharedDataPointer< QScriptValuePrivate > d_ptr
Definition: qscriptvalue.h:209
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
JSC::ExecState * currentFrame
JSC::JSValue scriptValueToJSCValue(const QScriptValue &value)
static QScriptEnginePrivate * getEngine(const QScriptValue &q)
Q_CORE_EXPORT void qWarning(const char *,...)
JSC::JSValue jscValue
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57
QScriptEnginePrivate * engine

◆ toBool()

bool QScriptValue::toBool ( ) const

Returns the boolean value of this QScriptValue, using the conversion rules described in ECMA-262 section 9.

Since
4.5

2, "ToBoolean".

Note that if this QScriptValue is an object, calling this function has side effects on the script engine, since the engine will call the object's valueOf() function (and possibly toString()) in an attempt to convert the object to a primitive value (possibly resulting in an uncaught script exception).

See also
isBool()

Definition at line 1088 of file qscriptvalue.cpp.

Referenced by QScript::Equals(), QScript::LessThan(), QDeclarativeObjectMethodScriptClass::property(), QDeclarativeWorkerScriptEnginePrivate::scriptValueToVariant(), and QDeclarativeSqlQueryScriptClass::setProperty().

1089 {
1090  Q_D(const QScriptValue);
1091  if (!d)
1092  return false;
1093  switch (d->type) {
1095  if (d->engine) {
1096  QScript::APIShim shim(d->engine);
1097  return QScriptEnginePrivate::toBool(d->engine->currentFrame, d->jscValue);
1098  } else {
1099  return QScriptEnginePrivate::toBool(0, d->jscValue);
1100  }
1101  }
1103  return QScript::ToBool(d->numberValue);
1105  return QScript::ToBool(d->stringValue);
1106  }
1107  return false;
1108 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
bool ToBool(qsreal)
static bool toBool(JSC::ExecState *, JSC::JSValue)
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57

◆ toBoolean()

bool QScriptValue::toBoolean ( ) const

Use toBool() instead.

Definition at line 1049 of file qscriptvalue.cpp.

Referenced by breakpointDataFromScriptValue(), QScriptDebuggerAgent::positionChange(), qmlxmlhttprequest_open(), QScriptDebuggerBackendPrivate::qsassert(), QScriptDebuggerValue::QScriptDebuggerValue(), and scriptValueToMessage().

1050 {
1051  Q_D(const QScriptValue);
1052  if (!d)
1053  return false;
1054  switch (d->type) {
1056  if (d->engine) {
1057  QScript::APIShim shim(d->engine);
1058  return QScriptEnginePrivate::toBool(d->engine->currentFrame, d->jscValue);
1059  } else {
1060  return QScriptEnginePrivate::toBool(0, d->jscValue);
1061  }
1062  }
1064  return QScript::ToBool(d->numberValue);
1066  return QScript::ToBool(d->stringValue);
1067  }
1068  return false;
1069 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
bool ToBool(qsreal)
static bool toBool(JSC::ExecState *, JSC::JSValue)
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57

◆ toDateTime()

QDateTime QScriptValue::toDateTime ( ) const

Returns a QDateTime representation of this value, in local time.

If this QScriptValue is not a date, or the value of the date is NaN (Not-a-Number), an invalid QDateTime is returned.

See also
isDate()

Definition at line 1313 of file qscriptvalue.cpp.

Referenced by QDeclarativeEnginePrivate::formatDate(), QDeclarativeEnginePrivate::formatDateTime(), QDeclarativeEnginePrivate::formatTime(), fromScriptValue(), and QDeclarativeWorkerScriptEnginePrivate::scriptValueToVariant().

1314 {
1315  Q_D(const QScriptValue);
1316  if (!d || !d->engine)
1317  return QDateTime();
1318  QScript::APIShim shim(d->engine);
1319  return QScriptEnginePrivate::toDateTime(d->engine->currentFrame, d->jscValue);
1320 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
static QDateTime toDateTime(JSC::ExecState *, JSC::JSValue)
The QDateTime class provides date and time functions.
Definition: qdatetime.h:216
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57

◆ toInt32()

qint32 QScriptValue::toInt32 ( ) const

Returns the signed 32-bit integer value of this QScriptValue, using the conversion rules described in ECMA-262 section 9.5, "ToInt32".

Note that if this QScriptValue is an object, calling this function has side effects on the script engine, since the engine will call the object's valueOf() function (and possibly toString()) in an attempt to convert the object to a primitive value (possibly resulting in an uncaught script exception).

See also
toNumber(), toUInt32()

Definition at line 1122 of file qscriptvalue.cpp.

Referenced by breakpointDataFromScriptValue(), debuggerScriptValuePropertyFromScriptValue(), QDeclarativeObjectScriptClass::destroy(), QScriptDebuggerBackendPrivate::exception(), QScriptEngineAgentPrivate::exceptionThrow(), QDeclarativeObjectMethodScriptClass::property(), qmlsqldatabase_executeSql(), scriptDataFromScriptValue(), QDeclarativeEnginePrivate::scriptValueToVariant(), ModelNode::setListValue(), QScriptEngine::uncaughtExceptionBacktrace(), and QScriptEngine::uncaughtExceptionLineNumber().

1123 {
1124  Q_D(const QScriptValue);
1125  if (!d)
1126  return 0;
1127  switch (d->type) {
1129  if (d->engine) {
1130  QScript::APIShim shim(d->engine);
1131  return QScriptEnginePrivate::toInt32(d->engine->currentFrame, d->jscValue);
1132  } else {
1133  return QScriptEnginePrivate::toInt32(0, d->jscValue);
1134  }
1135  }
1137  return QScript::ToInt32(d->numberValue);
1139  return QScript::ToInt32(d->stringValue);
1140  }
1141  return 0;
1142 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
static qint32 toInt32(JSC::ExecState *, JSC::JSValue)
qint32 ToInt32(qsreal n)
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57

◆ toInteger()

qsreal QScriptValue::toInteger ( ) const

Returns the integer value of this QScriptValue, using the conversion rules described in ECMA-262 section 9.4, "ToInteger".

Note that if this QScriptValue is an object, calling this function has side effects on the script engine, since the engine will call the object's valueOf() function (and possibly toString()) in an attempt to convert the object to a primitive value (possibly resulting in an uncaught script exception).

See also
toNumber()

Definition at line 1224 of file qscriptvalue.cpp.

1225 {
1226  Q_D(const QScriptValue);
1227  if (!d)
1228  return 0;
1229  switch (d->type) {
1231  if (d->engine) {
1232  QScript::APIShim shim(d->engine);
1233  return QScriptEnginePrivate::toInteger(d->engine->currentFrame, d->jscValue);
1234  } else {
1235  return QScriptEnginePrivate::toInteger(0, d->jscValue);
1236  }
1237  }
1239  return QScript::ToInteger(d->numberValue);
1241  return QScript::ToInteger(d->stringValue);
1242  }
1243  return 0;
1244 }
double d
Definition: qnumeric_p.h:62
qsreal ToInteger(qsreal n)
#define Q_D(Class)
Definition: qglobal.h:2482
static qsreal toInteger(JSC::ExecState *, JSC::JSValue)
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57

◆ toNumber()

qsreal QScriptValue::toNumber ( ) const

Returns the number value of this QScriptValue, as defined in ECMA-262 section 9.3, "ToNumber".

Note that if this QScriptValue is an object, calling this function has side effects on the script engine, since the engine will call the object's valueOf() function (and possibly toString()) in an attempt to convert the object to a primitive value (possibly resulting in an uncaught script exception).

See also
isNumber(), toInteger(), toInt32(), toUInt32(), toUInt16()

Definition at line 1019 of file qscriptvalue.cpp.

Referenced by _q_equal(), breakpointDataFromScriptValue(), QDeclarativeEnginePrivate::darker(), QScript::Equals(), QDeclarativeEnginePrivate::hsla(), QScript::LessThan(), QDeclarativeEnginePrivate::lighter(), QDeclarativeEnginePrivate::point(), QDeclarativeObjectMethodScriptClass::property(), qmlsqldatabase_item(), qmlsqldatabase_open_sync(), QScriptDebuggerValue::QScriptDebuggerValue(), QDeclarativeEnginePrivate::rect(), QDeclarativeEnginePrivate::rgba(), QDeclarativeWorkerScriptEnginePrivate::scriptValueToVariant(), QDeclarativeObjectScriptClass::setProperty(), QDeclarativeEnginePrivate::size(), and QDeclarativeEnginePrivate::vector3d().

1020 {
1021  Q_D(const QScriptValue);
1022  if (!d)
1023  return 0;
1024  switch (d->type) {
1026  if (d->engine) {
1027  QScript::APIShim shim(d->engine);
1028  return QScriptEnginePrivate::toNumber(d->engine->currentFrame, d->jscValue);
1029  } else {
1030  return QScriptEnginePrivate::toNumber(0, d->jscValue);
1031  }
1032  }
1034  return d->numberValue;
1036  return QScript::ToNumber(d->stringValue);
1037  }
1038  return 0;
1039 }
double d
Definition: qnumeric_p.h:62
static qsreal toNumber(JSC::ExecState *, JSC::JSValue)
#define Q_D(Class)
Definition: qglobal.h:2482
qsreal ToNumber(const QString &)
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57

◆ toObject()

QScriptValue QScriptValue::toObject ( ) const

This function is obsolete; use QScriptEngine::toObject() instead.

Definition at line 1298 of file qscriptvalue.cpp.

1299 {
1300  Q_D(const QScriptValue);
1301  if (!d || !d->engine)
1302  return QScriptValue();
1303  return engine()->toObject(*this);
1304 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
QScriptValue()
Constructs an invalid QScriptValue.
QScriptEngine * engine() const
Returns the QScriptEngine that created this QScriptValue, or 0 if this QScriptValue is invalid or the...
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57
QScriptValue toObject(const QScriptValue &value)
Converts the given value to an object, if such a conversion is possible; otherwise returns an invalid...

◆ toQMetaObject()

const QMetaObject * QScriptValue::toQMetaObject ( ) const

If this QScriptValue is a QMetaObject, returns the QMetaObject pointer that the QScriptValue represents; otherwise, returns 0.

See also
isQMetaObject()

Definition at line 1365 of file qscriptvalue.cpp.

1366 {
1367  Q_D(const QScriptValue);
1368  if (!d || !d->engine)
1369  return 0;
1370  QScript::APIShim shim(d->engine);
1371  return QScriptEnginePrivate::toQMetaObject(d->engine->currentFrame, d->jscValue);
1372 }
double d
Definition: qnumeric_p.h:62
static const QMetaObject * toQMetaObject(JSC::ExecState *, JSC::JSValue)
#define Q_D(Class)
Definition: qglobal.h:2482
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57

◆ toQObject()

QObject * QScriptValue::toQObject ( ) const

If this QScriptValue is a QObject, returns the QObject pointer that the QScriptValue represents; otherwise, returns 0.

If the QObject that this QScriptValue wraps has been deleted, this function returns 0 (i.e. it is possible for toQObject() to return 0 even when isQObject() returns true).

See also
isQObject()

Definition at line 1350 of file qscriptvalue.cpp.

Referenced by do_dbus_call(), QScript::Equals(), fromScriptValue(), QDeclarativeEnginePrivate::isQtObject(), QDeclarativeItem::mapFromItem(), QDeclarativeItem::mapToItem(), QDeclarativeObjectMethodScriptClass::property(), qmlxmlhttprequest_abort(), qmlxmlhttprequest_getAllResponseHeaders(), qmlxmlhttprequest_getResponseHeader(), qmlxmlhttprequest_onreadystatechange(), qmlxmlhttprequest_open(), qmlxmlhttprequest_readyState(), qmlxmlhttprequest_responseText(), qmlxmlhttprequest_responseXML(), qmlxmlhttprequest_send(), qmlxmlhttprequest_setRequestHeader(), qmlxmlhttprequest_status(), qmlxmlhttprequest_statusText(), QScriptDBusInterfaceConstructor::qscript_call(), QDeclarativeWorkerScriptEnginePrivate::scriptValueToVariant(), QDeclarativeEnginePrivate::scriptValueToVariant(), QScriptDebuggerScriptedConsoleCommandJob::start(), QDeclarativeObjectScriptClass::toQObject(), and QDeclarativeObjectScriptClass::tostring().

1351 {
1352  Q_D(const QScriptValue);
1353  if (!d || !d->engine)
1354  return 0;
1355  QScript::APIShim shim(d->engine);
1356  return QScriptEnginePrivate::toQObject(d->engine->currentFrame, d->jscValue);
1357 }
double d
Definition: qnumeric_p.h:62
static QObject * toQObject(JSC::ExecState *, JSC::JSValue)
#define Q_D(Class)
Definition: qglobal.h:2482
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57

◆ toRegExp()

QRegExp QScriptValue::toRegExp ( ) const

Returns the QRegExp representation of this value.

If this QScriptValue is not a regular expression, an empty QRegExp is returned.

See also
isRegExp()

Definition at line 1330 of file qscriptvalue.cpp.

Referenced by QDeclarativeWorkerScriptEnginePrivate::scriptValueToVariant().

1331 {
1332  Q_D(const QScriptValue);
1333  if (!d || !d->engine)
1334  return QRegExp();
1335  QScript::APIShim shim(d->engine);
1336  return QScriptEnginePrivate::toRegExp(d->engine->currentFrame, d->jscValue);
1337 }
double d
Definition: qnumeric_p.h:62
The QRegExp class provides pattern matching using regular expressions.
Definition: qregexp.h:61
static QRegExp toRegExp(JSC::ExecState *, JSC::JSValue)
#define Q_D(Class)
Definition: qglobal.h:2482
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57

◆ toString()

QString QScriptValue::toString ( ) const

Returns the string value of this QScriptValue, as defined in ECMA-262 section 9.8, "ToString".

Note that if this QScriptValue is an object, calling this function has side effects on the script engine, since the engine will call the object's toString() function (and possibly valueOf()) in an attempt to convert the object to a primitive value (possibly resulting in an uncaught script exception).

See also
isString()

Definition at line 986 of file qscriptvalue.cpp.

Referenced by QScript::__setupPackage__(), QDeclarativeEnginePrivate::atob(), breakpointDataFromScriptValue(), QDeclarativeEnginePrivate::btoa(), QDeclarativeEnginePrivate::consoleLog(), QDeclarativeEnginePrivate::createComponent(), QScriptDBusMessageConstructor::createErrorReply(), QDeclarativeEnginePrivate::createQmlObject(), debuggerScriptValuePropertyFromScriptValue(), QDeclarativeEnginePrivate::desktopOpenUrl(), do_dbus_call(), QScriptDebuggerBackend::doPendingEvaluate(), QScript::Equals(), QScriptDebuggerBackendPrivate::exception(), QDeclarativeExpressionPrivate::exceptionToError(), QScriptDebuggerCommandExecutor::execute(), QDeclarativeEnginePrivate::formatDate(), QDeclarativeEnginePrivate::formatDateTime(), QDeclarativeEnginePrivate::formatTime(), fromScriptValue(), QJSDebuggerAgent::functionExit(), QScriptDebuggerScriptedConsoleCommandJob::handleResponse(), QDeclarativeInclude::include(), QDeclarativeExpressionPrivate::init(), QScript::LessThan(), QDeclarativeItem::mapFromItem(), QDeclarativeItem::mapToItem(), QDeclarativeEnginePrivate::md5(), QScriptDebuggerScriptedConsoleCommand::parse(), QDeclarativeObjectMethodScriptClass::property(), qmlsqldatabase_change_version(), qmlsqldatabase_executeSql(), qmlsqldatabase_executeSql_readonly(), qmlsqldatabase_open_sync(), qmlxmlhttprequest_getResponseHeader(), qmlxmlhttprequest_open(), qmlxmlhttprequest_send(), qmlxmlhttprequest_setRequestHeader(), QScriptDebuggerBackendPrivate::qsassert(), QScriptDebuggerValue::QScriptDebuggerValue(), QDeclarativeScriptEngine::resolvedUrl(), scriptDataFromScriptValue(), QDeclarativeWorkerScriptEnginePrivate::scriptValueToVariant(), QDeclarativeObjectScriptClass::setProperty(), QScriptDebuggerScriptedConsoleCommandJob::start(), QScriptDebuggerBackendPrivate::stepped(), QJSDebuggerAgentPrivate::stopped(), QScriptContext::toString(), QScriptDebuggerBackendPrivate::trace(), QScriptEngine::uncaughtExceptionBacktrace(), and QDeclarativeInclude::worker_include().

987 {
988  Q_D(const QScriptValue);
989  if (!d)
990  return QString();
991  switch (d->type) {
993  if (d->engine) {
994  QScript::APIShim shim(d->engine);
995  return QScriptEnginePrivate::toString(d->engine->currentFrame, d->jscValue);
996  } else {
997  return QScriptEnginePrivate::toString(0, d->jscValue);
998  } }
1000  return QScript::ToString(d->numberValue);
1002  return d->stringValue;
1003  }
1004  return QString();
1005 }
double d
Definition: qnumeric_p.h:62
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define Q_D(Class)
Definition: qglobal.h:2482
static JSC::UString toString(JSC::ExecState *, JSC::JSValue)
QString ToString(qsreal)
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57

◆ toUInt16()

quint16 QScriptValue::toUInt16 ( ) const

Returns the unsigned 16-bit integer value of this QScriptValue, using the conversion rules described in ECMA-262 section 9.7, "ToUint16".

Note that if this QScriptValue is an object, calling this function has side effects on the script engine, since the engine will call the object's valueOf() function (and possibly toString()) in an attempt to convert the object to a primitive value (possibly resulting in an uncaught script exception).

See also
toNumber()

Definition at line 1190 of file qscriptvalue.cpp.

1191 {
1192  Q_D(const QScriptValue);
1193  if (!d)
1194  return 0;
1195  switch (d->type) {
1197  if (d->engine) {
1198  QScript::APIShim shim(d->engine);
1199  return QScriptEnginePrivate::toUInt16(d->engine->currentFrame, d->jscValue);
1200  } else {
1201  return QScriptEnginePrivate::toUInt16(0, d->jscValue);
1202  }
1203  }
1205  return QScript::ToUInt16(d->numberValue);
1207  return QScript::ToUInt16(d->stringValue);
1208  }
1209  return 0;
1210 }
double d
Definition: qnumeric_p.h:62
static quint16 toUInt16(JSC::ExecState *, JSC::JSValue)
#define Q_D(Class)
Definition: qglobal.h:2482
quint16 ToUInt16(qsreal n)
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57

◆ toUInt32()

quint32 QScriptValue::toUInt32 ( ) const

Returns the unsigned 32-bit integer value of this QScriptValue, using the conversion rules described in ECMA-262 section 9.6, "ToUint32".

Note that if this QScriptValue is an object, calling this function has side effects on the script engine, since the engine will call the object's valueOf() function (and possibly toString()) in an attempt to convert the object to a primitive value (possibly resulting in an uncaught script exception).

See also
toNumber(), toInt32()

Definition at line 1156 of file qscriptvalue.cpp.

Referenced by call(), construct(), QDeclarativeEnginePrivate::formatDate(), QDeclarativeEnginePrivate::formatDateTime(), QDeclarativeEnginePrivate::formatTime(), QDeclarativeObjectMethodScriptClass::property(), qScriptValueToSequence(), and scriptValueToMessage().

1157 {
1158  Q_D(const QScriptValue);
1159  if (!d)
1160  return 0;
1161  switch (d->type) {
1163  if (d->engine) {
1164  QScript::APIShim shim(d->engine);
1165  return QScriptEnginePrivate::toUInt32(d->engine->currentFrame, d->jscValue);
1166  } else {
1167  return QScriptEnginePrivate::toUInt32(0, d->jscValue);
1168  }
1169  }
1171  return QScript::ToUInt32(d->numberValue);
1173  return QScript::ToUInt32(d->stringValue);
1174  }
1175  return 0;
1176 }
double d
Definition: qnumeric_p.h:62
quint32 ToUInt32(qsreal n)
#define Q_D(Class)
Definition: qglobal.h:2482
static quint32 toUInt32(JSC::ExecState *, JSC::JSValue)
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57

◆ toVariant()

QVariant QScriptValue::toVariant ( ) const

Returns the QVariant value of this QScriptValue, if it can be converted to a QVariant; otherwise returns an invalid QVariant.

The conversion is performed according to the following table:

Input Type Result
Undefined An invalid QVariant.
Null An invalid QVariant.
Boolean A QVariant containing the value of the boolean.
Number A QVariant containing the value of the number.
String A QVariant containing the value of the string.
QVariant Object The result is the QVariant value of the object (no conversion).
QObject Object A QVariant containing a pointer to the QObject.
Date Object A QVariant containing the date value (toDateTime()).
RegExp Object A QVariant containing the regular expression value (toRegExp()).
Array Object The array is converted to a QVariantList. Each element is converted to a QVariant, recursively; cyclic references are not followed.
Object The object is converted to a QVariantMap. Each property is converted to a QVariant, recursively; cyclic references are not followed.
See also
isVariant()

Definition at line 1268 of file qscriptvalue.cpp.

Referenced by FlatListModel::addValue(), QScriptDBusMessageConstructor::createReply(), QDeclarativeEnginePrivate::darker(), do_dbus_call(), QScript::Equals(), QDeclarativeEnginePrivate::formatTime(), QDeclarativeEnginePrivate::lighter(), QDeclarativeObjectMethodScriptClass::matchScore(), QDeclarativeWorkerScriptEnginePrivate::onMessage(), qmlsqldatabase_executeSql(), qscriptvalue_cast(), scriptValueToMessage(), QDeclarativeEnginePrivate::scriptValueToVariant(), QDeclarativeWorkerScriptEnginePrivate::sendMessage(), ModelNode::setListValue(), ModelNode::setObjectValue(), FlatListScriptClass::setProperty(), and QDeclarativeEnginePrivate::tint().

1269 {
1270  Q_D(const QScriptValue);
1271  if (!d)
1272  return QVariant();
1273  switch (d->type) {
1275  if (d->engine) {
1276  QScript::APIShim shim(d->engine);
1277  return QScriptEnginePrivate::toVariant(d->engine->currentFrame, d->jscValue);
1278  } else {
1279  return QScriptEnginePrivate::toVariant(0, d->jscValue);
1280  }
1281  }
1283  return QVariant(d->numberValue);
1285  return QVariant(d->stringValue);
1286  }
1287  return QVariant();
1288 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
double d
Definition: qnumeric_p.h:62
static QVariant toVariant(JSC::ExecState *, JSC::JSValue)
#define Q_D(Class)
Definition: qglobal.h:2482
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57

Friends and Related Functions

◆ QScriptEnginePrivate

friend class QScriptEnginePrivate
friend

Definition at line 213 of file qscriptvalue.h.

◆ qscriptvalue_cast()

T qscriptvalue_cast ( const QScriptValue value)
related

Returns the given value converted to the template type T.

Since
4.3
See also
qScriptRegisterMetaType(), QScriptEngine::toScriptValue()

Definition at line 344 of file qscriptengine.h.

Referenced by debuggerScriptValuePropertyFromScriptValue(), and qscriptQMetaObjectConstructor().

345 {
346  T t;
347  const int id = qMetaTypeId<T>();
348 
349  if (qscriptvalue_cast_helper(value, id, &t))
350  return t;
351  else if (value.isVariant())
352  return qvariant_cast<T>(value.toVariant());
353 
354  return T();
355 }
QVariant toVariant() const
Returns the QVariant value of this QScriptValue, if it can be converted to a QVariant; otherwise retu...
bool qscriptvalue_cast_helper(const QScriptValue &value, int type, void *ptr)
bool isVariant() const
Returns true if this QScriptValue is a variant value; otherwise returns false.

Properties

◆ d_ptr

QExplicitlySharedDataPointer<QScriptValuePrivate> QScriptValue::d_ptr
private

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