Changeset 80103 in webkit


Ignore:
Timestamp:
Mar 2, 2011 1:49:39 AM (13 years ago)
Author:
steveblock@google.com
Message:

2011-03-02 Steve Block <steveblock@google.com>

Reviewed by Jeremy Orlow.

JObjectWrapper should be moved to its own file
https://bugs.webkit.org/show_bug.cgi?id=55384

No new tests, refactoring only.

  • Android.v8bindings.mk:
  • WebCore.gypi:
  • bridge/jni/v8/JNIBridgeV8.cpp: (JavaField::JavaField):
  • bridge/jni/v8/JNIBridgeV8.h:
  • bridge/jni/v8/JavaInstanceV8.cpp: (JavaInstance::JavaInstance):
  • bridge/jni/v8/JavaInstanceV8.h:
  • bridge/jni/v8/JobjectWrapper.cpp: Copied from Source/WebCore/bridge/jni/v8/JNIBridgeV8.h. (JobjectWrapper::JobjectWrapper): (JobjectWrapper::~JobjectWrapper):
  • bridge/jni/v8/JobjectWrapper.h: Copied from Source/WebCore/bridge/jni/v8/JNIBridgeV8.h. (JSC::Bindings::JobjectWrapper::instance): (JSC::Bindings::JobjectWrapper::setInstance): (JSC::Bindings::JobjectWrapper::ref): (JSC::Bindings::JobjectWrapper::deref):
Location:
trunk/Source/WebCore
Files:
7 edited
2 copied

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/Android.v8bindings.mk

    r75313 r80103  
    179179        bridge/jni/v8/JavaClassV8.cpp \
    180180        bridge/jni/v8/JavaInstanceV8.cpp \
    181         bridge/jni/v8/JavaNPObject.cpp
     181        bridge/jni/v8/JavaNPObject.cpp \
     182        bridge/jni/v8/JobjectWrapper.cpp
  • trunk/Source/WebCore/ChangeLog

    r80102 r80103  
     12011-03-02  Steve Block  <steveblock@google.com>
     2
     3        Reviewed by Jeremy Orlow.
     4
     5        JObjectWrapper should be moved to its own file
     6        https://bugs.webkit.org/show_bug.cgi?id=55384
     7
     8        No new tests, refactoring only.
     9
     10        * Android.v8bindings.mk:
     11        * WebCore.gypi:
     12        * bridge/jni/v8/JNIBridgeV8.cpp:
     13        (JavaField::JavaField):
     14        * bridge/jni/v8/JNIBridgeV8.h:
     15        * bridge/jni/v8/JavaInstanceV8.cpp:
     16        (JavaInstance::JavaInstance):
     17        * bridge/jni/v8/JavaInstanceV8.h:
     18        * bridge/jni/v8/JobjectWrapper.cpp: Copied from Source/WebCore/bridge/jni/v8/JNIBridgeV8.h.
     19        (JobjectWrapper::JobjectWrapper):
     20        (JobjectWrapper::~JobjectWrapper):
     21        * bridge/jni/v8/JobjectWrapper.h: Copied from Source/WebCore/bridge/jni/v8/JNIBridgeV8.h.
     22        (JSC::Bindings::JobjectWrapper::instance):
     23        (JSC::Bindings::JobjectWrapper::setInstance):
     24        (JSC::Bindings::JobjectWrapper::ref):
     25        (JSC::Bindings::JobjectWrapper::deref):
     26
    1272011-02-25  Andrey Kosyakov  <caseq@chromium.org>
    228
  • trunk/Source/WebCore/WebCore.gypi

    r80102 r80103  
    10221022            'bridge/jni/v8/JavaNPObjectV8.h',
    10231023            'bridge/jni/v8/JavaStringV8.h',
     1024            'bridge/jni/v8/JobjectWrapper.cpp',
     1025            'bridge/jni/v8/JobjectWrapper.h',
    10241026            'css/CSSBorderImageValue.cpp',
    10251027            'css/CSSBorderImageValue.h',
  • trunk/Source/WebCore/bridge/jni/v8/JNIBridgeV8.cpp

    r79998 r80103  
    4343    m_name = JavaString(env, fieldName);
    4444
    45     m_field = new JObjectWrapper(aField);
     45    m_field = new JobjectWrapper(aField);
    4646}
    4747
  • trunk/Source/WebCore/bridge/jni/v8/JNIBridgeV8.h

    r79998 r80103  
    3030
    3131#include "JNIBridge.h" // For JavaString
    32 #include "JavaInstanceV8.h" // For JObjectWrapper
     32#include "JobjectWrapper.h"
    3333
    3434namespace JSC {
     
    4949    JavaString m_type;
    5050    JNIType m_JNIType;
    51     RefPtr<JObjectWrapper> m_field;
     51    RefPtr<JobjectWrapper> m_field;
    5252};
    5353
  • trunk/Source/WebCore/bridge/jni/v8/JavaInstanceV8.cpp

    r79998 r80103  
    3434#include "JavaClassV8.h"
    3535
    36 #include <assert.h>
    37 
    3836using namespace JSC::Bindings;
    3937
    4038JavaInstance::JavaInstance(jobject instance)
    4139{
    42     m_instance = new JObjectWrapper(instance);
     40    m_instance = new JobjectWrapper(instance);
    4341    m_class = 0;
    4442}
     
    155153}
    156154
    157 JObjectWrapper::JObjectWrapper(jobject instance)
    158     : m_refCount(0)
    159 {
    160     assert(instance);
    161 
    162     // Cache the JNIEnv used to get the global ref for this java instanace.
    163     // It'll be used to delete the reference.
    164     m_env = getJNIEnv();
    165 
    166     m_instance = m_env->NewGlobalRef(instance);
    167 
    168     if (!m_instance)
    169         fprintf(stderr, "%s:  could not get GlobalRef for %p\n", __PRETTY_FUNCTION__, instance);
    170 }
    171 
    172 JObjectWrapper::~JObjectWrapper()
    173 {
    174     m_env->DeleteGlobalRef(m_instance);
    175 }
    176 
    177155#endif // ENABLE(JAVA_BRIDGE)
  • trunk/Source/WebCore/bridge/jni/v8/JavaInstanceV8.h

    r79998 r80103  
    3131
    3232#include "JNIUtility.h"
     33#include "JobjectWrapper.h"
    3334#include "npruntime.h"
    3435
     
    4344
    4445class JavaClass;
    45 
    46 class JObjectWrapper {
    47 friend class RefPtr<JObjectWrapper>;
    48 friend class JavaField;
    49 friend class JavaInstance;
    50 
    51 public:
    52     jobject instance() const { return m_instance; }
    53     void setInstance(jobject instance) { m_instance = instance; }
    54 
    55     void ref() { m_refCount++; }
    56     void deref()
    57     {
    58         if (!(--m_refCount))
    59             delete this;
    60     }
    61 
    62 protected:
    63     JObjectWrapper(jobject);
    64     ~JObjectWrapper();
    65 
    66     jobject m_instance;
    67 
    68 private:
    69     JNIEnv* m_env;
    70     unsigned int m_refCount;
    71 };
    7246
    7347class JavaInstance : public RefCounted<JavaInstance> {
     
    8963
    9064protected:
    91     RefPtr<JObjectWrapper> m_instance;
     65    RefPtr<JobjectWrapper> m_instance;
    9266    mutable JavaClass* m_class;
    9367
  • trunk/Source/WebCore/bridge/jni/v8/JobjectWrapper.cpp

    r80102 r80103  
    11/*
    2  * Copyright 2010, The Android Open Source Project
     2 * Copyright 2011, The Android Open Source Project
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2424 */
    2525
    26 #ifndef JNIBridgeV8_h
    27 #define JNIBridgeV8_h
     26#include "config.h"
     27#include "JobjectWrapper.h"
    2828
    2929#if ENABLE(JAVA_BRIDGE)
    3030
    31 #include "JNIBridge.h" // For JavaString
    32 #include "JavaInstanceV8.h" // For JObjectWrapper
     31#include <assert.h>
    3332
    34 namespace JSC {
     33using namespace JSC::Bindings;
    3534
    36 namespace Bindings {
     35JobjectWrapper::JobjectWrapper(jobject instance)
     36    : m_refCount(0)
     37{
     38    assert(instance);
    3739
    38 class JavaField {
    39 public:
    40     JavaField(JNIEnv*, jobject aField);
     40    // Cache the JNIEnv used to get the global ref for this java instanace.
     41    // It'll be used to delete the reference.
     42    m_env = getJNIEnv();
    4143
    42     const JavaString& name() const { return m_name; }
    43     const char* type() const { return m_type.utf8(); }
     44    m_instance = m_env->NewGlobalRef(instance);
    4445
    45     JNIType getJNIType() const { return m_JNIType; }
     46    if (!m_instance)
     47        fprintf(stderr, "%s:  could not get GlobalRef for %p\n", __PRETTY_FUNCTION__, instance);
     48}
    4649
    47 private:
    48     JavaString m_name;
    49     JavaString m_type;
    50     JNIType m_JNIType;
    51     RefPtr<JObjectWrapper> m_field;
    52 };
    53 
    54 } // namespace Bindings
    55 
    56 } // namespace JSC
     50JobjectWrapper::~JobjectWrapper()
     51{
     52    m_env->DeleteGlobalRef(m_instance);
     53}
    5754
    5855#endif // ENABLE(JAVA_BRIDGE)
    59 
    60 #endif // JNIBridgeV8_h
  • trunk/Source/WebCore/bridge/jni/v8/JobjectWrapper.h

    r80102 r80103  
    11/*
    2  * Copyright 2010, The Android Open Source Project
     2 * Copyright 2011, The Android Open Source Project
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2424 */
    2525
    26 #ifndef JNIBridgeV8_h
    27 #define JNIBridgeV8_h
     26#ifndef JobjectWrapper_h
     27#define JobjectWrapper_h
    2828
    2929#if ENABLE(JAVA_BRIDGE)
    3030
    31 #include "JNIBridge.h" // For JavaString
    32 #include "JavaInstanceV8.h" // For JObjectWrapper
     31#include "JNIUtility.h"
    3332
    3433namespace JSC {
     
    3635namespace Bindings {
    3736
    38 class JavaField {
     37class JobjectWrapper {
     38friend class JavaField;
     39friend class JavaInstance;
     40
    3941public:
    40     JavaField(JNIEnv*, jobject aField);
     42    jobject instance() const { return m_instance; }
     43    void setInstance(jobject instance) { m_instance = instance; }
    4144
    42     const JavaString& name() const { return m_name; }
    43     const char* type() const { return m_type.utf8(); }
     45    void ref() { m_refCount++; }
     46    void deref()
     47    {
     48        if (!(--m_refCount))
     49            delete this;
     50    }
    4451
    45     JNIType getJNIType() const { return m_JNIType; }
     52protected:
     53    JobjectWrapper(jobject);
     54    ~JobjectWrapper();
     55
     56    jobject m_instance;
    4657
    4758private:
    48     JavaString m_name;
    49     JavaString m_type;
    50     JNIType m_JNIType;
    51     RefPtr<JObjectWrapper> m_field;
     59    JNIEnv* m_env;
     60    unsigned int m_refCount;
    5261};
    5362
     
    5766
    5867#endif // ENABLE(JAVA_BRIDGE)
    59 
    60 #endif // JNIBridgeV8_h
     68#endif // JobjectWrapper_h
Note: See TracChangeset for help on using the changeset viewer.