| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <cmath> | 5 #include <cmath> |
| 6 | 6 |
| 7 #include "src/allocation.h" | 7 #include "src/allocation.h" |
| 8 #include "src/base/logging.h" | 8 #include "src/base/logging.h" |
| 9 #include "src/conversions-inl.h" | 9 #include "src/conversions-inl.h" |
| 10 #include "src/conversions.h" | 10 #include "src/conversions.h" |
| (...skipping 911 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 922 | 922 |
| 923 // Similarly for strong mode. | 923 // Similarly for strong mode. |
| 924 Scanner::Location undefined_loc = Scanner::Location::invalid(); | 924 Scanner::Location undefined_loc = Scanner::Location::invalid(); |
| 925 | 925 |
| 926 bool is_rest = false; | 926 bool is_rest = false; |
| 927 bool done = arity_restriction == FunctionLiteral::GETTER_ARITY || | 927 bool done = arity_restriction == FunctionLiteral::GETTER_ARITY || |
| 928 (peek() == Token::RPAREN && | 928 (peek() == Token::RPAREN && |
| 929 arity_restriction != FunctionLiteral::SETTER_ARITY); | 929 arity_restriction != FunctionLiteral::SETTER_ARITY); |
| 930 while (!done) { | 930 while (!done) { |
| 931 bool is_strict_reserved = false; | 931 bool is_strict_reserved = false; |
| 932 int rest_pos; |
| 932 is_rest = peek() == Token::ELLIPSIS && allow_harmony_rest_params(); | 933 is_rest = peek() == Token::ELLIPSIS && allow_harmony_rest_params(); |
| 933 if (is_rest) { | 934 if (is_rest) { |
| 934 Consume(Token::ELLIPSIS); | 935 Consume(Token::ELLIPSIS); |
| 936 rest_pos = position(); |
| 935 } | 937 } |
| 936 | 938 |
| 937 Identifier param_name = | 939 Identifier param_name = |
| 938 ParseIdentifierOrStrictReservedWord(&is_strict_reserved, CHECK_OK); | 940 ParseIdentifierOrStrictReservedWord(&is_strict_reserved, CHECK_OK); |
| 939 if (!eval_args_loc.IsValid() && param_name.IsEvalOrArguments()) { | 941 if (!eval_args_loc.IsValid() && param_name.IsEvalOrArguments()) { |
| 940 eval_args_loc = scanner()->location(); | 942 eval_args_loc = scanner()->location(); |
| 941 } | 943 } |
| 942 if (!undefined_loc.IsValid() && param_name.IsUndefined()) { | 944 if (!undefined_loc.IsValid() && param_name.IsUndefined()) { |
| 943 undefined_loc = scanner()->location(); | 945 undefined_loc = scanner()->location(); |
| 944 } | 946 } |
| 945 if (!reserved_loc.IsValid() && is_strict_reserved) { | 947 if (!reserved_loc.IsValid() && is_strict_reserved) { |
| 946 reserved_loc = scanner()->location(); | 948 reserved_loc = scanner()->location(); |
| 947 } | 949 } |
| 948 | 950 |
| 949 int prev_value = scanner()->FindSymbol(&duplicate_finder, 1); | 951 int prev_value = scanner()->FindSymbol(&duplicate_finder, 1); |
| 950 | 952 |
| 951 if (!dupe_loc.IsValid() && prev_value != 0) { | 953 if (!dupe_loc.IsValid() && prev_value != 0) { |
| 952 dupe_loc = scanner()->location(); | 954 dupe_loc = scanner()->location(); |
| 953 } | 955 } |
| 954 | 956 |
| 957 if (peek() == Token::ASSIGN) { |
| 958 Consume(Token::ASSIGN); |
| 959 static const bool accept_IN = true; |
| 960 ExpressionT defaultValue = ParseAssignmentExpression(accept_IN, CHECK_OK); |
| 961 if (is_rest) { |
| 962 ReportMessageAt( |
| 963 Scanner::Location(rest_pos, scanner()->location().end_pos), |
| 964 "rest_param_default"); |
| 965 *ok = false; |
| 966 return Expression::Default(); |
| 967 } |
| 968 // Default value is not needed in pre-parser. |
| 969 USE(defaultValue); |
| 970 } |
| 971 |
| 972 if (peek() == Token::ASSIGN) { |
| 973 Consume(Token::ASSIGN); |
| 974 static const bool accept_IN = true; |
| 975 ExpressionT defaultValue = ParseAssignmentExpression(accept_IN, CHECK_OK); |
| 976 if (is_rest) { |
| 977 ReportMessageAt( |
| 978 Scanner::Location(rest_pos, scanner()->location().end_pos), |
| 979 "rest_param_default"); |
| 980 *ok = false; |
| 981 return Expression::Default(); |
| 982 } |
| 983 // Default value is not needed in pre-parser. |
| 984 USE(defaultValue); |
| 985 } |
| 986 |
| 955 if (arity_restriction == FunctionLiteral::SETTER_ARITY) break; | 987 if (arity_restriction == FunctionLiteral::SETTER_ARITY) break; |
| 956 done = (peek() == Token::RPAREN); | 988 done = (peek() == Token::RPAREN); |
| 957 if (!done) { | 989 if (!done) { |
| 958 if (is_rest) { | 990 if (is_rest) { |
| 959 ReportMessageAt(scanner()->peek_location(), "param_after_rest"); | 991 ReportMessageAt(scanner()->peek_location(), "param_after_rest"); |
| 960 *ok = false; | 992 *ok = false; |
| 961 return Expression::Default(); | 993 return Expression::Default(); |
| 962 } | 994 } |
| 963 Expect(Token::COMMA, CHECK_OK); | 995 Expect(Token::COMMA, CHECK_OK); |
| 964 } | 996 } |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1088 | 1120 |
| 1089 DCHECK(!spread_pos.IsValid()); | 1121 DCHECK(!spread_pos.IsValid()); |
| 1090 | 1122 |
| 1091 return Expression::Default(); | 1123 return Expression::Default(); |
| 1092 } | 1124 } |
| 1093 | 1125 |
| 1094 #undef CHECK_OK | 1126 #undef CHECK_OK |
| 1095 | 1127 |
| 1096 | 1128 |
| 1097 } } // v8::internal | 1129 } } // v8::internal |
| OLD | NEW |