Skip to content

Commit 4fc438c

Browse files
committed
test doubles
1 parent bafec88 commit 4fc438c

7 files changed

Lines changed: 41 additions & 2 deletions

File tree

src/utils.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ jvalueType javaGetType(JNIEnv *env, jclass type) {
109109
//printf("javaGetType: %s\n", typeStr);
110110
if(strcmp(typeStr, "int") == 0) {
111111
return TYPE_INT;
112+
} else if(strcmp(typeStr, "double") == 0) {
113+
return TYPE_DOUBLE;
112114
} else if(strcmp(typeStr, "long") == 0) {
113115
return TYPE_LONG;
114116
} else if(strcmp(typeStr, "void") == 0) {
@@ -171,13 +173,20 @@ jobject v8ToJava(JNIEnv* env, v8::Local<v8::Value> arg) {
171173
return env->NewStringUTF(*val);
172174
}
173175

174-
if(arg->IsInt32()) {
176+
if(arg->IsInt32() || arg->IsUint32()) {
175177
jint val = arg->ToInt32()->Value();
176178
jclass clazz = env->FindClass("java/lang/Integer");
177179
jmethodID constructor = env->GetMethodID(clazz, "<init>", "(I)V");
178180
return env->NewObject(clazz, constructor, val);
179181
}
180182

183+
if(arg->IsNumber()) {
184+
jdouble val = arg->ToNumber()->Value();
185+
jclass clazz = env->FindClass("java/lang/Double");
186+
jmethodID constructor = env->GetMethodID(clazz, "<init>", "(D)V");
187+
return env->NewObject(clazz, constructor, val);
188+
}
189+
181190
if(arg->IsBoolean()) {
182191
jboolean val = arg->ToBoolean()->Value();
183192
jclass clazz = env->FindClass("java/lang/Boolean");
@@ -310,6 +319,13 @@ v8::Handle<v8::Value> javaToV8(Java* java, JNIEnv* env, jvalueType resultType, j
310319
jint result = env->CallIntMethod(obj, integer_intValue);
311320
return scope.Close(v8::Integer::New(result));
312321
}
322+
case TYPE_DOUBLE:
323+
{
324+
jclass doubleClazz = env->FindClass("java/lang/Double");
325+
jmethodID double_doubleValue = env->GetMethodID(doubleClazz, "doubleValue", "()D");
326+
jdouble result = env->CallDoubleMethod(obj, double_doubleValue);
327+
return scope.Close(v8::Number::New(result));
328+
}
313329
case TYPE_STRING:
314330
return scope.Close(v8::String::New(javaObjectToString(env, obj).c_str()));
315331
case TYPE_OBJECT:

src/utils.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ typedef enum _jvalueType {
2424
TYPE_BOOLEAN = 0x006,
2525
TYPE_ARRAY_BOOLEAN = 0x106,
2626
TYPE_BYTE = 0x007,
27-
TYPE_ARRAY_BYTE = 0x107
27+
TYPE_ARRAY_BYTE = 0x107,
28+
TYPE_DOUBLE = 0x008,
29+
TYPE_ARRAY_DOUBLE = 0x108,
2830
} jvalueType;
2931

3032
#define VALUE_TYPE_ARRAY 0x100

test/Test$SubClass.class

0 Bytes
Binary file not shown.

test/Test$SuperClass.class

0 Bytes
Binary file not shown.

test/Test.class

61 Bytes
Binary file not shown.

test/Test.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ public class Test {
33
private int i;
44
public int nonstaticInt = 42;
55
public static int staticFieldInt = 42;
6+
public static double staticFieldDouble = 42.5;
67
public static Test[] staticArrayObjects = null;
78

89
public Test() {}

test/java-staticField-test.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,24 @@ exports['Java - Static Field'] = nodeunit.testCase({
1717
test.equal(val, 112);
1818
test.done();
1919
},
20+
21+
"getStaticFieldValue double": function(test) {
22+
var val = java.getStaticFieldValue("Test", "staticFieldDouble");
23+
test.equal(val, 42.5);
24+
test.done();
25+
},
26+
27+
"setStaticFieldValue double": function(test) {
28+
java.setStaticFieldValue("Test", "staticFieldDouble", 112.12);
29+
var val = java.getStaticFieldValue("Test", "staticFieldDouble");
30+
test.equal(val, 112.12);
31+
test.done();
32+
},
33+
34+
"setStaticFieldValue double (set int)": function(test) {
35+
java.setStaticFieldValue("Test", "staticFieldDouble", 112);
36+
var val = java.getStaticFieldValue("Test", "staticFieldDouble");
37+
test.equal(val, 112);
38+
test.done();
39+
},
2040
});

0 commit comments

Comments
 (0)