Skip to content

Commit 2080cab

Browse files
committed
support char arrays
1 parent 50d89a8 commit 2080cab

File tree

7 files changed

+24
-0
lines changed

7 files changed

+24
-0
lines changed
70 Bytes
Binary file not shown.

src/java.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,19 @@ v8::Handle<v8::Value> Java::createJVM(JavaVM** jvm, JNIEnv** env) {
470470
}
471471
}
472472

473+
else if(strcmp(className.c_str(), "char") == 0) {
474+
results = env->NewCharArray(arrayObj->Length());
475+
for(uint32_t i=0; i<arrayObj->Length(); i++) {
476+
v8::Local<v8::Value> item = arrayObj->Get(i);
477+
jobject val = v8ToJava(env, item);
478+
jclass stringClazz = env->FindClass("java/lang/String");
479+
jmethodID string_charAt = env->GetMethodID(stringClazz, "charAt", "(I)C");
480+
jchar itemValues[1];
481+
itemValues[0] = env->CallCharMethod(val, string_charAt, 0);
482+
env->SetCharArrayRegion((jcharArray)results, i, 1, itemValues);
483+
}
484+
}
485+
473486
else
474487
{
475488
jclass clazz = javaFindClass(env, className);

test/Test$SubClass.class

0 Bytes
Binary file not shown.

test/Test$SuperClass.class

0 Bytes
Binary file not shown.

test/Test.class

144 Bytes
Binary file not shown.

test/Test.java

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

27+
public static String staticMethodCharArrayToString(char[] a) { return new String(a); }
28+
2729
public static class SuperClass {
2830
public int getVal() { return 3; }
2931
}

test/java-callStaticMethod-test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,5 +127,14 @@ exports['Java - Call Static Method'] = nodeunit.testCase({
127127
test.ok(err.toString().match(/my exception/));
128128
}
129129
test.done();
130+
},
131+
132+
"char array": function(test) {
133+
var charArray = java.newArray("char", "hello world\n".split(''));
134+
java.callStaticMethod("Test", "staticMethodCharArrayToString", charArray, function(err, result) {
135+
test.ok(result);
136+
test.equal(result, "hello world\n");
137+
test.done();
138+
});
130139
}
131140
});

0 commit comments

Comments
 (0)