Bug 715667: Remove some unnecessary toFunction() calls applied to JSFunction values. r=luke
authorJim Blandy <jimb@mozilla.com>
Fri, 06 Jan 2012 11:06:48 -0800
changeset 85179 89c6efec31a704c07a40af3fb1d4b68f36115257
parent 85178 47cc12948f74963a2c28e8018b2253fd88a33611
child 85180 f0eab7fd20af5570670f3f048846a5536cac0cfe
push id805
push userakeybl@mozilla.com
push dateWed, 01 Feb 2012 18:17:35 +0000
treeherdermozilla-aurora@6fb3bf232436 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersluke
bugs715667
milestone12.0a1
Bug 715667: Remove some unnecessary toFunction() calls applied to JSFunction values. r=luke
js/src/jsfun.h
js/src/vm/Stack-inl.h
--- a/js/src/jsfun.h
+++ b/js/src/jsfun.h
@@ -284,16 +284,23 @@ struct JSFunction : public JSObject
 
     /*
      * Method name imputed from property uniquely assigned to or initialized,
      * where the function does not need to be cloned to carry a scope chain or
      * flattened upvars. This is set on both the original and cloned function.
      */
     inline JSAtom *methodAtom() const;
     inline void setMethodAtom(JSAtom *atom);
+
+    /* 
+     * These member functions are inherited from JSObject, but should never be applied to
+     * a value statically known to be a JSFunction.
+     */
+    inline JSFunction *toFunction() MOZ_DELETE;
+    inline const JSFunction *toFunction() const MOZ_DELETE;
 };
 
 inline JSFunction *
 JSObject::toFunction()
 {
     JS_ASSERT(JS_ObjectIsFunction(NULL, this));
     return static_cast<JSFunction *>(this);
 }
--- a/js/src/vm/Stack-inl.h
+++ b/js/src/vm/Stack-inl.h
@@ -147,23 +147,23 @@ StackFrame::resetInlinePrev(StackFrame *
 inline void
 StackFrame::initCallFrame(JSContext *cx, JSFunction &callee,
                           JSScript *script, uint32_t nactual, StackFrame::Flags flagsArg)
 {
     JS_ASSERT((flagsArg & ~(CONSTRUCTING |
                             LOWERED_CALL_APPLY |
                             OVERFLOW_ARGS |
                             UNDERFLOW_ARGS)) == 0);
-    JS_ASSERT(script == callee.toFunction()->script());
+    JS_ASSERT(script == callee.script());
 
     /* Initialize stack frame members. */
     flags_ = FUNCTION | HAS_PREVPC | HAS_SCOPECHAIN | HAS_BLOCKCHAIN | flagsArg;
     exec.fun = &callee;
     args.nactual = nactual;
-    scopeChain_ = callee.toFunction()->environment();
+    scopeChain_ = callee.environment();
     ncode_ = NULL;
     initPrev(cx);
     blockChain_= NULL;
     JS_ASSERT(!hasBlockChain());
     JS_ASSERT(!hasHookData());
     JS_ASSERT(annotation() == NULL);
     JS_ASSERT(!hasCallObj());
 
@@ -564,17 +564,17 @@ ContextStack::getCallFrame(JSContext *cx
 JS_ALWAYS_INLINE bool
 ContextStack::pushInlineFrame(JSContext *cx, FrameRegs &regs, const CallArgs &args,
                               JSFunction &callee, JSScript *script,
                               InitialFrameFlags initial)
 {
     JS_ASSERT(onTop());
     JS_ASSERT(regs.sp == args.end());
     /* Cannot assert callee == args.callee() since this is called from LeaveTree. */
-    JS_ASSERT(script == callee.toFunction()->script());
+    JS_ASSERT(script == callee.script());
 
     /*StackFrame::Flags*/ uint32_t flags = ToFrameFlags(initial);
     StackFrame *fp = getCallFrame(cx, REPORT_ERROR, args, &callee, script, &flags);
     if (!fp)
         return false;
 
     /* Initialize frame, locals, regs. */
     fp->initCallFrame(cx, callee, script, args.length(), (StackFrame::Flags) flags);