# HG changeset patch # User sundar # Date 1358615143 -19800 # Node ID b9578bc4cd689adfd07520f462282cc51d381a83 # Parent 06e8c712f6a3ec82a53037a41712bbbc5b05eb82 8006557: JDK8/Lambda build clashes on Map.replace() Reviewed-by: jlaskey diff -r 06e8c712f6a3 -r b9578bc4cd68 nashorn/src/jdk/nashorn/internal/runtime/ScriptObject.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 { +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 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 iter = valueIterator(); while (iter.hasNext()) { @@ -1439,7 +1437,6 @@ return false; } - @Override public Set> entrySet() { final Iterator iter = propertyIterator(); final Set> entries = new HashSet<>(); @@ -1450,12 +1447,10 @@ return Collections.unmodifiableSet(entries); } - @Override public boolean isEmpty() { return !propertyIterator().hasNext(); } - @Override public Set keySet() { final Iterator iter = propertyIterator(); final Set 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 iter = propertyIterator(); iter.hasNext(); iter.next()) { @@ -1496,7 +1487,6 @@ return n; } - @Override public Collection values() { final List values = new ArrayList<>(size()); final Iterator iter = valueIterator(); diff -r 06e8c712f6a3 -r b9578bc4cd68 nashorn/test/src/jdk/nashorn/internal/runtime/ContextTest.java --- 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, "", code))).doubleValue()); code = "obj = { js: 'nashorn' }; obj.js"; - assertEquals("nashorn", eval(cx, "", code)); + assertEquals(eval(cx, "", 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 map = (Map)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);