Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

TIMOB-12651 Exploration and preparing for event extension.

  • Loading branch information...
commit fc8826575c2e24f6ff7f8fac7f36c0a0b856c801 1 parent e9a2ffd
@BlainHamon authored
View
4 android/runtime/v8/src/java/org/appcelerator/kroll/runtime/v8/V8Object.java
@@ -55,7 +55,7 @@ public boolean fireEvent(String type, Object data)
Log.w(TAG, "Runtime disposed, cannot fire event '" + type + "'");
return false;
}
- return nativeFireEvent(ptr, type, data);
+ return nativeFireEvent(ptr, type, data,false,false,0,null);
}
@Override
@@ -98,7 +98,7 @@ protected void finalize() throws Throwable
private static native boolean nativeRelease(long ptr);
private native void nativeSetProperty(long ptr, String name, Object value);
- private native boolean nativeFireEvent(long ptr, String event, Object data);
+ private native boolean nativeFireEvent(long ptr, String event, Object data, boolean bubble, boolean reportSuccess, int code, String errorMessage);
private native void nativeSetWindow(long ptr, Object windowProxyObject);
}
View
2  android/runtime/v8/src/native/JNIUtil.cpp
@@ -28,6 +28,7 @@ jclass JNIUtil::longClass = NULL;
jclass JNIUtil::floatClass = NULL;
jclass JNIUtil::doubleClass = NULL;
jclass JNIUtil::booleanClass = NULL;
+jclass JNIUtil::stringArrayClass = NULL;
jclass JNIUtil::objectArrayClass = NULL;
jclass JNIUtil::shortArrayClass = NULL;
jclass JNIUtil::intArrayClass = NULL;
@@ -276,6 +277,7 @@ void JNIUtil::initCache()
floatArrayClass = findClass("[F");
doubleArrayClass = findClass("[D");
booleanArrayClass = findClass("[Z");
+ stringArrayClass = findClass("[Ljava/lang/String;");
objectArrayClass = findClass("[Ljava/lang/Object;");
arrayListClass = findClass("java/util/ArrayList");
hashMapClass = findClass("java/util/HashMap");
View
1  android/runtime/v8/src/native/JNIUtil.h
@@ -48,6 +48,7 @@ class JNIUtil
static jclass floatClass;
static jclass doubleClass;
static jclass booleanClass;
+ static jclass stringArrayClass;
static jclass objectArrayClass;
static jclass shortArrayClass;
static jclass intArrayClass;
View
70 android/runtime/v8/src/native/TypeConverter.cpp
@@ -118,11 +118,10 @@ v8::Handle<v8::Value> TypeConverter::javaStringToJsString(jstring javaString)
return v8::Null();
}
- const jchar *nativeString = env->GetStringChars(javaString, NULL);
int nativeStringLength = env->GetStringLength(javaString);
-
+ const jchar *nativeString = env->GetStringCritical(javaString, NULL);
v8::Handle<v8::String> jsString = v8::String::New(nativeString, nativeStringLength);
- env->ReleaseStringChars(javaString, nativeString);
+ env->ReleaseStringCritical(javaString, nativeString);
return jsString;
}
@@ -577,6 +576,48 @@ jobject TypeConverter::jsValueToJavaError(v8::Local<v8::Value> jsValue, bool* is
}
return NULL;
}
+
+// converts java hashmap to js value and recursively converts sub objects if this
+// object is a container type. If javaObject is NULL, an empty object is created.
+v8::Handle<v8::Value> TypeConverter::javaHashMapToJsValue(JNIEnv *env, jobject javaObject)
+{
+ v8::Handle<v8::Object> jsObject = v8::Object::New();
+ if (!javaObject || !env) {
+ return jsObject;
+ }
+
+ jobject hashMapSet = env->CallObjectMethod(javaObject, JNIUtil::hashMapKeySetMethod);
+ jobjectArray hashMapKeys = (jobjectArray) env->CallObjectMethod(hashMapSet, JNIUtil::setToArrayMethod);
+ env->DeleteLocalRef(hashMapSet);
+
+ int hashMapKeysLength = env->GetArrayLength(hashMapKeys);
+ bool isStringHashMap = env->IsInstanceOf(hashMapKeys, JNIUtil::objectArrayClass);
+
+ for (int i = 0; i < hashMapKeysLength; i++) {
+ jobject javaPairKey = env->GetObjectArrayElement(hashMapKeys, i);
+ v8::Handle<v8::Value> jsPairKey;
+ if (isStringHashMap) {
+ jstring javaString = (jstring)javaPairKey;
+ int nativeStringLength = env->GetStringLength(javaString);
+ const jchar *nativeString = env->GetStringCritical(javaString, NULL);
+ jsPairKey = v8::String::New(nativeString, nativeStringLength);
+ env->ReleaseStringCritical(javaString, nativeString);
+ } else {
+ jsPairKey = TypeConverter::javaObjectToJsValue(javaPairKey);
+ }
+
+ jobject javaPairValue = env->CallObjectMethod(javaObject, JNIUtil::hashMapGetMethod, javaPairKey);
+ env->DeleteLocalRef(javaPairKey);
+
+ jsObject->Set(jsPairKey, TypeConverter::javaObjectToJsValue(javaPairValue));
+ env->DeleteLocalRef(javaPairValue);
+ }
+
+ env->DeleteLocalRef(hashMapKeys);
+
+ return jsObject;
+}
+
// converts java object to js value and recursively converts sub objects if this
// object is a container type
v8::Handle<v8::Value> TypeConverter::javaObjectToJsValue(jobject javaObject)
@@ -605,28 +646,7 @@ v8::Handle<v8::Value> TypeConverter::javaObjectToJsValue(jobject javaObject)
return TypeConverter::javaDateToJsDate(javaObject);
} else if (env->IsInstanceOf(javaObject, JNIUtil::hashMapClass)) {
- v8::Handle<v8::Object> jsObject = v8::Object::New();
-
- jobject hashMapSet = env->CallObjectMethod(javaObject, JNIUtil::hashMapKeySetMethod);
-
- jobjectArray hashMapKeys = (jobjectArray) env->CallObjectMethod(hashMapSet, JNIUtil::setToArrayMethod);
- env->DeleteLocalRef(hashMapSet);
- int hashMapKeysLength = env->GetArrayLength(hashMapKeys);
-
- for (int i = 0; i < hashMapKeysLength; i++) {
- jobject javaPairKey = env->GetObjectArrayElement(hashMapKeys, i);
- v8::Handle<v8::Value> jsPairKey = TypeConverter::javaObjectToJsValue(javaPairKey);
-
- jobject javaPairValue = env->CallObjectMethod(javaObject, JNIUtil::hashMapGetMethod, javaPairKey);
- env->DeleteLocalRef(javaPairKey);
-
- jsObject->Set(jsPairKey, TypeConverter::javaObjectToJsValue(javaPairValue));
- env->DeleteLocalRef(javaPairValue);
- }
-
- env->DeleteLocalRef(hashMapKeys);
-
- return jsObject;
+ return TypeConverter::javaHashMapToJsValue(env, javaObject);
} else if (env->IsInstanceOf(javaObject, JNIUtil::krollProxyClass)) {
jobject krollObject = env->GetObjectField(javaObject, JNIUtil::krollProxyKrollObjectField);
if (krollObject) {
View
1  android/runtime/v8/src/native/TypeConverter.h
@@ -84,6 +84,7 @@ class TypeConverter
static jobject jsValueToJavaError(v8::Local<v8::Value> jsValue, bool *isNew);
static jobject jsValueToJavaObject(v8::Local<v8::Value> jsValue, bool *isNew);
+ static v8::Handle<v8::Value> javaHashMapToJsValue(JNIEnv *env, jobject javaObject);
static v8::Handle<v8::Value> javaObjectToJsValue(jobject javaObject);
// Convert a JS object's indexed properties to a Java object array.
View
4 android/runtime/v8/src/native/V8Object.cpp
@@ -62,7 +62,7 @@ Java_org_appcelerator_kroll_runtime_v8_V8Object_nativeSetProperty
JNIEXPORT jboolean JNICALL
Java_org_appcelerator_kroll_runtime_v8_V8Object_nativeFireEvent
- (JNIEnv *env, jobject jEmitter, jlong ptr, jstring event, jobject data)
+ (JNIEnv *env, jobject jEmitter, jlong ptr, jstring event, jobject data, jboolean bubble, jboolean reportSuccess, jint code, jstring errorMessage)
{
ENTER_V8(V8Runtime::globalContext);
JNIScope jniScope(env);
@@ -88,7 +88,7 @@ Java_org_appcelerator_kroll_runtime_v8_V8Object_nativeFireEvent
Handle<Function> fireEvent = Handle<Function>::Cast(fireEventValue->ToObject());
- Handle<Value> jsData = TypeConverter::javaObjectToJsValue(data);
+ Handle<Value> jsData = TypeConverter::javaHashMapToJsValue(env,data);
Handle<Value> result;
TryCatch tryCatch;

1 comment on commit fc88265

@jhaynie

OMG Blain is doing Android work. Blain FTW!

Please sign in to comment.
Something went wrong with that request. Please try again.