Skip to content

Commit 1da7c00

Browse files
committed
remove auto conversion of Long data types
1 parent f1f28b1 commit 1da7c00

6 files changed

Lines changed: 41 additions & 10 deletions

File tree

src/utils.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -429,13 +429,14 @@ v8::Handle<v8::Value> javaToV8(Java* java, JNIEnv* env, jobject obj) {
429429
jbyte result = env->CallByteMethod(obj, byte_byteValue);
430430
return scope.Close(v8::Number::New(result));
431431
}
432-
case TYPE_LONG:
433-
{
434-
jclass longClazz = env->FindClass("java/lang/Long");
435-
jmethodID long_longValue = env->GetMethodID(longClazz, "longValue", "()J");
436-
jlong result = env->CallLongMethod(obj, long_longValue);
437-
return scope.Close(v8::Number::New(result));
438-
}
432+
// Removed to support long return types and long parameters.
433+
// case TYPE_LONG:
434+
// {
435+
// jclass longClazz = env->FindClass("java/lang/Long");
436+
// jmethodID long_longValue = env->GetMethodID(longClazz, "longValue", "()J");
437+
// jlong result = env->CallLongMethod(obj, long_longValue);
438+
// return scope.Close(v8::Number::New(result));
439+
// }
439440
case TYPE_INT:
440441
{
441442
jclass integerClazz = env->FindClass("java/lang/Integer");

test/Test$SubClass.class

0 Bytes
Binary file not shown.

test/Test$SuperClass.class

0 Bytes
Binary file not shown.

test/Test.class

232 Bytes
Binary file not shown.

test/Test.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ public Test() {}
2525
public static int staticMethodOverload(SuperClass a) { return a.getVal(); }
2626

2727
public static String staticMethodCharArrayToString(char[] a) { return new String(a); }
28+
public static String staticMethodLongToString(java.lang.Long l) { return l.toString(); }
29+
public static long staticMethodReturnLong() { return java.lang.Long.MAX_VALUE; }
2830

2931
public static class SuperClass {
3032
public int getVal() { return 3; }

test/java-callStaticMethod-test.js

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
var java = require("../testHelpers").java;
32

43
var nodeunit = require("nodeunit");
@@ -22,6 +21,9 @@ exports['Java - Call Static Method'] = nodeunit.testCase({
2221

2322
"callStaticMethod with args": function(test) {
2423
java.callStaticMethod("Test", "staticMethod", 42, function(err, result) {
24+
if (err) {
25+
return test.done(err);
26+
}
2527
test.ok(result);
2628
test.equal(result, 43);
2729
test.done();
@@ -111,7 +113,7 @@ exports['Java - Call Static Method'] = nodeunit.testCase({
111113
try {
112114
java.callStaticMethodSync("Test", "staticMethodThrows", ex);
113115
test.fail("should throw");
114-
} catch(err) {
116+
} catch (err) {
115117
test.ok(err.toString().match(/my exception/));
116118
}
117119
test.done();
@@ -123,7 +125,7 @@ exports['Java - Call Static Method'] = nodeunit.testCase({
123125
try {
124126
myTest.methodThrowsSync(ex);
125127
test.fail("should throw");
126-
} catch(err) {
128+
} catch (err) {
127129
test.ok(err.toString().match(/my exception/));
128130
}
129131
test.done();
@@ -132,9 +134,35 @@ exports['Java - Call Static Method'] = nodeunit.testCase({
132134
"char array": function(test) {
133135
var charArray = java.newArray("char", "hello world\n".split(''));
134136
java.callStaticMethod("Test", "staticMethodCharArrayToString", charArray, function(err, result) {
137+
if (err) {
138+
return test.done(err);
139+
}
135140
test.ok(result);
136141
test.equal(result, "hello world\n");
137142
test.done();
138143
});
144+
},
145+
146+
"java.lang.Long calls (java Long)": function(test) {
147+
var javaLong = java.newInstanceSync("java.lang.Long", 5);
148+
java.callStaticMethod("Test", "staticMethodLongToString", javaLong, function(err, result) {
149+
if (err) {
150+
return test.done(err);
151+
}
152+
test.ok(result);
153+
test.equal(result, "5");
154+
test.done();
155+
});
156+
},
157+
158+
"Call method that returns a long": function(test) {
159+
java.callStaticMethod("Test", "staticMethodReturnLong", function(err, result) {
160+
if (err) {
161+
return test.done(err);
162+
}
163+
test.ok(result);
164+
test.equal(result.toStringSync(), "9223372036854775807");
165+
test.done();
166+
});
139167
}
140168
});

0 commit comments

Comments
 (0)