Do not set values to JavaScript undefined. Rather, treat these as deletes.

This commit is contained in:
hns 2003-12-03 15:19:17 +00:00
parent b622dbd039
commit c833015c1b

View file

@ -20,6 +20,7 @@ import org.mozilla.javascript.Context;
import org.mozilla.javascript.Scriptable;
import org.mozilla.javascript.ScriptableObject;
import org.mozilla.javascript.Wrapper;
import org.mozilla.javascript.Undefined;
import java.util.HashMap;
import java.util.Map;
@ -60,7 +61,9 @@ public class MapWrapper extends ScriptableObject {
map = new HashMap();
}
if (value instanceof Wrapper) {
if (value == null || value == Undefined.instance) {
map.remove(name);
} else if (value instanceof Wrapper) {
map.put(name, ((Wrapper) value).unwrap());
} else {
map.put(name, value);
@ -131,7 +134,10 @@ public class MapWrapper extends ScriptableObject {
if (map == null) {
map = new HashMap();
}
if (value instanceof Wrapper) {
if (value == null || value == Undefined.instance) {
map.remove(Integer.toString(idx));
} else if (value instanceof Wrapper) {
map.put(Integer.toString(idx), ((Wrapper) value).unwrap());
} else {
map.put(Integer.toString(idx), value);