[SCM] WebKit Debian packaging branch, webkit-1.1, updated. upstream/1.1.19-706-ge5415e9
steveblock at google.com
steveblock at google.com
Thu Feb 4 21:35:46 UTC 2010
The following commit has been merged in the webkit-1.1 branch:
commit 750d0c284441457a7689862e3591a14982e06dcd
Author: steveblock at google.com <steveblock at google.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date: Tue Feb 2 00:03:37 2010 +0000
Adds V8 version of JavaInstance
https://bugs.webkit.org/show_bug.cgi?id=33951
Reviewed by Ariya Hidayat.
This is the V8 equivalent of bridge/jni/jsc/JavaInstanceJSC.
Also fixes a typo in a comment in JavaInstanceJSC.cpp.
No new tests, build fix only.
* Android.v8bindings.mk: Modified. Added JavaInstanceV8.cpp
* bridge/jni/jsc/JavaInstanceJSC.cpp: Modified.
(JavaInstance::invokeMethod): Modified. Fixed comment
* bridge/jni/v8/JavaInstanceV8.cpp: Added.
(JavaInstance::JavaInstance):
(JavaInstance::~JavaInstance):
(JavaInstance::getClass):
(JavaInstance::invokeMethod):
(JObjectWrapper::JObjectWrapper):
(JObjectWrapper::~JObjectWrapper):
* bridge/jni/v8/JavaInstanceV8.h: Added.
(JSC::Bindings::JObjectWrapper::instance):
(JSC::Bindings::JObjectWrapper::setInstance):
(JSC::Bindings::JObjectWrapper::ref):
(JSC::Bindings::JObjectWrapper::deref):
(JSC::Bindings::JavaInstance::javaInstance):
(JSC::Bindings::JavaInstance::begin):
(JSC::Bindings::JavaInstance::end):
(JSC::Bindings::JavaInstance::virtualBegin):
(JSC::Bindings::JavaInstance::virtualEnd):
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@54165 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/WebCore/Android.v8bindings.mk b/WebCore/Android.v8bindings.mk
index a8fdd33..95c1df3 100644
--- a/WebCore/Android.v8bindings.mk
+++ b/WebCore/Android.v8bindings.mk
@@ -177,4 +177,5 @@ LOCAL_SRC_FILES += \
bindings/v8/custom/V8XMLHttpRequestUploadCustom.cpp
LOCAL_SRC_FILES += \
- bridge/jni/JNIUtility.cpp
+ bridge/jni/JNIUtility.cpp \
+ bridge/jni/v8/JavaInstanceV8.cpp
diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index 9045dba..29d3ff6 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -1,3 +1,36 @@
+2010-02-01 Steve Block <steveblock at google.com>
+
+ Reviewed by Ariya Hidayat.
+
+ Adds V8 version of JavaInstance
+ https://bugs.webkit.org/show_bug.cgi?id=33951
+
+ This is the V8 equivalent of bridge/jni/jsc/JavaInstanceJSC.
+ Also fixes a typo in a comment in JavaInstanceJSC.cpp.
+
+ No new tests, build fix only.
+
+ * Android.v8bindings.mk: Modified. Added JavaInstanceV8.cpp
+ * bridge/jni/jsc/JavaInstanceJSC.cpp: Modified.
+ (JavaInstance::invokeMethod): Modified. Fixed comment
+ * bridge/jni/v8/JavaInstanceV8.cpp: Added.
+ (JavaInstance::JavaInstance):
+ (JavaInstance::~JavaInstance):
+ (JavaInstance::getClass):
+ (JavaInstance::invokeMethod):
+ (JObjectWrapper::JObjectWrapper):
+ (JObjectWrapper::~JObjectWrapper):
+ * bridge/jni/v8/JavaInstanceV8.h: Added.
+ (JSC::Bindings::JObjectWrapper::instance):
+ (JSC::Bindings::JObjectWrapper::setInstance):
+ (JSC::Bindings::JObjectWrapper::ref):
+ (JSC::Bindings::JObjectWrapper::deref):
+ (JSC::Bindings::JavaInstance::javaInstance):
+ (JSC::Bindings::JavaInstance::begin):
+ (JSC::Bindings::JavaInstance::end):
+ (JSC::Bindings::JavaInstance::virtualBegin):
+ (JSC::Bindings::JavaInstance::virtualEnd):
+
2010-02-01 Dumitru Daniliuc <dumi at chromium.org>
Reviewed by Eric Seidel.
diff --git a/WebCore/bridge/jni/jsc/JavaInstanceJSC.cpp b/WebCore/bridge/jni/jsc/JavaInstanceJSC.cpp
index aaa79b8..b42456c 100644
--- a/WebCore/bridge/jni/jsc/JavaInstanceJSC.cpp
+++ b/WebCore/bridge/jni/jsc/JavaInstanceJSC.cpp
@@ -123,7 +123,7 @@ JSValue JavaInstance::invokeMethod(ExecState* exec, const MethodList& methodList
size_t numMethods = methodList.size();
// Try to find a good match for the overloaded method. The
- // fundamental problem is that JavaScript doesn have the
+ // fundamental problem is that JavaScript doesn't 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.
diff --git a/WebCore/bridge/jni/v8/JavaInstanceV8.cpp b/WebCore/bridge/jni/v8/JavaInstanceV8.cpp
new file mode 100644
index 0000000..a926704
--- /dev/null
+++ b/WebCore/bridge/jni/v8/JavaInstanceV8.cpp
@@ -0,0 +1,169 @@
+/*
+ * Copyright (C) 2003, 2008, 2010 Apple Inc. All rights reserved.
+ * Copyright 2010, The Android Open Source Project
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "JavaInstanceV8.h"
+
+#include "JNIBridge.h"
+#include "JNIUtilityPrivate.h"
+#include "JavaClassV8.h"
+
+#include <assert.h>
+#include <utils/Log.h>
+
+#define LOG_TAG "v8binding"
+
+using namespace JSC::Bindings;
+
+JavaInstance::JavaInstance(jobject instance)
+{
+ m_instance = new JObjectWrapper(instance);
+ m_class = 0;
+}
+
+JavaInstance::~JavaInstance()
+{
+ m_instance = 0;
+ delete m_class;
+}
+
+JavaClass* JavaInstance::getClass() const
+{
+ if (!m_class)
+ m_class = new JavaClass(javaInstance());
+ return m_class;
+}
+
+bool JavaInstance::invokeMethod(const char* methodName, const NPVariant* args, int count, NPVariant* resultValue)
+{
+ VOID_TO_NPVARIANT(*resultValue);
+
+ MethodList methodList = getClass()->methodsNamed(methodName);
+
+ size_t numMethods = methodList.size();
+
+ // Try to find a good match for the overloaded method. The
+ // fundamental problem is that JavaScript doesn't 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.
+ JavaMethod* aMethod;
+ JavaMethod* method = 0;
+ for (size_t methodIndex = 0; methodIndex < numMethods; methodIndex++) {
+ aMethod = methodList[methodIndex];
+ if (aMethod->numParameters() == count) {
+ method = aMethod;
+ break;
+ }
+ }
+ if (!method) {
+ LOGW("unable to find an appropiate method\n");
+ return false;
+ }
+
+ const JavaMethod* jMethod = static_cast<const JavaMethod*>(method);
+
+ jvalue* jArgs = 0;
+ if (count > 0)
+ jArgs = static_cast<jvalue*>(malloc(count * sizeof(jvalue)));
+
+ for (int i = 0; i < count; i++) {
+ JavaParameter* aParameter = jMethod->parameterAt(i);
+ jArgs[i] = convertNPVariantToJValue(args[i], aParameter->getJNIType(), aParameter->type());
+ }
+
+ jvalue result;
+
+ // The following code can be conditionally removed once we have a Tiger update that
+ // contains the new Java plugin. It is needed for builds prior to Tiger.
+ {
+ jobject obj = javaInstance();
+ switch (jMethod->JNIReturnType()) {
+ case void_type:
+ callJNIMethodIDA<void>(obj, jMethod->methodID(obj), jArgs);
+ break;
+ case object_type:
+ result.l = callJNIMethodIDA<jobject>(obj, jMethod->methodID(obj), jArgs);
+ break;
+ case boolean_type:
+ result.z = callJNIMethodIDA<jboolean>(obj, jMethod->methodID(obj), jArgs);
+ break;
+ case byte_type:
+ result.b = callJNIMethodIDA<jbyte>(obj, jMethod->methodID(obj), jArgs);
+ break;
+ case char_type:
+ result.c = callJNIMethodIDA<jchar>(obj, jMethod->methodID(obj), jArgs);
+ break;
+ case short_type:
+ result.s = callJNIMethodIDA<jshort>(obj, jMethod->methodID(obj), jArgs);
+ break;
+ case int_type:
+ result.i = callJNIMethodIDA<jint>(obj, jMethod->methodID(obj), jArgs);
+ break;
+
+ case long_type:
+ result.j = callJNIMethodIDA<jlong>(obj, jMethod->methodID(obj), jArgs);
+ break;
+ case float_type:
+ result.f = callJNIMethodIDA<jfloat>(obj, jMethod->methodID(obj), jArgs);
+ break;
+ case double_type:
+ result.d = callJNIMethodIDA<jdouble>(obj, jMethod->methodID(obj), jArgs);
+ break;
+ case invalid_type:
+ default:
+ break;
+ }
+ }
+
+ convertJValueToNPVariant(result, jMethod->JNIReturnType(), jMethod->returnType(), resultValue);
+ free(jArgs);
+
+ return true;
+}
+
+JObjectWrapper::JObjectWrapper(jobject instance)
+ : m_refCount(0)
+{
+ assert(instance);
+
+ // Cache the JNIEnv used to get the global ref for this java instanace.
+ // It'll be used to delete the reference.
+ m_env = getJNIEnv();
+
+ m_instance = m_env->NewGlobalRef(instance);
+
+ LOGV("new global ref %p for %p\n", m_instance, instance);
+
+ if (!m_instance)
+ fprintf(stderr, "%s: could not get GlobalRef for %p\n", __PRETTY_FUNCTION__, instance);
+}
+
+JObjectWrapper::~JObjectWrapper()
+{
+ LOGV("deleting global ref %p\n", m_instance);
+ m_env->DeleteGlobalRef(m_instance);
+}
diff --git a/WebCore/bridge/jni/v8/JavaInstanceV8.h b/WebCore/bridge/jni/v8/JavaInstanceV8.h
new file mode 100644
index 0000000..c18f2d6
--- /dev/null
+++ b/WebCore/bridge/jni/v8/JavaInstanceV8.h
@@ -0,0 +1,100 @@
+/*
+ * Copyright (C) 2003, 2008, 2010 Apple Inc. All rights reserved.
+ * Copyright 2010, The Android Open Source Project
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef JavaInstanceV8_h
+#define JavaInstanceV8_h
+
+#include "npruntime.h"
+
+#include <JavaVM/jni.h>
+#include <wtf/RefCounted.h>
+#include <wtf/RefPtr.h>
+
+using namespace WTF;
+
+namespace JSC {
+
+namespace Bindings {
+
+class JavaClass;
+
+class JObjectWrapper {
+friend class RefPtr<JObjectWrapper>;
+friend class JavaField;
+friend class JavaInstance;
+
+public:
+ jobject instance() const { return m_instance; }
+ void setInstance(jobject instance) { m_instance = instance; }
+
+protected:
+ JObjectWrapper(jobject);
+ ~JObjectWrapper();
+
+ void ref() { m_refCount++; }
+ void deref()
+ {
+ if (!(--m_refCount))
+ delete this;
+ }
+
+ jobject m_instance;
+
+private:
+ JNIEnv* m_env;
+ unsigned int m_refCount;
+};
+
+class JavaInstance : public RefCounted<JavaInstance> {
+public:
+ JavaInstance(jobject instance);
+ virtual ~JavaInstance();
+
+ JavaClass* getClass() const;
+
+ bool invokeMethod(const char* name, const NPVariant* args, int argsCount, NPVariant* result);
+
+ jobject javaInstance() const { return m_instance->m_instance; }
+
+ // These functions are called before and after the main entry points into
+ // the native implementations. They can be used to establish and cleanup
+ // any needed state.
+ void begin() { virtualBegin(); }
+ void end() { virtualEnd(); }
+
+protected:
+ RefPtr<JObjectWrapper> m_instance;
+ mutable JavaClass* m_class;
+
+ virtual void virtualBegin() {}
+ virtual void virtualEnd() {}
+};
+
+} // namespace Bindings
+
+} // namespace JSC
+
+#endif // JavaInstanceV8_h
--
WebKit Debian packaging
More information about the Pkg-webkit-commits
mailing list