Coerce undefined into null in hosted mode.
Patch by: bobv
Review by: scottb (desk)
git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@2486 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/dev/core/src/com/google/gwt/dev/shell/JsValueGlue.java b/dev/core/src/com/google/gwt/dev/shell/JsValueGlue.java
index 21d9b7e..0a8783e 100644
--- a/dev/core/src/com/google/gwt/dev/shell/JsValueGlue.java
+++ b/dev/core/src/com/google/gwt/dev/shell/JsValueGlue.java
@@ -46,14 +46,11 @@
public static <T> T get(JsValue value, CompilingClassLoader cl,
Class<T> type, String msgPrefix) {
- if (value.isUndefined()) {
- // undefined is never legal to return from JavaScript into Java
- throw new HostedModeException(msgPrefix
- + ": attempt to use JavaScript 'undefined' as a value, expected " + type.getName());
- }
-
if (type.isPrimitive()) {
- if (value.isNull()) {
+ if (value.isUndefined()) {
+ throw new HostedModeException("Expected primitive type " + type
+ + "; actual value was undefined");
+ } else if (value.isNull()) {
throw new HostedModeException("Expected primitive type " + type
+ "; actual value was null");
}
@@ -118,7 +115,7 @@
}
}
- if (value.isNull()) {
+ if (value.isNull() || value.isUndefined()) {
return null;
}
if (value.isWrappedJavaObject()) {