Package com.google.caja.parser.js

Examples of com.google.caja.parser.js.Operation


        }
      }
      if (!(first instanceof ExpressionStmt)) { break; }
      Expression e = ((ExpressionStmt) first).getExpression();
      if (!Operation.is(e, Operator.ASSIGN)) { break; }
      Operation op = (Operation) e;
      Expression lhs = op.children().get(0);
      if (!(lhs instanceof Reference)) { break; }
      Reference r = (Reference) lhs;
      if (!unassigned.contains(r.getIdentifier())) { break; }
      // Don't return two with the same name, because we don't want to have
      // multiple var declarations for the same name.
View Full Code Here


              "handlerIndex", handlerIndex,
              "body", new ParseTreeNodeContainer(b.children()));
          handlers.add(new EventHandler(attr.env, handler));
          handlerCache.put(value, handlerIndexName);

          Operation urlAdapter = (Operation) QuasiBuilder.substV(
              ""
              + "'javascript:' + /*@synthetic*/encodeURIComponent("
              + "   'try{void ___.plugin_dispatchToHandler___('"
              + "    + ___./*@synthetic*/getId(IMPORTS___)"
              + "    + ',' + @handlerIndex + ',[{}])}catch(_){}')",
              "handlerIndex", new Reference(handlerIndex));
          urlAdapter.setFilePosition(pos);
          urlAdapter.getAttributes().set(HANDLER_NAME, handlerIndexName);
          dynamicValue = urlAdapter;
        } else {
          URI uri;
          try {
            uri = new URI(UriUtil.normalizeUri(value));
View Full Code Here

        || e instanceof ArrayConstructor || e instanceof ObjectConstructor
        || e instanceof FunctionConstructor) {
      return true;
    }
    if (!(e instanceof Operation)) { return false; }
    Operation op = (Operation) e;
    switch (op.getOperator()) {
      case ASSIGN:
      case DELETE:
      case POST_DECREMENT: case POST_INCREMENT:
      case PRE_DECREMENT: case PRE_INCREMENT:
      case VOID: // indicates value purposely ignored
        return false;
      case FUNCTION_CALL:
        return false;
      case CONSTRUCTOR:
        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,
        //    baz();
        // $FALL-THROUGH
      default:
        return op.getOperator().getCategory() != OperatorCategory.ASSIGNMENT;
    }
  }
View Full Code Here

    return es.parent.cast(ForEachLoop.class).node.getKeyReceiver() == es.node;
  }

  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

        }
      }
      if (!(first instanceof ExpressionStmt)) { break; }
      Expression e = ((ExpressionStmt) first).getExpression();
      if (!Operation.is(e, Operator.ASSIGN)) { break; }
      Operation op = (Operation) e;
      Expression lhs = op.children().get(0);
      if (!(lhs instanceof Reference)) { break; }
      Reference r = (Reference) lhs;
      if (!unassigned.contains(r.getIdentifier())) { break; }
      // Don't return two with the same name, because we don't want to have
      // multiple var declarations for the same name.
View Full Code Here

              "handlerIndex", handlerIndex,
              "body", new ParseTreeNodeContainer(b.children()));
          handlers.add(new EventHandler(attr.env, handler));
          handlerCache.put(value, handlerIndexName);

          Operation urlAdapter = (Operation) QuasiBuilder.substV(
              ""
              + "'javascript:' + /*@synthetic*/encodeURIComponent("
              + "   'try{void ___.plugin_dispatchToHandler___('"
              + "    + ___./*@synthetic*/getId(IMPORTS___)"
              + "    + ',' + @handlerIndex + ',[{}])}catch(_){}')",
              "handlerIndex", new Reference(handlerIndex));
          urlAdapter.setFilePosition(pos);
          urlAdapter.getAttributes().set(HANDLER_NAME, handlerIndexName);
          dynamicValue = urlAdapter;
        } else {
          URI uri;
          try {
            uri = new URI(UriUtil.normalizeUri(value));
View Full Code Here

      childScope = Scope.fromCatchStmt(s, (CatchStmt) n);
    } else if (n instanceof Reference) {
      String name = ((Reference) n).getIdentifierName();
      if (isOuter(name, s)) { outers.add(name); }
    } else if (Operation.is(n, Operator.MEMBER_ACCESS)) {
      Operation op = (Operation) n;
      checkScope(op.children().get(0), s, outers);
      return;
    }
    for (ParseTreeNode child : n.children()) {
      checkScope(child, childScope, outers);
    }
View Full Code Here

  }

  static boolean isStringy(Expression e, boolean strict) {
    if (e instanceof StringLiteral) { return true; }
    if (e instanceof Operation) {
      Operation op = (Operation) e;
      List<? extends Expression> operands = op.children();
      switch (op.getOperator()) {
        case ADDITION:
          return isStringy(operands.get(0), false)
              || isStringy(operands.get(1), false);
        case TERNARY:
        case LOGICAL_AND:
View Full Code Here

  static Expression makeStringy(Expression e, boolean strict) {
    if (isStringy(e, strict)) { return e; }

    Expression stringier = null;
    if (e instanceof Operation) {
      Operation op = (Operation) e;
      List<? extends Expression> operands = op.children();
      switch (op.getOperator()) {
        // Change arguments to ||,&& would change semantics.
        case TERNARY:
          stringier = Operation.create(
              e.getFilePosition(), Operator.TERNARY, operands.get(0),
              makeStringy(operands.get(1), strict),
View Full Code Here

    return e instanceof Operation && op == ((Operation) e).getOperator();
  }

  static boolean isStringConcat(Expression e) {
    if (!is(e, Operator.ADDITION)) { return false; }
    Operation op = (Operation) e;
    return isStringy(op.children().get(0), false)
        || isStringy(op.children().get(1), false);
  }
View Full Code Here

TOP

Related Classes of com.google.caja.parser.js.Operation

Copyright © 2018 www.massapicom. 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.