Examples of FunctionConstructor


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

        js(fromString("var dis___ = IMPORTS___; ___.iM([]).foo;")));
  }

  public final void testSyntheticFormals() throws Exception {
    FilePosition unk = FilePosition.UNKNOWN;
    FunctionConstructor fc = new FunctionConstructor(
        unk,
        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(
            ""
            // x and y___ are formals, but z is free to the function.
            + "var dis___ = IMPORTS___;"
            + "function f(x, y___) {"
View Full Code Here

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

              + " 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() {
      @Override
      @RuleDescription(
          name="ie6functions",
          reason="simulate IE 6's broken scoping of function constructors as "
              + "described in JScript Deviations Section 2.3",
          synopsis="")
      public ParseTreeNode fire(ParseTreeNode node, Scope scope) {
        if (node instanceof FunctionConstructor) {
          FunctionConstructor ctor = (FunctionConstructor) node;
          Scope s2 = Scope.fromFunctionConstructor(scope, ctor);
          if (ctor.getIdentifierName() == null) {
            return expandAll(node, s2);
          }
          Identifier ident = ctor.getIdentifier();
          Reference identRef = new Reference(ident);
          identRef.setFilePosition(ident.getFilePosition());
          scope.addStartStatement(
              new Declaration(FilePosition.UNKNOWN, ident, identRef));
          return QuasiBuilder.substV(
              "(@var = function @ident(@formals*) { @stmts*; @body*; })",
              "var", identRef,
              "ident", ident,
              "formals", new ParseTreeNodeContainer(ctor.getParams()),
              "stmts", new ParseTreeNodeContainer(s2.getStartStatements()),
              "body", expandAll(
                  new ParseTreeNodeContainer(ctor.getBody().children()), s2)
              );
        }
        return NONE;
      }
    });
View Full Code Here

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

          Identifier id = (Identifier) n;
          if (id.getName() != null && id.getName().endsWith("___")) {
            SyntheticNodes.s(id);
          }
        } else if (n instanceof FunctionConstructor) {
          FunctionConstructor fc = (FunctionConstructor) n;
          if (fc.getIdentifierName() != null
              && fc.getIdentifierName().endsWith("___")) {
            SyntheticNodes.s(fc);
          }
        }
        return true;
      }
View Full Code Here

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

    // 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

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

    // 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

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

    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

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

              "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

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

    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

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

      }
      @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

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

  }

  private static LiveSet processImmediatelyCalledFunction(
      Operation op, LiveSet onEntry) {
    List<? extends Expression> operands = op.children();
    FunctionConstructor fn = (FunctionConstructor) operands.get(0);
    // operands are resolved before the function body is executed
    LiveSet onExit = onEntry;
    for (Expression actual : operands.subList(1, operands.size())) {
      onExit = liveness(actual, onExit).vars;
    }
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.