From 5ae078453dae4438d350f97cd2b37d2e1f523625 Mon Sep 17 00:00:00 2001 From: Terrence Cole Date: Tue, 8 Nov 2011 10:17:25 -0800 Subject: [PATCH] Bug 697322 - Add easier to use reset method to CallReceiver; r=luke All users of InvokeArgsGuard that use calleeHasBeenReset use it before setting a new callee/this in a loop. We should make it easier to use by combining the reset with the setup with the setting of the new callee. --- js/src/jsarray.cpp | 15 +++++---------- js/src/jsstr.cpp | 3 +-- js/src/vm/Stack.h | 3 ++- 3 files changed, 8 insertions(+), 13 deletions(-) diff --git a/js/src/jsarray.cpp b/js/src/jsarray.cpp index b21ce5c9ea7..8cb3677edc8 100644 --- a/js/src/jsarray.cpp +++ b/js/src/jsarray.cpp @@ -2151,8 +2151,7 @@ sort_compare(void *arg, const void *a, const void *b, int *result) if (!ag.pushed() && !cx->stack.pushInvokeArgs(cx, 2, &ag)) return JS_FALSE; - ag.calleeHasBeenReset(); - ag.calleev() = ca->fval; + ag.setCallee(ca->fval); ag.thisv() = UndefinedValue(); ag[0] = *av; ag[1] = *bv; @@ -3360,8 +3359,7 @@ array_readonlyCommon(JSContext *cx, CallArgs &args) if (!kNotPresent) { if (!ag.pushed() && !cx->stack.pushInvokeArgs(cx, 3, &ag)) return false; - ag.calleeHasBeenReset(); - ag.calleev() = ObjectValue(*callable); + ag.setCallee(ObjectValue(*callable)); ag.thisv() = thisv; ag[0] = kValue; ag[1] = NumberValue(k); @@ -3462,8 +3460,7 @@ array_map(JSContext *cx, uintN argc, Value *vp) if (!kNotPresent) { if (!ag.pushed() && !cx->stack.pushInvokeArgs(cx, 3, &ag)) return false; - ag.calleeHasBeenReset(); - ag.calleev() = ObjectValue(*callable); + ag.setCallee(ObjectValue(*callable)); ag.thisv() = thisv; ag[0] = kValue; ag[1] = NumberValue(k); @@ -3542,8 +3539,7 @@ array_filter(JSContext *cx, uintN argc, Value *vp) if (!kNotPresent) { if (!ag.pushed() && !cx->stack.pushInvokeArgs(cx, 3, &ag)) return false; - ag.calleeHasBeenReset(); - ag.calleev() = ObjectValue(*callable); + ag.setCallee(ObjectValue(*callable)); ag.thisv() = thisv; ag[0] = kValue; ag[1] = NumberValue(k); @@ -3661,8 +3657,7 @@ array_reduceCommon(JSContext *cx, CallArgs &args) if (!kNotPresent) { if (!ag.pushed() && !cx->stack.pushInvokeArgs(cx, 4, &ag)) return false; - ag.calleeHasBeenReset(); - ag.calleev() = ObjectValue(*callable); + ag.setCallee(ObjectValue(*callable)); ag.thisv() = UndefinedValue(); ag[0] = accumulator; ag[1] = kValue; diff --git a/js/src/jsstr.cpp b/js/src/jsstr.cpp index b6f4108bce8..e8b28d0c139 100644 --- a/js/src/jsstr.cpp +++ b/js/src/jsstr.cpp @@ -1791,8 +1791,7 @@ FindReplaceLength(JSContext *cx, RegExpStatics *res, ReplaceData &rdata, size_t if (!args.pushed() && !cx->stack.pushInvokeArgs(cx, argc, &args)) return false; - args.calleeHasBeenReset(); - args.calleev() = ObjectValue(*lambda); + args.setCallee(ObjectValue(*lambda)); args.thisv() = UndefinedValue(); /* Push $&, $1, $2, ... */ diff --git a/js/src/vm/Stack.h b/js/src/vm/Stack.h index dd321035a97..0c866824976 100644 --- a/js/src/vm/Stack.h +++ b/js/src/vm/Stack.h @@ -208,8 +208,9 @@ class CallReceiver return argv_ - 1; } - void calleeHasBeenReset() const { + void setCallee(Value calleev) { clearUsedRval(); + this->calleev() = calleev; } };