68 import jdk.nashorn.internal.ir.IdentNode; |
68 import jdk.nashorn.internal.ir.IdentNode; |
69 import jdk.nashorn.internal.ir.IndexNode; |
69 import jdk.nashorn.internal.ir.IndexNode; |
70 import jdk.nashorn.internal.ir.LexicalContext; |
70 import jdk.nashorn.internal.ir.LexicalContext; |
71 import jdk.nashorn.internal.ir.LexicalContextNode; |
71 import jdk.nashorn.internal.ir.LexicalContextNode; |
72 import jdk.nashorn.internal.ir.LiteralNode; |
72 import jdk.nashorn.internal.ir.LiteralNode; |
73 import jdk.nashorn.internal.ir.LiteralNode.ArrayLiteralNode; |
|
74 import jdk.nashorn.internal.ir.LiteralNode.ArrayLiteralNode.ArrayUnit; |
|
75 import jdk.nashorn.internal.ir.Node; |
73 import jdk.nashorn.internal.ir.Node; |
76 import jdk.nashorn.internal.ir.RuntimeNode; |
74 import jdk.nashorn.internal.ir.RuntimeNode; |
77 import jdk.nashorn.internal.ir.RuntimeNode.Request; |
75 import jdk.nashorn.internal.ir.RuntimeNode.Request; |
|
76 import jdk.nashorn.internal.ir.Splittable; |
78 import jdk.nashorn.internal.ir.Statement; |
77 import jdk.nashorn.internal.ir.Statement; |
79 import jdk.nashorn.internal.ir.SwitchNode; |
78 import jdk.nashorn.internal.ir.SwitchNode; |
80 import jdk.nashorn.internal.ir.Symbol; |
79 import jdk.nashorn.internal.ir.Symbol; |
81 import jdk.nashorn.internal.ir.TryNode; |
80 import jdk.nashorn.internal.ir.TryNode; |
82 import jdk.nashorn.internal.ir.UnaryNode; |
81 import jdk.nashorn.internal.ir.UnaryNode; |
982 } |
981 } |
983 |
982 |
984 boolean previousWasBlock = false; |
983 boolean previousWasBlock = false; |
985 for (final Iterator<LexicalContextNode> it = lc.getAllNodes(); it.hasNext();) { |
984 for (final Iterator<LexicalContextNode> it = lc.getAllNodes(); it.hasNext();) { |
986 final LexicalContextNode node = it.next(); |
985 final LexicalContextNode node = it.next(); |
987 if (node instanceof FunctionNode || isSplitArray(node)) { |
986 if (node instanceof FunctionNode || isSplitLiteral(node)) { |
988 // We reached the function boundary or a splitting boundary without seeing a definition for the symbol. |
987 // We reached the function boundary or a splitting boundary without seeing a definition for the symbol. |
989 // It needs to be in scope. |
988 // It needs to be in scope. |
990 return true; |
989 return true; |
991 } else if (node instanceof WithNode) { |
990 } else if (node instanceof WithNode) { |
992 if (previousWasBlock) { |
991 if (previousWasBlock) { |
1008 } |
1007 } |
1009 } |
1008 } |
1010 throw new AssertionError(); |
1009 throw new AssertionError(); |
1011 } |
1010 } |
1012 |
1011 |
1013 private static boolean isSplitArray(final LexicalContextNode expr) { |
1012 private static boolean isSplitLiteral(final LexicalContextNode expr) { |
1014 if(!(expr instanceof ArrayLiteralNode)) { |
1013 return expr instanceof Splittable && ((Splittable) expr).getSplitRanges() != null; |
1015 return false; |
|
1016 } |
|
1017 final List<ArrayUnit> units = ((ArrayLiteralNode)expr).getUnits(); |
|
1018 return !(units == null || units.isEmpty()); |
|
1019 } |
1014 } |
1020 |
1015 |
1021 private void throwUnprotectedSwitchError(final VarNode varNode) { |
1016 private void throwUnprotectedSwitchError(final VarNode varNode) { |
1022 // Block scoped declarations in switch statements without explicit blocks should be declared |
1017 // Block scoped declarations in switch statements without explicit blocks should be declared |
1023 // in a common block that contains all the case clauses. We cannot support this without a |
1018 // in a common block that contains all the case clauses. We cannot support this without a |