runtime_method.cpp [plain text]
#include "context.h"
#include "internal.h"
#include "runtime_method.h"
#include "runtime_object.h"
using namespace KJS::Bindings;
using namespace KJS;
RuntimeMethodImp::RuntimeMethodImp(ExecState *exec, const Identifier &ident, Bindings::MethodList &m) : FunctionImp (exec, ident)
{
_methodList = m;
}
RuntimeMethodImp::~RuntimeMethodImp()
{
}
Value RuntimeMethodImp::get(ExecState *exec, const Identifier &propertyName) const
{
if (propertyName == argumentsPropertyName) {
ContextImp *context = exec->_context;
while (context) {
if (context->function() == this)
return static_cast<ActivationImp *>
(context->activationObject())->get(exec, propertyName);
context = context->callingContext();
}
return Undefined();
}
if (propertyName == lengthPropertyName) {
return Number(_methodList.methodAt(0)->numParameters());
}
return FunctionImp::get(exec, propertyName);
}
bool RuntimeMethodImp::implementsCall() const
{
return true;
}
Value RuntimeMethodImp::call(ExecState *exec, Object &thisObj, const List &args)
{
if (_methodList.length() > 0) {
RuntimeObjectImp *imp;
if (thisObj.classInfo() != &KJS::RuntimeObjectImp::info) {
Value runtimeObject = thisObj.get(exec, "__apple_runtime_object");
imp = static_cast<RuntimeObjectImp*>(runtimeObject.imp());
}
else {
imp = static_cast<RuntimeObjectImp*>(thisObj.imp());
}
if (imp) {
Instance *instance = imp->getInternalInstance();
instance->begin();
Value aValue = instance->invokeMethod(exec, _methodList, args);
instance->end();
return aValue;
}
}
return Undefined();
}
CodeType RuntimeMethodImp::codeType() const
{
return FunctionCode;
}
Completion RuntimeMethodImp::execute(ExecState *exec)
{
return Completion(Normal, Undefined());
}