changeset 1210:13b4d61fac98

8074661: Forward port AbstractJSObject.getDefaultValue(JSObject, Class) Reviewed-by: hannesw, sundar
author attila
date Wed, 11 Mar 2015 17:47:28 +0100
parents 36fbf759ab8d
children 367ac913fcb3
files src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/scripting/AbstractJSObject.java src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/scripting/ScriptObjectMirror.java
diffstat 2 files changed, 23 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/scripting/AbstractJSObject.java	Wed Mar 11 16:58:04 2015 +0530
+++ b/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/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/scripting/ScriptObjectMirror.java	Wed Mar 11 16:58:04 2015 +0530
+++ b/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 {