8074661: Forward port AbstractJSObject.getDefaultValue(JSObject, Class)
authorattila
Wed, 11 Mar 2015 17:47:28 +0100
changeset 29413 153d198cfdc3
parent 29412 6dfd487fbad4
child 29414 4c635c98c0b4
8074661: Forward port AbstractJSObject.getDefaultValue(JSObject, Class) Reviewed-by: hannesw, sundar
nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/scripting/AbstractJSObject.java
nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/scripting/ScriptObjectMirror.java
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/scripting/AbstractJSObject.java	Wed Mar 11 16:58:04 2015 +0530
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/scripting/AbstractJSObject.java	Wed Mar 11 17:47:28 2015 +0100
@@ -161,9 +161,8 @@
      * @return set of property names
      */
     @Override
-    @SuppressWarnings("unchecked")
     public Set<String> keySet() {
-        return Collections.EMPTY_SET;
+        return Collections.emptySet();
     }
 
     /**
@@ -172,9 +171,8 @@
      * @return set of property values.
      */
     @Override
-    @SuppressWarnings("unchecked")
     public Collection<Object> values() {
-        return Collections.EMPTY_SET;
+        return Collections.emptySet();
     }
 
     // JavaScript instanceof check
@@ -249,10 +247,27 @@
      * Returns this object's numeric value.
      *
      * @return this object's numeric value.
+     * @deprecated use {@link #getDefaultValue(Class)} with {@link Number} hint instead.
      */
-    @SuppressWarnings("deprecation")
-    @Override
+    @Override @Deprecated
     public double toNumber() {
         return Double.NaN;
     }
+
+    /**
+     * When passed an {@link AbstractJSObject}, invokes its {@link #getDefaultValue(Class)} method. When passed any
+     * other {@link JSObject}, it will obtain its {@code [[DefaultValue]]} method as per ECMAScript 5.1 section
+     * 8.6.2.
+     *
+     * @param jsobj the {@link JSObject} whose {@code [[DefaultValue]]} is obtained.
+     * @param hint the type hint. Should be either {@code null}, {@code Number.class} or {@code String.class}.
+     * @return this object's default value.
+     * @throws UnsupportedOperationException if the conversion can't be performed. The engine will convert this
+     * exception into a JavaScript {@code TypeError}.
+     * @deprecated use {@link JSObject#getDefaultValue(Class)} instead.
+     */
+    @Deprecated
+    public static Object getDefaultValue(final JSObject jsobj, final Class<?> hint) {
+        return jsobj.getDefaultValue(hint);
+    }
 }
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/scripting/ScriptObjectMirror.java	Wed Mar 11 16:58:04 2015 +0530
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/scripting/ScriptObjectMirror.java	Wed Mar 11 17:47:28 2015 +0100
@@ -813,7 +813,7 @@
         }
     }
 
-    @Override
+    @Override @Deprecated
     public double toNumber() {
         return inGlobal(new Callable<Double>() {
             @Override public Double call() {
@@ -823,7 +823,7 @@
     }
 
     @Override
-    public Object getDefaultValue(Class<?> hint) {
+    public Object getDefaultValue(final Class<?> hint) {
         return inGlobal(new Callable<Object>() {
             @Override public Object call() {
                 try {