Skip to content

Commit e8fd74e

Browse files
committed
Add support to float[] array
1 parent 35edc9b commit e8fd74e

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

src/java.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -818,6 +818,20 @@ NAN_METHOD(Java::newArray) {
818818
}
819819
}
820820

821+
else if(strcmp(className.c_str(), "float") == 0) {
822+
results = env->NewFloatArray(arrayObj->Length());
823+
for(uint32_t i=0; i<arrayObj->Length(); i++) {
824+
v8::Local<v8::Value> item = arrayObj->Get(i);
825+
jobject val = v8ToJava(env, item);
826+
jclass floatClazz = env->FindClass("java/lang/Float");
827+
jmethodID float_floatValue = env->GetMethodID(floatClazz, "floatValue", "()F");
828+
jfloat floatValues[1];
829+
floatValues[0] = env->CallFloatMethod(val, float_floatValue);
830+
checkJavaException(env);
831+
env->SetFloatArrayRegion((jfloatArray)results, i, 1, floatValues);
832+
}
833+
}
834+
821835
else if(strcmp(className.c_str(), "boolean") == 0) {
822836
results = env->NewBooleanArray(arrayObj->Length());
823837
for(uint32_t i=0; i<arrayObj->Length(); i++) {

0 commit comments

Comments
 (0)