aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/qml/v8
diff options
context:
space:
mode:
Diffstat (limited to 'src/qml/qml/v8')
-rw-r--r--src/qml/qml/v8/qjsengine.cpp2
-rw-r--r--src/qml/qml/v8/qjsvalue.cpp44
-rw-r--r--src/qml/qml/v8/qqmlbuiltinfunctions.cpp107
-rw-r--r--src/qml/qml/v8/qv8bindings.cpp6
-rw-r--r--src/qml/qml/v8/qv8contextwrapper.cpp18
-rw-r--r--src/qml/qml/v8/qv8qobjectwrapper.cpp21
-rw-r--r--src/qml/qml/v8/qv8valuetypewrapper.cpp4
7 files changed, 108 insertions, 94 deletions
diff --git a/src/qml/qml/v8/qjsengine.cpp b/src/qml/qml/v8/qjsengine.cpp
index 3121d1b361..92c968f9aa 100644
--- a/src/qml/qml/v8/qjsengine.cpp
+++ b/src/qml/qml/v8/qjsengine.cpp
@@ -92,7 +92,7 @@ Q_DECLARE_METATYPE(QList<int>)
\section1 Engine Configuration
- The globalObject() function returns the \bold {Global Object}
+ The globalObject() function returns the \b {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
diff --git a/src/qml/qml/v8/qjsvalue.cpp b/src/qml/qml/v8/qjsvalue.cpp
index e0a925c3bb..4471e68a61 100644
--- a/src/qml/qml/v8/qjsvalue.cpp
+++ b/src/qml/qml/v8/qjsvalue.cpp
@@ -426,18 +426,18 @@ quint32 QJSValue::toUInt() const
The conversion is performed according to the following table:
\table
- \header \o Input Type \o Result
- \row \o Undefined \o An invalid QVariant.
- \row \o Null \o An invalid QVariant.
- \row \o Boolean \o A QVariant containing the value of the boolean.
- \row \o Number \o A QVariant containing the value of the number.
- \row \o String \o A QVariant containing the value of the string.
- \row \o QVariant Object \o The result is the QVariant value of the object (no conversion).
- \row \o QObject Object \o A QVariant containing a pointer to the QObject.
- \row \o Date Object \o A QVariant containing the date value (toDateTime()).
- \row \o RegExp Object \o A QVariant containing the regular expression value.
- \row \o Array Object \o The array is converted to a QVariantList. Each element is converted to a QVariant, recursively; cyclic references are not followed.
- \row \o Object \o The object is converted to a QVariantMap. Each property is converted to a QVariant, recursively; cyclic references are not followed.
+ \header \li Input Type \li Result
+ \row \li Undefined \li An invalid QVariant.
+ \row \li Null \li An invalid QVariant.
+ \row \li Boolean \li A QVariant containing the value of the boolean.
+ \row \li Number \li A QVariant containing the value of the number.
+ \row \li String \li A QVariant containing the value of the string.
+ \row \li QVariant Object \li The result is the QVariant value of the object (no conversion).
+ \row \li QObject Object \li A QVariant containing a pointer to the QObject.
+ \row \li Date Object \li A QVariant containing the date value (toDateTime()).
+ \row \li RegExp Object \li A QVariant containing the regular expression value.
+ \row \li Array Object \li The array is converted to a QVariantList. Each element is converted to a QVariant, recursively; cyclic references are not followed.
+ \row \li Object \li The object is converted to a QVariantMap. Each property is converted to a QVariant, recursively; cyclic references are not followed.
\endtable
\sa isVariant()
@@ -634,13 +634,13 @@ bool QJSValue::equals(const QJSValue& other) const
the result depends on the type, as shown in the following table:
\table
- \header \o Type \o Result
- \row \o Undefined \o true
- \row \o Null \o true
- \row \o Boolean \o true if both values are true, false otherwise
- \row \o Number \o false if either value is NaN (Not-a-Number); true if values are equal, false otherwise
- \row \o String \o true if both values are exactly the same sequence of characters, false otherwise
- \row \o Object \o true if both values refer to the same object, false otherwise
+ \header \li Type \li Result
+ \row \li Undefined \li true
+ \row \li Null \li true
+ \row \li Boolean \li true if both values are true, false otherwise
+ \row \li Number \li false if either value is NaN (Not-a-Number); true if values are equal, false otherwise
+ \row \li String \li true if both values are exactly the same sequence of characters, false otherwise
+ \row \li Object \li true if both values refer to the same object, false otherwise
\endtable
\sa equals()
@@ -737,11 +737,11 @@ void QJSValue::setProperty(quint32 arrayIndex, const QJSValue& value)
delete operator. In particular:
\list
- \o Non-configurable properties cannot be deleted.
- \o This function will return true even if this object doesn't
+ \li Non-configurable properties cannot be deleted.
+ \li This function will return true even if this object doesn't
have a property of the given \a name (i.e., non-existent
properties are "trivially deletable").
- \o If this object doesn't have an own property of the given
+ \li If this object doesn't have an own property of the given
\a name, but an object in the prototype() chain does, the
prototype object's property is not deleted, and this function
returns true.
diff --git a/src/qml/qml/v8/qqmlbuiltinfunctions.cpp b/src/qml/qml/v8/qqmlbuiltinfunctions.cpp
index 143ccee960..68c62ef240 100644
--- a/src/qml/qml/v8/qqmlbuiltinfunctions.cpp
+++ b/src/qml/qml/v8/qqmlbuiltinfunctions.cpp
@@ -797,54 +797,54 @@ If \a format is not provided, \a dateTime is formatted using
\a format should be either:
\list
-\o One of the Qt::DateFormat enumeration values, such as
+\li One of the Qt::DateFormat enumeration values, such as
\c Qt.DefaultLocaleShortDate or \c Qt.ISODate
-\o A string that specifies the format of the returned string, as detailed below.
+\li A string that specifies the format of the returned string, as detailed below.
\endlist
If \a format specifies a format string, it should use the following expressions
to specify the date:
\table
- \header \i Expression \i Output
- \row \i d \i the day as number without a leading zero (1 to 31)
- \row \i dd \i the day as number with a leading zero (01 to 31)
- \row \i ddd
- \i the abbreviated localized day name (e.g. 'Mon' to 'Sun').
+ \header \li Expression \li Output
+ \row \li d \li the day as number without a leading zero (1 to 31)
+ \row \li dd \li the day as number with a leading zero (01 to 31)
+ \row \li ddd
+ \li the abbreviated localized day name (e.g. 'Mon' to 'Sun').
Uses QDate::shortDayName().
- \row \i dddd
- \i the long localized day name (e.g. 'Monday' to 'Qt::Sunday').
+ \row \li dddd
+ \li the long localized day name (e.g. 'Monday' to 'Qt::Sunday').
Uses QDate::longDayName().
- \row \i M \i the month as number without a leading zero (1-12)
- \row \i MM \i the month as number with a leading zero (01-12)
- \row \i MMM
- \i the abbreviated localized month name (e.g. 'Jan' to 'Dec').
+ \row \li M \li the month as number without a leading zero (1-12)
+ \row \li MM \li the month as number with a leading zero (01-12)
+ \row \li MMM
+ \li the abbreviated localized month name (e.g. 'Jan' to 'Dec').
Uses QDate::shortMonthName().
- \row \i MMMM
- \i the long localized month name (e.g. 'January' to 'December').
+ \row \li MMMM
+ \li the long localized month name (e.g. 'January' to 'December').
Uses QDate::longMonthName().
- \row \i yy \i the year as two digit number (00-99)
- \row \i yyyy \i the year as four digit number
+ \row \li yy \li the year as two digit number (00-99)
+ \row \li yyyy \li the year as four digit number
\endtable
In addition the following expressions can be used to specify the time:
\table
- \header \i Expression \i Output
- \row \i h
- \i the hour without a leading zero (0 to 23 or 1 to 12 if AM/PM display)
- \row \i hh
- \i the hour with a leading zero (00 to 23 or 01 to 12 if AM/PM display)
- \row \i m \i the minute without a leading zero (0 to 59)
- \row \i mm \i the minute with a leading zero (00 to 59)
- \row \i s \i the second without a leading zero (0 to 59)
- \row \i ss \i the second with a leading zero (00 to 59)
- \row \i z \i the milliseconds without leading zeroes (0 to 999)
- \row \i zzz \i the milliseconds with leading zeroes (000 to 999)
- \row \i AP
- \i use AM/PM display. \e AP will be replaced by either "AM" or "PM".
- \row \i ap
- \i use am/pm display. \e ap will be replaced by either "am" or "pm".
+ \header \li Expression \li Output
+ \row \li h
+ \li the hour without a leading zero (0 to 23 or 1 to 12 if AM/PM display)
+ \row \li hh
+ \li the hour with a leading zero (00 to 23 or 01 to 12 if AM/PM display)
+ \row \li m \li the minute without a leading zero (0 to 59)
+ \row \li mm \li the minute with a leading zero (00 to 59)
+ \row \li s \li the second without a leading zero (0 to 59)
+ \row \li ss \li the second with a leading zero (00 to 59)
+ \row \li z \li the milliseconds without leading zeroes (0 to 999)
+ \row \li zzz \li the milliseconds with leading zeroes (000 to 999)
+ \row \li AP
+ \li use AM/PM display. \e AP will be replaced by either "AM" or "PM".
+ \row \li ap
+ \li use am/pm display. \e ap will be replaced by either "am" or "pm".
\endtable
All other input characters will be ignored. Any sequence of characters that
@@ -864,11 +864,11 @@ This \a dateTime value could be passed to \c Qt.formatDateTime(),
with the \a format values below to produce the following results:
\table
- \header \i Format \i Result
- \row \i "dd.MM.yyyy" \i 21.05.2001
- \row \i "ddd MMMM d yy" \i Tue May 21 01
- \row \i "hh:mm:ss.zzz" \i 14:13:09.042
- \row \i "h:m:s ap" \i 2:13:9 pm
+ \header \li Format \li Result
+ \row \li "dd.MM.yyyy" \li 21.05.2001
+ \row \li "ddd MMMM d yy" \li Tue May 21 01
+ \row \li "hh:mm:ss.zzz" \li 14:13:09.042
+ \row \li "h:m:s ap" \li 2:13:9 pm
\endtable
\sa Locale
@@ -1120,7 +1120,7 @@ v8::Handle<v8::Value> createQmlObject(const v8::Arguments &args)
}
/*!
-\qmlmethod object Qt::createComponent(url)
+\qmlmethod object Qt::createComponent(url, mode)
Returns a \l Component object created using the QML file at the specified \a url,
or \c null if an empty string was given.
@@ -1129,6 +1129,12 @@ The returned component's \l Component::status property indicates whether the
component was successfully created. If the status is \c Component.Error,
see \l Component::errorString() for an error description.
+If the optional \a mode parameter is set to \c Component.Asynchronous, the
+component will be loaded in a background thread. The Component::status property
+will be \c Component.Loading while it is loading. The status will change to
+\c Component.Ready if the component loads successfully, or \c Component.Error
+if loading fails.
+
Call \l {Component::createObject()}{Component.createObject()} on the returned
component to create an object instance of the component.
@@ -1143,8 +1149,9 @@ use \l{QML:Qt::createQmlObject()}{Qt.createQmlObject()}.
*/
v8::Handle<v8::Value> createComponent(const v8::Arguments &args)
{
- if (args.Length() != 1)
- V8THROW_ERROR("Qt.createComponent(): Invalid arguments");
+ const char *invalidArgs = "Qt.createComponent(): Invalid arguments";
+ if (args.Length() < 1 || args.Length() > 2)
+ V8THROW_ERROR(invalidArgs);
QV8Engine *v8engine = V8ENGINE();
QQmlEngine *engine = v8engine->engine();
@@ -1159,8 +1166,20 @@ v8::Handle<v8::Value> createComponent(const v8::Arguments &args)
if (arg.isEmpty())
return v8::Null();
+ QQmlComponent::CompilationMode compileMode = QQmlComponent::PreferSynchronous;
+ if (args.Length() == 2) {
+ if (args[1]->IsInt32()) {
+ int mode = args[1]->Int32Value();
+ if (mode != int(QQmlComponent::PreferSynchronous) && mode != int(QQmlComponent::Asynchronous))
+ V8THROW_ERROR(invalidArgs);
+ compileMode = QQmlComponent::CompilationMode(mode);
+ } else {
+ V8THROW_ERROR(invalidArgs);
+ }
+ }
+
QUrl url = context->resolvedUrl(QUrl(arg));
- QQmlComponent *c = new QQmlComponent(engine, url, engine);
+ QQmlComponent *c = new QQmlComponent(engine, url, compileMode, engine);
QQmlComponentPrivate::get(c)->creationContext = effectiveContext;
QQmlData::get(c, true)->setImplicitDestructible();
return v8engine->newQObject(c);
@@ -1287,9 +1306,9 @@ v8::Handle<v8::Value> qsTrIdNoOp(const v8::Arguments &args)
or "C", where:
\list
- \o language is a lowercase, two-letter, ISO 639 language code,
- \o territory is an uppercase, two-letter, ISO 3166 country code,
- \o and codeset and modifier are ignored.
+ \li language is a lowercase, two-letter, ISO 639 language code,
+ \li territory is an uppercase, two-letter, ISO 3166 country code,
+ \li and codeset and modifier are ignored.
\endlist
If the string violates the locale format, or language is not a
diff --git a/src/qml/qml/v8/qv8bindings.cpp b/src/qml/qml/v8/qv8bindings.cpp
index 76fbea137e..4b96679cf3 100644
--- a/src/qml/qml/v8/qv8bindings.cpp
+++ b/src/qml/qml/v8/qv8bindings.cpp
@@ -45,7 +45,6 @@
#include <private/qqmlbinding_p.h>
#include <private/qqmlcompiler_p.h>
#include <private/qqmlproperty_p.h>
-#include <private/qqmlbinding_p_p.h>
#include <private/qqmlexpression_p.h>
#include <private/qobject_p.h>
#include <private/qqmltrace_p.h>
@@ -157,9 +156,8 @@ void QV8Bindings::Binding::update(QQmlPropertyPrivate::WriteFlags flags)
ep->dereferenceScarceResources();
} else {
- QQmlProperty p = QQmlPropertyPrivate::restore(target, instruction->property,
- context);
- QQmlBindingPrivate::printBindingLoopError(p);
+ QQmlProperty p = QQmlPropertyPrivate::restore(target, instruction->property, context);
+ QQmlAbstractBinding::printBindingLoopError(p);
}
}
diff --git a/src/qml/qml/v8/qv8contextwrapper.cpp b/src/qml/qml/v8/qv8contextwrapper.cpp
index 246b716aa0..39392b8984 100644
--- a/src/qml/qml/v8/qv8contextwrapper.cpp
+++ b/src/qml/qml/v8/qv8contextwrapper.cpp
@@ -238,16 +238,11 @@ QQmlContextData *QV8ContextWrapper::context(v8::Handle<v8::Value> value)
return r?r->getContext():0;
}
-v8::Handle<v8::Value> QV8ContextWrapper::NullGetter(v8::Local<v8::String> property,
- const v8::AccessorInfo &info)
+v8::Handle<v8::Value> QV8ContextWrapper::NullGetter(v8::Local<v8::String>,
+ const v8::AccessorInfo &)
{
- QV8ContextResource *resource = v8_resource_check<QV8ContextResource>(info.This());
-
- QV8Engine *engine = resource->engine;
-
- QString error = QLatin1String("Can't find variable: ") + engine->toString(property);
- v8::ThrowException(v8::Exception::ReferenceError(engine->toString(error)));
- return v8::Undefined();
+ // V8 will throw a ReferenceError if appropriate ("typeof" should not throw)
+ return v8::Handle<v8::Value>();
}
v8::Handle<v8::Value> QV8ContextWrapper::Getter(v8::Local<v8::String> property,
@@ -365,9 +360,8 @@ v8::Handle<v8::Value> QV8ContextWrapper::Getter(v8::Local<v8::String> property,
expressionContext->unresolvedNames = true;
- QString error = QLatin1String("Can't find variable: ") + engine->toString(property);
- v8::ThrowException(v8::Exception::ReferenceError(engine->toString(error)));
- return v8::Undefined();
+ // V8 will throw a ReferenceError if appropriate ("typeof" should not throw)
+ return v8::Handle<v8::Value>();
}
v8::Handle<v8::Value> QV8ContextWrapper::NullSetter(v8::Local<v8::String> property,
diff --git a/src/qml/qml/v8/qv8qobjectwrapper.cpp b/src/qml/qml/v8/qv8qobjectwrapper.cpp
index 61cfa242c9..2350b9dc2c 100644
--- a/src/qml/qml/v8/qv8qobjectwrapper.cpp
+++ b/src/qml/qml/v8/qv8qobjectwrapper.cpp
@@ -599,11 +599,10 @@ static inline void StoreProperty(QV8Engine *engine, QObject *object, QQmlPropert
v8::StackTrace::kScriptName));
v8::Local<v8::StackFrame> frame = trace->GetFrame(0);
int lineNumber = frame->GetLineNumber();
- int columNumber = frame->GetColumn();
+ int columnNumber = frame->GetColumn();
QString url = engine->toString(frame->GetScriptName());
- newBinding = new QQmlBinding(&function, object, context);
- newBinding->setSourceLocation(url, lineNumber, columNumber);
+ newBinding = new QQmlBinding(&function, object, context, url, lineNumber, columnNumber);
newBinding->setTarget(object, *property, context);
newBinding->setEvaluateFlags(newBinding->evaluateFlags() |
QQmlBinding::RequiresThisObject);
@@ -619,11 +618,10 @@ static inline void StoreProperty(QV8Engine *engine, QObject *object, QQmlPropert
v8::StackTrace::kScriptName));
v8::Local<v8::StackFrame> frame = trace->GetFrame(0);
int lineNumber = frame->GetLineNumber();
- int columNumber = frame->GetColumn();
+ int columnNumber = frame->GetColumn();
QString url = engine->toString(frame->GetScriptName());
- newBinding = new QQmlBinding(&function, object, context);
- newBinding->setSourceLocation(url, lineNumber, columNumber);
+ newBinding = new QQmlBinding(&function, object, context, url, lineNumber, columnNumber);
newBinding->setTarget(object, *property, context);
newBinding->setEvaluateFlags(newBinding->evaluateFlags() |
QQmlBinding::RequiresThisObject);
@@ -925,8 +923,10 @@ static void WeakQObjectReferenceCallback(v8::Persistent<v8::Value> handle, void
QQmlData *ddata = QQmlData::get(object, false);
if (ddata) {
ddata->v8object.Clear();
- if (!object->parent() && !ddata->indestructible)
+ if (!object->parent() && !ddata->indestructible) {
+ ddata->isQueuedForDeletion = true;
object->deleteLater();
+ }
}
}
@@ -1084,13 +1084,16 @@ v8::Handle<v8::Value> QV8QObjectWrapper::newQObject(QObject *object)
return v8::Null();
if (QObjectPrivate::get(object)->wasDeleted)
- return v8::Undefined();
-
+ return v8::Null();
+
QQmlData *ddata = QQmlData::get(object, true);
if (!ddata)
return v8::Undefined();
+ if (ddata->isQueuedForDeletion)
+ return v8::Null();
+
if (ddata->v8objectid == m_id && !ddata->v8object.IsEmpty()) {
// We own the v8object
return v8::Local<v8::Object>::New(ddata->v8object);
diff --git a/src/qml/qml/v8/qv8valuetypewrapper.cpp b/src/qml/qml/v8/qv8valuetypewrapper.cpp
index d54f04a9b0..cf2c13fce9 100644
--- a/src/qml/qml/v8/qv8valuetypewrapper.cpp
+++ b/src/qml/qml/v8/qv8valuetypewrapper.cpp
@@ -352,8 +352,8 @@ v8::Handle<v8::Value> QV8ValueTypeWrapper::Setter(v8::Local<v8::String> property
int columnNumber = frame->GetColumn();
QString url = r->engine->toString(frame->GetScriptName());
- newBinding = new QQmlBinding(&function, reference->object, context);
- newBinding->setSourceLocation(url, lineNumber, columnNumber);
+ newBinding = new QQmlBinding(&function, reference->object, context,
+ url, lineNumber, columnNumber);
newBinding->setTarget(reference->object, cacheData, context);
newBinding->setEvaluateFlags(newBinding->evaluateFlags() |
QQmlBinding::RequiresThisObject);