Package com.google.caja.parser.js

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


    assertMsgType(MessageType.MASKING_SYMBOL, mq.getMessages().get(0));
    assertMsgLevel(MessageLevel.LINT, mq.getMessages().get(0));
  }

  public final void testMaskedExceptionVariablesErrorB() throws Exception {
    Block n = js(fromString(
        "try { } catch (e) { function foo() { var e; } }"));

    TryStmt t = (TryStmt)n.children().get(0);
    CatchStmt c = (CatchStmt)t.children().get(1);
    Declaration d = findNodeWithIdentifier(n, Declaration.class, "foo");
    FunctionConstructor fc = (FunctionConstructor)d.getInitializer();

    Scope s0 = fromProgram(n);
View Full Code Here


    for (int i = b.length; --i >= 0;) {
      b[i] = new ExpressionStmt(unk, new IntegerLiteral(unk, i));
    }

    LabeledStmtWrapper b1 = new LabeledStmtWrapper(
        unk, "$1", new Block(unk, Arrays.asList(b[2], b[3], b[4])));

    LabeledStmtWrapper b5 = new LabeledStmtWrapper(
        unk, "$5", new Block(unk, Arrays.asList(b[6], b[7], b[8])));
    root = new LabeledStmtWrapper(
        unk, "$0", new Block(unk, Arrays.asList(b1, b5)));

    b9 = new LabeledStmtWrapper(
        unk, "$9", new Block(unk, Arrays.asList(b[10], b[11], b[12])));
  }
View Full Code Here

    assertMsgType(MessageType.MASKING_SYMBOL, mq.getMessages().get(0));
    assertMsgLevel(MessageLevel.LINT, mq.getMessages().get(0));
  }

  public final void testMaskedExceptionVariablesSame() throws Exception {
    Block outerBlock = js(fromString(
        "try { } catch (e) { try { } catch (e) { var x; } }"));

    TryStmt t0 = (TryStmt) outerBlock.children().get(0);
    CatchStmt c0 = t0.getCatchClause();
    Block b0 = c0.getBody();
    TryStmt t1 = (TryStmt) b0.children().get(0);
    CatchStmt c1 = t1.getCatchClause();

    Scope sn = fromProgram(outerBlock);
    Scope sc0 = Scope.fromCatchStmt(sn, c0);
    Scope.fromCatchStmt(sc0, c1);
View Full Code Here

  }

  @SuppressWarnings("unchecked")
  // setComments causes a warning about generic array for varargs
  public final void testImmutability() throws Exception {
    Block n = new Block(
        FilePosition.UNKNOWN,
        Arrays.asList(
            new ExpressionStmt(new IntegerLiteral(FilePosition.UNKNOWN, 42)),
            new ExpressionStmt(new IntegerLiteral(FilePosition.UNKNOWN, 13))));
    assertTrue(n.makeImmutable());
    assertTrue(n.isImmutable());
    assertTrue(n.children().get(0).isImmutable());
    assertTrue(n.children().get(0).children().get(0).isImmutable());
    assertTrue(n.children().get(1).isImmutable());
    assertTrue(n.children().get(1).children().get(0).isImmutable());
    try {
      n.appendChild(new Noop(FilePosition.UNKNOWN));
      fail();
    } catch (UnsupportedOperationException e) { /* OK */ }
    try {
      n.setComments(Arrays.asList(
          Token.instance("test", JsTokenType.COMMENT, FilePosition.UNKNOWN)));
      fail();
    } catch (UnsupportedOperationException e) { /* OK */ }
  }
View Full Code Here

      String code,
      boolean recurseIntoFunction,
      MessageType type,
      MessageLevel level)
      throws Exception {
    Block b = js(fromString(code));
    Scope s0 = fromProgram(b);
    if (recurseIntoFunction) {
      Scope.fromFunctionConstructor(
          s0, findFunctionConstructor(b, "foo"));
    }
View Full Code Here

    assertEquals(1, s1.getStartStatements().size());
  }

  public final void testStartStatementsForCatchStmt() throws Exception {
    Scope s0 = fromProgram(js(fromString("{}")));
    Block block = js(fromString("try {} catch (e) {}"));
    TryStmt t = (TryStmt)block.children().get(0);
    Scope s1 = Scope.fromCatchStmt(s0, t.getCatchClause());

    assertEquals(0, s0.getStartStatements().size());
    assertEquals(0, s1.getStartStatements().size());
View Full Code Here

  }

  public final void testStartStatementsForFunctionConstructor()
      throws Exception {
    Scope s0 = fromProgram(js(fromString("{}")));
    Block block = js(fromString("function() {};"));
    FunctionConstructor fc = (FunctionConstructor)
        block.children().get(0).children().get(0);
    Scope s1 = Scope.fromFunctionConstructor(s0, fc);

    assertEquals(0, s0.getStartStatements().size());
    assertEquals(0, s1.getStartStatements().size());
View Full Code Here

    assertEquals(2, s0.getStartStatements().size());
    assertEquals(1, s1.getStartStatements().size());
  }

  public final void testUnmaskableIdentifiersInCatch() throws Exception {
    Block b = js(fromString("try {} catch (Object) {}"));
    TryStmt tryStmt = (TryStmt) b.children().get(0);
    Scope top = fromProgram(b);
    Scope.fromCatchStmt(top, tryStmt.getCatchClause());
    assertMessage(
        RewriterMessageType.CANNOT_MASK_IDENTIFIER, MessageLevel.FATAL_ERROR,
        MessagePart.Factory.valueOf("Object"));
View Full Code Here

        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

    @Override public boolean makeImmutable() { return false; /* refuse! */ }
  }

  public final void testIncompleteImmutability() throws Exception {
    // Immutability should be best-effort, stopping at a node that refuses
    Block n = new Block(
        FilePosition.UNKNOWN,
        Arrays.asList(
            new ExpressionStmt(new IntegerLiteral(FilePosition.UNKNOWN, 42)),
            new ExpressionStmt(new AlwaysMutable())));
    assertFalse(n.makeImmutable());
    assertFalse(n.isImmutable());
    assertTrue(n.children().get(0).isImmutable());
    assertTrue(n.children().get(0).children().get(0).isImmutable());
    assertFalse(n.children().get(1).isImmutable());
    assertFalse(n.children().get(1).children().get(0).isImmutable());
  }
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.