I've found a consistent bug while trying to load a large object in
JSON format like this:
-----
obj = {
'key_1' : 'value_1',
'key_2' : 'value_2',
...
'key_32768' : 'value_32768',
'key_32769' : 'value_32769',
...
}
-----
Starting with key_32768, the Javascript parser *reverses* key<=>value
pairs and treats the rest as if it was written:
----
'value_32768' : 'key_32768',
'value_32769' : 'key_32769',
...
----
You may test it yourselves with the script "json_bug.js":
-----
function save(obj, filename) {
var file = new Stream(filename, "w");
file.write("obj={\n");
for (var key in obj)
file.write("\""+key+"\" : \""+obj[key]+"\",\n");
file.write("};");
file.close();
}
if (!system.exists("json_bug1.js")) {
var obj = {};
for (var i = 1; i <= 33000; i++)
obj['any_key_'+i] = 'any_value_'+i;
save(obj, "json_bug1.js");
} else {
load("json_bug1.js");
save(obj, "json_bug2.js");
}
-----
On the first run the script builds a large object and writes it to
file "json_bug1.js" in JSON format.
On the second run the script loads "json_bug1.js" and writes it to
another file "json_bug2.js".
Now view "json_bug2.js" and see keys<=>values reversed after key_32768 !
This bug is also present in Kmeleon browser (http://kmeleon.sourceforge.net/)
but absent from Mozilla Firefox (I've not tested other Mozilla applications).
I guess this is due to some unclear bugs in Microsoft libraries from
the MSVC compiler.
Can you fix it please once and forever ?
I wonder why Firefox doesn't have this bug ?
Truly yours,
Pollex.
--
You received this message because you are subscribed to the Google Groups "JSDB" group.
To post to this group, send email to js...@googlegroups.com.
To unsubscribe from this group, send email to jsdb+uns...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/jsdb?hl=en.
Indeed, the latest jsdb version 1.8.0.1 doesn't have this bug,
but I've tested versions 1.7.2 and earlier, which all do have it !
I wonder whether it is due to Mozilla code and how could it survive
for such a long time ?
Pollex
You're probably wondering: why did it take JSDB so long to catch up?
Mostly because I've been chasing my toddler around instead of writing
code. Sorry. But my firm, Raosoft, Inc. has always had a policy of
being slightly behind the bleeding edge in delivering software. We
value robustness and reliability. SpiderMonkey 1.8 went through some
big changes, especially with the JIT compiler. The configure script is
an outright nightmare -- JSDB 1.8 still doesn't compile on SunOS. With
JSDB 1.7.2, bugs were discovered about once a month. Not many. JSDB
1.8 is revealing some unpleasant surprises in the Mozilla engine, so
we'll have to make the bug reporting process more formal.
Shanti