MCPcopy Create free account
hub / github.com/mozilla/rhino / createIf

Method createIf

rhino/src/main/java/org/mozilla/javascript/IRFactory.java:1969–2005  ·  view source on GitHub ↗
(Node cond, Node ifTrue, Node ifFalse, int lineno, int column)

Source from the content-addressed store, hash-verified

1967 }
1968
1969 private static Node createIf(Node cond, Node ifTrue, Node ifFalse, int lineno, int column) {
1970 int condStatus = isAlwaysDefinedBoolean(cond);
1971 if (condStatus == ALWAYS_TRUE_BOOLEAN) {
1972 return ifTrue;
1973 } else if (condStatus == ALWAYS_FALSE_BOOLEAN) {
1974 if (ifFalse != null) {
1975 return ifFalse;
1976 }
1977 // Replace if (false) xxx by empty block
1978 return new Node(Token.BLOCK, lineno, column);
1979 }
1980
1981 Node result = new Node(Token.BLOCK, lineno, column);
1982 Node ifNotTarget = Node.newTarget();
1983 Jump IFNE = new Jump(Token.IFNE, cond);
1984 IFNE.target = ifNotTarget;
1985
1986 result.addChildToBack(IFNE);
1987 result.addChildrenToBack(ifTrue);
1988
1989 if (ifFalse != null) {
1990 Node endTarget = Node.newTarget();
1991 result.addChildToBack(makeJump(Token.GOTO, endTarget));
1992 result.addChildToBack(ifNotTarget);
1993 result.addChildrenToBack(ifFalse);
1994 result.addChildToBack(endTarget);
1995 } else {
1996 result.addChildToBack(ifNotTarget);
1997 }
1998
1999 if (cond.getFirstChild() != null) {
2000 Node conditionalChild = cond.getFirstChild();
2001 result.setLineColumnNumber(conditionalChild.getLineno(), conditionalChild.getColumn());
2002 }
2003
2004 return result;
2005 }
2006
2007 private static Node createCondExpr(Node cond, Node ifTrue, Node ifFalse) {
2008 int condStatus = isAlwaysDefinedBoolean(cond);

Callers 5

transformFunctionMethod · 0.95
transformIfMethod · 0.95
createTryCatchFinallyMethod · 0.95

Calls 9

newTargetMethod · 0.95
addChildToBackMethod · 0.95
addChildrenToBackMethod · 0.95
makeJumpMethod · 0.95
setLineColumnNumberMethod · 0.95
getLinenoMethod · 0.95
getColumnMethod · 0.95
getFirstChildMethod · 0.80

Tested by

no test coverage detected