Package com.google.caja.parser.js

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


        "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);
    Scope s1 = Scope.fromCatchStmt(s0, c);
    Scope.fromFunctionConstructor(s1, fc);
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

      }
      @Override
      protected void initScope(LexicalScope scope) {
        super.initScope(scope);
        if (scope.isFunctionScope()) {
          FunctionConstructor fc = scope.root.cast(FunctionConstructor.class)
              .node;
          // Simulate JScript quirks around named functions
          if (fc.getIdentifierName() != null
              && scope.root.parent != null
              && !(scope.root.parent.node instanceof FunctionDeclaration)) {
            LexicalScope containing = scope.parent;
            while (containing.parent != null
                   && (hoist(scope.root, containing)
                       || isLoopy(containing.root))) {
              containing = containing.parent;
            }
            containing.symbols.declare(fc.getIdentifierName(), scope.root);
          }
        } else if (scope.isGlobal()) {
          for (String symbolName : Sets.union(
                   env.outers, Sets.union(requires, overrides))) {
            if (scope.symbols.getSymbol(symbolName) == null) {
View Full Code Here

    // it is declared were renamed.
    boolean infected = false;
    ParseTreeNode n = ac.node;
    n.getAttributes().set(SCOPE, scope);
    if (n instanceof FunctionConstructor) {
      FunctionConstructor fc = (FunctionConstructor) n;
      scope = new ScopeInfo(scope, Scope.fromFunctionConstructor(scope.s, fc));
      if (fc.getIdentifierName() != null) {
        scope.fns.add(ac.cast(FunctionConstructor.class));
      }
      // A ctor's name is apparent in its scope, unlike a fn declarations name
      // which is apparent in the containing scope.
      n.getAttributes().set(SCOPE, scope);
View Full Code Here

    // Allocate names of function constructors in children to make sure
    // that, on IE with its weird scoping rules, their names do not collide
    // with any locals.
    for (ScopeInfo inner : scope.inners) {
      for (AncestorChain<FunctionConstructor> f : inner.fns) {
        FunctionConstructor fc = f.node;
        String fnName = fc.getIdentifierName();
        assert fnName != null;
        if (inner.mapping.containsKey(fnName)) { continue; // Skip duplicates
        String newName;
        if (f.parent.node instanceof FunctionDeclaration) {
          // Use the same name as the enclosing function declaration.
View Full Code Here

    if (n instanceof Reference) {
      if (!isMemberAccess(parent, (Reference) n)) {
        renameOne((Reference) n);
      }
    } else if (n instanceof FunctionConstructor) {
      FunctionConstructor fc = (FunctionConstructor) n;
      if (fc.getIdentifierName() != null) {
        renameOne(fc);
      }
    } else if (n instanceof Declaration) {
      renameOne((Declaration) n);
    }
View Full Code Here

              "body", new ParseTreeNodeContainer(b.children()));
          handlers.add(new EventHandler(attr.env, handler));
          handlerCache.put(value, handlerFnName);
        }

        FunctionConstructor eventAdapter
            = (FunctionConstructor) QuasiBuilder.substV(
            ""
            + "(/*@synthetic*/ function (event) {"
            + "  return /*@synthetic*/ (___.plugin_dispatchEvent___("
            + "      /*@synthetic*/this, event, "
            + "      ___./*@synthetic*/getId(IMPORTS___), @tail));"
            + "})",
            "tail", new Reference(SyntheticNodes.s(
                new Identifier(pos, handlerFnName))));
        eventAdapter.setFilePosition(pos);
        eventAdapter.getAttributes().set(HANDLER_NAME, handlerFnName);
        dynamicValue = eventAdapter;
        break;
      case STYLE:
        CssTree.DeclarationGroup decls = styleFromAttrib(attr);
        if (decls == null || decls.children().isEmpty()) {
View Full Code Here

      }
      @Override
      protected void initScope(LexicalScope scope) {
        super.initScope(scope);
        if (scope.isFunctionScope()) {
          FunctionConstructor fc = scope.root.cast(FunctionConstructor.class)
              .node;
          // Simulate JScript quirks around named functions
          if (fc.getIdentifierName() != null
              && scope.root.parent != null
              && !(scope.root.parent.node instanceof FunctionDeclaration)) {
            LexicalScope containing = scope.parent;
            while (containing.parent != null
                   && (hoist(scope.root, containing)
                       || isLoopy(containing.root))) {
              containing = containing.parent;
            }
            containing.symbols.declare(fc.getIdentifierName(), scope.root);
          }
        } else if (scope.isGlobal()) {
          for (String symbolName : Sets.union(
                   env.outers, Sets.union(requires, overrides))) {
            if (scope.symbols.getSymbol(symbolName) == null) {
View Full Code Here

        "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);
    Scope s1 = Scope.fromCatchStmt(s0, c);
    Scope.fromFunctionConstructor(s1, fc);
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

TOP

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

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.