< prev index next >

src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/parser/Parser.java

Print this page




2651      *
2652      * See 13
2653      *
2654      * Parse function declaration.
2655      * @param isStatement True if for is a statement.
2656      *
2657      * @return Expression node.
2658      */
2659     private Expression functionExpression(final boolean isStatement, final boolean topLevel) {
2660         final long functionToken = token;
2661         final int  functionLine  = line;
2662         // FUNCTION is tested in caller.
2663         next();
2664 
2665         IdentNode name = null;
2666 
2667         if (type == IDENT || isNonStrictModeIdent()) {
2668             name = getIdent();
2669             verifyStrictIdent(name, "function name");
2670         } else if (isStatement) {
2671             // Nashorn extension: anonymous function statements
2672             if (env._no_syntax_extensions) {




2673                 expect(IDENT);
2674             }
2675         }
2676 
2677         // name is null, generate anonymous name
2678         boolean isAnonymous = false;
2679         if (name == null) {
2680             final String tmpName = getDefaultValidFunctionName(functionLine, isStatement);
2681             name = new IdentNode(functionToken, Token.descPosition(functionToken), tmpName);
2682             isAnonymous = true;
2683         }
2684 
2685         expect(LPAREN);
2686         final List<IdentNode> parameters = formalParameterList();
2687         expect(RPAREN);
2688 
2689         final ParserContextFunctionNode functionNode = createParserContextFunctionNode(name, functionToken, FunctionNode.Kind.NORMAL, functionLine, parameters);
2690         lc.push(functionNode);
2691         Block functionBody = null;
2692         // Hide the current default name across function boundaries. E.g. "x3 = function x1() { function() {}}"




2651      *
2652      * See 13
2653      *
2654      * Parse function declaration.
2655      * @param isStatement True if for is a statement.
2656      *
2657      * @return Expression node.
2658      */
2659     private Expression functionExpression(final boolean isStatement, final boolean topLevel) {
2660         final long functionToken = token;
2661         final int  functionLine  = line;
2662         // FUNCTION is tested in caller.
2663         next();
2664 
2665         IdentNode name = null;
2666 
2667         if (type == IDENT || isNonStrictModeIdent()) {
2668             name = getIdent();
2669             verifyStrictIdent(name, "function name");
2670         } else if (isStatement) {
2671             // Nashorn extension: anonymous function statements.
2672             // Do not allow anonymous function statement if extensions
2673             // are now allowed. But if we are reparsing then anon function
2674             // statement is possible - because it was used as function
2675             // expression in surrounding code.
2676             if (env._no_syntax_extensions && reparsedFunction == null) {
2677                 expect(IDENT);
2678             }
2679         }
2680 
2681         // name is null, generate anonymous name
2682         boolean isAnonymous = false;
2683         if (name == null) {
2684             final String tmpName = getDefaultValidFunctionName(functionLine, isStatement);
2685             name = new IdentNode(functionToken, Token.descPosition(functionToken), tmpName);
2686             isAnonymous = true;
2687         }
2688 
2689         expect(LPAREN);
2690         final List<IdentNode> parameters = formalParameterList();
2691         expect(RPAREN);
2692 
2693         final ParserContextFunctionNode functionNode = createParserContextFunctionNode(name, functionToken, FunctionNode.Kind.NORMAL, functionLine, parameters);
2694         lc.push(functionNode);
2695         Block functionBody = null;
2696         // Hide the current default name across function boundaries. E.g. "x3 = function x1() { function() {}}"


< prev index next >