Bug 891215 (part 12) - Slim down ScopeObject-inl.h. r=terrence.

--HG--
extra : rebase_source : ea982556f2203254cd8c79272d746d6271c3a904
This commit is contained in:
Nicholas Nethercote 2013-07-08 23:03:03 -07:00
Родитель a30a8a0d93
Коммит f7993c1ab1
2 изменённых файлов: 115 добавлений и 181 удалений

Просмотреть файл

@ -13,30 +13,6 @@
#include "jsobjinlines.h" #include "jsobjinlines.h"
#include "jsscriptinlines.h" #include "jsscriptinlines.h"
template<>
inline bool
JSObject::is<js::ClonedBlockObject>() const
{
return is<js::BlockObject>() && !!getProto();
}
template<>
inline bool
JSObject::is<js::StaticBlockObject>() const
{
return is<js::BlockObject>() && !getProto();
}
inline JSObject *
JSObject::enclosingScope()
{
return is<js::ScopeObject>()
? &as<js::ScopeObject>().enclosingScope()
: is<js::DebugScopeObject>()
? &as<js::DebugScopeObject>().enclosingScope()
: getParent();
}
namespace js { namespace js {
inline void inline void
@ -47,13 +23,6 @@ ScopeObject::setEnclosingScope(HandleObject obj)
setFixedSlot(SCOPE_CHAIN_SLOT, ObjectValue(*obj)); setFixedSlot(SCOPE_CHAIN_SLOT, ObjectValue(*obj));
} }
inline const Value &
ScopeObject::aliasedVar(ScopeCoordinate sc)
{
JS_ASSERT(is<CallObject>() || is<ClonedBlockObject>());
return getSlot(sc.slot);
}
inline void inline void
ScopeObject::setAliasedVar(JSContext *cx, ScopeCoordinate sc, PropertyName *name, const Value &v) ScopeObject::setAliasedVar(JSContext *cx, ScopeCoordinate sc, PropertyName *name, const Value &v)
{ {
@ -68,33 +37,6 @@ ScopeObject::setAliasedVar(JSContext *cx, ScopeCoordinate sc, PropertyName *name
types::AddTypePropertyId(cx, this, NameToId(name), v); types::AddTypePropertyId(cx, this, NameToId(name), v);
} }
/*static*/ inline size_t
ScopeObject::offsetOfEnclosingScope()
{
return getFixedSlotOffset(SCOPE_CHAIN_SLOT);
}
inline bool
CallObject::isForEval() const
{
JS_ASSERT(getReservedSlot(CALLEE_SLOT).isObjectOrNull());
JS_ASSERT_IF(getReservedSlot(CALLEE_SLOT).isObject(),
getReservedSlot(CALLEE_SLOT).toObject().is<JSFunction>());
return getReservedSlot(CALLEE_SLOT).isNull();
}
inline JSFunction &
CallObject::callee() const
{
return getReservedSlot(CALLEE_SLOT).toObject().as<JSFunction>();
}
inline const Value &
CallObject::aliasedVar(AliasedFormalIter fi)
{
return getSlot(fi.scopeSlot());
}
inline void inline void
CallObject::setAliasedVar(JSContext *cx, AliasedFormalIter fi, PropertyName *name, const Value &v) CallObject::setAliasedVar(JSContext *cx, AliasedFormalIter fi, PropertyName *name, const Value &v)
{ {
@ -104,55 +46,6 @@ CallObject::setAliasedVar(JSContext *cx, AliasedFormalIter fi, PropertyName *nam
types::AddTypePropertyId(cx, this, NameToId(name), v); types::AddTypePropertyId(cx, this, NameToId(name), v);
} }
/*static*/ inline size_t
CallObject::offsetOfCallee()
{
return getFixedSlotOffset(CALLEE_SLOT);
}
inline uint32_t
NestedScopeObject::stackDepth() const
{
return getReservedSlot(DEPTH_SLOT).toPrivateUint32();
}
inline JSObject &
WithObject::withThis() const
{
return getReservedSlot(THIS_SLOT).toObject();
}
inline JSObject &
WithObject::object() const
{
return *JSObject::getProto();
}
inline uint32_t
BlockObject::slotCount() const
{
return propertyCount();
}
inline unsigned
BlockObject::slotToLocalIndex(const Bindings &bindings, unsigned slot)
{
JS_ASSERT(slot < RESERVED_SLOTS + slotCount());
return bindings.numVars() + stackDepth() + (slot - RESERVED_SLOTS);
}
inline unsigned
BlockObject::localIndexToSlot(const Bindings &bindings, unsigned i)
{
return RESERVED_SLOTS + (i - (bindings.numVars() + stackDepth()));
}
inline const Value &
BlockObject::slotValue(unsigned i)
{
return getSlotRef(RESERVED_SLOTS + i);
}
inline void inline void
BlockObject::setSlotValue(unsigned i, const Value &v) BlockObject::setSlotValue(unsigned i, const Value &v)
{ {
@ -178,19 +71,6 @@ StaticBlockObject::initEnclosingStaticScope(JSObject *obj)
setReservedSlot(SCOPE_CHAIN_SLOT, ObjectOrNullValue(obj)); setReservedSlot(SCOPE_CHAIN_SLOT, ObjectOrNullValue(obj));
} }
inline StaticBlockObject *
StaticBlockObject::enclosingBlock() const
{
JSObject *obj = getReservedSlot(SCOPE_CHAIN_SLOT).toObjectOrNull();
return obj && obj->is<StaticBlockObject>() ? &obj->as<StaticBlockObject>() : NULL;
}
inline JSObject *
StaticBlockObject::enclosingStaticScope() const
{
return getReservedSlot(SCOPE_CHAIN_SLOT).toObjectOrNull();
}
inline void inline void
StaticBlockObject::setStackDepth(uint32_t depth) StaticBlockObject::setStackDepth(uint32_t depth)
{ {
@ -205,13 +85,6 @@ StaticBlockObject::setDefinitionParseNode(unsigned i, frontend::Definition *def)
setSlotValue(i, PrivateValue(def)); setSlotValue(i, PrivateValue(def));
} }
inline frontend::Definition *
StaticBlockObject::maybeDefinitionParseNode(unsigned i)
{
Value v = slotValue(i);
return v.isUndefined() ? NULL : reinterpret_cast<frontend::Definition *>(v.toPrivate());
}
inline void inline void
StaticBlockObject::setAliased(unsigned i, bool aliased) StaticBlockObject::setAliased(unsigned i, bool aliased)
{ {
@ -223,37 +96,6 @@ StaticBlockObject::setAliased(unsigned i, bool aliased)
} }
} }
inline bool
StaticBlockObject::isAliased(unsigned i)
{
return slotValue(i).isTrue();
}
inline bool
StaticBlockObject::needsClone()
{
return !slotValue(0).isFalse();
}
inline bool
StaticBlockObject::containsVarAtDepth(uint32_t depth)
{
return depth >= stackDepth() && depth < stackDepth() + slotCount();
}
inline StaticBlockObject &
ClonedBlockObject::staticBlock() const
{
return getProto()->as<StaticBlockObject>();
}
inline const Value &
ClonedBlockObject::var(unsigned i, MaybeCheckAliasing checkAliasing)
{
JS_ASSERT_IF(checkAliasing, staticBlock().isAliased(i));
return slotValue(i);
}
inline void inline void
ClonedBlockObject::setVar(unsigned i, const Value &v, MaybeCheckAliasing checkAliasing) ClonedBlockObject::setVar(unsigned i, const Value &v, MaybeCheckAliasing checkAliasing)
{ {

Просмотреть файл

@ -167,7 +167,7 @@ class ScopeObject : public JSObject
inline JSObject &enclosingScope() const { inline JSObject &enclosingScope() const {
return getReservedSlot(SCOPE_CHAIN_SLOT).toObject(); return getReservedSlot(SCOPE_CHAIN_SLOT).toObject();
} }
inline void setEnclosingScope(HandleObject obj); void setEnclosingScope(HandleObject obj);
/* /*
* Get or set an aliased variable contained in this scope. Unaliased * Get or set an aliased variable contained in this scope. Unaliased
@ -176,12 +176,15 @@ class ScopeObject : public JSObject
* take a ScopeCoordinate instead of just the slot index. * take a ScopeCoordinate instead of just the slot index.
*/ */
inline const Value &aliasedVar(ScopeCoordinate sc); inline const Value &aliasedVar(ScopeCoordinate sc);
inline void setAliasedVar(JSContext *cx, ScopeCoordinate sc, PropertyName *name, const Value &v); inline void setAliasedVar(JSContext *cx, ScopeCoordinate sc, PropertyName *name, const Value &v);
/* For jit access. */ /* For jit access. */
static inline size_t offsetOfEnclosingScope(); static size_t offsetOfEnclosingScope() {
return getFixedSlotOffset(SCOPE_CHAIN_SLOT);
}
static inline size_t enclosingScopeSlot() { static size_t enclosingScopeSlot() {
return SCOPE_CHAIN_SLOT; return SCOPE_CHAIN_SLOT;
} }
}; };
@ -211,21 +214,34 @@ class CallObject : public ScopeObject
static CallObject *createForStrictEval(JSContext *cx, AbstractFramePtr frame); static CallObject *createForStrictEval(JSContext *cx, AbstractFramePtr frame);
/* True if this is for a strict mode eval frame. */ /* True if this is for a strict mode eval frame. */
inline bool isForEval() const; bool isForEval() const {
JS_ASSERT(getReservedSlot(CALLEE_SLOT).isObjectOrNull());
JS_ASSERT_IF(getReservedSlot(CALLEE_SLOT).isObject(),
getReservedSlot(CALLEE_SLOT).toObject().is<JSFunction>());
return getReservedSlot(CALLEE_SLOT).isNull();
}
/* /*
* Returns the function for which this CallObject was created. (This may * Returns the function for which this CallObject was created. (This may
* only be called if !isForEval.) * only be called if !isForEval.)
*/ */
inline JSFunction &callee() const; JSFunction &callee() const {
return getReservedSlot(CALLEE_SLOT).toObject().as<JSFunction>();
}
/* Get/set the aliased variable referred to by 'bi'. */ /* Get/set the aliased variable referred to by 'bi'. */
inline const Value &aliasedVar(AliasedFormalIter fi); const Value &aliasedVar(AliasedFormalIter fi) {
return getSlot(fi.scopeSlot());
}
inline void setAliasedVar(JSContext *cx, AliasedFormalIter fi, PropertyName *name, const Value &v); inline void setAliasedVar(JSContext *cx, AliasedFormalIter fi, PropertyName *name, const Value &v);
/* For jit access. */ /* For jit access. */
static inline size_t offsetOfCallee(); static size_t offsetOfCallee() {
static inline size_t calleeSlot() { return getFixedSlotOffset(CALLEE_SLOT);
}
static size_t calleeSlot() {
return CALLEE_SLOT; return CALLEE_SLOT;
} }
}; };
@ -258,7 +274,9 @@ class NestedScopeObject : public ScopeObject
public: public:
/* Return the abstract stack depth right before entering this nested scope. */ /* Return the abstract stack depth right before entering this nested scope. */
uint32_t stackDepth() const; uint32_t stackDepth() const {
return getReservedSlot(DEPTH_SLOT).toPrivateUint32();
}
}; };
class WithObject : public NestedScopeObject class WithObject : public NestedScopeObject
@ -278,10 +296,14 @@ class WithObject : public NestedScopeObject
create(JSContext *cx, HandleObject proto, HandleObject enclosing, uint32_t depth); create(JSContext *cx, HandleObject proto, HandleObject enclosing, uint32_t depth);
/* Return object for the 'this' class hook. */ /* Return object for the 'this' class hook. */
JSObject &withThis() const; JSObject &withThis() const {
return getReservedSlot(THIS_SLOT).toObject();
}
/* Return the 'o' in 'with (o)'. */ /* Return the 'o' in 'with (o)'. */
JSObject &object() const; JSObject &object() const {
return *JSObject::getProto();
}
}; };
class BlockObject : public NestedScopeObject class BlockObject : public NestedScopeObject
@ -293,19 +315,30 @@ class BlockObject : public NestedScopeObject
static Class class_; static Class class_;
/* Return the number of variables associated with this block. */ /* Return the number of variables associated with this block. */
inline uint32_t slotCount() const; uint32_t slotCount() const {
return propertyCount();
}
/* /*
* Return the local corresponding to the ith binding where i is in the * Return the local corresponding to the ith binding where i is in the
* range [0, slotCount()) and the return local index is in the range * range [0, slotCount()) and the return local index is in the range
* [script->nfixed, script->nfixed + script->nslots). * [script->nfixed, script->nfixed + script->nslots).
*/ */
unsigned slotToLocalIndex(const Bindings &bindings, unsigned slot); unsigned slotToLocalIndex(const Bindings &bindings, unsigned slot) {
unsigned localIndexToSlot(const Bindings &bindings, uint32_t i); JS_ASSERT(slot < RESERVED_SLOTS + slotCount());
return bindings.numVars() + stackDepth() + (slot - RESERVED_SLOTS);
}
unsigned localIndexToSlot(const Bindings &bindings, uint32_t i) {
return RESERVED_SLOTS + (i - (bindings.numVars() + stackDepth()));
}
protected: protected:
/* Blocks contain an object slot for each slot i: 0 <= i < slotCount. */ /* Blocks contain an object slot for each slot i: 0 <= i < slotCount. */
inline const Value &slotValue(unsigned i); const Value &slotValue(unsigned i) {
return getSlotRef(RESERVED_SLOTS + i);
}
inline void setSlotValue(unsigned i, const Value &v); inline void setSlotValue(unsigned i, const Value &v);
}; };
@ -315,7 +348,9 @@ class StaticBlockObject : public BlockObject
static StaticBlockObject *create(JSContext *cx); static StaticBlockObject *create(JSContext *cx);
/* See StaticScopeIter comment. */ /* See StaticScopeIter comment. */
inline JSObject *enclosingStaticScope() const; JSObject *enclosingStaticScope() const {
return getReservedSlot(SCOPE_CHAIN_SLOT).toObjectOrNull();
}
/* /*
* A refinement of enclosingStaticScope that returns NULL if the enclosing * A refinement of enclosingStaticScope that returns NULL if the enclosing
@ -327,19 +362,25 @@ class StaticBlockObject : public BlockObject
* Return whether this StaticBlockObject contains a variable stored at * Return whether this StaticBlockObject contains a variable stored at
* the given stack depth (i.e., fp->base()[depth]). * the given stack depth (i.e., fp->base()[depth]).
*/ */
bool containsVarAtDepth(uint32_t depth); bool containsVarAtDepth(uint32_t depth) {
return depth >= stackDepth() && depth < stackDepth() + slotCount();
}
/* /*
* A let binding is aliased if accessed lexically by nested functions or * A let binding is aliased if accessed lexically by nested functions or
* dynamically through dynamic name lookup (eval, with, function::, etc). * dynamically through dynamic name lookup (eval, with, function::, etc).
*/ */
bool isAliased(unsigned i); bool isAliased(unsigned i) {
return slotValue(i).isTrue();
}
/* /*
* A static block object is cloned (when entering the block) iff some * A static block object is cloned (when entering the block) iff some
* variable of the block isAliased. * variable of the block isAliased.
*/ */
bool needsClone(); bool needsClone() {
return !slotValue(0).isFalse();
}
/* Frontend-only functions ***********************************************/ /* Frontend-only functions ***********************************************/
@ -353,7 +394,10 @@ class StaticBlockObject : public BlockObject
* a let var to its associated Definition parse node. * a let var to its associated Definition parse node.
*/ */
void setDefinitionParseNode(unsigned i, frontend::Definition *def); void setDefinitionParseNode(unsigned i, frontend::Definition *def);
frontend::Definition *maybeDefinitionParseNode(unsigned i); frontend::Definition *maybeDefinitionParseNode(unsigned i) {
Value v = slotValue(i);
return v.isUndefined() ? NULL : reinterpret_cast<frontend::Definition *>(v.toPrivate());
}
/* /*
* The parser uses 'enclosingBlock' as the prev-link in the pc->blockChain * The parser uses 'enclosingBlock' as the prev-link in the pc->blockChain
@ -375,11 +419,17 @@ class ClonedBlockObject : public BlockObject
AbstractFramePtr frame); AbstractFramePtr frame);
/* The static block from which this block was cloned. */ /* The static block from which this block was cloned. */
StaticBlockObject &staticBlock() const; StaticBlockObject &staticBlock() const {
return getProto()->as<StaticBlockObject>();
}
/* Assuming 'put' has been called, return the value of the ith let var. */ /* Assuming 'put' has been called, return the value of the ith let var. */
const Value &var(unsigned i, MaybeCheckAliasing = CHECK_ALIASING); const Value &var(unsigned i, MaybeCheckAliasing checkAliasing = CHECK_ALIASING) {
void setVar(unsigned i, const Value &v, MaybeCheckAliasing = CHECK_ALIASING); JS_ASSERT_IF(checkAliasing, staticBlock().isAliased(i));
return slotValue(i);
}
void setVar(unsigned i, const Value &v, MaybeCheckAliasing checkAliasing = CHECK_ALIASING);
/* Copy in all the unaliased formals and locals. */ /* Copy in all the unaliased formals and locals. */
void copyUnaliasedValues(AbstractFramePtr frame); void copyUnaliasedValues(AbstractFramePtr frame);
@ -653,4 +703,46 @@ JSObject::is<js::DebugScopeObject>() const
return getClass() == &js::ObjectProxyClass && js_IsDebugScopeSlow(const_cast<JSObject*>(this)); return getClass() == &js::ObjectProxyClass && js_IsDebugScopeSlow(const_cast<JSObject*>(this));
} }
template<>
inline bool
JSObject::is<js::ClonedBlockObject>() const
{
return is<js::BlockObject>() && !!getProto();
}
template<>
inline bool
JSObject::is<js::StaticBlockObject>() const
{
return is<js::BlockObject>() && !getProto();
}
inline JSObject *
JSObject::enclosingScope()
{
return is<js::ScopeObject>()
? &as<js::ScopeObject>().enclosingScope()
: is<js::DebugScopeObject>()
? &as<js::DebugScopeObject>().enclosingScope()
: getParent();
}
namespace js {
inline const Value &
ScopeObject::aliasedVar(ScopeCoordinate sc)
{
JS_ASSERT(is<CallObject>() || is<ClonedBlockObject>());
return getSlot(sc.slot);
}
inline StaticBlockObject *
StaticBlockObject::enclosingBlock() const
{
JSObject *obj = getReservedSlot(SCOPE_CHAIN_SLOT).toObjectOrNull();
return obj && obj->is<StaticBlockObject>() ? &obj->as<StaticBlockObject>() : NULL;
}
} // namespace js
#endif /* vm_ScopeObject_h */ #endif /* vm_ScopeObject_h */