Changeset 91355 in webkit
- Timestamp:
- Jul 20, 2011 4:20:02 AM (13 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r91353 r91355 1 2011-07-20 Steve Block <steveblock@google.com> 2 3 JobjectWrapper should inherit from RefCounted rather than implementing its own ref counting 4 https://bugs.webkit.org/show_bug.cgi?id=55786 5 6 Also adds static create() method and cleans up use of data members. 7 8 Reviewed by Tony Gentilcore. 9 10 No new tests, refactoring only. 11 12 * bridge/jni/JobjectWrapper.cpp: 13 (JobjectWrapper::JobjectWrapper): 14 * bridge/jni/JobjectWrapper.h: 15 (JSC::Bindings::JobjectWrapper::create): 16 * bridge/jni/jsc/JavaArrayJSC.cpp: 17 (JavaArray::JavaArray): 18 * bridge/jni/jsc/JavaArrayJSC.h: 19 (JSC::Bindings::JavaArray::javaArray): 20 * bridge/jni/jsc/JavaFieldJSC.cpp: 21 (JavaField::JavaField): 22 (JavaField::dispatchValueFromInstance): 23 (JavaField::dispatchSetValueToInstance): 24 * bridge/jni/jsc/JavaInstanceJSC.cpp: 25 (JavaInstance::JavaInstance): 26 (JavaInstance::getClass): 27 (JavaInstance::stringValue): 28 (JavaInstance::numberValue): 29 (JavaInstance::booleanValue): 30 (JavaInstance::invokeMethod): 31 * bridge/jni/jsc/JavaInstanceJSC.h: 32 (JSC::Bindings::JavaInstance::javaInstance): 33 * bridge/jni/v8/JavaFieldJobjectV8.cpp: 34 (JavaFieldJobject::JavaFieldJobject): 35 * bridge/jni/v8/JavaInstanceJobjectV8.cpp: 36 (JavaInstanceJobject::JavaInstanceJobject): 37 * bridge/jni/v8/JavaInstanceJobjectV8.h: 38 (JSC::Bindings::JavaInstanceJobject::javaInstance): 39 1 40 2011-07-20 Kentaro Hara <haraken@google.com> 2 41 -
trunk/Source/WebCore/bridge/jni/JobjectWrapper.cpp
r80367 r91355 30 30 #if ENABLE(JAVA_BRIDGE) 31 31 32 #include <assert.h>33 34 32 using namespace JSC::Bindings; 35 33 36 34 JobjectWrapper::JobjectWrapper(jobject instance) 37 : m_refCount(0)38 35 { 39 assert(instance);36 ASSERT(instance); 40 37 41 38 // Cache the JNIEnv used to get the global ref for this java instanace. -
trunk/Source/WebCore/bridge/jni/JobjectWrapper.h
r82950 r91355 31 31 32 32 #include "JNIUtility.h" 33 #include <wtf/PassRefPtr.h> 34 #include <wtf/RefCounted.h> 33 35 34 36 namespace JSC { … … 36 38 namespace Bindings { 37 39 38 class JobjectWrapper { 39 friend class JavaArray; 40 friend class JavaField; 41 friend class JavaFieldJobject; 42 friend class JavaInstance; 43 friend class JavaInstanceJobject; 40 class JobjectWrapper : public RefCounted<JobjectWrapper> { 41 public: 42 static PassRefPtr<JobjectWrapper> create(jobject object) { return adoptRef(new JobjectWrapper(object)); } 43 ~JobjectWrapper(); 44 44 45 public:46 45 jobject instance() const { return m_instance; } 47 46 void setInstance(jobject instance) { m_instance = instance; } 48 47 49 void ref() { m_refCount++; } 50 void deref() 51 { 52 if (!--m_refCount) 53 delete this; 54 } 55 56 protected: 48 private: 57 49 JobjectWrapper(jobject); 58 ~JobjectWrapper();59 50 60 51 jobject m_instance; 61 62 private:63 52 JNIEnv* m_env; 64 unsigned int m_refCount;65 53 }; 66 54 -
trunk/Source/WebCore/bridge/jni/jsc/JavaArrayJSC.cpp
r81860 r91355 54 54 : Array(rootObject) 55 55 { 56 m_array = new JobjectWrapper(array);56 m_array = JobjectWrapper::create(array); 57 57 // Java array are fixed length, so we can cache length. 58 58 JNIEnv* env = getJNIEnv(); 59 m_length = env->GetArrayLength(static_cast<jarray>(m_array-> m_instance));59 m_length = env->GetArrayLength(static_cast<jarray>(m_array->instance())); 60 60 m_type = strdup(type); 61 61 } -
trunk/Source/WebCore/bridge/jni/jsc/JavaArrayJSC.h
r80476 r91355 49 49 virtual unsigned int getLength() const; 50 50 51 jobject javaArray() const { return m_array-> m_instance; }51 jobject javaArray() const { return m_array->instance(); } 52 52 53 53 static JSValue convertJObjectToArray(ExecState*, jobject, const char* type, PassRefPtr<RootObject>); -
trunk/Source/WebCore/bridge/jni/jsc/JavaFieldJSC.cpp
r81860 r91355 59 59 m_name = JavaString(env, fieldName); 60 60 61 m_field = new JobjectWrapper(aField);61 m_field = JobjectWrapper::create(aField); 62 62 } 63 63 … … 65 65 { 66 66 jobject jinstance = instance->javaInstance(); 67 jobject fieldJInstance = m_field-> m_instance;67 jobject fieldJInstance = m_field->instance(); 68 68 JNIEnv* env = getJNIEnv(); 69 69 jvalue result; … … 152 152 { 153 153 jobject jinstance = instance->javaInstance(); 154 jobject fieldJInstance = m_field-> m_instance;154 jobject fieldJInstance = m_field->instance(); 155 155 JNIEnv* env = getJNIEnv(); 156 156 -
trunk/Source/WebCore/bridge/jni/jsc/JavaInstanceJSC.cpp
r85036 r91355 53 53 : Instance(rootObject) 54 54 { 55 m_instance = new JobjectWrapper(instance);55 m_instance = JobjectWrapper::create(instance); 56 56 m_class = 0; 57 57 } … … 82 82 { 83 83 if (!m_class) 84 m_class = new JavaClass (m_instance-> m_instance);84 m_class = new JavaClass (m_instance->instance()); 85 85 return m_class; 86 86 } … … 90 90 JSLock lock(SilenceAssertionsOnly); 91 91 92 jstring stringValue = (jstring)callJNIMethod<jobject>(m_instance-> m_instance, "toString", "()Ljava/lang/String;");92 jstring stringValue = (jstring)callJNIMethod<jobject>(m_instance->instance(), "toString", "()Ljava/lang/String;"); 93 93 94 94 // Should throw a JS exception, rather than returning ""? - but better than a null dereference. … … 105 105 JSValue JavaInstance::numberValue(ExecState*) const 106 106 { 107 jdouble doubleValue = callJNIMethod<jdouble>(m_instance-> m_instance, "doubleValue", "()D");107 jdouble doubleValue = callJNIMethod<jdouble>(m_instance->instance(), "doubleValue", "()D"); 108 108 return jsNumber(doubleValue); 109 109 } … … 111 111 JSValue JavaInstance::booleanValue() const 112 112 { 113 jboolean booleanValue = callJNIMethod<jboolean>(m_instance-> m_instance, "booleanValue", "()Z");113 jboolean booleanValue = callJNIMethod<jboolean>(m_instance->instance(), "booleanValue", "()Z"); 114 114 return jsBoolean(booleanValue); 115 115 } … … 193 193 bool handled = false; 194 194 if (rootObject->nativeHandle()) { 195 jobject obj = m_instance-> m_instance;195 jobject obj = m_instance->instance(); 196 196 JSValue exceptionDescription; 197 197 const char *callingURL = 0; // FIXME, need to propagate calling URL to Java … … 208 208 #if PLATFORM(ANDROID) 209 209 if (!handled) 210 result = callJNIMethod(m_instance-> m_instance, jMethod->returnType(), jMethod->name().utf8().data(), jMethod->signature(), jArgs.data());210 result = callJNIMethod(m_instance->instance(), jMethod->returnType(), jMethod->name().utf8().data(), jMethod->signature(), jArgs.data()); 211 211 #endif 212 212 -
trunk/Source/WebCore/bridge/jni/jsc/JavaInstanceJSC.h
r80367 r91355 57 57 virtual JSValue invokeMethod(ExecState* exec, RuntimeMethod* method); 58 58 59 jobject javaInstance() const { return m_instance-> m_instance; }59 jobject javaInstance() const { return m_instance->instance(); } 60 60 61 61 JSValue stringValue(ExecState*) const; -
trunk/Source/WebCore/bridge/jni/v8/JavaFieldJobjectV8.cpp
r82554 r91355 43 43 m_name = JavaString(env, fieldName); 44 44 45 m_field = new JobjectWrapper(aField);45 m_field = JobjectWrapper::create(aField); 46 46 } 47 47 -
trunk/Source/WebCore/bridge/jni/v8/JavaInstanceJobjectV8.cpp
r82950 r91355 42 42 43 43 JavaInstanceJobject::JavaInstanceJobject(jobject instance) 44 : m_instance( new JobjectWrapper(instance))44 : m_instance(JobjectWrapper::create(instance)) 45 45 { 46 46 } -
trunk/Source/WebCore/bridge/jni/v8/JavaInstanceJobjectV8.h
r82950 r91355 54 54 virtual void end(); 55 55 56 jobject javaInstance() const { return m_instance-> m_instance; }56 jobject javaInstance() const { return m_instance->instance(); } 57 57 58 58 protected:
Note: See TracChangeset
for help on using the changeset viewer.