提交 7a21e153 编写于 作者: A attila

8015955: ObjectNode.elements should be stronger typed

Reviewed-by: lagergren, sundar
上级 83f6b24f
......@@ -1326,8 +1326,7 @@ final class CodeGenerator extends NodeOperatorVisitor<CodeGeneratorLexicalContex
@Override
public boolean enterObjectNode(final ObjectNode objectNode) {
final List<Node> elements = objectNode.getElements();
final int size = elements.size();
final List<PropertyNode> elements = objectNode.getElements();
final List<String> keys = new ArrayList<>();
final List<Symbol> symbols = new ArrayList<>();
......@@ -1335,8 +1334,7 @@ final class CodeGenerator extends NodeOperatorVisitor<CodeGeneratorLexicalContex
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();
......
......@@ -63,7 +63,6 @@ public class BlockLexicalContext extends LexicalContext {
return sstack.pop();
}
@SuppressWarnings("unchecked")
@Override
public <T extends LexicalContextNode> T pop(final T node) {
T expected = node;
......
......@@ -27,7 +27,6 @@ package jdk.nashorn.internal.ir;
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 @@ import jdk.nashorn.internal.ir.visitor.NodeVisitor;
public final class ObjectNode extends Node {
/** Literal elements. */
private final List<Node> elements;
private final List<PropertyNode> elements;
/**
* Constructor
......@@ -47,12 +46,12 @@ public final class ObjectNode extends Node {
* @param finish finish
* @param elements the elements used to initialize this ObjectNode
*/
public ObjectNode(final long token, final int finish, final List<Node> elements) {
public ObjectNode(final long token, final int finish, final List<PropertyNode> elements) {
super(token, finish);
this.elements = elements;
}
private ObjectNode(final ObjectNode objectNode, final List<Node> elements) {
private ObjectNode(final ObjectNode objectNode, final List<PropertyNode> elements) {
super(objectNode);
this.elements = elements;
}
......@@ -60,7 +59,7 @@ public final class ObjectNode extends Node {
@Override
public Node accept(final NodeVisitor<? extends LexicalContext> 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 @@ public final class ObjectNode extends Node {
* Get the elements of this literal node
* @return a list of elements
*/
public List<Node> getElements() {
public List<PropertyNode> getElements() {
return Collections.unmodifiableList(elements);
}
private ObjectNode setElements(final List<Node> elements) {
private ObjectNode setElements(final List<PropertyNode> elements) {
if (this.elements == elements) {
return this;
}
......
......@@ -282,7 +282,7 @@ loop:
next();
// Prepare to accumulate elements.
final List<Node> elements = new ArrayList<>();
final List<PropertyNode> elements = new ArrayList<>();
// Create a block for the object literal.
loop:
......@@ -298,7 +298,7 @@ loop:
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 @@ loop:
* 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;
......
......@@ -59,7 +59,6 @@ import java.util.Iterator;
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 @@ loop:
}
}
return new ObjectNode(objectToken, finish, new ArrayList<Node>(map.values()));
return new ObjectNode(objectToken, finish, new ArrayList<>(map.values()));
}
/**
......
......@@ -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.ir.UnaryNode;
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 @@ public final class JSONFunctions {
final ObjectNode objNode = (ObjectNode) node;
final ScriptObject object = ((GlobalObject)global).newObject();
final boolean strict = global.isStrictContext();
final List<Node> 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();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册