Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Rhino & MooTools

62 views
Skip to first unread message

Vinicius Isola

unread,
May 27, 2010, 4:00:00 PM5/27/10
to dev-tech-js-...@lists.mozilla.org
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

Mark Porter

unread,
May 28, 2010, 10:45:46 AM5/28/10
to
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

Vinicius Isola

unread,
May 28, 2010, 1:42:36 PM5/28/10
to dev-tech-js-...@lists.mozilla.org
Using "Date(resultSet.getDate(index))" works great!

Thanks!
Vinicius Isola
"Não podemos escolher as consequências, mas podemos escolher nossos atos."


On Fri, May 28, 2010 at 11:45 AM, Mark Porter <dm4...@gmail.com> wrote:

> 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<http://groups.google.com/group/mozilla.dev.tech.js-engine.rhino/%0Abrowse_thread/thread/14b74d5b9ee711fa/1b1e5462e5b2819d>

> _______________________________________________
> dev-tech-js-engine-rhino mailing list
> dev-tech-js-...@lists.mozilla.org
> https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino
>

0 new messages