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