Updates to take advantage of allowing undefined in Java code.
Review by: spoon (pair prog)
git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@2487 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/user/src/com/google/gwt/json/client/JSONArray.java b/user/src/com/google/gwt/json/client/JSONArray.java
index 97024ba..cc8aa31 100644
--- a/user/src/com/google/gwt/json/client/JSONArray.java
+++ b/user/src/com/google/gwt/json/client/JSONArray.java
@@ -142,11 +142,12 @@
}-*/;
private native void set0(int index, JSONValue value) /*-{
- if (value === null) {
- value = undefined;
- } else {
+ if (value) {
var func = value.@com.google.gwt.json.client.JSONValue::getUnwrapper()();
value = func(value);
+ } else {
+ // Coerce Java null to undefined; there's a JSONNull for null.
+ value = undefined;
}
this.@com.google.gwt.json.client.JSONArray::jsArray[index] = value;
}-*/;
diff --git a/user/src/com/google/gwt/json/client/JSONObject.java b/user/src/com/google/gwt/json/client/JSONObject.java
index e94b0b7..6fd985d 100644
--- a/user/src/com/google/gwt/json/client/JSONObject.java
+++ b/user/src/com/google/gwt/json/client/JSONObject.java
@@ -56,7 +56,7 @@
* @return <code>true</code> if the JSONObject contains the specified property
*/
public native boolean containsKey(String key) /*-{
- return this.@com.google.gwt.json.client.JSONObject::jsObject[key] !== undefined;
+ return key in this.@com.google.gwt.json.client.JSONObject::jsObject;
}-*/;
/**
@@ -176,9 +176,7 @@
private native void addAllKeys(Collection<String> s) /*-{
var jsObject = this.@com.google.gwt.json.client.JSONObject::jsObject;
for (var key in jsObject) {
- if (jsObject[key] !== undefined) {
- s.@java.util.Collection::add(Ljava/lang/Object;)(key);
- }
+ s.@java.util.Collection::add(Ljava/lang/Object;)(key);
}
}-*/;
@@ -189,12 +187,11 @@
}-*/;
private native void put0(String key, JSONValue value) /*-{
- if (value === null) {
- value = undefined;
- } else {
+ if (value) {
var func = value.@com.google.gwt.json.client.JSONValue::getUnwrapper()();
- value = func(value);
+ this.@com.google.gwt.json.client.JSONObject::jsObject[key] = func(value);
+ } else {
+ delete this.@com.google.gwt.json.client.JSONObject::jsObject[key];
}
- this.@com.google.gwt.json.client.JSONObject::jsObject[key] = value;
}-*/;
}
diff --git a/user/src/com/google/gwt/user/client/ui/FastStringMap.java b/user/src/com/google/gwt/user/client/ui/FastStringMap.java
index b2ad53c..36caa12 100644
--- a/user/src/com/google/gwt/user/client/ui/FastStringMap.java
+++ b/user/src/com/google/gwt/user/client/ui/FastStringMap.java
@@ -173,9 +173,7 @@
// Prepend ':' to avoid conflicts with built-in Object properties.
public native T get(String key) /*-{
- var value
- = this.@com.google.gwt.user.client.ui.FastStringMap::map[':' + key];
- return (value == null) ? null : value;
+ return this.@com.google.gwt.user.client.ui.FastStringMap::map[':' + key];
}-*/;
@Override
@@ -207,11 +205,12 @@
// Prepend ':' to avoid conflicts with built-in Object properties.
@Override
- public native T put(String key, T widget) /*-{
- var previous
- = this.@com.google.gwt.user.client.ui.FastStringMap::map[':' + key];
- this.@com.google.gwt.user.client.ui.FastStringMap::map[':' + key] = widget;
- return (previous == null) ? null : previous;
+ public native T put(String key, T value) /*-{
+ key = ':' + key;
+ var map = this.@com.google.gwt.user.client.ui.FastStringMap::map;
+ var previous = map[key];
+ map[key] = value;
+ return previous;
}-*/;
@Override
@@ -265,7 +264,7 @@
// Prepend ':' to avoid conflicts with built-in Object properties.
private native boolean containsKey(String key, JavaScriptObject obj)/*-{
- return obj[':' + key] !== undefined;
+ return (':' + key) in obj;
}-*/;
private native void init() /*-{
@@ -283,9 +282,10 @@
// Prepend ':' to avoid conflicts with built-in Object properties.
private native T remove(String key) /*-{
- var previous
- = this.@com.google.gwt.user.client.ui.FastStringMap::map[':' + key];
- delete this.@com.google.gwt.user.client.ui.FastStringMap::map[':' + key];
- return (previous == null) ? null : previous;
+ key = ':' + key;
+ var map = this.@com.google.gwt.user.client.ui.FastStringMap::map;
+ var previous = map[key];
+ delete map[key];
+ return previous;
}-*/;
}
diff --git a/user/super/com/google/gwt/emul/java/util/AbstractHashMap.java b/user/super/com/google/gwt/emul/java/util/AbstractHashMap.java
index b54bc1b..4b0c50d 100644
--- a/user/super/com/google/gwt/emul/java/util/AbstractHashMap.java
+++ b/user/super/com/google/gwt/emul/java/util/AbstractHashMap.java
@@ -379,7 +379,7 @@
* <code>null</code> if the specified key does not exist.
*/
private native V getStringValue(String key) /*-{
- return (_ = this.@java.util.AbstractHashMap::stringMap[':' + key]) == null ? null : _ ;
+ return this.@java.util.AbstractHashMap::stringMap[':' + key];
}-*/;
/**
@@ -451,11 +451,15 @@
* key did not exist.
*/
private native V putStringValue(String key, V value) /*-{
+ var result, stringMap = this.@java.util.AbstractHashMap::stringMap;
key = ':' + key;
- var result = this.@java.util.AbstractHashMap::stringMap[key];
- this.@java.util.AbstractHashMap::stringMap[key] = value;
- return (result === undefined) ?
- (++this.@java.util.AbstractHashMap::size, null) : result;
+ if (key in stringMap) {
+ result = stringMap[key];
+ } else {
+ ++this.@java.util.AbstractHashMap::size;
+ }
+ stringMap[key] = value;
+ return result;
}-*/;
/**
@@ -502,11 +506,13 @@
* exist.
*/
private native V removeStringValue(String key) /*-{
+ var result, stringMap = this.@java.util.AbstractHashMap::stringMap;
key = ':' + key;
- var result = this.@java.util.AbstractHashMap::stringMap[key];
- return (result === undefined) ? null :
- (--this.@java.util.AbstractHashMap::size,
- delete this.@java.util.AbstractHashMap::stringMap[key],
- result);
+ if (key in stringMap) {
+ result = stringMap[key];
+ --this.@java.util.AbstractHashMap::size;
+ delete stringMap[key];
+ }
+ return result;
}-*/;
}