I am writing a Node.js application in which I populate an Object using string converted integers as keys (for example, "62616324573"). Objects always store {key:} keys as strings, which is ideal compared to javascript methods of arrays and their [index] :
An array defines a million times undefined , once for each index between specific indices.
However, I found that I cannot debug my new objects properly, because the Variables panel in Eclipse displays Failed to read variables . Inside, they seem to be working fine.
Take the following code:
var util = require('util'); util.debug('Run this with --debug-brk=port, and press Resume (F8) to break at the breakpoint below.'); var debugMe = { "1000000000" : { // "2011743958" : { "some" : 1234, "random" : true, "data" : undefined }, // "1000000001" : { // "8302611133" : { "3302611133" : { "some" : 12345678, "random" : false, "data" : null } }; util.debug(JSON.stringify(debugMe)); // Look, it prints fine in all cases. This is internal javascript code. util.debug('...'); util.inspect(debugMe); // And now it doesn't. This is V8 debugging code. var breakpoint_here = true; // Set breakpoint here! // hohoho
Set a breakpoint in breakpoint_here and start it with an instant interrupt debugger, for example. node --debug-brk=5858 debugtest.js . Press resume to go from line 1 to the breakpoint. Go to the Variables panel and try checking debugMe : the panel will work.
Try again from 10..00 and 10..01. No problems. In addition, numbers are apparently parsed as an array index (!), Judging by how it is written.
debugMe -> [1000000000] -> [Object] [1000000001] -> [Object]
Now try 10.10 and 83..02. Suddenly, 83..33 is a regular JSON key instead of an array index, but 10..00 is still an array index. (?)
debugMe -> 8302611133 -> [Object] [1000000000] -> [Object]
Now try 10..00 and 33..33 and the Variables window will work again. This is what I expected:
debugMe -> 1000000000 -> [Object] 3302611133 -> [Object]
This is what I'm guessing is happening, although you cannot see it when debugging an object that is still cooperating:
debugMe -> [1000000000] -> [Object] [1000000001] -> undefined // (...) // debugger memory fills up [3302611132] -> undefined [3302611133] -> [Object]
The problem that I guess is that the numbers in this case are also the indexes of the array, and the difference is too big, because the debugger will remember 2302611133 times undefined , a problem that should only exist when the array used in place of the JSON object .
- Why are some numbers accepted as a key (string) and others as an index?
- Why does some combination of indexes work in the debugger, while others do not?
- Is the problem a million times undefined without I knowing what happens to objects?
Let me remind you:
- Small differences in integer integer int lines seem to work fine, but in the debugger they become [indexes]
- Big differences up to a billion in a key do not work;
Variables crash windows. No console output. - Even bigger differences work again, but some become [index], while others remain the "key".
Since I had to do manual crash tests, it took me from time to time to find out that the problem was in the rooms, and not in the content of the objects themselves. It is hard to imagine that the problem affects only the debugger, and not the application itself, because it is the same (V8) engine. I hope someone can point out all the facts and variables that I am missing.
-update -
Nobody knows about it. Unknown logic or known error. I filed an error in Eclipse WDT, although I'm not sure what the source of the behavior is.