< prev index next >

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

Print this page




2748                 }
2749 
2750                 parametersSet.add(parameterName);
2751             }
2752         } else if (arity == 1) {
2753             if (isArguments(parameters.get(0))) {
2754                 functionNode.setFlag(FunctionNode.DEFINES_ARGUMENTS);
2755             }
2756         }
2757 
2758         final FunctionNode function = createFunctionNode(
2759                 functionNode,
2760                 functionToken,
2761                 name,
2762                 parameters,
2763                 FunctionNode.Kind.NORMAL,
2764                 functionLine,
2765                 functionBody);
2766 
2767         if (isStatement) {





2768             // mark ES6 block functions as lexically scoped
2769             final int     varFlags = (topLevel || !useBlockScope()) ? 0 : VarNode.IS_LET;
2770             final VarNode varNode  = new VarNode(functionLine, functionToken, finish, name, function, varFlags);
2771             if (topLevel) {
2772                 functionDeclarations.add(varNode);
2773             } else if (useBlockScope()) {
2774                 prependStatement(varNode); // Hoist to beginning of current block
2775             } else {
2776                 appendStatement(varNode);
2777             }
2778         }
2779 
2780         return function;
2781     }
2782 
2783     private String getDefaultValidFunctionName(final int functionLine, final boolean isStatement) {
2784         final String defaultFunctionName = getDefaultFunctionName();
2785         if (isValidIdentifier(defaultFunctionName)) {
2786             if (isStatement) {
2787                 // The name will be used as the LHS of a symbol assignment. We add the anonymous function




2748                 }
2749 
2750                 parametersSet.add(parameterName);
2751             }
2752         } else if (arity == 1) {
2753             if (isArguments(parameters.get(0))) {
2754                 functionNode.setFlag(FunctionNode.DEFINES_ARGUMENTS);
2755             }
2756         }
2757 
2758         final FunctionNode function = createFunctionNode(
2759                 functionNode,
2760                 functionToken,
2761                 name,
2762                 parameters,
2763                 FunctionNode.Kind.NORMAL,
2764                 functionLine,
2765                 functionBody);
2766 
2767         if (isStatement) {
2768             if (isAnonymous) {
2769                 appendStatement(new ExpressionStatement(functionLine, functionToken, finish, function));
2770                 return function;
2771             }
2772 
2773             // mark ES6 block functions as lexically scoped
2774             final int     varFlags = (topLevel || !useBlockScope()) ? 0 : VarNode.IS_LET;
2775             final VarNode varNode  = new VarNode(functionLine, functionToken, finish, name, function, varFlags);
2776             if (topLevel) {
2777                 functionDeclarations.add(varNode);
2778             } else if (useBlockScope()) {
2779                 prependStatement(varNode); // Hoist to beginning of current block
2780             } else {
2781                 appendStatement(varNode);
2782             }
2783         }
2784 
2785         return function;
2786     }
2787 
2788     private String getDefaultValidFunctionName(final int functionLine, final boolean isStatement) {
2789         final String defaultFunctionName = getDefaultFunctionName();
2790         if (isValidIdentifier(defaultFunctionName)) {
2791             if (isStatement) {
2792                 // The name will be used as the LHS of a symbol assignment. We add the anonymous function


< prev index next >