Commit 27856417 authored by andersca's avatar andersca
Browse files

Reviewed by Oliver.

        
        Get rid of the MethodList class and use a good ol' Vector instead.

        * bindings/c/c_class.cpp:
        (KJS::Bindings::CClass::methodsNamed):
        * bindings/c/c_instance.cpp:
        (KJS::Bindings::CInstance::invokeMethod):
        * bindings/jni/jni_class.cpp:
        (JavaClass::JavaClass):
        (JavaClass::~JavaClass):
        * bindings/jni/jni_instance.cpp:
        (JavaInstance::invokeMethod):
        * bindings/objc/objc_class.mm:
        (KJS::Bindings::ObjcClass::methodsNamed):
        * bindings/objc/objc_instance.mm:
        (ObjcInstance::invokeMethod):
        * bindings/objc/objc_runtime.mm:
        (ObjcFallbackObjectImp::callAsFunction):
        * bindings/runtime.cpp:
        * bindings/runtime.h:
        * bindings/runtime_method.cpp:
        (RuntimeMethod::lengthGetter):
        (RuntimeMethod::callAsFunction):
        * bindings/runtime_object.cpp:
        (RuntimeObjectImp::getOwnPropertySlot):



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@23479 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent b7e13e4e
2007-06-12 Anders Carlsson <andersca@apple.com>
Reviewed by Oliver.
Get rid of the MethodList class and use a good ol' Vector instead.
* bindings/c/c_class.cpp:
(KJS::Bindings::CClass::methodsNamed):
* bindings/c/c_instance.cpp:
(KJS::Bindings::CInstance::invokeMethod):
* bindings/jni/jni_class.cpp:
(JavaClass::JavaClass):
(JavaClass::~JavaClass):
* bindings/jni/jni_instance.cpp:
(JavaInstance::invokeMethod):
* bindings/objc/objc_class.mm:
(KJS::Bindings::ObjcClass::methodsNamed):
* bindings/objc/objc_instance.mm:
(ObjcInstance::invokeMethod):
* bindings/objc/objc_runtime.mm:
(ObjcFallbackObjectImp::callAsFunction):
* bindings/runtime.cpp:
* bindings/runtime.h:
* bindings/runtime_method.cpp:
(RuntimeMethod::lengthGetter):
(RuntimeMethod::callAsFunction):
* bindings/runtime_object.cpp:
(RuntimeObjectImp::getOwnPropertySlot):
2007-06-12 Anders Carlsson <andersca@apple.com>
 
Reviewed by Geoff.
......
......@@ -77,7 +77,7 @@ MethodList CClass::methodsNamed(const Identifier& identifier, Instance* instance
Method* method = _methods.get(identifier.ustring().rep());
if (method) {
methodList.addMethod(method);
methodList.append(method);
return methodList;
}
......@@ -90,7 +90,7 @@ MethodList CClass::methodsNamed(const Identifier& identifier, Instance* instance
JSLock lock;
_methods.set(identifier.ustring().rep(), aMethod);
}
methodList.addMethod(aMethod);
methodList.append(aMethod);
}
return methodList;
......
......@@ -77,9 +77,9 @@ JSValue* CInstance::invokeMethod(ExecState* exec, const MethodList& methodList,
{
// Overloading methods are not allowed by NPObjects. Should only be one
// name match for a particular method.
assert(methodList.length() == 1);
assert(methodList.size() == 1);
CMethod* method = static_cast<CMethod*>(methodList.methodAt(0));
CMethod* method = static_cast<CMethod*>(methodList[0]);
NPIdentifier ident = _NPN_GetStringIdentifier(method->name());
if (!_object->_class->hasMethod(_object, ident))
......
......@@ -77,7 +77,7 @@ JavaClass::JavaClass(jobject anInstance)
_methods.set(Identifier(aMethod->name()).ustring().rep(), methodList);
}
}
methodList->addMethod(aMethod);
methodList->append(aMethod);
env->DeleteLocalRef(aJMethod);
}
}
......@@ -93,9 +93,7 @@ JavaClass::~JavaClass() {
MethodListMap::const_iterator end = _methods.end();
for (MethodListMap::const_iterator it = _methods.begin(); it != end; ++it) {
const MethodList* methodList = it->second;
int length = methodList->length();
for (int i = 0; i < length; i++)
delete methodList->methodAt(i);
deleteAllValues(*methodList);
delete methodList;
}
_methods.clear();
......
......@@ -104,17 +104,16 @@ JSValue *JavaInstance::invokeMethod (ExecState *exec, const MethodList &methodLi
jvalue *jArgs;
JSValue *resultValue;
Method *method = 0;
unsigned int numMethods = methodList.length();
size_t numMethods = methodList.size();
// Try to find a good match for the overloaded method. The
// fundamental problem is that JavaScript doesn have the
// notion of method overloading and Java does. We could
// get a bit more sophisticated and attempt to does some
// type checking as we as checking the number of parameters.
unsigned int methodIndex;
Method *aMethod;
for (methodIndex = 0; methodIndex < numMethods; methodIndex++) {
aMethod = methodList.methodAt (methodIndex);
for (size_t methodIndex = 0; methodIndex < numMethods; methodIndex++) {
aMethod = methodList[methodIndex];
if (aMethod->numParameters() == count) {
method = aMethod;
break;
......
......@@ -95,12 +95,12 @@ MethodList ObjcClass::methodsNamed(const Identifier& identifier, Instance*) cons
RetainPtr<CFStringRef> methodName(AdoptCF, CFStringCreateWithCString(NULL, buffer, kCFStringEncodingASCII));
Method* method = (Method*)CFDictionaryGetValue(_methods.get(), methodName.get());
if (method) {
methodList.addMethod(method);
methodList.append(method);
return methodList;
}
ClassStructPtr thisClass = _isa;
while (thisClass && methodList.length() < 1) {
while (thisClass && methodList.isEmpty()) {
#if defined(OBJC_API_VERSION) && OBJC_API_VERSION >= 2
unsigned numMethodsInClass = 0;
MethodStructPtr* objcMethodList = class_copyMethodList(thisClass, &numMethodsInClass);
......@@ -135,7 +135,7 @@ MethodList ObjcClass::methodsNamed(const Identifier& identifier, Instance*) cons
if ((mappedName && [mappedName isEqual:(NSString*)methodName.get()]) || strcmp(objcMethodSelectorName, buffer) == 0) {
Method* aMethod = new ObjcMethod(thisClass, objcMethodSelectorName); // deleted when the dictionary is destroyed
CFDictionaryAddValue(_methods.get(), methodName.get(), aMethod);
methodList.addMethod(aMethod);
methodList.append(aMethod);
break;
}
}
......
......@@ -97,11 +97,11 @@ JSValue* ObjcInstance::invokeMethod(ExecState* exec, const MethodList &methodLis
// Overloading methods is not allowed in ObjectiveC. Should only be one
// name match for a particular method.
assert(methodList.length() == 1);
assert(methodList.size() == 1);
@try {
ObjcMethod* method = 0;
method = static_cast<ObjcMethod*>(methodList.methodAt(0));
method = static_cast<ObjcMethod*>(methodList[0]);
NSMethodSignature* signature = method->getMethodSignature();
NSInvocation* invocation = [NSInvocation invocationWithMethodSignature:signature];
#if defined(OBJC_API_VERSION) && OBJC_API_VERSION >= 2
......
......@@ -275,7 +275,7 @@ JSValue* ObjcFallbackObjectImp::callAsFunction(ExecState* exec, JSObject* thisOb
ObjcClass* objcClass = static_cast<ObjcClass*>(instance->getClass());
ObjcMethod* fallbackMethod = new ObjcMethod (objcClass->isa(), sel_getName(@selector(invokeUndefinedMethodFromWebScript:withArguments:)));
fallbackMethod->setJavaScriptName((CFStringRef)[NSString stringWithCString:_item.ascii() encoding:NSASCIIStringEncoding]);
methodList.addMethod ((Method*)fallbackMethod);
methodList.append(fallbackMethod);
result = instance->invokeMethod(exec, methodList, args);
delete fallbackMethod;
}
......
......@@ -44,56 +44,6 @@
namespace KJS { namespace Bindings {
void MethodList::addMethod(Method *aMethod)
{
Method **_newMethods = new Method *[_length + 1];
if (_length > 0) {
memcpy(_newMethods, _methods, sizeof(Method *) * _length);
delete [] _methods;
}
_methods = _newMethods;
_methods[_length++] = aMethod;
}
unsigned int MethodList::length() const
{
return _length;
}
Method *MethodList::methodAt(unsigned int index) const
{
assert(index < _length);
return _methods[index];
}
MethodList::~MethodList()
{
delete [] _methods;
}
MethodList::MethodList(const MethodList &other)
{
_length = other._length;
_methods = new Method *[_length];
if (_length > 0)
memcpy (_methods, other._methods, sizeof(Method *) * _length);
}
MethodList &MethodList::operator=(const MethodList &other)
{
if (this == &other)
return *this;
delete [] _methods;
_length = other._length;
_methods = new Method *[_length];
if (_length > 0)
memcpy(_methods, other._methods, sizeof(Method *) * _length);
return *this;
}
Array::Array(PassRefPtr<RootObject> rootObject)
: _rootObject(rootObject)
{
......
......@@ -30,6 +30,7 @@
#include <wtf/Noncopyable.h>
#include <wtf/HashMap.h>
#include <wtf/Vector.h>
namespace KJS {
......@@ -46,6 +47,8 @@ class RootObject;
// For now just use Java style type descriptors.
typedef const char * RuntimeType;
typedef Vector<Method*> MethodList;
class Field
{
public:
......@@ -58,25 +61,6 @@ public:
virtual ~Field() {}
};
class MethodList
{
public:
MethodList() : _methods(0), _length(0) {}
void addMethod(Method*);
unsigned int length() const;
Method* methodAt(unsigned int index) const;
~MethodList();
MethodList(const MethodList&);
MethodList& operator=(const MethodList&);
private:
Method **_methods;
unsigned int _length;
};
class Method : Noncopyable
{
public:
......
......@@ -53,7 +53,7 @@ JSValue *RuntimeMethod::lengthGetter(ExecState*, JSObject*, const Identifier&, c
// Java does.
// FIXME: a better solution might be to give the maximum number of parameters
// of any method
return jsNumber(thisObj->_methodList->methodAt(0)->numParameters());
return jsNumber(thisObj->_methodList->at(0)->numParameters());
}
bool RuntimeMethod::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot &slot)
......@@ -68,30 +68,29 @@ bool RuntimeMethod::getOwnPropertySlot(ExecState* exec, const Identifier& proper
JSValue *RuntimeMethod::callAsFunction(ExecState *exec, JSObject *thisObj, const List &args)
{
if (_methodList->length() > 0) {
RuntimeObjectImp *imp = 0;
if (thisObj->classInfo() == &KJS::RuntimeObjectImp::info) {
imp = static_cast<RuntimeObjectImp*>(thisObj);
} else {
// If thisObj is the DOM object for a plugin, get the corresponding
// runtime object from the DOM object.
JSValue* value = thisObj->get(exec, "__apple_runtime_object");
if (value->isObject(&KJS::RuntimeObjectImp::info))
imp = static_cast<RuntimeObjectImp*>(value);
}
if (!imp)
return throwError(exec, TypeError);
if (_methodList->isEmpty())
return jsUndefined();
RuntimeObjectImp *imp = 0;
Instance *instance = imp->getInternalInstance();
instance->begin();
JSValue *aValue = instance->invokeMethod(exec, *_methodList, args);
instance->end();
return aValue;
if (thisObj->classInfo() == &KJS::RuntimeObjectImp::info) {
imp = static_cast<RuntimeObjectImp*>(thisObj);
} else {
// If thisObj is the DOM object for a plugin, get the corresponding
// runtime object from the DOM object.
JSValue* value = thisObj->get(exec, "__apple_runtime_object");
if (value->isObject(&KJS::RuntimeObjectImp::info))
imp = static_cast<RuntimeObjectImp*>(value);
}
return jsUndefined();
if (!imp)
return throwError(exec, TypeError);
Instance *instance = imp->getInternalInstance();
instance->begin();
JSValue *aValue = instance->invokeMethod(exec, *_methodList, args);
instance->end();
return aValue;
}
CodeType RuntimeMethod::codeType() const
......
......@@ -104,8 +104,9 @@ bool RuntimeObjectImp::getOwnPropertySlot(ExecState *exec, const Identifier& pro
// Now check if a method with specified name exists, if so return a function object for
// that method.
MethodList methodList = aClass->methodsNamed(propertyName, instance.get());
if (methodList.length() > 0) {
if (methodList.size() > 0) {
slot.setCustom(this, methodGetter);
instance->end();
return true;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment