Package com.google.caja.parser.js

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


      throws IOException {
    RhinoTestBed.runJs(
        new Executor.Input(getClass(), "/js/jsunit/2.2/jsUnitCore.js"),
        new Executor.Input(getClass(), "array-opt-operator-test.js"),
        new Executor.Input(render(
            new Block(FilePosition.UNKNOWN, stmts)), getName()));
  }
View Full Code Here


  private static Identifier ident(String name) {
    return new Identifier(FilePosition.UNKNOWN, name);
  }

  private void assertNotChangedByOptimizer(String jsSrc) throws Exception {
    Block b = js(fromString(jsSrc));
    ArrayIndexOptimization.optimize(b);
    ParseTreeNode golden = js(fromString(jsSrc));
    assertEquals(render(b), render(golden), render(b));
  }
View Full Code Here

    children.add(js(
        testPath == null ?
        fromString(caja, is) :
        testPath));
    String cajoledJs = render(rewriteTopLevelNode(
        new UncajoledModule(new Block(FilePosition.UNKNOWN, children))));

    assertNoErrors();

    final String[] assertFunctions = new String[] {
        "fail",
View Full Code Here

  public class Caja {
    public String cajole(String source) throws ParseException {
      List<Statement> children = Lists.newArrayList();
      children.add(js(fromString(source, is)));
      String cajoledJs = render(rewriteTopLevelNode(
          new UncajoledModule(new Block(FilePosition.UNKNOWN, children))));
      // TODO: return code to construct the appropriate error object when there
      // are errors during translation.
      return cajoledJs;
    }
View Full Code Here

        new Identifier(unk, "f"),
        Arrays.asList(
            new FormalParam(new Identifier(unk, "x")),
            new FormalParam(
                SyntheticNodes.s(new Identifier(unk, "y___")))),
        new Block(
            unk,
            Arrays.<Statement>asList(new ReturnStmt(
                unk,
                Operation.createInfix(
                    Operator.MULTIPLICATION,
                    Operation.createInfix(
                        Operator.ADDITION,
                        new Reference(new Identifier(unk, "x")),
                        new Reference(SyntheticNodes.s(
                            new Identifier(unk, "y___")))),
                    new Reference(new Identifier(unk, "z")))))));
    checkSucceeds(
        new Block(
            unk,
            Arrays.asList(
                new FunctionDeclaration((FunctionConstructor) fc.clone()))),
        js(fromString(
            ""
            // x and y___ are formals, but z is free to the function.
            + "var dis___ = IMPORTS___;"
            + "{"
            + "  function f(x, y___) {"
            + "    return (x + y___) *"
            + "        (IMPORTS___.z_v___ ?"
            + "        IMPORTS___.z :"
            + "        ___.ri(IMPORTS___, 'z'));"
            + "  }"
            + "  IMPORTS___.w___('f', ___.f(f, 'f'));"
            + "}")));

    SyntheticNodes.s(fc);
    checkSucceeds(
        new Block(
            unk,
            Arrays.asList(
                new FunctionDeclaration((FunctionConstructor) fc.clone()))),
        js(fromString(
            ""
View Full Code Here

    mq.getMessages().clear();

    List<Statement> children = Lists.newArrayList();
    children.add(js(fromString(caja, is)));
    String cajoledJs = render(rewriteTopLevelNode(
        new UncajoledModule(new Block(FilePosition.UNKNOWN, children))));

    assertNoErrors();

    final String[] assertFunctions = new String[] {
        "fail",
View Full Code Here

  private Scope fromProgram(Block n) {
    return Scope.fromProgram(n, new Rewriter(mq, false, false));
  }

  public final void testSimpleDeclaredFunction() throws Exception {
    Block n = js(fromString(
        "var x = 3;" +
        "function foo() {" +
        "  var y = 3;" +
        "  z = 4;" +
        "};"));
View Full Code Here

  private void assertFreeVariables(String code,
                                   String freeVariables,
                                   String notFreeVariables)
      throws Exception {
    Block n = js(fromString(code));
    Scope s = fromProgram(n);
    for (String v : freeVariables.split(",")) {
      assertTrue(
          "<" + v + "> should be a free variable in <" + code + ">",
          s.isImported(v));
View Full Code Here

          s.isImported(v));
    }
  }

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

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

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

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

    assertTrue(s0.isDefined("x"));
    assertFalse(s0.isImported("x"));
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.