From 646ef8f495f830e3e5da3488854aeabe6bc461ac Mon Sep 17 00:00:00 2001 From: hns Date: Thu, 6 Nov 2003 12:00:28 +0000 Subject: [PATCH] Do not wrap primitive property values as objects when retrieving them - as objects they are unusable for many purpuses, e.g. testing for equality via ==. --- src/helma/scripting/rhino/MapWrapper.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/helma/scripting/rhino/MapWrapper.java b/src/helma/scripting/rhino/MapWrapper.java index 415be346..a1bfbf31 100644 --- a/src/helma/scripting/rhino/MapWrapper.java +++ b/src/helma/scripting/rhino/MapWrapper.java @@ -59,6 +59,7 @@ public class MapWrapper extends ScriptableObject { if (map == null) { map = new HashMap(); } + if (value instanceof Wrapper) { map.put(name, ((Wrapper) value).unwrap()); } else { @@ -82,7 +83,11 @@ public class MapWrapper extends ScriptableObject { Object obj = map.get(name); if (obj != null && !(obj instanceof Scriptable)) { - if (obj instanceof String) { + // do NOT wrap primitives - otherwise they'll be wrapped as Objects, + // which makes them unusable for many purposes (e.g. ==) + if (obj instanceof String || + obj instanceof Number || + obj instanceof Boolean) { return obj; } @@ -149,6 +154,14 @@ public class MapWrapper extends ScriptableObject { Object obj = map.get(Integer.toString(idx)); if (obj != null && !(obj instanceof Scriptable)) { + // do NOT wrap primitives - otherwise they'll be wrapped as Objects, + // which makes them unusable for many purposes (e.g. ==) + if (obj instanceof String || + obj instanceof Number || + obj instanceof Boolean) { + return obj; + } + return Context.toObject(obj, core.global); }