8006557: JDK8/Lambda build clashes on Map.replace()
authorsundar
Sat, 19 Jan 2013 22:35:43 +0530
changeset 16183 b9578bc4cd68
parent 16182 06e8c712f6a3
child 16184 bea4e75d192c
8006557: JDK8/Lambda build clashes on Map.replace() Reviewed-by: jlaskey
nashorn/src/jdk/nashorn/internal/runtime/ScriptObject.java
nashorn/test/src/jdk/nashorn/internal/runtime/ContextTest.java
--- a/nashorn/src/jdk/nashorn/internal/runtime/ScriptObject.java	Sat Jan 19 09:14:43 2013 +0530
+++ b/nashorn/src/jdk/nashorn/internal/runtime/ScriptObject.java	Sat Jan 19 22:35:43 2013 +0530
@@ -87,7 +87,7 @@
  */
 
 
-public abstract class ScriptObject extends PropertyListenerManager implements PropertyAccess, Map<Object, Object> {
+public abstract class ScriptObject extends PropertyListenerManager implements PropertyAccess {
 
     /** Search fall back routine name for "no such method" */
     static final String NO_SUCH_METHOD_NAME   = "__noSuchMethod__";
@@ -1414,7 +1414,7 @@
         return (flags & IS_SCOPE) != 0;
     }
 
-    @Override
+    // java.util.Map-like methods to help ScriptObjectMirror implementation
     public void clear() {
         final boolean strict = getContext()._strict;
         final Iterator<String> iter = propertyIterator();
@@ -1423,12 +1423,10 @@
         }
     }
 
-    @Override
     public boolean containsKey(final Object key) {
         return has(key);
     }
 
-    @Override
     public boolean containsValue(final Object value) {
         final Iterator<Object> iter = valueIterator();
         while (iter.hasNext()) {
@@ -1439,7 +1437,6 @@
         return false;
     }
 
-    @Override
     public Set<Map.Entry<Object, Object>> entrySet() {
         final Iterator<String> iter = propertyIterator();
         final Set<Map.Entry<Object, Object>> entries = new HashSet<>();
@@ -1450,12 +1447,10 @@
         return Collections.unmodifiableSet(entries);
     }
 
-    @Override
     public boolean isEmpty() {
         return !propertyIterator().hasNext();
     }
 
-    @Override
     public Set<Object> keySet() {
         final Iterator<String> iter = propertyIterator();
         final Set<Object> keySet = new HashSet<>();
@@ -1465,14 +1460,12 @@
         return Collections.unmodifiableSet(keySet);
     }
 
-    @Override
     public Object put(final Object key, final Object value) {
         final Object oldValue = get(key);
         set(key, value, getContext()._strict);
         return oldValue;
     }
 
-    @Override
     public void putAll(final Map<?, ?> otherMap) {
         final boolean strict = getContext()._strict;
         for (final Map.Entry<?, ?> entry : otherMap.entrySet()) {
@@ -1480,14 +1473,12 @@
         }
     }
 
-    @Override
     public Object remove(final Object key) {
         final Object oldValue = get(key);
         delete(key, getContext()._strict);
         return oldValue;
     }
 
-    @Override
     public int size() {
         int n = 0;
         for (final Iterator<String> iter = propertyIterator(); iter.hasNext(); iter.next()) {
@@ -1496,7 +1487,6 @@
         return n;
     }
 
-    @Override
     public Collection<Object> values() {
         final List<Object>     values = new ArrayList<>(size());
         final Iterator<Object> iter   = valueIterator();
--- a/nashorn/test/src/jdk/nashorn/internal/runtime/ContextTest.java	Sat Jan 19 09:14:43 2013 +0530
+++ b/nashorn/test/src/jdk/nashorn/internal/runtime/ContextTest.java	Sat Jan 19 22:35:43 2013 +0530
@@ -49,13 +49,13 @@
             assertTrue(32.0 == ((Number)(eval(cx, "<evalTest>", code))).doubleValue());
 
             code = "obj = { js: 'nashorn' }; obj.js";
-            assertEquals("nashorn", eval(cx, "<evalTest2>", code));
+            assertEquals(eval(cx, "<evalTest2>", code), "nashorn");
         } finally {
             Context.setGlobal(oldGlobal);
         }
     }
 
-    // basic check for JS reflection access
+    // basic check for JS reflection access - java.util.Map-like access on ScriptObject
     @Test
     public void reflectionTest() {
         final Options options = new Options("");
@@ -70,12 +70,11 @@
 
             final Object obj = cx.getGlobal().get("obj");
 
-            assertTrue(obj instanceof Map);
+            assertTrue(obj instanceof ScriptObject);
 
-            @SuppressWarnings("unchecked")
-            final Map<Object, Object> map = (Map<Object, Object>)obj;
+            final ScriptObject sobj = (ScriptObject)obj;
             int count = 0;
-            for (final Map.Entry<?, ?> ex : map.entrySet()) {
+            for (final Map.Entry<?, ?> ex : sobj.entrySet()) {
                 final Object key = ex.getKey();
                 if (key.equals("x")) {
                     assertTrue(ex.getValue() instanceof Number);
@@ -89,13 +88,13 @@
                     count++;
                 }
             }
-            assertEquals(2, count);
-            assertEquals(2, map.size());
+            assertEquals(count, 2);
+            assertEquals(sobj.size(), 2);
 
             // add property
-            map.put("zee", "hello");
-            assertEquals("hello", map.get("zee"));
-            assertEquals(3, map.size());
+            sobj.put("zee", "hello");
+            assertEquals(sobj.get("zee"), "hello");
+            assertEquals(sobj.size(), 3);
 
         } finally {
             Context.setGlobal(oldGlobal);