Changeset 53436 in webkit


Ignore:
Timestamp:
Jan 18, 2010 3:49:35 PM (14 years ago)
Author:
eric@webkit.org
Message:

2010-01-18 Steve Block <steveblock@google.com>

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
Location:
trunk/WebCore
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r53434 r53436  
     12010-01-18  Steve Block  <steveblock@google.com>
     2
     3        Reviewed by Adam Barth.
     4
     5        Fix style in WebCore/bridge/jni/jsc/JavaInstanceJSC.[cpp|h]
     6        https://bugs.webkit.org/show_bug.cgi?id=33792
     7
     8        No new tests, style fixes only.
     9
     10        * bridge/jni/jni_runtime.cpp: Modified.
     11        (JavaField::dispatchValueFromInstance): Modified. Updated to use renamed JavaInstance::m_instance
     12        (JavaField::dispatchSetValueToInstance): Modified. Updated to use renamed JavaInstance::m_instance
     13        (JavaArray::JavaArray): Modified. Updated to use renamed JavaInstance::m_instance
     14        * bridge/jni/jni_runtime.h: Modified.
     15        (JSC::Bindings::JavaArray::javaArray): Modified. Updated to use renamed JavaInstance::m_instance
     16        * bridge/jni/jsc/JavaInstanceJSC.cpp: Modified. Fixed style
     17        * bridge/jni/jsc/JavaInstanceJSC.h: Modified. Fixed style
     18
    1192010-01-18  Chris Marrin  <cmarrin@apple.com>
    220
  • trunk/WebCore/bridge/jni/jni_runtime.cpp

    r53193 r53436  
    8585{
    8686    jobject jinstance = instance->javaInstance();
    87     jobject fieldJInstance = _field->_instance;
     87    jobject fieldJInstance = _field->m_instance;
    8888    JNIEnv *env = getJNIEnv();
    8989    jvalue result;
     
    169169{
    170170    jobject jinstance = instance->javaInstance();
    171     jobject fieldJInstance = _field->_instance;
     171    jobject fieldJInstance = _field->m_instance;
    172172    JNIEnv *env = getJNIEnv();
    173173
     
    378378    // Java array are fixed length, so we can cache length.
    379379    JNIEnv *env = getJNIEnv();
    380     _length = env->GetArrayLength((jarray)_array->_instance);
     380    _length = env->GetArrayLength((jarray)_array->m_instance);
    381381    _type = strdup(type);
    382382    _rootObject = rootObject;
  • trunk/WebCore/bridge/jni/jni_runtime.h

    r53412 r53436  
    173173    virtual unsigned int getLength() const;
    174174   
    175     jobject javaArray() const { return _array->_instance; }
     175    jobject javaArray() const { return _array->m_instance; }
    176176
    177177    static JSValue convertJObjectToArray (ExecState* exec, jobject anObject, const char* type, PassRefPtr<RootObject>);
  • trunk/WebCore/bridge/jni/jsc/JavaInstanceJSC.cpp

    r53412 r53436  
    11/*
    2  * Copyright (C) 2003, 2008 Apple Inc. All rights reserved.
     2 * Copyright (C) 2003, 2008, 2010 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2121 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    2222 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
     23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2424 */
    2525
     
    4747#else
    4848#define JS_LOG(formatAndArgs...) { \
    49     fprintf (stderr, "%s:%d -- %s:  ", __FILE__, __LINE__, __FUNCTION__); \
     49    fprintf(stderr, "%s:%d -- %s:  ", __FILE__, __LINE__, __FUNCTION__); \
    5050    fprintf(stderr, formatAndArgs); \
    5151}
    5252#endif
    53  
     53
    5454using namespace JSC::Bindings;
    5555using namespace JSC;
    5656
    57 JavaInstance::JavaInstance (jobject instance, PassRefPtr<RootObject> rootObject)
     57JavaInstance::JavaInstance(jobject instance, PassRefPtr<RootObject> rootObject)
    5858    : Instance(rootObject)
    5959{
    60     _instance = new JObjectWrapper (instance);
    61     _class = 0;
    62 }
    63 
    64 JavaInstance::~JavaInstance ()
    65 {
    66     delete _class;
     60    m_instance = new JObjectWrapper(instance);
     61    m_class = 0;
     62}
     63
     64JavaInstance::~JavaInstance()
     65{
     66    delete m_class;
    6767}
    6868
     
    7171void JavaInstance::virtualBegin()
    7272{
    73     getJNIEnv()->PushLocalFrame (NUM_LOCAL_REFS);
     73    getJNIEnv()->PushLocalFrame(NUM_LOCAL_REFS);
    7474}
    7575
    7676void JavaInstance::virtualEnd()
    7777{
    78     getJNIEnv()->PopLocalFrame (NULL);
    79 }
    80 
    81 Class *JavaInstance::getClass() const
    82 {
    83     if (_class == 0)
    84         _class = new JavaClass (_instance->_instance);
    85     return _class;
     78    getJNIEnv()->PopLocalFrame(0);
     79}
     80
     81Class* JavaInstance::getClass() const
     82{
     83    if (!m_class)
     84        m_class = new JavaClass (m_instance->m_instance);
     85    return m_class;
    8686}
    8787
     
    8989{
    9090    JSLock lock(SilenceAssertionsOnly);
    91    
    92     jstring stringValue = (jstring)callJNIMethod<jobject>(_instance->_instance, "toString", "()Ljava/lang/String;");
    93     JNIEnv *env = getJNIEnv();
    94     const jchar *c = getUCharactersFromJStringInEnv(env, stringValue);
    95     UString u((const UChar *)c, (int)env->GetStringLength(stringValue));
     91
     92    jstring stringValue = (jstring)callJNIMethod<jobject>(m_instance->m_instance, "toString", "()Ljava/lang/String;");
     93    JNIEnv* env = getJNIEnv();
     94    const jchar* c = getUCharactersFromJStringInEnv(env, stringValue);
     95    UString u((const UChar*)c, (int)env->GetStringLength(stringValue));
    9696    releaseUCharactersForJStringInEnv(env, stringValue, c);
    9797    return jsString(exec, u);
     
    100100JSValue JavaInstance::numberValue(ExecState* exec) const
    101101{
    102     jdouble doubleValue = callJNIMethod<jdouble>(_instance->_instance, "doubleValue", "()D");
     102    jdouble doubleValue = callJNIMethod<jdouble>(m_instance->m_instance, "doubleValue", "()D");
    103103    return jsNumber(exec, doubleValue);
    104104}
     
    106106JSValue JavaInstance::booleanValue() const
    107107{
    108     jboolean booleanValue = callJNIMethod<jboolean>(_instance->_instance, "booleanValue", "()Z");
     108    jboolean booleanValue = callJNIMethod<jboolean>(m_instance->m_instance, "booleanValue", "()Z");
    109109    return jsBoolean(booleanValue);
    110110}
    111111
    112 JSValue JavaInstance::invokeMethod (ExecState *exec, const MethodList &methodList, const ArgList &args)
     112JSValue JavaInstance::invokeMethod(ExecState* exec, const MethodList& methodList, const ArgList &args)
    113113{
    114114    int i, count = args.size();
    115     jvalue *jArgs;
     115    jvalue* jArgs;
    116116    JSValue resultValue;
    117     Method *method = 0;
     117    Method* method = 0;
    118118    size_t numMethods = methodList.size();
    119    
    120     // Try to find a good match for the overloaded method.  The 
     119
     120    // Try to find a good match for the overloaded method.  The
    121121    // fundamental problem is that JavaScript doesn have the
    122     // notion of method overloading and Java does.  We could 
     122    // notion of method overloading and Java does.  We could
    123123    // get a bit more sophisticated and attempt to does some
    124124    // type checking as we as checking the number of parameters.
    125     Method *aMethod;
     125    Method* aMethod;
    126126    for (size_t methodIndex = 0; methodIndex < numMethods; methodIndex++) {
    127127        aMethod = methodList[methodIndex];
     
    131131        }
    132132    }
    133     if (method == 0) {
    134         JS_LOG ("unable to find an appropiate method\n");
     133    if (!method) {
     134        JS_LOG("unable to find an appropiate method\n");
    135135        return jsUndefined();
    136136    }
    137    
    138     const JavaMethod *jMethod = static_cast<const JavaMethod*>(method);
    139     JS_LOG ("call %s %s on %p\n", UString(jMethod->name()).UTF8String().c_str(), jMethod->signature(), _instance->_instance);
    140    
    141     if (count > 0) {
    142         jArgs = (jvalue *)malloc (count * sizeof(jvalue));
    143     }
     137
     138    const JavaMethod* jMethod = static_cast<const JavaMethod*>(method);
     139    JS_LOG("call %s %s on %p\n", UString(jMethod->name()).UTF8String().c_str(), jMethod->signature(), m_instance->m_instance);
     140
     141    if (count > 0)
     142        jArgs = (jvalue*)malloc(count * sizeof(jvalue));
    144143    else
    145144        jArgs = 0;
    146        
     145
    147146    for (i = 0; i < count; i++) {
    148147        JavaParameter* aParameter = jMethod->parameterAt(i);
     
    150149        JS_LOG("arg[%d] = %s\n", i, args.at(i).toString(exec).ascii());
    151150    }
    152        
     151
    153152    jvalue result;
    154153
     
    162161    bool handled = false;
    163162    if (rootObject->nativeHandle()) {
    164         jobject obj = _instance->_instance;
     163        jobject obj = m_instance->m_instance;
    165164        JSValue exceptionDescription;
    166         const char *callingURL = 0;  // FIXME, need to propagate calling URL to Java
     165        const char *callingURL = 0; // FIXME, need to propagate calling URL to Java
    167166        handled = dispatchJNICall(exec, rootObject->nativeHandle(), obj, jMethod->isStatic(), jMethod->JNIReturnType(), jMethod->methodID(obj), jArgs, result, callingURL, exceptionDescription);
    168167        if (exceptionDescription) {
    169168            throwError(exec, GeneralError, exceptionDescription.toString(exec));
    170             free (jArgs);
     169            free(jArgs);
    171170            return jsUndefined();
    172171        }
    173172    }
    174    
     173
    175174    // The following code can be conditionally removed once we have a Tiger update that
    176175    // contains the new Java plugin.  It is needed for builds prior to Tiger.
    177     if (!handled) {   
    178         jobject obj = _instance->_instance;
    179         switch (jMethod->JNIReturnType()){
    180             case void_type:
    181                 callJNIMethodIDA<void>(obj, jMethod->methodID(obj), jArgs);
    182                 break;           
    183             case object_type:
    184                 result.l = callJNIMethodIDA<jobject>(obj, jMethod->methodID(obj), jArgs);
    185                 break;
    186             case boolean_type:
    187                 result.z = callJNIMethodIDA<jboolean>(obj, jMethod->methodID(obj), jArgs);
    188                 break;
    189             case byte_type:
    190                 result.b = callJNIMethodIDA<jbyte>(obj, jMethod->methodID(obj), jArgs);
    191                 break;
    192             case char_type:
    193                 result.c = callJNIMethodIDA<jchar>(obj, jMethod->methodID(obj), jArgs);
    194                 break;           
    195             case short_type:
    196                 result.s = callJNIMethodIDA<jshort>(obj, jMethod->methodID(obj), jArgs);
    197                 break;
    198             case int_type:
    199                 result.i = callJNIMethodIDA<jint>(obj, jMethod->methodID(obj), jArgs);
    200                 break;
    201            
    202             case long_type:
    203                 result.j = callJNIMethodIDA<jlong>(obj, jMethod->methodID(obj), jArgs);
    204                 break;
    205             case float_type:
    206                 result.f = callJNIMethodIDA<jfloat>(obj, jMethod->methodID(obj), jArgs);
    207                 break;
    208             case double_type:
    209                 result.d = callJNIMethodIDA<jdouble>(obj, jMethod->methodID(obj), jArgs);
    210                 break;
    211             case invalid_type:
    212             default:
    213                 break;
    214         }
    215     }
    216        
    217     switch (jMethod->JNIReturnType()){
    218         case void_type: {
     176    if (!handled) {
     177        jobject obj = m_instance->m_instance;
     178        switch (jMethod->JNIReturnType()) {
     179        case void_type:
     180            callJNIMethodIDA<void>(obj, jMethod->methodID(obj), jArgs);
     181            break;
     182        case object_type:
     183            result.l = callJNIMethodIDA<jobject>(obj, jMethod->methodID(obj), jArgs);
     184            break;
     185        case boolean_type:
     186            result.z = callJNIMethodIDA<jboolean>(obj, jMethod->methodID(obj), jArgs);
     187            break;
     188        case byte_type:
     189            result.b = callJNIMethodIDA<jbyte>(obj, jMethod->methodID(obj), jArgs);
     190            break;
     191        case char_type:
     192            result.c = callJNIMethodIDA<jchar>(obj, jMethod->methodID(obj), jArgs);
     193            break;
     194        case short_type:
     195            result.s = callJNIMethodIDA<jshort>(obj, jMethod->methodID(obj), jArgs);
     196            break;
     197        case int_type:
     198            result.i = callJNIMethodIDA<jint>(obj, jMethod->methodID(obj), jArgs);
     199            break;
     200
     201        case long_type:
     202            result.j = callJNIMethodIDA<jlong>(obj, jMethod->methodID(obj), jArgs);
     203            break;
     204        case float_type:
     205            result.f = callJNIMethodIDA<jfloat>(obj, jMethod->methodID(obj), jArgs);
     206            break;
     207        case double_type:
     208            result.d = callJNIMethodIDA<jdouble>(obj, jMethod->methodID(obj), jArgs);
     209            break;
     210        case invalid_type:
     211        default:
     212            break;
     213        }
     214    }
     215
     216    switch (jMethod->JNIReturnType()) {
     217    case void_type:
     218        {
    219219            resultValue = jsUndefined();
    220220        }
    221221        break;
    222        
    223         case object_type: {
    224             if (result.l != 0) {
    225                 const char *arrayType = jMethod->returnType();
    226                 if (arrayType[0] == '[') {
     222
     223    case object_type:
     224        {
     225            if (result.l) {
     226                const char* arrayType = jMethod->returnType();
     227                if (arrayType[0] == '[')
    227228                    resultValue = JavaArray::convertJObjectToArray(exec, result.l, arrayType, rootObject);
    228                 }
    229                 else {
     229                else
    230230                    resultValue = JavaInstance::create(result.l, rootObject)->createRuntimeObject(exec);
    231                 }
    232             }
    233             else {
     231            } else
    234232                resultValue = jsUndefined();
    235             }
    236         }
    237         break;
    238        
    239         case boolean_type: {
     233        }
     234        break;
     235
     236    case boolean_type:
     237        {
    240238            resultValue = jsBoolean(result.z);
    241239        }
    242240        break;
    243        
    244         case byte_type: {
     241
     242    case byte_type:
     243        {
    245244            resultValue = jsNumber(exec, result.b);
    246245        }
    247246        break;
    248        
    249         case char_type: {
     247
     248    case char_type:
     249        {
    250250            resultValue = jsNumber(exec, result.c);
    251251        }
    252252        break;
    253        
    254         case short_type: {
     253
     254    case short_type:
     255        {
    255256            resultValue = jsNumber(exec, result.s);
    256257        }
    257258        break;
    258        
    259         case int_type: {
     259
     260    case int_type:
     261        {
    260262            resultValue = jsNumber(exec, result.i);
    261263        }
    262264        break;
    263        
    264         case long_type: {
     265
     266    case long_type:
     267        {
    265268            resultValue = jsNumber(exec, result.j);
    266269        }
    267270        break;
    268        
    269         case float_type: {
     271
     272    case float_type:
     273        {
    270274            resultValue = jsNumber(exec, result.f);
    271275        }
    272276        break;
    273        
    274         case double_type: {
     277
     278    case double_type:
     279        {
    275280            resultValue = jsNumber(exec, result.d);
    276281        }
    277282        break;
    278283
    279         case invalid_type:
    280         default: {
     284    case invalid_type:
     285    default:
     286        {
    281287            resultValue = jsUndefined();
    282288        }
     
    284290    }
    285291
    286     free (jArgs);
     292    free(jArgs);
    287293
    288294    return resultValue;
     
    295301    if (hint == PreferNumber)
    296302        return numberValue(exec);
    297     JavaClass *aClass = static_cast<JavaClass*>(getClass());
     303    JavaClass* aClass = static_cast<JavaClass*>(getClass());
    298304    if (aClass->isStringClass())
    299305        return stringValue(exec);
     
    305311}
    306312
    307 JSValue JavaInstance::valueOf(ExecState* exec) const 
     313JSValue JavaInstance::valueOf(ExecState* exec) const
    308314{
    309315    return stringValue(exec);
     
    311317
    312318JObjectWrapper::JObjectWrapper(jobject instance)
    313 : _refCount(0)
    314 {
    315     assert (instance != 0);
     319    : m_refCount(0)
     320{
     321    assert(instance);
    316322
    317323    // Cache the JNIEnv used to get the global ref for this java instanace.
    318324    // It'll be used to delete the reference.
    319     _env = getJNIEnv();
    320        
    321     _instance = _env->NewGlobalRef (instance);
    322    
    323     JS_LOG ("new global ref %p for %p\n", _instance, instance);
    324 
    325     if  (_instance == NULL) {
    326         fprintf (stderr, "%s:  could not get GlobalRef for %p\n", __PRETTY_FUNCTION__, instance);
    327     }
    328 }
    329 
    330 JObjectWrapper::~JObjectWrapper() {
    331     JS_LOG ("deleting global ref %p\n", _instance);
    332     _env->DeleteGlobalRef (_instance);
     325    m_env = getJNIEnv();
     326
     327    m_instance = m_env->NewGlobalRef(instance);
     328
     329    JS_LOG("new global ref %p for %p\n", m_instance, instance);
     330
     331    if  (!m_instance)
     332        fprintf(stderr, "%s:  could not get GlobalRef for %p\n", __PRETTY_FUNCTION__, instance);
     333}
     334
     335JObjectWrapper::~JObjectWrapper()
     336{
     337    JS_LOG("deleting global ref %p\n", m_instance);
     338    m_env->DeleteGlobalRef(m_instance);
    333339}
    334340
  • trunk/WebCore/bridge/jni/jsc/JavaInstanceJSC.h

    r53412 r53436  
    2121 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    2222 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
     23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2424 */
    2525
     
    4040class JavaClass;
    4141
    42 class JObjectWrapper
    43 {
     42class JObjectWrapper {
    4443friend class RefPtr<JObjectWrapper>;
    4544friend class JavaArray;
     
    4948
    5049public:
    51     jobject instance() const { return _instance; }
    52     void setInstance(jobject instance) { _instance = instance; }
     50    jobject instance() const { return m_instance; }
     51    void setInstance(jobject instance) { m_instance = instance; }
    5352
    5453protected:
    55     JObjectWrapper(jobject instance);   
     54    JObjectWrapper(jobject instance);
    5655    ~JObjectWrapper();
    57    
    58     void ref() { _refCount++; }
    59     void deref() 
    60     { 
    61         if (--_refCount == 0)
    62             delete this; 
     56
     57    void ref() { m_refCount++; }
     58    void deref()
     59    {
     60        if (!(--m_refCount))
     61            delete this;
    6362    }
    6463
    65     jobject _instance;
     64    jobject m_instance;
    6665
    6766private:
    68     JNIEnv *_env;
    69     unsigned int _refCount;
     67    JNIEnv* m_env;
     68    unsigned int m_refCount;
    7069};
    7170
    72 class JavaInstance : public Instance
    73 {
     71class JavaInstance : public Instance {
    7472public:
    75     static PassRefPtr<JavaInstance> create(jobject instance, PassRefPtr<RootObject> rootObject) 
     73    static PassRefPtr<JavaInstance> create(jobject instance, PassRefPtr<RootObject> rootObject)
    7674    {
    7775        return adoptRef(new JavaInstance(instance, rootObject));
    7876    }
    79    
     77
    8078    ~JavaInstance();
    81    
    82     virtual Class *getClass() const;
    83    
     79
     80    virtual Class* getClass() const;
     81
    8482    virtual JSValue valueOf(ExecState*) const;
    8583    virtual JSValue defaultValue(ExecState*, PreferredPrimitiveType) const;
     
    8785    virtual JSValue invokeMethod(ExecState* exec, const MethodList& method, const ArgList& args);
    8886
    89     jobject javaInstance() const { return _instance->_instance; }
    90    
     87    jobject javaInstance() const { return m_instance->m_instance; }
     88
    9189    JSValue stringValue(ExecState*) const;
    9290    JSValue numberValue(ExecState*) const;
     
    9896    virtual void virtualEnd();
    9997
    100     RefPtr<JObjectWrapper> _instance;
    101     mutable JavaClass *_class;
     98    RefPtr<JObjectWrapper> m_instance;
     99    mutable JavaClass* m_class;
    102100};
    103101
Note: See TracChangeset for help on using the changeset viewer.