#include "context.h"
namespace KJS {
Context::Context(JSObject* glob, Interpreter* interpreter, JSObject* thisV,
FunctionBodyNode* currentBody, CodeType type, Context* callingCon,
FunctionImp* func, const List* args)
: m_interpreter(interpreter)
, m_currentBody(currentBody)
, m_function(func)
, m_arguments(args)
, m_iterationDepth(0)
, m_switchDepth(0)
{
m_codeType = type;
m_callingContext = callingCon;
if (type == FunctionCode || type == AnonymousCode ) {
m_activation = new ActivationImp(func, *args);
m_variable = m_activation;
} else {
m_activation = 0;
m_variable = glob;
}
switch(type) {
case EvalCode:
if (m_callingContext) {
scope = m_callingContext->scopeChain();
m_variable = m_callingContext->variableObject();
m_thisVal = m_callingContext->thisValue();
break;
} case GlobalCode:
scope.clear();
scope.push(glob);
m_thisVal = static_cast<JSObject*>(glob);
break;
case FunctionCode:
case AnonymousCode:
if (type == FunctionCode) {
scope = func->scope();
scope.push(m_activation);
} else {
scope.clear();
scope.push(glob);
scope.push(m_activation);
}
m_variable = m_activation; m_thisVal = thisV;
break;
}
m_interpreter->setContext(this);
}
Context::~Context()
{
m_interpreter->setContext(m_callingContext);
}
void Context::mark()
{
for (Context* context = this; context; context = context->m_callingContext)
context->scope.mark();
}
}