diff options
author | Lars Knoll <lars.knoll@digia.com> | 2013-09-22 15:32:25 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-09-22 20:12:52 +0200 |
commit | 9213d031980d32f25468eeb9177d6f403060bf00 (patch) | |
tree | afad3289bc434cdfdbed0345d77a0cda9e580980 /src | |
parent | 5c153bd8aa197025c70bdd52d6181ee5bd2197f6 (diff) |
Make qv4objectproto GC clean
Fix the remaining usages of raw pointers into the GC heap.
Change-Id: I3654a6f74fe6b59e25ed65a79ff02c29cc2cdecc
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/qml/jsruntime/qv4objectproto.cpp | 50 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4objectproto_p.h | 2 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4serialize.cpp | 4 |
3 files changed, 29 insertions, 27 deletions
diff --git a/src/qml/jsruntime/qv4objectproto.cpp b/src/qml/jsruntime/qv4objectproto.cpp index 0da2bf60b3..befc01936d 100644 --- a/src/qml/jsruntime/qv4objectproto.cpp +++ b/src/qml/jsruntime/qv4objectproto.cpp @@ -164,12 +164,13 @@ ReturnedValue ObjectPrototype::method_getOwnPropertyDescriptor(SimpleCallContext ReturnedValue ObjectPrototype::method_getOwnPropertyNames(SimpleCallContext *context) { - Object *O = context->argumentCount ? context->arguments[0].asObject() : 0; + Scope scope(context); + ScopedObject O(scope, context->argument(0)); if (!O) context->throwTypeError(); - ArrayObject *array = getOwnPropertyNames(context->engine, context->arguments[0]); - return Value::fromObject(array).asReturnedValue(); + ScopedArrayObject array(scope, getOwnPropertyNames(context->engine, context->arguments[0])); + return array.asReturnedValue(); } ReturnedValue ObjectPrototype::method_create(SimpleCallContext *ctx) @@ -385,13 +386,14 @@ ReturnedValue ObjectPrototype::method_keys(SimpleCallContext *ctx) ReturnedValue ObjectPrototype::method_toString(SimpleCallContext *ctx) { + Scope scope(ctx); if (ctx->thisObject.isUndefined()) { return Value::fromString(ctx, QStringLiteral("[object Undefined]")).asReturnedValue(); } else if (ctx->thisObject.isNull()) { return Value::fromString(ctx, QStringLiteral("[object Null]")).asReturnedValue(); } else { - Value obj = Value::fromReturnedValue(__qmljs_to_object(ctx, ValueRef(&ctx->thisObject))); - QString className = obj.objectValue()->className(); + ScopedObject obj(scope, __qmljs_to_object(ctx, ValueRef(&ctx->thisObject))); + QString className = obj->className(); return Value::fromString(ctx, QString::fromUtf8("[object %1]").arg(className)).asReturnedValue(); } } @@ -502,7 +504,8 @@ ReturnedValue ObjectPrototype::method_defineSetter(SimpleCallContext *ctx) ReturnedValue ObjectPrototype::method_get_proto(SimpleCallContext *ctx) { - Object *o = ctx->thisObject.asObject(); + Scope scope(ctx); + ScopedObject o(scope, ctx->thisObject.asObject()); if (!o) ctx->throwTypeError(); @@ -537,11 +540,10 @@ ReturnedValue ObjectPrototype::method_set_proto(SimpleCallContext *ctx) void ObjectPrototype::toPropertyDescriptor(ExecutionContext *ctx, Value v, Property *desc, PropertyAttributes *attrs) { - if (!v.isObject()) - ctx->throwTypeError(); - Scope scope(ctx); - Object *o = v.objectValue(); + ScopedObject o(scope, v); + if (!o) + ctx->throwTypeError(); attrs->clear(); desc->setGetter(0); @@ -606,7 +608,8 @@ ReturnedValue ObjectPrototype::fromPropertyDescriptor(ExecutionContext *ctx, con ExecutionEngine *engine = ctx->engine; Scope scope(engine); -// Let obj be the result of creating a new object as if by the expression new Object() where Object is the standard built-in constructor with that name. + // Let obj be the result of creating a new object as if by the expression new Object() where Object + // is the standard built-in constructor with that name. Scoped<Object> o(scope, engine->newObject()); ScopedString s(scope); @@ -637,21 +640,20 @@ ReturnedValue ObjectPrototype::fromPropertyDescriptor(ExecutionContext *ctx, con } -ArrayObject *ObjectPrototype::getOwnPropertyNames(ExecutionEngine *v4, const Value &o) +Returned<ArrayObject> *ObjectPrototype::getOwnPropertyNames(ExecutionEngine *v4, const ValueRef o) { Scope scope(v4); Scoped<ArrayObject> array(scope, v4->newArrayObject()); - Object *O = o.asObject(); - if (!O) - return array.getPointer(); - - ObjectIterator it(O, ObjectIterator::NoFlags); - ScopedValue name(scope); - while (1) { - name = it.nextPropertyNameAsString(); - if (name->isNull()) - break; - array->push_back(name); + ScopedObject O(scope, o); + if (O) { + ObjectIterator it(O.getPointer(), ObjectIterator::NoFlags); + ScopedValue name(scope); + while (1) { + name = it.nextPropertyNameAsString(); + if (name->isNull()) + break; + array->push_back(name); + } } - return array.getPointer(); + return array->asReturned<ArrayObject>(); } diff --git a/src/qml/jsruntime/qv4objectproto_p.h b/src/qml/jsruntime/qv4objectproto_p.h index 3930b39569..2f3041ab6a 100644 --- a/src/qml/jsruntime/qv4objectproto_p.h +++ b/src/qml/jsruntime/qv4objectproto_p.h @@ -94,7 +94,7 @@ struct ObjectPrototype: Object static void toPropertyDescriptor(ExecutionContext *ctx, Value v, Property *desc, PropertyAttributes *attrs); static ReturnedValue fromPropertyDescriptor(ExecutionContext *ctx, const Property *desc, PropertyAttributes attrs); - static ArrayObject *getOwnPropertyNames(ExecutionEngine *v4, const Value &o); + static Returned<ArrayObject> *getOwnPropertyNames(ExecutionEngine *v4, const ValueRef o); }; diff --git a/src/qml/jsruntime/qv4serialize.cpp b/src/qml/jsruntime/qv4serialize.cpp index ae35d6c375..e62027ab9e 100644 --- a/src/qml/jsruntime/qv4serialize.cpp +++ b/src/qml/jsruntime/qv4serialize.cpp @@ -259,7 +259,8 @@ void Serialize::serialize(QByteArray &data, const QV4::Value &v, QV8Engine *engi } // regular object - QV4::ArrayObject *properties = QV4::ObjectPrototype::getOwnPropertyNames(v4, v); + QV4::ScopedValue val(scope, v); + QV4::ScopedArrayObject properties(scope, QV4::ObjectPrototype::getOwnPropertyNames(v4, val)); quint32 length = properties->arrayLength(); if (length > 0xFFFFFF) { push(data, valueheader(WorkerUndefined)); @@ -267,7 +268,6 @@ void Serialize::serialize(QByteArray &data, const QV4::Value &v, QV8Engine *engi } push(data, valueheader(WorkerObject, length)); - QV4::ScopedValue val(scope); QV4::ScopedValue s(scope); QV4::ScopedString str(scope); for (quint32 ii = 0; ii < length; ++ii) { |