Package com.google.caja.parser.js

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


        RewriterMessageType.CANNOT_MASK_IDENTIFIER, MessageLevel.FATAL_ERROR,
        MessagePart.Factory.valueOf("Object"));
  }

  public final void testUnmaskableIdentifiersInDeclarations() throws Exception {
    Block b = js(fromString("var Array, undefined;"));
    fromProgram(b);
    assertMessage(
        RewriterMessageType.CANNOT_MASK_IDENTIFIER, MessageLevel.FATAL_ERROR,
        MessagePart.Factory.valueOf("Array"));
  }
View Full Code Here


        RewriterMessageType.CANNOT_MASK_IDENTIFIER, MessageLevel.FATAL_ERROR,
        MessagePart.Factory.valueOf("Array"));
  }

  public final void testUnmaskableFormals() throws Exception {
    Block b = js(fromString("function NaN(Infinity, arguments) {}"));
    Scope top = fromProgram(b);
    FunctionDeclaration fn = ((FunctionDeclaration) b.children().get(0));
    Scope.fromFunctionConstructor(top, fn.getInitializer());
    assertMessage(
        RewriterMessageType.CANNOT_MASK_IDENTIFIER, MessageLevel.FATAL_ERROR,
        MessagePart.Factory.valueOf("NaN"));
    assertMessage(
View Full Code Here

  @Override
  protected Object rewriteAndExecute(String pre, String trans, String post)
      throws IOException, ParseException {
    mq.getMessages().clear();

    Block input = new Block(
        FilePosition.UNKNOWN,
        Arrays.asList(
            js(fromResource("../../../../../js/jsunit/2.2/jsUnitCore.js")),
            js(fromString(trans, is))));
    String transJs = render(rewriteTopLevelNode(input));
View Full Code Here

    assertFalse(ArrayIndexOptimization.doesVarReferenceVisibleProperty(
        new Reference(ident("x")), inner, new HashSet<String>()));
  }

  public final void testSimpleReferences() throws Exception {
    Block b = js(fromString(
        ""
        + "function map(f, arr) {\n"
        + "  for (var i = 0, n = arr.length; i < n; ++i) {\n"
        + "    f(arr[i]);\n"
        + "  }\n"
View Full Code Here

        + "}"));
    assertEquals(render(golden), render(b));
  }

  public void checkReferenceChains() throws Exception {
    Block b = js(fromString(REFERENCE_EXAMPLE));
    ArrayIndexOptimization.optimize(b);
    ParseTreeNode golden = js(fromString(
        ""
        + "function map(f, arr) {\n"
        + "  for (var i = 0, n = arr.length; i < n; ++i) {\n"
View Full Code Here

        + "}"));
    assertEquals(render(golden), render(b));
  }

  public final void testSubtraction() throws Exception {
    Block b = js(fromString(
        ""
        + "function lastOf(arr) {\n"
        + "  return arr[arr.length - 1];\n"
        + "}"));
    ArrayIndexOptimization.optimize(b);
View Full Code Here

        + "}"));
    assertEquals(render(golden), render(b));
  }

  public final void testAddition() throws Exception {
    Block b = js(fromString(
        ""
        + "function join(arr, sep) {\n"
        + "  var s = '';\n"
        + "  for (var i = 0; i < arr.length; i++) {"
        + "    if (s && arr[i + 1]) { s += sep; }"
View Full Code Here

        + "join(myArray[foo + bar]);"));
    assertEquals(render(golden), render(b));
  }

  public final void testCompoundAssignments() throws Exception {
    Block b = js(fromString(
        ""
        + "function lastIndexOf(arr, o) {\n"
        + "  for (var i = arr.length; i > 0;) {\n"
        + "    if (o === arr[--i]) { return i; }\n"
        + "  }\n"
View Full Code Here

        + "}"));
    assertEquals(render(golden), render(b));
  }

  public final void testConcatenation() throws Exception {
    Block b = js(fromString(
        ""
        + "function cheating(arr) {\n"
        + "  return arr['length' + 'length'];\n"
        + "}"));
    ArrayIndexOptimization.optimize(b);
View Full Code Here

        + "}"));
    assertEquals(render(golden), render(b));
  }

  public final void testBug1292() throws Exception {
    Block b = js(fromString("this;"));
    ArrayIndexOptimization.optimize(b);
    assertEquals("this;", renderProgram(b));
  }
View Full Code Here

TOP

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

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.