it's not a bug. You should use JS native type. For example
new Number("3") + 1
will give you 4.
But when you use java.lang.Double JS consider it as an Object and + is
not defined for it of course.
regards,
--H
Christophe Grand wrote:
While writing a memoizing comùbinator, I encountered a bug which can be
reduced to:
new java.lang.Double("3") + 1 evals to "31"
Rhino doesn't unbox number values before performing arithmetic and hence
stringify them. I hope this is not the expected behavior. Is it?
I filled a bug and submitted a patch at:
https://bugzilla.mozilla.org/show_bug.cgi?id=398396
(If it's bad form to back the bug report with this forum post, please
tell me.)
Thanks,
Christophe Grand
--
function memo(f) {
var NULL = new java.lang.Object();
var cache = new java.util.WeakHashMap();
return function(arg) {
var v = cache.get(arg);
if (v == null) {
v = f(arg);
cache.put(arg, (v == null) ? NULL : v);
return v;
} else {
return (v == NULL) ? null : v;
}
}
}
memo = memo(memo);
_______________________________________________
dev-tech-js-engine-rhino mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino