Package com.google.caja.parser.js

Examples of com.google.caja.parser.js.Operation.children()


        return true;
      case LOGICAL_AND: case LOGICAL_OR:
        return shouldBeEvaluatedForValue(op.children().get(1));
      case TERNARY:
        return shouldBeEvaluatedForValue(op.children().get(1))
            && shouldBeEvaluatedForValue(op.children().get(2));
      case COMMA:
        // We do not allow comma, since bad things happen when commas are used.
        // Consider
        //    if (foo)
        //      return bar,
View Full Code Here


  private static boolean isCommaOperationNotEvaluatedForValue(Expression e) {
    if (!(e instanceof Operation)) { return false; }
    Operation op = (Operation) e;
    if (op.getOperator() != Operator.COMMA) { return false; }
    Expression left = op.children().get(0), right = op.children().get(1);
    return !shouldBeEvaluatedForValue(right)
        && (!shouldBeEvaluatedForValue(left)
            || isCommaOperationNotEvaluatedForValue(left));
  }
View Full Code Here

  private static boolean isCommaOperationNotEvaluatedForValue(Expression e) {
    if (!(e instanceof Operation)) { return false; }
    Operation op = (Operation) e;
    if (op.getOperator() != Operator.COMMA) { return false; }
    Expression left = op.children().get(0), right = op.children().get(1);
    return !shouldBeEvaluatedForValue(right)
        && (!shouldBeEvaluatedForValue(left)
            || isCommaOperationNotEvaluatedForValue(left));
  }
View Full Code Here

    putFact(e, digest, fact);

    // Infer extra facts
    if (e instanceof Operation) {
      Operation op = ((Operation) e);
      List<? extends Expression> operands = op.children();
      switch (op.getOperator()) {
        case NOT:
          // If (!x) then x is falsey.
          addFuzzyFact(operands.get(0), !fact.isTruthy());
          break;
View Full Code Here

      case EQUAL: case STRICTLY_EQUAL: eq = true; break;
      case NOT_EQUAL: case STRICTLY_NOT_EQUAL: eq = false; break;
      default: return null;
    }
    strict = o == Operator.STRICTLY_EQUAL || o == Operator.STRICTLY_NOT_EQUAL;
    List<? extends Expression> operands = op.children();
    Expression a = operands.get(0);
    Expression b = operands.get(1);
    if (strict ? isUndefOrLiteral(a) : isNullOrUndef(a)) {
      // continue to check
    } else if (strict ? isUndefOrLiteral(b) : isNullOrUndef(b)) {
View Full Code Here

      if (e instanceof Reference) { return ((Reference) e).getIdentifierName(); }
      if (!(e instanceof Operation)) { return null; }
      Operation op = (Operation) e;
      switch (op.getOperator()) {
        case MEMBER_ACCESS: case SQUARE_BRACKET:
          e = op.children().get(0);
          break;
        default: return null;
      }
    }
  }
View Full Code Here

    if (e instanceof Reference) {
      return Operation.createInfix(
          Operator.MEMBER_ACCESS, new Reference(new Identifier(UNK, lhs)), e);
    } else {
      Operation op = (Operation) e;
      List<? extends Expression> operands = op.children();
      return Operation.create(
          e.getFilePosition(), op.getOperator(),
          withTopRef(operands.get(0), lhs), operands.get(1));
    }
  }
View Full Code Here

    }
  }

  private static Expression withoutTopRef(Expression e) {
    Operation op = (Operation) e;
    List<? extends Expression> operands = op.children();
    Expression obj = operands.get(0), prop = operands.get(1);
    if (obj instanceof Reference) { return prop; }
    return Operation.create(
        e.getFilePosition(), op.getOperator(), withoutTopRef(obj), prop);
  }
View Full Code Here

  }

  private static Expression rfold(Expression e, boolean isFn) {
    if (e instanceof Operation) {
      Operation o = (Operation) e;
      List<? extends Expression> children = o.children();
      Expression[] newChildren = null;
      boolean oIsFn = o.getOperator() == Operator.FUNCTION_CALL;
      for (int i = 0, n = children.size(); i < n; ++i) {
        Expression operand = children.get(i);
        Expression newOperand = rfold(operand, oIsFn && i == 0);
View Full Code Here

  private static void optimize(ParseTreeNode node, ScopeTree t) {
    if (node instanceof Operation) {
      Operation op = (Operation) node;
      if (op.getOperator() == Operator.SQUARE_BRACKET) {
        Expression index = op.children().get(1);
        Set<String> expanding = new HashSet<String>();
        if (isVisiblePropertyExpr(index, t, expanding)) {
          Operation numIndex = Operation.create(
              index.getFilePosition(), Operator.TO_NUMBER, index);
          numIndex.setFilePosition(index.getFilePosition());
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.