Package com.google.caja.parser.js

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


    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 {
View Full Code Here


    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

  }

  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

        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

            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());
  }

  static class IntEnqueuer implements Visitor {
View Full Code Here

            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());
  }

  static class IntEnqueuer implements Visitor {
    private final List<Number> nums = new ArrayList<Number>();
View Full Code Here

    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());
  }

  static class IntEnqueuer implements Visitor {
    private final List<Number> nums = new ArrayList<Number>();
View Full Code Here

              .replaceChild(ref, use.node);
        }
      }
    }
    if (!decls.isEmpty()) {
      Statement first = body.children().get(0);
      MultiDeclaration md;
      if (first instanceof MultiDeclaration) {
        md = (MultiDeclaration) first;
      } else if (first instanceof Declaration) {
        md = new MultiDeclaration(
View Full Code Here

    boolean hasDefault = false;
    for (int i = newChildren.size(); --i >= 1;) {
      SwitchCase cs = (SwitchCase) newChildren.get(i);
      if (!(cs instanceof DefaultCaseStmt)) { continue; }
      Block body = cs.getBody();
      if (body.children().isEmpty()) {
        changed = true;
        newChildren.remove(i);
      } else if (isBlankBreak(body)) {
        if (i != 1 || !exits(((SwitchCase) newChildren.get(i - 1)).getBody())) {
          // Move the break into the preceding case.
View Full Code Here

      int lastIndex = newChildren.size() - 1;
      last = (SwitchCase) newChildren.get(lastIndex);

      Block lastBody = last.getBody();
      boolean changedOne = false;
      if (!lastBody.children().isEmpty()) {
        // Eliminate trailing break statement.
        List<? extends Statement> stmts = lastBody.children();
        int n = stmts.size();
        if (n > 0 && isBlankBreak(stmts.get(n - 1))) {
          stmts = stmts.subList(0, n - 1);
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.