Bug 886205 (part 4) - Move some function definitions from jsfuninlines.h to jsfun.h. r=terrence.
authorNicholas Nethercote <nnethercote@mozilla.com>
Mon, 24 Jun 2013 23:52:04 -0700
changeset 136467 3e88bc7d02b8a999a4aa7872808058fb0c891f6c
parent 136466 5b4318f8f3f4aaba4e5389da305537746cb39e57
child 136468 f0fffee790c92e8832014754eb135199e49ce748
push id30121
push usernnethercote@mozilla.com
push dateWed, 26 Jun 2013 04:41:21 +0000
treeherdermozilla-inbound@927d1bf5f36d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersterrence
bugs886205
milestone25.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 886205 (part 4) - Move some function definitions from jsfuninlines.h to jsfun.h. r=terrence.
js/src/builtin/Eval.cpp
js/src/jsapi.cpp
js/src/jsfun.cpp
js/src/jsfun.h
js/src/jsfuninlines.h
--- a/js/src/builtin/Eval.cpp
+++ b/js/src/builtin/Eval.cpp
@@ -464,17 +464,17 @@ js::IsAnyBuiltinEval(JSFunction *fun)
     return fun->maybeNative() == IndirectEval;
 }
 
 JSPrincipals *
 js::PrincipalsForCompiledCode(const CallReceiver &call, JSContext *cx)
 {
     JSObject &callee = call.callee();
     JS_ASSERT(IsAnyBuiltinEval(&callee.as<JSFunction>()) ||
-              IsBuiltinFunctionConstructor(&callee.as<JSFunction>()));
+              callee.as<JSFunction>().isBuiltinFunctionConstructor());
 
     // To compute the principals of the compiled eval/Function code, we simply
     // use the callee's principals. To see why the caller's principals are
     // ignored, consider first that, in the capability-model we assume, the
     // high-privileged eval/Function should never have escaped to the
     // low-privileged caller. (For the Mozilla embedding, this is brute-enforced
     // by explicit filtering by wrappers.) Thus, the caller's privileges should
     // subsume the callee's.
--- a/js/src/jsapi.cpp
+++ b/js/src/jsapi.cpp
@@ -657,17 +657,17 @@ JS_PUBLIC_API(JSBool)
 JS_IsBuiltinEvalFunction(JSFunction *fun)
 {
     return IsAnyBuiltinEval(fun);
 }
 
 JS_PUBLIC_API(JSBool)
 JS_IsBuiltinFunctionConstructor(JSFunction *fun)
 {
-    return IsBuiltinFunctionConstructor(fun);
+    return fun->isBuiltinFunctionConstructor();
 }
 
 /************************************************************************/
 
 /*
  * Has a new runtime ever been created?  This flag is used to control things
  * that should happen only once across all runtimes.
  */
--- a/js/src/jsfun.cpp
+++ b/js/src/jsfun.cpp
@@ -1519,19 +1519,19 @@ js::Function(JSContext *cx, unsigned arg
         fun->setHasRest();
 
     bool ok = frontend::CompileFunctionBody(cx, &fun, options, formals, chars, length);
     args.rval().setObject(*fun);
     return ok;
 }
 
 bool
-js::IsBuiltinFunctionConstructor(JSFunction *fun)
+JSFunction::isBuiltinFunctionConstructor()
 {
-    return fun->maybeNative() == Function;
+    return maybeNative() == Function;
 }
 
 JSFunction *
 js::NewFunction(JSContext *cx, HandleObject funobjArg, Native native, unsigned nargs,
                 JSFunction::Flags flags, HandleObject parent, HandleAtom atom,
                 gc::AllocKind allocKind /* = JSFunction::FinalizeKind */,
                 NewObjectKind newKind /* = GenericObject */)
 {
--- a/js/src/jsfun.h
+++ b/js/src/jsfun.h
@@ -6,16 +6,17 @@
 
 #ifndef jsfun_h
 #define jsfun_h
 /*
  * JS function definitions.
  */
 #include "jsprvtd.h"
 #include "jsobj.h"
+#include "jsscript.h"
 
 #include "gc/Barrier.h"
 
 namespace js { class FunctionExtended; }
 
 class JSFunction : public JSObject
 {
   public:
@@ -77,17 +78,27 @@ class JSFunction : public JSObject
         void            *nativeOrScript;
     } u;
   private:
     js::HeapPtrAtom  atom_;       /* name for diagnostics and decompiling */
 
   public:
 
     /* Call objects must be created for each invocation of a heavyweight function. */
-    inline bool isHeavyweight() const;
+    bool isHeavyweight() const {
+        JS_ASSERT(!isInterpretedLazy());
+
+        if (isNative())
+            return false;
+
+        // Note: this should be kept in sync with FunctionBox::isHeavyweight().
+        return nonLazyScript()->bindings.hasAnyAliasedBindings() ||
+               nonLazyScript()->funHasExtensibleScope ||
+               nonLazyScript()->funNeedsDeclEnvObject;
+    }
 
     /* A function can be classified as either native (C++) or interpreted (JS): */
     bool isInterpreted()            const { return flags & (INTERPRETED | INTERPRETED_LAZY); }
     bool isNative()                 const { return !isInterpreted(); }
 
     /* Possible attributes of a native function: */
     bool isNativeConstructor()      const { return flags & NATIVE_CTOR; }
 
@@ -123,22 +134,26 @@ class JSFunction : public JSObject
     /* Compound attributes: */
     bool isBuiltin() const {
         return isNative() || isSelfHostedBuiltin();
     }
     bool isInterpretedConstructor() const {
         return isInterpreted() && !isFunctionPrototype() &&
                (!isSelfHostedBuiltin() || isSelfHostedConstructor());
     }
-    bool isNamedLambda()     const {
+    bool isNamedLambda() const {
         return isLambda() && atom_ && !hasGuessedAtom();
     }
 
+    bool isBuiltinFunctionConstructor();
+
     /* Returns the strictness of this function, which must be interpreted. */
-    inline bool strict() const;
+    bool strict() const {
+        return nonLazyScript()->strict;
+    }
 
     // Can be called multiple times by the parser.
     void setArgCount(uint16_t nargs) {
         this->nargs = nargs;
     }
 
     // Can be called multiple times by the parser.
     void setHasRest() {
@@ -185,17 +200,20 @@ class JSFunction : public JSObject
 
     /* uint16_t representation bounds number of call object dynamic slots. */
     enum { MAX_ARGS_AND_VARS = 2 * ((1U << 16) - 1) };
 
     /*
      * For an interpreted function, accessors for the initial scope object of
      * activations (stack frames) of the function.
      */
-    inline JSObject *environment() const;
+    JSObject *environment() const {
+        JS_ASSERT(isInterpreted());
+        return u.i.env_;
+    }
     inline void setEnvironment(JSObject *obj);
     inline void initEnvironment(JSObject *obj);
 
     static inline size_t offsetOfEnvironment() { return offsetof(JSFunction, u.i.env_); }
     static inline size_t offsetOfAtom() { return offsetof(JSFunction, atom_); }
 
     static bool createScriptForLazilyInterpretedFunction(JSContext *cx, js::HandleFunction fun);
 
@@ -253,30 +271,47 @@ class JSFunction : public JSObject
 
     js::LazyScript *lazyScriptOrNull() const {
         JS_ASSERT(isInterpretedLazy());
         return u.i.s.lazy_;
     }
 
     inline void setScript(JSScript *script_);
     inline void initScript(JSScript *script_);
-    inline void initLazyScript(js::LazyScript *script);
+    void initLazyScript(js::LazyScript *lazy) {
+        JS_ASSERT(isInterpreted());
+        flags &= ~INTERPRETED;
+        flags |= INTERPRETED_LAZY;
+        u.i.s.lazy_ = lazy;
+    }
 
     JSNative native() const {
         JS_ASSERT(isNative());
         return u.n.native;
     }
 
     JSNative maybeNative() const {
         return isInterpreted() ? NULL : native();
     }
 
-    inline void initNative(js::Native native, const JSJitInfo *jitinfo);
-    inline const JSJitInfo *jitInfo() const;
-    inline void setJitInfo(const JSJitInfo *data);
+    void initNative(js::Native native, const JSJitInfo *jitinfo) {
+        JS_ASSERT(native);
+        u.n.native = native;
+        u.n.jitinfo = jitinfo;
+    }
+
+    const JSJitInfo *jitInfo() const {
+        JS_ASSERT(isNative());
+        return u.n.jitinfo;
+    }
+
+    void setJitInfo(const JSJitInfo *data) {
+        JS_ASSERT(isNative());
+        u.n.jitinfo = data;
+    }
 
     static unsigned offsetOfNativeOrScript() {
         JS_STATIC_ASSERT(offsetof(U, n.native) == offsetof(U, i.s.script_));
         JS_STATIC_ASSERT(offsetof(U, n.native) == offsetof(U, nativeOrScript));
         return offsetof(JSFunction, u.nativeOrScript);
     }
 
 #if JS_BITS_PER_WORD == 32
@@ -342,16 +377,41 @@ JSAPIToJSFunctionFlags(unsigned flags)
 {
     return (flags & JSFUN_CONSTRUCTOR)
            ? JSFunction::NATIVE_CTOR
            : JSFunction::NATIVE_FUN;
 }
 
 namespace js {
 
+/* Valueified JS_IsConstructing. */
+static JS_ALWAYS_INLINE bool
+IsConstructing(const Value *vp)
+{
+#ifdef DEBUG
+    JSObject *callee = &JS_CALLEE(cx, vp).toObject();
+    if (callee->is<JSFunction>()) {
+        JSFunction *fun = &callee->as<JSFunction>();
+        JS_ASSERT(fun->isNativeConstructor());
+    } else {
+        JS_ASSERT(callee->getClass()->construct != NULL);
+    }
+#endif
+    return vp[1].isMagic();
+}
+
+inline bool
+IsConstructing(CallReceiver call)
+{
+    return IsConstructing(call.base());
+}
+
+extern JSBool
+Function(JSContext *cx, unsigned argc, Value *vp);
+
 extern JSFunction *
 NewFunction(JSContext *cx, HandleObject funobj, JSNative native, unsigned nargs,
             JSFunction::Flags flags, HandleObject parent, HandleAtom atom,
             gc::AllocKind allocKind = JSFunction::FinalizeKind,
             NewObjectKind newKind = GenericObject);
 
 extern JSFunction *
 DefineFunction(JSContext *cx, HandleObject obj, HandleId id, JSNative native,
@@ -392,16 +452,23 @@ JSFunction::toExtended()
 
 inline const js::FunctionExtended *
 JSFunction::toExtended() const
 {
     JS_ASSERT(isExtended());
     return static_cast<const js::FunctionExtended *>(this);
 }
 
+inline const js::Value &
+JSFunction::getExtendedSlot(size_t which) const
+{
+    JS_ASSERT(which < mozilla::ArrayLength(toExtended()->extendedSlots));
+    return toExtended()->extendedSlots[which];
+}
+
 namespace js {
 
 JSString *FunctionToString(JSContext *cx, HandleFunction fun, bool bodyOnly, bool lambdaParen);
 
 template<XDRMode mode>
 bool
 XDRInterpretedFunction(XDRState<mode> *xdr, HandleObject enclosingScope,
                        HandleScript enclosingScript, MutableHandleObject objp);
--- a/js/src/jsfuninlines.h
+++ b/js/src/jsfuninlines.h
@@ -11,82 +11,47 @@
 
 #include "jsscript.h"
 
 #include "vm/GlobalObject.h"
 
 #include "vm/ScopeObject-inl.h"
 #include "vm/String-inl.h"
 
-inline bool
-JSFunction::strict() const
-{
-    return nonLazyScript()->strict;
-}
-
 inline void
 JSFunction::initAtom(JSAtom *atom)
 {
     atom_.init(atom);
 }
 
 inline void
 JSFunction::setGuessedAtom(JSAtom *atom)
 {
     JS_ASSERT(atom_ == NULL);
     JS_ASSERT(atom != NULL);
     JS_ASSERT(!hasGuessedAtom());
     atom_ = atom;
     flags |= HAS_GUESSED_ATOM;
 }
 
-inline JSObject *
-JSFunction::environment() const
-{
-    JS_ASSERT(isInterpreted());
-    return u.i.env_;
-}
-
 inline void
 JSFunction::setEnvironment(JSObject *obj)
 {
     JS_ASSERT(isInterpreted());
     *(js::HeapPtrObject *)&u.i.env_ = obj;
 }
 
 inline void
 JSFunction::initEnvironment(JSObject *obj)
 {
     JS_ASSERT(isInterpreted());
     ((js::HeapPtrObject *)&u.i.env_)->init(obj);
 }
 
 inline void
-JSFunction::initNative(js::Native native, const JSJitInfo *data)
-{
-    JS_ASSERT(native);
-    u.n.native = native;
-    u.n.jitinfo = data;
-}
-
-inline const JSJitInfo *
-JSFunction::jitInfo() const
-{
-    JS_ASSERT(isNative());
-    return u.n.jitinfo;
-}
-
-inline void
-JSFunction::setJitInfo(const JSJitInfo *data)
-{
-    JS_ASSERT(isNative());
-    u.n.jitinfo = data;
-}
-
-inline void
 JSFunction::initializeExtended()
 {
     JS_ASSERT(isExtended());
 
     JS_ASSERT(mozilla::ArrayLength(toExtended()->extendedSlots) == 2);
     toExtended()->extendedSlots[0].init(js::UndefinedValue());
     toExtended()->extendedSlots[1].init(js::UndefinedValue());
 }
@@ -100,70 +65,27 @@ JSFunction::initExtendedSlot(size_t whic
 
 inline void
 JSFunction::setExtendedSlot(size_t which, const js::Value &val)
 {
     JS_ASSERT(which < mozilla::ArrayLength(toExtended()->extendedSlots));
     toExtended()->extendedSlots[which] = val;
 }
 
-inline const js::Value &
-JSFunction::getExtendedSlot(size_t which) const
-{
-    JS_ASSERT(which < mozilla::ArrayLength(toExtended()->extendedSlots));
-    return toExtended()->extendedSlots[which];
-}
-
 namespace js {
 
-extern JS_ALWAYS_INLINE bool
-SameTraceType(const Value &lhs, const Value &rhs)
-{
-    return SameType(lhs, rhs) &&
-           (lhs.isPrimitive() ||
-            lhs.toObject().is<JSFunction>() == rhs.toObject().is<JSFunction>());
-}
-
-/* Valueified JS_IsConstructing. */
-static JS_ALWAYS_INLINE bool
-IsConstructing(const Value *vp)
-{
-#ifdef DEBUG
-    JSObject *callee = &JS_CALLEE(cx, vp).toObject();
-    if (callee->is<JSFunction>()) {
-        JSFunction *fun = &callee->as<JSFunction>();
-        JS_ASSERT(fun->isNativeConstructor());
-    } else {
-        JS_ASSERT(callee->getClass()->construct != NULL);
-    }
-#endif
-    return vp[1].isMagic();
-}
-
-inline bool
-IsConstructing(CallReceiver call)
-{
-    return IsConstructing(call.base());
-}
-
 inline const char *
 GetFunctionNameBytes(JSContext *cx, JSFunction *fun, JSAutoByteString *bytes)
 {
     JSAtom *atom = fun->atom();
     if (atom)
         return bytes->encodeLatin1(cx, atom);
     return js_anonymous_str;
 }
 
-extern JSBool
-Function(JSContext *cx, unsigned argc, Value *vp);
-
-extern bool
-IsBuiltinFunctionConstructor(JSFunction *fun);
-
 static inline JSObject *
 SkipScopeParent(JSObject *parent)
 {
     if (!parent)
         return NULL;
     while (parent->is<ScopeObject>())
         parent = &parent->as<ScopeObject>().enclosingScope();
     return parent;
@@ -219,30 +141,16 @@ CloneFunctionObjectIfNotSingleton(JSCont
     gc::AllocKind kind = fun->isExtended()
                          ? extendedFinalizeKind
                          : finalizeKind;
     return CloneFunctionObject(cx, fun, parent, kind, newKind);
 }
 
 } /* namespace js */
 
-inline bool
-JSFunction::isHeavyweight() const
-{
-    JS_ASSERT(!isInterpretedLazy());
-
-    if (isNative())
-        return false;
-
-    // Note: this should be kept in sync with FunctionBox::isHeavyweight().
-    return nonLazyScript()->bindings.hasAnyAliasedBindings() ||
-           nonLazyScript()->funHasExtensibleScope ||
-           nonLazyScript()->funNeedsDeclEnvObject;
-}
-
 inline JSScript *
 JSFunction::existingScript()
 {
     JS_ASSERT(isInterpreted());
     if (isInterpretedLazy()) {
         js::LazyScript *lazy = lazyScript();
         JSScript *script = lazy->maybeScript();
         JS_ASSERT(script);
@@ -267,27 +175,16 @@ JSFunction::setScript(JSScript *script_)
 
 inline void
 JSFunction::initScript(JSScript *script_)
 {
     JS_ASSERT(isInterpreted());
     mutableScript().init(script_);
 }
 
-inline void
-JSFunction::initLazyScript(js::LazyScript *lazy)
-{
-    JS_ASSERT(isInterpreted());
-
-    flags &= ~INTERPRETED;
-    flags |= INTERPRETED_LAZY;
-
-    u.i.s.lazy_ = lazy;
-}
-
 inline JSObject *
 JSFunction::getBoundFunctionTarget() const
 {
     JS_ASSERT(isBoundFunction());
 
     /* Bound functions abuse |parent| to store their target function. */
     return getParent();
 }