aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@digia.com>2013-09-13 21:54:21 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-09-18 13:14:10 +0200
commite4e90923c93adfafb23c81be7359e8df2a500b4f (patch)
tree36be927b72606c4f37326089ff3c6261f484c92b /src/qml
parent9dcc12d52343960400192c817f54a16f7e1f8247 (diff)
Convert some methods to use Returned<>
Change-Id: I631606cb5ab3b35b72104e70092a5200dd235fbc Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'src/qml')
-rw-r--r--src/qml/jsruntime/qv4context.cpp71
-rw-r--r--src/qml/jsruntime/qv4context_p.h5
-rw-r--r--src/qml/jsruntime/qv4engine.cpp18
-rw-r--r--src/qml/jsruntime/qv4engine_p.h8
-rw-r--r--src/qml/jsruntime/qv4errorobject.cpp2
-rw-r--r--src/qml/jsruntime/qv4lookup.cpp4
-rw-r--r--src/qml/jsruntime/qv4runtime.cpp2
-rw-r--r--src/qml/jsruntime/qv4scopedvalue_p.h9
-rw-r--r--src/qml/jsruntime/qv4script.cpp7
-rw-r--r--src/qml/jsruntime/qv4string.cpp6
-rw-r--r--src/qml/jsruntime/qv4stringobject.cpp2
-rw-r--r--src/qml/qml/qqmlcontextwrapper.cpp6
-rw-r--r--src/qml/qml/qqmlvaluetypewrapper.cpp10
-rw-r--r--src/qml/qml/qqmlxmlhttprequest.cpp27
-rw-r--r--src/qml/qml/v8/qqmlbuiltinfunctions.cpp23
-rw-r--r--src/qml/qml/v8/qv4domerrors_p.h6
16 files changed, 135 insertions, 71 deletions
diff --git a/src/qml/jsruntime/qv4context.cpp b/src/qml/jsruntime/qv4context.cpp
index 1a1efc0b4c..56701457e4 100644
--- a/src/qml/jsruntime/qv4context.cpp
+++ b/src/qml/jsruntime/qv4context.cpp
@@ -363,6 +363,7 @@ void ExecutionContext::mark()
void ExecutionContext::setProperty(String *name, const Value& value)
{
+ Scope scope(this);
for (ExecutionContext *ctx = this; ctx; ctx = ctx->outer) {
if (ctx->type == Type_WithContext) {
Object *w = static_cast<WithContext *>(ctx)->withObject;
@@ -398,8 +399,10 @@ void ExecutionContext::setProperty(String *name, const Value& value)
}
}
}
- if (strictMode || name->isEqualTo(engine->id_this))
- throwReferenceError(Value::fromString(name));
+ if (strictMode || name->isEqualTo(engine->id_this)) {
+ Scoped<String> n(scope, name);
+ throwReferenceError(n);
+ }
engine->globalObject->put(name, value);
}
@@ -463,7 +466,8 @@ ReturnedValue ExecutionContext::getProperty(String *name)
return v.asReturnedValue();
}
}
- throwReferenceError(Value::fromString(name));
+ Scoped<String> n(scope, name);
+ throwReferenceError(n);
return Value::undefinedValue().asReturnedValue();
}
@@ -595,75 +599,92 @@ ReturnedValue ExecutionContext::getPropertyAndBase(String *name, Object **base)
return v.asReturnedValue();
}
}
- throwReferenceError(Value::fromString(name));
+ Scoped<String> n(scope, name);
+ throwReferenceError(n);
return Value::undefinedValue().asReturnedValue();
}
-void ExecutionContext::throwError(const Value &value)
+void ExecutionContext::throwError(const ValueRef value)
{
- Scope scope(this);
- ScopedValue v(scope, value);
- __qmljs_throw(this, v);
+ __qmljs_throw(this, value);
}
void ExecutionContext::throwError(const QString &message)
{
- Value v = Value::fromString(this, message);
- throwError(Value::fromObject(engine->newErrorObject(v)));
+ Scope scope(this);
+ ScopedValue v(scope, Value::fromString(this, message));
+ v = engine->newErrorObject(v);
+ throwError(v);
}
void ExecutionContext::throwSyntaxError(const QString &message, const QString &fileName, int line, int column)
{
- Object *error = engine->newSyntaxErrorObject(message, fileName, line, column);
- throwError(Value::fromObject(error));
+ Scope scope(this);
+ Scoped<Object> error(scope, engine->newSyntaxErrorObject(message, fileName, line, column));
+ throwError(error);
}
void ExecutionContext::throwSyntaxError(const QString &message)
{
- Object *error = engine->newSyntaxErrorObject(message);
- throwError(Value::fromObject(error));
+ Scope scope(this);
+ Scoped<Object> error(scope, engine->newSyntaxErrorObject(message));
+ throwError(error);
}
void ExecutionContext::throwTypeError()
{
- throwError(Value::fromObject(engine->newTypeErrorObject(QStringLiteral("Type error"))));
+ Scope scope(this);
+ Scoped<Object> error(scope, engine->newTypeErrorObject(QStringLiteral("Type error")));
+ throwError(error);
}
void ExecutionContext::throwTypeError(const QString &message)
{
- throwError(Value::fromObject(engine->newTypeErrorObject(message)));
+ Scope scope(this);
+ Scoped<Object> error(scope, engine->newTypeErrorObject(message));
+ throwError(error);
}
void ExecutionContext::throwUnimplemented(const QString &message)
{
- Value v = Value::fromString(this, QStringLiteral("Unimplemented ") + message);
- throwError(Value::fromObject(engine->newErrorObject(v)));
+ Scope scope(this);
+ ScopedValue v(scope, Value::fromString(this, QStringLiteral("Unimplemented ") + message));
+ v = engine->newErrorObject(v);
+ throwError(v);
}
-void ExecutionContext::throwReferenceError(Value value)
+void ExecutionContext::throwReferenceError(const ValueRef value)
{
- String *s = value.toString(this);
+ Scope scope(this);
+ Scoped<String> s(scope, value->toString(this));
QString msg = s->toQString() + QStringLiteral(" is not defined");
- throwError(Value::fromObject(engine->newReferenceErrorObject(msg)));
+ Scoped<Object> error(scope, engine->newReferenceErrorObject(msg));
+ throwError(error);
}
void ExecutionContext::throwReferenceError(const QString &message, const QString &fileName, int line, int column)
{
+ Scope scope(this);
QString msg = message + QStringLiteral(" is not defined");
- throwError(Value::fromObject(engine->newReferenceErrorObject(msg, fileName, line, column)));
+ Scoped<Object> error(scope, engine->newReferenceErrorObject(msg, fileName, line, column));
+ throwError(error);
}
void ExecutionContext::throwRangeError(Value value)
{
- String *s = value.toString(this);
+ Scope scope(this);
+ Scoped<String> s(scope, value.toString(this));
QString msg = s->toQString() + QStringLiteral(" out of range");
- throwError(Value::fromObject(engine->newRangeErrorObject(msg)));
+ Scoped<Object> error(scope, engine->newRangeErrorObject(msg));
+ throwError(error);
}
void ExecutionContext::throwURIError(Value msg)
{
- throwError(Value::fromObject(engine->newURIErrorObject(msg)));
+ Scope scope(this);
+ Scoped<Object> error(scope, engine->newURIErrorObject(msg));
+ throwError(error);
}
void SimpleCallContext::initSimpleCallContext(ExecutionEngine *engine)
diff --git a/src/qml/jsruntime/qv4context_p.h b/src/qml/jsruntime/qv4context_p.h
index 8ebffea981..0c3b189401 100644
--- a/src/qml/jsruntime/qv4context_p.h
+++ b/src/qml/jsruntime/qv4context_p.h
@@ -54,6 +54,7 @@ struct ExecutionEngine;
struct DeclarativeEnvironment;
struct Lookup;
struct Function;
+struct ValueRef;
namespace CompiledData {
struct CompilationUnit;
@@ -129,13 +130,13 @@ struct Q_QML_EXPORT ExecutionContext
void createMutableBinding(String *name, bool deletable);
- void Q_NORETURN throwError(const Value &value);
+ void Q_NORETURN throwError(const QV4::ValueRef value);
void Q_NORETURN throwError(const QString &message);
void Q_NORETURN throwSyntaxError(const QString &message);
void Q_NORETURN throwSyntaxError(const QString &message, const QString &fileName, int line, int column);
void Q_NORETURN throwTypeError();
void Q_NORETURN throwTypeError(const QString &message);
- void Q_NORETURN throwReferenceError(Value value);
+ void Q_NORETURN throwReferenceError(const ValueRef value);
void Q_NORETURN throwReferenceError(const QString &value, const QString &fileName, int line, int column);
void Q_NORETURN throwRangeError(Value value);
void Q_NORETURN throwURIError(Value msg);
diff --git a/src/qml/jsruntime/qv4engine.cpp b/src/qml/jsruntime/qv4engine.cpp
index 875ab84cf5..0187099f62 100644
--- a/src/qml/jsruntime/qv4engine.cpp
+++ b/src/qml/jsruntime/qv4engine.cpp
@@ -375,10 +375,10 @@ String *ExecutionEngine::newIdentifier(const QString &text)
return identifierTable->insertString(text);
}
-Object *ExecutionEngine::newStringObject(const Value &value)
+Returned<Object> *ExecutionEngine::newStringObject(const Value &value)
{
StringObject *object = new (memoryManager) StringObject(this, value);
- return object;
+ return object->asReturned<Object>();
}
Returned<Object> *ExecutionEngine::newNumberObject(const Value &value)
@@ -455,20 +455,22 @@ Returned<RegExpObject> *ExecutionEngine::newRegExpObject(const QRegExp &re)
return object->asReturned<RegExpObject>();
}
-Object *ExecutionEngine::newErrorObject(const Value &value)
+Returned<Object> *ExecutionEngine::newErrorObject(const Value &value)
{
ErrorObject *object = new (memoryManager) ErrorObject(errorClass, value);
- return object;
+ return object->asReturned<Object>();
}
-Object *ExecutionEngine::newSyntaxErrorObject(const QString &message)
+Returned<Object> *ExecutionEngine::newSyntaxErrorObject(const QString &message)
{
- return new (memoryManager) SyntaxErrorObject(this, Value::fromString(this, message));
+ Object *error = new (memoryManager) SyntaxErrorObject(this, Value::fromString(this, message));
+ return error->asReturned<Object>();
}
-Object *ExecutionEngine::newSyntaxErrorObject(const QString &message, const QString &fileName, int line, int column)
+Returned<Object> *ExecutionEngine::newSyntaxErrorObject(const QString &message, const QString &fileName, int line, int column)
{
- return new (memoryManager) SyntaxErrorObject(this, message, fileName, line, column);
+ Object *error = new (memoryManager) SyntaxErrorObject(this, message, fileName, line, column);
+ return error->asReturned<Object>();
}
diff --git a/src/qml/jsruntime/qv4engine_p.h b/src/qml/jsruntime/qv4engine_p.h
index a59a837499..5ef7d08a4a 100644
--- a/src/qml/jsruntime/qv4engine_p.h
+++ b/src/qml/jsruntime/qv4engine_p.h
@@ -270,7 +270,7 @@ struct Q_QML_EXPORT ExecutionEngine
String *newString(const QString &s);
String *newIdentifier(const QString &text);
- Object *newStringObject(const Value &value);
+ Returned<Object> *newStringObject(const Value &value);
Returned<Object> *newNumberObject(const Value &value);
Returned<Object> *newBooleanObject(const Value &value);
@@ -285,9 +285,9 @@ struct Q_QML_EXPORT ExecutionEngine
Returned<RegExpObject> *newRegExpObject(RegExp* re, bool global);
Returned<RegExpObject> *newRegExpObject(const QRegExp &re);
- Object *newErrorObject(const Value &value);
- Object *newSyntaxErrorObject(const QString &message, const QString &fileName, int line, int column);
- Object *newSyntaxErrorObject(const QString &message);
+ Returned<Object> *newErrorObject(const Value &value);
+ Returned<Object> *newSyntaxErrorObject(const QString &message, const QString &fileName, int line, int column);
+ Returned<Object> *newSyntaxErrorObject(const QString &message);
Object *newReferenceErrorObject(const QString &message);
Object *newReferenceErrorObject(const QString &message, const QString &fileName, int lineNumber, int columnNumber);
Object *newTypeErrorObject(const QString &message);
diff --git a/src/qml/jsruntime/qv4errorobject.cpp b/src/qml/jsruntime/qv4errorobject.cpp
index 7c75d1162a..987d5083fa 100644
--- a/src/qml/jsruntime/qv4errorobject.cpp
+++ b/src/qml/jsruntime/qv4errorobject.cpp
@@ -242,7 +242,7 @@ ErrorCtor::ErrorCtor(ExecutionContext *scope, String *name)
ReturnedValue ErrorCtor::construct(Managed *m, CallData *callData)
{
- return Value::fromObject(m->engine()->newErrorObject(callData->argc ? callData->args[0] : Value::undefinedValue())).asReturnedValue();
+ return Encode(m->engine()->newErrorObject(callData->argc ? callData->args[0] : Value::undefinedValue()));
}
ReturnedValue ErrorCtor::call(Managed *that, CallData *callData)
diff --git a/src/qml/jsruntime/qv4lookup.cpp b/src/qml/jsruntime/qv4lookup.cpp
index a4116b049e..a844a25008 100644
--- a/src/qml/jsruntime/qv4lookup.cpp
+++ b/src/qml/jsruntime/qv4lookup.cpp
@@ -334,7 +334,9 @@ ReturnedValue Lookup::globalGetterGeneric(Lookup *l, ExecutionContext *ctx)
return o->getValue(p, attrs);
}
}
- ctx->throwReferenceError(Value::fromString(l->name));
+ Scope scope(ctx);
+ Scoped<String> n(scope, l->name);
+ ctx->throwReferenceError(n);
}
ReturnedValue Lookup::globalGetter0(Lookup *l, ExecutionContext *ctx)
diff --git a/src/qml/jsruntime/qv4runtime.cpp b/src/qml/jsruntime/qv4runtime.cpp
index 7af8b21cc5..d98087b6a4 100644
--- a/src/qml/jsruntime/qv4runtime.cpp
+++ b/src/qml/jsruntime/qv4runtime.cpp
@@ -607,7 +607,7 @@ Returned<Object> *__qmljs_convert_to_object(ExecutionContext *ctx, const ValueRe
case Value::Boolean_Type:
return ctx->engine->newBooleanObject(*value);
case Value::String_Type:
- return ctx->engine->newStringObject(*value)->asReturned<Object>();
+ return ctx->engine->newStringObject(*value);
break;
case Value::Object_Type:
Q_UNREACHABLE();
diff --git a/src/qml/jsruntime/qv4scopedvalue_p.h b/src/qml/jsruntime/qv4scopedvalue_p.h
index eed49bfe1f..4bbd3303ee 100644
--- a/src/qml/jsruntime/qv4scopedvalue_p.h
+++ b/src/qml/jsruntime/qv4scopedvalue_p.h
@@ -142,7 +142,7 @@ struct ScopedValue
ScopedValue(const Scope &scope, Returned<T> *t)
{
ptr = scope.engine->jsStackTop++;
- ptr->val = T::toValue(t->getPointer());
+ *ptr = T::toValue(t->getPointer());
#ifndef QT_NO_DEBUG
++scope.size;
#endif
@@ -159,8 +159,8 @@ struct ScopedValue
}
template<typename T>
- ScopedValue &operator=(const Returned<T> *t) {
- ptr->val = T::toValue(t->getPointer());
+ ScopedValue &operator=(Returned<T> *t) {
+ *ptr = T::toValue(t->getPointer());
return *this;
}
@@ -331,6 +331,9 @@ struct ScopedCallData {
struct ValueRef {
ValueRef(const ScopedValue &v)
: ptr(v.ptr) {}
+ template <typename T>
+ ValueRef(const Scoped<T> &v)
+ : ptr(v.ptr) {}
ValueRef(const PersistentValue &v)
: ptr(&v.d->value) {}
ValueRef(PersistentValuePrivate *p)
diff --git a/src/qml/jsruntime/qv4script.cpp b/src/qml/jsruntime/qv4script.cpp
index e3c9505ab7..1834e28be6 100644
--- a/src/qml/jsruntime/qv4script.cpp
+++ b/src/qml/jsruntime/qv4script.cpp
@@ -153,6 +153,7 @@ void Script::parse()
parsed = true;
ExecutionEngine *v4 = scope->engine;
+ Scope valueScope(v4);
MemoryManager::GCBlocker gcBlocker(v4->memoryManager);
@@ -199,9 +200,11 @@ void Script::parse()
compilationUnitHolder = Value::fromObject(new (v4->memoryManager) CompilationUnitHolder(v4, compilationUnit));
}
- if (!vmFunction)
+ if (!vmFunction) {
// ### FIX file/line number
- v4->current->throwError(QV4::Value::fromObject(v4->newSyntaxErrorObject("Syntax error")));
+ Scoped<Object> error(valueScope, v4->newSyntaxErrorObject("Syntax error"));
+ v4->current->throwError(error);
+ }
}
ReturnedValue Script::run()
diff --git a/src/qml/jsruntime/qv4string.cpp b/src/qml/jsruntime/qv4string.cpp
index 2b2eda7c8c..d0f3a196b7 100644
--- a/src/qml/jsruntime/qv4string.cpp
+++ b/src/qml/jsruntime/qv4string.cpp
@@ -173,15 +173,17 @@ ReturnedValue String::getIndexed(Managed *m, uint index, bool *hasProperty)
void String::put(Managed *m, String *name, const Value &value)
{
+ Scope scope(m->engine());
String *that = static_cast<String *>(m);
- Object *o = that->engine()->newStringObject(Value::fromString(that));
+ Scoped<Object> o(scope, that->engine()->newStringObject(Value::fromString(that)));
o->put(name, value);
}
void String::putIndexed(Managed *m, uint index, const Value &value)
{
+ Scope scope(m->engine());
String *that = static_cast<String *>(m);
- Object *o = m->engine()->newStringObject(Value::fromString(that));
+ Scoped<Object> o(scope, that->engine()->newStringObject(Value::fromString(that)));
o->putIndexed(index, value);
}
diff --git a/src/qml/jsruntime/qv4stringobject.cpp b/src/qml/jsruntime/qv4stringobject.cpp
index dfdb639d1e..2223432ec9 100644
--- a/src/qml/jsruntime/qv4stringobject.cpp
+++ b/src/qml/jsruntime/qv4stringobject.cpp
@@ -167,7 +167,7 @@ ReturnedValue StringCtor::construct(Managed *m, CallData *callData)
value = Value::fromString(callData->args[0].toString(m->engine()->current));
else
value = Value::fromString(m->engine()->current, QString());
- return Value::fromObject(m->engine()->newStringObject(value)).asReturnedValue();
+ return Encode(m->engine()->newStringObject(value));
}
ReturnedValue StringCtor::call(Managed *m, CallData *callData)
diff --git a/src/qml/qml/qqmlcontextwrapper.cpp b/src/qml/qml/qqmlcontextwrapper.cpp
index 50d1f32c10..153743aa58 100644
--- a/src/qml/qml/qqmlcontextwrapper.cpp
+++ b/src/qml/qml/qqmlcontextwrapper.cpp
@@ -274,8 +274,9 @@ ReturnedValue QmlContextWrapper::get(Managed *m, String *name, bool *hasProperty
void QmlContextWrapper::put(Managed *m, String *name, const Value &value)
{
- QmlContextWrapper *wrapper = m->as<QmlContextWrapper>();
ExecutionEngine *v4 = m->engine();
+ QV4::Scope scope(v4);
+ QV4::Scoped<QmlContextWrapper> wrapper(scope, m->as<QmlContextWrapper>());
if (!wrapper)
v4->current->throwTypeError();
@@ -283,7 +284,8 @@ void QmlContextWrapper::put(Managed *m, String *name, const Value &value)
if (wrapper && wrapper->readOnly) {
QString error = QLatin1String("Invalid write to global property \"") + name->toQString() +
QLatin1Char('"');
- v4->current->throwError(Value::fromString(v4->current->engine->newString(error)));
+ Scoped<String> e(scope, v4->current->engine->newString(error));
+ v4->current->throwError(e);
}
Object::put(m, name, value);
diff --git a/src/qml/qml/qqmlvaluetypewrapper.cpp b/src/qml/qml/qqmlvaluetypewrapper.cpp
index 88704d58b3..f89ce15a57 100644
--- a/src/qml/qml/qqmlvaluetypewrapper.cpp
+++ b/src/qml/qml/qqmlvaluetypewrapper.cpp
@@ -327,14 +327,15 @@ ReturnedValue QmlValueTypeWrapper::get(Managed *m, String *name, bool *hasProper
void QmlValueTypeWrapper::put(Managed *m, String *name, const Value &value)
{
- QmlValueTypeWrapper *r = m->as<QmlValueTypeWrapper>();
ExecutionEngine *v4 = m->engine();
+ Scope scope(v4);
+ Scoped<QmlValueTypeWrapper> r(scope, m->as<QmlValueTypeWrapper>());
if (!r)
v4->current->throwTypeError();
QByteArray propName = name->toQString().toUtf8();
if (r->objectType == QmlValueTypeWrapper::Reference) {
- QmlValueTypeReference *reference = static_cast<QmlValueTypeReference *>(r);
+ QmlValueTypeReference *reference = static_cast<QmlValueTypeReference *>(r.getPointer());
QMetaProperty writebackProperty = reference->object->metaObject()->property(reference->property);
if (!reference->object || !writebackProperty.isWritable() || !readReferenceValue(reference))
@@ -353,7 +354,8 @@ void QmlValueTypeWrapper::put(Managed *m, String *name, const Value &value)
if (!f->bindingKeyFlag) {
// assigning a JS function to a non-var-property is not allowed.
QString error = QLatin1String("Cannot assign JavaScript function to value-type property");
- v4->current->throwError(r->v8->toString(error));
+ Scoped<String> e(scope, r->v8->toString(error));
+ v4->current->throwError(e);
}
QQmlContextData *context = r->v8->callingContext();
@@ -400,7 +402,7 @@ void QmlValueTypeWrapper::put(Managed *m, String *name, const Value &value)
} else {
Q_ASSERT(r->objectType == QmlValueTypeWrapper::Copy);
- QmlValueTypeCopy *copy = static_cast<QmlValueTypeCopy *>(r);
+ QmlValueTypeCopy *copy = static_cast<QmlValueTypeCopy *>(r.getPointer());
int index = r->type->metaObject()->indexOfProperty(propName.constData());
if (index == -1)
diff --git a/src/qml/qml/qqmlxmlhttprequest.cpp b/src/qml/qml/qqmlxmlhttprequest.cpp
index b7447aee07..dc98bd176e 100644
--- a/src/qml/qml/qqmlxmlhttprequest.cpp
+++ b/src/qml/qml/qqmlxmlhttprequest.cpp
@@ -70,8 +70,10 @@ using namespace QV4;
#ifndef QT_NO_XMLSTREAMREADER
-#define V4THROW_REFERENCE(string) \
- ctx->throwError(Value::fromObject(ctx->engine->newReferenceErrorObject(QStringLiteral(string))))
+#define V4THROW_REFERENCE(string) { \
+ Scoped<Object> error(scope, ctx->engine->newReferenceErrorObject(QStringLiteral(string))); \
+ ctx->throwError(error); \
+ }
QT_BEGIN_NAMESPACE
@@ -1658,6 +1660,7 @@ void QQmlXMLHttpRequestCtor::setupProto()
// XMLHttpRequest methods
ReturnedValue QQmlXMLHttpRequestCtor::method_open(SimpleCallContext *ctx)
{
+ Scope scope(ctx);
QQmlXMLHttpRequestWrapper *w = ctx->thisObject.as<QQmlXMLHttpRequestWrapper>();
if (!w)
V4THROW_REFERENCE("Not an XMLHttpRequest object");
@@ -1706,6 +1709,8 @@ ReturnedValue QQmlXMLHttpRequestCtor::method_open(SimpleCallContext *ctx)
ReturnedValue QQmlXMLHttpRequestCtor::method_setRequestHeader(SimpleCallContext *ctx)
{
+ Scope scope(ctx);
+
QQmlXMLHttpRequestWrapper *w = ctx->thisObject.as<QQmlXMLHttpRequestWrapper>();
if (!w)
V4THROW_REFERENCE("Not an XMLHttpRequest object");
@@ -1752,6 +1757,8 @@ ReturnedValue QQmlXMLHttpRequestCtor::method_setRequestHeader(SimpleCallContext
ReturnedValue QQmlXMLHttpRequestCtor::method_send(SimpleCallContext *ctx)
{
+ Scope scope(ctx);
+
QQmlXMLHttpRequestWrapper *w = ctx->thisObject.as<QQmlXMLHttpRequestWrapper>();
if (!w)
V4THROW_REFERENCE("Not an XMLHttpRequest object");
@@ -1772,6 +1779,8 @@ ReturnedValue QQmlXMLHttpRequestCtor::method_send(SimpleCallContext *ctx)
ReturnedValue QQmlXMLHttpRequestCtor::method_abort(SimpleCallContext *ctx)
{
+ Scope scope(ctx);
+
QQmlXMLHttpRequestWrapper *w = ctx->thisObject.as<QQmlXMLHttpRequestWrapper>();
if (!w)
V4THROW_REFERENCE("Not an XMLHttpRequest object");
@@ -1782,6 +1791,8 @@ ReturnedValue QQmlXMLHttpRequestCtor::method_abort(SimpleCallContext *ctx)
ReturnedValue QQmlXMLHttpRequestCtor::method_getResponseHeader(SimpleCallContext *ctx)
{
+ Scope scope(ctx);
+
QQmlXMLHttpRequestWrapper *w = ctx->thisObject.as<QQmlXMLHttpRequestWrapper>();
if (!w)
V4THROW_REFERENCE("Not an XMLHttpRequest object");
@@ -1802,6 +1813,8 @@ ReturnedValue QQmlXMLHttpRequestCtor::method_getResponseHeader(SimpleCallContext
ReturnedValue QQmlXMLHttpRequestCtor::method_getAllResponseHeaders(SimpleCallContext *ctx)
{
+ Scope scope(ctx);
+
QQmlXMLHttpRequestWrapper *w = ctx->thisObject.as<QQmlXMLHttpRequestWrapper>();
if (!w)
V4THROW_REFERENCE("Not an XMLHttpRequest object");
@@ -1823,6 +1836,8 @@ ReturnedValue QQmlXMLHttpRequestCtor::method_getAllResponseHeaders(SimpleCallCon
// XMLHttpRequest properties
ReturnedValue QQmlXMLHttpRequestCtor::method_get_readyState(SimpleCallContext *ctx)
{
+ Scope scope(ctx);
+
QQmlXMLHttpRequestWrapper *w = ctx->thisObject.as<QQmlXMLHttpRequestWrapper>();
if (!w)
V4THROW_REFERENCE("Not an XMLHttpRequest object");
@@ -1833,6 +1848,8 @@ ReturnedValue QQmlXMLHttpRequestCtor::method_get_readyState(SimpleCallContext *c
ReturnedValue QQmlXMLHttpRequestCtor::method_get_status(SimpleCallContext *ctx)
{
+ Scope scope(ctx);
+
QQmlXMLHttpRequestWrapper *w = ctx->thisObject.as<QQmlXMLHttpRequestWrapper>();
if (!w)
V4THROW_REFERENCE("Not an XMLHttpRequest object");
@@ -1850,6 +1867,8 @@ ReturnedValue QQmlXMLHttpRequestCtor::method_get_status(SimpleCallContext *ctx)
ReturnedValue QQmlXMLHttpRequestCtor::method_get_statusText(SimpleCallContext *ctx)
{
+ Scope scope(ctx);
+
QQmlXMLHttpRequestWrapper *w = ctx->thisObject.as<QQmlXMLHttpRequestWrapper>();
if (!w)
V4THROW_REFERENCE("Not an XMLHttpRequest object");
@@ -1869,6 +1888,8 @@ ReturnedValue QQmlXMLHttpRequestCtor::method_get_statusText(SimpleCallContext *c
ReturnedValue QQmlXMLHttpRequestCtor::method_get_responseText(SimpleCallContext *ctx)
{
+ Scope scope(ctx);
+
QQmlXMLHttpRequestWrapper *w = ctx->thisObject.as<QQmlXMLHttpRequestWrapper>();
if (!w)
V4THROW_REFERENCE("Not an XMLHttpRequest object");
@@ -1885,6 +1906,8 @@ ReturnedValue QQmlXMLHttpRequestCtor::method_get_responseText(SimpleCallContext
ReturnedValue QQmlXMLHttpRequestCtor::method_get_responseXML(SimpleCallContext *ctx)
{
+ Scope scope(ctx);
+
QQmlXMLHttpRequestWrapper *w = ctx->thisObject.as<QQmlXMLHttpRequestWrapper>();
if (!w)
V4THROW_REFERENCE("Not an XMLHttpRequest object");
diff --git a/src/qml/qml/v8/qqmlbuiltinfunctions.cpp b/src/qml/qml/v8/qqmlbuiltinfunctions.cpp
index 2a75bf9834..6389ad2715 100644
--- a/src/qml/qml/v8/qqmlbuiltinfunctions.cpp
+++ b/src/qml/qml/v8/qqmlbuiltinfunctions.cpp
@@ -949,29 +949,30 @@ See \l {Dynamic QML Object Creation from JavaScript} for more information on usi
*/
ReturnedValue QtObject::method_createQmlObject(SimpleCallContext *ctx)
{
+ Scope scope(ctx);
if (ctx->argumentCount < 2 || ctx->argumentCount > 3)
V4THROW_ERROR("Qt.createQmlObject(): Invalid arguments");
struct Error {
- static Value create(QV8Engine *engine, const QList<QQmlError> &errors) {
+ static ReturnedValue create(QV4::ExecutionEngine *v4, const QList<QQmlError> &errors) {
+ Scope scope(v4);
QString errorstr = QLatin1String("Qt.createQmlObject(): failed to create object: ");
- QV4::ExecutionEngine *v4 = QV8Engine::getV4(engine);
- QV4::ArrayObject *qmlerrors = v4->newArrayObject();
+ QV4::Scoped<ArrayObject> qmlerrors(scope, v4->newArrayObject());
for (int ii = 0; ii < errors.count(); ++ii) {
const QQmlError &error = errors.at(ii);
errorstr += QLatin1String("\n ") + error.toString();
QV4::Object *qmlerror = v4->newObject();
qmlerror->put(v4->newString("lineNumber"), QV4::Value::fromInt32(error.line()));
qmlerror->put(v4->newString("columnNumber"), QV4::Value::fromInt32(error.column()));
- qmlerror->put(v4->newString("fileName"), engine->toString(error.url().toString()));
- qmlerror->put(v4->newString("message"), engine->toString(error.description()));
+ qmlerror->put(v4->newString("fileName"), Value::fromString(v4->newString(error.url().toString())));
+ qmlerror->put(v4->newString("message"), Value::fromString(v4->newString(error.description())));
qmlerrors->putIndexed(ii, QV4::Value::fromObject(qmlerror));
}
- QV4::Object *errorObject = v4->newErrorObject(engine->toString(errorstr));
- errorObject->put(v4->newString("qmlErrors"), Value::fromObject(qmlerrors));
- return Value::fromObject(errorObject);
+ Scoped<Object> errorObject(scope, v4->newErrorObject(Value::fromString(v4->newString(errorstr))));
+ errorObject->put(v4->newString("qmlErrors"), qmlerrors.asValue());
+ return errorObject.asReturnedValue();
}
};
@@ -1009,7 +1010,8 @@ ReturnedValue QtObject::method_createQmlObject(SimpleCallContext *ctx)
component.setData(qml.toUtf8(), url);
if (component.isError()) {
- ctx->throwError(Error::create(v8engine, component.errors()));
+ ScopedValue v(scope, Error::create(ctx->engine, component.errors()));
+ ctx->throwError(v);
return QV4::Encode::undefined();
}
@@ -1033,7 +1035,8 @@ ReturnedValue QtObject::method_createQmlObject(SimpleCallContext *ctx)
component.completeCreate();
if (component.isError()) {
- ctx->throwError(Error::create(v8engine, component.errors()));
+ ScopedValue v(scope, Error::create(ctx->engine, component.errors()));
+ ctx->throwError(v);
return QV4::Encode::undefined();
}
diff --git a/src/qml/qml/v8/qv4domerrors_p.h b/src/qml/qml/v8/qv4domerrors_p.h
index ed38886e15..ce6fb9edea 100644
--- a/src/qml/qml/v8/qv4domerrors_p.h
+++ b/src/qml/qml/v8/qv4domerrors_p.h
@@ -77,10 +77,10 @@ QT_BEGIN_NAMESPACE
#define DOMEXCEPTION_TYPE_MISMATCH_ERR 17
#define V4THROW_DOM(error, string) { \
- QV4::Value v = QV4::Value::fromString(ctx, QStringLiteral(string)); \
- QV4::Object *ex = ctx->engine->newErrorObject(v); \
+ QV4::ScopedValue v(scope, QV4::Value::fromString(ctx, QStringLiteral(string))); \
+ QV4::Scoped<Object> ex(scope, ctx->engine->newErrorObject(v)); \
ex->put(ctx->engine->newIdentifier(QStringLiteral("code")), QV4::Value::fromInt32(error)); \
- ctx->throwError(QV4::Value::fromObject(ex)); \
+ ctx->throwError(ex); \
}
namespace QV4 {