< prev index next >

src/jdk/nashorn/internal/parser/Parser.java

Print this page
rev 1387 : 8085802: Nashorn -nse option causes parse error on anonymous function definition
Reviewed-by: lagergren, attila


2618      *
2619      * See 13
2620      *
2621      * Parse function declaration.
2622      * @param isStatement True if for is a statement.
2623      *
2624      * @return Expression node.
2625      */
2626     private Expression functionExpression(final boolean isStatement, final boolean topLevel) {
2627         final long functionToken = token;
2628         final int  functionLine  = line;
2629         // FUNCTION is tested in caller.
2630         next();
2631 
2632         IdentNode name = null;
2633 
2634         if (type == IDENT || isNonStrictModeIdent()) {
2635             name = getIdent();
2636             verifyStrictIdent(name, "function name");
2637         } else if (isStatement) {
2638             // Nashorn extension: anonymous function statements
2639             if (env._no_syntax_extensions) {




2640                 expect(IDENT);
2641             }
2642         }
2643 
2644         // name is null, generate anonymous name
2645         boolean isAnonymous = false;
2646         if (name == null) {
2647             final String tmpName = getDefaultValidFunctionName(functionLine, isStatement);
2648             name = new IdentNode(functionToken, Token.descPosition(functionToken), tmpName);
2649             isAnonymous = true;
2650         }
2651 
2652         expect(LPAREN);
2653         final List<IdentNode> parameters = formalParameterList();
2654         expect(RPAREN);
2655 
2656         FunctionNode functionNode;
2657         // Hide the current default name across function boundaries. E.g. "x3 = function x1() { function() {}}"
2658         // If we didn't hide the current default name, then the innermost anonymous function would receive "x3".
2659         hideDefaultName();




2618      *
2619      * See 13
2620      *
2621      * Parse function declaration.
2622      * @param isStatement True if for is a statement.
2623      *
2624      * @return Expression node.
2625      */
2626     private Expression functionExpression(final boolean isStatement, final boolean topLevel) {
2627         final long functionToken = token;
2628         final int  functionLine  = line;
2629         // FUNCTION is tested in caller.
2630         next();
2631 
2632         IdentNode name = null;
2633 
2634         if (type == IDENT || isNonStrictModeIdent()) {
2635             name = getIdent();
2636             verifyStrictIdent(name, "function name");
2637         } else if (isStatement) {
2638             // Nashorn extension: anonymous function statements.
2639             // Do not allow anonymous function statement if extensions
2640             // are now allowed. But if we are reparsing then anon function
2641             // statement is possible - because it was used as function
2642             // expression in surrounding code.
2643             if (env._no_syntax_extensions && reparsedFunction == null) {
2644                 expect(IDENT);
2645             }
2646         }
2647 
2648         // name is null, generate anonymous name
2649         boolean isAnonymous = false;
2650         if (name == null) {
2651             final String tmpName = getDefaultValidFunctionName(functionLine, isStatement);
2652             name = new IdentNode(functionToken, Token.descPosition(functionToken), tmpName);
2653             isAnonymous = true;
2654         }
2655 
2656         expect(LPAREN);
2657         final List<IdentNode> parameters = formalParameterList();
2658         expect(RPAREN);
2659 
2660         FunctionNode functionNode;
2661         // Hide the current default name across function boundaries. E.g. "x3 = function x1() { function() {}}"
2662         // If we didn't hide the current default name, then the innermost anonymous function would receive "x3".
2663         hideDefaultName();


< prev index next >