src/jdk/nashorn/internal/ir/debug/JSONWriter.java
Print this page
*** 25,34 ****
--- 25,35 ----
package jdk.nashorn.internal.ir.debug;
import java.util.Arrays;
import java.util.List;
+ import java.util.ArrayList;
import jdk.nashorn.internal.codegen.CompilerConstants;
import jdk.nashorn.internal.ir.AccessNode;
import jdk.nashorn.internal.ir.BinaryNode;
import jdk.nashorn.internal.ir.Block;
import jdk.nashorn.internal.ir.BlockStatement;
*** 195,208 ****
type("BreakStatement");
comma();
final IdentNode label = breakNode.getLabel();
if (label != null) {
! property("label", label.getName());
} else {
- property("label");
nullValue();
}
return leave();
}
--- 196,209 ----
type("BreakStatement");
comma();
final IdentNode label = breakNode.getLabel();
+ property("label");
if (label != null) {
! label.accept(this);
} else {
nullValue();
}
return leave();
}
*** 254,270 ****
property("param");
catchNode.getException().accept(this);
comma();
final Node guard = catchNode.getExceptionCondition();
- property("guard");
if (guard != null) {
guard.accept(this);
- } else {
- nullValue();
- }
comma();
property("body");
catchNode.getBody().accept(this);
return leave();
--- 255,269 ----
property("param");
catchNode.getException().accept(this);
comma();
final Node guard = catchNode.getExceptionCondition();
if (guard != null) {
+ property("guard");
guard.accept(this);
comma();
+ }
property("body");
catchNode.getBody().accept(this);
return leave();
*** 276,289 ****
type("ContinueStatement");
comma();
final IdentNode label = continueNode.getLabel();
if (label != null) {
! property("label", label.getName());
} else {
- property("label");
nullValue();
}
return leave();
}
--- 275,288 ----
type("ContinueStatement");
comma();
final IdentNode label = continueNode.getLabel();
+ property("label");
if (label != null) {
! label.accept(this);
} else {
nullValue();
}
return leave();
}
*** 297,313 ****
return leave();
}
@Override
public boolean enterExpressionStatement(final ExpressionStatement expressionStatement) {
enterDefault(expressionStatement);
type("ExpressionStatement");
comma();
property("expression");
! expressionStatement.getExpression().accept(this);
return leave();
}
@Override
--- 296,319 ----
return leave();
}
@Override
public boolean enterExpressionStatement(final ExpressionStatement expressionStatement) {
+ // handle debugger statement
+ final Node expression = expressionStatement.getExpression();
+ if (expression instanceof RuntimeNode) {
+ expression.accept(this);
+ return false;
+ }
+
enterDefault(expressionStatement);
type("ExpressionStatement");
comma();
property("expression");
! expression.accept(this);
return leave();
}
@Override
*** 386,428 ****
return leave();
}
@Override
public boolean enterFunctionNode(final FunctionNode functionNode) {
- enterDefault(functionNode);
-
final boolean program = functionNode.isProgram();
- final String name;
if (program) {
! name = "Program";
! } else if (functionNode.isDeclared()) {
name = "FunctionDeclaration";
} else {
name = "FunctionExpression";
}
type(name);
comma();
- if (! program) {
property("id");
if (functionNode.isAnonymous()) {
nullValue();
} else {
functionNode.getIdent().accept(this);
}
comma();
! }
property("rest");
nullValue();
comma();
! if (!program) {
! array("params", functionNode.getParameters());
comma();
}
// body consists of nested functions and statements
final List<Statement> stats = functionNode.getBody().getStatements();
final int size = stats.size();
int idx = 0;
arrayStart("body");
--- 392,452 ----
return leave();
}
@Override
public boolean enterFunctionNode(final FunctionNode functionNode) {
final boolean program = functionNode.isProgram();
if (program) {
! return emitProgram(functionNode);
! }
!
! enterDefault(functionNode);
! final String name;
! if (functionNode.isDeclared()) {
name = "FunctionDeclaration";
} else {
name = "FunctionExpression";
}
type(name);
comma();
property("id");
if (functionNode.isAnonymous()) {
nullValue();
} else {
functionNode.getIdent().accept(this);
}
comma();
!
! array("params", functionNode.getParameters());
! comma();
!
! arrayStart("defaults");
! arrayEnd();
! comma();
property("rest");
nullValue();
comma();
! property("body");
! functionNode.getBody().accept(this);
! comma();
!
! property("generator", false);
comma();
+
+ property("expression", false);
+
+ return leave();
}
+ private boolean emitProgram(final FunctionNode functionNode) {
+ enterDefault(functionNode);
+ type("Program");
+ comma();
+
// body consists of nested functions and statements
final List<Statement> stats = functionNode.getBody().getStatements();
final int size = stats.size();
int idx = 0;
arrayStart("body");
*** 728,738 ****
property("block");
tryNode.getBody().accept(this);
comma();
! array("handlers", tryNode.getCatches());
comma();
property("finalizer");
final Node finallyNode = tryNode.getFinallyBody();
if (finallyNode != null) {
--- 752,786 ----
property("block");
tryNode.getBody().accept(this);
comma();
!
! final List<? extends Node> catches = tryNode.getCatches();
! final List<CatchNode> guarded = new ArrayList<>();
! CatchNode unguarded = null;
! if (catches != null) {
! for (Node n : catches) {
! CatchNode cn = (CatchNode)n;
! if (cn.getExceptionCondition() != null) {
! guarded.add(cn);
! } else {
! assert unguarded == null: "too many unguarded?";
! unguarded = cn;
! }
! }
! }
!
! array("guardedHandlers", guarded);
! comma();
!
! property("handler");
! if (unguarded != null) {
! unguarded.accept(this);
! } else {
! nullValue();
! }
comma();
property("finalizer");
final Node finallyNode = tryNode.getFinallyBody();
if (finallyNode != null) {
*** 758,769 ****
callNode.getFunction().accept(this);
comma();
array("arguments", callNode.getArgs());
} else {
- final boolean prefix;
final String operator;
switch (tokenType) {
case INCPOSTFIX:
prefix = false;
operator = "++";
break;
--- 806,817 ----
callNode.getFunction().accept(this);
comma();
array("arguments", callNode.getArgs());
} else {
final String operator;
+ final boolean prefix;
switch (tokenType) {
case INCPOSTFIX:
prefix = false;
operator = "++";
break;
*** 778,789 ****
case DECPREFIX:
operator = "--";
prefix = true;
break;
default:
! prefix = false;
operator = tokenType.getName();
}
type(unaryNode.isAssignment()? "UpdateExpression" : "UnaryExpression");
comma();
--- 826,838 ----
case DECPREFIX:
operator = "--";
prefix = true;
break;
default:
! prefix = true;
operator = tokenType.getName();
+ break;
}
type(unaryNode.isAssignment()? "UpdateExpression" : "UnaryExpression");
comma();
*** 800,809 ****
--- 849,866 ----
return leave();
}
@Override
public boolean enterVarNode(final VarNode varNode) {
+ final Node init = varNode.getInit();
+ if (init instanceof FunctionNode && ((FunctionNode)init).isDeclared()) {
+ // function declaration - don't emit VariableDeclaration instead
+ // just emit FunctionDeclaration using 'init' Node.
+ init.accept(this);
+ return false;
+ }
+
enterDefault(varNode);
type("VariableDeclaration");
comma();
*** 814,828 ****
location(varNode.getName());
type("VariableDeclarator");
comma();
! property("id", varNode.getName().toString());
comma();
property("init");
- final Node init = varNode.getInit();
if (init != null) {
init.accept(this);
} else {
nullValue();
}
--- 871,885 ----
location(varNode.getName());
type("VariableDeclarator");
comma();
! property("id");
! varNode.getName().accept(this);
comma();
property("init");
if (init != null) {
init.accept(this);
} else {
nullValue();
}
*** 853,863 ****
} else {
property("test");
whileNode.getTest().accept(this);
comma();
! property("block");
whileNode.getBody().accept(this);
}
return leave();
}
--- 910,920 ----
} else {
property("test");
whileNode.getTest().accept(this);
comma();
! property("body");
whileNode.getBody().accept(this);
}
return leave();
}
*** 892,918 ****
private String getString() {
return buf.toString();
}
! private void property(final String key, final String value) {
buf.append('"');
buf.append(key);
buf.append("\":");
if (value != null) {
! buf.append('"');
buf.append(value);
! buf.append('"');
}
}
private void property(final String key, final boolean value) {
! property(key, Boolean.toString(value));
}
private void property(final String key, final int value) {
! property(key, Integer.toString(value));
}
private void property(final String key) {
property(key, null);
}
--- 949,979 ----
private String getString() {
return buf.toString();
}
! private void property(final String key, final String value, final boolean escape) {
buf.append('"');
buf.append(key);
buf.append("\":");
if (value != null) {
! if (escape) buf.append('"');
buf.append(value);
! if (escape) buf.append('"');
! }
}
+
+ private void property(final String key, final String value) {
+ property(key, value, true);
}
private void property(final String key, final boolean value) {
! property(key, Boolean.toString(value), false);
}
private void property(final String key, final int value) {
! property(key, Integer.toString(value), false);
}
private void property(final String key) {
property(key, null);
}