Debian Codegraph @

rhino/testsrc/jstests/stringify-jarray-replacer.jstest

raw
1 // Ensure that a stringify replacer function gets a chance to do something sane with native java array
2
3 var nja = java.lang.String.valueOf("a,b,c").split(",");
4 var expected = JSON.stringify("a,b,c".split(/,/));
5 try {
6 var actual = JSON.stringify(nja, function(key, value) {
7 if (value instanceof java.lang.Object) {
8 if (value instanceof Array)
9 return value.slice();
10 if (value instanceof java.lang.CharSequence)
11 return String(value);
12 }
13 return value;
14 });
15 } catch (e) {
16 throw "JSON.stringify(nja, replacer) threw an Exception: " + JSON.stringify(e);
17 }
18 if (actual !== expected) {
19 throw "Expected '" + expected + "', got '" + actual + "'";
20 }
21
22 "success";