I have this Java code:

                    Scriptable ruleScope = ctx.newObject(scope);
                    ruleScope.setParentScope(null);
                    ruleScope.setPrototype(scope);
                    Map ruleContext =
RuleCodeManager.instance.getContext(r.getId());
                    ruleScope.put("ruleContext", ruleScope,
ruleContext);
                    body.exec(ctx, ruleScope);
                    ruleContext = (Map) ruleScope.get("ruleContext",
ruleScope);

ruleContext is a simple, empty HashMap.

body looks like this:

var b = ruleContext.get("test");
if (b == null) {
    b = 1;
} else {
    b = b + 1;
}
ruleContext.put("test", b);
out.println("b = " + b);

The first time I run this, I ruleContext comes back populated with the
"test" key and a Double value == 1.0.

When I run that code a second time, now the the ruleContext being the
same map with a "test" -> (Double)1.0, JS converts it to a string.

So, the first time through I get "b = 1" and the second, and later,
time I get "b = 1.01". The ruleContext contains "test" -> "1.01" when
it comes back the second time.

What am I doing wrong, and what's the best way to pass numbers back
and forth reliably?

Thanx!

Regards,

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

Reply via email to