From be164dbcfc9adfae8ae7c559ebdff00580f8086d Mon Sep 17 00:00:00 2001 From: Steve Block Date: Tue, 19 Jan 2010 02:13:06 +0000 Subject: Cherry-pick WebKit change 53443 to move jni_class to JavaClassJSC See http://trac.webkit.org/changeset/53443 This is required to sync the Android tree with webkit.org to allow unforking in WebCore/bridge. Change-Id: I0f2b0581e0850694953f79d45242c44d16bbf5fa --- WebCore/Android.jscbindings.mk | 2 +- WebCore/ChangeLog | 18 ++++ WebCore/GNUmakefile.am | 2 +- WebCore/WebCore.xcodeproj/project.pbxproj | 16 ++-- WebCore/bridge/jni/jni_class.cpp | 145 ----------------------------- WebCore/bridge/jni/jni_class.h | 62 ------------ WebCore/bridge/jni/jsc/JavaClassJSC.cpp | 145 +++++++++++++++++++++++++++++ WebCore/bridge/jni/jsc/JavaClassJSC.h | 62 ++++++++++++ WebCore/bridge/jni/jsc/JavaInstanceJSC.cpp | 2 +- 9 files changed, 236 insertions(+), 218 deletions(-) delete mode 100644 WebCore/bridge/jni/jni_class.cpp delete mode 100644 WebCore/bridge/jni/jni_class.h create mode 100644 WebCore/bridge/jni/jsc/JavaClassJSC.cpp create mode 100644 WebCore/bridge/jni/jsc/JavaClassJSC.h diff --git a/WebCore/Android.jscbindings.mk b/WebCore/Android.jscbindings.mk index 31edd49..119601d 100644 --- a/WebCore/Android.jscbindings.mk +++ b/WebCore/Android.jscbindings.mk @@ -187,9 +187,9 @@ LOCAL_SRC_FILES += \ bridge/c/c_instance.cpp \ bridge/c/c_runtime.cpp \ bridge/c/c_utility.cpp \ - bridge/jni/jni_class.cpp \ bridge/jni/jni_runtime.cpp \ bridge/jni/jni_utility.cpp \ + bridge/jni/jsc/JavaClassJSC.cpp \ bridge/jni/jsc/JavaInstanceJSC.cpp \ bridge/jni/jsc/jni_utility_private.cpp \ bridge/npruntime.cpp \ diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog index 95285c8..81abb2d 100644 --- a/WebCore/ChangeLog +++ b/WebCore/ChangeLog @@ -97,6 +97,24 @@ (WebCore::WebGLRenderingContext::bufferSubData): (WebCore::WebGLRenderingContext::compileShader): (WebCore::WebGLRenderingContext::createShader): + +2010-01-18 Steve Block + + Reviewed by Adam Barth. + + Moves JSC-specific version of JavaClass from bridge/jni/jni_class to bridge/jni/jsc/JavaClassJSC + https://bugs.webkit.org/show_bug.cgi?id=33561 + + No new tests, refactoring only. + + * Android.jscbindings.mk: Modified. Removed jni_class.cpp and added JavaClassJSC.cpp + * GNUmakefile.am: Modified. Removed jni_class.h and added JavaClassJSC.h + * WebCore.xcodeproj/project.pbxproj: Modified. Removed jni_class.[cpp|h] and added JavaClassJSC.[cpp|h] + * bridge/jni/jni_class.cpp: Removed. + * bridge/jni/jni_class.h: Removed. + * bridge/jni/jsc/JavaClassJSC.cpp: Copied from WebCore/bridge/jni/jni_class.cpp. + * bridge/jni/jsc/JavaClassJSC.h: Copied from WebCore/bridge/jni/jni_class.h. + * bridge/jni/jsc/JavaInstanceJSC.cpp: Modified. Includes JavaClassJSC.h (WebCore::WebGLRenderingContext::detachShader): (WebCore::WebGLRenderingContext::disableVertexAttribArray): (WebCore::WebGLRenderingContext::drawArrays): diff --git a/WebCore/GNUmakefile.am b/WebCore/GNUmakefile.am index 220801a..d3a9003 100644 --- a/WebCore/GNUmakefile.am +++ b/WebCore/GNUmakefile.am @@ -496,10 +496,10 @@ webcore_sources += \ WebCore/bridge/c/c_runtime.h \ WebCore/bridge/c/c_utility.cpp \ WebCore/bridge/c/c_utility.h \ - WebCore/bridge/jni/jni_class.h \ WebCore/bridge/jni/jni_jsobject.h \ WebCore/bridge/jni/jni_runtime.h \ WebCore/bridge/jni/jni_utility.h \ + WebCore/bridge/jni/jsc/JavaClassJSC.h \ WebCore/bridge/jni/jsc/JavaInstanceJSC.h \ WebCore/bridge/npapi.h \ WebCore/bridge/npruntime.cpp \ diff --git a/WebCore/WebCore.xcodeproj/project.pbxproj b/WebCore/WebCore.xcodeproj/project.pbxproj index c008276..5c9981f 100644 --- a/WebCore/WebCore.xcodeproj/project.pbxproj +++ b/WebCore/WebCore.xcodeproj/project.pbxproj @@ -295,8 +295,6 @@ 1A569CFC0D7E2B82007C3983 /* c_runtime.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A569CCB0D7E2B82007C3983 /* c_runtime.h */; }; 1A569CFD0D7E2B82007C3983 /* c_utility.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A569CCC0D7E2B82007C3983 /* c_utility.cpp */; }; 1A569CFE0D7E2B82007C3983 /* c_utility.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A569CCD0D7E2B82007C3983 /* c_utility.h */; }; - 1A569CFF0D7E2B82007C3983 /* jni_class.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A569CCF0D7E2B82007C3983 /* jni_class.cpp */; }; - 1A569D000D7E2B82007C3983 /* jni_class.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A569CD00D7E2B82007C3983 /* jni_class.h */; }; 1A569D030D7E2B82007C3983 /* jni_jsobject.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1A569CD30D7E2B82007C3983 /* jni_jsobject.mm */; }; 1A569D040D7E2B82007C3983 /* jni_jsobject.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A569CD40D7E2B82007C3983 /* jni_jsobject.h */; settings = {ATTRIBUTES = (Private, ); }; }; 1A569D050D7E2B82007C3983 /* jni_objc.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1A569CD50D7E2B82007C3983 /* jni_objc.mm */; }; @@ -1105,6 +1103,8 @@ 59A9E7B21104759400DFB4C1 /* JavaInstanceJSC.h in Headers */ = {isa = PBXBuildFile; fileRef = 59A9E7B11104759400DFB4C1 /* JavaInstanceJSC.h */; }; 59C77F2A10545B3B00506104 /* GeolocationServiceMock.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 59C77F2810545B3B00506104 /* GeolocationServiceMock.cpp */; }; 59C77F2B10545B3B00506104 /* GeolocationServiceMock.h in Headers */ = {isa = PBXBuildFile; fileRef = 59C77F2910545B3B00506104 /* GeolocationServiceMock.h */; settings = {ATTRIBUTES = (Private, ); }; }; + 59E560A71105336600AA1258 /* JavaClassJSC.h in Headers */ = {isa = PBXBuildFile; fileRef = 59E560A61105336600AA1258 /* JavaClassJSC.h */; }; + 59E560A91105336F00AA1258 /* JavaClassJSC.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 59E560A81105336F00AA1258 /* JavaClassJSC.cpp */; }; 5D15E3AB0F9E6AC1009E0E3F /* XMLTokenizerScope.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5D15E3A90F9E6AC1009E0E3F /* XMLTokenizerScope.cpp */; }; 5D15E3AC0F9E6AC1009E0E3F /* XMLTokenizerScope.h in Headers */ = {isa = PBXBuildFile; fileRef = 5D15E3AA0F9E6AC1009E0E3F /* XMLTokenizerScope.h */; }; 5D874F130D161D3200796C3B /* NetscapePlugInStreamLoader.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 93E227DD0AF589AD00D48324 /* NetscapePlugInStreamLoader.cpp */; }; @@ -5515,8 +5515,6 @@ 1A569CCB0D7E2B82007C3983 /* c_runtime.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = c_runtime.h; sourceTree = ""; }; 1A569CCC0D7E2B82007C3983 /* c_utility.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = c_utility.cpp; sourceTree = ""; }; 1A569CCD0D7E2B82007C3983 /* c_utility.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = c_utility.h; sourceTree = ""; }; - 1A569CCF0D7E2B82007C3983 /* jni_class.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = jni_class.cpp; sourceTree = ""; }; - 1A569CD00D7E2B82007C3983 /* jni_class.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = jni_class.h; sourceTree = ""; }; 1A569CD30D7E2B82007C3983 /* jni_jsobject.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = jni_jsobject.mm; sourceTree = ""; }; 1A569CD40D7E2B82007C3983 /* jni_jsobject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = jni_jsobject.h; sourceTree = ""; }; 1A569CD50D7E2B82007C3983 /* jni_objc.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = jni_objc.mm; sourceTree = ""; }; @@ -6429,6 +6427,8 @@ 59A9E7B11104759400DFB4C1 /* JavaInstanceJSC.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = JavaInstanceJSC.h; path = jsc/JavaInstanceJSC.h; sourceTree = ""; }; 59C77F2810545B3B00506104 /* GeolocationServiceMock.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = GeolocationServiceMock.cpp; path = mock/GeolocationServiceMock.cpp; sourceTree = ""; }; 59C77F2910545B3B00506104 /* GeolocationServiceMock.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = GeolocationServiceMock.h; path = mock/GeolocationServiceMock.h; sourceTree = ""; }; + 59E560A61105336600AA1258 /* JavaClassJSC.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = JavaClassJSC.h; path = jsc/JavaClassJSC.h; sourceTree = ""; }; + 59E560A81105336F00AA1258 /* JavaClassJSC.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = JavaClassJSC.cpp; path = jsc/JavaClassJSC.cpp; sourceTree = ""; }; 5D15E3A90F9E6AC1009E0E3F /* XMLTokenizerScope.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = XMLTokenizerScope.cpp; sourceTree = ""; }; 5D15E3AA0F9E6AC1009E0E3F /* XMLTokenizerScope.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XMLTokenizerScope.h; sourceTree = ""; }; 5D925B650F64D4DD00B847F0 /* ScrollBehavior.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ScrollBehavior.cpp; sourceTree = ""; }; @@ -10281,8 +10281,6 @@ isa = PBXGroup; children = ( 599D1E2F10C97D4C00E0EF12 /* jsc */, - 1A569CCF0D7E2B82007C3983 /* jni_class.cpp */, - 1A569CD00D7E2B82007C3983 /* jni_class.h */, 1A569CD40D7E2B82007C3983 /* jni_jsobject.h */, 1A569CD30D7E2B82007C3983 /* jni_jsobject.mm */, 1A569CD50D7E2B82007C3983 /* jni_objc.mm */, @@ -10984,6 +10982,8 @@ 599D1E2F10C97D4C00E0EF12 /* jsc */ = { isa = PBXGroup; children = ( + 59E560A81105336F00AA1258 /* JavaClassJSC.cpp */, + 59E560A61105336600AA1258 /* JavaClassJSC.h */, 59A9E7B11104759400DFB4C1 /* JavaInstanceJSC.h */, 59A9E7AF1104758800DFB4C1 /* JavaInstanceJSC.cpp */, 599D1E3010C97D6E00E0EF12 /* jni_utility_private.cpp */, @@ -17054,7 +17054,6 @@ 1C81BA0E0E97348300266E07 /* JavaScriptDebugServer.h in Headers */, 1C81BA010E9733CB00266E07 /* JavaScriptProfile.h in Headers */, 1C81B9FF0E9733CB00266E07 /* JavaScriptProfileNode.h in Headers */, - 1A569D000D7E2B82007C3983 /* jni_class.h in Headers */, 1A569D040D7E2B82007C3983 /* jni_jsobject.h in Headers */, 1A569D070D7E2B82007C3983 /* jni_runtime.h in Headers */, 1A569D090D7E2B82007C3983 /* jni_utility.h in Headers */, @@ -18263,6 +18262,7 @@ 1C81BA330E97357C00266E07 /* Copy Inspector Resources */, 59A9E7B21104759400DFB4C1 /* JavaInstanceJSC.h in Headers */, 1C5F9D760E09A1B400E91D0A /* Streamline Inspector Source */, + 59E560A71105336600AA1258 /* JavaClassJSC.h in Headers */, 93F19A0C08245E59001E9ABC /* Sources */, 93F19B1208245E59001E9ABC /* Frameworks */, 939D050109D9FF6B00984996 /* Check For Global Initializers */, @@ -19212,7 +19212,6 @@ 1C81BA0D0E97348300266E07 /* JavaScriptDebugServer.cpp in Sources */, 1C81BA020E9733CB00266E07 /* JavaScriptProfile.cpp in Sources */, 1C81BA000E9733CB00266E07 /* JavaScriptProfileNode.cpp in Sources */, - 1A569CFF0D7E2B82007C3983 /* jni_class.cpp in Sources */, 1A569D030D7E2B82007C3983 /* jni_jsobject.mm in Sources */, 1A569D050D7E2B82007C3983 /* jni_objc.mm in Sources */, 1A569D060D7E2B82007C3983 /* jni_runtime.cpp in Sources */, @@ -20412,6 +20411,7 @@ isa = PBXTargetDependency; 59A9E7B01104758800DFB4C1 /* JavaInstanceJSC.cpp in Sources */, target = DD041FBE09D9DDBE0010AF2A /* Derived Sources */; + 59E560A91105336F00AA1258 /* JavaClassJSC.cpp in Sources */, targetProxy = DD041FF009D9E3250010AF2A /* PBXContainerItemProxy */; }; /* End PBXTargetDependency section */ diff --git a/WebCore/bridge/jni/jni_class.cpp b/WebCore/bridge/jni/jni_class.cpp deleted file mode 100644 index 6728e7b..0000000 --- a/WebCore/bridge/jni/jni_class.cpp +++ /dev/null @@ -1,145 +0,0 @@ -/* - * Copyright (C) 2003 Apple Computer, Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. 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 "jni_class.h" - -#if ENABLE(MAC_JAVA_BRIDGE) - -#include "JSDOMWindow.h" -#include -#include -#include "jni_utility.h" -#include "jni_runtime.h" - -using namespace JSC::Bindings; - -JavaClass::JavaClass(jobject anInstance) -{ - jobject aClass = callJNIMethod(anInstance, "getClass", "()Ljava/lang/Class;"); - - if (!aClass) { - fprintf(stderr, "%s: unable to call getClass on instance %p\n", __PRETTY_FUNCTION__, anInstance); - return; - } - - jstring className = (jstring)callJNIMethod(aClass, "getName", "()Ljava/lang/String;"); - const char *classNameC = getCharactersFromJString(className); - _name = strdup(classNameC); - releaseCharactersForJString(className, classNameC); - - int i; - JNIEnv *env = getJNIEnv(); - - // Get the fields - jarray fields = (jarray)callJNIMethod(aClass, "getFields", "()[Ljava/lang/reflect/Field;"); - int numFields = env->GetArrayLength(fields); - for (i = 0; i < numFields; i++) { - jobject aJField = env->GetObjectArrayElement((jobjectArray)fields, i); - JavaField *aField = new JavaField(env, aJField); // deleted in the JavaClass destructor - { - JSLock lock(SilenceAssertionsOnly); - _fields.set(aField->name(), aField); - } - env->DeleteLocalRef(aJField); - } - - // Get the methods - jarray methods = (jarray)callJNIMethod(aClass, "getMethods", "()[Ljava/lang/reflect/Method;"); - int numMethods = env->GetArrayLength(methods); - for (i = 0; i < numMethods; i++) { - jobject aJMethod = env->GetObjectArrayElement((jobjectArray)methods, i); - JavaMethod *aMethod = new JavaMethod(env, aJMethod); // deleted in the JavaClass destructor - MethodList* methodList; - { - JSLock lock(SilenceAssertionsOnly); - - methodList = _methods.get(aMethod->name()); - if (!methodList) { - methodList = new MethodList(); - _methods.set(aMethod->name(), methodList); - } - } - methodList->append(aMethod); - env->DeleteLocalRef(aJMethod); - } - - env->DeleteLocalRef(fields); - env->DeleteLocalRef(methods); - env->DeleteLocalRef(aClass); -} - -JavaClass::~JavaClass() { - free((void *)_name); - - JSLock lock(SilenceAssertionsOnly); - - deleteAllValues(_fields); - _fields.clear(); - - MethodListMap::const_iterator end = _methods.end(); - for (MethodListMap::const_iterator it = _methods.begin(); it != end; ++it) { - const MethodList* methodList = it->second; - deleteAllValues(*methodList); - delete methodList; - } - _methods.clear(); -} - -MethodList JavaClass::methodsNamed(const Identifier& identifier, Instance*) const -{ - MethodList *methodList = _methods.get(identifier.ustring().rep()); - - if (methodList) - return *methodList; - return MethodList(); -} - -Field *JavaClass::fieldNamed(const Identifier& identifier, Instance*) const -{ - return _fields.get(identifier.ustring().rep()); -} - -bool JavaClass::isNumberClass() const -{ - return ((strcmp(_name, "java.lang.Byte") == 0 || - strcmp(_name, "java.lang.Short") == 0 || - strcmp(_name, "java.lang.Integer") == 0 || - strcmp(_name, "java.lang.Long") == 0 || - strcmp(_name, "java.lang.Float") == 0 || - strcmp(_name, "java.lang.Double") == 0) ); -} - -bool JavaClass::isBooleanClass() const -{ - return strcmp(_name, "java.lang.Boolean") == 0; -} - -bool JavaClass::isStringClass() const -{ - return strcmp(_name, "java.lang.String") == 0; -} - -#endif // ENABLE(MAC_JAVA_BRIDGE) diff --git a/WebCore/bridge/jni/jni_class.h b/WebCore/bridge/jni/jni_class.h deleted file mode 100644 index 890b4d3..0000000 --- a/WebCore/bridge/jni/jni_class.h +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (C) 2003 Apple Computer, Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. 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 JNI_CLASS_H_ -#define JNI_CLASS_H_ - -#if ENABLE(MAC_JAVA_BRIDGE) - -#include -#include - -namespace JSC { - -namespace Bindings { - -class JavaClass : public Class { -public: - JavaClass (jobject anInstance); - ~JavaClass (); - - virtual MethodList methodsNamed(const Identifier&, Instance* instance) const; - virtual Field *fieldNamed(const Identifier&, Instance* instance) const; - - bool isNumberClass() const; - bool isBooleanClass() const; - bool isStringClass() const; - -private: - const char *_name; - FieldMap _fields; - MethodListMap _methods; -}; - -} // namespace Bindings - -} // namespace JSC - -#endif // ENABLE(MAC_JAVA_BRIDGE) - -#endif // JNI_CLASS_H_ diff --git a/WebCore/bridge/jni/jsc/JavaClassJSC.cpp b/WebCore/bridge/jni/jsc/JavaClassJSC.cpp new file mode 100644 index 0000000..3e30a4a --- /dev/null +++ b/WebCore/bridge/jni/jsc/JavaClassJSC.cpp @@ -0,0 +1,145 @@ +/* + * Copyright (C) 2003 Apple Computer, Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. 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 "JavaClassJSC.h" + +#if ENABLE(MAC_JAVA_BRIDGE) + +#include "JSDOMWindow.h" +#include +#include +#include "jni_utility.h" +#include "jni_runtime.h" + +using namespace JSC::Bindings; + +JavaClass::JavaClass(jobject anInstance) +{ + jobject aClass = callJNIMethod(anInstance, "getClass", "()Ljava/lang/Class;"); + + if (!aClass) { + fprintf(stderr, "%s: unable to call getClass on instance %p\n", __PRETTY_FUNCTION__, anInstance); + return; + } + + jstring className = (jstring)callJNIMethod(aClass, "getName", "()Ljava/lang/String;"); + const char *classNameC = getCharactersFromJString(className); + _name = strdup(classNameC); + releaseCharactersForJString(className, classNameC); + + int i; + JNIEnv *env = getJNIEnv(); + + // Get the fields + jarray fields = (jarray)callJNIMethod(aClass, "getFields", "()[Ljava/lang/reflect/Field;"); + int numFields = env->GetArrayLength(fields); + for (i = 0; i < numFields; i++) { + jobject aJField = env->GetObjectArrayElement((jobjectArray)fields, i); + JavaField *aField = new JavaField(env, aJField); // deleted in the JavaClass destructor + { + JSLock lock(SilenceAssertionsOnly); + _fields.set(aField->name(), aField); + } + env->DeleteLocalRef(aJField); + } + + // Get the methods + jarray methods = (jarray)callJNIMethod(aClass, "getMethods", "()[Ljava/lang/reflect/Method;"); + int numMethods = env->GetArrayLength(methods); + for (i = 0; i < numMethods; i++) { + jobject aJMethod = env->GetObjectArrayElement((jobjectArray)methods, i); + JavaMethod *aMethod = new JavaMethod(env, aJMethod); // deleted in the JavaClass destructor + MethodList* methodList; + { + JSLock lock(SilenceAssertionsOnly); + + methodList = _methods.get(aMethod->name()); + if (!methodList) { + methodList = new MethodList(); + _methods.set(aMethod->name(), methodList); + } + } + methodList->append(aMethod); + env->DeleteLocalRef(aJMethod); + } + + env->DeleteLocalRef(fields); + env->DeleteLocalRef(methods); + env->DeleteLocalRef(aClass); +} + +JavaClass::~JavaClass() { + free((void *)_name); + + JSLock lock(SilenceAssertionsOnly); + + deleteAllValues(_fields); + _fields.clear(); + + MethodListMap::const_iterator end = _methods.end(); + for (MethodListMap::const_iterator it = _methods.begin(); it != end; ++it) { + const MethodList* methodList = it->second; + deleteAllValues(*methodList); + delete methodList; + } + _methods.clear(); +} + +MethodList JavaClass::methodsNamed(const Identifier& identifier, Instance*) const +{ + MethodList *methodList = _methods.get(identifier.ustring().rep()); + + if (methodList) + return *methodList; + return MethodList(); +} + +Field *JavaClass::fieldNamed(const Identifier& identifier, Instance*) const +{ + return _fields.get(identifier.ustring().rep()); +} + +bool JavaClass::isNumberClass() const +{ + return ((strcmp(_name, "java.lang.Byte") == 0 || + strcmp(_name, "java.lang.Short") == 0 || + strcmp(_name, "java.lang.Integer") == 0 || + strcmp(_name, "java.lang.Long") == 0 || + strcmp(_name, "java.lang.Float") == 0 || + strcmp(_name, "java.lang.Double") == 0) ); +} + +bool JavaClass::isBooleanClass() const +{ + return strcmp(_name, "java.lang.Boolean") == 0; +} + +bool JavaClass::isStringClass() const +{ + return strcmp(_name, "java.lang.String") == 0; +} + +#endif // ENABLE(MAC_JAVA_BRIDGE) diff --git a/WebCore/bridge/jni/jsc/JavaClassJSC.h b/WebCore/bridge/jni/jsc/JavaClassJSC.h new file mode 100644 index 0000000..cbf7160 --- /dev/null +++ b/WebCore/bridge/jni/jsc/JavaClassJSC.h @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2003 Apple Computer, Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. 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 JavaClassJSC_h +#define JavaClassJSC_h + +#if ENABLE(MAC_JAVA_BRIDGE) + +#include +#include + +namespace JSC { + +namespace Bindings { + +class JavaClass : public Class { +public: + JavaClass (jobject anInstance); + ~JavaClass (); + + virtual MethodList methodsNamed(const Identifier&, Instance* instance) const; + virtual Field *fieldNamed(const Identifier&, Instance* instance) const; + + bool isNumberClass() const; + bool isBooleanClass() const; + bool isStringClass() const; + +private: + const char *_name; + FieldMap _fields; + MethodListMap _methods; +}; + +} // namespace Bindings + +} // namespace JSC + +#endif // ENABLE(MAC_JAVA_BRIDGE) + +#endif // JavaClassJSC_h diff --git a/WebCore/bridge/jni/jsc/JavaInstanceJSC.cpp b/WebCore/bridge/jni/jsc/JavaInstanceJSC.cpp index 37f413e..17e0147 100644 --- a/WebCore/bridge/jni/jsc/JavaInstanceJSC.cpp +++ b/WebCore/bridge/jni/jsc/JavaInstanceJSC.cpp @@ -28,7 +28,7 @@ #if ENABLE(MAC_JAVA_BRIDGE) -#include "jni_class.h" +#include "JavaClassJSC.h" #include "jni_runtime.h" #include "jni_utility.h" #include "jni_utility_private.h" -- cgit v1.1