#ifndef KJS_SCOPE_CHAIN_H
#define KJS_SCOPE_CHAIN_H
#include "fast_malloc.h"
namespace KJS {
class ObjectImp;
class ExecState;
class ScopeChainNode {
public:
ScopeChainNode(ScopeChainNode *n, ObjectImp *o)
: next(n), object(o), refCount(1) { }
KJS_FAST_ALLOCATED;
ScopeChainNode *next;
ObjectImp *object;
int refCount;
};
class ScopeChain {
public:
ScopeChain() : _node(0) { }
~ScopeChain() { deref(); }
ScopeChain(const ScopeChain &c) : _node(c._node)
{ if (_node) ++_node->refCount; }
ScopeChain &operator=(const ScopeChain &);
bool isEmpty() const { return !_node; }
ObjectImp *top() const { return _node->object; }
ObjectImp *bottom() const;
void clear() { deref(); _node = 0; }
void push(ObjectImp *);
void push(const ScopeChain &);
void pop();
void mark();
private:
ScopeChainNode *_node;
void deref() { if (_node && --_node->refCount == 0) release(); }
void ref() const;
void release();
};
};
#endif // KJS_SCOPE_CHAIN_H