Comparing version 0.4.7 to 5.0.0
@@ -10,3 +10,3 @@ { | ||
], | ||
"version": "0.4.7", | ||
"version": "5.0.0", | ||
"engines": { | ||
@@ -31,11 +31,11 @@ "node": ">=0.10.0" | ||
"find-java-home": "0.1.2", | ||
"glob": "~3.2.9", | ||
"nan": "1.4.1" | ||
"glob": "5.0.5", | ||
"nan": "1.7.0" | ||
}, | ||
"devDependencies": { | ||
"async": "0.9.0", | ||
"chalk": "^1.0.0", | ||
"lodash": "^3.5.0", | ||
"nodeunit": "0.9.0", | ||
"when": "3.6.4" | ||
"chalk": "1.0.0", | ||
"lodash": "3.7.0", | ||
"nodeunit": "0.9.1", | ||
"when": "3.7.2" | ||
}, | ||
@@ -42,0 +42,0 @@ "scripts": { |
@@ -188,4 +188,24 @@ [![Build Status](https://travis-ci.org/joeferner/node-java.png)](https://travis-ci.org/joeferner/node-java) | ||
## Varargs support | ||
With v0.5.0 node-java now supports methods with variadic arguments (varargs). Prior to v0.5.0, | ||
a javascript call to a Java varargs method had to construct an array of the variadic arguments using `java.newArray()`. With v0.5.0 javascript applications can simply use the variadic style. | ||
In most cases it is still acceptable to use `java.newArray()`. But it is now possible to pass a plain javascript array, or use the variadic style. For example, consider these snippets from the unit test file `test/varargs-test.js`: | ||
``` | ||
test.equal(Test.staticVarargsSync(5, 'a', 'b', 'c'), '5abc'); | ||
test.equal(Test.staticVarargsSync(5, ['a', 'b', 'c']), '5abc'); | ||
test.equal(Test.staticVarargsSync(5, java.newArray('java.lang.String', ['a', 'b', 'c'])), '5abc'); | ||
``` | ||
Note that when passing a Javascript array (e.g. `['a', 'b', 'c']`) for a varargs parameter, node-java must infer the Java type of the array. If all of the elements are of the same javascript primitive type (`string` in this example) then node-java will create a Java array of the corresponding type (e.g. `java.lang.String`). The Java types that node-java can infer are: `java.lang.String`, `java.lang.Boolean`, `java.lang.Integer`, `java.lang.Long`, and `java.lang.Double`. If an array has a mix of `Integer`, `Long`, and `Double`, then the inferred type will be `java.lang.Number`. Any other mix will result in an inferred type of `java.lang.Object`. | ||
# Release Notes | ||
### v0.5.0 | ||
* Support for varargs. This change is not 100% backwards compatible, but the fix is generally easy and results in more natural code. | ||
### v0.2.0 | ||
@@ -192,0 +212,0 @@ |
@@ -270,4 +270,16 @@ var java = require("../testHelpers").java; | ||
test.done(); | ||
}, | ||
"Call static method with varargs": function(test) { | ||
var Test = java.import("Test"); | ||
var str = Test.staticVarargsSync(5, java.newArray('java.lang.String', ['a', 'b', 'c'])); | ||
test.equal(str, "5abc"); | ||
str = Test.staticVarargsSync(5, 'a', 'b', 'c'); | ||
test.equal(str, "5abc"); | ||
test.done(); | ||
} | ||
}); |
@@ -59,3 +59,3 @@ | ||
"newInstance bad arg types": function(test) { | ||
java.newInstance("Test", "z", function(err, result) { | ||
java.newInstance("Test", 'a', function(err, result) { | ||
test.ok(err); | ||
@@ -69,3 +69,3 @@ test.ok(!result); | ||
test.throws(function() { | ||
java.newInstanceSync("Test", "z"); | ||
java.newInstanceSync("Test", 'a'); | ||
}); | ||
@@ -76,3 +76,3 @@ test.done(); | ||
"newInstance bad number of args": function(test) { | ||
java.newInstance("Test", 42, "z", function(err, result) { | ||
java.newInstance("Test", 42, 15, function(err, result) { | ||
test.ok(err); | ||
@@ -86,3 +86,3 @@ test.ok(!result); | ||
test.throws(function() { | ||
java.newInstanceSync("Test", 42, "z"); | ||
java.newInstanceSync("Test", 42, 15); | ||
}); | ||
@@ -112,2 +112,15 @@ test.done(); | ||
}, | ||
"newInstanceSync with varargs": function(test) { | ||
var result = java.newInstanceSync("Test", 42, java.newArray('java.lang.String', ["a", "b"])); | ||
test.ok(result); | ||
result = java.newInstanceSync("Test", 42, "a"); | ||
test.ok(result); | ||
result = java.newInstanceSync("Test", 42, "a", "b", "c"); | ||
test.ok(result); | ||
test.done(); | ||
} | ||
}); |
@@ -70,3 +70,3 @@ // testAllThreeSuffix.js | ||
var String = java.import("java.lang.String"); | ||
test.strictEqual(String.formatSync('%s--%s', java.newArray("java.lang.String", ["hello", "world"])), "hello--world"); | ||
test.strictEqual(String.formatSync('%s--%s', "hello", "world"), "hello--world"); | ||
test.done(); | ||
@@ -73,0 +73,0 @@ }, |
@@ -67,3 +67,3 @@ // testAsyncSuffixSyncDefault.js | ||
var String = java.import("java.lang.String"); | ||
test.strictEqual(String.format('%s--%s', java.newArray("java.lang.String", ["hello", "world"])), "hello--world"); | ||
test.strictEqual(String.format('%s--%s', "hello", "world"), "hello--world"); | ||
test.done(); | ||
@@ -70,0 +70,0 @@ }, |
@@ -67,3 +67,3 @@ // testDefacto.js | ||
var String = java.import("java.lang.String"); | ||
test.strictEqual(String.formatSync('%s--%s', java.newArray("java.lang.String", ["hello", "world"])), "hello--world"); | ||
test.strictEqual(String.formatSync('%s--%s', "hello", "world"), "hello--world"); | ||
test.done(); | ||
@@ -70,0 +70,0 @@ }, |
@@ -69,3 +69,3 @@ // testDefactoPlusPromise.js | ||
var String = java.import("java.lang.String"); | ||
test.strictEqual(String.formatSync('%s--%s', java.newArray("java.lang.String", ["hello", "world"])), "hello--world"); | ||
test.strictEqual(String.formatSync('%s--%s', "hello", "world"), "hello--world"); | ||
test.done(); | ||
@@ -72,0 +72,0 @@ }, |
@@ -65,3 +65,3 @@ // testDefault.js | ||
var String = java.import("java.lang.String"); | ||
test.strictEqual(String.formatSync('%s--%s', java.newArray("java.lang.String", ["hello", "world"])), "hello--world"); | ||
test.strictEqual(String.formatSync('%s--%s', "hello", "world"), "hello--world"); | ||
test.done(); | ||
@@ -68,0 +68,0 @@ }, |
@@ -69,3 +69,3 @@ // testNoAsync.js | ||
var String = java.import("java.lang.String"); | ||
test.strictEqual(String.formatSync('%s--%s', java.newArray("java.lang.String", ["hello", "world"])), "hello--world"); | ||
test.strictEqual(String.formatSync('%s--%s', "hello", "world"), "hello--world"); | ||
test.done(); | ||
@@ -72,0 +72,0 @@ }, |
@@ -71,3 +71,3 @@ // testSyncDefaultPlusPromise.js | ||
var String = java.import("java.lang.String"); | ||
test.strictEqual(String.format('%s--%s', java.newArray("java.lang.String", ["hello", "world"])), "hello--world"); | ||
test.strictEqual(String.format('%s--%s', "hello", "world"), "hello--world"); | ||
test.done(); | ||
@@ -74,0 +74,0 @@ }, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
2603199
89
2205
1
656
+ Addedbalanced-match@1.0.2(transitive)
+ Addedbrace-expansion@1.1.11(transitive)
+ Addedconcat-map@0.0.1(transitive)
+ Addedglob@5.0.5(transitive)
+ Addedinflight@1.0.6(transitive)
+ Addedminimatch@2.0.10(transitive)
+ Addednan@1.7.0(transitive)
+ Addedonce@1.4.0(transitive)
+ Addedpath-is-absolute@1.0.1(transitive)
+ Addedwrappy@1.0.2(transitive)
- Removedglob@3.2.11(transitive)
- Removedlru-cache@2.7.3(transitive)
- Removedminimatch@0.3.0(transitive)
- Removednan@1.4.1(transitive)
- Removedsigmund@1.0.1(transitive)
Updatedglob@5.0.5
Updatednan@1.7.0