Package com.google.caja.parser.js

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


  }

  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(
        RewriterMessageType.CANNOT_MASK_IDENTIFIER, MessageLevel.FATAL_ERROR,
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(
        RewriterMessageType.CANNOT_MASK_IDENTIFIER, MessageLevel.FATAL_ERROR,
View Full Code Here

                    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(
            ""
            // x and y___ are formals, but z is free to the function.
            + "var dis___ = IMPORTS___;"
            + "function f(x, y___) {"
View Full Code Here

          reason="function declarations contain function constructors but don't"
              + " have the same discrepencies on IE 6 as function constructors",
          synopsis="")
      public ParseTreeNode fire(ParseTreeNode node, Scope scope) {
        if (node instanceof FunctionDeclaration) {
          FunctionDeclaration decl = ((FunctionDeclaration) node);
          FunctionConstructor ctor = decl.getInitializer();

          Scope s2 = Scope.fromFunctionConstructor(scope, ctor);
          FunctionConstructor rewritten
              = (FunctionConstructor) QuasiBuilder.substV(
                  "function @ident(@formals*) { @stmts*; @body*; }",
                  "ident", ctor.getIdentifier(),
                  "formals", expandAll(
                      new ParseTreeNodeContainer(ctor.getParams()), s2),
                  "stmts", new ParseTreeNodeContainer(s2.getStartStatements()),
                  "body", expandAll(
                      new ParseTreeNodeContainer(ctor.getBody().children()), s2)
                  );
          return new FunctionDeclaration(rewritten);
        }
        return NONE;
      }
    });
    w.addRule(new Rule() {
View Full Code Here

    Block consolidated = new Block();
    MutableParseTreeNode.Mutation mut = consolidated.createMutation();
    FilePosition unk = FilePosition.UNKNOWN;
    for (SafeJsChunk chunk : chunks) {
      Identifier ident = new Identifier(unk, "module");
      mut.appendChild(new FunctionDeclaration(new FunctionConstructor(
          unk, ident, Collections.<FormalParam>emptyList(),
          (Block) chunk.body)));
    }
    mut.execute();
    stripTranslatedCode(consolidated);
View Full Code Here

            FunctionConstructor out = (FunctionConstructor) substV(
                "name", rewrittenName,
                "headDecls", optionalDeclarations(headDecls),
                "params", new ParseTreeNodeContainer(newFormals),
                "body", expandAll(bindings.get("body"), newScope));
            return isDeclaration ? new FunctionDeclaration(out) : out;
          }
          return NONE;
        }
      },
View Full Code Here

TOP

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

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.