Bug 886205 (part 4) - Move some function definitions from jsfuninlines.h to jsfun.h. r=terrence.

--HG--
extra : rebase_source : 1bd4bf6c2c4db1392d43908a438df3fde48e29b2
This commit is contained in:
Nicholas Nethercote 2013-06-24 23:52:04 -07:00
parent 2cad2097bc
commit 1c0e8900ee
5 changed files with 79 additions and 115 deletions

View File

@ -469,7 +469,7 @@ 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

View File

@ -662,7 +662,7 @@ JS_IsBuiltinEvalFunction(JSFunction *fun)
JS_PUBLIC_API(JSBool)
JS_IsBuiltinFunctionConstructor(JSFunction *fun)
{
return IsBuiltinFunctionConstructor(fun);
return fun->isBuiltinFunctionConstructor();
}
/************************************************************************/

View File

@ -1524,9 +1524,9 @@ js::Function(JSContext *cx, unsigned argc, Value *vp)
}
bool
js::IsBuiltinFunctionConstructor(JSFunction *fun)
JSFunction::isBuiltinFunctionConstructor()
{
return fun->maybeNative() == Function;
return maybeNative() == Function;
}
JSFunction *

View File

@ -11,6 +11,7 @@
*/
#include "jsprvtd.h"
#include "jsobj.h"
#include "jsscript.h"
#include "gc/Barrier.h"
@ -82,7 +83,17 @@ class JSFunction : public JSObject
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); }
@ -128,12 +139,16 @@ class JSFunction : public JSObject
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) {
@ -190,7 +205,10 @@ class JSFunction : public JSObject
* 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);
@ -258,7 +276,12 @@ class JSFunction : public JSObject
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());
@ -269,9 +292,21 @@ class JSFunction : public JSObject
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_));
@ -347,6 +382,31 @@ JSAPIToJSFunctionFlags(unsigned flags)
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,
@ -397,6 +457,13 @@ JSFunction::toExtended() const
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);

View File

@ -16,12 +16,6 @@
#include "vm/ScopeObject-inl.h"
#include "vm/String-inl.h"
inline bool
JSFunction::strict() const
{
return nonLazyScript()->strict;
}
inline void
JSFunction::initAtom(JSAtom *atom)
{
@ -38,13 +32,6 @@ JSFunction::setGuessedAtom(JSAtom *atom)
flags |= HAS_GUESSED_ATOM;
}
inline JSObject *
JSFunction::environment() const
{
JS_ASSERT(isInterpreted());
return u.i.env_;
}
inline void
JSFunction::setEnvironment(JSObject *obj)
{
@ -59,28 +46,6 @@ JSFunction::initEnvironment(JSObject *obj)
((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()
{
@ -105,45 +70,8 @@ JSFunction::setExtendedSlot(size_t which, const js::Value &val)
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)
{
@ -153,12 +81,6 @@ GetFunctionNameBytes(JSContext *cx, JSFunction *fun, JSAutoByteString *bytes)
return js_anonymous_str;
}
extern JSBool
Function(JSContext *cx, unsigned argc, Value *vp);
extern bool
IsBuiltinFunctionConstructor(JSFunction *fun);
static inline JSObject *
SkipScopeParent(JSObject *parent)
{
@ -224,20 +146,6 @@ CloneFunctionObjectIfNotSingleton(JSContext *cx, HandleFunction fun, HandleObjec
} /* 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()
{
@ -272,17 +180,6 @@ JSFunction::initScript(JSScript *script_)
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
{