private void handle(AstNode block) { Node child = block.getFirstChild(); while (child != null) { Node next = child.getNext(); if (child instanceof ExpressionStatement) { ExpressionStatement statement = (ExpressionStatement) child; if (statement.getExpression() instanceof StringLiteral) { block.removeChild(child); } } child = next; } } }
private static Node addBeforeCurrent(Node parent, Node previous, Node current, Node toAdd) { if (previous == null) { if (!(current == parent.getFirstChild())) Kit.codeBug(); parent.addChildToFront(toAdd); } else { if (!(current == previous.getNext())) Kit.codeBug(); parent.addChildAfter(toAdd, previous); } return toAdd; }
private int getLocalBlockRef(Node node) { Node localBlock = (Node)node.getProp(Node.LOCAL_BLOCK_PROP); return localBlock.getExistingIntProp(Node.LOCAL_PROP); }
private Node createWith(Node obj, Node body, int lineno) { setRequiresActivation(); Node result = new Node(Token.BLOCK, lineno); result.addChildToBack(new Node(Token.ENTERWITH, obj)); Node bodyNode = new Node(Token.WITH, body, lineno); result.addChildrenToBack(bodyNode); result.addChildToBack(new Node(Token.LEAVEWITH)); return result; }
private Node transformScript(ScriptNode node) { decompiler.addToken(Token.SCRIPT); if (currentScope != null) Kit.codeBug(); currentScope = node; Node body = new Node(Token.BLOCK); for (Node kid : node) { body.addChildToBack(transform((AstNode)kid)); } node.removeChildren(); Node children = body.getFirstChild(); if (children != null) { node.addChildrenToBack(children); } return node; }
private static void buildStatementList_r(Node node, ObjArray statements) { int type = node.getType(); if (type == Token.BLOCK || type == Token.LOCAL_BLOCK || type == Token.LOOP || type == Token.FUNCTION) { Node child = node.getFirstChild(); while (child != null) { buildStatementList_r(child, statements); child = child.getNext(); } } else { statements.add(node); } }
private Node createName(int type, String name, Node child) { Node result = createName(name); result.setType(type); if (child != null) result.addChildToBack(child); return result; }
private boolean getterSetterProperty(ObjArray elems, Object property, boolean isGetter) throws IOException { Node f = function(FunctionNode.FUNCTION_EXPRESSION); if (f.getType() != Token.FUNCTION) { reportError("msg.bad.prop"); return false; } int fnIndex = f.getExistingIntProp(Node.FUNCTION_PROP); FunctionNode fn = currentScriptOrFn.getFunctionNode(fnIndex); if (fn.getFunctionName().length() != 0) { reportError("msg.bad.prop"); return false; } elems.add(property); if (isGetter) { elems.add(nf.createUnary(Token.GET, f)); } else { elems.add(nf.createUnary(Token.SET, f)); } return true; } }
private void visitSetConst(Node node, Node child) { String name = node.getFirstChild().getString(); while (child != null) { generateExpression(child, node); child = child.getNext(); } cfw.addALoad(contextLocal); cfw.addPush(name); addScriptRuntimeInvoke( "setConst", "(Lorg/mozilla/javascript/Scriptable;" +"Ljava/lang/Object;" +"Lorg/mozilla/javascript/Context;" +"Ljava/lang/String;" +")Ljava/lang/Object;"); }
private static boolean isArithmeticNode(Node node) { int type = node.getType(); return (type == Token.SUB) || (type == Token.MOD) || (type == Token.DIV) || (type == Token.MUL); }
private static Node replaceCurrent(Node parent, Node previous, Node current, Node replacement) { if (previous == null) { if (!(current == parent.getFirstChild())) Kit.codeBug(); parent.replaceChild(current, replacement); } else if (previous.next == current) { // Check cachedPrev.next == current is necessary due to possible // tree mutations parent.replaceChildAfter(previous, replacement); } else { parent.replaceChild(current, replacement); } return replacement; }
private boolean convertParameter(Node n) { if (inDirectCallFunction && n.getType() == Token.GETVAR) { int varIndex = theFunction.getVarIndex(n); if (theFunction.isParameter(varIndex)) { n.removeProp(Node.ISNUMBER_PROP); return true; } } return false; }
/** * Sets the JsDoc comment string attached to this node. */ public void setJsDocNode(Comment jsdocNode) { putProp(JSDOC_PROP, jsdocNode); }
private Node expr(boolean inForInit) throws IOException, ParserException { Node pn = assignExpr(inForInit); while (matchToken(Token.COMMA)) { decompiler.addToken(Token.COMMA); if (compilerEnv.isStrictMode() && !pn.hasSideEffects()) addStrictWarning("msg.no.side.effects", ""); pn = nf.createBinary(Token.COMMA, pn, assignExpr(inForInit)); } return pn; }
/** * Leaf */ Node createLeaf(int nodeType) { return new Node(nodeType); }
/** * Regular expressions */ Node createRegExp(int regexpIndex) { Node n = new Node(Token.REGEXP); n.putIntProp(Node.REGEXP_PROP, regexpIndex); return n; }
Node createPropertyGet(Node target, String namespace, String name, int memberTypeFlags) { if (namespace == null && memberTypeFlags == 0) { if (target == null) { return createName(name); } checkActivationName(name, Token.GETPROP); if (ScriptRuntime.isSpecialProperty(name)) { Node ref = new Node(Token.REF_SPECIAL, target); ref.putProp(Node.NAME_PROP, name); return new Node(Token.GET_REF, ref); } return new Node(Token.GETPROP, target, createString(name)); } Node elem = createString(name); memberTypeFlags |= Node.PROPERTY_FLAG; return createMemberRefGet(target, namespace, elem, memberTypeFlags); }