This is probably because Rhino returns Java zative objects by default.
Changing this to return JS native objects may help[1]

Another option is to coerce the object yourself via "new Date(<the
returned java date object>)"


[1]:http://groups.google.com/group/mozilla.dev.tech.js-engine.rhino/
browse_thread/thread/14b74d5b9ee711fa/1b1e5462e5b2819d


----------------------------------------------------------
Mark Porter

Myna JavaScript Application Server
Easy server-side JS on a Java platform
http://www.mynajs.org

On May 27, 2:00 pm, Vinicius Isola <[email protected]> wrote:
> I'm working on a servlet that runs javascript using Rhino.
> I added MooTools into the scope I'm using so I could use its useful helpers
> classes and functions.
>
> But I stumbled into a problem that I've been unable to solve. When
> retrieving a record from the database I use a switch to automatically find
> what kind of data was retrieved and add it to an object.
>
> When a java.sql.Date is retrieved and added to this object, calling
> JSON.encode will throw the following exception:
> org.mozilla.javascript.EcmaError: TypeError: Cannot find function
> hasOwnProperty in object 1975-01-01.
>
> That would happen when MooTools try to access the hasOwnProperty method of
> the java.sql.Date object. In the following method:
> forEach: function(fn, bind){
>     for (var key in this){
>         if (this.hasOwnProperty(key)) fn.call(bind, this[key], key, this);
> // <- Here
>     }
>
> },
>
> Has any one had the same problem or knows how I could avoid or correct that?
> Thanks.
> Vinicius

_______________________________________________
dev-tech-js-engine-rhino mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino

Reply via email to