From 7fb686e7b9de38c5d493745bcff821cd1782102b Mon Sep 17 00:00:00 2001 From: Steve Block Date: Tue, 19 Jan 2010 00:56:35 +0000 Subject: Cherry-pick WebKit change 53436 to fix style in JavaInstanceJSC See http://trac.webkit.org/changeset/53436 This is required to sync the Android tree with webkit.org to allow unforking in WebCore/bridge. Note that changes to the following were required as a result of this cherry-pick. - WebCoreFrameBridge.cpp - updated to use JavaInstance::m_instance - V8Binding/jni/jni_instance - Updated to rename the V8 version of JavaInstance::_instance to JavaInstance::m_instance to allow the same code path to be used in WebCoreFrameBridge. Change-Id: I6884f7424c8a0917095f828bda4ca62452e527b5 --- V8Binding/jni/jni_instance.cpp | 4 +- V8Binding/jni/jni_instance.h | 4 +- WebCore/ChangeLog | 18 ++ WebCore/bridge/jni/jni_runtime.cpp | 6 +- WebCore/bridge/jni/jni_runtime.h | 2 +- WebCore/bridge/jni/jsc/JavaInstanceJSC.cpp | 266 +++++++++++++++-------------- WebCore/bridge/jni/jsc/JavaInstanceJSC.h | 50 +++--- WebKit/android/jni/WebCoreFrameBridge.cpp | 10 +- 8 files changed, 191 insertions(+), 169 deletions(-) diff --git a/V8Binding/jni/jni_instance.cpp b/V8Binding/jni/jni_instance.cpp index 70da861..5b39690 100644 --- a/V8Binding/jni/jni_instance.cpp +++ b/V8Binding/jni/jni_instance.cpp @@ -40,13 +40,13 @@ using namespace JSC::Bindings; JavaInstance::JavaInstance (jobject instance) { - _instance = new JObjectWrapper(instance); + m_instance = new JObjectWrapper(instance); _class = 0; } JavaInstance::~JavaInstance () { - _instance = 0; + m_instance = 0; delete _class; } diff --git a/V8Binding/jni/jni_instance.h b/V8Binding/jni/jni_instance.h index 608b461..28a4607 100644 --- a/V8Binding/jni/jni_instance.h +++ b/V8Binding/jni/jni_instance.h @@ -79,7 +79,7 @@ public: bool invokeMethod(const char* name, const NPVariant* args, int argsCount, NPVariant* result); - jobject javaInstance() const { return _instance->_instance; } + jobject javaInstance() const { return m_instance->_instance; } // These functions are called before and after the main entry points into // the native implementations. They can be used to establish and cleanup @@ -88,7 +88,7 @@ public: void end() { virtualEnd(); } protected: - RefPtr _instance; + RefPtr m_instance; mutable JavaClass* _class; virtual void virtualBegin() {} diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog index d60de59..95285c8 100644 --- a/WebCore/ChangeLog +++ b/WebCore/ChangeLog @@ -2,6 +2,24 @@ Reviewed by Adam Barth. + Fix style in WebCore/bridge/jni/jsc/JavaInstanceJSC.[cpp|h] + https://bugs.webkit.org/show_bug.cgi?id=33792 + + No new tests, style fixes only. + + * bridge/jni/jni_runtime.cpp: Modified. + (JavaField::dispatchValueFromInstance): Modified. Updated to use renamed JavaInstance::m_instance + (JavaField::dispatchSetValueToInstance): Modified. Updated to use renamed JavaInstance::m_instance + (JavaArray::JavaArray): Modified. Updated to use renamed JavaInstance::m_instance + * bridge/jni/jni_runtime.h: Modified. + (JSC::Bindings::JavaArray::javaArray): Modified. Updated to use renamed JavaInstance::m_instance + * bridge/jni/jsc/JavaInstanceJSC.cpp: Modified. Fixed style + * bridge/jni/jsc/JavaInstanceJSC.h: Modified. Fixed style + +2010-01-18 Steve Block + + Reviewed by Adam Barth. + Moves JSC-specific version of JavaInstance from bridge/jni/jni_instance to bridge/jni/jsc/JavaInstanceJSC https://bugs.webkit.org/show_bug.cgi?id=33672 diff --git a/WebCore/bridge/jni/jni_runtime.cpp b/WebCore/bridge/jni/jni_runtime.cpp index 7f9fb72..d77048d 100644 --- a/WebCore/bridge/jni/jni_runtime.cpp +++ b/WebCore/bridge/jni/jni_runtime.cpp @@ -84,7 +84,7 @@ JSValue JavaArray::convertJObjectToArray(ExecState* exec, jobject anObject, cons jvalue JavaField::dispatchValueFromInstance(ExecState *exec, const JavaInstance *instance, const char *name, const char *sig, JNIType returnType) const { jobject jinstance = instance->javaInstance(); - jobject fieldJInstance = _field->_instance; + jobject fieldJInstance = _field->m_instance; JNIEnv *env = getJNIEnv(); jvalue result; @@ -168,7 +168,7 @@ JSValue JavaField::valueFromInstance(ExecState* exec, const Instance* i) const void JavaField::dispatchSetValueToInstance(ExecState *exec, const JavaInstance *instance, jvalue javaValue, const char *name, const char *sig) const { jobject jinstance = instance->javaInstance(); - jobject fieldJInstance = _field->_instance; + jobject fieldJInstance = _field->m_instance; JNIEnv *env = getJNIEnv(); jclass cls = env->GetObjectClass(fieldJInstance); @@ -377,7 +377,7 @@ JavaArray::JavaArray(jobject array, const char* type, PassRefPtr roo _array = new JObjectWrapper(array); // Java array are fixed length, so we can cache length. JNIEnv *env = getJNIEnv(); - _length = env->GetArrayLength((jarray)_array->_instance); + _length = env->GetArrayLength((jarray)_array->m_instance); _type = strdup(type); _rootObject = rootObject; } diff --git a/WebCore/bridge/jni/jni_runtime.h b/WebCore/bridge/jni/jni_runtime.h index e18b9a1..3b3aaf6 100644 --- a/WebCore/bridge/jni/jni_runtime.h +++ b/WebCore/bridge/jni/jni_runtime.h @@ -172,7 +172,7 @@ public: virtual JSValue valueAt(ExecState *exec, unsigned int index) const; virtual unsigned int getLength() const; - jobject javaArray() const { return _array->_instance; } + jobject javaArray() const { return _array->m_instance; } static JSValue convertJObjectToArray (ExecState* exec, jobject anObject, const char* type, PassRefPtr); diff --git a/WebCore/bridge/jni/jsc/JavaInstanceJSC.cpp b/WebCore/bridge/jni/jsc/JavaInstanceJSC.cpp index 3f88002..37f413e 100644 --- a/WebCore/bridge/jni/jsc/JavaInstanceJSC.cpp +++ b/WebCore/bridge/jni/jsc/JavaInstanceJSC.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003, 2008 Apple Inc. All rights reserved. + * Copyright (C) 2003, 2008, 2010 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -20,7 +20,7 @@ * 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. + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "config.h" @@ -46,83 +46,83 @@ #define JS_LOG(formatAndArgs...) ((void)0) #else #define JS_LOG(formatAndArgs...) { \ - fprintf (stderr, "%s:%d -- %s: ", __FILE__, __LINE__, __FUNCTION__); \ + fprintf(stderr, "%s:%d -- %s: ", __FILE__, __LINE__, __FUNCTION__); \ fprintf(stderr, formatAndArgs); \ } #endif - + using namespace JSC::Bindings; using namespace JSC; -JavaInstance::JavaInstance (jobject instance, PassRefPtr rootObject) +JavaInstance::JavaInstance(jobject instance, PassRefPtr rootObject) : Instance(rootObject) { - _instance = new JObjectWrapper (instance); - _class = 0; + m_instance = new JObjectWrapper(instance); + m_class = 0; } -JavaInstance::~JavaInstance () +JavaInstance::~JavaInstance() { - delete _class; + delete m_class; } #define NUM_LOCAL_REFS 64 void JavaInstance::virtualBegin() { - getJNIEnv()->PushLocalFrame (NUM_LOCAL_REFS); + getJNIEnv()->PushLocalFrame(NUM_LOCAL_REFS); } void JavaInstance::virtualEnd() { - getJNIEnv()->PopLocalFrame (NULL); + getJNIEnv()->PopLocalFrame(0); } -Class *JavaInstance::getClass() const +Class* JavaInstance::getClass() const { - if (_class == 0) - _class = new JavaClass (_instance->_instance); - return _class; + if (!m_class) + m_class = new JavaClass (m_instance->m_instance); + return m_class; } JSValue JavaInstance::stringValue(ExecState* exec) const { JSLock lock(SilenceAssertionsOnly); - - jstring stringValue = (jstring)callJNIMethod(_instance->_instance, "toString", "()Ljava/lang/String;"); - JNIEnv *env = getJNIEnv(); - const jchar *c = getUCharactersFromJStringInEnv(env, stringValue); - UString u((const UChar *)c, (int)env->GetStringLength(stringValue)); + + jstring stringValue = (jstring)callJNIMethod(m_instance->m_instance, "toString", "()Ljava/lang/String;"); + JNIEnv* env = getJNIEnv(); + const jchar* c = getUCharactersFromJStringInEnv(env, stringValue); + UString u((const UChar*)c, (int)env->GetStringLength(stringValue)); releaseUCharactersForJStringInEnv(env, stringValue, c); return jsString(exec, u); } JSValue JavaInstance::numberValue(ExecState* exec) const { - jdouble doubleValue = callJNIMethod(_instance->_instance, "doubleValue", "()D"); + jdouble doubleValue = callJNIMethod(m_instance->m_instance, "doubleValue", "()D"); return jsNumber(exec, doubleValue); } JSValue JavaInstance::booleanValue() const { - jboolean booleanValue = callJNIMethod(_instance->_instance, "booleanValue", "()Z"); + jboolean booleanValue = callJNIMethod(m_instance->m_instance, "booleanValue", "()Z"); return jsBoolean(booleanValue); } -JSValue JavaInstance::invokeMethod (ExecState *exec, const MethodList &methodList, const ArgList &args) +JSValue JavaInstance::invokeMethod(ExecState* exec, const MethodList& methodList, const ArgList &args) { int i, count = args.size(); - jvalue *jArgs; + jvalue* jArgs; JSValue resultValue; - Method *method = 0; + Method* method = 0; size_t numMethods = methodList.size(); - - // Try to find a good match for the overloaded method. The + + // 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 + // 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. - Method *aMethod; + Method* aMethod; for (size_t methodIndex = 0; methodIndex < numMethods; methodIndex++) { aMethod = methodList[methodIndex]; if (aMethod->numParameters() == count) { @@ -130,26 +130,25 @@ JSValue JavaInstance::invokeMethod (ExecState *exec, const MethodList &methodLis break; } } - if (method == 0) { - JS_LOG ("unable to find an appropiate method\n"); + if (!method) { + JS_LOG("unable to find an appropiate method\n"); return jsUndefined(); } - - const JavaMethod *jMethod = static_cast(method); - JS_LOG ("call %s %s on %p\n", UString(jMethod->name()).UTF8String().c_str(), jMethod->signature(), _instance->_instance); - - if (count > 0) { - jArgs = (jvalue *)malloc (count * sizeof(jvalue)); - } + + const JavaMethod* jMethod = static_cast(method); + JS_LOG("call %s %s on %p\n", UString(jMethod->name()).UTF8String().c_str(), jMethod->signature(), m_instance->m_instance); + + if (count > 0) + jArgs = (jvalue*)malloc(count * sizeof(jvalue)); else jArgs = 0; - + for (i = 0; i < count; i++) { JavaParameter* aParameter = jMethod->parameterAt(i); jArgs[i] = convertValueToJValue(exec, args.at(i), aParameter->getJNIType(), aParameter->type()); JS_LOG("arg[%d] = %s\n", i, args.at(i).toString(exec).ascii()); } - + jvalue result; // Try to use the JNI abstraction first, otherwise fall back to @@ -161,129 +160,136 @@ JSValue JavaInstance::invokeMethod (ExecState *exec, const MethodList &methodLis bool handled = false; if (rootObject->nativeHandle()) { - jobject obj = _instance->_instance; + jobject obj = m_instance->m_instance; JSValue exceptionDescription; - const char *callingURL = 0; // FIXME, need to propagate calling URL to Java + const char *callingURL = 0; // FIXME, need to propagate calling URL to Java handled = dispatchJNICall(exec, rootObject->nativeHandle(), obj, jMethod->isStatic(), jMethod->JNIReturnType(), jMethod->methodID(obj), jArgs, result, callingURL, exceptionDescription); if (exceptionDescription) { throwError(exec, GeneralError, exceptionDescription.toString(exec)); - free (jArgs); + free(jArgs); return jsUndefined(); } } - + // 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. - if (!handled) { - jobject obj = _instance->_instance; - switch (jMethod->JNIReturnType()){ - case void_type: - callJNIMethodIDA(obj, jMethod->methodID(obj), jArgs); - break; - case object_type: - result.l = callJNIMethodIDA(obj, jMethod->methodID(obj), jArgs); - break; - case boolean_type: - result.z = callJNIMethodIDA(obj, jMethod->methodID(obj), jArgs); - break; - case byte_type: - result.b = callJNIMethodIDA(obj, jMethod->methodID(obj), jArgs); - break; - case char_type: - result.c = callJNIMethodIDA(obj, jMethod->methodID(obj), jArgs); - break; - case short_type: - result.s = callJNIMethodIDA(obj, jMethod->methodID(obj), jArgs); - break; - case int_type: - result.i = callJNIMethodIDA(obj, jMethod->methodID(obj), jArgs); - break; - - case long_type: - result.j = callJNIMethodIDA(obj, jMethod->methodID(obj), jArgs); - break; - case float_type: - result.f = callJNIMethodIDA(obj, jMethod->methodID(obj), jArgs); - break; - case double_type: - result.d = callJNIMethodIDA(obj, jMethod->methodID(obj), jArgs); - break; - case invalid_type: - default: - break; + if (!handled) { + jobject obj = m_instance->m_instance; + switch (jMethod->JNIReturnType()) { + case void_type: + callJNIMethodIDA(obj, jMethod->methodID(obj), jArgs); + break; + case object_type: + result.l = callJNIMethodIDA(obj, jMethod->methodID(obj), jArgs); + break; + case boolean_type: + result.z = callJNIMethodIDA(obj, jMethod->methodID(obj), jArgs); + break; + case byte_type: + result.b = callJNIMethodIDA(obj, jMethod->methodID(obj), jArgs); + break; + case char_type: + result.c = callJNIMethodIDA(obj, jMethod->methodID(obj), jArgs); + break; + case short_type: + result.s = callJNIMethodIDA(obj, jMethod->methodID(obj), jArgs); + break; + case int_type: + result.i = callJNIMethodIDA(obj, jMethod->methodID(obj), jArgs); + break; + + case long_type: + result.j = callJNIMethodIDA(obj, jMethod->methodID(obj), jArgs); + break; + case float_type: + result.f = callJNIMethodIDA(obj, jMethod->methodID(obj), jArgs); + break; + case double_type: + result.d = callJNIMethodIDA(obj, jMethod->methodID(obj), jArgs); + break; + case invalid_type: + default: + break; } } - - switch (jMethod->JNIReturnType()){ - case void_type: { + + switch (jMethod->JNIReturnType()) { + case void_type: + { resultValue = jsUndefined(); } break; - - case object_type: { - if (result.l != 0) { - const char *arrayType = jMethod->returnType(); - if (arrayType[0] == '[') { + + case object_type: + { + if (result.l) { + const char* arrayType = jMethod->returnType(); + if (arrayType[0] == '[') resultValue = JavaArray::convertJObjectToArray(exec, result.l, arrayType, rootObject); - } - else { + else resultValue = JavaInstance::create(result.l, rootObject)->createRuntimeObject(exec); - } - } - else { + } else resultValue = jsUndefined(); - } } break; - - case boolean_type: { + + case boolean_type: + { resultValue = jsBoolean(result.z); } break; - - case byte_type: { + + case byte_type: + { resultValue = jsNumber(exec, result.b); } break; - - case char_type: { + + case char_type: + { resultValue = jsNumber(exec, result.c); } break; - - case short_type: { + + case short_type: + { resultValue = jsNumber(exec, result.s); } break; - - case int_type: { + + case int_type: + { resultValue = jsNumber(exec, result.i); } break; - - case long_type: { + + case long_type: + { resultValue = jsNumber(exec, result.j); } break; - - case float_type: { + + case float_type: + { resultValue = jsNumber(exec, result.f); } break; - - case double_type: { + + case double_type: + { resultValue = jsNumber(exec, result.d); } break; - case invalid_type: - default: { + case invalid_type: + default: + { resultValue = jsUndefined(); } break; } - free (jArgs); + free(jArgs); return resultValue; } @@ -294,7 +300,7 @@ JSValue JavaInstance::defaultValue(ExecState* exec, PreferredPrimitiveType hint) return stringValue(exec); if (hint == PreferNumber) return numberValue(exec); - JavaClass *aClass = static_cast(getClass()); + JavaClass* aClass = static_cast(getClass()); if (aClass->isStringClass()) return stringValue(exec); if (aClass->isNumberClass()) @@ -304,32 +310,32 @@ JSValue JavaInstance::defaultValue(ExecState* exec, PreferredPrimitiveType hint) return valueOf(exec); } -JSValue JavaInstance::valueOf(ExecState* exec) const +JSValue JavaInstance::valueOf(ExecState* exec) const { return stringValue(exec); } JObjectWrapper::JObjectWrapper(jobject instance) -: _refCount(0) + : m_refCount(0) { - assert (instance != 0); + assert(instance); // Cache the JNIEnv used to get the global ref for this java instanace. // It'll be used to delete the reference. - _env = getJNIEnv(); - - _instance = _env->NewGlobalRef (instance); - - JS_LOG ("new global ref %p for %p\n", _instance, instance); - - if (_instance == NULL) { - fprintf (stderr, "%s: could not get GlobalRef for %p\n", __PRETTY_FUNCTION__, instance); - } + m_env = getJNIEnv(); + + m_instance = m_env->NewGlobalRef(instance); + + JS_LOG("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() { - JS_LOG ("deleting global ref %p\n", _instance); - _env->DeleteGlobalRef (_instance); +JObjectWrapper::~JObjectWrapper() +{ + JS_LOG("deleting global ref %p\n", m_instance); + m_env->DeleteGlobalRef(m_instance); } #endif // ENABLE(MAC_JAVA_BRIDGE) diff --git a/WebCore/bridge/jni/jsc/JavaInstanceJSC.h b/WebCore/bridge/jni/jsc/JavaInstanceJSC.h index a9b83e3..fcd53f4 100644 --- a/WebCore/bridge/jni/jsc/JavaInstanceJSC.h +++ b/WebCore/bridge/jni/jsc/JavaInstanceJSC.h @@ -20,7 +20,7 @@ * 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. + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef JavaInstanceJSC_h @@ -39,8 +39,7 @@ namespace Bindings { class JavaClass; -class JObjectWrapper -{ +class JObjectWrapper { friend class RefPtr; friend class JavaArray; friend class JavaField; @@ -48,46 +47,45 @@ friend class JavaInstance; friend class JavaMethod; public: - jobject instance() const { return _instance; } - void setInstance(jobject instance) { _instance = instance; } + jobject instance() const { return m_instance; } + void setInstance(jobject instance) { m_instance = instance; } protected: - JObjectWrapper(jobject instance); + JObjectWrapper(jobject instance); ~JObjectWrapper(); - - void ref() { _refCount++; } - void deref() - { - if (--_refCount == 0) - delete this; + + void ref() { m_refCount++; } + void deref() + { + if (!(--m_refCount)) + delete this; } - jobject _instance; + jobject m_instance; private: - JNIEnv *_env; - unsigned int _refCount; + JNIEnv* m_env; + unsigned int m_refCount; }; -class JavaInstance : public Instance -{ +class JavaInstance : public Instance { public: - static PassRefPtr create(jobject instance, PassRefPtr rootObject) + static PassRefPtr create(jobject instance, PassRefPtr rootObject) { return adoptRef(new JavaInstance(instance, rootObject)); } - + ~JavaInstance(); - - virtual Class *getClass() const; - + + virtual Class* getClass() const; + virtual JSValue valueOf(ExecState*) const; virtual JSValue defaultValue(ExecState*, PreferredPrimitiveType) const; virtual JSValue invokeMethod(ExecState* exec, const MethodList& method, const ArgList& args); - jobject javaInstance() const { return _instance->_instance; } - + jobject javaInstance() const { return m_instance->m_instance; } + JSValue stringValue(ExecState*) const; JSValue numberValue(ExecState*) const; JSValue booleanValue() const; @@ -97,8 +95,8 @@ protected: virtual void virtualBegin(); virtual void virtualEnd(); - RefPtr _instance; - mutable JavaClass *_class; + RefPtr m_instance; + mutable JavaClass* m_class; }; } // namespace Bindings diff --git a/WebKit/android/jni/WebCoreFrameBridge.cpp b/WebKit/android/jni/WebCoreFrameBridge.cpp index 14d26f9..567fb6f 100644 --- a/WebKit/android/jni/WebCoreFrameBridge.cpp +++ b/WebKit/android/jni/WebCoreFrameBridge.cpp @@ -1222,14 +1222,14 @@ private: { JNIEnv* env = getJNIEnv(); // JavaInstance creates a global ref to instance in its constructor. - env->DeleteGlobalRef(_instance->instance()); + env->DeleteGlobalRef(m_instance->instance()); // Set the object to our WeakReference wrapper. - _instance->setInstance(adoptGlobalRef(env, instance)); + m_instance->setInstance(adoptGlobalRef(env, instance)); } virtual void virtualBegin() { - _weakRef = _instance->instance(); + _weakRef = m_instance->instance(); JNIEnv* env = getJNIEnv(); // This is odd. getRealObject returns an AutoJObject which is used to // cleanly create and delete a local reference. But, here we need to @@ -1238,7 +1238,7 @@ private: // and delete the local reference in virtualEnd(). _realObject = getRealObject(env, _weakRef).release(); // Point to the real object - _instance->setInstance(_realObject); + m_instance->setInstance(_realObject); // Call the base class method INHERITED::virtualBegin(); } @@ -1250,7 +1250,7 @@ private: // Get rid of the local reference to the real object. getJNIEnv()->DeleteLocalRef(_realObject); // Point back to the WeakReference. - _instance->setInstance(_weakRef); + m_instance->setInstance(_weakRef); } private: -- cgit v1.1