object with numeric indexes fills up
Christoph Gritschenberger
christoph.gritschenberger at gmail.com
Wed Oct 29 12:18:06 UTC 2014
I ran into an oddity when listing the keys of an object today.
If I add a value with a numeric key >=524288 and then add more than one
value with a key <524288, nashorn fills up the space between the lower
indexes.
I got some sample-code here:
ScriptEngine engine = new
ScriptEngineManager().getEngineByName("javascript");
Object eval = engine.eval("var x = {}; x[524287] = 'xxx'; x[1] =
'foo'; x[3] = 'bar'; Object.keys(x);");
System.out.println(((Map) eval).values());
// prints [1, 3, 524287] as expected
eval = engine.eval("var x = {}; x[524288] = 'xxx'; x[1] = 'foo';
x[3] = 'bar'; Object.keys(x);");
System.out.println(((Map) eval).values());
// prints [1, 2, 3, 524288]
Any idea why that is?
kind regards,
Christoph
More information about the nashorn-dev
mailing list