00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
#include "scope_chain.h"
00023
00024
#include "object.h"
00025
00026
#include <assert.h>
00027
00028
namespace KJS {
00029
00030
inline void ScopeChain::ref()
const
00031
{
00032
for (ScopeChainNode *n = _node; n; n = n->next) {
00033
if (n->refCount++ != 0)
00034
break;
00035 }
00036 }
00037
00038 ScopeChain &ScopeChain::operator=(
const ScopeChain &c)
00039 {
00040 c.ref();
00041 deref();
00042 _node = c._node;
00043
return *
this;
00044 }
00045
00046
void ScopeChain::push(ObjectImp *o)
00047 {
00048 assert(o);
00049 _node =
new ScopeChainNode(_node, o);
00050 }
00051
00052
void ScopeChain::pop()
00053 {
00054 ScopeChainNode *oldNode = _node;
00055 assert(oldNode);
00056 ScopeChainNode *newNode = oldNode->next;
00057 _node = newNode;
00058
00059
if (--oldNode->refCount != 0) {
00060
if (newNode)
00061 ++newNode->refCount;
00062 }
else {
00063
delete oldNode;
00064 }
00065 }
00066
00067
void ScopeChain::release()
00068 {
00069
00070
00071 assert(_node && _node->refCount == 0);
00072 ScopeChainNode *n = _node;
00073
do {
00074 ScopeChainNode *
next = n->next;
00075
delete n;
00076 n =
next;
00077 }
while (n && --n->refCount == 0);
00078 }
00079
00080
void ScopeChain::mark()
00081 {
00082
for (ScopeChainNode *n = _node; n; n = n->next) {
00083 ObjectImp *o = n->object;
00084
if (!o->marked())
00085 o->mark();
00086 }
00087 }
00088
00089 }