diff options
author | Lars Knoll <lars.knoll@digia.com> | 2012-11-11 00:08:44 +0100 |
---|---|---|
committer | Lars Knoll <lars.knoll@digia.com> | 2012-11-11 21:24:50 +0100 |
commit | 29bc5f59a12710a8369ab0651418bf6f5e25f063 (patch) | |
tree | cdea5a9223eff4985eb377ca419bf93c8834420f /qmljs_runtime.cpp | |
parent | 0c1424362fad42cd4ed027adad811ecdaea6d676 (diff) |
Correct implementation of inplace binops
Fix the last parts of the inplace bitops to
do the correct thing.
Change-Id: I748dde919082193c034cdc20e92cc568d8efa225
Reviewed-by: Erik Verbruggen <erik.verbruggen@digia.com>
Diffstat (limited to 'qmljs_runtime.cpp')
-rw-r--r-- | qmljs_runtime.cpp | 77 |
1 files changed, 22 insertions, 55 deletions
diff --git a/qmljs_runtime.cpp b/qmljs_runtime.cpp index 5d6ea221d0..e98b7ebbe8 100644 --- a/qmljs_runtime.cpp +++ b/qmljs_runtime.cpp @@ -257,6 +257,17 @@ PropertyDescriptor *Context::lookupPropertyDescriptor(String *name, PropertyDesc return 0; } +void Context::inplaceBitOp(Value value, String *name, BinOp op) +{ + for (Context *ctx = this; ctx; ctx = ctx->parent) { + if (Object *act = ctx->activation.asObject()) { + if (act->inplaceBinOp(value, this, name, op)) + return; + } + } + throwReferenceError(Value::fromString(name)); +} + void Context::throwError(Value value) { result = value; @@ -488,101 +499,57 @@ Value __qmljs_in(Value left, Value right, Context *ctx) void __qmljs_inplace_bit_and_name(Value value, String *name, Context *ctx) { - PropertyDescriptor tmp; - if (PropertyDescriptor *prop = ctx->lookupPropertyDescriptor(name, &tmp)) - prop->value = __qmljs_bit_and(prop->value, value, ctx); - else - ctx->throwReferenceError(Value::fromString(name)); + ctx->inplaceBitOp(value, name, __qmljs_bit_and); } void __qmljs_inplace_bit_or_name(Value value, String *name, Context *ctx) { - PropertyDescriptor tmp; - if (PropertyDescriptor *prop = ctx->lookupPropertyDescriptor(name, &tmp)) - prop->value = __qmljs_bit_or(prop->value, value, ctx); - else - ctx->throwReferenceError(Value::fromString(name)); + ctx->inplaceBitOp(value, name, __qmljs_bit_or); } void __qmljs_inplace_bit_xor_name(Value value, String *name, Context *ctx) { - PropertyDescriptor tmp; - if (PropertyDescriptor *prop = ctx->lookupPropertyDescriptor(name, &tmp)) - prop->value = __qmljs_bit_xor(prop->value, value, ctx); - else - ctx->throwReferenceError(Value::fromString(name)); + ctx->inplaceBitOp(value, name, __qmljs_bit_xor); } void __qmljs_inplace_add_name(Value value, String *name, Context *ctx) { - PropertyDescriptor tmp; - if (PropertyDescriptor *prop = ctx->lookupPropertyDescriptor(name, &tmp)) - prop->value = __qmljs_add(prop->value, value, ctx); - else - ctx->throwReferenceError(Value::fromString(name)); + ctx->inplaceBitOp(value, name, __qmljs_add); } void __qmljs_inplace_sub_name(Value value, String *name, Context *ctx) { - PropertyDescriptor tmp; - if (PropertyDescriptor *prop = ctx->lookupPropertyDescriptor(name, &tmp)) - prop->value = __qmljs_sub(prop->value, value, ctx); - else - ctx->throwReferenceError(Value::fromString(name)); + ctx->inplaceBitOp(value, name, __qmljs_sub); } void __qmljs_inplace_mul_name(Value value, String *name, Context *ctx) { - PropertyDescriptor tmp; - if (PropertyDescriptor *prop = ctx->lookupPropertyDescriptor(name, &tmp)) - prop->value = __qmljs_mul(prop->value, value, ctx); - else - ctx->throwReferenceError(Value::fromString(name)); + ctx->inplaceBitOp(value, name, __qmljs_mul); } void __qmljs_inplace_div_name(Value value, String *name, Context *ctx) { - PropertyDescriptor tmp; - if (PropertyDescriptor *prop = ctx->lookupPropertyDescriptor(name, &tmp)) - prop->value = __qmljs_div(prop->value, value, ctx); - else - ctx->throwReferenceError(Value::fromString(name)); + ctx->inplaceBitOp(value, name, __qmljs_div); } void __qmljs_inplace_mod_name(Value value, String *name, Context *ctx) { - PropertyDescriptor tmp; - if (PropertyDescriptor *prop = ctx->lookupPropertyDescriptor(name, &tmp)) - prop->value = __qmljs_mod(prop->value, value, ctx); - else - ctx->throwReferenceError(Value::fromString(name)); + ctx->inplaceBitOp(value, name, __qmljs_mod); } void __qmljs_inplace_shl_name(Value value, String *name, Context *ctx) { - PropertyDescriptor tmp; - if (PropertyDescriptor *prop = ctx->lookupPropertyDescriptor(name, &tmp)) - prop->value = __qmljs_shl(prop->value, value, ctx); - else - ctx->throwReferenceError(Value::fromString(name)); + ctx->inplaceBitOp(value, name, __qmljs_shl); } void __qmljs_inplace_shr_name(Value value, String *name, Context *ctx) { - PropertyDescriptor tmp; - if (PropertyDescriptor *prop = ctx->lookupPropertyDescriptor(name, &tmp)) - prop->value = __qmljs_shr(prop->value, value, ctx); - else - ctx->throwReferenceError(Value::fromString(name)); + ctx->inplaceBitOp(value, name, __qmljs_shr); } void __qmljs_inplace_ushr_name(Value value, String *name, Context *ctx) { - PropertyDescriptor tmp; - if (PropertyDescriptor *prop = ctx->lookupPropertyDescriptor(name, &tmp)) - prop->value = __qmljs_ushr(prop->value, value, ctx); - else - ctx->throwReferenceError(Value::fromString(name)); + ctx->inplaceBitOp(value, name, __qmljs_ushr); } void __qmljs_inplace_bit_and_element(Value base, Value index, Value value, Context *ctx) |