Hi Hannes,
I'm waiting to confirm a new account on the Bugzilla server. Meanwhile, wondered if you or anyone else on the list could comment on why sometimes Rhino has difficulty converting Functions to JSON strings.
The CouchDB test suite throws many
StackOverflowErrors because the module/core/JSON.js library
has difficulty converting Java objects into JSON, leading to an
infinite loop. A bunch of JVM errors start spewing in the console, eventually ending with an out-of-memory error: "Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space at java.lang.Object.clone(Native Method)"
I don't understand how the javascript-to-Java conversion works, but an old blog post describes the problem and a solution:
http://www.cosmocode.de/en/blogs/detman/json_rhino_pitfalls/
There's
an object conversion function starting at line 99 in
<helma>/modules/core/JSON.js. I added his fix at line 104 to skip
the error:
---------------- JSON.js ----------------
object: function (x) {
if (x) {
if (x instanceof Array) {
return s.array(x);
}
if (x.hashCode) return s.string(''+x.toString()); // <-- added this line
--------------------------------------------
I followed the stacktrace to
Rhino having difficulties with Function.toSource or Function.toString.
However, I can't figure out why some functions will stringify and
others won't. Is it related to this other Rhino bug?
http://dev.helma.org/bugs/show_bug.cgi?id=545
After this fix, many of the CouchDB tests still assert (maybe due to
Rhino's incompatible Function.toString() output), but at least they
don't crash anymore.
-Sam