runtime_object.cpp [plain text]
#if BINDINGS
#include "config.h"
#include "runtime_object.h"
#include "error_object.h"
#include "operations.h"
#include "runtime_method.h"
using namespace KJS;
using namespace Bindings;
const ClassInfo RuntimeObjectImp::info = {"RuntimeObject", 0, 0, 0};
RuntimeObjectImp::RuntimeObjectImp(Bindings::Instance *i)
: instance(i)
{
}
JSValue *RuntimeObjectImp::fallbackObjectGetter(ExecState* exec, JSObject*, const Identifier& propertyName, const PropertySlot& slot)
{
RuntimeObjectImp *thisObj = static_cast<RuntimeObjectImp *>(slot.slotBase());
Bindings::Instance *instance = thisObj->instance.get();
instance->begin();
Class *aClass = instance->getClass();
JSValue *result = aClass->fallbackObject(exec, instance, propertyName);
instance->end();
return result;
}
JSValue *RuntimeObjectImp::fieldGetter(ExecState* exec, JSObject*, const Identifier& propertyName, const PropertySlot& slot)
{
RuntimeObjectImp *thisObj = static_cast<RuntimeObjectImp *>(slot.slotBase());
Bindings::Instance *instance = thisObj->instance.get();
instance->begin();
Class *aClass = instance->getClass();
Field *aField = aClass->fieldNamed(propertyName.ascii(), instance);
JSValue *result = instance->getValueOfField(exec, aField);
instance->end();
return result;
}
JSValue *RuntimeObjectImp::methodGetter(ExecState* exec, JSObject*, const Identifier& propertyName, const PropertySlot& slot)
{
RuntimeObjectImp *thisObj = static_cast<RuntimeObjectImp *>(slot.slotBase());
Bindings::Instance *instance = thisObj->instance.get();
instance->begin();
Class *aClass = instance->getClass();
MethodList methodList = aClass->methodsNamed(propertyName.ascii(), instance);
JSValue *result = new RuntimeMethod(exec, propertyName, methodList);
instance->end();
return result;
}
bool RuntimeObjectImp::getOwnPropertySlot(ExecState *exec, const Identifier& propertyName, PropertySlot& slot)
{
instance->begin();
Class *aClass = instance->getClass();
if (aClass) {
Field *aField = aClass->fieldNamed(propertyName.ascii(), instance.get());
if (aField) {
slot.setCustom(this, fieldGetter);
instance->end();
return true;
} else {
MethodList methodList = aClass->methodsNamed(propertyName.ascii(), instance.get());
if (methodList.length() > 0) {
slot.setCustom(this, methodGetter);
instance->end();
return true;
}
}
if (!aClass->fallbackObject(exec, instance.get(), propertyName)->isUndefined()) {
slot.setCustom(this, fallbackObjectGetter);
instance->end();
return true;
}
}
instance->end();
return false;
}
void RuntimeObjectImp::put(ExecState* exec, const Identifier& propertyName, JSValue* value, int)
{
instance->begin();
Field *aField = instance->getClass()->fieldNamed(propertyName.ascii(), instance.get());
if (aField) {
getInternalInstance()->setValueOfField(exec, aField, value);
}
else {
if (getInternalInstance()->supportsSetValueOfUndefinedField()){
getInternalInstance()->setValueOfUndefinedField(exec, propertyName, value);
}
}
instance->end();
}
bool RuntimeObjectImp::canPut(ExecState*, const Identifier& propertyName) const
{
bool result = false;
instance->begin();
Field *aField = instance->getClass()->fieldNamed(propertyName.ascii(), instance.get());
instance->end();
if (aField)
return true;
return result;
}
bool RuntimeObjectImp::deleteProperty(ExecState*, const Identifier&)
{
return false;
}
JSValue *RuntimeObjectImp::defaultValue(ExecState*, JSType hint) const
{
JSValue *result;
instance->begin();
result = getInternalInstance()->defaultValue(hint);
instance->end();
return result;
}
bool RuntimeObjectImp::implementsCall() const
{
return getInternalInstance()->implementsCall();
}
JSValue *RuntimeObjectImp::callAsFunction(ExecState* exec, JSObject*, const List& args)
{
instance->begin();
JSValue *aValue = getInternalInstance()->invokeDefaultMethod(exec, args);
instance->end();
return aValue;
}
#endif //BINDINGS