< prev index next >

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

Print this page




2703                 if (parametersSet.contains(parameterName)) {
2704                     // redefinition of parameter name
2705                     if (strict) {
2706                         throw error(AbstractParser.message("strict.param.redefinition", parameterName), parameter.getToken());
2707                     }
2708                     // rename in non-strict mode
2709                     parameterName = functionNode.uniqueName(parameterName);
2710                     final long parameterToken = parameter.getToken();
2711                     parameters.set(i, new IdentNode(parameterToken, Token.descPosition(parameterToken), functionNode.uniqueName(parameterName)));
2712                 }
2713 
2714                 parametersSet.add(parameterName);
2715             }
2716         } else if (arity == 1) {
2717             if (isArguments(parameters.get(0))) {
2718                 functionNode = functionNode.setFlag(lc, FunctionNode.DEFINES_ARGUMENTS);
2719             }
2720         }
2721 
2722         if (isStatement) {





2723             final int     varFlags = (topLevel || !useBlockScope()) ? 0 : VarNode.IS_LET;
2724             final VarNode varNode = new VarNode(functionLine, functionToken, finish, name, functionNode, varFlags);
2725             if (topLevel) {
2726                 functionDeclarations.add(varNode);
2727             } else if (useBlockScope()) {
2728                 prependStatement(varNode); // Hoist to beginning of current block
2729             } else {
2730                 appendStatement(varNode);
2731             }
2732         }
2733 
2734         return functionNode;
2735     }
2736 
2737     private String getDefaultValidFunctionName(final int functionLine, final boolean isStatement) {
2738         final String defaultFunctionName = getDefaultFunctionName();
2739         if (isValidIdentifier(defaultFunctionName)) {
2740             if (isStatement) {
2741                 // The name will be used as the LHS of a symbol assignment. We add the anonymous function
2742                 // prefix to ensure that it can't clash with another variable.




2703                 if (parametersSet.contains(parameterName)) {
2704                     // redefinition of parameter name
2705                     if (strict) {
2706                         throw error(AbstractParser.message("strict.param.redefinition", parameterName), parameter.getToken());
2707                     }
2708                     // rename in non-strict mode
2709                     parameterName = functionNode.uniqueName(parameterName);
2710                     final long parameterToken = parameter.getToken();
2711                     parameters.set(i, new IdentNode(parameterToken, Token.descPosition(parameterToken), functionNode.uniqueName(parameterName)));
2712                 }
2713 
2714                 parametersSet.add(parameterName);
2715             }
2716         } else if (arity == 1) {
2717             if (isArguments(parameters.get(0))) {
2718                 functionNode = functionNode.setFlag(lc, FunctionNode.DEFINES_ARGUMENTS);
2719             }
2720         }
2721 
2722         if (isStatement) {
2723             if (isAnonymous) {
2724                 appendStatement(new ExpressionStatement(functionLine, functionToken, finish, functionNode));
2725                 return functionNode;
2726             }
2727 
2728             final int     varFlags = (topLevel || !useBlockScope()) ? 0 : VarNode.IS_LET;
2729             final VarNode varNode = new VarNode(functionLine, functionToken, finish, name, functionNode, varFlags);
2730             if (topLevel) {
2731                 functionDeclarations.add(varNode);
2732             } else if (useBlockScope()) {
2733                 prependStatement(varNode); // Hoist to beginning of current block
2734             } else {
2735                 appendStatement(varNode);
2736             }
2737         }
2738 
2739         return functionNode;
2740     }
2741 
2742     private String getDefaultValidFunctionName(final int functionLine, final boolean isStatement) {
2743         final String defaultFunctionName = getDefaultFunctionName();
2744         if (isValidIdentifier(defaultFunctionName)) {
2745             if (isStatement) {
2746                 // The name will be used as the LHS of a symbol assignment. We add the anonymous function
2747                 // prefix to ensure that it can't clash with another variable.


< prev index next >