runtime_method.cpp [plain text]
#include "config.h"
#include "runtime_method.h"
#include "JSDOMBinding.h"
#include "runtime_object.h"
#include <runtime/Error.h>
#include <runtime/FunctionPrototype.h>
using namespace WebCore;
namespace JSC {
using namespace Bindings;
ASSERT_CLASS_FITS_IN_CELL(RuntimeMethod);
const ClassInfo RuntimeMethod::s_info = { "RuntimeMethod", 0, 0, 0 };
RuntimeMethod::RuntimeMethod(ExecState* exec, const Identifier& ident, Bindings::MethodList& m)
: InternalFunction(&exec->globalData(), deprecatedGetDOMStructure<RuntimeMethod>(exec), ident)
, _methodList(new MethodList(m))
{
}
JSValue RuntimeMethod::lengthGetter(ExecState* exec, const Identifier&, const PropertySlot& slot)
{
RuntimeMethod* thisObj = static_cast<RuntimeMethod*>(asObject(slot.slotBase()));
return jsNumber(exec, thisObj->_methodList->at(0)->numParameters());
}
bool RuntimeMethod::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot &slot)
{
if (propertyName == exec->propertyNames().length) {
slot.setCustom(this, lengthGetter);
return true;
}
return InternalFunction::getOwnPropertySlot(exec, propertyName, slot);
}
bool RuntimeMethod::getOwnPropertyDescriptor(ExecState* exec, const Identifier& propertyName, PropertyDescriptor &descriptor)
{
if (propertyName == exec->propertyNames().length) {
PropertySlot slot;
slot.setCustom(this, lengthGetter);
descriptor.setDescriptor(slot.getValue(exec, propertyName), ReadOnly | DontDelete | DontEnum);
return true;
}
return InternalFunction::getOwnPropertyDescriptor(exec, propertyName, descriptor);
}
static JSValue JSC_HOST_CALL callRuntimeMethod(ExecState* exec, JSObject* function, JSValue thisValue, const ArgList& args)
{
RuntimeMethod* method = static_cast<RuntimeMethod*>(function);
if (method->methods()->isEmpty())
return jsUndefined();
RuntimeObjectImp* imp;
if (thisValue.inherits(&RuntimeObjectImp::s_info)) {
imp = static_cast<RuntimeObjectImp*>(asObject(thisValue));
} else {
JSValue value = thisValue.get(exec, Identifier(exec, "__apple_runtime_object"));
if (value.inherits(&RuntimeObjectImp::s_info))
imp = static_cast<RuntimeObjectImp*>(asObject(value));
else
return throwError(exec, TypeError);
}
RefPtr<Instance> instance = imp->getInternalInstance();
if (!instance)
return RuntimeObjectImp::throwInvalidAccessError(exec);
instance->begin();
JSValue result = instance->invokeMethod(exec, *method->methods(), args);
instance->end();
return result;
}
CallType RuntimeMethod::getCallData(CallData& callData)
{
callData.native.function = callRuntimeMethod;
return CallTypeHost;
}
}