changeset 1414:fb99aafd5c0d

8081813: JSONListAdapter should delegate its [[DefaultValue]] to wrapped object Reviewed-by: lagergren, sundar
author attila
date Wed, 03 Jun 2015 16:44:24 +0200
parents 07f32a26bc1e
children d5a9705a27b1
files src/jdk/nashorn/api/scripting/AbstractJSObject.java src/jdk/nashorn/internal/runtime/JSONListAdapter.java
diffstat 2 files changed, 16 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk/nashorn/api/scripting/AbstractJSObject.java	Tue Jun 02 10:55:17 2015 +0200
+++ b/src/jdk/nashorn/api/scripting/AbstractJSObject.java	Wed Jun 03 16:44:24 2015 +0200
@@ -28,6 +28,7 @@
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Set;
+import jdk.nashorn.internal.runtime.JSONListAdapter;
 import jdk.nashorn.internal.runtime.JSType;
 
 /**
@@ -282,6 +283,8 @@
     public static Object getDefaultValue(final JSObject jsobj, final Class<?> hint) {
         if (jsobj instanceof AbstractJSObject) {
             return ((AbstractJSObject)jsobj).getDefaultValue(hint);
+        } else if (jsobj instanceof JSONListAdapter) {
+            return ((JSONListAdapter)jsobj).getDefaultValue(hint);
         }
         return DefaultValueImpl.getDefaultValue(jsobj, hint);
     }
--- a/src/jdk/nashorn/internal/runtime/JSONListAdapter.java	Tue Jun 02 10:55:17 2015 +0200
+++ b/src/jdk/nashorn/internal/runtime/JSONListAdapter.java	Wed Jun 03 16:44:24 2015 +0200
@@ -28,6 +28,7 @@
 import java.util.Collection;
 import java.util.List;
 import java.util.Set;
+import jdk.nashorn.api.scripting.AbstractJSObject;
 import jdk.nashorn.api.scripting.JSObject;
 import jdk.nashorn.api.scripting.ScriptObjectMirror;
 import jdk.nashorn.internal.objects.Global;
@@ -153,4 +154,16 @@
     public double toNumber() {
         return obj.toNumber();
     }
+
+    /**
+     * Implements this object's {@code [[DefaultValue]]} method by returning its wrapped object's {@code [[DefaultValue]]}.
+     *
+     * @param hint the type hint. Should be either {@code null}, {@code Number.class} or {@code String.class}.
+     * @return the wrapped object's default value.
+     * @throws UnsupportedOperationException if the conversion can't be performed. The engine will convert this
+     * exception into a JavaScript {@code TypeError}.
+     */
+    public Object getDefaultValue(final Class<?> hint) {
+        return AbstractJSObject.getDefaultValue(obj, hint);
+    }
 }