runtime_method.cpp [plain text]
#include "config.h"
#include "runtime_method.h"
#include "JSDOMBinding.h"
#include "JSHTMLElement.h"
#include "JSPluginElementFunctions.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", &InternalFunction::info, 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, JSValue slotBase, const Identifier&)
{
RuntimeMethod* thisObj = static_cast<RuntimeMethod*>(asObject(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.setCacheableCustom(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();
RefPtr<Instance> instance;
if (thisValue.inherits(&RuntimeObject::s_info)) {
RuntimeObject* runtimeObject = static_cast<RuntimeObject*>(asObject(thisValue));
instance = runtimeObject->getInternalInstance();
if (!instance)
return RuntimeObject::throwInvalidAccessError(exec);
} else {
if (thisValue.inherits(&JSHTMLElement::s_info)) {
HTMLElement* element = static_cast<JSHTMLElement*>(asObject(thisValue))->impl();
instance = pluginInstance(element);
}
if (!instance)
return throwError(exec, TypeError);
}
ASSERT(instance);
instance->begin();
JSValue result = instance->invokeMethod(exec, method, args);
instance->end();
return result;
}
CallType RuntimeMethod::getCallData(CallData& callData)
{
callData.native.function = callRuntimeMethod;
return CallTypeHost;
}
}