Skip to content

Commit

Permalink
support char arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
joeferner committed Jan 28, 2013
1 parent 50d89a8 commit 2080cab
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 0 deletions.
Binary file modified src-java/node/NodeDynamicProxyClass.class
Binary file not shown.
13 changes: 13 additions & 0 deletions src/java.cpp
Expand Up @@ -470,6 +470,19 @@ v8::Handle<v8::Value> Java::createJVM(JavaVM** jvm, JNIEnv** env) {
}
}

else if(strcmp(className.c_str(), "char") == 0) {
results = env->NewCharArray(arrayObj->Length());
for(uint32_t i=0; i<arrayObj->Length(); i++) {
v8::Local<v8::Value> item = arrayObj->Get(i);
jobject val = v8ToJava(env, item);
jclass stringClazz = env->FindClass("java/lang/String");
jmethodID string_charAt = env->GetMethodID(stringClazz, "charAt", "(I)C");
jchar itemValues[1];
itemValues[0] = env->CallCharMethod(val, string_charAt, 0);
env->SetCharArrayRegion((jcharArray)results, i, 1, itemValues);
}
}

else
{
jclass clazz = javaFindClass(env, className);
Expand Down
Binary file modified test/Test$SubClass.class
Binary file not shown.
Binary file modified test/Test$SuperClass.class
Binary file not shown.
Binary file modified test/Test.class
Binary file not shown.
2 changes: 2 additions & 0 deletions test/Test.java
Expand Up @@ -24,6 +24,8 @@ public Test() {}
public static int staticMethodOverload(int a) { return 2; }
public static int staticMethodOverload(SuperClass a) { return a.getVal(); }

public static String staticMethodCharArrayToString(char[] a) { return new String(a); }

public static class SuperClass {
public int getVal() { return 3; }
}
Expand Down
9 changes: 9 additions & 0 deletions test/java-callStaticMethod-test.js
Expand Up @@ -127,5 +127,14 @@ exports['Java - Call Static Method'] = nodeunit.testCase({
test.ok(err.toString().match(/my exception/));
}
test.done();
},

"char array": function(test) {
var charArray = java.newArray("char", "hello world\n".split(''));
java.callStaticMethod("Test", "staticMethodCharArrayToString", charArray, function(err, result) {
test.ok(result);
test.equal(result, "hello world\n");
test.done();
});
}
});

0 comments on commit 2080cab

Please sign in to comment.