[SCM] WebKit Debian packaging branch, debian/unstable, updated. debian/1.1.15-1-40151-g37bb677
rjw
rjw at 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Sat Sep 26 08:22:32 UTC 2009
The following commit has been merged in the debian/unstable branch:
commit dad1fcae9b2a6f9805125d1e26212735046d0a2d
Author: rjw <rjw at 268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date: Fri Jan 16 23:23:04 2004 +0000
JavaScriptCore:
Fixed 3525853. We weren't handling mapping to overloaded Java
methods very well. Even though this is undefined the other
browsers support it. Also fixed a bug with returning arrays
from Java functions.
Reviewed by John.
* bindings/jni/jni_class.cpp:
(JavaClass::_commonInit):
(JavaClass::methodsNamed):
* bindings/jni/jni_class.h:
* bindings/jni/jni_instance.cpp:
(JavaInstance::invokeMethod):
* bindings/jni/jni_instance.h:
* bindings/jni/jni_runtime.cpp:
(JavaArray::convertJObjectToArray):
(JavaField::valueFromInstance):
(JavaMethod::signature):
(JavaArray::valueAt):
* bindings/jni/jni_runtime.h:
* bindings/jni_jsobject.cpp:
(JSObject::call):
(JSObject::convertJObjectToValue):
* bindings/runtime.cpp:
(MethodList::addMethod):
(MethodList::length):
(MethodList::methodAt):
(MethodList::~MethodList):
* bindings/runtime.h:
(KJS::Bindings::MethodList::MethodList):
* bindings/runtime_method.cpp:
(RuntimeMethodImp::RuntimeMethodImp):
(RuntimeMethodImp::get):
(RuntimeMethodImp::call):
* bindings/runtime_method.h:
* bindings/runtime_object.cpp:
(RuntimeObjectImp::get):
(RuntimeObjectImp::hasProperty):
Tests:
Extending test to cover issues in 3525853.
Reviewed by John.
* ChangeLog:
* LiveConnect/Blink/Blink.java:
(Blink.init):
(Blink.getStrings):
(Blink):
(Blink.getManyNumbers):
(Blink.overloadedFunction):
* LiveConnect/Blink/Blink.pbproj/project.pbxproj:
* LiveConnect/Blink/test.html:
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@5919 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/JavaScriptCore/ChangeLog b/JavaScriptCore/ChangeLog
index 163f633..deb94d9 100644
--- a/JavaScriptCore/ChangeLog
+++ b/JavaScriptCore/ChangeLog
@@ -1,5 +1,46 @@
2004-01-16 Richard Williamson <rjw at apple.com>
+ Fixed 3525853. We weren't handling mapping to overloaded Java
+ methods very well. Even though this is undefined the other
+ browsers support it. Also fixed a bug with returning arrays
+ from Java functions.
+
+ Reviewed by John.
+
+ * bindings/jni/jni_class.cpp:
+ (JavaClass::_commonInit):
+ (JavaClass::methodsNamed):
+ * bindings/jni/jni_class.h:
+ * bindings/jni/jni_instance.cpp:
+ (JavaInstance::invokeMethod):
+ * bindings/jni/jni_instance.h:
+ * bindings/jni/jni_runtime.cpp:
+ (JavaArray::convertJObjectToArray):
+ (JavaField::valueFromInstance):
+ (JavaMethod::signature):
+ (JavaArray::valueAt):
+ * bindings/jni/jni_runtime.h:
+ * bindings/jni_jsobject.cpp:
+ (JSObject::call):
+ (JSObject::convertJObjectToValue):
+ * bindings/runtime.cpp:
+ (MethodList::addMethod):
+ (MethodList::length):
+ (MethodList::methodAt):
+ (MethodList::~MethodList):
+ * bindings/runtime.h:
+ (KJS::Bindings::MethodList::MethodList):
+ * bindings/runtime_method.cpp:
+ (RuntimeMethodImp::RuntimeMethodImp):
+ (RuntimeMethodImp::get):
+ (RuntimeMethodImp::call):
+ * bindings/runtime_method.h:
+ * bindings/runtime_object.cpp:
+ (RuntimeObjectImp::get):
+ (RuntimeObjectImp::hasProperty):
+
+2004-01-16 Richard Williamson <rjw at apple.com>
+
Fixed 3531229. Another place that needs the Push/PopLocalFrame
protection implemented for 3530401.
diff --git a/JavaScriptCore/bindings/jni/jni_class.cpp b/JavaScriptCore/bindings/jni/jni_class.cpp
index 0185d4f..ea3e0bf 100644
--- a/JavaScriptCore/bindings/jni/jni_class.cpp
+++ b/JavaScriptCore/bindings/jni/jni_class.cpp
@@ -56,7 +56,12 @@ void JavaClass::_commonInit (jobject aClass)
jobject aJMethod = env->GetObjectArrayElement ((jobjectArray)methods, i);
Method *aMethod = new JavaMethod (env, aJMethod);
CFStringRef methodName = CFStringCreateWithCString(NULL, aMethod->name(), kCFStringEncodingASCII);
- CFDictionaryAddValue ((CFMutableDictionaryRef)_methods, methodName, aMethod);
+ MethodList *methodList = (MethodList *)CFDictionaryGetValue ((CFMutableDictionaryRef)_methods, methodName);
+ if (!methodList) {
+ methodList = new MethodList();
+ CFDictionaryAddValue ((CFMutableDictionaryRef)_methods, methodName, methodList);
+ }
+ methodList->addMethod (aMethod);
CFRelease (methodName);
env->DeleteLocalRef (aJMethod);
}
@@ -154,13 +159,14 @@ JavaClass *JavaClass::classForInstance (jobject instance)
return aClass;
}
-Method *JavaClass::methodNamed(const char *name) const
+MethodList *JavaClass::methodsNamed(const char *name) const
{
CFStringRef methodName = CFStringCreateWithCString(NULL, name, kCFStringEncodingASCII);
- Method *aMethod = (Method *)CFDictionaryGetValue(_methods, methodName);
+ MethodList *methodList = (MethodList *)CFDictionaryGetValue(_methods, methodName);
CFRelease (methodName);
- return aMethod;
-};
+ return methodList;
+}
+
Field *JavaClass::fieldNamed(const char *name) const
{
diff --git a/JavaScriptCore/bindings/jni/jni_class.h b/JavaScriptCore/bindings/jni/jni_class.h
index fcc879f..30d60f6 100644
--- a/JavaScriptCore/bindings/jni/jni_class.h
+++ b/JavaScriptCore/bindings/jni/jni_class.h
@@ -100,7 +100,7 @@ public:
virtual const char *name() const { return _name; };
- virtual Method *methodNamed(const char *name) const;
+ virtual MethodList *methodsNamed(const char *name) const;
virtual Field *fieldNamed(const char *name) const;
diff --git a/JavaScriptCore/bindings/jni/jni_instance.cpp b/JavaScriptCore/bindings/jni/jni_instance.cpp
index f15fb08..e0cb434 100644
--- a/JavaScriptCore/bindings/jni/jni_instance.cpp
+++ b/JavaScriptCore/bindings/jni/jni_instance.cpp
@@ -103,14 +103,35 @@ KJS::Value JavaInstance::booleanValue() const
return v;
}
-Value JavaInstance::invokeMethod (KJS::ExecState *exec, const Method *method, const List &args)
+Value JavaInstance::invokeMethod (KJS::ExecState *exec, const MethodList *methodList, const List &args)
{
- const JavaMethod *jMethod = static_cast<const JavaMethod*>(method);
int i, count = args.size();
jvalue *jArgs;
Value resultValue;
+ Method *method = 0;
+ unsigned int numMethods = methodList->length();
+
+ // 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);
+ if (aMethod->numParameters() == count) {
+ method = aMethod;
+ break;
+ }
+ }
+ if (method == 0) {
+ JS_LOG ("unable to find an appropiate method\n");
+ return Undefined();
+ }
- JS_LOG ("call %s on %p\n", method->name(), _instance->_instance);
+ const JavaMethod *jMethod = static_cast<const JavaMethod*>(method);
+ JS_LOG ("call %s %s on %p\n", method->name(), jMethod->signature(), _instance->_instance);
if (count > 0) {
jArgs = (jvalue *)malloc (count * sizeof(jvalue));
@@ -135,7 +156,13 @@ Value JavaInstance::invokeMethod (KJS::ExecState *exec, const Method *method, co
case object_type: {
result.l = callJNIObjectMethodIDA (obj, jMethod->methodID(obj), jArgs);
if (result.l != 0) {
- resultValue = Object(new RuntimeObjectImp(new JavaInstance (result.l)));
+ const char *arrayType = jMethod->returnType();
+ if (arrayType[0] == '[') {
+ resultValue = JavaArray::convertJObjectToArray (exec, result.l, arrayType);
+ }
+ else {
+ resultValue = Object(new RuntimeObjectImp(new JavaInstance (result.l)));
+ }
}
else {
resultValue = Undefined();
diff --git a/JavaScriptCore/bindings/jni/jni_instance.h b/JavaScriptCore/bindings/jni/jni_instance.h
index d08e294..ad1e03d 100644
--- a/JavaScriptCore/bindings/jni/jni_instance.h
+++ b/JavaScriptCore/bindings/jni/jni_instance.h
@@ -93,7 +93,7 @@ public:
virtual KJS::Value valueOf() const;
virtual KJS::Value defaultValue (KJS::Type hint) const;
- virtual KJS::Value invokeMethod (KJS::ExecState *exec, const Method *method, const KJS::List &args);
+ virtual KJS::Value invokeMethod (KJS::ExecState *exec, const MethodList *method, const KJS::List &args);
jobject javaInstance() const { return _instance->_instance; }
diff --git a/JavaScriptCore/bindings/jni/jni_runtime.cpp b/JavaScriptCore/bindings/jni/jni_runtime.cpp
index babdbce..9240c7c 100644
--- a/JavaScriptCore/bindings/jni/jni_runtime.cpp
+++ b/JavaScriptCore/bindings/jni/jni_runtime.cpp
@@ -57,7 +57,7 @@ JavaField::JavaField (JNIEnv *env, jobject aField)
_field = new JavaInstance(aField);
}
-KJS::Value convertJObjectToArray (KJS::ExecState *exec, jobject anObject, const char *type)
+KJS::Value JavaArray::convertJObjectToArray (KJS::ExecState *exec, jobject anObject, const char *type)
{
if (type[0] != '[')
return Undefined();
@@ -77,7 +77,7 @@ KJS::Value JavaField::valueFromInstance(const Instance *i) const
const char *arrayType = type();
if (arrayType[0] == '[') {
- return convertJObjectToArray (0, anObject, arrayType);
+ return JavaArray::convertJObjectToArray (0, anObject, arrayType);
}
else {
return KJS::Object(new RuntimeObjectImp(new JavaInstance ((jobject)anObject)));
@@ -258,10 +258,16 @@ const char *JavaMethod::signature() const
}
_signature->append(")");
- _signature->append(signatureFromPrimitiveType (_JNIReturnType));
- if (_JNIReturnType == object_type) {
- appendClassName (_signature, _returnType.UTF8String());
- _signature->append(";");
+ const char *returnType = _returnType.UTF8String();
+ if (returnType[0] == '[') {
+ appendClassName (_signature, returnType);
+ }
+ else {
+ _signature->append(signatureFromPrimitiveType (_JNIReturnType));
+ if (_JNIReturnType == object_type) {
+ appendClassName (_signature, returnType);
+ _signature->append(";");
+ }
}
}
@@ -386,7 +392,7 @@ KJS::Value JavaArray::valueAt(unsigned int index) const
// Nested array?
if (_type[1] == '[') {
- return convertJObjectToArray (0, anObject, _type+1);
+ return JavaArray::convertJObjectToArray (0, anObject, _type+1);
}
// or array of other object type?
return KJS::Object(new RuntimeObjectImp(new JavaInstance ((jobject)anObject)));
diff --git a/JavaScriptCore/bindings/jni/jni_runtime.h b/JavaScriptCore/bindings/jni/jni_runtime.h
index 09d2271..c283458 100644
--- a/JavaScriptCore/bindings/jni/jni_runtime.h
+++ b/JavaScriptCore/bindings/jni/jni_runtime.h
@@ -332,6 +332,8 @@ public:
jobject javaArray() const { return _array->_instance; }
+ static KJS::Value convertJObjectToArray (KJS::ExecState *exec, jobject anObject, const char *type);
+
private:
JObjectWrapper *_array;
unsigned int _length;
diff --git a/JavaScriptCore/bindings/jni_jsobject.cpp b/JavaScriptCore/bindings/jni_jsobject.cpp
index 200a6f0..704bdec 100644
--- a/JavaScriptCore/bindings/jni_jsobject.cpp
+++ b/JavaScriptCore/bindings/jni_jsobject.cpp
@@ -441,7 +441,9 @@ jobject JSObject::call(jstring methodName, jobjectArray args) const
// Lookup the function object.
ExecState *exec = _root->interpreter()->globalExec();
Interpreter::lock();
- Value func = _imp->get (exec, Identifier (JavaString(methodName).ustring()));
+
+ Identifier identifier(JavaString(methodName).ustring());
+ Value func = _imp->get (exec, identifier);
Interpreter::unlock();
if (func.isNull() || func.type() == UndefinedType) {
// Maybe throw an exception here?
@@ -659,6 +661,9 @@ KJS::Value JSObject::convertJObjectToValue (jobject theObject) const
// figure 22-4.
jobject classOfInstance = callJNIObjectMethod(theObject, "getClass", "()Ljava/lang/Class;");
jstring className = (jstring)callJNIObjectMethod(classOfInstance, "getName", "()Ljava/lang/String;");
+
+ JS_LOG ("converting instance of class %s\n", Bindings::JavaString(className).UTF8String());
+
if (strcmp(Bindings::JavaString(className).UTF8String(), "netscape.javascript.JSObject") == 0) {
// Pull the nativeJSObject value from the Java instance. This is a
// pointer to the ObjectImp.
diff --git a/JavaScriptCore/bindings/runtime.cpp b/JavaScriptCore/bindings/runtime.cpp
index aa282f1..83062e7 100644
--- a/JavaScriptCore/bindings/runtime.cpp
+++ b/JavaScriptCore/bindings/runtime.cpp
@@ -30,6 +30,35 @@
using namespace KJS;
using namespace KJS::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;
+}
+
+
Instance *Instance::createBindingForLanguageInstance (BindingLanguage language, void *instance)
{
if (language == Instance::JavaLanguage)
diff --git a/JavaScriptCore/bindings/runtime.h b/JavaScriptCore/bindings/runtime.h
index afabd46..4130926 100644
--- a/JavaScriptCore/bindings/runtime.h
+++ b/JavaScriptCore/bindings/runtime.h
@@ -35,6 +35,7 @@ namespace Bindings
{
class Instance;
+class Method;
// For now just use Java style type descriptors.
typedef const char * RuntimeType;
@@ -69,6 +70,24 @@ public:
virtual ~Field() {};
};
+
+class MethodList
+{
+public:
+ MethodList() : _methods(0), _length(0) {};
+
+ void addMethod (Method *aMethod);
+ unsigned int length() const;
+ Method *methodAt (unsigned int index) const;
+
+ ~MethodList();
+
+private:
+ Method **_methods;
+ unsigned int _length;
+};
+
+
class Method
{
public:
@@ -87,7 +106,7 @@ class Class
public:
virtual const char *name() const = 0;
- virtual Method *methodNamed(const char *name) const = 0;
+ virtual MethodList *methodsNamed(const char *name) const = 0;
virtual Constructor *constructorAt(long i) const = 0;
virtual long numConstructors() const = 0;
@@ -118,7 +137,7 @@ public:
virtual KJS::Value getValueOfField (const Field *aField) const;
virtual void setValueOfField (KJS::ExecState *exec, const Field *aField, const KJS::Value &aValue) const;
- virtual KJS::Value invokeMethod (KJS::ExecState *exec, const Method *method, const KJS::List &args) = 0;
+ virtual KJS::Value invokeMethod (KJS::ExecState *exec, const MethodList *method, const KJS::List &args) = 0;
virtual KJS::Value defaultValue (KJS::Type hint) const = 0;
diff --git a/JavaScriptCore/bindings/runtime_method.cpp b/JavaScriptCore/bindings/runtime_method.cpp
index e4f9163..48d3538 100644
--- a/JavaScriptCore/bindings/runtime_method.cpp
+++ b/JavaScriptCore/bindings/runtime_method.cpp
@@ -31,9 +31,9 @@
using namespace KJS::Bindings;
using namespace KJS;
-RuntimeMethodImp::RuntimeMethodImp(ExecState *exec, const Identifier &ident, Bindings::Method *m) : FunctionImp (exec, ident)
+RuntimeMethodImp::RuntimeMethodImp(ExecState *exec, const Identifier &ident, Bindings::MethodList *m) : FunctionImp (exec, ident)
{
- method = m;
+ _methodList = m;
}
RuntimeMethodImp::~RuntimeMethodImp()
@@ -56,7 +56,11 @@ Value RuntimeMethodImp::get(ExecState *exec, const Identifier &propertyName) con
// Compute length of parameters.
if (propertyName == lengthPropertyName) {
- return Number(method->numParameters());
+ // Ick! There may be more than one method with this name. Arbitrarily
+ // just pick the first method. The fundamental problem here is that
+ // JavaScript doesn't have the notion of method overloading and
+ // Java does.
+ return Number(_methodList->methodAt(0)->numParameters());
}
return FunctionImp::get(exec, propertyName);
@@ -69,14 +73,14 @@ bool RuntimeMethodImp::implementsCall() const
Value RuntimeMethodImp::call(ExecState *exec, Object &thisObj, const List &args)
{
- if (method) {
+ if (_methodList) {
RuntimeObjectImp *imp = static_cast<RuntimeObjectImp*>(thisObj.imp());
if (imp) {
Instance *instance = imp->getInternalInstance();
instance->begin();
- Value aValue = instance->invokeMethod(exec, method, args);
+ Value aValue = instance->invokeMethod(exec, _methodList, args);
instance->end();
diff --git a/JavaScriptCore/bindings/runtime_method.h b/JavaScriptCore/bindings/runtime_method.h
index 21c1116..51bded7 100644
--- a/JavaScriptCore/bindings/runtime_method.h
+++ b/JavaScriptCore/bindings/runtime_method.h
@@ -34,7 +34,7 @@ namespace KJS {
class RuntimeMethodImp : public FunctionImp
{
public:
- RuntimeMethodImp(ExecState *exec, const Identifier &n = Identifier::null(), Bindings::Method *method = 0);
+ RuntimeMethodImp(ExecState *exec, const Identifier &n = Identifier::null(), Bindings::MethodList *methodList = 0);
virtual ~RuntimeMethodImp();
@@ -48,7 +48,7 @@ public:
virtual Completion execute(ExecState *exec);
private:
- Bindings::Method *method;
+ Bindings::MethodList *_methodList;
};
} // namespace KJS
diff --git a/JavaScriptCore/bindings/runtime_object.cpp b/JavaScriptCore/bindings/runtime_object.cpp
index bacca7f..1b3771d 100644
--- a/JavaScriptCore/bindings/runtime_object.cpp
+++ b/JavaScriptCore/bindings/runtime_object.cpp
@@ -72,10 +72,10 @@ Value RuntimeObjectImp::get(ExecState *exec, const Identifier &propertyName) con
// Now check if a method with specified name exists, if so return a function object for
// that method.
- Method *aMethod = instance->getClass()->methodNamed(propertyName.ascii());
- if (aMethod) {
+ MethodList *methodList = instance->getClass()->methodsNamed(propertyName.ascii());
+ if (methodList) {
instance->end();
- return Object (new RuntimeMethodImp(exec, propertyName, aMethod));
+ return Object (new RuntimeMethodImp(exec, propertyName, methodList));
}
instance->end();
@@ -119,11 +119,11 @@ bool RuntimeObjectImp::hasProperty(ExecState *exec,
return true;
}
- Method *aMethod = instance->getClass()->methodNamed(propertyName.ascii());
+ MethodList *methodList = instance->getClass()->methodsNamed(propertyName.ascii());
instance->end();
- if (aMethod)
+ if (methodList)
return true;
return false;
--
WebKit Debian packaging
More information about the Pkg-webkit-commits
mailing list