# HG changeset patch # User attila # Date 1370421872 -7200 # Node ID 9b8e085aa1fe69b1afe61c3333b8487674eedbe4 # Parent adae4d39ee07bf8d2cb8d999329c7d0b7be84e1c 8015955: ObjectNode.elements should be stronger typed Reviewed-by: lagergren, sundar diff -r adae4d39ee07 -r 9b8e085aa1fe nashorn/src/jdk/nashorn/internal/codegen/CodeGenerator.java --- a/nashorn/src/jdk/nashorn/internal/codegen/CodeGenerator.java Wed Jun 05 12:08:49 2013 +0530 +++ b/nashorn/src/jdk/nashorn/internal/codegen/CodeGenerator.java Wed Jun 05 10:44:32 2013 +0200 @@ -1326,8 +1326,7 @@ @Override public boolean enterObjectNode(final ObjectNode objectNode) { - final List elements = objectNode.getElements(); - final int size = elements.size(); + final List elements = objectNode.getElements(); final List keys = new ArrayList<>(); final List symbols = new ArrayList<>(); @@ -1335,8 +1334,7 @@ boolean hasGettersSetters = false; - for (int i = 0; i < size; i++) { - final PropertyNode propertyNode = (PropertyNode)elements.get(i); + for (PropertyNode propertyNode: elements) { final Node value = propertyNode.getValue(); final String key = propertyNode.getKeyName(); final Symbol symbol = value == null ? null : propertyNode.getSymbol(); diff -r adae4d39ee07 -r 9b8e085aa1fe nashorn/src/jdk/nashorn/internal/ir/BlockLexicalContext.java --- a/nashorn/src/jdk/nashorn/internal/ir/BlockLexicalContext.java Wed Jun 05 12:08:49 2013 +0530 +++ b/nashorn/src/jdk/nashorn/internal/ir/BlockLexicalContext.java Wed Jun 05 10:44:32 2013 +0200 @@ -63,7 +63,6 @@ return sstack.pop(); } - @SuppressWarnings("unchecked") @Override public T pop(final T node) { T expected = node; diff -r adae4d39ee07 -r 9b8e085aa1fe nashorn/src/jdk/nashorn/internal/ir/ObjectNode.java --- a/nashorn/src/jdk/nashorn/internal/ir/ObjectNode.java Wed Jun 05 12:08:49 2013 +0530 +++ b/nashorn/src/jdk/nashorn/internal/ir/ObjectNode.java Wed Jun 05 10:44:32 2013 +0200 @@ -27,7 +27,6 @@ import java.util.Collections; import java.util.List; - import jdk.nashorn.internal.ir.annotations.Immutable; import jdk.nashorn.internal.ir.visitor.NodeVisitor; @@ -38,7 +37,7 @@ public final class ObjectNode extends Node { /** Literal elements. */ - private final List elements; + private final List elements; /** * Constructor @@ -47,12 +46,12 @@ * @param finish finish * @param elements the elements used to initialize this ObjectNode */ - public ObjectNode(final long token, final int finish, final List elements) { + public ObjectNode(final long token, final int finish, final List elements) { super(token, finish); this.elements = elements; } - private ObjectNode(final ObjectNode objectNode, final List elements) { + private ObjectNode(final ObjectNode objectNode, final List elements) { super(objectNode); this.elements = elements; } @@ -60,7 +59,7 @@ @Override public Node accept(final NodeVisitor visitor) { if (visitor.enterObjectNode(this)) { - return visitor.leaveObjectNode(setElements(Node.accept(visitor, Node.class, elements))); + return visitor.leaveObjectNode(setElements(Node.accept(visitor, PropertyNode.class, elements))); } return this; @@ -92,11 +91,11 @@ * Get the elements of this literal node * @return a list of elements */ - public List getElements() { + public List getElements() { return Collections.unmodifiableList(elements); } - private ObjectNode setElements(final List elements) { + private ObjectNode setElements(final List elements) { if (this.elements == elements) { return this; } diff -r adae4d39ee07 -r 9b8e085aa1fe nashorn/src/jdk/nashorn/internal/parser/JSONParser.java --- a/nashorn/src/jdk/nashorn/internal/parser/JSONParser.java Wed Jun 05 12:08:49 2013 +0530 +++ b/nashorn/src/jdk/nashorn/internal/parser/JSONParser.java Wed Jun 05 10:44:32 2013 +0200 @@ -282,7 +282,7 @@ next(); // Prepare to accumulate elements. - final List elements = new ArrayList<>(); + final List elements = new ArrayList<>(); // Create a block for the object literal. loop: @@ -298,7 +298,7 @@ default: // Get and add the next property. - final Node property = propertyAssignment(); + final PropertyNode property = propertyAssignment(); elements.add(property); // Comma between property assigments is mandatory in JSON. @@ -317,7 +317,7 @@ * Parse a property assignment from the token stream * @return the property assignment as a Node */ - private Node propertyAssignment() { + private PropertyNode propertyAssignment() { // Capture firstToken. final long propertyToken = token; LiteralNode name = null; diff -r adae4d39ee07 -r 9b8e085aa1fe nashorn/src/jdk/nashorn/internal/parser/Parser.java --- a/nashorn/src/jdk/nashorn/internal/parser/Parser.java Wed Jun 05 12:08:49 2013 +0530 +++ b/nashorn/src/jdk/nashorn/internal/parser/Parser.java Wed Jun 05 10:44:32 2013 +0200 @@ -59,7 +59,6 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; - import jdk.nashorn.internal.codegen.CompilerConstants; import jdk.nashorn.internal.codegen.Namespace; import jdk.nashorn.internal.ir.AccessNode; @@ -2028,7 +2027,7 @@ } } - return new ObjectNode(objectToken, finish, new ArrayList(map.values())); + return new ObjectNode(objectToken, finish, new ArrayList<>(map.values())); } /** diff -r adae4d39ee07 -r 9b8e085aa1fe nashorn/src/jdk/nashorn/internal/runtime/JSONFunctions.java --- a/nashorn/src/jdk/nashorn/internal/runtime/JSONFunctions.java Wed Jun 05 12:08:49 2013 +0530 +++ b/nashorn/src/jdk/nashorn/internal/runtime/JSONFunctions.java Wed Jun 05 10:44:32 2013 +0200 @@ -25,9 +25,11 @@ package jdk.nashorn.internal.runtime; +import static jdk.nashorn.internal.runtime.arrays.ArrayIndex.getArrayIndexNoThrow; +import static jdk.nashorn.internal.runtime.arrays.ArrayIndex.isValidArrayIndex; + import java.lang.invoke.MethodHandle; import java.util.Iterator; -import java.util.List; import jdk.nashorn.internal.ir.LiteralNode; import jdk.nashorn.internal.ir.Node; import jdk.nashorn.internal.ir.ObjectNode; @@ -36,8 +38,6 @@ import jdk.nashorn.internal.parser.JSONParser; import jdk.nashorn.internal.parser.TokenType; import jdk.nashorn.internal.runtime.linker.Bootstrap; -import static jdk.nashorn.internal.runtime.arrays.ArrayIndex.getArrayIndexNoThrow; -import static jdk.nashorn.internal.runtime.arrays.ArrayIndex.isValidArrayIndex; /** * Utilities used by "JSON" object implementation. @@ -171,10 +171,8 @@ final ObjectNode objNode = (ObjectNode) node; final ScriptObject object = ((GlobalObject)global).newObject(); final boolean strict = global.isStrictContext(); - final List elements = objNode.getElements(); - for (final Node elem : elements) { - final PropertyNode pNode = (PropertyNode) elem; + for (final PropertyNode pNode: objNode.getElements()) { final Node valueNode = pNode.getValue(); final String name = pNode.getKeyName();