Changeset 53436 in webkit
- Timestamp:
- Jan 18, 2010 3:49:35 PM (14 years ago)
- Location:
- trunk/WebCore
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebCore/ChangeLog
r53434 r53436 1 2010-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 1 19 2010-01-18 Chris Marrin <cmarrin@apple.com> 2 20 -
trunk/WebCore/bridge/jni/jni_runtime.cpp
r53193 r53436 85 85 { 86 86 jobject jinstance = instance->javaInstance(); 87 jobject fieldJInstance = _field-> _instance;87 jobject fieldJInstance = _field->m_instance; 88 88 JNIEnv *env = getJNIEnv(); 89 89 jvalue result; … … 169 169 { 170 170 jobject jinstance = instance->javaInstance(); 171 jobject fieldJInstance = _field-> _instance;171 jobject fieldJInstance = _field->m_instance; 172 172 JNIEnv *env = getJNIEnv(); 173 173 … … 378 378 // Java array are fixed length, so we can cache length. 379 379 JNIEnv *env = getJNIEnv(); 380 _length = env->GetArrayLength((jarray)_array-> _instance);380 _length = env->GetArrayLength((jarray)_array->m_instance); 381 381 _type = strdup(type); 382 382 _rootObject = rootObject; -
trunk/WebCore/bridge/jni/jni_runtime.h
r53412 r53436 173 173 virtual unsigned int getLength() const; 174 174 175 jobject javaArray() const { return _array-> _instance; }175 jobject javaArray() const { return _array->m_instance; } 176 176 177 177 static JSValue convertJObjectToArray (ExecState* exec, jobject anObject, const char* type, PassRefPtr<RootObject>); -
trunk/WebCore/bridge/jni/jsc/JavaInstanceJSC.cpp
r53412 r53436 1 1 /* 2 * Copyright (C) 2003, 2008 Apple Inc. All rights reserved.2 * Copyright (C) 2003, 2008, 2010 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 21 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 22 * (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. 24 24 */ 25 25 … … 47 47 #else 48 48 #define JS_LOG(formatAndArgs...) { \ 49 fprintf 49 fprintf(stderr, "%s:%d -- %s: ", __FILE__, __LINE__, __FUNCTION__); \ 50 50 fprintf(stderr, formatAndArgs); \ 51 51 } 52 52 #endif 53 53 54 54 using namespace JSC::Bindings; 55 55 using namespace JSC; 56 56 57 JavaInstance::JavaInstance 57 JavaInstance::JavaInstance(jobject instance, PassRefPtr<RootObject> rootObject) 58 58 : Instance(rootObject) 59 59 { 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 64 JavaInstance::~JavaInstance() 65 { 66 delete m_class; 67 67 } 68 68 … … 71 71 void JavaInstance::virtualBegin() 72 72 { 73 getJNIEnv()->PushLocalFrame 73 getJNIEnv()->PushLocalFrame(NUM_LOCAL_REFS); 74 74 } 75 75 76 76 void JavaInstance::virtualEnd() 77 77 { 78 getJNIEnv()->PopLocalFrame (NULL);79 } 80 81 Class *JavaInstance::getClass() const82 { 83 if ( _class == 0)84 _class = new JavaClass (_instance->_instance);85 return _class;78 getJNIEnv()->PopLocalFrame(0); 79 } 80 81 Class* JavaInstance::getClass() const 82 { 83 if (!m_class) 84 m_class = new JavaClass (m_instance->m_instance); 85 return m_class; 86 86 } 87 87 … … 89 89 { 90 90 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 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)); 96 96 releaseUCharactersForJStringInEnv(env, stringValue, c); 97 97 return jsString(exec, u); … … 100 100 JSValue JavaInstance::numberValue(ExecState* exec) const 101 101 { 102 jdouble doubleValue = callJNIMethod<jdouble>( _instance->_instance, "doubleValue", "()D");102 jdouble doubleValue = callJNIMethod<jdouble>(m_instance->m_instance, "doubleValue", "()D"); 103 103 return jsNumber(exec, doubleValue); 104 104 } … … 106 106 JSValue JavaInstance::booleanValue() const 107 107 { 108 jboolean booleanValue = callJNIMethod<jboolean>( _instance->_instance, "booleanValue", "()Z");108 jboolean booleanValue = callJNIMethod<jboolean>(m_instance->m_instance, "booleanValue", "()Z"); 109 109 return jsBoolean(booleanValue); 110 110 } 111 111 112 JSValue JavaInstance::invokeMethod (ExecState *exec, const MethodList &methodList, const ArgList &args)112 JSValue JavaInstance::invokeMethod(ExecState* exec, const MethodList& methodList, const ArgList &args) 113 113 { 114 114 int i, count = args.size(); 115 jvalue *jArgs;115 jvalue* jArgs; 116 116 JSValue resultValue; 117 Method *method = 0;117 Method* method = 0; 118 118 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 121 121 // 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 123 123 // get a bit more sophisticated and attempt to does some 124 124 // type checking as we as checking the number of parameters. 125 Method *aMethod;125 Method* aMethod; 126 126 for (size_t methodIndex = 0; methodIndex < numMethods; methodIndex++) { 127 127 aMethod = methodList[methodIndex]; … … 131 131 } 132 132 } 133 if ( method == 0) {134 JS_LOG 133 if (!method) { 134 JS_LOG("unable to find an appropiate method\n"); 135 135 return jsUndefined(); 136 136 } 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)); 144 143 else 145 144 jArgs = 0; 146 145 147 146 for (i = 0; i < count; i++) { 148 147 JavaParameter* aParameter = jMethod->parameterAt(i); … … 150 149 JS_LOG("arg[%d] = %s\n", i, args.at(i).toString(exec).ascii()); 151 150 } 152 151 153 152 jvalue result; 154 153 … … 162 161 bool handled = false; 163 162 if (rootObject->nativeHandle()) { 164 jobject obj = _instance->_instance;163 jobject obj = m_instance->m_instance; 165 164 JSValue exceptionDescription; 166 const char *callingURL = 0; 165 const char *callingURL = 0; // FIXME, need to propagate calling URL to Java 167 166 handled = dispatchJNICall(exec, rootObject->nativeHandle(), obj, jMethod->isStatic(), jMethod->JNIReturnType(), jMethod->methodID(obj), jArgs, result, callingURL, exceptionDescription); 168 167 if (exceptionDescription) { 169 168 throwError(exec, GeneralError, exceptionDescription.toString(exec)); 170 free 169 free(jArgs); 171 170 return jsUndefined(); 172 171 } 173 172 } 174 173 175 174 // The following code can be conditionally removed once we have a Tiger update that 176 175 // 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 { 219 219 resultValue = jsUndefined(); 220 220 } 221 221 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] == '[') 227 228 resultValue = JavaArray::convertJObjectToArray(exec, result.l, arrayType, rootObject); 228 } 229 else { 229 else 230 230 resultValue = JavaInstance::create(result.l, rootObject)->createRuntimeObject(exec); 231 } 232 } 233 else { 231 } else 234 232 resultValue = jsUndefined(); 235 236 }237 break; 238 239 case boolean_type:{233 } 234 break; 235 236 case boolean_type: 237 { 240 238 resultValue = jsBoolean(result.z); 241 239 } 242 240 break; 243 244 case byte_type: { 241 242 case byte_type: 243 { 245 244 resultValue = jsNumber(exec, result.b); 246 245 } 247 246 break; 248 249 case char_type: { 247 248 case char_type: 249 { 250 250 resultValue = jsNumber(exec, result.c); 251 251 } 252 252 break; 253 254 case short_type: { 253 254 case short_type: 255 { 255 256 resultValue = jsNumber(exec, result.s); 256 257 } 257 258 break; 258 259 case int_type: { 259 260 case int_type: 261 { 260 262 resultValue = jsNumber(exec, result.i); 261 263 } 262 264 break; 263 264 case long_type: { 265 266 case long_type: 267 { 265 268 resultValue = jsNumber(exec, result.j); 266 269 } 267 270 break; 268 269 case float_type: { 271 272 case float_type: 273 { 270 274 resultValue = jsNumber(exec, result.f); 271 275 } 272 276 break; 273 274 case double_type: { 277 278 case double_type: 279 { 275 280 resultValue = jsNumber(exec, result.d); 276 281 } 277 282 break; 278 283 279 case invalid_type: 280 default: { 284 case invalid_type: 285 default: 286 { 281 287 resultValue = jsUndefined(); 282 288 } … … 284 290 } 285 291 286 free 292 free(jArgs); 287 293 288 294 return resultValue; … … 295 301 if (hint == PreferNumber) 296 302 return numberValue(exec); 297 JavaClass *aClass = static_cast<JavaClass*>(getClass());303 JavaClass* aClass = static_cast<JavaClass*>(getClass()); 298 304 if (aClass->isStringClass()) 299 305 return stringValue(exec); … … 305 311 } 306 312 307 JSValue JavaInstance::valueOf(ExecState* exec) const 313 JSValue JavaInstance::valueOf(ExecState* exec) const 308 314 { 309 315 return stringValue(exec); … … 311 317 312 318 JObjectWrapper::JObjectWrapper(jobject instance) 313 :_refCount(0)314 { 315 assert (instance != 0);319 : m_refCount(0) 320 { 321 assert(instance); 316 322 317 323 // Cache the JNIEnv used to get the global ref for this java instanace. 318 324 // 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 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 335 JObjectWrapper::~JObjectWrapper() 336 { 337 JS_LOG("deleting global ref %p\n", m_instance); 338 m_env->DeleteGlobalRef(m_instance); 333 339 } 334 340 -
trunk/WebCore/bridge/jni/jsc/JavaInstanceJSC.h
r53412 r53436 21 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 22 * (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. 24 24 */ 25 25 … … 40 40 class JavaClass; 41 41 42 class JObjectWrapper 43 { 42 class JObjectWrapper { 44 43 friend class RefPtr<JObjectWrapper>; 45 44 friend class JavaArray; … … 49 48 50 49 public: 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; } 53 52 54 53 protected: 55 JObjectWrapper(jobject instance); 54 JObjectWrapper(jobject instance); 56 55 ~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; 63 62 } 64 63 65 jobject _instance;64 jobject m_instance; 66 65 67 66 private: 68 JNIEnv *_env;69 unsigned int _refCount;67 JNIEnv* m_env; 68 unsigned int m_refCount; 70 69 }; 71 70 72 class JavaInstance : public Instance 73 { 71 class JavaInstance : public Instance { 74 72 public: 75 static PassRefPtr<JavaInstance> create(jobject instance, PassRefPtr<RootObject> rootObject) 73 static PassRefPtr<JavaInstance> create(jobject instance, PassRefPtr<RootObject> rootObject) 76 74 { 77 75 return adoptRef(new JavaInstance(instance, rootObject)); 78 76 } 79 77 80 78 ~JavaInstance(); 81 82 virtual Class *getClass() const;83 79 80 virtual Class* getClass() const; 81 84 82 virtual JSValue valueOf(ExecState*) const; 85 83 virtual JSValue defaultValue(ExecState*, PreferredPrimitiveType) const; … … 87 85 virtual JSValue invokeMethod(ExecState* exec, const MethodList& method, const ArgList& args); 88 86 89 jobject javaInstance() const { return _instance->_instance; }90 87 jobject javaInstance() const { return m_instance->m_instance; } 88 91 89 JSValue stringValue(ExecState*) const; 92 90 JSValue numberValue(ExecState*) const; … … 98 96 virtual void virtualEnd(); 99 97 100 RefPtr<JObjectWrapper> _instance;101 mutable JavaClass *_class;98 RefPtr<JObjectWrapper> m_instance; 99 mutable JavaClass* m_class; 102 100 }; 103 101
Note: See TracChangeset
for help on using the changeset viewer.