Package com.google.caja.parser.js

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


    assertTrue(s1.isDefined("foo"));
    assertFalse(s1.isImported("foo"));
  }

  public final void testNamedFunctionSameName() throws Exception {
    Block n = js(fromString("var x = function x() {};"));
    Scope s0 = fromProgram(n);
    Scope s1 = Scope.fromFunctionConstructor(s0, findFunctionConstructor(n, "x"));

    assertTrue(s0.isDefined("x"));
    assertFalse(s0.isImported("x"));
View Full Code Here


    assertTrue(s1.isDefined("x"));
    assertFalse(s1.isImported("x"));
  }

  public final void testFormalParams() throws Exception {
    Block n = js(fromString("function f(x) {};"));
    Scope s0 = fromProgram(n);
    Scope s1 = Scope.fromFunctionConstructor(s0, findFunctionConstructor(n, "f"));

    assertFalse(s0.isDefined("x"));
    assertTrue(s1.isDefined("x"));
View Full Code Here

    assertFalse(s0.isDefined("x"));
    assertTrue(s1.isDefined("x"));
  }

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

    TryStmt t = (TryStmt) n.children().get(0);
    CatchStmt c = (CatchStmt) t.children().get(1);

    Scope s0 = fromProgram(n);
    Scope s1 = Scope.fromCatchStmt(s0, c);
View Full Code Here

    // Definition of x appears in main scope
    assertTrue(s0.isDefined("x"));
  }

  public final void testBodyOfNamedFunction() throws Exception {
    Block n = js(fromString("function foo() { var x; }"));

    Scope s0 = fromProgram(n);

    assertEquals(0, mq.getMessages().size());
    assertTrue(s0.isDefined("foo"));
View Full Code Here

    assertEquals(0, mq.getMessages().size());
    assertTrue(s0.isDefined("foo"));
  }

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

    TryStmt t = (TryStmt) n.children().get(1);
    CatchStmt c = (CatchStmt) t.children().get(1);

    Scope s0 = fromProgram(n);
    Scope.fromCatchStmt(s0, c);
View Full Code Here

    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

    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

      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

  }

  // TODO(ihab.awad): Refactor tests to use checkAddsMessage(...) instead
  protected void checkFails(String input, String error) throws Exception {
    mq.getMessages().clear();
    getRewriter().expand(new UncajoledModule(new Block(
        FilePosition.UNKNOWN, Arrays.asList(js(fromString(input, is))))));

    assertFalse(
        "Expected error, found none: " + error,
        mq.getMessages().isEmpty());
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.