Bug 598682, part 1 - Minor cleanups to jsinterp.h and jsinterpinlines.h (r=lw)
authorJim Blandy <jimb@mozilla.com>
Tue, 05 Oct 2010 14:41:55 -0700
changeset 55516 02acd5c6ab3e556374d68e30bad68d26ac73cf01
parent 55515 cf3746fc25f9265d992b79eeb89acfafe4a6d10a
child 55517 7110c6d3d183760e18ffcfc5089fe2363c8a0be7
push idunknown
push userunknown
push dateunknown
reviewerslw
bugs598682
milestone2.0b7pre
Bug 598682, part 1 - Minor cleanups to jsinterp.h and jsinterpinlines.h (r=lw)
js/src/jsinterp.h
js/src/jsinterpinlines.h
--- a/js/src/jsinterp.h
+++ b/js/src/jsinterp.h
@@ -342,33 +342,38 @@ struct JSStackFrame
      * arguments from the frame pointer. Since the formal subset of the actual
      * arguments is potentially on the stack twice, it is important for all
      * reads/writes to refer to the same canonical memory location.
      *
      * An arguments object (the object returned by the 'arguments' keyword) is
      * lazily created, so a given function frame may or may not have one.
      */
 
+    /* True if this frame has arguments. Contrast with hasArgsObj. */
+    bool hasArgs() const {
+        return isFunctionFrame() && !isEvalFrame();
+    }
+
     uintN numFormalArgs() const {
-        JS_ASSERT(isFunctionFrame() && !isEvalFrame());
+        JS_ASSERT(hasArgs());
         return fun()->nargs;
     }
 
     js::Value &formalArg(uintN i) const {
         JS_ASSERT(i < numFormalArgs());
         return formalArgs()[i];
     }
 
     js::Value *formalArgs() const {
-        JS_ASSERT(isFunctionFrame() && !isEvalFrame());
+        JS_ASSERT(hasArgs());
         return (js::Value *)this - numFormalArgs();
     }
 
     js::Value *formalArgsEnd() const {
-        JS_ASSERT(isFunctionFrame() && !isEvalFrame());
+        JS_ASSERT(hasArgs());
         return (js::Value *)this;
     }
 
     js::Value *maybeFormalArgs() const {
         return (flags_ & (JSFRAME_FUNCTION | JSFRAME_EVAL)) == JSFRAME_FUNCTION
                ? formalArgs()
                : NULL;
     }
@@ -376,16 +381,17 @@ struct JSStackFrame
     inline uintN numActualArgs() const;
     inline js::Value *actualArgs() const;
     inline js::Value *actualArgsEnd() const;
 
     inline js::Value &canonicalActualArg(uintN i) const;
     template <class Op> inline void forEachCanonicalActualArg(Op op);
     template <class Op> inline void forEachFormalArg(Op op);
 
+    /* True if we have created an arguments object for this frame; implies hasArgs(). */
     bool hasArgsObj() const {
         return !!(flags_ & JSFRAME_HAS_ARGS_OBJ);
     }
 
     JSObject &argsObj() const {
         JS_ASSERT(hasArgsObj());
         JS_ASSERT(!isEvalFrame());
         return *args.obj;
@@ -415,17 +421,17 @@ struct JSStackFrame
     js::Value &functionThis() const {
         JS_ASSERT(isFunctionFrame());
         if (isEvalFrame())
             return ((js::Value *)this)[-1];
         return formalArgs()[-1];
     }
 
     JSObject &constructorThis() const {
-        JS_ASSERT(isFunctionFrame() && !isEvalFrame());
+        JS_ASSERT(hasArgs());
         return formalArgs()[-1].toObject();
     }
 
     js::Value &globalThis() const {
         JS_ASSERT(isGlobalFrame());
         return ((js::Value *)this)[-1];
     }
 
--- a/js/src/jsinterpinlines.h
+++ b/js/src/jsinterpinlines.h
@@ -271,43 +271,41 @@ JSStackFrame::varobj(JSContext *cx) cons
 {
     JS_ASSERT(cx->activeSegment()->contains(this));
     return isFunctionFrame() ? callObj() : cx->activeSegment()->getInitialVarObj();
 }
 
 inline uintN
 JSStackFrame::numActualArgs() const
 {
-    JS_ASSERT(isFunctionFrame() && !isEvalFrame());
+    JS_ASSERT(hasArgs());
     if (JS_UNLIKELY(flags_ & (JSFRAME_OVERFLOW_ARGS | JSFRAME_UNDERFLOW_ARGS)))
         return hasArgsObj() ? argsObj().getArgsInitialLength() : args.nactual;
     return numFormalArgs();
 }
 
 inline js::Value *
 JSStackFrame::actualArgs() const
 {
-    JS_ASSERT(isFunctionFrame() && !isEvalFrame());
-    js::Value *argv = formalArgsEnd() - numFormalArgs();
+    JS_ASSERT(hasArgs());
+    js::Value *argv = formalArgs();
     if (JS_UNLIKELY(flags_ & JSFRAME_OVERFLOW_ARGS)) {
         uintN nactual = hasArgsObj() ? argsObj().getArgsInitialLength() : args.nactual;
         return argv - (2 + nactual);
     }
     return argv;
 }
 
 inline js::Value *
 JSStackFrame::actualArgsEnd() const
 {
-    JS_ASSERT(isFunctionFrame() && !isEvalFrame());
+    JS_ASSERT(hasArgs());
     if (JS_UNLIKELY(flags_ & JSFRAME_OVERFLOW_ARGS))
-        return formalArgsEnd() - (2 + numFormalArgs());
-    uintN argc = numActualArgs();
-    uintN nmissing = numFormalArgs() - argc;
-    return formalArgsEnd() - nmissing;
+        return formalArgs() - 2;
+    return formalArgs() + numActualArgs();
 }
 
 inline void
 JSStackFrame::setArgsObj(JSObject &obj)
 {
     JS_ASSERT_IF(hasArgsObj(), &obj == args.obj);
     JS_ASSERT_IF(!hasArgsObj(), numActualArgs() == obj.getArgsInitialLength());
     args.obj = &obj;