From df5edd28bc4258b89d9d5ffdddf837f339a17aad Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Wed, 18 Sep 2013 16:36:02 +0200 Subject: convert Managed::put() API to be GC safe Change-Id: I09198ce372fa545372db389fac26828d21ad5731 Reviewed-by: Simon Hausmann --- src/imports/localstorage/plugin.cpp | 18 ++--- src/qml/jsapi/qjsvalue.cpp | 2 +- src/qml/jsruntime/qv4arrayobject.cpp | 28 +++---- src/qml/jsruntime/qv4context.cpp | 14 ++-- src/qml/jsruntime/qv4context_p.h | 2 +- src/qml/jsruntime/qv4include.cpp | 28 +++---- src/qml/jsruntime/qv4jsonobject.cpp | 11 ++- src/qml/jsruntime/qv4lookup.cpp | 100 +++++++++++++------------ src/qml/jsruntime/qv4lookup_p.h | 38 +++++----- src/qml/jsruntime/qv4managed.cpp | 12 ++- src/qml/jsruntime/qv4managed_p.h | 12 ++- src/qml/jsruntime/qv4object.cpp | 42 ++++++----- src/qml/jsruntime/qv4object_p.h | 10 +-- src/qml/jsruntime/qv4qobjectwrapper.cpp | 8 +- src/qml/jsruntime/qv4qobjectwrapper_p.h | 2 +- src/qml/jsruntime/qv4regexp.cpp | 2 +- src/qml/jsruntime/qv4regexp_p.h | 2 +- src/qml/jsruntime/qv4runtime.cpp | 16 ++-- src/qml/jsruntime/qv4serialize.cpp | 4 +- src/qml/jsruntime/qv4string.cpp | 2 +- src/qml/jsruntime/qv4string_p.h | 2 +- src/qml/jsruntime/qv4stringobject.cpp | 4 +- src/qml/qml/qqmlcontextwrapper.cpp | 13 ++-- src/qml/qml/qqmlcontextwrapper_p.h | 2 +- src/qml/qml/qqmllistwrapper.cpp | 2 +- src/qml/qml/qqmllistwrapper_p.h | 2 +- src/qml/qml/qqmltypewrapper.cpp | 6 +- src/qml/qml/qqmltypewrapper_p.h | 2 +- src/qml/qml/qqmlvaluetypewrapper.cpp | 10 +-- src/qml/qml/qqmlvaluetypewrapper_p.h | 2 +- src/qml/qml/qqmlxmlhttprequest.cpp | 4 +- src/qml/qml/v8/qqmlbuiltinfunctions.cpp | 23 +++--- src/qml/qml/v8/qv4domerrors_p.h | 2 +- src/qml/qml/v8/qv8engine.cpp | 6 +- src/qml/types/qquickworkerscript.cpp | 10 +-- src/quick/items/context2d/qquickcontext2d.cpp | 3 +- src/quick/items/qquickitem.cpp | 30 +++++--- tests/auto/qml/qv4debugger/tst_qv4debugger.cpp | 2 +- tools/v4/main.cpp | 10 +-- 39 files changed, 263 insertions(+), 225 deletions(-) diff --git a/src/imports/localstorage/plugin.cpp b/src/imports/localstorage/plugin.cpp index 2a3cb1ccc5..211809e59c 100644 --- a/src/imports/localstorage/plugin.cpp +++ b/src/imports/localstorage/plugin.cpp @@ -67,7 +67,7 @@ using namespace QV4; #define V4THROW_SQL(error, desc) { \ QV4::Scoped v(scope, Value::fromString(ctx, desc)); \ QV4::Scoped ex(scope, ctx->engine->newErrorObject(v.asValue())); \ - ex->put(ctx->engine->newIdentifier(QStringLiteral("code")), Value::fromInt32(error)); \ + ex->put(QV4::ScopedString(scope, ctx->engine->newIdentifier(QStringLiteral("code"))), QV4::ScopedValue(scope, Value::fromInt32(error))); \ ctx->throwError(ex); \ } @@ -210,11 +210,9 @@ static ReturnedValue qmlsqldatabase_rows_index(QQmlSqlDatabaseWrapper *r, Execut Scoped row(scope, v4->newObject()); for (int ii = 0; ii < record.count(); ++ii) { QVariant v = record.value(ii); - if (v.isNull()) { - row->put(v4->newIdentifier(record.fieldName(ii)), Value::nullValue()); - } else { - row->put(v4->newIdentifier(record.fieldName(ii)), Value::fromReturnedValue(v8->fromVariant(v))); - } + ScopedString s(scope, v4->newIdentifier(record.fieldName(ii))); + ScopedValue val(scope, v.isNull() ? Encode::null() : v8->fromVariant(v)); + row->put(s, val); } if (hasProperty) *hasProperty = true; @@ -307,9 +305,11 @@ static ReturnedValue qmlsqldatabase_executeSql(SimpleCallContext *ctx) Scoped resultObject(scope, ctx->engine->newObject()); result = resultObject.asValue(); // XXX optimize - resultObject->put(ctx->engine->newIdentifier("rowsAffected"), Value::fromInt32(query.numRowsAffected())); - resultObject->put(ctx->engine->newIdentifier("insertId"), engine->toString(query.lastInsertId().toString())); - resultObject->put(ctx->engine->newIdentifier("rows"), Value::fromObject(rows)); + ScopedString s(scope); + ScopedValue v(scope); + resultObject->put((s = ctx->engine->newIdentifier("rowsAffected")), (v = Value::fromInt32(query.numRowsAffected()))); + resultObject->put((s = ctx->engine->newIdentifier("insertId")), (v = engine->toString(query.lastInsertId().toString()))); + resultObject->put((s = ctx->engine->newIdentifier("rows")), (v = Value::fromObject(rows))); } else { err = true; } diff --git a/src/qml/jsapi/qjsvalue.cpp b/src/qml/jsapi/qjsvalue.cpp index 987dd8b29f..eb4d43c6c8 100644 --- a/src/qml/jsapi/qjsvalue.cpp +++ b/src/qml/jsapi/qjsvalue.cpp @@ -883,7 +883,7 @@ void QJSValue::setProperty(const QString& name, const QJSValue& value) return; } - String *s = engine->newString(name); + ScopedString s(scope, engine->newString(name)); uint idx = s->asArrayIndex(); if (idx < UINT_MAX) { setProperty(idx, value); diff --git a/src/qml/jsruntime/qv4arrayobject.cpp b/src/qml/jsruntime/qv4arrayobject.cpp index 61ceee95f5..ff4f4aa40e 100644 --- a/src/qml/jsruntime/qv4arrayobject.cpp +++ b/src/qml/jsruntime/qv4arrayobject.cpp @@ -247,12 +247,12 @@ ReturnedValue ArrayPrototype::method_join(SimpleCallContext *ctx) ReturnedValue ArrayPrototype::method_pop(SimpleCallContext *ctx) { Scope scope(ctx); - Object *instance = ctx->thisObject.toObject(ctx); - uint len = getLength(ctx, instance); + ScopedObject instance(scope, ctx->thisObject.toObject(ctx)); + uint len = getLength(ctx, instance.getPointer()); if (!len) { if (!instance->isArrayObject()) - instance->put(ctx->engine->id_length, Value::fromInt32(0)); + instance->put(ctx->engine->id_length, ScopedValue(scope, Value::fromInt32(0))); return Value::undefinedValue().asReturnedValue(); } @@ -262,25 +262,27 @@ ReturnedValue ArrayPrototype::method_pop(SimpleCallContext *ctx) if (instance->isArrayObject()) instance->setArrayLengthUnchecked(len - 1); else - instance->put(ctx->engine->id_length, Value::fromDouble(len - 1)); + instance->put(ctx->engine->id_length, ScopedValue(scope, Value::fromDouble(len - 1))); return result.asReturnedValue(); } ReturnedValue ArrayPrototype::method_push(SimpleCallContext *ctx) { - Object *instance = ctx->thisObject.toObject(ctx); - uint len = getLength(ctx, instance); + Scope scope(ctx); + ScopedObject instance(scope, ctx->thisObject.toObject(ctx)); + uint len = getLength(ctx, instance.getPointer()); if (len + ctx->argumentCount < len) { // ughh... double l = len; for (int i = 0; i < ctx->argumentCount; ++i) { Value idx = Value::fromDouble(l + i); - instance->put(idx.toString(ctx), ctx->arguments[i]); + ScopedString s(scope, idx.toString(ctx)); + instance->put(s, ctx->arguments[i]); } double newLen = l + ctx->argumentCount; if (!instance->isArrayObject()) - instance->put(ctx->engine->id_length, Value::fromDouble(newLen)); + instance->put(ctx->engine->id_length, ScopedValue(scope, Value::fromDouble(newLen))); else ctx->throwRangeError(Value::fromString(ctx, QStringLiteral("Array.prototype.push: Overflow"))); return Value::fromDouble(newLen).asReturnedValue(); @@ -311,7 +313,7 @@ ReturnedValue ArrayPrototype::method_push(SimpleCallContext *ctx) if (instance->isArrayObject()) instance->setArrayLengthUnchecked(len); else - instance->put(ctx->engine->id_length, Value::fromDouble(len)); + instance->put(ctx->engine->id_length, ScopedValue(scope, Value::fromDouble(len))); if (len < INT_MAX) return Value::fromInt32(len).asReturnedValue(); @@ -353,7 +355,7 @@ ReturnedValue ArrayPrototype::method_shift(SimpleCallContext *ctx) if (!len) { if (!instance->isArrayObject()) - instance->put(ctx->engine->id_length, Value::fromInt32(0)); + instance->put(ctx->engine->id_length, ScopedValue(scope, Value::fromInt32(0))); return Value::undefinedValue().asReturnedValue(); } @@ -395,7 +397,7 @@ ReturnedValue ArrayPrototype::method_shift(SimpleCallContext *ctx) if (instance->isArrayObject()) instance->setArrayLengthUnchecked(len - 1); else - instance->put(ctx->engine->id_length, Value::fromDouble(len - 1)); + instance->put(ctx->engine->id_length, ScopedValue(scope, Value::fromDouble(len - 1))); return result.asReturnedValue(); } @@ -507,7 +509,7 @@ ReturnedValue ArrayPrototype::method_splice(SimpleCallContext *ctx) instance->putIndexed(start + i, ctx->arguments[i + 2]); ctx->strictMode = true; - instance->put(ctx->engine->id_length, Value::fromDouble(len - deleteCount + itemCount)); + instance->put(ctx->engine->id_length, ScopedValue(scope, Value::fromDouble(len - deleteCount + itemCount))); return newArray.asReturnedValue(); } @@ -558,7 +560,7 @@ ReturnedValue ArrayPrototype::method_unshift(SimpleCallContext *ctx) if (instance->isArrayObject()) instance->setArrayLengthUnchecked(newLen); else - instance->put(ctx->engine->id_length, Value::fromDouble(newLen)); + instance->put(ctx->engine->id_length, ScopedValue(scope, Value::fromDouble(newLen))); if (newLen < INT_MAX) return Value::fromInt32(newLen).asReturnedValue(); diff --git a/src/qml/jsruntime/qv4context.cpp b/src/qml/jsruntime/qv4context.cpp index 1da2499ec5..73a059c4e8 100644 --- a/src/qml/jsruntime/qv4context.cpp +++ b/src/qml/jsruntime/qv4context.cpp @@ -367,7 +367,7 @@ void ExecutionContext::mark() } } -void ExecutionContext::setProperty(String *name, const Value& value) +void ExecutionContext::setProperty(String *name, const ValueRef value) { Scope scope(this); ScopedString n(scope, name); @@ -375,11 +375,11 @@ void ExecutionContext::setProperty(String *name, const Value& value) if (ctx->type == Type_WithContext) { Object *w = static_cast(ctx)->withObject; if (w->__hasProperty__(n)) { - w->put(name, value); + w->put(n, value); return; } } else if (ctx->type == Type_CatchContext && static_cast(ctx)->exceptionVarName->isEqualTo(name)) { - static_cast(ctx)->exceptionValue = value; + static_cast(ctx)->exceptionValue = *value; return; } else { Object *activation = 0; @@ -387,12 +387,12 @@ void ExecutionContext::setProperty(String *name, const Value& value) CallContext *c = static_cast(ctx); for (unsigned int i = 0; i < c->function->varCount; ++i) if (c->function->varList[i]->isEqualTo(name)) { - c->locals[i] = value; + c->locals[i] = *value; return; } for (int i = (int)c->function->formalParameterCount - 1; i >= 0; --i) if (c->function->formalParameterList[i]->isEqualTo(name)) { - c->arguments[i] = value; + c->arguments[i] = *value; return; } activation = c->activation; @@ -401,7 +401,7 @@ void ExecutionContext::setProperty(String *name, const Value& value) } if (activation && (ctx->type == Type_QmlContext || activation->__hasProperty__(n))) { - activation->put(name, value); + activation->put(n, value); return; } } @@ -410,7 +410,7 @@ void ExecutionContext::setProperty(String *name, const Value& value) Scoped n(scope, name); throwReferenceError(n); } - engine->globalObject->put(name, value); + engine->globalObject->put(n, value); } ReturnedValue ExecutionContext::getProperty(String *name) diff --git a/src/qml/jsruntime/qv4context_p.h b/src/qml/jsruntime/qv4context_p.h index fe15a53fd2..3e230f97c2 100644 --- a/src/qml/jsruntime/qv4context_p.h +++ b/src/qml/jsruntime/qv4context_p.h @@ -142,7 +142,7 @@ struct Q_QML_EXPORT ExecutionContext void Q_NORETURN throwURIError(Value msg); void Q_NORETURN throwUnimplemented(const QString &message); - void setProperty(String *name, const Value &value); + void setProperty(String *name, const ValueRef value); ReturnedValue getProperty(String *name); ReturnedValue getPropertyNoThrow(String *name); ReturnedValue getPropertyAndBase(String *name, Object **base); diff --git a/src/qml/jsruntime/qv4include.cpp b/src/qml/jsruntime/qv4include.cpp index 4d9573b990..681ae5990d 100644 --- a/src/qml/jsruntime/qv4include.cpp +++ b/src/qml/jsruntime/qv4include.cpp @@ -87,13 +87,14 @@ QV4::ReturnedValue QV4Include::resultValue(QV4::ExecutionEngine *v4, Status stat QV4::Scope scope(v4); // XXX It seems inefficient to create this object from scratch each time. - QV4::Scoped o(scope, v4->newObject()); - o->put(v4->newString("OK"), QV4::Value::fromInt32(Ok)); - o->put(v4->newString("LOADING"), QV4::Value::fromInt32(Loading)); - o->put(v4->newString("NETWORK_ERROR"), QV4::Value::fromInt32(NetworkError)); - o->put(v4->newString("EXCEPTION"), QV4::Value::fromInt32(Exception)); - - o->put(v4->newString("status"), QV4::Value::fromInt32(status)); + QV4::ScopedObject o(scope, v4->newObject()); + QV4::ScopedString s(scope); + QV4::ScopedValue v(scope); + o->put((s = v4->newString("OK")), (v = QV4::Value::fromInt32(Ok))); + o->put((s = v4->newString("LOADING")), (v = QV4::Value::fromInt32(Loading))); + o->put((s = v4->newString("NETWORK_ERROR")), (v = QV4::Value::fromInt32(NetworkError))); + o->put((s = v4->newString("EXCEPTION")), (v = QV4::Value::fromInt32(Exception))); + o->put((s = v4->newString("status")), (v = QV4::Value::fromInt32(status))); return o.asReturnedValue(); } @@ -141,6 +142,7 @@ void QV4Include::finished() } } + QV4::Scope scope(v4); if (m_reply->error() == QNetworkReply::NoError) { QByteArray data = m_reply->readAll(); @@ -150,20 +152,20 @@ void QV4Include::finished() QV4::Script script(v4, m_qmlglobal.value().asObject(), code, m_url.toString()); QV4::ExecutionContext *ctx = v4->current; - QV4::Scope scope(v4); QV4::Scoped o(scope, m_resultObject.value()); + QV4::ScopedString status(scope, v4->newString("status")); try { script.parse(); script.run(); - o->put(v4->newString("status"), QV4::Value::fromInt32(Ok)); + o->put(status, QV4::ScopedValue(scope, QV4::Value::fromInt32(Ok))); } catch (QV4::Exception &e) { e.accept(ctx); - o->put(v4->newString("status"), QV4::Value::fromInt32(Exception)); + o->put(status, QV4::ScopedValue(scope, QV4::Value::fromInt32(Exception))); QV4::ScopedValue ex(scope, e.value()); - o->put(v4->newString("exception"), ex); + o->put(QV4::ScopedString(scope, v4->newString("exception")), ex); } } else { - m_resultObject.value().asObject()->put(v4->newString("status"), QV4::Value::fromInt32(NetworkError)); + m_resultObject.value().asObject()->put(QV4::ScopedString(scope, v4->newString("status")), QV4::ScopedValue(scope, QV4::Value::fromInt32(NetworkError))); } callback(m_callbackFunction.value(), m_resultObject.value()); @@ -225,7 +227,7 @@ QV4::ReturnedValue QV4Include::method_include(QV4::SimpleCallContext *ctx) e.accept(ctx); result = resultValue(v4, Exception); QV4::ScopedValue ex(scope, e.value()); - result->asObject()->put(v4->newString("exception"), ex); + result->asObject()->put(QV4::ScopedString(scope, v4->newString("exception")), ex); } } else { result = resultValue(v4, NetworkError); diff --git a/src/qml/jsruntime/qv4jsonobject.cpp b/src/qml/jsruntime/qv4jsonobject.cpp index 6dec2d1ec6..e3e159233b 100644 --- a/src/qml/jsruntime/qv4jsonobject.cpp +++ b/src/qml/jsruntime/qv4jsonobject.cpp @@ -716,7 +716,8 @@ QString Stringify::Str(const QString &key, Value value) if (replacerFunction) { Scoped holder(scope, ctx->engine->newObject()); - holder->put(ctx, QString(), value); + ScopedValue v(scope, value); + holder->put(ctx, QString(), v); ScopedCallData callData(scope, 2); callData->args[0] = Value::fromString(ctx, key); callData->args[1] = value; @@ -985,8 +986,12 @@ QV4::ReturnedValue JsonObject::fromJsonObject(ExecutionEngine *engine, const QJs { Scope scope(engine); Scoped o(scope, engine->newObject()); - for (QJsonObject::const_iterator it = object.begin(); it != object.end(); ++it) - o->put(engine->newString(it.key()), Value::fromReturnedValue(fromJsonValue(engine, it.value()))); + ScopedString s(scope); + ScopedValue v(scope); + for (QJsonObject::const_iterator it = object.begin(); it != object.end(); ++it) { + v = Value::fromReturnedValue(fromJsonValue(engine, it.value())); + o->put((s = engine->newString(it.key())), v); + } return o.asReturnedValue(); } diff --git a/src/qml/jsruntime/qv4lookup.cpp b/src/qml/jsruntime/qv4lookup.cpp index da078729e4..50e56edcbd 100644 --- a/src/qml/jsruntime/qv4lookup.cpp +++ b/src/qml/jsruntime/qv4lookup.cpp @@ -87,14 +87,14 @@ Property *Lookup::lookup(Object *obj, PropertyAttributes *attrs) } -ReturnedValue Lookup::getterGeneric(QV4::Lookup *l, const QV4::Value &object) +ReturnedValue Lookup::getterGeneric(QV4::Lookup *l, const ValueRef object) { - if (Object *o = object.asObject()) + if (Object *o = object->asObject()) return o->getLookup(l); ExecutionEngine *engine = l->name->engine(); Object *proto; - switch (object.type()) { + switch (object->type()) { case Value::Undefined_Type: case Value::Null_Type: engine->current->throwTypeError(); @@ -102,7 +102,7 @@ ReturnedValue Lookup::getterGeneric(QV4::Lookup *l, const QV4::Value &object) proto = engine->booleanClass->prototype; break; case Value::Managed_Type: - Q_ASSERT(object.isString()); + Q_ASSERT(object->isString()); proto = engine->stringClass->prototype; if (l->name == engine->id_length) { // special case, as the property is on the object itself @@ -118,7 +118,7 @@ ReturnedValue Lookup::getterGeneric(QV4::Lookup *l, const QV4::Value &object) PropertyAttributes attrs; Property *p = l->lookup(proto, &attrs); if (p) { - l->type = object.type(); + l->type = object->type(); l->proto = proto; if (attrs.isData()) { if (l->level == 0) @@ -131,16 +131,16 @@ ReturnedValue Lookup::getterGeneric(QV4::Lookup *l, const QV4::Value &object) l->getter = Lookup::primitiveGetterAccessor0; else if (l->level == 1) l->getter = Lookup::primitiveGetterAccessor1; - return proto->getValue(object, p, attrs); + return proto->getValue(*object, p, attrs); } } return Value::undefinedValue().asReturnedValue(); } -ReturnedValue Lookup::getter0(Lookup *l, const Value &object) +ReturnedValue Lookup::getter0(Lookup *l, const ValueRef object) { - if (Object *o = object.asObject()) { + if (Object *o = object->asObject()) { if (l->classList[0] == o->internalClass) return o->memberData[l->index].value.asReturnedValue(); } @@ -148,9 +148,9 @@ ReturnedValue Lookup::getter0(Lookup *l, const Value &object) return getterGeneric(l, object); } -ReturnedValue Lookup::getter1(Lookup *l, const Value &object) +ReturnedValue Lookup::getter1(Lookup *l, const ValueRef object) { - if (Object *o = object.asObject()) { + if (Object *o = object->asObject()) { if (l->classList[0] == o->internalClass && l->classList[1] == o->prototype()->internalClass) return o->prototype()->memberData[l->index].value.asReturnedValue(); @@ -159,9 +159,9 @@ ReturnedValue Lookup::getter1(Lookup *l, const Value &object) return getterGeneric(l, object); } -ReturnedValue Lookup::getter2(Lookup *l, const Value &object) +ReturnedValue Lookup::getter2(Lookup *l, const ValueRef object) { - if (Object *o = object.asObject()) { + if (Object *o = object->asObject()) { if (l->classList[0] == o->internalClass) { o = o->prototype(); if (l->classList[1] == o->internalClass) { @@ -175,9 +175,9 @@ ReturnedValue Lookup::getter2(Lookup *l, const Value &object) return getterGeneric(l, object); } -ReturnedValue Lookup::getterAccessor0(Lookup *l, const Value &object) +ReturnedValue Lookup::getterAccessor0(Lookup *l, const ValueRef object) { - if (Object *o = object.asObject()) { + if (Object *o = object->asObject()) { if (l->classList[0] == o->internalClass) { Scope scope(o->engine()); FunctionObject *getter = o->memberData[l->index].getter(); @@ -185,7 +185,7 @@ ReturnedValue Lookup::getterAccessor0(Lookup *l, const Value &object) return Value::undefinedValue().asReturnedValue(); ScopedCallData callData(scope, 0); - callData->thisObject = object; + callData->thisObject = *object; return getter->call(callData); } } @@ -193,9 +193,9 @@ ReturnedValue Lookup::getterAccessor0(Lookup *l, const Value &object) return getterGeneric(l, object); } -ReturnedValue Lookup::getterAccessor1(Lookup *l, const Value &object) +ReturnedValue Lookup::getterAccessor1(Lookup *l, const ValueRef object) { - if (Object *o = object.asObject()) { + if (Object *o = object->asObject()) { if (l->classList[0] == o->internalClass && l->classList[1] == o->prototype()->internalClass) { Scope scope(o->engine()); @@ -204,7 +204,7 @@ ReturnedValue Lookup::getterAccessor1(Lookup *l, const Value &object) return Value::undefinedValue().asReturnedValue(); ScopedCallData callData(scope, 0); - callData->thisObject = object; + callData->thisObject = *object; return getter->call(callData); } } @@ -212,9 +212,9 @@ ReturnedValue Lookup::getterAccessor1(Lookup *l, const Value &object) return getterGeneric(l, object); } -ReturnedValue Lookup::getterAccessor2(Lookup *l, const Value &object) +ReturnedValue Lookup::getterAccessor2(Lookup *l, const ValueRef object) { - if (Object *o = object.asObject()) { + if (Object *o = object->asObject()) { if (l->classList[0] == o->internalClass) { o = o->prototype(); if (l->classList[1] == o->internalClass) { @@ -226,7 +226,7 @@ ReturnedValue Lookup::getterAccessor2(Lookup *l, const Value &object) return Value::undefinedValue().asReturnedValue(); ScopedCallData callData(scope, 0); - callData->thisObject = object; + callData->thisObject = *object; return getter->call(callData); } } @@ -237,9 +237,9 @@ ReturnedValue Lookup::getterAccessor2(Lookup *l, const Value &object) } -ReturnedValue Lookup::primitiveGetter0(Lookup *l, const Value &object) +ReturnedValue Lookup::primitiveGetter0(Lookup *l, const ValueRef object) { - if (object.type() == l->type) { + if (object->type() == l->type) { Object *o = l->proto; if (l->classList[0] == o->internalClass) return o->memberData[l->index].value.asReturnedValue(); @@ -248,9 +248,9 @@ ReturnedValue Lookup::primitiveGetter0(Lookup *l, const Value &object) return getterGeneric(l, object); } -ReturnedValue Lookup::primitiveGetter1(Lookup *l, const Value &object) +ReturnedValue Lookup::primitiveGetter1(Lookup *l, const ValueRef object) { - if (object.type() == l->type) { + if (object->type() == l->type) { Object *o = l->proto; if (l->classList[0] == o->internalClass && l->classList[1] == o->prototype()->internalClass) @@ -260,9 +260,9 @@ ReturnedValue Lookup::primitiveGetter1(Lookup *l, const Value &object) return getterGeneric(l, object); } -ReturnedValue Lookup::primitiveGetterAccessor0(Lookup *l, const Value &object) +ReturnedValue Lookup::primitiveGetterAccessor0(Lookup *l, const ValueRef object) { - if (object.type() == l->type) { + if (object->type() == l->type) { Object *o = l->proto; if (l->classList[0] == o->internalClass) { Scope scope(o->engine()); @@ -272,7 +272,7 @@ ReturnedValue Lookup::primitiveGetterAccessor0(Lookup *l, const Value &object) return Value::undefinedValue().asReturnedValue(); ScopedCallData callData(scope, 0); - callData->thisObject = object; + callData->thisObject = *object; return getter->call(callData); } } @@ -280,9 +280,9 @@ ReturnedValue Lookup::primitiveGetterAccessor0(Lookup *l, const Value &object) return getterGeneric(l, object); } -ReturnedValue Lookup::primitiveGetterAccessor1(Lookup *l, const Value &object) +ReturnedValue Lookup::primitiveGetterAccessor1(Lookup *l, const ValueRef object) { - if (object.type() == l->type) { + if (object->type() == l->type) { Object *o = l->proto; if (l->classList[0] == o->internalClass && l->classList[1] == o->prototype()->internalClass) { @@ -293,7 +293,7 @@ ReturnedValue Lookup::primitiveGetterAccessor1(Lookup *l, const Value &object) return Value::undefinedValue().asReturnedValue(); ScopedCallData callData(scope, 0); - callData->thisObject = object; + callData->thisObject = *object; return getter->call(callData); } } @@ -301,9 +301,9 @@ ReturnedValue Lookup::primitiveGetterAccessor1(Lookup *l, const Value &object) return getterGeneric(l, object); } -ReturnedValue Lookup::stringLengthGetter(Lookup *l, const Value &object) +ReturnedValue Lookup::stringLengthGetter(Lookup *l, const ValueRef object) { - if (String *s = object.asString()) + if (String *s = object->asString()) return Value::fromUInt32(s->length()).asReturnedValue(); l->getter = getterGeneric; @@ -435,22 +435,24 @@ ReturnedValue Lookup::globalGetterAccessor2(Lookup *l, ExecutionContext *ctx) return globalGetterGeneric(l, ctx); } -void Lookup::setterGeneric(Lookup *l, const Value &object, const Value &value) +void Lookup::setterGeneric(Lookup *l, const ValueRef object, const ValueRef value) { - Object *o = object.asObject(); + Scope scope(l->name->engine()); + ScopedObject o(scope, object); if (!o) { - o = __qmljs_convert_to_object(l->name->engine()->current, ValueRef::fromRawValue(&object))->getPointer(); - o->put(l->name, value); + o = __qmljs_convert_to_object(scope.engine->current, object); + ScopedString s(scope, l->name); + o->put(s, value); return; } o->setLookup(l, value); } -void Lookup::setter0(Lookup *l, const Value &object, const Value &value) +void Lookup::setter0(Lookup *l, const ValueRef object, const ValueRef value) { - Object *o = object.asObject(); + Object *o = object->asObject(); if (o && o->internalClass == l->classList[0]) { - o->memberData[l->index].value = value; + o->memberData[l->index].value = *value; return; } @@ -458,12 +460,12 @@ void Lookup::setter0(Lookup *l, const Value &object, const Value &value) setterGeneric(l, object, value); } -void Lookup::setterInsert0(Lookup *l, const Value &object, const Value &value) +void Lookup::setterInsert0(Lookup *l, const ValueRef object, const ValueRef value) { - Object *o = object.asObject(); + Object *o = object->asObject(); if (o && o->internalClass == l->classList[0]) { if (!o->prototype()) { - o->memberData[l->index].value = value; + o->memberData[l->index].value = *value; o->internalClass = l->classList[3]; return; } @@ -473,13 +475,13 @@ void Lookup::setterInsert0(Lookup *l, const Value &object, const Value &value) setterGeneric(l, object, value); } -void Lookup::setterInsert1(Lookup *l, const Value &object, const Value &value) +void Lookup::setterInsert1(Lookup *l, const ValueRef object, const ValueRef value) { - Object *o = object.asObject(); + Object *o = object->asObject(); if (o && o->internalClass == l->classList[0]) { Object *p = o->prototype(); if (p && p->internalClass == l->classList[1]) { - o->memberData[l->index].value = value; + o->memberData[l->index].value = *value; o->internalClass = l->classList[3]; return; } @@ -489,16 +491,16 @@ void Lookup::setterInsert1(Lookup *l, const Value &object, const Value &value) setterGeneric(l, object, value); } -void Lookup::setterInsert2(Lookup *l, const Value &object, const Value &value) +void Lookup::setterInsert2(Lookup *l, const ValueRef object, const ValueRef value) { - Object *o = object.asObject(); + Object *o = object->asObject(); if (o && o->internalClass == l->classList[0]) { Object *p = o->prototype(); if (p && p->internalClass == l->classList[1]) { p = p->prototype(); if (p && p->internalClass == l->classList[2]) { o->ensureMemberIndex(l->index); - o->memberData[l->index].value = value; + o->memberData[l->index].value = *value; o->internalClass = l->classList[3]; return; } diff --git a/src/qml/jsruntime/qv4lookup_p.h b/src/qml/jsruntime/qv4lookup_p.h index b79e91028f..9966d36604 100644 --- a/src/qml/jsruntime/qv4lookup_p.h +++ b/src/qml/jsruntime/qv4lookup_p.h @@ -55,9 +55,9 @@ namespace QV4 { struct Lookup { enum { Size = 4 }; union { - ReturnedValue (*getter)(Lookup *l, const Value &object); + ReturnedValue (*getter)(Lookup *l, const ValueRef object); ReturnedValue (*globalGetter)(Lookup *l, ExecutionContext *ctx); - void (*setter)(Lookup *l, const Value &object, const Value &v); + void (*setter)(Lookup *l, const ValueRef object, const ValueRef v); }; union { InternalClass *classList[Size]; @@ -72,19 +72,19 @@ struct Lookup { uint index; String *name; - static ReturnedValue getterGeneric(Lookup *l, const Value &object); - static ReturnedValue getter0(Lookup *l, const Value &object); - static ReturnedValue getter1(Lookup *l, const Value &object); - static ReturnedValue getter2(Lookup *l, const Value &object); - static ReturnedValue getterAccessor0(Lookup *l, const Value &object); - static ReturnedValue getterAccessor1(Lookup *l, const Value &object); - static ReturnedValue getterAccessor2(Lookup *l, const Value &object); + static ReturnedValue getterGeneric(Lookup *l, const ValueRef object); + static ReturnedValue getter0(Lookup *l, const ValueRef object); + static ReturnedValue getter1(Lookup *l, const ValueRef object); + static ReturnedValue getter2(Lookup *l, const ValueRef object); + static ReturnedValue getterAccessor0(Lookup *l, const ValueRef object); + static ReturnedValue getterAccessor1(Lookup *l, const ValueRef object); + static ReturnedValue getterAccessor2(Lookup *l, const ValueRef object); - static ReturnedValue primitiveGetter0(Lookup *l, const Value &object); - static ReturnedValue primitiveGetter1(Lookup *l, const Value &object); - static ReturnedValue primitiveGetterAccessor0(Lookup *l, const Value &object); - static ReturnedValue primitiveGetterAccessor1(Lookup *l, const Value &object); - static ReturnedValue stringLengthGetter(Lookup *l, const Value &object); + static ReturnedValue primitiveGetter0(Lookup *l, const ValueRef object); + static ReturnedValue primitiveGetter1(Lookup *l, const ValueRef object); + static ReturnedValue primitiveGetterAccessor0(Lookup *l, const ValueRef object); + static ReturnedValue primitiveGetterAccessor1(Lookup *l, const ValueRef object); + static ReturnedValue stringLengthGetter(Lookup *l, const ValueRef object); static ReturnedValue globalGetterGeneric(Lookup *l, ExecutionContext *ctx); static ReturnedValue globalGetter0(Lookup *l, ExecutionContext *ctx); @@ -94,11 +94,11 @@ struct Lookup { static ReturnedValue globalGetterAccessor1(Lookup *l, ExecutionContext *ctx); static ReturnedValue globalGetterAccessor2(Lookup *l, ExecutionContext *ctx); - static void setterGeneric(Lookup *l, const Value &object, const Value &value); - static void setter0(Lookup *l, const Value &object, const Value &value); - static void setterInsert0(Lookup *l, const Value &object, const Value &value); - static void setterInsert1(Lookup *l, const Value &object, const Value &value); - static void setterInsert2(Lookup *l, const Value &object, const Value &value); + static void setterGeneric(Lookup *l, const ValueRef object, const ValueRef value); + static void setter0(Lookup *l, const ValueRef object, const ValueRef value); + static void setterInsert0(Lookup *l, const ValueRef object, const ValueRef value); + static void setterInsert1(Lookup *l, const ValueRef object, const ValueRef value); + static void setterInsert2(Lookup *l, const ValueRef object, const ValueRef value); Property *lookup(Object *obj, PropertyAttributes *attrs); diff --git a/src/qml/jsruntime/qv4managed.cpp b/src/qml/jsruntime/qv4managed.cpp index 776819a75f..c469293f5e 100644 --- a/src/qml/jsruntime/qv4managed.cpp +++ b/src/qml/jsruntime/qv4managed.cpp @@ -192,7 +192,7 @@ ReturnedValue Managed::getLookup(Managed *m, Lookup *) return 0; } -void Managed::setLookup(Managed *m, Lookup *, const Value &) +void Managed::setLookup(Managed *m, Lookup *, const ValueRef) { m->engine()->current->throwTypeError(); } @@ -211,3 +211,13 @@ ReturnedValue Managed::getIndexed(uint index, bool *hasProperty) { return vtbl->getIndexed(this, index, hasProperty); } + +void Managed::put(const StringRef name, const ValueRef value) +{ + vtbl->put(this, name, value); +} + +void Managed::setLookup(Lookup *l, const ValueRef v) +{ + vtbl->setLookup(this, l, v); +} diff --git a/src/qml/jsruntime/qv4managed_p.h b/src/qml/jsruntime/qv4managed_p.h index 71b3573922..00ad52a9ef 100644 --- a/src/qml/jsruntime/qv4managed_p.h +++ b/src/qml/jsruntime/qv4managed_p.h @@ -99,14 +99,14 @@ struct ManagedVTable bool (*hasInstance)(Managed *, const Value &value); ReturnedValue (*get)(Managed *, const StringRef name, bool *hasProperty); ReturnedValue (*getIndexed)(Managed *, uint index, bool *hasProperty); - void (*put)(Managed *, String *name, const Value &value); + void (*put)(Managed *, const StringRef name, const ValueRef value); void (*putIndexed)(Managed *, uint index, const Value &value); PropertyAttributes (*query)(const Managed *, String *name); PropertyAttributes (*queryIndexed)(const Managed *, uint index); bool (*deleteProperty)(Managed *m, String *name); bool (*deleteIndexedProperty)(Managed *m, uint index); ReturnedValue (*getLookup)(Managed *m, Lookup *l); - void (*setLookup)(Managed *m, Lookup *l, const Value &v); + void (*setLookup)(Managed *m, Lookup *l, const ValueRef v); bool (*isEqualTo)(Managed *m, Managed *other); Property *(*advanceIterator)(Managed *m, ObjectIterator *it, String **name, uint *index, PropertyAttributes *attributes); const char *className; @@ -265,8 +265,7 @@ public: ReturnedValue call(CallData *d); ReturnedValue get(const StringRef name, bool *hasProperty = 0); ReturnedValue getIndexed(uint index, bool *hasProperty = 0); - void put(String *name, const Value &value) - { vtbl->put(this, name, value); } + void put(const StringRef name, const ValueRef value); void putIndexed(uint index, const Value &value) { vtbl->putIndexed(this, index, value); } PropertyAttributes query(String *name) const @@ -280,8 +279,7 @@ public: { return vtbl->deleteIndexedProperty(this, index); } ReturnedValue getLookup(Lookup *l) { return vtbl->getLookup(this, l); } - void setLookup(Lookup *l, const Value &v) - { vtbl->setLookup(this, l, v); } + void setLookup(Lookup *l, const ValueRef v); bool isEqualTo(Managed *other) { return vtbl->isEqualTo(this, other); } @@ -293,7 +291,7 @@ public: static ReturnedValue construct(Managed *m, CallData *d); static ReturnedValue call(Managed *m, CallData *); static ReturnedValue getLookup(Managed *m, Lookup *); - static void setLookup(Managed *m, Lookup *l, const Value &v); + static void setLookup(Managed *m, Lookup *l, const ValueRef v); static bool isEqualTo(Managed *m, Managed *other); uint internalType() const { diff --git a/src/qml/jsruntime/qv4object.cpp b/src/qml/jsruntime/qv4object.cpp index 168933f8e5..44c248dd1a 100644 --- a/src/qml/jsruntime/qv4object.cpp +++ b/src/qml/jsruntime/qv4object.cpp @@ -122,9 +122,11 @@ void Object::destroy(Managed *that) static_cast(that)->~Object(); } -void Object::put(ExecutionContext *ctx, const QString &name, const Value &value) +void Object::put(ExecutionContext *ctx, const QString &name, const ValueRef value) { - put(ctx->engine->newString(name), value); + Scope scope(ctx); + ScopedString n(scope, ctx->engine->newString(name)); + put(n, value); } ReturnedValue Object::getValue(const Value &thisObject, const Property *p, PropertyAttributes attrs) @@ -173,7 +175,7 @@ void Object::inplaceBinOp(ExecutionContext *ctx, BinOp op, String *name, const V ScopedString n(scope, name); ScopedValue v(scope, get(n)); ScopedValue result(scope, op(v, rhs)); - put(name, result); + put(n, result); } void Object::inplaceBinOp(ExecutionContext *ctx, BinOp op, const ValueRef index, const ValueRef rhs) @@ -198,7 +200,7 @@ void Object::inplaceBinOp(ExecutionContext *ctx, BinOpContext op, String *name, ScopedString n(scope, name); ScopedValue v(scope, get(n)); ScopedValue result(scope, op(ctx, v, rhs)); - put(name, result); + put(n, result); } void Object::inplaceBinOp(ExecutionContext *ctx, BinOpContext op, const ValueRef index, const ValueRef rhs) @@ -465,11 +467,9 @@ ReturnedValue Object::getIndexed(Managed *m, uint index, bool *hasProperty) return static_cast(m)->internalGetIndexed(index, hasProperty); } -void Object::put(Managed *m, String *name, const Value &value) +void Object::put(Managed *m, const StringRef name, const ValueRef value) { - Scope scope(m->engine()); - ScopedString s(scope, name); - static_cast(m)->internalPut(s, value); + static_cast(m)->internalPut(name, value); } void Object::putIndexed(Managed *m, uint index, const Value &value) @@ -545,9 +545,10 @@ ReturnedValue Object::getLookup(Managed *m, Lookup *l) return Value::undefinedValue().asReturnedValue(); } -void Object::setLookup(Managed *m, Lookup *l, const Value &value) +void Object::setLookup(Managed *m, Lookup *l, const ValueRef value) { - Object *o = static_cast(m); + Scope scope(m->engine()); + ScopedObject o(scope, static_cast(m)); InternalClass *c = o->internalClass; uint idx = c->find(l->name); @@ -556,17 +557,18 @@ void Object::setLookup(Managed *m, Lookup *l, const Value &value) l->classList[0] = o->internalClass; l->index = idx; l->setter = Lookup::setter0; - o->memberData[idx].value = value; + o->memberData[idx].value = *value; return; } if (idx != UINT_MAX) { - o->putValue(o->memberData + idx, o->internalClass->propertyData[idx], value); + o->putValue(o->memberData + idx, o->internalClass->propertyData[idx], *value); return; } } - o->put(l->name, value); + ScopedString s(scope, l->name); + o->put(s, value); if (o->internalClass == c) return; @@ -717,11 +719,11 @@ ReturnedValue Object::internalGetIndexed(uint index, bool *hasProperty) // Section 8.12.5 -void Object::internalPut(const StringRef name, const Value &value) +void Object::internalPut(const StringRef name, const ValueRef value) { uint idx = name->asArrayIndex(); if (idx != UINT_MAX) - return putIndexed(idx, value); + return putIndexed(idx, *value); name->makeIdentifier(); @@ -743,14 +745,14 @@ void Object::internalPut(const StringRef name, const Value &value) goto reject; else if (isArrayObject() && name->isEqualTo(engine()->id_length)) { bool ok; - uint l = value.asArrayLength(&ok); + uint l = value->asArrayLength(&ok); if (!ok) - engine()->current->throwRangeError(value); + engine()->current->throwRangeError(*value); ok = setArrayLength(l); if (!ok) goto reject; } else { - pd->value = value; + pd->value = *value; } return; } else if (!prototype()) { @@ -778,7 +780,7 @@ void Object::internalPut(const StringRef name, const Value &value) Scope scope(engine()); ScopedCallData callData(scope, 1); - callData->args[0] = value; + callData->args[0] = *value; callData->thisObject = Value::fromObject(this); pd->setter()->call(callData); return; @@ -786,7 +788,7 @@ void Object::internalPut(const StringRef name, const Value &value) { Property *p = insertMember(name, Attr_Data); - p->value = value; + p->value = *value; return; } diff --git a/src/qml/jsruntime/qv4object_p.h b/src/qml/jsruntime/qv4object_p.h index b17146c64a..dd75187cc2 100644 --- a/src/qml/jsruntime/qv4object_p.h +++ b/src/qml/jsruntime/qv4object_p.h @@ -148,7 +148,7 @@ struct Q_QML_EXPORT Object: Managed { // // helpers // - void put(ExecutionContext *ctx, const QString &name, const Value &value); + void put(ExecutionContext *ctx, const QString &name, const ValueRef value); static ReturnedValue getValue(const Value &thisObject, const Property *p, PropertyAttributes attrs); ReturnedValue getValue(const Property *p, PropertyAttributes attrs) const { @@ -292,7 +292,7 @@ public: { return vtbl->get(this, name, hasProperty); } inline ReturnedValue getIndexed(uint idx, bool *hasProperty = 0) { return vtbl->getIndexed(this, idx, hasProperty); } - inline void put(String *name, const Value &v) + inline void put(const StringRef name, const ValueRef v) { vtbl->put(this, name, v); } inline void putIndexed(uint idx, const Value &v) { vtbl->putIndexed(this, idx, v); } @@ -312,21 +312,21 @@ protected: static void markObjects(Managed *that); static ReturnedValue get(Managed *m, const StringRef name, bool *hasProperty); static ReturnedValue getIndexed(Managed *m, uint index, bool *hasProperty); - static void put(Managed *m, String *name, const Value &value); + static void put(Managed *m, const StringRef name, const ValueRef value); static void putIndexed(Managed *m, uint index, const Value &value); static PropertyAttributes query(const Managed *m, String *name); static PropertyAttributes queryIndexed(const Managed *m, uint index); static bool deleteProperty(Managed *m, String *name); static bool deleteIndexedProperty(Managed *m, uint index); static ReturnedValue getLookup(Managed *m, Lookup *l); - static void setLookup(Managed *m, Lookup *l, const Value &v); + static void setLookup(Managed *m, Lookup *l, const ValueRef v); static Property *advanceIterator(Managed *m, ObjectIterator *it, String **name, uint *index, PropertyAttributes *attributes); private: ReturnedValue internalGet(const StringRef name, bool *hasProperty); ReturnedValue internalGetIndexed(uint index, bool *hasProperty); - void internalPut(const StringRef name, const Value &value); + void internalPut(const StringRef name, const ValueRef value); void internalPutIndexed(uint index, const Value &value); bool internalDeleteProperty(String *name); bool internalDeleteIndexedProperty(uint index); diff --git a/src/qml/jsruntime/qv4qobjectwrapper.cpp b/src/qml/jsruntime/qv4qobjectwrapper.cpp index c8488924a9..226de86a38 100644 --- a/src/qml/jsruntime/qv4qobjectwrapper.cpp +++ b/src/qml/jsruntime/qv4qobjectwrapper.cpp @@ -332,8 +332,8 @@ ReturnedValue QObjectWrapper::getQmlProperty(ExecutionContext *ctx, QQmlContextD QV4::ScopedString connect(scope, ctx->engine->newIdentifier(QStringLiteral("connect"))); QV4::ScopedString disconnect(scope, ctx->engine->newIdentifier(QStringLiteral("disconnect"))); - handler->put(connect.getPointer(), QV4::Value::fromReturnedValue(ctx->engine->functionClass->prototype->get(connect))); - handler->put(disconnect.getPointer(), QV4::Value::fromReturnedValue(ctx->engine->functionClass->prototype->get(disconnect))); + handler->put(connect, QV4::ScopedValue(scope, ctx->engine->functionClass->prototype->get(connect))); + handler->put(disconnect, QV4::ScopedValue(scope, ctx->engine->functionClass->prototype->get(disconnect))); return QV4::Value::fromObject(handler).asReturnedValue(); } else { @@ -605,7 +605,7 @@ QV4::ReturnedValue QObjectWrapper::get(Managed *m, const StringRef name, bool *h return that->getQmlProperty(v4->current, qmlContext, name.getPointer(), IgnoreRevision, hasProperty, /*includeImports*/ true); } -void QObjectWrapper::put(Managed *m, String *name, const Value &value) +void QObjectWrapper::put(Managed *m, const StringRef name, const ValueRef value) { QObjectWrapper *that = static_cast(m); ExecutionEngine *v4 = m->engine(); @@ -614,7 +614,7 @@ void QObjectWrapper::put(Managed *m, String *name, const Value &value) return; QQmlContextData *qmlContext = QV4::QmlContextWrapper::callingContext(v4); - if (!setQmlProperty(v4->current, qmlContext, that->m_object, name, QV4::QObjectWrapper::IgnoreRevision, value)) { + if (!setQmlProperty(v4->current, qmlContext, that->m_object, name.getPointer(), QV4::QObjectWrapper::IgnoreRevision, *value)) { QString error = QLatin1String("Cannot assign to non-existent property \"") + name->toQString() + QLatin1Char('\"'); v4->current->throwError(error); diff --git a/src/qml/jsruntime/qv4qobjectwrapper_p.h b/src/qml/jsruntime/qv4qobjectwrapper_p.h index 3e4abc30b9..e8c2d91da6 100644 --- a/src/qml/jsruntime/qv4qobjectwrapper_p.h +++ b/src/qml/jsruntime/qv4qobjectwrapper_p.h @@ -106,7 +106,7 @@ private: String *m_toString; static ReturnedValue get(Managed *m, const StringRef name, bool *hasProperty); - static void put(Managed *m, String *name, const Value &value); + static void put(Managed *m, const StringRef name, const ValueRef value); static PropertyAttributes query(const Managed *, String *name); static Property *advanceIterator(Managed *m, ObjectIterator *it, String **name, uint *index, PropertyAttributes *attributes); static void markObjects(Managed *that); diff --git a/src/qml/jsruntime/qv4regexp.cpp b/src/qml/jsruntime/qv4regexp.cpp index 0a10002766..076bd72adf 100644 --- a/src/qml/jsruntime/qv4regexp.cpp +++ b/src/qml/jsruntime/qv4regexp.cpp @@ -146,7 +146,7 @@ ReturnedValue RegExp::getIndexed(Managed *m, uint index, bool *hasProperty) return Value::undefinedValue().asReturnedValue(); } -void RegExp::put(Managed *m, String *name, const Value &value) +void RegExp::put(Managed *m, const StringRef name, const ValueRef value) { } diff --git a/src/qml/jsruntime/qv4regexp_p.h b/src/qml/jsruntime/qv4regexp_p.h index cae0665469..2600cac425 100644 --- a/src/qml/jsruntime/qv4regexp_p.h +++ b/src/qml/jsruntime/qv4regexp_p.h @@ -113,7 +113,7 @@ protected: static void markObjects(Managed *that); static ReturnedValue get(Managed *, const StringRef, bool *); static ReturnedValue getIndexed(Managed *m, uint index, bool *hasProperty); - static void put(Managed *m, String *name, const Value &value); + static void put(Managed *m, const StringRef name, const ValueRef value); static void putIndexed(Managed *m, uint index, const Value &value); static PropertyAttributes query(const Managed *m, String *name); static PropertyAttributes queryIndexed(const Managed *m, uint index); diff --git a/src/qml/jsruntime/qv4runtime.cpp b/src/qml/jsruntime/qv4runtime.cpp index f297762ec7..9ecb1bf103 100644 --- a/src/qml/jsruntime/qv4runtime.cpp +++ b/src/qml/jsruntime/qv4runtime.cpp @@ -645,8 +645,10 @@ Returned *__qmljs_convert_to_string(ExecutionContext *ctx, const ValueRe void __qmljs_set_property(ExecutionContext *ctx, const ValueRef object, String *name, const ValueRef value) { - Object *o = object->toObject(ctx); - o->put(name, *value); + Scope scope(ctx); + ScopedObject o(scope, object->toObject(ctx)); + ScopedString n(scope, name); + o->put(n, value); } ReturnedValue __qmljs_get_element(ExecutionContext *ctx, const ValueRef object, const ValueRef index) @@ -692,7 +694,7 @@ ReturnedValue __qmljs_get_element(ExecutionContext *ctx, const ValueRef object, void __qmljs_set_element(ExecutionContext *ctx, const ValueRef object, const ValueRef index, const ValueRef value) { Scope scope(ctx); - Object *o = object->toObject(ctx); + ScopedObject o(scope, object->toObject(ctx)); uint idx = index->asArrayIndex(); if (idx < UINT_MAX) { @@ -719,7 +721,7 @@ void __qmljs_set_element(ExecutionContext *ctx, const ValueRef object, const Val } ScopedCallData callData(scope, 1); - callData->thisObject = Value::fromObject(o); + callData->thisObject = o; callData->args[0] = *value; setter->call(callData); return; @@ -729,8 +731,8 @@ void __qmljs_set_element(ExecutionContext *ctx, const ValueRef object, const Val return; } - String *name = index->toString(ctx); - o->put(name, *value); + ScopedString name(scope, index->toString(ctx)); + o->put(name, value); } ReturnedValue __qmljs_foreach_iterator_object(ExecutionContext *ctx, const ValueRef in) @@ -756,7 +758,7 @@ ReturnedValue __qmljs_foreach_next_property_name(const ValueRef foreach_iterator void __qmljs_set_activation_property(ExecutionContext *ctx, String *name, const ValueRef value) { - ctx->setProperty(name, *value); + ctx->setProperty(name, value); } ReturnedValue __qmljs_get_property(ExecutionContext *ctx, const ValueRef object, String *n) diff --git a/src/qml/jsruntime/qv4serialize.cpp b/src/qml/jsruntime/qv4serialize.cpp index 48f2272e7d..cabe326d13 100644 --- a/src/qml/jsruntime/qv4serialize.cpp +++ b/src/qml/jsruntime/qv4serialize.cpp @@ -333,11 +333,13 @@ ReturnedValue Serialize::deserialize(const char *&data, QV8Engine *engine) quint32 size = headersize(header); Scoped o(scope, v4->newObject()); ScopedValue name(scope); + ScopedString n(scope); ScopedValue value(scope); for (quint32 ii = 0; ii < size; ++ii) { name = deserialize(data, engine); value = deserialize(data, engine); - o->put(name->asString(), value); + n = name.asReturnedValue(); + o->put(n, value); } return o.asReturnedValue(); } diff --git a/src/qml/jsruntime/qv4string.cpp b/src/qml/jsruntime/qv4string.cpp index 0323f3c1d3..73e55a09dc 100644 --- a/src/qml/jsruntime/qv4string.cpp +++ b/src/qml/jsruntime/qv4string.cpp @@ -173,7 +173,7 @@ ReturnedValue String::getIndexed(Managed *m, uint index, bool *hasProperty) return engine->stringClass->prototype->getValue(Value::fromString(that), pd, attrs); } -void String::put(Managed *m, String *name, const Value &value) +void String::put(Managed *m, const StringRef name, const ValueRef value) { Scope scope(m->engine()); String *that = static_cast(m); diff --git a/src/qml/jsruntime/qv4string_p.h b/src/qml/jsruntime/qv4string_p.h index 36eb5103eb..4289725cf9 100644 --- a/src/qml/jsruntime/qv4string_p.h +++ b/src/qml/jsruntime/qv4string_p.h @@ -129,7 +129,7 @@ protected: static void destroy(Managed *); static ReturnedValue get(Managed *m, const StringRef name, bool *hasProperty); static ReturnedValue getIndexed(Managed *m, uint index, bool *hasProperty); - static void put(Managed *m, String *name, const Value &value); + static void put(Managed *m, const StringRef name, const ValueRef value); static void putIndexed(Managed *m, uint index, const Value &value); static PropertyAttributes query(const Managed *m, String *name); static PropertyAttributes queryIndexed(const Managed *m, uint index); diff --git a/src/qml/jsruntime/qv4stringobject.cpp b/src/qml/jsruntime/qv4stringobject.cpp index 22e746311c..26f662d005 100644 --- a/src/qml/jsruntime/qv4stringobject.cpp +++ b/src/qml/jsruntime/qv4stringobject.cpp @@ -379,7 +379,7 @@ ReturnedValue StringPrototype::method_match(SimpleCallContext *context) return exec->call(callData); ScopedString lastIndex(scope, context->engine->newString(QStringLiteral("lastIndex"))); - rx->put(lastIndex.getPointer(), Value::fromInt32(0)); + rx->put(lastIndex, ScopedValue(scope, Value::fromInt32(0))); Scoped a(scope, context->engine->newArrayObject()); double previousLastIndex = 0; @@ -396,7 +396,7 @@ ReturnedValue StringPrototype::method_match(SimpleCallContext *context) double thisIndex = index->toInteger(); if (previousLastIndex == thisIndex) { previousLastIndex = thisIndex + 1; - rx->put(lastIndex.getPointer(), Value::fromDouble(previousLastIndex)); + rx->put(lastIndex, ScopedValue(scope, Value::fromDouble(previousLastIndex))); } else { previousLastIndex = thisIndex; } diff --git a/src/qml/qml/qqmlcontextwrapper.cpp b/src/qml/qml/qqmlcontextwrapper.cpp index 40b90037d8..e1c75f2f26 100644 --- a/src/qml/qml/qqmlcontextwrapper.cpp +++ b/src/qml/qml/qqmlcontextwrapper.cpp @@ -272,7 +272,7 @@ ReturnedValue QmlContextWrapper::get(Managed *m, const StringRef name, bool *has return Value::undefinedValue().asReturnedValue(); } -void QmlContextWrapper::put(Managed *m, String *name, const Value &value) +void QmlContextWrapper::put(Managed *m, const StringRef name, const ValueRef value) { ExecutionEngine *v4 = m->engine(); QV4::Scope scope(v4); @@ -293,10 +293,9 @@ void QmlContextWrapper::put(Managed *m, String *name, const Value &value) } PropertyAttributes attrs; - ScopedString n(scope, name); - Property *pd = wrapper->__getOwnProperty__(n, &attrs); + Property *pd = wrapper->__getOwnProperty__(name, &attrs); if (pd) { - wrapper->putValue(pd, attrs, value); + wrapper->putValue(pd, attrs, *value); return; } @@ -314,18 +313,18 @@ void QmlContextWrapper::put(Managed *m, String *name, const Value &value) while (context) { // Search context properties - if (context->propertyNames.count() && -1 != context->propertyNames.value(name)) + if (context->propertyNames.count() && -1 != context->propertyNames.value(name.getPointer())) return; // Search scope object if (scopeObject && - QV4::QObjectWrapper::setQmlProperty(v4->current, context, scopeObject, name, QV4::QObjectWrapper::CheckRevision, value)) + QV4::QObjectWrapper::setQmlProperty(v4->current, context, scopeObject, name.getPointer(), QV4::QObjectWrapper::CheckRevision, *value)) return; scopeObject = 0; // Search context object if (context->contextObject && - QV4::QObjectWrapper::setQmlProperty(v4->current, context, context->contextObject, name, QV4::QObjectWrapper::CheckRevision, value)) + QV4::QObjectWrapper::setQmlProperty(v4->current, context, context->contextObject, name.getPointer(), QV4::QObjectWrapper::CheckRevision, *value)) return; context = context->parent; diff --git a/src/qml/qml/qqmlcontextwrapper_p.h b/src/qml/qml/qqmlcontextwrapper_p.h index f0169cc739..6660e1ab29 100644 --- a/src/qml/qml/qqmlcontextwrapper_p.h +++ b/src/qml/qml/qqmlcontextwrapper_p.h @@ -83,7 +83,7 @@ struct Q_QML_EXPORT QmlContextWrapper : Object void setReadOnly(bool b) { readOnly = b; } static ReturnedValue get(Managed *m, const StringRef name, bool *hasProperty); - static void put(Managed *m, String *name, const Value &value); + static void put(Managed *m, const StringRef name, const ValueRef value); static void destroy(Managed *that); diff --git a/src/qml/qml/qqmllistwrapper.cpp b/src/qml/qml/qqmllistwrapper.cpp index 517c6c46db..395a832c6e 100644 --- a/src/qml/qml/qqmllistwrapper.cpp +++ b/src/qml/qml/qqmllistwrapper.cpp @@ -131,7 +131,7 @@ ReturnedValue QmlListWrapper::getIndexed(Managed *m, uint index, bool *hasProper return Value::undefinedValue().asReturnedValue(); } -void QmlListWrapper::put(Managed *m, String *name, const Value &value) +void QmlListWrapper::put(Managed *m, const StringRef name, const ValueRef value) { // doesn't do anything. Should we throw? Q_UNUSED(m); diff --git a/src/qml/qml/qqmllistwrapper_p.h b/src/qml/qml/qqmllistwrapper_p.h index 4bc1e95753..ea35ad091d 100644 --- a/src/qml/qml/qqmllistwrapper_p.h +++ b/src/qml/qml/qqmllistwrapper_p.h @@ -83,7 +83,7 @@ public: static ReturnedValue get(Managed *m, const StringRef name, bool *hasProperty); static ReturnedValue getIndexed(Managed *m, uint index, bool *hasProperty); - static void put(Managed *m, String *name, const Value &value); + static void put(Managed *m, const StringRef name, const ValueRef value); static Property *advanceIterator(Managed *m, ObjectIterator *it, String **name, uint *index, PropertyAttributes *attributes); static void destroy(Managed *that); diff --git a/src/qml/qml/qqmltypewrapper.cpp b/src/qml/qml/qqmltypewrapper.cpp index f7e831cb80..2b27f48d6e 100644 --- a/src/qml/qml/qqmltypewrapper.cpp +++ b/src/qml/qml/qqmltypewrapper.cpp @@ -224,7 +224,7 @@ ReturnedValue QmlTypeWrapper::get(Managed *m, const StringRef name, bool *hasPro } -void QmlTypeWrapper::put(Managed *m, String *name, const Value &value) +void QmlTypeWrapper::put(Managed *m, const StringRef name, const ValueRef value) { QmlTypeWrapper *w = m->as(); QV4::ExecutionEngine *v4 = m->engine(); @@ -239,7 +239,7 @@ void QmlTypeWrapper::put(Managed *m, String *name, const Value &value) QObject *object = w->object; QObject *ao = qmlAttachedPropertiesObjectById(type->attachedPropertiesId(), object); if (ao) - QV4::QObjectWrapper::setQmlProperty(v4->current, context, ao, name, QV4::QObjectWrapper::IgnoreRevision, value); + QV4::QObjectWrapper::setQmlProperty(v4->current, context, ao, name.getPointer(), QV4::QObjectWrapper::IgnoreRevision, *value); } else if (type && type->isSingleton()) { QQmlEngine *e = v8engine->engine(); QQmlType::SingletonInstanceInfo *siinfo = type->singletonInstanceInfo(); @@ -247,7 +247,7 @@ void QmlTypeWrapper::put(Managed *m, String *name, const Value &value) QObject *qobjectSingleton = siinfo->qobjectApi(e); if (qobjectSingleton) { - QV4::QObjectWrapper::setQmlProperty(v4->current, context, qobjectSingleton, name, QV4::QObjectWrapper::IgnoreRevision, value); + QV4::QObjectWrapper::setQmlProperty(v4->current, context, qobjectSingleton, name.getPointer(), QV4::QObjectWrapper::IgnoreRevision, *value); } else if (!siinfo->scriptApi(e).isUndefined()) { QV4::Object *apiprivate = QJSValuePrivate::get(siinfo->scriptApi(e))->value.asObject(); if (!apiprivate) { diff --git a/src/qml/qml/qqmltypewrapper_p.h b/src/qml/qml/qqmltypewrapper_p.h index 770c50cc64..6c762a2d19 100644 --- a/src/qml/qml/qqmltypewrapper_p.h +++ b/src/qml/qml/qqmltypewrapper_p.h @@ -83,7 +83,7 @@ public: static ReturnedValue get(Managed *m, const StringRef name, bool *hasProperty); - static void put(Managed *m, String *name, const Value &value); + static void put(Managed *m, const StringRef name, const ValueRef value); static PropertyAttributes query(const Managed *, String *name); static void destroy(Managed *that); diff --git a/src/qml/qml/qqmlvaluetypewrapper.cpp b/src/qml/qml/qqmlvaluetypewrapper.cpp index ca6fa1f277..e38bc191dd 100644 --- a/src/qml/qml/qqmlvaluetypewrapper.cpp +++ b/src/qml/qml/qqmlvaluetypewrapper.cpp @@ -326,7 +326,7 @@ ReturnedValue QmlValueTypeWrapper::get(Managed *m, const StringRef name, bool *h #undef VALUE_TYPE_ACCESSOR } -void QmlValueTypeWrapper::put(Managed *m, String *name, const Value &value) +void QmlValueTypeWrapper::put(Managed *m, const StringRef name, const ValueRef value) { ExecutionEngine *v4 = m->engine(); Scope scope(v4); @@ -350,7 +350,7 @@ void QmlValueTypeWrapper::put(Managed *m, String *name, const Value &value) QQmlBinding *newBinding = 0; - QV4::FunctionObject *f = value.asFunctionObject(); + QV4::ScopedFunctionObject f(scope, value); if (f) { if (!f->bindingKeyFlag) { // assigning a JS function to a non-var-property is not allowed. @@ -372,7 +372,7 @@ void QmlValueTypeWrapper::put(Managed *m, String *name, const Value &value) QV4::ExecutionEngine::StackFrame frame = v4->currentStackFrame(); - newBinding = new QQmlBinding(value, reference->object, context, + newBinding = new QQmlBinding(*value, reference->object, context, frame.source, qmlSourceCoordinate(frame.line), qmlSourceCoordinate(frame.column)); newBinding->setTarget(reference->object, cacheData, context); newBinding->setEvaluateFlags(newBinding->evaluateFlags() | @@ -385,7 +385,7 @@ void QmlValueTypeWrapper::put(Managed *m, String *name, const Value &value) oldBinding->destroy(); if (!f) { - QVariant v = r->v8->toVariant(value, -1); + QVariant v = r->v8->toVariant(*value, -1); if (p.isEnumType() && (QMetaType::Type)v.type() == QMetaType::Double) v = v.toInt(); @@ -409,7 +409,7 @@ void QmlValueTypeWrapper::put(Managed *m, String *name, const Value &value) if (index == -1) return; - QVariant v = r->v8->toVariant(value, -1); + QVariant v = r->v8->toVariant(*value, -1); r->type->setValue(copy->value); QMetaProperty p = r->type->metaObject()->property(index); diff --git a/src/qml/qml/qqmlvaluetypewrapper_p.h b/src/qml/qml/qqmlvaluetypewrapper_p.h index 5e1256f8a1..1ff04f6104 100644 --- a/src/qml/qml/qqmlvaluetypewrapper_p.h +++ b/src/qml/qml/qqmlvaluetypewrapper_p.h @@ -84,7 +84,7 @@ public: static ReturnedValue get(Managed *m, const StringRef name, bool *hasProperty); - static void put(Managed *m, String *name, const Value &value); + static void put(Managed *m, const StringRef name, const ValueRef value); static void destroy(Managed *that); static bool isEqualTo(Managed *m, Managed *other); static PropertyAttributes query(const Managed *, String *name); diff --git a/src/qml/qml/qqmlxmlhttprequest.cpp b/src/qml/qml/qqmlxmlhttprequest.cpp index aa2ac897cc..79b9344994 100644 --- a/src/qml/qml/qqmlxmlhttprequest.cpp +++ b/src/qml/qml/qqmlxmlhttprequest.cpp @@ -105,9 +105,9 @@ static ReturnedValue constructMeObject(const Value &thisObj, QV8Engine *e) ExecutionEngine *v4 = QV8Engine::getV4(e); Scope scope(v4); Scoped meObj(scope, v4->newObject()); - meObj->put(v4->newString(QStringLiteral("ThisObject")), thisObj); + meObj->put(ScopedString(scope, v4->newString(QStringLiteral("ThisObject"))), ScopedValue(scope, thisObj)); ScopedValue v(scope, QmlContextWrapper::qmlScope(e, e->callingContext(), 0)); - meObj->put(v4->newString(QStringLiteral("ActivationObject")), v); + meObj->put(ScopedString(scope, v4->newString(QStringLiteral("ActivationObject"))), v); return meObj.asReturnedValue(); } diff --git a/src/qml/qml/v8/qqmlbuiltinfunctions.cpp b/src/qml/qml/v8/qqmlbuiltinfunctions.cpp index 816680e1d9..c5cba16f48 100644 --- a/src/qml/qml/v8/qqmlbuiltinfunctions.cpp +++ b/src/qml/qml/v8/qqmlbuiltinfunctions.cpp @@ -96,14 +96,16 @@ QV4::QtObject::QtObject(ExecutionEngine *v4, QQmlEngine *qmlEngine) // Set all the enums from the "Qt" namespace const QMetaObject *qtMetaObject = StaticQtMetaObject::get(); + ScopedString str(scope); + ScopedValue v(scope); for (int ii = 0; ii < qtMetaObject->enumeratorCount(); ++ii) { QMetaEnum enumerator = qtMetaObject->enumerator(ii); for (int jj = 0; jj < enumerator.keyCount(); ++jj) { - put(v4->newString(enumerator.key(jj)), QV4::Value::fromInt32(enumerator.value(jj))); + put((str = v4->newString(enumerator.key(jj))), (v = QV4::Value::fromInt32(enumerator.value(jj)))); } } - put(v4->newString("Asynchronous"), QV4::Value::fromInt32(0)); - put(v4->newString("Synchronous"), QV4::Value::fromInt32(1)); + put((str = v4->newString("Asynchronous")), (v = QV4::Value::fromInt32(0))); + put((str = v4->newString("Synchronous")), (v = QV4::Value::fromInt32(1))); defineDefaultProperty(QStringLiteral("include"), QV4Include::method_include); defineDefaultProperty(QStringLiteral("isQtObject"), method_isQtObject); @@ -946,19 +948,22 @@ ReturnedValue QtObject::method_createQmlObject(SimpleCallContext *ctx) QString errorstr = QLatin1String("Qt.createQmlObject(): failed to create object: "); QV4::Scoped qmlerrors(scope, v4->newArrayObject()); + QV4::ScopedObject qmlerror(scope); + QV4::ScopedString s(scope); + QV4::ScopedValue v(scope); for (int ii = 0; ii < errors.count(); ++ii) { const QQmlError &error = errors.at(ii); errorstr += QLatin1String("\n ") + error.toString(); - QV4::Scoped qmlerror(scope, 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"), Value::fromString(v4->newString(error.url().toString()))); - qmlerror->put(v4->newString("message"), Value::fromString(v4->newString(error.description()))); + qmlerror = v4->newObject(); + qmlerror->put((s = v4->newString("lineNumber")), (v = QV4::Value::fromInt32(error.line()))); + qmlerror->put((s = v4->newString("columnNumber")), (v = QV4::Value::fromInt32(error.column()))); + qmlerror->put((s = v4->newString("fileName")), (v = Value::fromString(v4->newString(error.url().toString())))); + qmlerror->put((s = v4->newString("message")), (v = Value::fromString(v4->newString(error.description())))); qmlerrors->putIndexed(ii, qmlerror.asValue()); } Scoped errorObject(scope, v4->newErrorObject(Value::fromString(v4->newString(errorstr)))); - errorObject->put(v4->newString("qmlErrors"), qmlerrors.asValue()); + errorObject->put((s = v4->newString("qmlErrors")), qmlerrors); return errorObject.asReturnedValue(); } }; diff --git a/src/qml/qml/v8/qv4domerrors_p.h b/src/qml/qml/v8/qv4domerrors_p.h index ce6fb9edea..3742e37114 100644 --- a/src/qml/qml/v8/qv4domerrors_p.h +++ b/src/qml/qml/v8/qv4domerrors_p.h @@ -79,7 +79,7 @@ QT_BEGIN_NAMESPACE #define V4THROW_DOM(error, string) { \ QV4::ScopedValue v(scope, QV4::Value::fromString(ctx, QStringLiteral(string))); \ QV4::Scoped ex(scope, ctx->engine->newErrorObject(v)); \ - ex->put(ctx->engine->newIdentifier(QStringLiteral("code")), QV4::Value::fromInt32(error)); \ + ex->put(QV4::ScopedString(scope, ctx->engine->newIdentifier(QStringLiteral("code"))), QV4::ScopedValue(scope, QV4::Value::fromInt32(error))); \ ctx->throwError(ex); \ } diff --git a/src/qml/qml/v8/qv8engine.cpp b/src/qml/qml/v8/qv8engine.cpp index 38c0902a7e..70c3104ffa 100644 --- a/src/qml/qml/v8/qv8engine.cpp +++ b/src/qml/qml/v8/qv8engine.cpp @@ -212,9 +212,11 @@ static QV4::ReturnedValue objectFromVariantMap(QV8Engine *engine, const QVariant { QV4::ExecutionEngine *e = QV8Engine::getV4(engine); QV4::Scope scope(e); - QV4::Scoped o(scope, e->newObject()); + QV4::ScopedObject o(scope, e->newObject()); + QV4::ScopedString s(scope); + QV4::ScopedValue v(scope); for (QVariantMap::ConstIterator iter = map.begin(); iter != map.end(); ++iter) - o->put(e->newString(iter.key()), QV4::Value::fromReturnedValue(engine->fromVariant(iter.value()))); + o->put((s = e->newString(iter.key())), (v = engine->fromVariant(iter.value()))); return o.asReturnedValue(); } diff --git a/src/qml/types/qquickworkerscript.cpp b/src/qml/types/qquickworkerscript.cpp index d60f7b213d..02fae8c292 100644 --- a/src/qml/types/qquickworkerscript.cpp +++ b/src/qml/types/qquickworkerscript.cpp @@ -147,7 +147,7 @@ public: QQuickWorkerScriptEnginePrivate *p; - QV4::Value sendFunction(int id); + QV4::ReturnedValue sendFunction(int id); QV4::PersistentValue onmessage; private: @@ -242,7 +242,7 @@ void QQuickWorkerScriptEnginePrivate::WorkerEngine::init() } // Requires handle and context scope -QV4::Value QQuickWorkerScriptEnginePrivate::WorkerEngine::sendFunction(int id) +QV4::ReturnedValue QQuickWorkerScriptEnginePrivate::WorkerEngine::sendFunction(int id) { QV4::FunctionObject *f = createsend.value().asFunctionObject(); QV4::ExecutionContext *ctx = f->engine()->current; @@ -258,7 +258,7 @@ QV4::Value QQuickWorkerScriptEnginePrivate::WorkerEngine::sendFunction(int id) e.accept(ctx); v = e.value(); } - return v; + return v.asReturnedValue(); } QNetworkAccessManager *QQuickWorkerScriptEnginePrivate::WorkerEngine::networkAccessManager() @@ -313,9 +313,9 @@ QV4::ReturnedValue QQuickWorkerScriptEnginePrivate::getWorker(WorkerScript *scri w->setReadOnly(false); QV4::Scoped api(scope, v4->newObject()); - api->put(v4->newString("sendMessage"), workerEngine->sendFunction(script->id)); + api->put(QV4::ScopedString(scope, v4->newString("sendMessage")), QV4::ScopedValue(scope, workerEngine->sendFunction(script->id))); - script->object.value().asObject()->put(v4->newString("WorkerScript"), api.asValue()); + script->object.value().asObject()->put(QV4::ScopedString(scope, v4->newString("WorkerScript")), api); w->setReadOnly(true); } diff --git a/src/quick/items/context2d/qquickcontext2d.cpp b/src/quick/items/context2d/qquickcontext2d.cpp index 1dd4e950c6..2e0657d6c1 100644 --- a/src/quick/items/context2d/qquickcontext2d.cpp +++ b/src/quick/items/context2d/qquickcontext2d.cpp @@ -2866,7 +2866,8 @@ QV4::ReturnedValue QQuickJSContext2DPrototype::method_measureText(QV4::SimpleCal QFontMetrics fm(r->context->state.font); uint width = fm.width(ctx->arguments[0].toQStringNoThrow()); QV4::Scoped tm(scope, ctx->engine->newObject()); - tm->put(ctx->engine->newIdentifier(QStringLiteral("width")), QV4::Value::fromDouble(width)); + tm->put(QV4::ScopedString(scope, ctx->engine->newIdentifier(QStringLiteral("width"))), + QV4::ScopedValue(scope, QV4::Value::fromDouble(width))); return tm.asReturnedValue(); } return QV4::Encode::undefined(); diff --git a/src/quick/items/qquickitem.cpp b/src/quick/items/qquickitem.cpp index 341339e7b9..1585b1e6dd 100644 --- a/src/quick/items/qquickitem.cpp +++ b/src/quick/items/qquickitem.cpp @@ -3882,6 +3882,9 @@ void QQuickItem::mapFromItem(QQmlV4Function *args) const QV4::Scoped rv(scope, v4->newObject()); args->setReturnValue(rv.asValue()); + QV4::ScopedString s(scope); + QV4::ScopedValue v(scope); + qreal x = (args->length() > 1) ? (*args)[1].asDouble() : 0; qreal y = (args->length() > 2) ? (*args)[2].asDouble() : 0; @@ -3891,15 +3894,15 @@ void QQuickItem::mapFromItem(QQmlV4Function *args) const QRectF r = mapRectFromItem(itemObj, QRectF(x, y, w, h)); - rv->put(v4->newString(QStringLiteral("x")), QV4::Value::fromDouble(r.x())); - rv->put(v4->newString(QStringLiteral("y")), QV4::Value::fromDouble(r.y())); - rv->put(v4->newString(QStringLiteral("width")), QV4::Value::fromDouble(r.width())); - rv->put(v4->newString(QStringLiteral("height")), QV4::Value::fromDouble(r.height())); + rv->put((s = v4->newString(QStringLiteral("x"))), (v = QV4::Value::fromDouble(r.x()))); + rv->put((s = v4->newString(QStringLiteral("y"))), (v = QV4::Value::fromDouble(r.y()))); + rv->put((s = v4->newString(QStringLiteral("width"))), (v = QV4::Value::fromDouble(r.width()))); + rv->put((s = v4->newString(QStringLiteral("height"))), (v = QV4::Value::fromDouble(r.height()))); } else { QPointF p = mapFromItem(itemObj, QPointF(x, y)); - rv->put(v4->newString(QStringLiteral("x")), QV4::Value::fromDouble(p.x())); - rv->put(v4->newString(QStringLiteral("y")), QV4::Value::fromDouble(p.y())); + rv->put((s = v4->newString(QStringLiteral("x"))), (v = QV4::Value::fromDouble(p.x()))); + rv->put((s = v4->newString(QStringLiteral("y"))), (v = QV4::Value::fromDouble(p.y()))); } } } @@ -3960,21 +3963,24 @@ void QQuickItem::mapToItem(QQmlV4Function *args) const qreal x = (args->length() > 1) ? (*args)[1].asDouble() : 0; qreal y = (args->length() > 2) ? (*args)[2].asDouble() : 0; + QV4::ScopedString s(scope); + QV4::ScopedValue v(scope); + if (args->length() > 3) { qreal w = (*args)[3].asDouble(); qreal h = (args->length() > 4) ? (*args)[4].asDouble() : 0; QRectF r = mapRectToItem(itemObj, QRectF(x, y, w, h)); - rv->put(v4->newString(QStringLiteral("x")), QV4::Value::fromDouble(r.x())); - rv->put(v4->newString(QStringLiteral("y")), QV4::Value::fromDouble(r.y())); - rv->put(v4->newString(QStringLiteral("width")), QV4::Value::fromDouble(r.width())); - rv->put(v4->newString(QStringLiteral("height")), QV4::Value::fromDouble(r.height())); + rv->put((s = v4->newString(QStringLiteral("x"))), (v = QV4::Value::fromDouble(r.x()))); + rv->put((s = v4->newString(QStringLiteral("y"))), (v = QV4::Value::fromDouble(r.y()))); + rv->put((s = v4->newString(QStringLiteral("width"))), (v = QV4::Value::fromDouble(r.width()))); + rv->put((s = v4->newString(QStringLiteral("height"))), (v = QV4::Value::fromDouble(r.height()))); } else { QPointF p = mapToItem(itemObj, QPointF(x, y)); - rv->put(v4->newString(QStringLiteral("x")), QV4::Value::fromDouble(p.x())); - rv->put(v4->newString(QStringLiteral("y")), QV4::Value::fromDouble(p.y())); + rv->put((s = v4->newString(QStringLiteral("x"))), (v = QV4::Value::fromDouble(p.x()))); + rv->put((s = v4->newString(QStringLiteral("y"))), (v = QV4::Value::fromDouble(p.y()))); } } } diff --git a/tests/auto/qml/qv4debugger/tst_qv4debugger.cpp b/tests/auto/qml/qv4debugger/tst_qv4debugger.cpp index 3acc9c8311..9fbcb4a118 100644 --- a/tests/auto/qml/qv4debugger/tst_qv4debugger.cpp +++ b/tests/auto/qml/qv4debugger/tst_qv4debugger.cpp @@ -86,7 +86,7 @@ public: QV4::Scoped name(scope, v4->newString(functionName)); QV4::ScopedValue function(scope, v4->newBuiltinFunction(v4->rootContext, name, injectedFunction)); - v4->globalObject->put(name.getPointer(), function); + v4->globalObject->put(name, function); } signals: diff --git a/tools/v4/main.cpp b/tools/v4/main.cpp index a49245fba9..ad91b88cda 100644 --- a/tools/v4/main.cpp +++ b/tools/v4/main.cpp @@ -193,11 +193,11 @@ int main(int argc, char *argv[]) QV4::ExecutionContext *ctx = vm.rootContext; QV4::Scope scope(ctx); - QV4::Object *globalObject = vm.globalObject; - QV4::Object *print = new (ctx->engine->memoryManager) builtins::Print(ctx); - globalObject->put(vm.newIdentifier(QStringLiteral("print")), QV4::Value::fromObject(print)); - QV4::Object *gc = new (ctx->engine->memoryManager) builtins::GC(ctx); - globalObject->put(vm.newIdentifier(QStringLiteral("gc")), QV4::Value::fromObject(gc)); + QV4::ScopedObject globalObject(scope, vm.globalObject); + QV4::ScopedObject print(scope, new (ctx->engine->memoryManager) builtins::Print(ctx)); + globalObject->put(QV4::ScopedString(scope, vm.newIdentifier(QStringLiteral("print"))), print); + QV4::ScopedObject gc(scope, new (ctx->engine->memoryManager) builtins::GC(ctx)); + globalObject->put(QV4::ScopedString(scope, vm.newIdentifier(QStringLiteral("gc"))), gc); foreach (const QString &fn, args) { QFile file(fn); -- cgit v1.2.3