aboutsummaryrefslogtreecommitdiffstats
path: root/src/declarative/qml/v8
diff options
context:
space:
mode:
Diffstat (limited to 'src/declarative/qml/v8')
-rw-r--r--src/declarative/qml/v8/qhashedstring.cpp34
-rw-r--r--src/declarative/qml/v8/qhashedstring_p.h34
-rw-r--r--src/declarative/qml/v8/qjsconverter_p.h3
-rw-r--r--src/declarative/qml/v8/qjsengine.cpp178
-rw-r--r--src/declarative/qml/v8/qjsengine.h4
-rw-r--r--src/declarative/qml/v8/qjsvalue.cpp115
-rw-r--r--src/declarative/qml/v8/qjsvalue.h4
-rw-r--r--src/declarative/qml/v8/qjsvalue_impl_p.h53
-rw-r--r--src/declarative/qml/v8/qjsvalue_p.h33
-rw-r--r--src/declarative/qml/v8/qjsvalueiterator.cpp169
-rw-r--r--src/declarative/qml/v8/qjsvalueiterator.h4
-rw-r--r--src/declarative/qml/v8/qjsvalueiterator_impl_p.h121
-rw-r--r--src/declarative/qml/v8/qjsvalueiterator_p.h68
-rw-r--r--src/declarative/qml/v8/qscript_impl_p.h1
-rw-r--r--src/declarative/qml/v8/qscriptoriginalglobalobject_p.h4
-rw-r--r--src/declarative/qml/v8/qscripttools_p.h182
-rw-r--r--src/declarative/qml/v8/qv8_p.h41
-rw-r--r--src/declarative/qml/v8/qv8bindings.cpp34
-rw-r--r--src/declarative/qml/v8/qv8bindings_p.h34
-rw-r--r--src/declarative/qml/v8/qv8contextwrapper.cpp34
-rw-r--r--src/declarative/qml/v8/qv8debug_p.h1
-rw-r--r--src/declarative/qml/v8/qv8domerrors.cpp73
-rw-r--r--src/declarative/qml/v8/qv8domerrors_p.h94
-rw-r--r--src/declarative/qml/v8/qv8engine.cpp159
-rw-r--r--src/declarative/qml/v8/qv8engine_impl_p.h30
-rw-r--r--src/declarative/qml/v8/qv8engine_p.h53
-rw-r--r--src/declarative/qml/v8/qv8include.cpp34
-rw-r--r--src/declarative/qml/v8/qv8listwrapper.cpp36
-rw-r--r--src/declarative/qml/v8/qv8listwrapper_p.h34
-rw-r--r--src/declarative/qml/v8/qv8qobjectwrapper.cpp44
-rw-r--r--src/declarative/qml/v8/qv8qobjectwrapper_p.h34
-rw-r--r--src/declarative/qml/v8/qv8stringwrapper.cpp42
-rw-r--r--src/declarative/qml/v8/qv8stringwrapper_p.h34
-rw-r--r--src/declarative/qml/v8/qv8typewrapper.cpp52
-rw-r--r--src/declarative/qml/v8/qv8valuetypewrapper.cpp105
-rw-r--r--src/declarative/qml/v8/qv8valuetypewrapper_p.h6
-rw-r--r--src/declarative/qml/v8/qv8variantwrapper.cpp47
-rw-r--r--src/declarative/qml/v8/qv8variantwrapper_p.h1
-rw-r--r--src/declarative/qml/v8/qv8worker.cpp34
-rw-r--r--src/declarative/qml/v8/qv8worker_p.h34
-rw-r--r--src/declarative/qml/v8/script.pri4
-rw-r--r--src/declarative/qml/v8/v8.pri5
42 files changed, 1254 insertions, 852 deletions
diff --git a/src/declarative/qml/v8/qhashedstring.cpp b/src/declarative/qml/v8/qhashedstring.cpp
index 4a23e3b7dd..2e2af98ff4 100644
--- a/src/declarative/qml/v8/qhashedstring.cpp
+++ b/src/declarative/qml/v8/qhashedstring.cpp
@@ -7,29 +7,29 @@
** This file is part of the QtDeclarative module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
+** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
**
**
**
diff --git a/src/declarative/qml/v8/qhashedstring_p.h b/src/declarative/qml/v8/qhashedstring_p.h
index 143bd0b995..e0ca1d466a 100644
--- a/src/declarative/qml/v8/qhashedstring_p.h
+++ b/src/declarative/qml/v8/qhashedstring_p.h
@@ -7,29 +7,29 @@
** This file is part of the QtDeclarative module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
+** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
**
**
**
diff --git a/src/declarative/qml/v8/qjsconverter_p.h b/src/declarative/qml/v8/qjsconverter_p.h
index 4aec472c7a..c42381bc55 100644
--- a/src/declarative/qml/v8/qjsconverter_p.h
+++ b/src/declarative/qml/v8/qjsconverter_p.h
@@ -28,6 +28,7 @@
#include <QtCore/qglobal.h>
#include <QtCore/qnumeric.h>
#include <QtCore/qstring.h>
+#include <QtCore/qstringlist.h>
#include <QtCore/qvarlengtharray.h>
#include <QtCore/qregexp.h>
#include <QtCore/qdatetime.h>
@@ -70,7 +71,7 @@ public:
return qstr;
}
- static v8::Handle<v8::String> toString(const QString& string)
+ static v8::Local<v8::String> toString(const QString& string)
{
return v8::String::New(reinterpret_cast<const uint16_t*>(string.data()), string.size());
}
diff --git a/src/declarative/qml/v8/qjsengine.cpp b/src/declarative/qml/v8/qjsengine.cpp
index e80fcb4e7e..3db7fc40e0 100644
--- a/src/declarative/qml/v8/qjsengine.cpp
+++ b/src/declarative/qml/v8/qjsengine.cpp
@@ -52,6 +52,97 @@ Q_DECLARE_METATYPE(QJSValue)
Q_DECLARE_METATYPE(QObjectList)
Q_DECLARE_METATYPE(QList<int>)
+/*!
+ \since 5.0
+ \class QJSEngine
+
+ \brief The QJSEngine class provides an environment for evaluating JavaScript code.
+
+ \ingroup qtjavascript
+ \mainclass
+
+ \section1 Evaluating Scripts
+
+ Use evaluate() to evaluate script code.
+
+ \snippet doc/src/snippets/code/src_script_qjsengine.cpp 0
+
+ evaluate() returns a QJSValue that holds the result of the
+ evaluation. The QJSValue class provides functions for converting
+ the result to various C++ types (e.g. QJSValue::toString()
+ and QJSValue::toNumber()).
+
+ The following code snippet shows how a script function can be
+ defined and then invoked from C++ using QJSValue::call():
+
+ \snippet doc/src/snippets/code/src_script_qjsengine.cpp 1
+
+ As can be seen from the above snippets, a script is provided to the
+ engine in the form of a string. One common way of loading scripts is
+ by reading the contents of a file and passing it to evaluate():
+
+ \snippet doc/src/snippets/code/src_script_qjsengine.cpp 2
+
+ Here we pass the name of the file as the second argument to
+ evaluate(). This does not affect evaluation in any way; the second
+ argument is a general-purpose string that is used to identify the
+ script for debugging purposes (for example, our filename will now
+ show up in any uncaughtExceptionBacktrace() involving the script).
+
+ \section1 Engine Configuration
+
+ The globalObject() function returns the \bold {Global Object}
+ associated with the script engine. Properties of the Global Object
+ are accessible from any script code (i.e. they are global
+ variables). Typically, before evaluating "user" scripts, you will
+ want to configure a script engine by adding one or more properties
+ to the Global Object:
+
+ \snippet doc/src/snippets/code/src_script_qjsengine.cpp 3
+
+ Adding custom properties to the scripting environment is one of the
+ standard means of providing a scripting API that is specific to your
+ application. Usually these custom properties are objects created by
+ the newQObject() or newObject() functions.
+
+ \section1 Script Exceptions
+
+ evaluate() can throw a script exception (e.g. due to a syntax
+ error); in that case, the return value is the value that was thrown
+ (typically an \c{Error} object). You can check whether the
+ evaluation caused an exception by calling hasUncaughtException(). In
+ that case, you can call toString() on the error object to obtain an
+ error message. The current uncaught exception is also available
+ through uncaughtException().
+ Calling clearExceptions() will cause any uncaught exceptions to be
+ cleared.
+
+ \snippet doc/src/snippets/code/src_script_qjsengine.cpp 4
+
+ \section1 Script Object Creation
+
+ Use newObject() to create a JavaScript object; this is the
+ C++ equivalent of the script statement \c{new Object()}. You can use
+ the object-specific functionality in QJSValue to manipulate the
+ script object (e.g. QJSValue::setProperty()). Similarly, use
+ newArray() to create a JavaScript array object. Use newDate() to
+ create a \c{Date} object, and newRegExp() to create a \c{RegExp}
+ object.
+
+ \section1 QObject Integration
+
+ Use newQObject() to wrap a QObject (or subclass)
+ pointer. newQObject() returns a proxy script object; properties,
+ children, and signals and slots of the QObject are available as
+ properties of the proxy object. No binding code is needed because it
+ is done dynamically using the Qt meta object system.
+
+ \snippet doc/src/snippets/code/src_script_qjsengine.cpp 5
+
+ \sa QJSValue, {Making Applications Scriptable}
+
+*/
+
QT_BEGIN_NAMESPACE
@@ -102,6 +193,11 @@ QJSEngine::~QJSEngine()
}
/*!
+ \fn QV8Engine *QJSEngine::handle() const
+ \internal
+*/
+
+/*!
Returns true if the last script evaluation resulted in an uncaught
exception; otherwise returns false.
@@ -201,6 +297,11 @@ QJSValue QJSEngine::evaluate(const QString& program, const QString& fileName, in
return QJSValuePrivate::get(d->evaluate(program, fileName, lineNumber));
}
+/*!
+ Returns a QJSValue of the primitive type Null.
+
+ \sa nullValue()
+*/
QJSValue QJSEngine::nullValue()
{
Q_D(QJSEngine);
@@ -209,6 +310,11 @@ QJSValue QJSEngine::nullValue()
return QJSValuePrivate::get(new QJSValuePrivate(d, v8::Null()));
}
+/*!
+ Returns a QJSValue of the primitive type Undefined.
+
+ \sa nullValue()
+*/
QJSValue QJSEngine::undefinedValue()
{
Q_D(QJSEngine);
@@ -217,6 +323,14 @@ QJSValue QJSEngine::undefinedValue()
return QJSValuePrivate::get(new QJSValuePrivate(d, v8::Undefined()));
}
+/*!
+ Creates a JavaScript object of class Object.
+
+ The prototype of the created object will be the Object
+ prototype object.
+
+ \sa newArray(), QJSValue::setProperty()
+*/
QJSValue QJSEngine::newObject()
{
Q_D(QJSEngine);
@@ -225,6 +339,11 @@ QJSValue QJSEngine::newObject()
return QJSValuePrivate::get(new QJSValuePrivate(d, v8::Object::New()));
}
+/*!
+ Creates a JavaScript object of class Array with the given \a length.
+
+ \sa newObject()
+*/
QJSValue QJSEngine::newArray(uint length)
{
Q_D(QJSEngine);
@@ -234,13 +353,12 @@ QJSValue QJSEngine::newArray(uint length)
}
/*!
- Creates a QtScript object that wraps the given QObject \a
+ Creates a JavaScript object that wraps the given QObject \a
object, using the given \a ownership. The given \a options control
various aspects of the interaction with the resulting script object.
Signals and slots, properties and children of \a object are
- available as properties of the created QJSValue. For more
- information, see the \l{QtScript} documentation.
+ available as properties of the created QJSValue.
If \a object is a null pointer, this function returns nullValue().
@@ -248,8 +366,8 @@ QJSValue QJSEngine::newArray(uint length)
(or its superclass, recursively), the prototype of the new script
object will be set to be that default prototype.
- If the given \a object is deleted outside of QtScript's control, any
- attempt to access the deleted QObject's members through the QtScript
+ If the given \a object is deleted outside of the engine's control, any
+ attempt to access the deleted QObject's members through the JavaScript
wrapper object (either by script code or C++) will result in a
script exception.
@@ -264,7 +382,7 @@ QJSValue QJSEngine::newQObject(QObject *object)
}
/*!
- Creates a QtScript object holding the given variant \a value.
+ Creates a JavaScript object holding the given variant \a value.
If a default prototype has been registered with the meta type id of
\a value, then the prototype of the created object will be that
@@ -282,6 +400,16 @@ QJSValue QJSEngine::newVariant(const QVariant &value)
}
+/*!
+ Returns this engine's Global Object.
+
+ By default, the Global Object contains the built-in objects that are
+ part of \l{ECMA-262}, such as Math, Date and String. Additionally,
+ you can set properties of the Global Object to make your own
+ extensions available to all script code. Non-local variables in
+ script code will be created as properties of the Global Object, as
+ well as local variables in global code.
+*/
QJSValue QJSEngine::globalObject() const
{
Q_D(const QJSEngine);
@@ -290,6 +418,23 @@ QJSValue QJSEngine::globalObject() const
return d->scriptValueFromInternal(d->global());
}
+/*!
+ Converts the given \a value to an object, if such a conversion is
+ possible; otherwise returns an invalid QJSValue. The conversion
+ is performed according to the following table:
+
+ \table
+ \header \o Input Type \o Result
+ \row \o Undefined \o An invalid QJSValue.
+ \row \o Null \o An invalid QJSValue.
+ \row \o Boolean \o A new Boolean object whose internal value is set to the value of the boolean.
+ \row \o Number \o A new Number object whose internal value is set to the value of the number.
+ \row \o String \o A new String object whose internal value is set to the value of the string.
+ \row \o Object \o The result is the object itself (no conversion).
+ \endtable
+
+ \sa newObject()
+*/
QJSValue QJSEngine::toObject(const QJSValue& value)
{
Q_D(QJSEngine);
@@ -299,7 +444,7 @@ QJSValue QJSEngine::toObject(const QJSValue& value)
}
/*!
- Creates a QtScript object of class Date from the given \a value.
+ Creates a JavaScript object of class Date from the given \a value.
\sa QJSValue::toDateTime()
*/
@@ -312,7 +457,7 @@ QJSValue QJSEngine::newDate(const QDateTime &dt)
}
/*!
- Creates a QtScript object of class Date with the given
+ Creates a JavaScript object of class Date with the given
\a value (the number of milliseconds since 01 January 1970,
UTC).
*/
@@ -325,7 +470,7 @@ QJSValue QJSEngine::newDate(double date)
}
/*!
- Creates a QtScript object of class RegExp with the given
+ Creates a JavaScript object of class RegExp with the given
\a regexp.
\sa QJSValue::toRegExp()
@@ -339,7 +484,7 @@ QJSValue QJSEngine::newRegExp(const QRegExp &regexp)
}
/*!
- Creates a QtScript object of class RegExp with the given
+ Creates a JavaScript object of class RegExp with the given
\a pattern and \a flags.
The legal flags are 'g' (global), 'i' (ignore case), and 'm'
@@ -425,6 +570,19 @@ bool QJSEngine::convertV2(const QJSValue &value, int type, void *ptr)
}
}
+/*! \fn QJSValue QJSEngine::toScriptValue(const T &value)
+
+ Creates a QJSValue with the given \a value.
+
+ \sa fromScriptValue()
+*/
+
+/*! \fn T QJSEngine::fromScriptValue(const QJSValue &value)
+
+ Returns the given \a value converted to the template type \c{T}.
+
+ \sa toScriptValue()
+*/
QT_END_NAMESPACE
diff --git a/src/declarative/qml/v8/qjsengine.h b/src/declarative/qml/v8/qjsengine.h
index 5109cefcf4..759363ab84 100644
--- a/src/declarative/qml/v8/qjsengine.h
+++ b/src/declarative/qml/v8/qjsengine.h
@@ -35,7 +35,7 @@ QT_BEGIN_HEADER
QT_BEGIN_NAMESPACE
-QT_MODULE(Script)
+QT_MODULE(Declarative)
class QDateTime;
class QV8Engine;
@@ -45,7 +45,7 @@ class QRegExp;
template <typename T>
inline T qjsvalue_cast(const QJSValue &);
-class Q_SCRIPT_EXPORT QJSEngine
+class Q_DECLARATIVE_EXPORT QJSEngine
: public QObject
{
Q_OBJECT
diff --git a/src/declarative/qml/v8/qjsvalue.cpp b/src/declarative/qml/v8/qjsvalue.cpp
index eff7b4321a..bbfae8983c 100644
--- a/src/declarative/qml/v8/qjsvalue.cpp
+++ b/src/declarative/qml/v8/qjsvalue.cpp
@@ -31,23 +31,71 @@
#include <QtCore/qregexp.h>
#include <QtCore/qstring.h>
-QT_BEGIN_NAMESPACE
-
/*!
- Constructs an invalid value.
+ \since 5.0
+ \class QJSValue
+
+ \brief The QJSValue class acts as a container for Qt/JavaScript data types.
+
+ \ingroup qtjavascript
+ \mainclass
+
+ QJSValue supports the types defined in the \l{ECMA-262}
+ standard: The primitive types, which are Undefined, Null, Boolean,
+ Number, and String; and the Object type. Additionally, built-in
+ support is provided for Qt/C++ types such as QVariant and QObject.
+
+ For the object-based types (including Date and RegExp), use the
+ newT() functions in QJSEngine (e.g. QJSEngine::newObject())
+ to create a QJSValue of the desired type. For the primitive types,
+ use one of the QJSValue 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
+ QJSValue to another type. You can also use the generic
+ QJSValue_cast() function.
+
+ Object values have zero or more properties which are themselves
+ QJSValues. Use setProperty() to set a property of an object, and
+ call property() to retrieve the value of a property.
+
+ \snippet doc/src/snippets/code/src_script_qjsvalue.cpp 0
+
+ The attributes of a property can be queried by calling the
+ propertyFlags() function.
+
+ If you want to iterate over the properties of a script object, use
+ the QJSValueIterator class.
+
+ Object values have an internal \c{prototype} property, which can be
+ accessed with prototype() and setPrototype().
+
+ 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() or strictlyEquals() to compare a QJSValue to another.
+
+ Note that a QJSValue for which isObject() is true only carries a
+ reference to an actual object; copying the QJSValue 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 \c{for-in} statement in
+ script code, or QJSValueIterator in C++.
+
+ \sa QJSEngine, QJSValueIterator
*/
-QJSValue::QJSValue()
- : d_ptr(InvalidValue())
-{
-}
/*!
- Constructs a new QJSValue with a boolean \a value.
+ \enum QJSValue::SpecialValue
+
+ This enum is used to specify a single-valued type.
+
+ \value UndefinedValue An undefined value.
+
+ \value NullValue A null value.
*/
-QJSValue::QJSValue(bool value)
- : d_ptr(new QJSValuePrivate(value))
-{
-}
/*!
\enum QJSValue::PropertyFlag
@@ -59,17 +107,25 @@ QJSValue::QJSValue(bool value)
\value Undeletable Attempts by Qt Script code to \c{delete} the property will be ignored.
\value SkipInEnumeration The property is not to be enumerated by a \c{for-in} enumeration.
+*/
- \value PropertyGetter The property is defined by a function which will be called to get the property value.
-
- \value PropertySetter The property is defined by a function which will be called to set the property value.
-
- \omitvalue QObjectMember This flag is used to indicate that an existing property is a QObject member (a property or method).
+QT_BEGIN_NAMESPACE
- \value 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.
+/*!
+ Constructs an invalid value.
+*/
+QJSValue::QJSValue()
+ : d_ptr(InvalidValue())
+{
+}
- \omitvalue UserRange Flags in this range are not used by Qt Script, and can be used for custom purposes.
+/*!
+ Constructs a new QJSValue with a boolean \a value.
*/
+QJSValue::QJSValue(bool value)
+ : d_ptr(new QJSValuePrivate(value))
+{
+}
/*!
Constructs a new QJSValue with a number \a value.
@@ -120,8 +176,6 @@ QJSValue::QJSValue(const QLatin1String &value)
}
/*!
- \fn QJSValue::QJSValue(const QLatin1String &value)
-
Constructs a new QJSValue with a string \a value.
*/
#ifndef QT_NO_CAST_FROM_ASCII
@@ -383,8 +437,6 @@ bool QJSValue::isUndefined() const
/*!
Returns true if this QJSValue is an object of the Error class;
otherwise returns false.
-
- \sa QScriptContext::throwError()
*/
bool QJSValue::isError() const
{
@@ -654,7 +706,7 @@ QVariant QJSValue::toVariant() const
QJSEngine::hasUncaughtException() to determine if an exception
occurred.
- \snippet doc/src/snippets/code/src_script_qscriptvalue.cpp 2
+ \snippet doc/src/snippets/code/src_script_qjsvalue.cpp 1
\sa construct()
*/
@@ -773,7 +825,7 @@ QJSValue& QJSValue::operator=(const QJSValue& other)
toString()) in an attempt to convert the object to a primitive value
(possibly resulting in an uncaught script exception).
- \sa strictlyEquals(), lessThan()
+ \sa strictlyEquals()
*/
bool QJSValue::equals(const QJSValue& other) const
{
@@ -830,9 +882,7 @@ bool QJSValue::instanceOf(const QJSValue &other) const
}
/*!
- Returns the value of this QJSValue's property with the given \a name,
- using the given \a mode to resolve the property.
-
+ Returns the value of this QJSValue's property with the given \a name.
If no such property exists, an invalid QJSValue is returned.
If the property is implemented using a getter function (i.e. has the
@@ -854,8 +904,7 @@ QJSValue QJSValue::property(const QString& name) const
/*!
\overload
- Returns the property at the given \a arrayIndex, using the given \a
- mode to resolve the property.
+ Returns the property at the given \a arrayIndex.
This function is provided for convenience and performance when
working with array objects.
@@ -878,8 +927,7 @@ QJSValue QJSValue::property(quint32 arrayIndex) const
If this QJSValue is not an object, this function does nothing.
If this QJSValue does not already have a property with name \a name,
- a new property is created; the given \a flags then specify how this
- property may be accessed by script code.
+ a new property is created.
If \a value is invalid, the property is removed.
@@ -922,8 +970,7 @@ void QJSValue::setProperty(quint32 arrayIndex, const QJSValue& value)
}
/*!
- Returns the flags of the property with the given \a name, using the
- given \a mode to resolve the property.
+ Returns the flags of the property with the given \a name.
\sa property()
*/
diff --git a/src/declarative/qml/v8/qjsvalue.h b/src/declarative/qml/v8/qjsvalue.h
index 07276bc694..8b78addd00 100644
--- a/src/declarative/qml/v8/qjsvalue.h
+++ b/src/declarative/qml/v8/qjsvalue.h
@@ -34,7 +34,7 @@ QT_BEGIN_HEADER
QT_BEGIN_NAMESPACE
-QT_MODULE(Script)
+QT_MODULE(Declarative)
class QJSValue;
class QJSEngine;
@@ -50,7 +50,7 @@ class QJSValuePrivate;
struct QScriptValuePrivatePointerDeleter;
template <class T> class QScriptPassPointer;
-class Q_SCRIPT_EXPORT QJSValue
+class Q_DECLARATIVE_EXPORT QJSValue
{
public:
enum PropertyFlag {
diff --git a/src/declarative/qml/v8/qjsvalue_impl_p.h b/src/declarative/qml/v8/qjsvalue_impl_p.h
index adff6ce945..b0ad7669d7 100644
--- a/src/declarative/qml/v8/qjsvalue_impl_p.h
+++ b/src/declarative/qml/v8/qjsvalue_impl_p.h
@@ -42,6 +42,29 @@
QT_BEGIN_NAMESPACE
+// This template is used indirectly by the Q_GLOBAL_STATIC macro below
+template<>
+class QGlobalStaticDeleter<QJSValuePrivate>
+{
+public:
+ QGlobalStatic<QJSValuePrivate> &globalStatic;
+ QGlobalStaticDeleter(QGlobalStatic<QJSValuePrivate> &_globalStatic)
+ : globalStatic(_globalStatic)
+ {
+ globalStatic.pointer->ref.ref();
+ }
+
+ inline ~QGlobalStaticDeleter()
+ {
+ if (!globalStatic.pointer->ref.deref()) { // Logic copy & paste from SharedDataPointer
+ delete globalStatic.pointer;
+ }
+ globalStatic.pointer = 0;
+ globalStatic.destroyed = true;
+ }
+};
+
+Q_GLOBAL_STATIC(QJSValuePrivate, InvalidValue)
QJSValuePrivate* QJSValuePrivate::get(const QJSValue& q) { Q_ASSERT(q.d_ptr.data()); return q.d_ptr.data(); }
@@ -803,6 +826,8 @@ inline QScriptPassPointer<QJSValuePrivate> QJSValuePrivate::property(const QStri
{
if (!name.length())
return InvalidValue();
+ if (!isObject())
+ return InvalidValue();
v8::HandleScope handleScope;
return property(QJSConverter::toString(name));
@@ -1013,12 +1038,14 @@ bool QJSValuePrivate::assignEngine(QV8Engine* engine)
/*!
\internal
- reinitialize this value to an invalid value.
+ Invalidates this value.
+
+ Does not remove the value from the engine's list of
+ registered values; that's the responsibility of the caller.
*/
-void QJSValuePrivate::reinitialize()
+void QJSValuePrivate::invalidate()
{
if (isJSBased()) {
- m_engine->unregisterValue(this);
m_value.Dispose();
m_value.Clear();
} else if (isStringBased()) {
@@ -1028,26 +1055,6 @@ void QJSValuePrivate::reinitialize()
m_state = Invalid;
}
-/*!
- \internal
- reinitialize this value to an JSValue.
-*/
-void QJSValuePrivate::reinitialize(QV8Engine* engine, v8::Handle<v8::Value> value)
-{
- Q_ASSERT_X(this != InvalidValue(), Q_FUNC_INFO, "static invalid can't be reinitialized to a different value");
- if (isJSBased()) {
- m_value.Dispose();
- // avoid double registration
- m_engine->unregisterValue(this);
- } else if (isStringBased()) {
- delete u.m_string;
- }
- m_engine = engine;
- m_state = JSValue;
- m_value = v8::Persistent<v8::Value>::New(value);
- m_engine->registerValue(this);
-}
-
QV8Engine* QJSValuePrivate::engine() const
{
return m_engine;
diff --git a/src/declarative/qml/v8/qjsvalue_p.h b/src/declarative/qml/v8/qjsvalue_p.h
index 7b2a001f97..09cd38b0bf 100644
--- a/src/declarative/qml/v8/qjsvalue_p.h
+++ b/src/declarative/qml/v8/qjsvalue_p.h
@@ -43,19 +43,20 @@
#include <QtCore/qvarlengtharray.h>
#include <qdebug.h>
-#include "qscripttools_p.h"
+#include <private/qintrusivelist_p.h>
#include "qscriptshareddata_p.h"
#include "qjsvalue.h"
QT_BEGIN_NAMESPACE
+class QV8Engine;
+
/*!
\internal
\class QJSValuePrivate
*/
class QJSValuePrivate
: public QSharedData
- , public QScriptLinkedNode
{
public:
inline QJSValuePrivate();
@@ -79,8 +80,7 @@ public:
inline QJSValuePrivate(QV8Engine *engine, const QString& value);
inline QJSValuePrivate(QV8Engine *engine, QJSValue::SpecialValue value);
inline QJSValuePrivate(QV8Engine *engine, v8::Handle<v8::Value>);
- inline void reinitialize();
- inline void reinitialize(QV8Engine *engine, v8::Handle<v8::Value> value);
+ inline void invalidate();
inline bool toBool() const;
inline double toNumber() const;
@@ -147,6 +147,7 @@ public:
inline operator v8::Handle<v8::Object>() const;
inline v8::Handle<v8::Value> asV8Value(QV8Engine *engine);
private:
+ QIntrusiveListNode m_node;
QV8Engine *m_engine;
// Please, update class documentation when you change the enum.
@@ -182,32 +183,10 @@ private:
inline bool isNumberBased() const;
inline bool isStringBased() const;
inline bool prepareArgumentsForCall(v8::Handle<v8::Value> argv[], const QJSValueList& arguments) const;
-};
-// This template is used indirectly by the Q_GLOBAL_STATIC macro below
-template<>
-class QGlobalStaticDeleter<QJSValuePrivate>
-{
-public:
- QGlobalStatic<QJSValuePrivate> &globalStatic;
- QGlobalStaticDeleter(QGlobalStatic<QJSValuePrivate> &_globalStatic)
- : globalStatic(_globalStatic)
- {
- globalStatic.pointer->ref.ref();
- }
-
- inline ~QGlobalStaticDeleter()
- {
- if (!globalStatic.pointer->ref.deref()) { // Logic copy & paste from SharedDataPointer
- delete globalStatic.pointer;
- }
- globalStatic.pointer = 0;
- globalStatic.destroyed = true;
- }
+ friend class QV8Engine;
};
-Q_GLOBAL_STATIC(QJSValuePrivate, InvalidValue)
-
QT_END_NAMESPACE
#endif
diff --git a/src/declarative/qml/v8/qjsvalueiterator.cpp b/src/declarative/qml/v8/qjsvalueiterator.cpp
index ca9123f0c0..76a43c9475 100644
--- a/src/declarative/qml/v8/qjsvalueiterator.cpp
+++ b/src/declarative/qml/v8/qjsvalueiterator.cpp
@@ -22,6 +22,7 @@
****************************************************************************/
#include "qjsvalueiterator.h"
+#include "qjsvalueiterator_p.h"
#include "qscriptisolate_p.h"
#include "qjsvalue_p.h"
@@ -35,7 +36,7 @@ QT_BEGIN_NAMESPACE
\brief The QJSValueIterator class provides a Java-style iterator for QJSValue.
- \ingroup script
+ \ingroup qtjavascript
The QJSValueIterator constructor takes a QJSValue as
@@ -43,169 +44,28 @@ QT_BEGIN_NAMESPACE
beginning of the sequence of properties. Here's how to iterate over
all the properties of a QJSValue:
- \snippet doc/src/snippets/code/src_script_QJSValueIterator.cpp 0
+ \snippet doc/src/snippets/code/src_script_qjsvalueiterator.cpp 0
- The next() advances the iterator. The name(), value() and flags()
- functions return the name, value and flags of the last item that was
+ The next() advances the iterator. The name() and value()
+ functions return the name and value of the last item that was
jumped over.
- If you want to remove properties as you iterate over the
- QJSValue, use remove(). If you want to modify the value of a
- property, use setValue().
-
Note that QJSValueIterator only iterates over the QJSValue's
own properties; i.e. it does not follow the prototype chain. You can
use a loop like this to follow the prototype chain:
- \snippet doc/src/snippets/code/src_script_QJSValueIterator.cpp 1
+ \snippet doc/src/snippets/code/src_script_qjsvalueiterator.cpp 1
Note that QJSValueIterator will not automatically skip over
properties that have the QJSValue::SkipInEnumeration flag set;
that flag only affects iteration in script code. If you want, you
can skip over such properties with code like the following:
- \snippet doc/src/snippets/code/src_script_QJSValueIterator.cpp 2
+ \snippet doc/src/snippets/code/src_script_qjsvalueiterator.cpp 2
\sa QJSValue::property()
*/
-using v8::Persistent;
-using v8::Local;
-using v8::Array;
-using v8::String;
-using v8::Handle;
-using v8::Object;
-using v8::Value;
-
-// FIXME (Qt5) This class should be refactored. It should use the common Iterator interface.
-// FIXME it could be faster!
-class QJSValueIteratorPrivate {
-public:
- inline QJSValueIteratorPrivate(const QJSValuePrivate* value);
- inline ~QJSValueIteratorPrivate();
-
- inline bool hasNext() const;
- inline bool next();
-
- inline QString name() const;
-
- inline QScriptPassPointer<QJSValuePrivate> value() const;
-
- inline bool isValid() const;
- inline QV8Engine* engine() const;
-private:
- Q_DISABLE_COPY(QJSValueIteratorPrivate)
- //void dump(QString) const;
-
- QScriptSharedDataPointer<QJSValuePrivate> m_object;
- QList<v8::Persistent<v8::String> > m_names;
- QMutableListIterator<v8::Persistent<v8::String> > m_iterator;
-};
-
-inline QJSValueIteratorPrivate::QJSValueIteratorPrivate(const QJSValuePrivate* value)
- : m_object(const_cast<QJSValuePrivate*>(value))
- , m_iterator(m_names)
-{
- Q_ASSERT(value);
- QV8Engine *engine = m_object->engine();
- QScriptIsolate api(engine);
- if (!m_object->isObject())
- m_object = 0;
- else {
- v8::HandleScope scope;
- Handle<Value> tmp = *value;
- Handle<Object> obj = Handle<Object>::Cast(tmp);
- Local<Array> names;
-
- // FIXME we need newer V8!
- //names = obj->GetOwnPropertyNames();
- names = engine->getOwnPropertyNames(obj);
-
- // it is suboptimal, it would be better to write iterator instead
- uint32_t count = names->Length();
- Local<String> name;
- m_names.reserve(count); // The count is the maximal count of values.
- for (uint32_t i = count - 1; i < count; --i) {
- name = names->Get(i)->ToString();
- m_names.append(v8::Persistent<v8::String>::New(name));
- }
-
- // Reinitialize the iterator.
- m_iterator = m_names;
- }
-}
-
-inline QJSValueIteratorPrivate::~QJSValueIteratorPrivate()
-{
- QMutableListIterator<v8::Persistent<v8::String> > it = m_names;
- //FIXME: we need register this QJSVAlueIterator
- if (engine()) {
- while (it.hasNext()) {
- it.next().Dispose();
- }
- } else {
- // FIXME leak ?
- }
-}
-
-inline bool QJSValueIteratorPrivate::hasNext() const
-{
- //dump("hasNext()");
- return isValid()
- ? m_iterator.hasNext() : false;
-}
-
-inline bool QJSValueIteratorPrivate::next()
-{
- //dump("next();");
- if (m_iterator.hasNext()) {
- m_iterator.next();
- return true;
- }
- return false;
-}
-
-inline QString QJSValueIteratorPrivate::name() const
-{
- //dump("name");
- if (!isValid())
- return QString();
-
- return QJSConverter::toString(m_iterator.value());
-}
-
-inline QScriptPassPointer<QJSValuePrivate> QJSValueIteratorPrivate::value() const
-{
- //dump("value()");
- if (!isValid())
- return InvalidValue();
-
- return m_object->property(m_iterator.value());
-}
-
-inline bool QJSValueIteratorPrivate::isValid() const
-{
- bool result = m_object ? m_object->isValid() : false;
- // We know that if this object is still valid then it is an object
- // if this assumption is not correct then some other logic in this class
- // have to be changed too.
- Q_ASSERT(!result || m_object->isObject());
- return result;
-}
-
-inline QV8Engine* QJSValueIteratorPrivate::engine() const
-{
- return m_object ? m_object->engine() : 0;
-}
-
-//void QJSValueIteratorPrivate::dump(QString fname) const
-//{
-// qDebug() << " *** " << fname << " ***";
-// foreach (Persistent<String> name, m_names) {
-// qDebug() << " - " << QJSConverter::toString(name);
-// }
-//}
-
/*!
Constructs an iterator for traversing \a object. The iterator is
set to be at the front of the sequence of properties (before the
@@ -226,7 +86,7 @@ QJSValueIterator::~QJSValueIterator()
(i.e. the iterator is \e not at the back of the property sequence);
otherwise returns false.
- \sa next(), hasPrevious()
+ \sa next()
*/
bool QJSValueIterator::hasNext() const
{
@@ -237,11 +97,14 @@ bool QJSValueIterator::hasNext() const
/*!
Advances the iterator by one position.
+ Returns true if there is at least one item ahead of the iterator
+ (i.e. the iterator is \e not at the back of the property sequence);
+ otherwise returns false.
Calling this function on an iterator located at the back of the
container leads to undefined results.
- \sa hasNext(), previous(), name()
+ \sa hasNext(), name()
*/
bool QJSValueIterator::next()
{
@@ -252,9 +115,9 @@ bool QJSValueIterator::next()
/*!
Returns the name of the last property that was jumped over using
- next() or previous().
+ next().
- \sa value(), flags()
+ \sa value()
*/
QString QJSValueIterator::name() const
{
@@ -266,9 +129,9 @@ QString QJSValueIterator::name() const
/*!
Returns the value of the last property that was jumped over using
- next() or previous().
+ next().
- \sa setValue(), name()
+ \sa name()
*/
QJSValue QJSValueIterator::value() const
{
diff --git a/src/declarative/qml/v8/qjsvalueiterator.h b/src/declarative/qml/v8/qjsvalueiterator.h
index 1ec4d4b63b..575421d33e 100644
--- a/src/declarative/qml/v8/qjsvalueiterator.h
+++ b/src/declarative/qml/v8/qjsvalueiterator.h
@@ -31,12 +31,12 @@ QT_BEGIN_HEADER
QT_BEGIN_NAMESPACE
-QT_MODULE(Script)
+QT_MODULE(Declarative)
class QString;
class QJSValueIteratorPrivate;
-class Q_SCRIPT_EXPORT QJSValueIterator
+class Q_DECLARATIVE_EXPORT QJSValueIterator
{
public:
QJSValueIterator(const QJSValue &value);
diff --git a/src/declarative/qml/v8/qjsvalueiterator_impl_p.h b/src/declarative/qml/v8/qjsvalueiterator_impl_p.h
new file mode 100644
index 0000000000..68075e55f3
--- /dev/null
+++ b/src/declarative/qml/v8/qjsvalueiterator_impl_p.h
@@ -0,0 +1,121 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtDeclarative module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL-ONLY$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QJSVALUEITERATOR_IMPL_P_H
+#define QJSVALUEITERATOR_IMPL_P_H
+
+#include <qjsvalueiterator_p.h>
+#include <qv8engine_p.h>
+#include <qjsconverter_p.h>
+
+inline QJSValueIteratorPrivate::QJSValueIteratorPrivate(const QJSValuePrivate* value)
+ : m_object(const_cast<QJSValuePrivate*>(value))
+ , m_index(0)
+ , m_count(0)
+{
+ Q_ASSERT(value);
+ QV8Engine *engine = m_object->engine();
+ if (!m_object->isObject())
+ m_object = 0;
+ else {
+ QScriptIsolate api(engine, QScriptIsolate::NotNullEngine);
+ v8::HandleScope scope;
+
+ v8::Handle<v8::Value> tmp = *value;
+ v8::Handle<v8::Object> obj = v8::Handle<v8::Object>::Cast(tmp);
+ v8::Local<v8::Array> names;
+
+ // FIXME we need newer V8!
+ //names = obj->GetOwnPropertyNames();
+ names = engine->getOwnPropertyNames(obj);
+ m_names = v8::Persistent<v8::Array>::New(names);
+ m_count = names->Length();
+
+ engine->registerValueIterator(this);
+ }
+}
+
+inline QJSValueIteratorPrivate::~QJSValueIteratorPrivate()
+{
+ if (isValid()) {
+ engine()->unregisterValueIterator(this);
+ m_names.Dispose();
+ }
+}
+
+inline void QJSValueIteratorPrivate::invalidate()
+{
+ m_names.Dispose();
+ m_object.reset();
+ m_index = 0;
+ m_count = 0;
+}
+
+inline bool QJSValueIteratorPrivate::hasNext() const
+{
+ return isValid() ? m_index < m_count : false;
+}
+
+inline bool QJSValueIteratorPrivate::next()
+{
+ if (hasNext()) {
+ ++m_index;
+ return true;
+ }
+ return false;
+}
+
+inline QString QJSValueIteratorPrivate::name() const
+{
+ if (!isValid())
+ return QString();
+
+ v8::HandleScope handleScope;
+ return QJSConverter::toString(m_names->Get(m_index - 1)->ToString());
+}
+
+inline QScriptPassPointer<QJSValuePrivate> QJSValueIteratorPrivate::value() const
+{
+ if (!isValid())
+ return InvalidValue();
+
+ v8::HandleScope handleScope;
+ return m_object->property(m_names->Get(m_index - 1)->ToString());
+}
+
+inline bool QJSValueIteratorPrivate::isValid() const
+{
+ bool result = m_object ? m_object->isValid() : false;
+ // We know that if this object is still valid then it is an object
+ // if this assumption is not correct then some other logic in this class
+ // have to be changed too.
+ Q_ASSERT(!result || m_object->isObject());
+ return result;
+}
+
+inline QV8Engine* QJSValueIteratorPrivate::engine() const
+{
+ return m_object ? m_object->engine() : 0;
+}
+
+#endif // QJSVALUEITERATOR_IMPL_P_H
diff --git a/src/declarative/qml/v8/qjsvalueiterator_p.h b/src/declarative/qml/v8/qjsvalueiterator_p.h
new file mode 100644
index 0000000000..6113d3dd4f
--- /dev/null
+++ b/src/declarative/qml/v8/qjsvalueiterator_p.h
@@ -0,0 +1,68 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtDeclarative module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL-ONLY$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QJSVALUEITERATOR_P_H
+#define QJSVALUEITERATOR_P_H
+
+#include <private/qintrusivelist_p.h>
+#include "qjsvalue_p.h"
+
+#include <private/qv8_p.h>
+
+QT_BEGIN_NAMESPACE
+
+class QV8Engine;
+
+class QJSValueIteratorPrivate
+{
+public:
+ inline QJSValueIteratorPrivate(const QJSValuePrivate* value);
+ inline ~QJSValueIteratorPrivate();
+
+ inline bool hasNext() const;
+ inline bool next();
+
+ inline QString name() const;
+
+ inline QScriptPassPointer<QJSValuePrivate> value() const;
+
+ inline bool isValid() const;
+ inline QV8Engine* engine() const;
+
+ inline void invalidate();
+private:
+ Q_DISABLE_COPY(QJSValueIteratorPrivate)
+
+ QIntrusiveListNode m_node;
+ QScriptSharedDataPointer<QJSValuePrivate> m_object;
+ v8::Persistent<v8::Array> m_names;
+ uint32_t m_index;
+ uint32_t m_count;
+
+ friend class QV8Engine;
+};
+
+
+QT_END_NAMESPACE
+
+#endif // QJSVALUEITERATOR_P_H
diff --git a/src/declarative/qml/v8/qscript_impl_p.h b/src/declarative/qml/v8/qscript_impl_p.h
index e66b561efe..d197d9fd6b 100644
--- a/src/declarative/qml/v8/qscript_impl_p.h
+++ b/src/declarative/qml/v8/qscript_impl_p.h
@@ -37,5 +37,6 @@
#include "qv8engine_impl_p.h"
#include "qjsvalue_impl_p.h"
+#include "qjsvalueiterator_impl_p.h"
#endif //QSCRIPT_IMPL_P_H
diff --git a/src/declarative/qml/v8/qscriptoriginalglobalobject_p.h b/src/declarative/qml/v8/qscriptoriginalglobalobject_p.h
index c46d0e37a0..c0a761f518 100644
--- a/src/declarative/qml/v8/qscriptoriginalglobalobject_p.h
+++ b/src/declarative/qml/v8/qscriptoriginalglobalobject_p.h
@@ -49,7 +49,7 @@ class QV8Engine;
class QScriptOriginalGlobalObject
{
public:
- inline QScriptOriginalGlobalObject(const QV8Engine *engine, v8::Handle<v8::Context> context);
+ inline QScriptOriginalGlobalObject(v8::Handle<v8::Context> context);
inline void destroy();
inline QJSValue::PropertyFlags getPropertyFlags(v8::Handle<v8::Object> object, v8::Handle<v8::Value> property);
@@ -63,7 +63,7 @@ private:
v8::Persistent<v8::Object> m_globalObject;
};
-QScriptOriginalGlobalObject::QScriptOriginalGlobalObject(const QV8Engine *engine, v8::Handle<v8::Context> context)
+QScriptOriginalGlobalObject::QScriptOriginalGlobalObject(v8::Handle<v8::Context> context)
{
// Please notice that engine is not fully initialized at this point.
diff --git a/src/declarative/qml/v8/qscripttools_p.h b/src/declarative/qml/v8/qscripttools_p.h
index f74fbab83f..c8dace0b9f 100644
--- a/src/declarative/qml/v8/qscripttools_p.h
+++ b/src/declarative/qml/v8/qscripttools_p.h
@@ -36,180 +36,32 @@
#ifndef QSCRIPTTOOLS_P_H
#define QSCRIPTTOOLS_P_H
-#include <qdebug.h>
+#include <private/qintrusivelist_p.h>
QT_BEGIN_NAMESPACE
-template<class T>
-class QScriptBagContainer;
-
-/*!
- \internal
- \interface
- Helper class for a container. The purpuse of it is to add two pointer properties to a class
- inheriting this class without bloating an interface.
-
- This class exist only as a memory storage implementation. The only way to use it is to inherit it.
-*/
-class QScriptLinkedNode
+template<class N, QIntrusiveListNode N::*member>
+class QScriptIntrusiveList : public QIntrusiveList<N, member>
{
-protected:
- QScriptLinkedNode()
- : m_next(0)
- , m_prev(0)
- {}
-
- ~QScriptLinkedNode()
- {
- Q_ASSERT_X(!isUsed(), Q_FUNC_INFO, "Destorying QScriptLinkedNode instance that still is in a container");
- }
-
-private:
- bool isUsed() const
- {
- return m_next || m_prev;
- }
-
-#if defined(Q_NO_TEMPLATE_FRIENDS)
public:
-#else
- template<class T>
- friend class QScriptBagContainer;
-#endif
- QScriptLinkedNode *m_next;
- QScriptLinkedNode *m_prev;
+ inline void insert(N *n);
+ inline void remove(N *n);
};
-/*!
- \internal
- The QScriptBagContainer is a simple, low level, set like container for a pointer type castable to
- QScriptLinkedNode*.
- Algorithms complexity:
- put: O(1)
- get: O(1)
- forEach: O(n)
- \note This container doesn't take ownership of pointed values.
- \attention All values have to be unique.
-*/
-template<class T>
-class QScriptBagContainer
+template<class N, QIntrusiveListNode N::*member>
+void QScriptIntrusiveList<N, member>::insert(N *n)
{
-public:
- QScriptBagContainer()
- : m_first(0)
- {}
-
- /*!
- \internal
- Add a this \a value to this container
- */
- void insert(T* value)
- {
- //dump(Q_FUNC_INFO, value);
- Q_ASSERT_X(!contains(value), Q_FUNC_INFO, "Can't insert a value which is in the bag already");
- QScriptLinkedNode* v = static_cast<QScriptLinkedNode*>(value);
- Q_ASSERT(v);
- Q_ASSERT_X(!v->m_next && !v->m_prev, Q_FUNC_INFO, "Can't insert a value which is in an another bag");
-
- if (m_first)
- m_first->m_prev = v;
-
- v->m_next = m_first;
- v->m_prev = 0;
- m_first = v;
- }
-
- /*!
- \internal
- Remove this \a value from this container
- */
- void remove(T* value)
- {
- //dump(Q_FUNC_INFO, value);
- QScriptLinkedNode* v = static_cast<QScriptLinkedNode*>(value);
- Q_ASSERT(v);
+ Q_ASSERT_X(!contains(n), Q_FUNC_INFO, "Can't insert a value which is in the list already");
+ Q_ASSERT_X(!(n->*member).isInList(), Q_FUNC_INFO, "Can't insert a value which is in another list");
+ QIntrusiveList<N, member>::insert(n);
+}
- if (!v->m_next && !v->m_prev && m_first != v) {
- // ignore that value as it is not registered at all
- // FIXME: That may be optimized out if unregister call is removed from ~QtDataBase
- return;
- }
-
- Q_ASSERT_X(contains(value), Q_FUNC_INFO, "Can't remove a value which is not in the bag");
- Q_ASSERT(v->m_prev || (m_first == v && !v->m_prev));
-
- if (v->m_next)
- v->m_next->m_prev= v->m_prev;
-
- if (v->m_prev)
- v->m_prev->m_next = v->m_next;
- else
- m_first = v->m_next;
- // reset removed value
- v->m_next = v->m_prev = 0;
- }
-
- /*!
- \internal
- Call \a fun for each element in this container. Fun should accept T* as a parameter.
- \note In general it is not allowed to change this container by calling put() or get() unless
- given value is the same as currently procceded by forEach.
- */
- template<class Functor>
- void forEach(Functor fun)
- {
- //dump(Q_FUNC_INFO);
- QScriptLinkedNode *i = m_first;
- QScriptLinkedNode *tmp;
- while (i) {
- tmp = i;
- i = i->m_next;
- fun(static_cast<T*>(tmp));
- }
- }
-
- /*!
- \internal
- Clear this container.
- */
- void clear()
- {
- m_first = 0;
- }
-
- /*!
- \internal
- Returns true if this container is empty; false otherwise.
- */
- bool isEmpty() const
- {
- return !m_first;
- }
-
-// void dump(const char* msg, T* obj = 0) const
-// {
-// qDebug() << msg << obj;
-// qDebug() << m_first;
-// QScriptLinkedNode *i = m_first;
-// while (i) {
-// qDebug() <<" - " << i << "(" << i->m_prev << ", " << i->m_next <<")";
-// i = i->m_next;
-// }
-// }
-
-private:
- bool contains(T *value) const
- {
- QScriptLinkedNode *i = m_first;
- while (i) {
- if (static_cast<T*>(i) == value)
- return true;
- i = i->m_next;
- }
- return false;
- }
- QScriptLinkedNode *m_first;
-};
+template<class N, QIntrusiveListNode N::*member>
+void QScriptIntrusiveList<N, member>::remove(N *n)
+{
+ Q_ASSERT_X(contains(n), Q_FUNC_INFO, "Can't remove a value which is not in the list");
+ QIntrusiveList<N, member>::remove(n);
+}
QT_END_NAMESPACE
diff --git a/src/declarative/qml/v8/qv8_p.h b/src/declarative/qml/v8/qv8_p.h
index 6aeb6f6458..8df007e804 100644
--- a/src/declarative/qml/v8/qv8_p.h
+++ b/src/declarative/qml/v8/qv8_p.h
@@ -1 +1,42 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtDeclarative module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
#include "../../../3rdparty/v8/include/v8.h"
diff --git a/src/declarative/qml/v8/qv8bindings.cpp b/src/declarative/qml/v8/qv8bindings.cpp
index c45274a97f..3c98af2951 100644
--- a/src/declarative/qml/v8/qv8bindings.cpp
+++ b/src/declarative/qml/v8/qv8bindings.cpp
@@ -7,29 +7,29 @@
** This file is part of the QtDeclarative module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
+** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
**
**
**
diff --git a/src/declarative/qml/v8/qv8bindings_p.h b/src/declarative/qml/v8/qv8bindings_p.h
index f8a9407ed8..b387a50df3 100644
--- a/src/declarative/qml/v8/qv8bindings_p.h
+++ b/src/declarative/qml/v8/qv8bindings_p.h
@@ -7,29 +7,29 @@
** This file is part of the QtDeclarative module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
+** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
**
**
**
diff --git a/src/declarative/qml/v8/qv8contextwrapper.cpp b/src/declarative/qml/v8/qv8contextwrapper.cpp
index 4984102ba2..f41c994a0d 100644
--- a/src/declarative/qml/v8/qv8contextwrapper.cpp
+++ b/src/declarative/qml/v8/qv8contextwrapper.cpp
@@ -7,29 +7,29 @@
** This file is part of the QtDeclarative module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
+** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
**
**
**
diff --git a/src/declarative/qml/v8/qv8debug_p.h b/src/declarative/qml/v8/qv8debug_p.h
new file mode 100644
index 0000000000..51208aac8e
--- /dev/null
+++ b/src/declarative/qml/v8/qv8debug_p.h
@@ -0,0 +1 @@
+#include "../../../3rdparty/v8/include/v8-debug.h"
diff --git a/src/declarative/qml/v8/qv8domerrors.cpp b/src/declarative/qml/v8/qv8domerrors.cpp
new file mode 100644
index 0000000000..e739e4a7bd
--- /dev/null
+++ b/src/declarative/qml/v8/qv8domerrors.cpp
@@ -0,0 +1,73 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtDeclarative module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qv8domerrors_p.h"
+#include "qv8engine_p.h"
+
+QT_BEGIN_NAMESPACE
+
+void qt_add_domexceptions(QV8Engine *engine)
+{
+ // DOM Exception
+ v8::PropertyAttribute attributes = (v8::PropertyAttribute)(v8::ReadOnly | v8::DontEnum | v8::DontDelete);
+
+ v8::Local<v8::Object> domexception = v8::Object::New();
+ domexception->Set(v8::String::New("INDEX_SIZE_ERR"), v8::Integer::New(DOMEXCEPTION_INDEX_SIZE_ERR), attributes);
+ domexception->Set(v8::String::New("DOMSTRING_SIZE_ERR"), v8::Integer::New(DOMEXCEPTION_DOMSTRING_SIZE_ERR), attributes);
+ domexception->Set(v8::String::New("HIERARCHY_REQUEST_ERR"), v8::Integer::New(DOMEXCEPTION_HIERARCHY_REQUEST_ERR), attributes);
+ domexception->Set(v8::String::New("WRONG_DOCUMENT_ERR"), v8::Integer::New(DOMEXCEPTION_WRONG_DOCUMENT_ERR), attributes);
+ domexception->Set(v8::String::New("INVALID_CHARACTER_ERR"), v8::Integer::New(DOMEXCEPTION_INVALID_CHARACTER_ERR), attributes);
+ domexception->Set(v8::String::New("NO_DATA_ALLOWED_ERR"), v8::Integer::New(DOMEXCEPTION_NO_DATA_ALLOWED_ERR), attributes);
+ domexception->Set(v8::String::New("NO_MODIFICATION_ALLOWED_ERR"), v8::Integer::New(DOMEXCEPTION_NO_MODIFICATION_ALLOWED_ERR), attributes);
+ domexception->Set(v8::String::New("NOT_FOUND_ERR"), v8::Integer::New(DOMEXCEPTION_NOT_FOUND_ERR), attributes);
+ domexception->Set(v8::String::New("NOT_SUPPORTED_ERR"), v8::Integer::New(DOMEXCEPTION_NOT_SUPPORTED_ERR), attributes);
+ domexception->Set(v8::String::New("INUSE_ATTRIBUTE_ERR"), v8::Integer::New(DOMEXCEPTION_INUSE_ATTRIBUTE_ERR), attributes);
+ domexception->Set(v8::String::New("INVALID_STATE_ERR"), v8::Integer::New(DOMEXCEPTION_INVALID_STATE_ERR), attributes);
+ domexception->Set(v8::String::New("SYNTAX_ERR"), v8::Integer::New(DOMEXCEPTION_SYNTAX_ERR), attributes);
+ domexception->Set(v8::String::New("INVALID_MODIFICATION_ERR"), v8::Integer::New(DOMEXCEPTION_INVALID_MODIFICATION_ERR), attributes);
+ domexception->Set(v8::String::New("NAMESPACE_ERR"), v8::Integer::New(DOMEXCEPTION_NAMESPACE_ERR), attributes);
+ domexception->Set(v8::String::New("INVALID_ACCESS_ERR"), v8::Integer::New(DOMEXCEPTION_INVALID_ACCESS_ERR), attributes);
+ domexception->Set(v8::String::New("VALIDATION_ERR"), v8::Integer::New(DOMEXCEPTION_VALIDATION_ERR), attributes);
+ domexception->Set(v8::String::New("TYPE_MISMATCH_ERR"), v8::Integer::New(DOMEXCEPTION_TYPE_MISMATCH_ERR), attributes);
+ engine->global()->Set(v8::String::New("DOMException"), domexception);
+}
+
+QT_END_NAMESPACE
diff --git a/src/declarative/qml/v8/qv8domerrors_p.h b/src/declarative/qml/v8/qv8domerrors_p.h
new file mode 100644
index 0000000000..ef8ab28c12
--- /dev/null
+++ b/src/declarative/qml/v8/qv8domerrors_p.h
@@ -0,0 +1,94 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtDeclarative module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QV8DOMERRORS_P_H
+#define QV8DOMERRORS_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtCore/qglobal.h>
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+// From DOM-Level-3-Core spec
+// http://www.w3.org/TR/DOM-Level-3-Core/core.html
+#define DOMEXCEPTION_INDEX_SIZE_ERR 1
+#define DOMEXCEPTION_DOMSTRING_SIZE_ERR 2
+#define DOMEXCEPTION_HIERARCHY_REQUEST_ERR 3
+#define DOMEXCEPTION_WRONG_DOCUMENT_ERR 4
+#define DOMEXCEPTION_INVALID_CHARACTER_ERR 5
+#define DOMEXCEPTION_NO_DATA_ALLOWED_ERR 6
+#define DOMEXCEPTION_NO_MODIFICATION_ALLOWED_ERR 7
+#define DOMEXCEPTION_NOT_FOUND_ERR 8
+#define DOMEXCEPTION_NOT_SUPPORTED_ERR 9
+#define DOMEXCEPTION_INUSE_ATTRIBUTE_ERR 10
+#define DOMEXCEPTION_INVALID_STATE_ERR 11
+#define DOMEXCEPTION_SYNTAX_ERR 12
+#define DOMEXCEPTION_INVALID_MODIFICATION_ERR 13
+#define DOMEXCEPTION_NAMESPACE_ERR 14
+#define DOMEXCEPTION_INVALID_ACCESS_ERR 15
+#define DOMEXCEPTION_VALIDATION_ERR 16
+#define DOMEXCEPTION_TYPE_MISMATCH_ERR 17
+
+#define V8THROW_DOM(error, string) { \
+ v8::Local<v8::Value> v = v8::Exception::Error(v8::String::New(string)); \
+ v->ToObject()->Set(v8::String::New("code"), v8::Integer::New(error)); \
+ v8::ThrowException(v); \
+ return v8::Handle<v8::Value>(); \
+}
+class QV8Engine;
+void qt_add_domexceptions(QV8Engine *engine);
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif // QV8DOMERRORS_P_H
diff --git a/src/declarative/qml/v8/qv8engine.cpp b/src/declarative/qml/v8/qv8engine.cpp
index acbfb92b15..4f5caa13f4 100644
--- a/src/declarative/qml/v8/qv8engine.cpp
+++ b/src/declarative/qml/v8/qv8engine.cpp
@@ -7,29 +7,29 @@
** This file is part of the QtDeclarative module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
+** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
**
**
**
@@ -42,6 +42,7 @@
#include "qv8engine_p.h"
#include "qv8contextwrapper_p.h"
+#include "qv8valuetypewrapper_p.h"
#include "qv8include_p.h"
#include "../../../3rdparty/javascriptcore/DateMath.h"
@@ -63,6 +64,7 @@
#include <private/qdeclarativesqldatabase_p.h>
#include "qscript_impl_p.h"
+#include "qv8domerrors_p.h"
Q_DECLARE_METATYPE(QJSValue)
Q_DECLARE_METATYPE(QList<int>)
@@ -87,10 +89,20 @@ static bool ObjectComparisonCallback(v8::Local<v8::Object> lhs, v8::Local<v8::Ob
QV8ObjectResource::ResourceType rhst = rhsr->resourceType();
switch (lhst) {
+ case QV8ObjectResource::ValueTypeType:
+ if (rhst == QV8ObjectResource::ValueTypeType) {
+ return lhsr->engine->valueTypeWrapper()->isEqual(lhsr, lhsr->engine->valueTypeWrapper()->toVariant(rhsr));
+ } else if (rhst == QV8ObjectResource::VariantType) {
+ return lhsr->engine->valueTypeWrapper()->isEqual(lhsr, lhsr->engine->variantWrapper()->toVariant(rhsr));
+ }
+ break;
case QV8ObjectResource::VariantType:
- if (rhst == QV8ObjectResource::VariantType)
+ if (rhst == QV8ObjectResource::VariantType) {
return lhsr->engine->variantWrapper()->toVariant(lhsr) ==
lhsr->engine->variantWrapper()->toVariant(rhsr);
+ } else if (rhst == QV8ObjectResource::ValueTypeType) {
+ return rhsr->engine->valueTypeWrapper()->isEqual(rhsr, rhsr->engine->variantWrapper()->toVariant(lhsr));
+ }
break;
default:
break;
@@ -105,7 +117,7 @@ QV8Engine::QV8Engine(QJSEngine* qq, QJSEngine::ContextOwnership ownership)
, m_engine(0)
, m_ownsV8Context(ownership == QJSEngine::CreateNewContext)
, m_context((ownership == QJSEngine::CreateNewContext) ? v8::Context::New() : v8::Persistent<v8::Context>::New(v8::Context::GetCurrent()))
- , m_originalGlobalObject(this, m_context)
+ , m_originalGlobalObject(m_context)
, m_xmlHttpRequestData(0)
, m_sqlDatabaseData(0)
, m_listModelData(0)
@@ -265,55 +277,6 @@ static v8::Handle<v8::Object> objectFromVariantMap(QV8Engine *engine, const QVar
Q_CORE_EXPORT QString qt_regexp_toCanonical(const QString &, QRegExp::PatternSyntax);
-// Converts a QRegExp to a JS RegExp.
-// The conversion is not 100% exact since ECMA regexp and QRegExp
-// have different semantics/flags, but we try to do our best.
-static v8::Handle<v8::RegExp> regexpFromQRegExp(QV8Engine *engine, const QRegExp &re)
-{
- // Convert the pattern to a ECMAScript pattern.
- QString pattern = qt_regexp_toCanonical(re.pattern(), re.patternSyntax());
- if (re.isMinimal()) {
- QString ecmaPattern;
- int len = pattern.length();
- ecmaPattern.reserve(len);
- int i = 0;
- const QChar *wc = pattern.unicode();
- bool inBracket = false;
- while (i < len) {
- QChar c = wc[i++];
- ecmaPattern += c;
- switch (c.unicode()) {
- case '?':
- case '+':
- case '*':
- case '}':
- if (!inBracket)
- ecmaPattern += QLatin1Char('?');
- break;
- case '\\':
- if (i < len)
- ecmaPattern += wc[i++];
- break;
- case '[':
- inBracket = true;
- break;
- case ']':
- inBracket = false;
- break;
- default:
- break;
- }
- }
- pattern = ecmaPattern;
- }
-
- int flags = v8::RegExp::kNone;
- if (re.caseSensitivity() == Qt::CaseInsensitive)
- flags |= v8::RegExp::kIgnoreCase;
-
- return v8::RegExp::New(engine->toString(pattern), static_cast<v8::RegExp::Flags>(flags));
-}
-
v8::Handle<v8::Value> QV8Engine::fromVariant(const QVariant &variant)
{
int type = variant.userType();
@@ -356,7 +319,7 @@ v8::Handle<v8::Value> QV8Engine::fromVariant(const QVariant &variant)
case QMetaType::QTime:
return v8::Date::New(qtDateTimeToJsDate(QDateTime(QDate(1970,1,1), *reinterpret_cast<const QTime *>(ptr))));
case QMetaType::QRegExp:
- return regexpFromQRegExp(this, *reinterpret_cast<const QRegExp *>(ptr));
+ return QJSConverter::toRegExp(*reinterpret_cast<const QRegExp *>(ptr));
case QMetaType::QObjectStar:
case QMetaType::QWidgetStar:
return newQObject(*reinterpret_cast<QObject* const *>(ptr));
@@ -464,13 +427,13 @@ QVariant QV8Engine::toBasicVariant(v8::Handle<v8::Value> value)
{
if (value->IsNull() || value->IsUndefined())
return QVariant();
- else if (value->IsBoolean())
+ if (value->IsBoolean())
return value->ToBoolean()->Value();
- else if (value->IsInt32())
+ if (value->IsInt32())
return value->ToInt32()->Value();
- else if (value->IsNumber())
+ if (value->IsNumber())
return value->ToNumber()->Value();
- else if (value->IsString())
+ if (value->IsString())
return m_stringWrapper.toString(value->ToString());
if (value->IsDate())
return qtDateTimeFromJsDate(v8::Handle<v8::Date>::Cast(value)->NumberValue());
@@ -480,17 +443,9 @@ QVariant QV8Engine::toBasicVariant(v8::Handle<v8::Value> value)
if (value->IsRegExp()) {
v8::Context::Scope scope(context());
- v8::Handle<v8::RegExp> jsRegExp = v8::Handle<v8::RegExp>::Cast(value);
- // Copied from QtScript
- // Converts a JS RegExp to a QRegExp.
- // The conversion is not 100% exact since ECMA regexp and QRegExp
- // have different semantics/flags, but we try to do our best.
- QString pattern = toString(jsRegExp->GetSource());
- Qt::CaseSensitivity caseSensitivity = Qt::CaseSensitive;
- if (jsRegExp->GetFlags() & v8::RegExp::kIgnoreCase)
- caseSensitivity = Qt::CaseInsensitive;
- return QRegExp(pattern, caseSensitivity, QRegExp::RegExp2);
- } else if (value->IsArray()) {
+ return QJSConverter::toRegExp(v8::Handle<v8::RegExp>::Cast(value));
+ }
+ if (value->IsArray()) {
v8::Context::Scope scope(context());
QVariantList rv;
@@ -500,7 +455,8 @@ QVariant QV8Engine::toBasicVariant(v8::Handle<v8::Value> value)
rv << toVariant(array->Get(ii), -1);
return rv;
- } else if (!value->IsFunction()) {
+ }
+ if (!value->IsFunction()) {
v8::Context::Scope scope(context());
v8::Handle<v8::Object> object = value->ToObject();
v8::Local<v8::Array> properties = object->GetPropertyNames();
@@ -522,6 +478,7 @@ QVariant QV8Engine::toBasicVariant(v8::Handle<v8::Value> value)
#include <QtGui/qvector3d.h>
+#include <QtGui/qvector4d.h>
struct StaticQtMetaObject : public QObject
{
@@ -556,6 +513,7 @@ void QV8Engine::initializeGlobal(v8::Handle<v8::Object> global)
qt->Set(v8::String::New("point"), V8FUNCTION(point, this));
qt->Set(v8::String::New("size"), V8FUNCTION(size, this));
qt->Set(v8::String::New("vector3d"), V8FUNCTION(vector3d, this));
+ qt->Set(v8::String::New("vector4d"), V8FUNCTION(vector4d, this));
qt->Set(v8::String::New("formatDate"), V8FUNCTION(formatDate, this));
qt->Set(v8::String::New("formatTime"), V8FUNCTION(formatTime, this));
@@ -594,6 +552,7 @@ void QV8Engine::initializeGlobal(v8::Handle<v8::Object> global)
v8::Local<v8::Object> stringPrototype = v8::Local<v8::Object>::Cast(string->Get(v8::String::New("prototype")));
stringPrototype->Set(v8::String::New("arg"), V8FUNCTION(stringArg, this));
+ qt_add_domexceptions(this);
m_xmlHttpRequestData = qt_add_qmlxmlhttprequest(this);
m_sqlDatabaseData = qt_add_qmlsqldatabase(this);
@@ -891,6 +850,23 @@ v8::Handle<v8::Value> QV8Engine::vector3d(const v8::Arguments &args)
}
/*!
+\qmlmethod Qt::vector4d(real x, real y, real z, real w)
+Returns a Vector4D with the specified \c x, \c y, \c z and \c w.
+*/
+v8::Handle<v8::Value> QV8Engine::vector4d(const v8::Arguments &args)
+{
+ if (args.Length() != 4)
+ V8THROW_ERROR("Qt.vector4d(): Invalid arguments");
+
+ double x = args[0]->NumberValue();
+ double y = args[1]->NumberValue();
+ double z = args[2]->NumberValue();
+ double w = args[3]->NumberValue();
+
+ return V8ENGINE()->fromVariant(QVariant::fromValue(QVector4D(x, y, z, w)));
+}
+
+/*!
\qmlmethod color Qt::lighter(color baseColor, real factor)
Returns a color lighter than \c baseColor by the \c factor provided.
@@ -2131,14 +2107,14 @@ bool QV8Engine::metaTypeFromJS(v8::Handle<v8::Value> value, int type, void *data
}
#endif
- // Try to use magic.
+ // Try to use magic; for compatibility with qscriptvalue_cast.
QByteArray name = QMetaType::typeName(type);
if (convertToNativeQObject(value, name, reinterpret_cast<void* *>(data)))
return true;
if (isVariant(value) && name.endsWith('*')) {
int valueType = QMetaType::type(name.left(name.size()-1));
- QVariant var = variantValue(value);
+ QVariant &var = variantValue(value);
if (valueType == var.userType()) {
// We have T t, T* is requested, so return &t.
*reinterpret_cast<void* *>(data) = var.data();
@@ -2201,9 +2177,9 @@ QVariant QV8Engine::variantFromJS(v8::Handle<v8::Value> value)
return QVariant();
if (value->IsBoolean())
return value->ToBoolean()->Value();
- else if (value->IsInt32())
+ if (value->IsInt32())
return value->ToInt32()->Value();
- else if (value->IsNumber())
+ if (value->IsNumber())
return value->ToNumber()->Value();
if (value->IsString())
return QJSConverter::toString(value->ToString());
@@ -2259,10 +2235,9 @@ QObject *QV8Engine::qtObjectFromJS(v8::Handle<v8::Value> value)
}
-QVariant QV8Engine::variantValue(v8::Handle<v8::Value> value)
+QVariant &QV8Engine::variantValue(v8::Handle<v8::Value> value)
{
- Q_ASSERT(isVariant(value));
- return QV8Engine::toVariant(value, -1 /*whateever magic hint is*/);
+ return variantWrapper()->variantValue(value);
}
// Creates a QVariant wrapper object.
diff --git a/src/declarative/qml/v8/qv8engine_impl_p.h b/src/declarative/qml/v8/qv8engine_impl_p.h
index 5c56efdf39..53ce2a5acd 100644
--- a/src/declarative/qml/v8/qv8engine_impl_p.h
+++ b/src/declarative/qml/v8/qv8engine_impl_p.h
@@ -38,6 +38,7 @@
#include "qv8engine_p.h"
#include "qjsvalue_p.h"
#include "qjsconverter_p.h"
+#include "qjsvalueiterator_p.h"
QT_BEGIN_NAMESPACE
@@ -80,6 +81,10 @@ public:
{
value->reinitialize();
}
+ void operator () (QJSValueIteratorPrivate *iterator) const
+ {
+ iterator->invalidate();
+ }
};
inline void QV8Engine::registerValue(QJSValuePrivate *data)
@@ -94,9 +99,28 @@ inline void QV8Engine::unregisterValue(QJSValuePrivate *data)
inline void QV8Engine::invalidateAllValues()
{
- QtScriptBagCleaner invalidator;
- m_values.forEach(invalidator);
- m_values.clear();
+ ValueList::iterator it;
+ for (it = m_values.begin(); it != m_values.end(); it = it.erase())
+ (*it)->invalidate();
+ Q_ASSERT(m_values.isEmpty());
+}
+
+inline void QV8Engine::registerValueIterator(QJSValueIteratorPrivate *data)
+{
+ m_valueIterators.insert(data);
+}
+
+inline void QV8Engine::unregisterValueIterator(QJSValueIteratorPrivate *data)
+{
+ m_valueIterators.remove(data);
+}
+
+inline void QV8Engine::invalidateAllIterators()
+{
+ ValueIteratorList::iterator it;
+ for (it = m_valueIterators.begin(); it != m_valueIterators.end(); it = it.erase())
+ (*it)->invalidate();
+ Q_ASSERT(m_valueIterators.isEmpty());
}
/*!
diff --git a/src/declarative/qml/v8/qv8engine_p.h b/src/declarative/qml/v8/qv8engine_p.h
index b95e55002b..43ef9821ac 100644
--- a/src/declarative/qml/v8/qv8engine_p.h
+++ b/src/declarative/qml/v8/qv8engine_p.h
@@ -7,29 +7,29 @@
** This file is part of the QtDeclarative module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
+** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
**
**
**
@@ -63,6 +63,8 @@
#include <private/qv8_p.h>
#include <qjsengine.h>
#include <qjsvalue.h>
+#include "qjsvalue_p.h"
+#include "qjsvalueiterator_p.h"
#include "qscriptoriginalglobalobject_p.h"
#include "qscripttools_p.h"
@@ -125,6 +127,7 @@ private:
return rv; \
} \
+
class QV8Engine;
class QV8ObjectResource : public v8::Object::ExternalResource
{
@@ -214,6 +217,7 @@ class QDeclarativeEngine;
class QDeclarativeValueType;
class QNetworkAccessManager;
class QDeclarativeContextData;
+
class Q_DECLARATIVE_EXPORT QV8Engine
{
public:
@@ -260,11 +264,16 @@ public:
inline void unregisterValue(QJSValuePrivate *data);
inline void invalidateAllValues();
+ inline void registerValueIterator(QJSValueIteratorPrivate *data);
+ inline void unregisterValueIterator(QJSValueIteratorPrivate *data);
+ inline void invalidateAllIterators();
+
QV8ContextWrapper *contextWrapper() { return &m_contextWrapper; }
QV8QObjectWrapper *qobjectWrapper() { return &m_qobjectWrapper; }
QV8TypeWrapper *typeWrapper() { return &m_typeWrapper; }
QV8ListWrapper *listWrapper() { return &m_listWrapper; }
QV8VariantWrapper *variantWrapper() { return &m_variantWrapper; }
+ QV8ValueTypeWrapper *valueTypeWrapper() { return &m_valueTypeWrapper; }
void *xmlHttpRequestData() { return m_xmlHttpRequestData; }
void *sqlDatabaseData() { return m_sqlDatabaseData; }
@@ -378,7 +387,7 @@ public:
const QByteArray &targetType,
void **result);
- QVariant variantValue(v8::Handle<v8::Value> value);
+ QVariant &variantValue(v8::Handle<v8::Value> value);
QJSValue scriptValueFromInternal(v8::Handle<v8::Value>) const;
@@ -427,6 +436,7 @@ protected:
static v8::Handle<v8::Value> point(const v8::Arguments &args);
static v8::Handle<v8::Value> size(const v8::Arguments &args);
static v8::Handle<v8::Value> vector3d(const v8::Arguments &args);
+ static v8::Handle<v8::Value> vector4d(const v8::Arguments &args);
static v8::Handle<v8::Value> lighter(const v8::Arguments &args);
static v8::Handle<v8::Value> darker(const v8::Arguments &args);
static v8::Handle<v8::Value> tint(const v8::Arguments &args);
@@ -452,10 +462,15 @@ protected:
double qtDateTimeToJsDate(const QDateTime &dt);
QDateTime qtDateTimeFromJsDate(double jsDate);
+
private:
- QScriptBagContainer<QJSValuePrivate> m_values;
+ typedef QScriptIntrusiveList<QJSValuePrivate, &QJSValuePrivate::m_node> ValueList;
+ ValueList m_values;
+ typedef QScriptIntrusiveList<QJSValueIteratorPrivate, &QJSValueIteratorPrivate::m_node> ValueIteratorList;
+ ValueIteratorList m_valueIterators;
Q_DISABLE_COPY(QV8Engine)
+ friend class QV8DebugService;
};
// Allocate a new Persistent handle. *ALL* persistent handles in QML must be allocated
diff --git a/src/declarative/qml/v8/qv8include.cpp b/src/declarative/qml/v8/qv8include.cpp
index 71937d0aad..1d68e8e4be 100644
--- a/src/declarative/qml/v8/qv8include.cpp
+++ b/src/declarative/qml/v8/qv8include.cpp
@@ -7,29 +7,29 @@
** This file is part of the QtDeclarative module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
+** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
**
**
**
diff --git a/src/declarative/qml/v8/qv8listwrapper.cpp b/src/declarative/qml/v8/qv8listwrapper.cpp
index 5f2d9fb91e..777ce78686 100644
--- a/src/declarative/qml/v8/qv8listwrapper.cpp
+++ b/src/declarative/qml/v8/qv8listwrapper.cpp
@@ -7,29 +7,29 @@
** This file is part of the QtDeclarative module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
+** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
**
**
**
@@ -135,7 +135,7 @@ v8::Handle<v8::Value> QV8ListWrapper::Getter(v8::Local<v8::String> property,
{
Q_UNUSED(property);
Q_UNUSED(info);
- return v8::Undefined();
+ return v8::Handle<v8::Value>();
}
v8::Handle<v8::Value> QV8ListWrapper::Setter(v8::Local<v8::String> property,
diff --git a/src/declarative/qml/v8/qv8listwrapper_p.h b/src/declarative/qml/v8/qv8listwrapper_p.h
index 82fdaa7271..8cbc7db0b8 100644
--- a/src/declarative/qml/v8/qv8listwrapper_p.h
+++ b/src/declarative/qml/v8/qv8listwrapper_p.h
@@ -7,29 +7,29 @@
** This file is part of the QtDeclarative module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
+** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
**
**
**
diff --git a/src/declarative/qml/v8/qv8qobjectwrapper.cpp b/src/declarative/qml/v8/qv8qobjectwrapper.cpp
index f97f427ede..c7ed0116e1 100644
--- a/src/declarative/qml/v8/qv8qobjectwrapper.cpp
+++ b/src/declarative/qml/v8/qv8qobjectwrapper.cpp
@@ -7,29 +7,29 @@
** This file is part of the QtDeclarative module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
+** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
**
**
**
@@ -336,7 +336,8 @@ static v8::Handle<v8::Value> LoadProperty(QV8Engine *engine, QObject *object,
void *args[] = { &handle, 0 };
QMetaObject::metacall(object, QMetaObject::ReadProperty, property.coreIndex, args);
return handle.toHandle();
- } else if (QDeclarativeValueTypeFactory::isValueType((uint)property.propType)) {
+ } else if (QDeclarativeValueTypeFactory::isValueType((uint)property.propType)
+ && engine->engine()) {
QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(engine->engine());
QDeclarativeValueType *valueType = ep->valueTypes[property.propType];
if (valueType)
@@ -381,7 +382,8 @@ static v8::Handle<v8::Value> LoadPropertyDirect(QV8Engine *engine, QObject *obje
void *args[] = { &handle, 0 };
object->qt_metacall(QMetaObject::ReadProperty, property.coreIndex, args);
return handle.toHandle();
- } else if (QDeclarativeValueTypeFactory::isValueType((uint)property.propType)) {
+ } else if (QDeclarativeValueTypeFactory::isValueType((uint)property.propType)
+ && engine->engine()) {
QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(engine->engine());
QDeclarativeValueType *valueType = ep->valueTypes[property.propType];
if (valueType)
@@ -600,7 +602,7 @@ v8::Handle<v8::Value> QV8QObjectWrapper::Getter(v8::Local<v8::String> property,
QV8QObjectResource *resource = v8_resource_check<QV8QObjectResource>(info.This());
if (resource->object.isNull())
- return v8::Undefined();
+ return v8::Handle<v8::Value>();
QObject *object = resource->object;
@@ -628,7 +630,7 @@ v8::Handle<v8::Value> QV8QObjectWrapper::Getter(v8::Local<v8::String> property,
}
}
- return v8::Undefined();
+ return v8::Handle<v8::Value>();
}
v8::Handle<v8::Value> QV8QObjectWrapper::Setter(v8::Local<v8::String> property,
diff --git a/src/declarative/qml/v8/qv8qobjectwrapper_p.h b/src/declarative/qml/v8/qv8qobjectwrapper_p.h
index dd787cc476..d0a489bed8 100644
--- a/src/declarative/qml/v8/qv8qobjectwrapper_p.h
+++ b/src/declarative/qml/v8/qv8qobjectwrapper_p.h
@@ -7,29 +7,29 @@
** This file is part of the QtDeclarative module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
+** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
**
**
**
diff --git a/src/declarative/qml/v8/qv8stringwrapper.cpp b/src/declarative/qml/v8/qv8stringwrapper.cpp
index 883c4826c5..1fea98fdc0 100644
--- a/src/declarative/qml/v8/qv8stringwrapper.cpp
+++ b/src/declarative/qml/v8/qv8stringwrapper.cpp
@@ -7,29 +7,29 @@
** This file is part of the QtDeclarative module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
+** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
**
**
**
@@ -40,6 +40,7 @@
****************************************************************************/
#include "qv8stringwrapper_p.h"
+#include "qjsconverter_p.h"
QT_BEGIN_NAMESPACE
@@ -73,7 +74,7 @@ void QV8StringWrapper::destroy()
v8::Local<v8::String> QV8StringWrapper::toString(const QString &qstr)
{
// return v8::String::NewExternal(new QV8StringResource(qstr));
- return v8::String::New((uint16_t*)qstr.constData(), qstr.length());
+ return QJSConverter::toString(qstr);
}
QString QV8StringWrapper::toString(v8::Handle<v8::String> jsstr)
@@ -84,10 +85,7 @@ QString QV8StringWrapper::toString(v8::Handle<v8::String> jsstr)
QV8StringResource *r = (QV8StringResource *)jsstr->GetExternalStringResource();
return r->str;
} else {
- QString qstr;
- qstr.resize(jsstr->Length());
- jsstr->Write((uint16_t*)qstr.data());
- return qstr;
+ return QJSConverter::toString(jsstr);
}
}
diff --git a/src/declarative/qml/v8/qv8stringwrapper_p.h b/src/declarative/qml/v8/qv8stringwrapper_p.h
index 36c9e24c06..beef80ff10 100644
--- a/src/declarative/qml/v8/qv8stringwrapper_p.h
+++ b/src/declarative/qml/v8/qv8stringwrapper_p.h
@@ -7,29 +7,29 @@
** This file is part of the QtDeclarative module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
+** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
**
**
**
diff --git a/src/declarative/qml/v8/qv8typewrapper.cpp b/src/declarative/qml/v8/qv8typewrapper.cpp
index fe30670fc2..c51a2eeb7f 100644
--- a/src/declarative/qml/v8/qv8typewrapper.cpp
+++ b/src/declarative/qml/v8/qv8typewrapper.cpp
@@ -7,29 +7,29 @@
** This file is part of the QtDeclarative module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
+** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
**
**
**
@@ -150,7 +150,7 @@ v8::Handle<v8::Value> QV8TypeWrapper::Getter(v8::Local<v8::String> property,
}
}
- // Fall through to undefined
+ // Fall through to return empty handle
} else if (resource->object) {
QObject *ao = qmlAttachedPropertiesObjectById(type->attachedPropertiesId(), object);
@@ -158,10 +158,10 @@ v8::Handle<v8::Value> QV8TypeWrapper::Getter(v8::Local<v8::String> property,
return v8engine->qobjectWrapper()->getProperty(ao, propertystring,
QV8QObjectWrapper::IgnoreRevision);
- // Fall through to undefined
+ // Fall through to return empty handle
}
- // Fall through to undefined
+ // Fall through to return empty handle
} else if (resource->typeNamespace) {
@@ -185,21 +185,19 @@ v8::Handle<v8::Value> QV8TypeWrapper::Getter(v8::Local<v8::String> property,
if (moduleApi->qobjectApi) {
v8::Handle<v8::Value> rv = v8engine->qobjectWrapper()->getProperty(moduleApi->qobjectApi, propertystring, QV8QObjectWrapper::IgnoreRevision);
- if (rv.IsEmpty())
- return v8::Undefined();
- else
- return rv;
+ return rv;
} else {
- return v8::Undefined();
+ return v8::Handle<v8::Value>();
}
}
- // Fall through to undefined
+ // Fall through to return empty handle
} else {
Q_ASSERT(!"Unreachable");
}
- return v8::Undefined();
+
+ return v8::Handle<v8::Value>();
}
v8::Handle<v8::Value> QV8TypeWrapper::Setter(v8::Local<v8::String> property,
diff --git a/src/declarative/qml/v8/qv8valuetypewrapper.cpp b/src/declarative/qml/v8/qv8valuetypewrapper.cpp
index f3100cf7b5..e459fee71f 100644
--- a/src/declarative/qml/v8/qv8valuetypewrapper.cpp
+++ b/src/declarative/qml/v8/qv8valuetypewrapper.cpp
@@ -7,29 +7,29 @@
** This file is part of the QtDeclarative module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
+** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
**
**
**
@@ -103,15 +103,21 @@ QV8ValueTypeWrapper::~QV8ValueTypeWrapper()
void QV8ValueTypeWrapper::destroy()
{
+ qPersistentDispose(m_toString);
qPersistentDispose(m_constructor);
}
void QV8ValueTypeWrapper::init(QV8Engine *engine)
{
m_engine = engine;
+ m_toString = qPersistentNew<v8::Function>(v8::FunctionTemplate::New(ToString)->GetFunction());
v8::Local<v8::FunctionTemplate> ft = v8::FunctionTemplate::New();
ft->InstanceTemplate()->SetNamedPropertyHandler(Getter, Setter);
ft->InstanceTemplate()->SetHasExternalResource(true);
+ ft->InstanceTemplate()->MarkAsUseUserObjectComparison();
+ ft->InstanceTemplate()->SetAccessor(v8::String::New("toString"), ToStringGetter, 0,
+ m_toString, v8::DEFAULT,
+ v8::PropertyAttribute(v8::ReadOnly | v8::DontDelete));
m_constructor = qPersistentNew<v8::Function>(ft->GetFunction());
}
@@ -166,26 +172,85 @@ QVariant QV8ValueTypeWrapper::toVariant(QV8ObjectResource *r)
}
}
+bool QV8ValueTypeWrapper::isEqual(QV8ObjectResource *r, const QVariant& value)
+{
+ Q_ASSERT(r->resourceType() == QV8ObjectResource::ValueTypeType);
+ QV8ValueTypeResource *resource = static_cast<QV8ValueTypeResource *>(r);
+
+ if (resource->objectType == QV8ValueTypeResource::Reference) {
+ QV8ValueTypeReferenceResource *reference = static_cast<QV8ValueTypeReferenceResource *>(resource);
+ if (reference->object) {
+ reference->type->read(reference->object, reference->property);
+ return reference->type->isEqual(value);
+ } else {
+ return false;
+ }
+ } else {
+ Q_ASSERT(resource->objectType == QV8ValueTypeResource::Copy);
+ QV8ValueTypeCopyResource *copy = static_cast<QV8ValueTypeCopyResource *>(resource);
+ return (value == copy->value);
+ }
+}
+
+v8::Handle<v8::Value> QV8ValueTypeWrapper::ToStringGetter(v8::Local<v8::String> property,
+ const v8::AccessorInfo &info)
+{
+ Q_UNUSED(property);
+ return info.Data();
+}
+
+v8::Handle<v8::Value> QV8ValueTypeWrapper::ToString(const v8::Arguments &args)
+{
+ QV8ValueTypeResource *resource = v8_resource_cast<QV8ValueTypeResource>(args.This());
+ if (resource) {
+ if (resource->objectType == QV8ValueTypeResource::Reference) {
+ QV8ValueTypeReferenceResource *reference = static_cast<QV8ValueTypeReferenceResource *>(resource);
+ if (reference->object) {
+ reference->type->read(reference->object, reference->property);
+ return resource->engine->toString(resource->type->toString());
+ } else {
+ return v8::Undefined();
+ }
+ } else {
+ Q_ASSERT(resource->objectType == QV8ValueTypeResource::Copy);
+ QV8ValueTypeCopyResource *copy = static_cast<QV8ValueTypeCopyResource *>(resource);
+ QString result = copy->value.toString();
+ if (result.isEmpty() && !copy->value.canConvert(QVariant::String)) {
+ result = QString::fromLatin1("QVariant(%0)").arg(QString::fromLatin1(copy->value.typeName()));
+ }
+ return resource->engine->toString(result);
+ }
+ } else {
+ return v8::Undefined();
+ }
+}
+
v8::Handle<v8::Value> QV8ValueTypeWrapper::Getter(v8::Local<v8::String> property,
const v8::AccessorInfo &info)
{
QV8ValueTypeResource *r = v8_resource_cast<QV8ValueTypeResource>(info.This());
- if (!r) return v8::Undefined();
+ if (!r) return v8::Handle<v8::Value>();
// XXX This is horribly inefficient. Sadly people seem to have taken a liking to
// value type properties, so we should probably try and optimize it a little.
// We should probably just replace all value properties with dedicated accessors.
QByteArray propName = r->engine->toString(property).toUtf8();
+ if (propName == QByteArray("toString")) {
+ return r->engine->valueTypeWrapper()->m_toString;
+ }
+
int index = r->type->metaObject()->indexOfProperty(propName.constData());
if (index == -1)
- return v8::Undefined();
+ return v8::Handle<v8::Value>();
+
if (r->objectType == QV8ValueTypeResource::Reference) {
QV8ValueTypeReferenceResource *reference = static_cast<QV8ValueTypeReferenceResource *>(r);
if (!reference->object)
- return v8::Undefined();
+ return v8::Handle<v8::Value>();
+
r->type->read(reference->object, reference->property);
} else {
diff --git a/src/declarative/qml/v8/qv8valuetypewrapper_p.h b/src/declarative/qml/v8/qv8valuetypewrapper_p.h
index d08d89392c..2582560c0f 100644
--- a/src/declarative/qml/v8/qv8valuetypewrapper_p.h
+++ b/src/declarative/qml/v8/qv8valuetypewrapper_p.h
@@ -77,7 +77,12 @@ public:
QVariant toVariant(v8::Handle<v8::Object>);
QVariant toVariant(QV8ObjectResource *);
+ static bool isEqual(QV8ObjectResource *, const QVariant& value);
+
private:
+ static v8::Handle<v8::Value> ToStringGetter(v8::Local<v8::String> property,
+ const v8::AccessorInfo &info);
+ static v8::Handle<v8::Value> ToString(const v8::Arguments &args);
static v8::Handle<v8::Value> Getter(v8::Local<v8::String> property,
const v8::AccessorInfo &info);
static v8::Handle<v8::Value> Setter(v8::Local<v8::String> property,
@@ -86,6 +91,7 @@ private:
QV8Engine *m_engine;
v8::Persistent<v8::Function> m_constructor;
+ v8::Persistent<v8::Function> m_toString;
};
QT_END_NAMESPACE
diff --git a/src/declarative/qml/v8/qv8variantwrapper.cpp b/src/declarative/qml/v8/qv8variantwrapper.cpp
index d4097d7f74..de4f0ce2d7 100644
--- a/src/declarative/qml/v8/qv8variantwrapper.cpp
+++ b/src/declarative/qml/v8/qv8variantwrapper.cpp
@@ -7,29 +7,29 @@
** This file is part of the QtDeclarative module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
+** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
**
**
**
@@ -159,17 +159,24 @@ QVariant QV8VariantWrapper::toVariant(QV8ObjectResource *r)
return static_cast<QV8VariantResource *>(r)->data;
}
-v8::Handle<v8::Value> QV8VariantWrapper::Getter(v8::Local<v8::String> property,
+QVariant &QV8VariantWrapper::variantValue(v8::Handle<v8::Value> value)
+{
+ Q_ASSERT(isVariant(value));
+ QV8VariantResource *r = v8_resource_cast<QV8VariantResource>(value->ToObject());
+ return static_cast<QV8VariantResource *>(r)->data;
+}
+
+v8::Handle<v8::Value> QV8VariantWrapper::Getter(v8::Local<v8::String> property,
const v8::AccessorInfo &info)
{
- return v8::Undefined();
+ return v8::Handle<v8::Value>();
}
v8::Handle<v8::Value> QV8VariantWrapper::Setter(v8::Local<v8::String> property,
v8::Local<v8::Value> value,
const v8::AccessorInfo &info)
{
- return v8::Undefined();
+ return value;
}
v8::Handle<v8::Value> QV8VariantWrapper::PreserveGetter(v8::Local<v8::String> property,
diff --git a/src/declarative/qml/v8/qv8variantwrapper_p.h b/src/declarative/qml/v8/qv8variantwrapper_p.h
index de74bc9e12..7e9924b3c0 100644
--- a/src/declarative/qml/v8/qv8variantwrapper_p.h
+++ b/src/declarative/qml/v8/qv8variantwrapper_p.h
@@ -74,6 +74,7 @@ public:
bool isVariant(v8::Handle<v8::Value>);
QVariant toVariant(v8::Handle<v8::Object>);
QVariant toVariant(QV8ObjectResource *);
+ QVariant &variantValue(v8::Handle<v8::Value>);
private:
static v8::Handle<v8::Value> Getter(v8::Local<v8::String> property,
diff --git a/src/declarative/qml/v8/qv8worker.cpp b/src/declarative/qml/v8/qv8worker.cpp
index 0d396d3304..d6998849e2 100644
--- a/src/declarative/qml/v8/qv8worker.cpp
+++ b/src/declarative/qml/v8/qv8worker.cpp
@@ -7,29 +7,29 @@
** This file is part of the QtDeclarative module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
+** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
**
**
**
diff --git a/src/declarative/qml/v8/qv8worker_p.h b/src/declarative/qml/v8/qv8worker_p.h
index 086e18e7e0..20a295a51c 100644
--- a/src/declarative/qml/v8/qv8worker_p.h
+++ b/src/declarative/qml/v8/qv8worker_p.h
@@ -7,29 +7,29 @@
** This file is part of the QtDeclarative module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
+** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
**
**
**
diff --git a/src/declarative/qml/v8/script.pri b/src/declarative/qml/v8/script.pri
index 04a23d1f2b..7454d2004c 100644
--- a/src/declarative/qml/v8/script.pri
+++ b/src/declarative/qml/v8/script.pri
@@ -17,4 +17,6 @@ HEADERS += \
$$PWD/qscriptshareddata_p.h \
$$PWD/qscripttools_p.h \
$$PWD/qscript_impl_p.h \
- $$PWD/qscriptoriginalglobalobject_p.h
+ $$PWD/qscriptoriginalglobalobject_p.h \
+ $$PWD/qjsvalueiterator_p.h \
+ $$PWD/qjsvalueiterator_impl_p.h
diff --git a/src/declarative/qml/v8/v8.pri b/src/declarative/qml/v8/v8.pri
index 97b3d679df..9349742c78 100644
--- a/src/declarative/qml/v8/v8.pri
+++ b/src/declarative/qml/v8/v8.pri
@@ -5,6 +5,7 @@ include(script.pri)
HEADERS += \
$$PWD/qv8_p.h \
+ $$PWD/qv8debug_p.h \
$$PWD/qv8stringwrapper_p.h \
$$PWD/qv8engine_p.h \
$$PWD/qhashedstring_p.h \
@@ -18,7 +19,8 @@ HEADERS += \
$$PWD/qv8worker_p.h \
$$PWD/qv8bindings_p.h \
$$PWD/../../../3rdparty/javascriptcore/DateMath.h \
- $$PWD/qv8engine_impl_p.h
+ $$PWD/qv8engine_impl_p.h \
+ $$PWD/qv8domerrors_p.h
SOURCES += \
$$PWD/qv8stringwrapper.cpp \
@@ -34,3 +36,4 @@ SOURCES += \
$$PWD/qv8worker.cpp \
$$PWD/qv8bindings.cpp \
$$PWD/../../../3rdparty/javascriptcore/DateMath.cpp \
+ $$PWD/qv8domerrors.cpp