#include "config.h"
#include "ScopeChain.h"
#include "JSActivation.h"
#include "JSGlobalObject.h"
#include "JSObject.h"
#include "PropertyNameArray.h"
#include <stdio.h>
namespace JSC {
ASSERT_HAS_TRIVIAL_DESTRUCTOR(ScopeChainNode);
#ifndef NDEBUG
void ScopeChainNode::print()
{
ScopeChainIterator scopeEnd = end();
for (ScopeChainIterator scopeIter = begin(); scopeIter != scopeEnd; ++scopeIter) {
JSObject* o = scopeIter->get();
PropertyNameArray propertyNames(globalObject->globalExec());
o->methodTable()->getPropertyNames(o, globalObject->globalExec(), propertyNames, ExcludeDontEnumProperties);
PropertyNameArray::const_iterator propEnd = propertyNames.end();
dataLog("----- [scope %p] -----\n", o);
for (PropertyNameArray::const_iterator propIter = propertyNames.begin(); propIter != propEnd; propIter++) {
Identifier name = *propIter;
dataLog("%s, ", name.ustring().utf8().data());
}
dataLog("\n");
}
}
#endif
const ClassInfo ScopeChainNode::s_info = { "ScopeChainNode", 0, 0, 0, CREATE_METHOD_TABLE(ScopeChainNode) };
int ScopeChainNode::localDepth()
{
int scopeDepth = 0;
ScopeChainIterator iter = this->begin();
ScopeChainIterator end = this->end();
while (!(*iter)->inherits(&JSActivation::s_info)) {
++iter;
if (iter == end)
break;
++scopeDepth;
}
return scopeDepth;
}
void ScopeChainNode::visitChildren(JSCell* cell, SlotVisitor& visitor)
{
ScopeChainNode* thisObject = jsCast<ScopeChainNode*>(cell);
ASSERT_GC_OBJECT_INHERITS(thisObject, &s_info);
COMPILE_ASSERT(StructureFlags & OverridesVisitChildren, OverridesVisitChildrenWithoutSettingFlag);
ASSERT(thisObject->structure()->typeInfo().overridesVisitChildren());
if (thisObject->next)
visitor.append(&thisObject->next);
visitor.append(&thisObject->object);
visitor.append(&thisObject->globalObject);
visitor.append(&thisObject->globalThis);
}
}