302c7681105d3c295ccb9f1410fe8989611d81fc
[profile/ivi/qtdeclarative.git] / src / declarative / qml / v8 / qjsvalue.cpp
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the QtScript module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL-ONLY$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser
11 ** General Public License version 2.1 as published by the Free Software
12 ** Foundation and appearing in the file LICENSE.LGPL included in the
13 ** packaging of this file.  Please review the following information to
14 ** ensure the GNU Lesser General Public License version 2.1 requirements
15 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
16 **
17 ** If you have questions regarding the use of this file, please contact
18 ** us via http://www.qt-project.org/.
19 **
20 ** $QT_END_LICENSE$
21 **
22 ****************************************************************************/
23
24 #include "qscriptisolate_p.h"
25 #include "qjsengine.h"
26 #include "qv8engine_p.h"
27 #include "qjsvalue.h"
28 #include "qjsvalue_p.h"
29 #include "qscript_impl_p.h"
30 #include "qscriptshareddata_p.h"
31 #include <QtCore/qstring.h>
32
33 /*!
34   \since 5.0
35   \class QJSValue
36
37   \brief The QJSValue class acts as a container for Qt/JavaScript data types.
38
39   \ingroup qtjavascript
40   \mainclass
41
42   QJSValue supports the types defined in the \l{ECMA-262}
43   standard: The primitive types, which are Undefined, Null, Boolean,
44   Number, and String; and the Object type. Additionally, built-in
45   support is provided for Qt/C++ types such as QVariant and QObject.
46
47   For the object-based types (including Date and RegExp), use the
48   newT() functions in QJSEngine (e.g. QJSEngine::newObject())
49   to create a QJSValue of the desired type. For the primitive types,
50   use one of the QJSValue constructor overloads.
51
52   The methods named isT() (e.g. isBool(), isUndefined()) can be
53   used to test if a value is of a certain type. The methods named
54   toT() (e.g. toBool(), toString()) can be used to convert a
55   QJSValue to another type. You can also use the generic
56   QJSValue_cast() function.
57
58   Object values have zero or more properties which are themselves
59   QJSValues. Use setProperty() to set a property of an object, and
60   call property() to retrieve the value of a property.
61
62   \snippet doc/src/snippets/code/src_script_qjsvalue.cpp 0
63
64   If you want to iterate over the properties of a script object, use
65   the QJSValueIterator class.
66
67   Object values have an internal \c{prototype} property, which can be
68   accessed with prototype() and setPrototype().
69
70   Function objects (objects for which isCallable()) returns true) can
71   be invoked by calling call(). Constructor functions can be used to
72   construct new objects by calling callAsConstructor().
73
74   Use equals() or strictlyEquals() to compare a QJSValue to another.
75
76   Note that a QJSValue for which isObject() is true only carries a
77   reference to an actual object; copying the QJSValue will only
78   copy the object reference, not the object itself. If you want to
79   clone an object (i.e. copy an object's properties to another
80   object), you can do so with the help of a \c{for-in} statement in
81   script code, or QJSValueIterator in C++.
82
83   \sa QJSEngine, QJSValueIterator
84 */
85
86 /*!
87     \enum QJSValue::SpecialValue
88
89     This enum is used to specify a single-valued type.
90
91     \value UndefinedValue An undefined value.
92
93     \value NullValue A null value.
94 */
95
96 QT_BEGIN_NAMESPACE
97
98 /*!
99   Constructs a new QJSValue with a boolean \a value.
100 */
101 QJSValue::QJSValue(bool value)
102     : d_ptr(new QJSValuePrivate(value))
103 {
104 }
105
106 /*!
107   Constructs a new QJSValue with a number \a value.
108 */
109 QJSValue::QJSValue(int value)
110     : d_ptr(new QJSValuePrivate(value))
111 {
112 }
113
114 /*!
115   Constructs a new QJSValue with a number \a value.
116 */
117 QJSValue::QJSValue(uint value)
118     : d_ptr(new QJSValuePrivate(value))
119 {
120 }
121
122 /*!
123   Constructs a new QJSValue with a number \a value.
124 */
125 QJSValue::QJSValue(double value)
126     : d_ptr(new QJSValuePrivate(value))
127 {
128 }
129
130 /*!
131   Constructs a new QJSValue with a string \a value.
132 */
133 QJSValue::QJSValue(const QString& value)
134     : d_ptr(new QJSValuePrivate(value))
135 {
136 }
137
138 /*!
139   Constructs a new QJSValue with a special \a value.
140 */
141 QJSValue::QJSValue(SpecialValue value)
142     : d_ptr(new QJSValuePrivate(value))
143 {
144 }
145
146 /*!
147   Constructs a new QJSValue with a string \a value.
148 */
149 QJSValue::QJSValue(const QLatin1String &value)
150     : d_ptr(new QJSValuePrivate(value))
151 {
152 }
153
154 /*!
155   Constructs a new QJSValue with a string \a value.
156 */
157 #ifndef QT_NO_CAST_FROM_ASCII
158 QJSValue::QJSValue(const char *value)
159     : d_ptr(new QJSValuePrivate(QString::fromAscii(value)))
160 {
161 }
162 #endif
163
164 /*!
165     Block automatic convertion to bool
166     \internal
167 */
168 QJSValue::QJSValue(void* d)
169 {
170     Q_UNUSED(d);
171     Q_ASSERT(false);
172 }
173
174 /*!
175     Constructs a new QJSValue from private
176     \internal
177 */
178 QJSValue::QJSValue(QJSValuePrivate* d)
179     : d_ptr(d)
180 {
181 }
182
183 /*!
184     Constructs a new QJSValue from private
185     \internal
186 */
187 QJSValue::QJSValue(QScriptPassPointer<QJSValuePrivate> d)
188     : d_ptr(d.give())
189 {
190 }
191
192 /*!
193   Constructs a new QJSValue that is a copy of \a other.
194
195   Note that if \a other is an object (i.e., isObject() would return
196   true), then only a reference to the underlying object is copied into
197   the new script value (i.e., the object itself is not copied).
198 */
199 QJSValue::QJSValue(const QJSValue& other)
200     : d_ptr(other.d_ptr)
201 {
202 }
203
204 /*!
205     Destroys this QJSValue.
206 */
207 QJSValue::~QJSValue()
208 {
209 }
210
211 /*!
212   Returns true if this QJSValue is of the primitive type Boolean;
213   otherwise returns false.
214
215   \sa toBool()
216 */
217 bool QJSValue::isBool() const
218 {
219     Q_D(const QJSValue);
220     QScriptIsolate api(d->engine());
221     return d->isBool();
222 }
223
224 /*!
225   Returns true if this QJSValue is of the primitive type Number;
226   otherwise returns false.
227
228   \sa toNumber()
229 */
230 bool QJSValue::isNumber() const
231 {
232     Q_D(const QJSValue);
233     QScriptIsolate api(d->engine());
234     return d->isNumber();
235 }
236
237 /*!
238   Returns true if this QJSValue is of the primitive type Null;
239   otherwise returns false.
240 */
241 bool QJSValue::isNull() const
242 {
243     Q_D(const QJSValue);
244     QScriptIsolate api(d->engine());
245     return d->isNull();
246 }
247
248 /*!
249   Returns true if this QJSValue is of the primitive type String;
250   otherwise returns false.
251
252   \sa toString()
253 */
254 bool QJSValue::isString() const
255 {
256     Q_D(const QJSValue);
257     QScriptIsolate api(d->engine());
258     return d->isString();
259 }
260
261 /*!
262   Returns true if this QJSValue is of the primitive type Undefined;
263   otherwise returns false.
264
265   \sa QJSEngine::undefinedValue()
266 */
267 bool QJSValue::isUndefined() const
268 {
269     Q_D(const QJSValue);
270     QScriptIsolate api(d->engine());
271     return d->isUndefined();
272 }
273
274 /*!
275   Returns true if this QJSValue is an object of the Error class;
276   otherwise returns false.
277 */
278 bool QJSValue::isError() const
279 {
280     Q_D(const QJSValue);
281     QScriptIsolate api(d->engine());
282     return d->isError();
283 }
284
285 /*!
286   Returns true if this QJSValue is an object of the Array class;
287   otherwise returns false.
288
289   \sa QJSEngine::newArray()
290 */
291 bool QJSValue::isArray() const
292 {
293     Q_D(const QJSValue);
294     QScriptIsolate api(d->engine());
295     return d->isArray();
296  }
297
298 /*!
299   Returns true if this QJSValue is of the Object type; otherwise
300   returns false.
301
302   Note that function values, variant values, and QObject values are
303   objects, so this function returns true for such values.
304
305   \sa QJSEngine::newObject()
306 */
307 bool QJSValue::isObject() const
308 {
309     Q_D(const QJSValue);
310     QScriptIsolate api(d->engine());
311     return d->isObject();
312 }
313
314 /*!
315   Returns true if this QJSValue can be called a function, otherwise
316   returns false.
317
318   \sa call()
319 */
320 bool QJSValue::isCallable() const
321 {
322     Q_D(const QJSValue);
323     QScriptIsolate api(d->engine());
324     return d->isCallable();
325 }
326
327 #ifdef QT_DEPRECATED
328
329 /*!
330   \obsolete
331
332   Use isCallable() instead.
333 */
334 bool QJSValue::isFunction() const
335 {
336     Q_D(const QJSValue);
337     QScriptIsolate api(d->engine());
338     return d->isCallable();
339 }
340
341 #endif // QT_DEPRECATED
342
343 /*!
344   Returns true if this QJSValue is a variant value;
345   otherwise returns false.
346
347   \sa toVariant()
348 */
349 bool QJSValue::isVariant() const
350 {
351     Q_D(const QJSValue);
352     QScriptIsolate api(d->engine());
353     return d->isVariant();
354 }
355
356 /*!
357   Returns the string value of this QJSValue, as defined in
358   \l{ECMA-262} section 9.8, "ToString".
359
360   Note that if this QJSValue is an object, calling this function
361   has side effects on the script engine, since the engine will call
362   the object's toString() function (and possibly valueOf()) in an
363   attempt to convert the object to a primitive value (possibly
364   resulting in an uncaught script exception).
365
366   \sa isString()
367 */
368 QString QJSValue::toString() const
369 {
370     Q_D(const QJSValue);
371     QScriptIsolate api(d->engine());
372     return d->toString();
373 }
374
375 /*!
376   Returns the number value of this QJSValue, as defined in
377   \l{ECMA-262} section 9.3, "ToNumber".
378
379   Note that if this QJSValue is an object, calling this function
380   has side effects on the script engine, since the engine will call
381   the object's valueOf() function (and possibly toString()) in an
382   attempt to convert the object to a primitive value (possibly
383   resulting in an uncaught script exception).
384
385   \sa isNumber(), toInt(), toUInt()
386 */
387 double QJSValue::toNumber() const
388 {
389     Q_D(const QJSValue);
390     QScriptIsolate api(d->engine());
391     return d->toNumber();
392 }
393
394 /*!
395   Returns the boolean value of this QJSValue, using the conversion
396   rules described in \l{ECMA-262} section 9.2, "ToBoolean".
397
398   Note that if this QJSValue is an object, calling this function
399   has side effects on the script engine, since the engine will call
400   the object's valueOf() function (and possibly toString()) in an
401   attempt to convert the object to a primitive value (possibly
402   resulting in an uncaught script exception).
403
404   \sa isBool()
405 */
406 bool QJSValue::toBool() const
407 {
408     Q_D(const QJSValue);
409     QScriptIsolate api(d->engine());
410     return d->toBool();
411 }
412
413 /*!
414   Returns the signed 32-bit integer value of this QJSValue, using
415   the conversion rules described in \l{ECMA-262} section 9.5, "ToInt32".
416
417   Note that if this QJSValue is an object, calling this function
418   has side effects on the script engine, since the engine will call
419   the object's valueOf() function (and possibly toString()) in an
420   attempt to convert the object to a primitive value (possibly
421   resulting in an uncaught script exception).
422
423   \sa toNumber(), toUInt()
424 */
425 qint32 QJSValue::toInt() const
426 {
427     Q_D(const QJSValue);
428     QScriptIsolate api(d->engine());
429     return d->toInt32();
430 }
431
432 /*!
433   Returns the unsigned 32-bit integer value of this QJSValue, using
434   the conversion rules described in \l{ECMA-262} section 9.6, "ToUint32".
435
436   Note that if this QJSValue is an object, calling this function
437   has side effects on the script engine, since the engine will call
438   the object's valueOf() function (and possibly toString()) in an
439   attempt to convert the object to a primitive value (possibly
440   resulting in an uncaught script exception).
441
442   \sa toNumber(), toInt()
443 */
444 quint32 QJSValue::toUInt() const
445 {
446     Q_D(const QJSValue);
447     QScriptIsolate api(d->engine());
448     return d->toUInt32();
449 }
450
451 #ifdef QT_DEPRECATED
452
453 /*!
454   \obsolete
455
456   Use toInt() instead.
457 */
458 qint32 QJSValue::toInt32() const
459 {
460     Q_D(const QJSValue);
461     QScriptIsolate api(d->engine());
462     return d->toInt32();
463 }
464
465 /*!
466   \obsolete
467
468   Use toUInt() instead.
469 */
470 quint32 QJSValue::toUInt32() const
471 {
472     Q_D(const QJSValue);
473     QScriptIsolate api(d->engine());
474     return d->toUInt32();
475 }
476
477 #endif // QT_DEPRECATED
478
479 /*!
480   Returns the QVariant value of this QJSValue, if it can be
481   converted to a QVariant; otherwise returns an invalid QVariant.
482   The conversion is performed according to the following table:
483
484     \table
485     \header \o Input Type \o Result
486     \row    \o Undefined  \o An invalid QVariant.
487     \row    \o Null       \o An invalid QVariant.
488     \row    \o Boolean    \o A QVariant containing the value of the boolean.
489     \row    \o Number     \o A QVariant containing the value of the number.
490     \row    \o String     \o A QVariant containing the value of the string.
491     \row    \o QVariant Object \o The result is the QVariant value of the object (no conversion).
492     \row    \o QObject Object \o A QVariant containing a pointer to the QObject.
493     \row    \o Date Object \o A QVariant containing the date value (toDateTime()).
494     \row    \o RegExp Object \o A QVariant containing the regular expression value.
495     \row    \o Array Object \o The array is converted to a QVariantList. Each element is converted to a QVariant, recursively; cyclic references are not followed.
496     \row    \o Object     \o The object is converted to a QVariantMap. Each property is converted to a QVariant, recursively; cyclic references are not followed.
497     \endtable
498
499   \sa isVariant()
500 */
501 QVariant QJSValue::toVariant() const
502 {
503     Q_D(const QJSValue);
504     QScriptIsolate api(d->engine());
505     return d->toVariant();
506 }
507
508 /*!
509   Calls this QJSValue as a function, passing \a args as arguments
510   to the function, and using the globalObject() as the "this"-object.
511   Returns the value returned from the function.
512
513   If this QJSValue is not callable, call() does nothing and
514   returns an undefined QJSValue.
515
516   Calling call() can cause an exception to occur in the script engine;
517   in that case, call() returns the value that was thrown (typically an
518   \c{Error} object). You can call
519   QJSEngine::hasUncaughtException() to determine if an exception
520   occurred.
521
522   \sa isCallable(), callWithInstance(), callAsConstructor()
523 */
524 QJSValue QJSValue::call(const QJSValueList &args)
525 {
526     Q_D(QJSValue);
527     QScriptIsolate api(d->engine());
528     return d->call(/*thisObject=*/0, args);
529 }
530
531 /*!
532   Calls this QJSValue as a function, using \a instance as
533   the `this' object in the function call, and passing \a args
534   as arguments to the function. Returns the value returned from
535   the function.
536
537   If this QJSValue is not a function, call() does nothing
538   and returns an undefined QJSValue.
539
540   Note that if \a instance is not an object, the global object
541   (see \l{QJSEngine::globalObject()}) will be used as the
542   `this' object.
543
544   Calling call() can cause an exception to occur in the script engine;
545   in that case, call() returns the value that was thrown (typically an
546   \c{Error} object). You can call
547   QJSEngine::hasUncaughtException() to determine if an exception
548   occurred.
549
550   \sa call()
551 */
552 QJSValue QJSValue::callWithInstance(const QJSValue &instance, const QJSValueList &args)
553 {
554     Q_D(QJSValue);
555     QScriptIsolate api(d->engine());
556     return d->call(QJSValuePrivate::get(instance), args);
557 }
558
559 /*!
560   Creates a new \c{Object} and calls this QJSValue as a
561   constructor, using the created object as the `this' object and
562   passing \a args as arguments. If the return value from the
563   constructor call is an object, then that object is returned;
564   otherwise the default constructed object is returned.
565
566   If this QJSValue is not a function, callAsConstructor() does
567   nothing and returns an undefined QJSValue.
568
569   Calling this function can cause an exception to occur in the
570   script engine; in that case, the value that was thrown
571   (typically an \c{Error} object) is returned. You can call
572   QJSEngine::hasUncaughtException() to determine if an exception
573   occurred.
574
575   \sa call(), QJSEngine::newObject()
576 */
577 QJSValue QJSValue::callAsConstructor(const QJSValueList &args)
578 {
579     Q_D(QJSValue);
580     QScriptIsolate api(d->engine());
581     return QJSValuePrivate::get(d->callAsConstructor(args));
582 }
583
584 #ifdef QT_DEPRECATED
585
586 /*!
587   \obsolete
588
589   Use callWithInstance() instead.
590 */
591 QJSValue QJSValue::call(const QJSValue& thisObject, const QJSValueList& args)
592 {
593     Q_D(QJSValue);
594     QScriptIsolate api(d->engine());
595     return d->call(QJSValuePrivate::get(thisObject), args);
596 }
597
598 /*!
599   \obsolete
600
601   Use callAsConstructor() instead.
602 */
603 QJSValue QJSValue::construct(const QJSValueList &args)
604 {
605     Q_D(QJSValue);
606     QScriptIsolate api(d->engine());
607     return QJSValuePrivate::get(d->callAsConstructor(args));
608 }
609
610 /*!
611   \obsolete
612
613   Returns the QJSEngine that created this QJSValue,
614   or 0 if this QJSValue is invalid or the value is not
615   associated with a particular engine.
616 */
617 QJSEngine* QJSValue::engine() const
618 {
619     Q_D(const QJSValue);
620     QScriptIsolate api(d->engine());
621     QV8Engine* engine = d->engine();
622     if (engine)
623         return QV8Engine::get(engine);
624     return 0;
625 }
626
627 #endif // QT_DEPRECATED
628
629 /*!
630   If this QJSValue is an object, returns the internal prototype
631   (\c{__proto__} property) of this object; otherwise returns an
632   undefined QJSValue.
633
634   \sa setPrototype(), isObject()
635 */
636 QJSValue QJSValue::prototype() const
637 {
638     Q_D(const QJSValue);
639     QScriptIsolate api(d->engine());
640     return QJSValuePrivate::get(d->prototype());
641 }
642
643 /*!
644   If this QJSValue is an object, sets the internal prototype
645   (\c{__proto__} property) of this object to be \a prototype;
646   otherwise does nothing.
647
648   The internal prototype should not be confused with the public
649   property with name "prototype"; the public prototype is usually
650   only set on functions that act as constructors.
651
652   \sa prototype(), isObject()
653 */
654 void QJSValue::setPrototype(const QJSValue& prototype)
655 {
656     Q_D(QJSValue);
657     QScriptIsolate api(d->engine());
658     d->setPrototype(QJSValuePrivate::get(prototype));
659 }
660
661 /*!
662   Assigns the \a other value to this QJSValue.
663
664   Note that if \a other is an object (isObject() returns true),
665   only a reference to the underlying object will be assigned;
666   the object itself will not be copied.
667 */
668 QJSValue& QJSValue::operator=(const QJSValue& other)
669 {
670     d_ptr = other.d_ptr;
671     return *this;
672 }
673
674 /*!
675   Returns true if this QJSValue is equal to \a other, otherwise
676   returns false. The comparison follows the behavior described in
677   \l{ECMA-262} section 11.9.3, "The Abstract Equality Comparison
678   Algorithm".
679
680   This function can return true even if the type of this QJSValue
681   is different from the type of the \a other value; i.e. the
682   comparison is not strict.  For example, comparing the number 9 to
683   the string "9" returns true; comparing an undefined value to a null
684   value returns true; comparing a \c{Number} object whose primitive
685   value is 6 to a \c{String} object whose primitive value is "6"
686   returns true; and comparing the number 1 to the boolean value
687   \c{true} returns true. If you want to perform a comparison
688   without such implicit value conversion, use strictlyEquals().
689
690   Note that if this QJSValue or the \a other value are objects,
691   calling this function has side effects on the script engine, since
692   the engine will call the object's valueOf() function (and possibly
693   toString()) in an attempt to convert the object to a primitive value
694   (possibly resulting in an uncaught script exception).
695
696   \sa strictlyEquals()
697 */
698 bool QJSValue::equals(const QJSValue& other) const
699 {
700     Q_D(const QJSValue);
701     QJSValuePrivate* otherValue = QJSValuePrivate::get(other);
702     QScriptIsolate api(d->engine() ? d->engine() : otherValue->engine());
703     return d_ptr->equals(otherValue);
704 }
705
706 /*!
707   Returns true if this QJSValue is equal to \a other using strict
708   comparison (no conversion), otherwise returns false. The comparison
709   follows the behavior described in \l{ECMA-262} section 11.9.6, "The
710   Strict Equality Comparison Algorithm".
711
712   If the type of this QJSValue is different from the type of the
713   \a other value, this function returns false. If the types are equal,
714   the result depends on the type, as shown in the following table:
715
716     \table
717     \header \o Type \o Result
718     \row    \o Undefined  \o true
719     \row    \o Null       \o true
720     \row    \o Boolean    \o true if both values are true, false otherwise
721     \row    \o Number     \o false if either value is NaN (Not-a-Number); true if values are equal, false otherwise
722     \row    \o String     \o true if both values are exactly the same sequence of characters, false otherwise
723     \row    \o Object     \o true if both values refer to the same object, false otherwise
724     \endtable
725
726   \sa equals()
727 */
728 bool QJSValue::strictlyEquals(const QJSValue& other) const
729 {
730     Q_D(const QJSValue);
731     QJSValuePrivate* o = QJSValuePrivate::get(other);
732     QScriptIsolate api(d->engine() ? d->engine() : o->engine());
733     return d_ptr->strictlyEquals(o);
734 }
735
736 /*!
737   Returns the value of this QJSValue's property with the given \a name.
738   If no such property exists, an undefined QJSValue is returned.
739
740   If the property is implemented using a getter function (i.e. has the
741   PropertyGetter flag set), calling property() has side-effects on the
742   script engine, since the getter function will be called (possibly
743   resulting in an uncaught script exception). If an exception
744   occurred, property() returns the value that was thrown (typically
745   an \c{Error} object).
746
747   \sa setProperty(), hasProperty(), QJSValueIterator
748 */
749 QJSValue QJSValue::property(const QString& name) const
750 {
751     Q_D(const QJSValue);
752     QScriptIsolate api(d->engine());
753     return QJSValuePrivate::get(d->property(name));
754 }
755
756 /*!
757   \overload
758
759   Returns the property at the given \a arrayIndex.
760
761   This function is provided for convenience and performance when
762   working with array objects.
763
764   If this QJSValue is not an Array object, this function behaves
765   as if property() was called with the string representation of \a
766   arrayIndex.
767 */
768 QJSValue QJSValue::property(quint32 arrayIndex) const
769 {
770     Q_D(const QJSValue);
771     QScriptIsolate api(d->engine());
772     return QJSValuePrivate::get(d->property(arrayIndex));
773 }
774
775 /*!
776   Sets the value of this QJSValue's property with the given \a name to
777   the given \a value.
778
779   If this QJSValue is not an object, this function does nothing.
780
781   If this QJSValue does not already have a property with name \a name,
782   a new property is created.
783
784   \sa property(), deleteProperty()
785 */
786 void QJSValue::setProperty(const QString& name, const QJSValue& value)
787 {
788     Q_D(QJSValue);
789     QScriptIsolate api(d->engine());
790     d->setProperty(name, QJSValuePrivate::get(value));
791 }
792
793 /*!
794   \overload
795
796   Sets the property at the given \a arrayIndex to the given \a value.
797
798   This function is provided for convenience and performance when
799   working with array objects.
800
801   If this QJSValue is not an Array object, this function behaves
802   as if setProperty() was called with the string representation of \a
803   arrayIndex.
804 */
805 void QJSValue::setProperty(quint32 arrayIndex, const QJSValue& value)
806 {
807     Q_D(QJSValue);
808     QScriptIsolate api(d->engine());
809     d->setProperty(arrayIndex, QJSValuePrivate::get(value));
810 }
811
812 /*!
813   Attempts to delete this object's property of the given \a name.
814   Returns true if the property was deleted, otherwise returns false.
815
816   The behavior of this function is consistent with the JavaScript
817   delete operator. In particular:
818
819   \list
820   \o Non-configurable properties cannot be deleted.
821   \o This function will return true even if this object doesn't
822      have a property of the given \a name (i.e., non-existent
823      properties are "trivially deletable").
824   \o If this object doesn't have an own property of the given
825      \a name, but an object in the prototype() chain does, the
826      prototype object's property is not deleted, and this function
827      returns true.
828   \endlist
829
830   \sa setProperty(), hasOwnProperty()
831 */
832 bool QJSValue::deleteProperty(const QString &name)
833 {
834     Q_D(QJSValue);
835     QScriptIsolate api(d->engine());
836     return d->deleteProperty(name);
837 }
838
839 /*!
840   Returns true if this object has a property of the given \a name,
841   otherwise returns false.
842
843   \sa property(), hasOwnProperty()
844 */
845 bool QJSValue::hasProperty(const QString &name) const
846 {
847     Q_D(const QJSValue);
848     QScriptIsolate api(d->engine());
849     return d->hasProperty(name);
850 }
851
852 /*!
853   Returns true if this object has an own (not prototype-inherited)
854   property of the given \a name, otherwise returns false.
855
856   \sa property(), hasProperty()
857 */
858 bool QJSValue::hasOwnProperty(const QString &name) const
859 {
860     Q_D(const QJSValue);
861     QScriptIsolate api(d->engine());
862     return d->hasOwnProperty(name);
863 }
864
865 /*!
866  * If this QJSValue is a QObject, returns the QObject pointer
867  * that the QJSValue represents; otherwise, returns 0.
868  *
869  * If the QObject that this QJSValue wraps has been deleted,
870  * this function returns 0 (i.e. it is possible for toQObject()
871  * to return 0 even when isQObject() returns true).
872  *
873  * \sa isQObject()
874  */
875 QObject *QJSValue::toQObject() const
876 {
877     Q_D(const QJSValue);
878     QScriptIsolate api(d->engine());
879     return d->toQObject();
880 }
881
882 /*!
883   Returns a QDateTime representation of this value, in local time.
884   If this QJSValue is not a date, or the value of the date is NaN
885   (Not-a-Number), an invalid QDateTime is returned.
886
887   \sa isDate()
888 */
889 QDateTime QJSValue::toDateTime() const
890 {
891     Q_D(const QJSValue);
892     QScriptIsolate api(d->engine());
893     return d->toDataTime();
894 }
895
896 /*!
897   Returns true if this QJSValue is an object of the Date class;
898   otherwise returns false.
899
900   \sa QJSEngine::newDate()
901 */
902 bool QJSValue::isDate() const
903 {
904     Q_D(const QJSValue);
905     QScriptIsolate api(d->engine());
906     return d->isDate();
907 }
908
909 /*!
910   Returns true if this QJSValue is an object of the RegExp class;
911   otherwise returns false.
912 */
913 bool QJSValue::isRegExp() const
914 {
915     Q_D(const QJSValue);
916     QScriptIsolate api(d->engine());
917     return d->isRegExp();
918 }
919
920 /*!
921   Returns true if this QJSValue is a QObject; otherwise returns
922   false.
923
924   Note: This function returns true even if the QObject that this
925   QJSValue wraps has been deleted.
926
927   \sa toQObject(), QJSEngine::newQObject()
928 */
929 bool QJSValue::isQObject() const
930 {
931     Q_D(const QJSValue);
932     QScriptIsolate api(d->engine());
933     return d->isQObject();
934 }
935
936 QT_END_NAMESPACE