diff options
author | Lars Knoll <lars.knoll@digia.com> | 2013-09-19 10:33:59 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-09-22 01:06:20 +0200 |
commit | f64cd3f5d3fb4e466598a07aa4b9385ef93822d3 (patch) | |
tree | b8915bc4784285c021968faa290804927a1a26d0 /src | |
parent | 383fa29f95a595be4d6f4da113dff3b0dca79343 (diff) |
Convert Object::inplaceBinOp to be GC safe
Change-Id: I98a8591f4b556cc1d00271e6b389dc0d2c16e6ec
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/qml/jsruntime/qv4object.cpp | 24 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4object_p.h | 11 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4runtime.cpp | 88 |
3 files changed, 69 insertions, 54 deletions
diff --git a/src/qml/jsruntime/qv4object.cpp b/src/qml/jsruntime/qv4object.cpp index 1e45334e3a..7b9074edd5 100644 --- a/src/qml/jsruntime/qv4object.cpp +++ b/src/qml/jsruntime/qv4object.cpp @@ -169,16 +169,15 @@ void Object::putValue(Property *pd, PropertyAttributes attrs, const Value &value } -void Object::inplaceBinOp(ExecutionContext *ctx, BinOp op, String *name, const ValueRef rhs) +void Object::inplaceBinOp(ExecutionContext *ctx, BinOp op, const StringRef name, const ValueRef rhs) { Scope scope(ctx); - ScopedString n(scope, name); - ScopedValue v(scope, get(n)); + ScopedValue v(scope, get(name)); ScopedValue result(scope, op(v, rhs)); - put(n, result); + put(name, result); } -void Object::inplaceBinOp(ExecutionContext *ctx, BinOp op, const ValueRef index, const ValueRef rhs) +void Object::inplaceBinOpValue(ExecutionContext *ctx, BinOp op, const ValueRef index, const ValueRef rhs) { Scope scope(ctx); uint idx = index->asArrayIndex(); @@ -189,21 +188,19 @@ void Object::inplaceBinOp(ExecutionContext *ctx, BinOp op, const ValueRef index, putIndexed(idx, result); return; } - String *name = index->toString(ctx); - assert(name); + ScopedString name(scope, index->toString(ctx)); inplaceBinOp(ctx, op, name, rhs); } -void Object::inplaceBinOp(ExecutionContext *ctx, BinOpContext op, String *name, const ValueRef rhs) +void Object::inplaceBinOp(ExecutionContext *ctx, BinOpContext op, const StringRef name, const ValueRef rhs) { Scope scope(ctx); - ScopedString n(scope, name); - ScopedValue v(scope, get(n)); + ScopedValue v(scope, get(name)); ScopedValue result(scope, op(ctx, v, rhs)); - put(n, result); + put(name, result); } -void Object::inplaceBinOp(ExecutionContext *ctx, BinOpContext op, const ValueRef index, const ValueRef rhs) +void Object::inplaceBinOpValue(ExecutionContext *ctx, BinOpContext op, const ValueRef index, const ValueRef rhs) { Scope scope(ctx); uint idx = index->asArrayIndex(); @@ -214,8 +211,7 @@ void Object::inplaceBinOp(ExecutionContext *ctx, BinOpContext op, const ValueRef putIndexed(idx, result); return; } - String *name = index->toString(ctx); - assert(name); + ScopedString name(scope, index->toString(ctx)); inplaceBinOp(ctx, op, name, rhs); } diff --git a/src/qml/jsruntime/qv4object_p.h b/src/qml/jsruntime/qv4object_p.h index 22cf9206b6..cfcd97ab06 100644 --- a/src/qml/jsruntime/qv4object_p.h +++ b/src/qml/jsruntime/qv4object_p.h @@ -101,9 +101,6 @@ struct SyntaxErrorPrototype; struct TypeErrorPrototype; struct URIErrorPrototype; -typedef Value (*PropertyEnumeratorFunction)(Object *object); -typedef PropertyAttributes (*PropertyQueryFunction)(const Object *object, String *name); - struct Q_QML_EXPORT Object: Managed { Q_MANAGED uint memberDataAlloc; @@ -157,10 +154,10 @@ struct Q_QML_EXPORT Object: Managed { void putValue(Property *pd, PropertyAttributes attrs, const Value &value); - void inplaceBinOp(ExecutionContext *, BinOp op, String *name, const ValueRef rhs); - void inplaceBinOp(ExecutionContext *ctx, BinOp op, const ValueRef index, const ValueRef rhs); - void inplaceBinOp(ExecutionContext *ctx, BinOpContext op, String *name, const ValueRef rhs); - void inplaceBinOp(ExecutionContext *ctx, BinOpContext op, const ValueRef index, const ValueRef rhs); + void inplaceBinOp(ExecutionContext *, BinOp op, const StringRef name, const ValueRef rhs); + void inplaceBinOpValue(ExecutionContext *ctx, BinOp op, const ValueRef index, const ValueRef rhs); + void inplaceBinOp(ExecutionContext *ctx, BinOpContext op, const StringRef name, const ValueRef rhs); + void inplaceBinOpValue(ExecutionContext *ctx, BinOpContext op, const ValueRef index, const ValueRef rhs); /* The spec default: Writable: true, Enumerable: false, Configurable: true */ void defineDefaultProperty(const StringRef name, Value value); diff --git a/src/qml/jsruntime/qv4runtime.cpp b/src/qml/jsruntime/qv4runtime.cpp index 5d899096cf..735c593889 100644 --- a/src/qml/jsruntime/qv4runtime.cpp +++ b/src/qml/jsruntime/qv4runtime.cpp @@ -384,133 +384,155 @@ void __qmljs_inplace_ushr_name(ExecutionContext *ctx, String *name, const ValueR void __qmljs_inplace_bit_and_element(ExecutionContext *ctx, const ValueRef base, const ValueRef index, const ValueRef rhs) { Object *obj = base->toObject(ctx); - obj->inplaceBinOp(ctx, __qmljs_bit_and, index, rhs); + obj->inplaceBinOpValue(ctx, __qmljs_bit_and, index, rhs); } void __qmljs_inplace_bit_or_element(ExecutionContext *ctx, const ValueRef base, const ValueRef index, const ValueRef rhs) { Object *obj = base->toObject(ctx); - obj->inplaceBinOp(ctx, __qmljs_bit_or, index, rhs); + obj->inplaceBinOpValue(ctx, __qmljs_bit_or, index, rhs); } void __qmljs_inplace_bit_xor_element(ExecutionContext *ctx, const ValueRef base, const ValueRef index, const ValueRef rhs) { Object *obj = base->toObject(ctx); - obj->inplaceBinOp(ctx, __qmljs_bit_xor, index, rhs); + obj->inplaceBinOpValue(ctx, __qmljs_bit_xor, index, rhs); } void __qmljs_inplace_add_element(ExecutionContext *ctx, const ValueRef base, const ValueRef index, const ValueRef rhs) { Object *obj = base->toObject(ctx); - obj->inplaceBinOp(ctx, __qmljs_add, index, rhs); + obj->inplaceBinOpValue(ctx, __qmljs_add, index, rhs); } void __qmljs_inplace_sub_element(ExecutionContext *ctx, const ValueRef base, const ValueRef index, const ValueRef rhs) { Object *obj = base->toObject(ctx); - obj->inplaceBinOp(ctx, __qmljs_sub, index, rhs); + obj->inplaceBinOpValue(ctx, __qmljs_sub, index, rhs); } void __qmljs_inplace_mul_element(ExecutionContext *ctx, const ValueRef base, const ValueRef index, const ValueRef rhs) { Object *obj = base->toObject(ctx); - obj->inplaceBinOp(ctx, __qmljs_mul, index, rhs); + obj->inplaceBinOpValue(ctx, __qmljs_mul, index, rhs); } void __qmljs_inplace_div_element(ExecutionContext *ctx, const ValueRef base, const ValueRef index, const ValueRef rhs) { Object *obj = base->toObject(ctx); - obj->inplaceBinOp(ctx, __qmljs_div, index, rhs); + obj->inplaceBinOpValue(ctx, __qmljs_div, index, rhs); } void __qmljs_inplace_mod_element(ExecutionContext *ctx, const ValueRef base, const ValueRef index, const ValueRef rhs) { Object *obj = base->toObject(ctx); - obj->inplaceBinOp(ctx, __qmljs_mod, index, rhs); + obj->inplaceBinOpValue(ctx, __qmljs_mod, index, rhs); } void __qmljs_inplace_shl_element(ExecutionContext *ctx, const ValueRef base, const ValueRef index, const ValueRef rhs) { Object *obj = base->toObject(ctx); - obj->inplaceBinOp(ctx, __qmljs_shl, index, rhs); + obj->inplaceBinOpValue(ctx, __qmljs_shl, index, rhs); } void __qmljs_inplace_shr_element(ExecutionContext *ctx, const ValueRef base, const ValueRef index, const ValueRef rhs) { Object *obj = base->toObject(ctx); - obj->inplaceBinOp(ctx, __qmljs_shr, index, rhs); + obj->inplaceBinOpValue(ctx, __qmljs_shr, index, rhs); } void __qmljs_inplace_ushr_element(ExecutionContext *ctx, const ValueRef base, const ValueRef index, const ValueRef rhs) { Object *obj = base->toObject(ctx); - obj->inplaceBinOp(ctx, __qmljs_ushr, index, rhs); + obj->inplaceBinOpValue(ctx, __qmljs_ushr, index, rhs); } void __qmljs_inplace_bit_and_member(ExecutionContext *ctx, const ValueRef base, String *name, const ValueRef rhs) { - Object *o = base->toObject(ctx); - o->inplaceBinOp(ctx, __qmljs_bit_and, name, rhs); + Scope scope(ctx); + ScopedObject o(scope, base->toObject(ctx)); + ScopedString n(scope, name); + o->inplaceBinOp(ctx, __qmljs_bit_and, n, rhs); } void __qmljs_inplace_bit_or_member(ExecutionContext *ctx, const ValueRef base, String *name, const ValueRef rhs) { - Object *o = base->toObject(ctx); - o->inplaceBinOp(ctx, __qmljs_bit_or, name, rhs); + Scope scope(ctx); + ScopedObject o(scope, base->toObject(ctx)); + ScopedString n(scope, name); + o->inplaceBinOp(ctx, __qmljs_bit_or, n, rhs); } void __qmljs_inplace_bit_xor_member(ExecutionContext *ctx, const ValueRef base, String *name, const ValueRef rhs) { - Object *o = base->toObject(ctx); - o->inplaceBinOp(ctx, __qmljs_bit_xor, name, rhs); + Scope scope(ctx); + ScopedObject o(scope, base->toObject(ctx)); + ScopedString n(scope, name); + o->inplaceBinOp(ctx, __qmljs_bit_xor, n, rhs); } void __qmljs_inplace_add_member(ExecutionContext *ctx, const ValueRef base, String *name, const ValueRef rhs) { - Object *o = base->toObject(ctx); - o->inplaceBinOp(ctx, __qmljs_add, name, rhs); + Scope scope(ctx); + ScopedObject o(scope, base->toObject(ctx)); + ScopedString n(scope, name); + o->inplaceBinOp(ctx, __qmljs_add, n, rhs); } void __qmljs_inplace_sub_member(ExecutionContext *ctx, const ValueRef base, String *name, const ValueRef rhs) { - Object *o = base->toObject(ctx); - o->inplaceBinOp(ctx, __qmljs_sub, name, rhs); + Scope scope(ctx); + ScopedObject o(scope, base->toObject(ctx)); + ScopedString n(scope, name); + o->inplaceBinOp(ctx, __qmljs_sub, n, rhs); } void __qmljs_inplace_mul_member(ExecutionContext *ctx, const ValueRef base, String *name, const ValueRef rhs) { - Object *o = base->toObject(ctx); - o->inplaceBinOp(ctx, __qmljs_mul, name, rhs); + Scope scope(ctx); + ScopedObject o(scope, base->toObject(ctx)); + ScopedString n(scope, name); + o->inplaceBinOp(ctx, __qmljs_mul, n, rhs); } void __qmljs_inplace_div_member(ExecutionContext *ctx, const ValueRef base, String *name, const ValueRef rhs) { - Object *o = base->toObject(ctx); - o->inplaceBinOp(ctx, __qmljs_div, name, rhs); + Scope scope(ctx); + ScopedObject o(scope, base->toObject(ctx)); + ScopedString n(scope, name); + o->inplaceBinOp(ctx, __qmljs_div, n, rhs); } void __qmljs_inplace_mod_member(ExecutionContext *ctx, const ValueRef base, String *name, const ValueRef rhs) { - Object *o = base->toObject(ctx); - o->inplaceBinOp(ctx, __qmljs_mod, name, rhs); + Scope scope(ctx); + ScopedObject o(scope, base->toObject(ctx)); + ScopedString n(scope, name); + o->inplaceBinOp(ctx, __qmljs_mod, n, rhs); } void __qmljs_inplace_shl_member(ExecutionContext *ctx, const ValueRef base, String *name, const ValueRef rhs) { - Object *o = base->toObject(ctx); - o->inplaceBinOp(ctx, __qmljs_shl, name, rhs); + Scope scope(ctx); + ScopedObject o(scope, base->toObject(ctx)); + ScopedString n(scope, name); + o->inplaceBinOp(ctx, __qmljs_shl, n, rhs); } void __qmljs_inplace_shr_member(ExecutionContext *ctx, const ValueRef base, String *name, const ValueRef rhs) { - Object *o = base->toObject(ctx); - o->inplaceBinOp(ctx, __qmljs_shr, name, rhs); + Scope scope(ctx); + ScopedObject o(scope, base->toObject(ctx)); + ScopedString n(scope, name); + o->inplaceBinOp(ctx, __qmljs_shr, n, rhs); } void __qmljs_inplace_ushr_member(ExecutionContext *ctx, const ValueRef base, String *name, const ValueRef rhs) { - Object *o = base->toObject(ctx); - o->inplaceBinOp(ctx, __qmljs_ushr, name, rhs); + Scope scope(ctx); + ScopedObject o(scope, base->toObject(ctx)); + ScopedString n(scope, name); + o->inplaceBinOp(ctx, __qmljs_ushr, n, rhs); } double __qmljs_string_to_number(const QString &string) |