Java Code Examples for com.google.javascript.rhino.jstype.TernaryValue#FALSE

The following examples show how to use com.google.javascript.rhino.jstype.TernaryValue#FALSE . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Cardumen_00200_s.java    From coming with MIT License 6 votes vote down vote up
/**
 * Copied from Rhino's ScriptRuntime
 */
public static TernaryValue isStrWhiteSpaceChar(int c) {
  switch (c) {
    case '\u000B': // <VT>
      return TernaryValue.UNKNOWN;  // IE says "no", ECMAScript says "yes"
    case ' ': // <SP>
    case '\n': // <LF>
    case '\r': // <CR>
    case '\t': // <TAB>
    case '\u00A0': // <NBSP>
    case '\u000C': // <FF>
    case '\u2028': // <LS>
    case '\u2029': // <PS>
    case '\uFEFF': // <BOM>
      return TernaryValue.TRUE;
    default:
      return (Character.getType(c) == Character.SPACE_SEPARATOR)
          ? TernaryValue.TRUE : TernaryValue.FALSE;
  }
}
 
Example 2
Source File: jKali_003_s.java    From coming with MIT License 6 votes vote down vote up
/**
 * Copied from Rhino's ScriptRuntime
 */
public static TernaryValue isStrWhiteSpaceChar(int c) {
  switch (c) {
    case '\u000B': // <VT>
      return TernaryValue.UNKNOWN;  // IE says "no", ECMAScript says "yes"
    case ' ': // <SP>
    case '\n': // <LF>
    case '\r': // <CR>
    case '\t': // <TAB>
    case '\u00A0': // <NBSP>
    case '\u000C': // <FF>
    case '\u2028': // <LS>
    case '\u2029': // <PS>
    case '\uFEFF': // <BOM>
      return TernaryValue.TRUE;
    default:
      return (Character.getType(c) == Character.SPACE_SEPARATOR)
          ? TernaryValue.TRUE : TernaryValue.FALSE;
  }
}
 
Example 3
Source File: Closure_10_NodeUtil_s.java    From coming with MIT License 6 votes vote down vote up
/**
 * Copied from Rhino's ScriptRuntime
 */
public static TernaryValue isStrWhiteSpaceChar(int c) {
  switch (c) {
    case '\u000B': // <VT>
      return TernaryValue.UNKNOWN;  // IE says "no", ECMAScript says "yes"
    case ' ': // <SP>
    case '\n': // <LF>
    case '\r': // <CR>
    case '\t': // <TAB>
    case '\u00A0': // <NBSP>
    case '\u000C': // <FF>
    case '\u2028': // <LS>
    case '\u2029': // <PS>
    case '\uFEFF': // <BOM>
      return TernaryValue.TRUE;
    default:
      return (Character.getType(c) == Character.SPACE_SEPARATOR)
          ? TernaryValue.TRUE : TernaryValue.FALSE;
  }
}
 
Example 4
Source File: Closure_61_NodeUtil_s.java    From coming with MIT License 6 votes vote down vote up
/**
 * Copied from Rhino's ScriptRuntime
 */
static TernaryValue isStrWhiteSpaceChar(int c) {
  switch (c) {
    case '\u000B': // <VT>
      return TernaryValue.UNKNOWN;  // IE says "no", EcmaScript says "yes"
    case ' ': // <SP>
    case '\n': // <LF>
    case '\r': // <CR>
    case '\t': // <TAB>
    case '\u00A0': // <NBSP>
    case '\u000C': // <FF>
    case '\u2028': // <LS>
    case '\u2029': // <PS>
    case '\uFEFF': // <BOM>
      return TernaryValue.TRUE;
    default:
      return (Character.getType(c) == Character.SPACE_SEPARATOR)
          ? TernaryValue.TRUE : TernaryValue.FALSE;
  }
}
 
Example 5
Source File: Cardumen_00149_t.java    From coming with MIT License 6 votes vote down vote up
/**
 * Copied from Rhino's ScriptRuntime
 */
public static TernaryValue isStrWhiteSpaceChar(int c) {
  switch (c) {
    case '\u000B': // <VT>
      return TernaryValue.UNKNOWN;  // IE says "no", ECMAScript says "yes"
    case ' ': // <SP>
    case '\n': // <LF>
    case '\r': // <CR>
    case '\t': // <TAB>
    case '\u00A0': // <NBSP>
    case '\u000C': // <FF>
    case '\u2028': // <LS>
    case '\u2029': // <PS>
    case '\uFEFF': // <BOM>
      return TernaryValue.TRUE;
    default:
      return (Character.getType(c) == Character.SPACE_SEPARATOR)
          ? TernaryValue.TRUE : TernaryValue.FALSE;
  }
}
 
Example 6
Source File: jKali_003_t.java    From coming with MIT License 6 votes vote down vote up
/**
 * Copied from Rhino's ScriptRuntime
 */
public static TernaryValue isStrWhiteSpaceChar(int c) {
  switch (c) {
    case '\u000B': // <VT>
      return TernaryValue.UNKNOWN;  // IE says "no", ECMAScript says "yes"
    case ' ': // <SP>
    case '\n': // <LF>
    case '\r': // <CR>
    case '\t': // <TAB>
    case '\u00A0': // <NBSP>
    case '\u000C': // <FF>
    case '\u2028': // <LS>
    case '\u2029': // <PS>
    case '\uFEFF': // <BOM>
      return TernaryValue.TRUE;
    default:
      return (Character.getType(c) == Character.SPACE_SEPARATOR)
          ? TernaryValue.TRUE : TernaryValue.FALSE;
  }
}
 
Example 7
Source File: Cardumen_0014_t.java    From coming with MIT License 6 votes vote down vote up
/**
 * Copied from Rhino's ScriptRuntime
 */
public static TernaryValue isStrWhiteSpaceChar(int c) {
  switch (c) {
    case '\u000B': // <VT>
      return TernaryValue.UNKNOWN;  // IE says "no", ECMAScript says "yes"
    case ' ': // <SP>
    case '\n': // <LF>
    case '\r': // <CR>
    case '\t': // <TAB>
    case '\u00A0': // <NBSP>
    case '\u000C': // <FF>
    case '\u2028': // <LS>
    case '\u2029': // <PS>
    case '\uFEFF': // <BOM>
      return TernaryValue.TRUE;
    default:
      return (Character.getType(c) == Character.SPACE_SEPARATOR)
          ? TernaryValue.TRUE : TernaryValue.FALSE;
  }
}
 
Example 8
Source File: NodeUtil.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Copied from Rhino's ScriptRuntime
 */
public static TernaryValue isStrWhiteSpaceChar(int c) {
  switch (c) {
    case '\u000B': // <VT>
      return TernaryValue.UNKNOWN;  // IE says "no", ECMAScript says "yes"
    case ' ': // <SP>
    case '\n': // <LF>
    case '\r': // <CR>
    case '\t': // <TAB>
    case '\u00A0': // <NBSP>
    case '\u000C': // <FF>
    case '\u2028': // <LS>
    case '\u2029': // <PS>
    case '\uFEFF': // <BOM>
      return TernaryValue.TRUE;
    default:
      return (Character.getType(c) == Character.SPACE_SEPARATOR)
          ? TernaryValue.TRUE : TernaryValue.FALSE;
  }
}
 
Example 9
Source File: Cardumen_0014_s.java    From coming with MIT License 6 votes vote down vote up
/**
 * Copied from Rhino's ScriptRuntime
 */
public static TernaryValue isStrWhiteSpaceChar(int c) {
  switch (c) {
    case '\u000B': // <VT>
      return TernaryValue.UNKNOWN;  // IE says "no", ECMAScript says "yes"
    case ' ': // <SP>
    case '\n': // <LF>
    case '\r': // <CR>
    case '\t': // <TAB>
    case '\u00A0': // <NBSP>
    case '\u000C': // <FF>
    case '\u2028': // <LS>
    case '\u2029': // <PS>
    case '\uFEFF': // <BOM>
      return TernaryValue.TRUE;
    default:
      return (Character.getType(c) == Character.SPACE_SEPARATOR)
          ? TernaryValue.TRUE : TernaryValue.FALSE;
  }
}
 
Example 10
Source File: Cardumen_0087_s.java    From coming with MIT License 6 votes vote down vote up
/**
 * Copied from Rhino's ScriptRuntime
 */
public static TernaryValue isStrWhiteSpaceChar(int c) {
  switch (c) {
    case '\u000B': // <VT>
      return TernaryValue.UNKNOWN;  // IE says "no", ECMAScript says "yes"
    case ' ': // <SP>
    case '\n': // <LF>
    case '\r': // <CR>
    case '\t': // <TAB>
    case '\u00A0': // <NBSP>
    case '\u000C': // <FF>
    case '\u2028': // <LS>
    case '\u2029': // <PS>
    case '\uFEFF': // <BOM>
      return TernaryValue.TRUE;
    default:
      return (Character.getType(c) == Character.SPACE_SEPARATOR)
          ? TernaryValue.TRUE : TernaryValue.FALSE;
  }
}
 
Example 11
Source File: MinimizeExitPoints.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void visit(NodeTraversal t, Node n, Node parent) {
  switch (n.getType()) {
    case Token.LABEL:
      tryMinimizeExits(
          n.getLastChild(), Token.BREAK, n.getFirstChild().getString());
      break;

    case Token.FOR:
    case Token.WHILE:
      tryMinimizeExits(
          NodeUtil.getLoopCodeBlock(n), Token.CONTINUE, null);
      break;

    case Token.DO:
      tryMinimizeExits(
          NodeUtil.getLoopCodeBlock(n), Token.CONTINUE, null);

      Node cond = NodeUtil.getConditionExpression(n);
      if (NodeUtil.getImpureBooleanValue(cond) == TernaryValue.FALSE) {
        // Normally, we wouldn't be able to optimize BREAKs inside a loop
        // but as we know the condition will always false, we can treat them
        // as we would a CONTINUE.
        tryMinimizeExits(
            n.getFirstChild(), Token.BREAK, null);
      }
      break;

    case Token.FUNCTION:
      tryMinimizeExits(
          n.getLastChild(), Token.RETURN, null);
      break;
  }
}
 
Example 12
Source File: Closure_86_NodeUtil_s.java    From coming with MIT License 5 votes vote down vote up
/**
 * Gets the boolean value of a node that represents a literal. This method
 * effectively emulates the <code>Boolean()</code> JavaScript cast function.
 */
static TernaryValue getBooleanValue(Node n) {
  switch (n.getType()) {
    case Token.STRING:
      return TernaryValue.forBoolean(n.getString().length() > 0);

    case Token.NUMBER:
      return TernaryValue.forBoolean(n.getDouble() != 0);

    case Token.NULL:
    case Token.FALSE:
    case Token.VOID:
      return TernaryValue.FALSE;

    case Token.NAME:
      String name = n.getString();
      if ("undefined".equals(name)
          || "NaN".equals(name)) {
        // We assume here that programs don't change the value of the keyword
        // undefined to something other than the value undefined.
        return TernaryValue.FALSE;
      } else if ("Infinity".equals(name)) {
        return TernaryValue.TRUE;
      }
      break;

    case Token.TRUE:
    case Token.ARRAYLIT:
    case Token.OBJECTLIT:
    case Token.REGEXP:
      return TernaryValue.TRUE;
  }

  return TernaryValue.UNKNOWN;
}
 
Example 13
Source File: PeepholeRemoveDeadCode.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Removes DOs that always evaluate to false. This leaves the
 * statements that were in the loop in a BLOCK node.
 * The block will be removed in a later pass, if possible.
 */
Node tryFoldDo(Node n) {
  Preconditions.checkArgument(n.isDo());

  Node cond = NodeUtil.getConditionExpression(n);
  if (NodeUtil.getImpureBooleanValue(cond) != TernaryValue.FALSE) {
    return n;
  }

  // TODO(johnlenz): The do-while can be turned into a label with
  // named breaks and the label optimized away (maybe).
  if (hasBreakOrContinue(n)) {
    return n;
  }

  Preconditions.checkState(
      NodeUtil.isControlStructureCodeBlock(n, n.getFirstChild()));
  Node block = n.removeFirstChild();

  Node parent =  n.getParent();
  parent.replaceChild(n, block);
  if (mayHaveSideEffects(cond)) {
    Node condStatement = IR.exprResult(cond.detachFromParent())
        .srcref(cond);
    parent.addChildAfter(condStatement, block);
  }
  reportCodeChange();

  return n;
}
 
Example 14
Source File: Closure_60_NodeUtil_s.java    From coming with MIT License 4 votes vote down vote up
/**
 * Gets the boolean value of a node that represents a literal. This method
 * effectively emulates the <code>Boolean()</code> JavaScript cast function
 * except it return UNKNOWN for known values with side-effects, use
 * getExpressionBooleanValue if you don't care about side-effects.
 */
static TernaryValue getPureBooleanValue(Node n) {
  switch (n.getType()) {
    case Token.STRING:
      return TernaryValue.forBoolean(n.getString().length() > 0);

    case Token.NUMBER:
      return TernaryValue.forBoolean(n.getDouble() != 0);

    case Token.NOT:
      return getPureBooleanValue(n.getLastChild()).not();

    case Token.NULL:
    case Token.FALSE:
      return TernaryValue.FALSE;

    case Token.VOID:
        return TernaryValue.FALSE;

    case Token.NAME:
      String name = n.getString();
      if ("undefined".equals(name)
          || "NaN".equals(name)) {
        // We assume here that programs don't change the value of the keyword
        // undefined to something other than the value undefined.
        return TernaryValue.FALSE;
      } else if ("Infinity".equals(name)) {
        return TernaryValue.TRUE;
      }
      break;

    case Token.TRUE:
    case Token.REGEXP:
      return TernaryValue.TRUE;

    case Token.ARRAYLIT:
    case Token.OBJECTLIT:
      if (!mayHaveSideEffects(n)) {
        return TernaryValue.TRUE;
      }
      break;
  }

  return TernaryValue.UNKNOWN;
}
 
Example 15
Source File: Closure_10_NodeUtil_s.java    From coming with MIT License 4 votes vote down vote up
/**
 * Gets the boolean value of a node that represents a literal. This method
 * effectively emulates the <code>Boolean()</code> JavaScript cast function
 * except it return UNKNOWN for known values with side-effects, use
 * getExpressionBooleanValue if you don't care about side-effects.
 */
static TernaryValue getPureBooleanValue(Node n) {
  switch (n.getType()) {
    case Token.STRING:
      return TernaryValue.forBoolean(n.getString().length() > 0);

    case Token.NUMBER:
      return TernaryValue.forBoolean(n.getDouble() != 0);

    case Token.NOT:
      return getPureBooleanValue(n.getLastChild()).not();

    case Token.NULL:
    case Token.FALSE:
      return TernaryValue.FALSE;

    case Token.VOID:
      if (!mayHaveSideEffects(n.getFirstChild())) {
        return TernaryValue.FALSE;
      }
      break;

    case Token.NAME:
      String name = n.getString();
      if ("undefined".equals(name)
          || "NaN".equals(name)) {
        // We assume here that programs don't change the value of the keyword
        // undefined to something other than the value undefined.
        return TernaryValue.FALSE;
      } else if ("Infinity".equals(name)) {
        return TernaryValue.TRUE;
      }
      break;

    case Token.TRUE:
    case Token.REGEXP:
      return TernaryValue.TRUE;

    case Token.ARRAYLIT:
    case Token.OBJECTLIT:
      if (!mayHaveSideEffects(n)) {
        return TernaryValue.TRUE;
      }
      break;
  }

  return TernaryValue.UNKNOWN;
}
 
Example 16
Source File: Closure_61_NodeUtil_t.java    From coming with MIT License 4 votes vote down vote up
/**
 * Gets the boolean value of a node that represents a literal. This method
 * effectively emulates the <code>Boolean()</code> JavaScript cast function
 * except it return UNKNOWN for known values with side-effects, use
 * getExpressionBooleanValue if you don't care about side-effects.
 */
static TernaryValue getPureBooleanValue(Node n) {
  switch (n.getType()) {
    case Token.STRING:
      return TernaryValue.forBoolean(n.getString().length() > 0);

    case Token.NUMBER:
      return TernaryValue.forBoolean(n.getDouble() != 0);

    case Token.NOT:
      return getPureBooleanValue(n.getLastChild()).not();

    case Token.NULL:
    case Token.FALSE:
    case Token.VOID:
      return TernaryValue.FALSE;

    case Token.NAME:
      String name = n.getString();
      if ("undefined".equals(name)
          || "NaN".equals(name)) {
        // We assume here that programs don't change the value of the keyword
        // undefined to something other than the value undefined.
        return TernaryValue.FALSE;
      } else if ("Infinity".equals(name)) {
        return TernaryValue.TRUE;
      }
      break;

    case Token.TRUE:
    case Token.REGEXP:
      return TernaryValue.TRUE;

    case Token.ARRAYLIT:
    case Token.OBJECTLIT:
      if (!mayHaveSideEffects(n)) {
        return TernaryValue.TRUE;
      }
  }

  return TernaryValue.UNKNOWN;
}
 
Example 17
Source File: Cardumen_0087_t.java    From coming with MIT License 4 votes vote down vote up
/**
 * Gets the boolean value of a node that represents a literal. This method
 * effectively emulates the <code>Boolean()</code> JavaScript cast function
 * except it return UNKNOWN for known values with side-effects, use
 * getExpressionBooleanValue if you don't care about side-effects.
 */
static TernaryValue getPureBooleanValue(Node n) {
  switch (n.getType()) {
    case Token.STRING:
      return TernaryValue.forBoolean(n.getString().length() > 0);

    case Token.NUMBER:
      return TernaryValue.forBoolean(n.getDouble() != 0);

    case Token.NOT:
      return getPureBooleanValue(n.getLastChild()).not();

    case Token.NULL:
    case Token.FALSE:
      return TernaryValue.FALSE;

    case Token.VOID:
      if (!mayHaveSideEffects(n.getFirstChild())) {
        return TernaryValue.FALSE;
      }
      break;

    case Token.NAME:
      String name = n.getString();
      if ("undefined".equals(name)
          || "NaN".equals(name)) {
        // We assume here that programs don't change the value of the keyword
        // undefined to something other than the value undefined.
        return TernaryValue.FALSE;
      } else if ("Infinity".equals(name)) {
        return TernaryValue.TRUE;
      }
      break;

    case Token.TRUE:
    case Token.REGEXP:
      return TernaryValue.TRUE;

    case Token.ARRAYLIT:
    case Token.OBJECTLIT:
      if (!mayHaveSideEffects(n)) {
        return TernaryValue.TRUE;
      }
      break;
  }

  return TernaryValue.UNKNOWN;
}
 
Example 18
Source File: jKali_003_s.java    From coming with MIT License 4 votes vote down vote up
/**
 * Gets the boolean value of a node that represents a literal. This method
 * effectively emulates the <code>Boolean()</code> JavaScript cast function
 * except it return UNKNOWN for known values with side-effects, use
 * getExpressionBooleanValue if you don't care about side-effects.
 */
static TernaryValue getPureBooleanValue(Node n) {
  switch (n.getType()) {
    case Token.STRING:
      return TernaryValue.forBoolean(n.getString().length() > 0);

    case Token.NUMBER:
      return TernaryValue.forBoolean(n.getDouble() != 0);

    case Token.NOT:
      return getPureBooleanValue(n.getLastChild()).not();

    case Token.NULL:
    case Token.FALSE:
      return TernaryValue.FALSE;

    case Token.VOID:
      if (!mayHaveSideEffects(n.getFirstChild())) {
        return TernaryValue.FALSE;
      }
      break;

    case Token.NAME:
      String name = n.getString();
      if ("undefined".equals(name)
          || "NaN".equals(name)) {
        // We assume here that programs don't change the value of the keyword
        // undefined to something other than the value undefined.
        return TernaryValue.FALSE;
      } else if ("Infinity".equals(name)) {
        return TernaryValue.TRUE;
      }
      break;

    case Token.TRUE:
    case Token.REGEXP:
      return TernaryValue.TRUE;

    case Token.ARRAYLIT:
    case Token.OBJECTLIT:
      if (!mayHaveSideEffects(n)) {
        return TernaryValue.TRUE;
      }
      break;
  }

  return TernaryValue.UNKNOWN;
}
 
Example 19
Source File: Cardumen_00149_s.java    From coming with MIT License 4 votes vote down vote up
/**
 * Gets the boolean value of a node that represents a literal. This method
 * effectively emulates the <code>Boolean()</code> JavaScript cast function
 * except it return UNKNOWN for known values with side-effects, use
 * getExpressionBooleanValue if you don't care about side-effects.
 */
static TernaryValue getPureBooleanValue(Node n) {
  switch (n.getType()) {
    case Token.STRING:
      return TernaryValue.forBoolean(n.getString().length() > 0);

    case Token.NUMBER:
      return TernaryValue.forBoolean(n.getDouble() != 0);

    case Token.NOT:
      return getPureBooleanValue(n.getLastChild()).not();

    case Token.NULL:
    case Token.FALSE:
      return TernaryValue.FALSE;

    case Token.VOID:
      if (!mayHaveSideEffects(n.getFirstChild())) {
        return TernaryValue.FALSE;
      }
      break;

    case Token.NAME:
      String name = n.getString();
      if ("undefined".equals(name)
          || "NaN".equals(name)) {
        // We assume here that programs don't change the value of the keyword
        // undefined to something other than the value undefined.
        return TernaryValue.FALSE;
      } else if ("Infinity".equals(name)) {
        return TernaryValue.TRUE;
      }
      break;

    case Token.TRUE:
    case Token.REGEXP:
      return TernaryValue.TRUE;

    case Token.ARRAYLIT:
    case Token.OBJECTLIT:
      if (!mayHaveSideEffects(n)) {
        return TernaryValue.TRUE;
      }
      break;
  }

  return TernaryValue.UNKNOWN;
}
 
Example 20
Source File: Cardumen_00200_s.java    From coming with MIT License 4 votes vote down vote up
/**
 * Gets the boolean value of a node that represents a literal. This method
 * effectively emulates the <code>Boolean()</code> JavaScript cast function
 * except it return UNKNOWN for known values with side-effects, use
 * getExpressionBooleanValue if you don't care about side-effects.
 */
static TernaryValue getPureBooleanValue(Node n) {
  switch (n.getType()) {
    case Token.STRING:
      return TernaryValue.forBoolean(n.getString().length() > 0);

    case Token.NUMBER:
      return TernaryValue.forBoolean(n.getDouble() != 0);

    case Token.NOT:
      return getPureBooleanValue(n.getLastChild()).not();

    case Token.NULL:
    case Token.FALSE:
      return TernaryValue.FALSE;

    case Token.VOID:
      if (!mayHaveSideEffects(n.getFirstChild())) {
        return TernaryValue.FALSE;
      }
      break;

    case Token.NAME:
      String name = n.getString();
      if ("undefined".equals(name)
          || "NaN".equals(name)) {
        // We assume here that programs don't change the value of the keyword
        // undefined to something other than the value undefined.
        return TernaryValue.FALSE;
      } else if ("Infinity".equals(name)) {
        return TernaryValue.TRUE;
      }
      break;

    case Token.TRUE:
    case Token.REGEXP:
      return TernaryValue.TRUE;

    case Token.ARRAYLIT:
    case Token.OBJECTLIT:
      if (!mayHaveSideEffects(n)) {
        return TernaryValue.TRUE;
      }
      break;
  }

  return TernaryValue.UNKNOWN;
}