OSDN Git Service

Fixes style in V8 jni_runtime.[cpp|h]
authorSteve Block <steveblock@google.com>
Thu, 21 Jan 2010 16:35:56 +0000 (16:35 +0000)
committerSteve Block <steveblock@google.com>
Thu, 21 Jan 2010 18:28:14 +0000 (18:28 +0000)
This change makes it far easier to compare these files with WebCore/bridge/jni/Bridge.[cpp|h],
with which these files will eventually be merged.

Change-Id: I1b4ba9843f61c909568f85c65a0872a36d727fb3

V8Binding/jni/jni_runtime.cpp
V8Binding/jni/jni_runtime.h

index 0bf0508..6428bf2 100644 (file)
@@ -1,6 +1,5 @@
 /*
- * Copyright (C) 2003 Apple Computer, Inc.  All rights reserved.
- * Copyright 2009, The Android Open Source Project
+ * 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
@@ -21,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"
 
 using namespace JSC::Bindings;
 
-JavaParameter::JavaParameter (JNIEnv *env, jstring type)
+JavaParameter::JavaParameter(JNIEnv* env, jstring type)
 {
-    _type = JavaString (env, type);
-    _JNIType = JNITypeFromClassName (_type.UTF8String());
+    m_type = JavaString(env, type);
+    m_JNIType = JNITypeFromClassName(m_type.UTF8String());
 }
 
-
-JavaField::JavaField (JNIEnv *env, jobject aField)
+JavaField::JavaField(JNIEnv* env, jobject aField)
 {
     // Get field type
     jobject fieldType = callJNIMethod<jobject>(aField, "getType", "()Ljava/lang/Class;");
-    jstring fieldTypeName = (jstring)callJNIMethod<jobject>(fieldType, "getName", "()Ljava/lang/String;");
-    _type = JavaString(env, fieldTypeName);
-    _JNIType = JNITypeFromClassName (_type.UTF8String());
+    jstring fieldTypeName = static_cast<jstring>(callJNIMethod<jobject>(fieldType, "getName", "()Ljava/lang/String;"));
+    m_type = JavaString(env, fieldTypeName);
+    m_JNIType = JNITypeFromClassName(m_type.UTF8String());
 
     // Get field name
-    jstring fieldName = (jstring)callJNIMethod<jobject>(aField, "getName", "()Ljava/lang/String;");
-    _name = JavaString(env, fieldName);
+    jstring fieldName = static_cast<jstring>(callJNIMethod<jobject>(aField, "getName", "()Ljava/lang/String;"));
+    m_name = JavaString(env, fieldName);
 
-    _field = new JObjectWrapper(aField);
+    m_field = new JObjectWrapper(aField);
 }
 
-
-JavaMethod::JavaMethod (JNIEnv *env, jobject aMethod)
+JavaMethod::JavaMethod(JNIEnv* env, jobject aMethod)
 {
     // Get return type
     jobject returnType = callJNIMethod<jobject>(aMethod, "getReturnType", "()Ljava/lang/Class;");
-    jstring returnTypeName = (jstring)callJNIMethod<jobject>(returnType, "getName", "()Ljava/lang/String;");
-    _returnType =JavaString (env, returnTypeName);
-    _JNIReturnType = JNITypeFromClassName (_returnType.UTF8String());
-    env->DeleteLocalRef (returnType);
-    env->DeleteLocalRef (returnTypeName);
+    jstring returnTypeName = static_cast<jstring>(callJNIMethod<jobject>(returnType, "getName", "()Ljava/lang/String;"));
+    m_returnType = JavaString(env, returnTypeName);
+    m_JNIReturnType = JNITypeFromClassName(m_returnType.UTF8String());
+    env->DeleteLocalRef(returnType);
+    env->DeleteLocalRef(returnTypeName);
 
     // Get method name
-    jstring methodName = (jstring)callJNIMethod<jobject>(aMethod, "getName", "()Ljava/lang/String;");
-    _name = JavaString (env, methodName);
-    env->DeleteLocalRef (methodName);
+    jstring methodName = static_cast<jstring>(callJNIMethod<jobject>(aMethod, "getName", "()Ljava/lang/String;"));
+    m_name = JavaString(env, methodName);
+    env->DeleteLocalRef(methodName);
 
     // Get parameters
-    jarray jparameters = (jarray)callJNIMethod<jobject>(aMethod, "getParameterTypes", "()[Ljava/lang/Class;");
-    _numParameters = env->GetArrayLength (jparameters);
-    _parameters = new JavaParameter[_numParameters];
-    
-    int i;
-    for (i = 0; i < _numParameters; i++) {
-        jobject aParameter = env->GetObjectArrayElement ((jobjectArray)jparameters, i);
-        jstring parameterName = (jstring)callJNIMethod<jobject>(aParameter, "getName", "()Ljava/lang/String;");
-        _parameters[i] = JavaParameter(env, parameterName);
-        env->DeleteLocalRef (aParameter);
-        env->DeleteLocalRef (parameterName);
+    jarray jparameters = static_cast<jarray>(callJNIMethod<jobject>(aMethod, "getParameterTypes", "()[Ljava/lang/Class;"));
+    m_numParameters = env->GetArrayLength(jparameters);
+    m_parameters = new JavaParameter[m_numParameters];
+
+    for (int i = 0; i < m_numParameters; i++) {
+        jobject aParameter = env->GetObjectArrayElement(static_cast<jobjectArray>(jparameters), i);
+        jstring parameterName = static_cast<jstring>(callJNIMethod<jobject>(aParameter, "getName", "()Ljava/lang/String;"));
+        m_parameters[i] = JavaParameter(env, parameterName);
+        env->DeleteLocalRef(aParameter);
+        env->DeleteLocalRef(parameterName);
     }
-    env->DeleteLocalRef (jparameters);
+    env->DeleteLocalRef(jparameters);
 
     // Created lazily.
-    _signature = 0;
-    _methodID = 0;
-    
+    m_signature = 0;
+    m_methodID = 0;
+
     jclass modifierClass = env->FindClass("java/lang/reflect/Modifier");
     int modifiers = callJNIMethod<jint>(aMethod, "getModifiers", "()I");
-    _isStatic = (bool)callJNIStaticMethod<jboolean>(modifierClass, "isStatic", "(I)Z", modifiers);
+    m_isStatic = static_cast<bool>(callJNIStaticMethod<jboolean>(modifierClass, "isStatic", "(I)Z", modifiers));
     env->DeleteLocalRef(modifierClass);
 }
 
-JavaMethod::~JavaMethod() 
+JavaMethod::~JavaMethod()
 {
-    if (_signature)
-        free(_signature);
-    delete [] _parameters;
+    if (m_signature)
+        free(m_signature);
+    delete[] m_parameters;
 };
 
 
@@ -107,20 +103,20 @@ public:
     explicit SignatureBuilder(int init_size) {
         if (init_size <= 0)
             init_size = 16;
-        size_ = init_size;
-        length_ = 0;
-        storage_ = (char*)malloc(size_ * sizeof(char));
+        m_size = init_size;
+        m_length = 0;
+        m_storage = (char*)malloc(m_size * sizeof(char));
     }
 
     ~SignatureBuilder() {
-        free(storage_);
+        free(m_storage);
     }
 
     void append(const char* s) {
         int l = strlen(s);
         expandIfNeeded(l);
-        memcpy(storage_ + length_, s, l);
-        length_ += l;
+        memcpy(m_storage + m_length, s, l);
+        m_length += l;
     }
 
     // JNI method signatures use '/' between components of a class name, but
@@ -129,9 +125,9 @@ public:
        int l = strlen(className);
        expandIfNeeded(l);
 
-       char* sp = storage_ + length_;
+       char* sp = m_storage + m_length;
        const char* cp = className;
-    
+
        while (*cp) {
            if (*cp == '.')
                *sp = '/';
@@ -142,84 +138,83 @@ public:
            sp++;
        }
 
-       length_ += l;
+       m_length += l;
     }
 
     // make a duplicated copy of the content.
     char* ascii() {
-        if (length_ == 0)
+        if (m_length == 0)
             return NULL;
-        storage_[length_] = '\0';
-        return strndup(storage_, length_);
+        m_storage[m_length] = '\0';
+        return strndup(m_storage, m_length);
     }
 
 private:
     void expandIfNeeded(int l) {
         // expand storage if needed
-        if (l + length_ >= size_) {
-            int new_size = 2 * size_;
-            if (l + length_ >= new_size)
-                new_size = l + length_ + 1;
+        if (l + m_length >= m_size) {
+            int new_size = 2 * m_size;
+            if (l + m_length >= new_size)
+                new_size = l + m_length + 1;
 
             char* new_storage = (char*)malloc(new_size * sizeof(char));
-            memcpy(new_storage, storage_, length_);
-            size_ = new_size;
-            free(storage_);
-            storage_ = new_storage;
+            memcpy(new_storage, m_storage, m_length);
+            m_size = new_size;
+            free(m_storage);
+            m_storage = new_storage;
         }
     }
 
-    int size_;
-    int length_;
-    char* storage_;
+    int m_size;
+    int m_length;
+    char* m_storage;
 };
 
-const char *JavaMethod::signature() const 
+const char* JavaMethod::signature() const
 {
-    if (!_signature) {
+    if (!m_signature) {
         SignatureBuilder signatureBuilder(64);
         signatureBuilder.append("(");
-        for (int i = 0; i < _numParameters; i++) {
+        for (int i = 0; i < m_numParameters; i++) {
             JavaParameter* aParameter = parameterAt(i);
-            JNIType _JNIType = aParameter->getJNIType();
-            if (_JNIType == array_type)
+            JNIType type = aParameter->getJNIType();
+            if (type == array_type)
                 signatureBuilder.appendClassName(aParameter->type());
             else {
-                signatureBuilder.append(signatureFromPrimitiveType(_JNIType));
-                if (_JNIType == object_type) {
+                signatureBuilder.append(signatureFromPrimitiveType(type));
+                if (type == object_type) {
                     signatureBuilder.appendClassName(aParameter->type());
                     signatureBuilder.append(";");
                 }
             }
         }
         signatureBuilder.append(")");
-        
-        const char *returnType = _returnType.UTF8String();
-        if (_JNIReturnType == array_type) {
+
+        const char* returnType = m_returnType.UTF8String();
+        if (m_JNIReturnType == array_type)
             signatureBuilder.appendClassName(returnType);
-        else {
-            signatureBuilder.append(signatureFromPrimitiveType(_JNIReturnType));
-            if (_JNIReturnType == object_type) {
+        else {
+            signatureBuilder.append(signatureFromPrimitiveType(m_JNIReturnType));
+            if (m_JNIReturnType == object_type) {
                 signatureBuilder.appendClassName(returnType);
                 signatureBuilder.append(";");
             }
         }
-        
-        _signature = signatureBuilder.ascii();
+
+        m_signature = signatureBuilder.ascii();
     }
-    
-    return _signature;
+
+    return m_signature;
 }
 
 JNIType JavaMethod::JNIReturnType() const
 {
-    return _JNIReturnType;
+    return m_JNIReturnType;
 }
 
-jmethodID JavaMethod::methodID (jobject obj) const
+jmethodID JavaMethod::methodID(jobject obj) const
 {
-    if (_methodID == 0) {
-        _methodID = getMethodID (obj, _name.UTF8String(), signature());
-    }
-    return _methodID;
+    if (!m_methodID)
+        m_methodID = getMethodID(obj, m_name.UTF8String(), signature());
+    return m_methodID;
 }
index b493a73..735e2c2 100644 (file)
@@ -1,6 +1,5 @@
 /*
- * Copyright (C) 2003 Apple Computer, Inc.  All rights reserved.
- * Copyright 2009, The Android Open Source Project
+ * 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
  * 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 _JNI_RUNTIME_H_
-#define _JNI_RUNTIME_H_
+#ifndef jni_runtime_h
+#define jni_runtime_h
 
 #include "JNIUtility.h"
 #include "JavaInstanceV8.h"
 #include "JavaStringV8.h"
 #endif
 
-namespace JSC
-{
+namespace JSC {
 
-namespace Bindings
-{
+namespace Bindings {
 
-class JavaString
-{
+class JavaString {
 public:
     JavaString()
     {
@@ -66,71 +62,68 @@ private:
     JavaStringImpl m_impl;
 };
 
-class JavaParameter
-{
+class JavaParameter {
 public:
-    JavaParameter () : _JNIType(invalid_type) {};
-    JavaParameter (JNIEnv *env, jstring type);
+    JavaParameter() : m_JNIType(invalid_type) { }
+    JavaParameter(JNIEnv*, jstring type);
     virtual ~JavaParameter() { }
 
-    const char* type() const { return _type.UTF8String(); }
-    JNIType getJNIType() const { return _JNIType; }
-    
+    const char* type() const { return m_type.UTF8String(); }
+    JNIType getJNIType() const { return m_JNIType; }
+
 private:
-    JavaString _type;
-    JNIType _JNIType;
+    JavaString m_type;
+    JNIType m_JNIType;
 };
 
 
-class JavaField
-{
+class JavaField {
 public:
-    JavaField (JNIEnv *env, jobject aField);
+    JavaField(JNIEnv*, jobject aField);
+
+    const JavaString& name() const { return m_name; }
+    const char* type() const { return m_type.UTF8String(); }
 
-    const JavaString& name() const { return _name; }
-    const char* type() const { return _type.UTF8String(); }
+    JNIType getJNIType() const { return m_JNIType; }
 
-    JNIType getJNIType() const { return _JNIType; }
-    
 private:
-    JavaString _name;
-    JavaString _type;
-    JNIType _JNIType;
-    RefPtr<JObjectWrapper> _field;
+    JavaString m_name;
+    JavaString m_type;
+    JNIType m_JNIType;
+    RefPtr<JObjectWrapper> m_field;
 };
 
 
-class JavaMethod
-{
+class JavaMethod {
 public:
-    JavaMethod(JNIEnv* env, jobject aMethod);
+    JavaMethod(JNIEnv*, jobject aMethod);
     ~JavaMethod();
 
-    const JavaString& name() const { return _name; }
-    const char* returnType() const { return _returnType.UTF8String(); };
-    JavaParameter* parameterAt(int i) const { return &_parameters[i]; };
-    int numParameters() const { return _numParameters; };
-    
-    const char *signature() const;
+    const JavaString& name() const { return m_name; }
+    const char* returnType() const { return m_returnType.UTF8String(); }
+    JavaParameter* parameterAt(int i) const { return &m_parameters[i]; }
+    int numParameters() const { return m_numParameters; }
+
+    const charsignature() const;
     JNIType JNIReturnType() const;
 
-    jmethodID methodID (jobject obj) const;
-    
-    bool isStatic() const { return _isStatic; }
+    jmethodID methodID(jobject obj) const;
+
+    bool isStatic() const { return m_isStatic; }
 
 private:
-    JavaParameter* _parameters;
-    int _numParameters;
-    JavaString _name;
-    mutable char* _signature;
-    JavaString _returnType;
-    JNIType _JNIReturnType;
-    mutable jmethodID _methodID;
-    bool _isStatic;
+    JavaParameter* m_parameters;
+    int m_numParameters;
+    JavaString m_name;
+    mutable char* m_signature;
+    JavaString m_returnType;
+    JNIType m_JNIReturnType;
+    mutable jmethodID m_methodID;
+    bool m_isStatic;
 };
 
 } // namespace Bindings
 
 } // namespace JSC
 
-#endif // _JNI_RUNTIME_H_
+#endif // jni_runtime_h