JSJavaScriptCallFrameCustom.cpp [plain text]
#include "config.h"
#if ENABLE(JAVASCRIPT_DEBUGGER)
#include "JSJavaScriptCallFrame.h"
#include "JavaScriptCallFrame.h"
#include <runtime/ArrayPrototype.h>
#include <runtime/Error.h>
using namespace JSC;
namespace WebCore {
JSValue JSJavaScriptCallFrame::evaluate(ExecState* exec)
{
JSValue exception;
JSValue result = impl()->evaluate(exec->argument(0).toString(exec)->value(exec), exception);
if (exception)
throwError(exec, exception);
return result;
}
JSValue JSJavaScriptCallFrame::thisObject(ExecState*) const
{
return impl()->thisObject() ? JSValue(impl()->thisObject()) : jsNull();
}
JSValue JSJavaScriptCallFrame::type(ExecState* exec) const
{
switch (impl()->type()) {
case DebuggerCallFrame::FunctionType:
return jsString(exec, UString("function"));
case DebuggerCallFrame::ProgramType:
return jsString(exec, UString("program"));
}
ASSERT_NOT_REACHED();
return jsNull();
}
JSValue JSJavaScriptCallFrame::scopeChain(ExecState* exec) const
{
if (!impl()->scopeChain())
return jsNull();
ScopeChainNode* scopeChain = impl()->scopeChain();
ScopeChainIterator iter = scopeChain->begin();
ScopeChainIterator end = scopeChain->end();
ASSERT(iter != end);
MarkedArgumentBuffer list;
do {
list.append(iter->get());
++iter;
} while (iter != end);
return constructArray(exec, globalObject(), list);
}
JSValue JSJavaScriptCallFrame::scopeType(ExecState* exec)
{
if (!impl()->scopeChain())
return jsUndefined();
if (!exec->argument(0).isInt32())
return jsUndefined();
int index = exec->argument(0).asInt32();
ScopeChainNode* scopeChain = impl()->scopeChain();
ScopeChainIterator end = scopeChain->end();
bool foundLocalScope = false;
for (ScopeChainIterator iter = scopeChain->begin(); iter != end; ++iter) {
JSObject* scope = iter->get();
if (scope->isActivationObject()) {
if (!foundLocalScope) {
if (!index)
return jsJavaScriptCallFrameLOCAL_SCOPE(exec, JSValue(), Identifier());
foundLocalScope = true;
} else if (!index)
return jsJavaScriptCallFrameCLOSURE_SCOPE(exec, JSValue(), Identifier());
}
if (!index) {
if (++iter == end)
return jsJavaScriptCallFrameGLOBAL_SCOPE(exec, JSValue(), Identifier());
return jsJavaScriptCallFrameWITH_SCOPE(exec, JSValue(), Identifier());
}
--index;
}
return jsUndefined();
}
}
#endif // ENABLE(JAVASCRIPT_DEBUGGER)