QString description;
quint16 line;
quint16 column;
+ QObject *object;
};
QQmlErrorPrivate::QQmlErrorPrivate()
-: line(0), column(0)
+: line(0), column(0), object()
{
}
d->description = other.d->description;
d->line = other.d->line;
d->column = other.d->column;
+ d->object = other.d->object;
}
return *this;
}
}
/*!
+ Returns the nearest object where this error occurred.
+ Exceptions in bound property expressions set this to the object
+ to which the property belongs. It will be 0 for all
+ other exceptions.
+ */
+QObject *QQmlError::object() const
+{
+ if (d) return d->object;
+ else return 0;
+}
+
+/*!
+ Sets the nearest \a object where this error occurred.
+ */
+void QQmlError::setObject(QObject *object)
+{
+ if (!d) d = new QQmlErrorPrivate;
+ d->object = object;
+}
+
+/*!
Returns the error as a human readable string.
*/
QString QQmlError::toString() const
void setLine(int);
int column() const;
void setColumn(int);
+ QObject *object() const;
+ void setObject(QObject *);
QString toString() const;
private:
m_error.setDescription(description);
}
+void QQmlDelayedError::setErrorObject(QObject *object)
+{
+ m_error.setObject(object);
+}
+
/*
Converting from a message to an error is relatively expensive.
error.setDescription(QLatin1String("Exception occurred during function compilation"));
error.setLine(line);
error.setUrl(QUrl::fromLocalFile(filename));
+ error.setObject(scope);
v8::Local<v8::Message> message = tc.Message();
if (!message.IsEmpty())
QQmlExpressionPrivate::exceptionToError(message, error);
error.setDescription(QLatin1String("Exception occurred during function evaluation"));
error.setLine(line);
error.setUrl(QUrl::fromLocalFile(filename));
+ error.setObject(scope);
v8::Local<v8::Message> message = tc.Message();
if (!message.IsEmpty())
QQmlExpressionPrivate::exceptionToError(message, error);
error.setDescription(QLatin1String("Exception occurred during function compilation"));
error.setLine(line);
error.setUrl(QUrl::fromLocalFile(filename));
+ error.setObject(scope);
v8::Local<v8::Message> message = tc.Message();
if (!message.IsEmpty())
QQmlExpressionPrivate::exceptionToError(message, error);
error.setDescription(QLatin1String("Exception occurred during function evaluation"));
error.setLine(line);
error.setUrl(QUrl::fromLocalFile(filename));
+ error.setObject(scope);
v8::Local<v8::Message> message = tc.Message();
if (!message.IsEmpty())
QQmlExpressionPrivate::exceptionToError(message, error);
void setMessage(v8::Handle<v8::Message> message);
void setErrorLocation(const QUrl &url, quint16 line, quint16 column);
void setErrorDescription(const QString &description);
+ void setErrorObject(QObject *object);
private:
void convertMessageToError(QQmlEngine *engine) const;
// we explicitly disallow this case to avoid confusion. Users can still store one
// in an array in a var property if they need to, but the common case is user error.
expression->delayedError()->setErrorDescription(QLatin1String("Invalid use of Qt.binding() in a binding declaration."));
+ expression->delayedError()->setErrorObject(object);
return false;
}
if (!result.IsEmpty() && result->IsFunction()
&& !result->ToObject()->GetHiddenValue(v8engine->bindingFlagKey()).IsEmpty()) {
expression->delayedError()->setErrorDescription(QLatin1String("Invalid use of Qt.binding() in a binding declaration."));
+ expression->delayedError()->setErrorObject(object);
return false;
}
writeValueProperty(object, core, QVariant::fromValue(v8engine->scriptValueFromInternal(result)), context, flags);
else
errorStr += QLatin1String(QMetaType::typeName(type));
expression->delayedError()->setErrorDescription(errorStr);
+ expression->delayedError()->setErrorObject(object);
return false;
} else if (result->IsFunction()) {
if (!result->ToObject()->GetHiddenValue(v8engine->bindingFlagKey()).IsEmpty())
expression->delayedError()->setErrorDescription(QLatin1String("Invalid use of Qt.binding() in a binding declaration."));
else
expression->delayedError()->setErrorDescription(QLatin1String("Unable to assign a function to a property of any type other than var."));
+ expression->delayedError()->setErrorObject(object);
return false;
} else if (!writeValueProperty(object, core, value, context, flags)) {
QLatin1String(valueType) +
QLatin1String(" to ") +
QLatin1String(propertyType));
+ expression->delayedError()->setErrorObject(object);
return false;
}
error->setErrorDescription(QLatin1String("TypeError: Result of expression is not an object"));
else
error->setErrorDescription(description);
+ error->setErrorObject(context->contextObject);
if (id != 0xFF) {
quint32 e = *((quint32 *)(program->data() + program->exceptionDataOffset) + id);
error->setErrorLocation(context->url, (e >> 16), (e & 0xFFFF));
delayedError()->setErrorLocation(parent->url(), instruction->line, 0);
if (hasError()) {
+ delayedError()->setErrorObject(object());
if (!delayedError()->addError(ep)) ep->warning(this->error(context->engine));
} else {
clearError();