OLD | NEW |
---|---|
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 #ifndef V8_PARSING_PARSER_BASE_H | 5 #ifndef V8_PARSING_PARSER_BASE_H |
6 #define V8_PARSING_PARSER_BASE_H | 6 #define V8_PARSING_PARSER_BASE_H |
7 | 7 |
8 #include "src/ast/ast.h" | 8 #include "src/ast/ast.h" |
9 #include "src/ast/scopes.h" | 9 #include "src/ast/scopes.h" |
10 #include "src/bailout-reason.h" | 10 #include "src/bailout-reason.h" |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
219 function_literal_id_(0), | 219 function_literal_id_(0), |
220 allow_natives_(false), | 220 allow_natives_(false), |
221 allow_tailcalls_(false), | 221 allow_tailcalls_(false), |
222 allow_harmony_do_expressions_(false), | 222 allow_harmony_do_expressions_(false), |
223 allow_harmony_function_sent_(false), | 223 allow_harmony_function_sent_(false), |
224 allow_harmony_restrictive_generators_(false), | 224 allow_harmony_restrictive_generators_(false), |
225 allow_harmony_trailing_commas_(false), | 225 allow_harmony_trailing_commas_(false), |
226 allow_harmony_class_fields_(false), | 226 allow_harmony_class_fields_(false), |
227 allow_harmony_object_rest_spread_(false), | 227 allow_harmony_object_rest_spread_(false), |
228 allow_harmony_dynamic_import_(false), | 228 allow_harmony_dynamic_import_(false), |
229 allow_harmony_async_iteration_(false) {} | 229 allow_harmony_async_iteration_(false), |
230 allow_harmony_template_escapes_(false) {} | |
230 | 231 |
231 #define ALLOW_ACCESSORS(name) \ | 232 #define ALLOW_ACCESSORS(name) \ |
232 bool allow_##name() const { return allow_##name##_; } \ | 233 bool allow_##name() const { return allow_##name##_; } \ |
233 void set_allow_##name(bool allow) { allow_##name##_ = allow; } | 234 void set_allow_##name(bool allow) { allow_##name##_ = allow; } |
234 | 235 |
235 ALLOW_ACCESSORS(natives); | 236 ALLOW_ACCESSORS(natives); |
236 ALLOW_ACCESSORS(tailcalls); | 237 ALLOW_ACCESSORS(tailcalls); |
237 ALLOW_ACCESSORS(harmony_do_expressions); | 238 ALLOW_ACCESSORS(harmony_do_expressions); |
238 ALLOW_ACCESSORS(harmony_function_sent); | 239 ALLOW_ACCESSORS(harmony_function_sent); |
239 ALLOW_ACCESSORS(harmony_restrictive_generators); | 240 ALLOW_ACCESSORS(harmony_restrictive_generators); |
240 ALLOW_ACCESSORS(harmony_trailing_commas); | 241 ALLOW_ACCESSORS(harmony_trailing_commas); |
241 ALLOW_ACCESSORS(harmony_class_fields); | 242 ALLOW_ACCESSORS(harmony_class_fields); |
242 ALLOW_ACCESSORS(harmony_object_rest_spread); | 243 ALLOW_ACCESSORS(harmony_object_rest_spread); |
243 ALLOW_ACCESSORS(harmony_dynamic_import); | 244 ALLOW_ACCESSORS(harmony_dynamic_import); |
244 ALLOW_ACCESSORS(harmony_async_iteration); | 245 ALLOW_ACCESSORS(harmony_async_iteration); |
246 ALLOW_ACCESSORS(harmony_template_escapes); | |
245 | 247 |
246 #undef ALLOW_ACCESSORS | 248 #undef ALLOW_ACCESSORS |
247 | 249 |
248 uintptr_t stack_limit() const { return stack_limit_; } | 250 uintptr_t stack_limit() const { return stack_limit_; } |
249 | 251 |
250 void set_stack_limit(uintptr_t stack_limit) { stack_limit_ = stack_limit; } | 252 void set_stack_limit(uintptr_t stack_limit) { stack_limit_ = stack_limit; } |
251 | 253 |
252 void set_default_eager_compile_hint( | 254 void set_default_eager_compile_hint( |
253 FunctionLiteral::EagerCompileHint eager_compile_hint) { | 255 FunctionLiteral::EagerCompileHint eager_compile_hint) { |
254 default_eager_compile_hint_ = eager_compile_hint; | 256 default_eager_compile_hint_ = eager_compile_hint; |
(...skipping 586 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
841 return true; | 843 return true; |
842 } | 844 } |
843 return false; | 845 return false; |
844 } | 846 } |
845 | 847 |
846 bool PeekInOrOf() { | 848 bool PeekInOrOf() { |
847 return peek() == Token::IN || PeekContextualKeyword(CStrVector("of")); | 849 return peek() == Token::IN || PeekContextualKeyword(CStrVector("of")); |
848 } | 850 } |
849 | 851 |
850 // Checks whether an octal literal was last seen between beg_pos and end_pos. | 852 // Checks whether an octal literal was last seen between beg_pos and end_pos. |
851 // If so, reports an error. Only called for strict mode and template strings. | 853 // Only called for strict mode strings. |
852 void CheckOctalLiteral(int beg_pos, int end_pos, bool is_template, bool* ok) { | 854 void CheckStrictOctalLiteral(int beg_pos, int end_pos, bool* ok) { |
853 Scanner::Location octal = scanner()->octal_position(); | 855 Scanner::Location octal = scanner()->octal_position(); |
854 if (octal.IsValid() && beg_pos <= octal.beg_pos && | 856 if (octal.IsValid() && beg_pos <= octal.beg_pos && |
855 octal.end_pos <= end_pos) { | 857 octal.end_pos <= end_pos) { |
856 MessageTemplate::Template message = | 858 MessageTemplate::Template message = scanner()->octal_message(); |
857 is_template ? MessageTemplate::kTemplateOctalLiteral | |
858 : scanner()->octal_message(); | |
859 DCHECK_NE(message, MessageTemplate::kNone); | 859 DCHECK_NE(message, MessageTemplate::kNone); |
860 impl()->ReportMessageAt(octal, message); | 860 impl()->ReportMessageAt(octal, message); |
861 scanner()->clear_octal_position(); | 861 scanner()->clear_octal_position(); |
862 if (message == MessageTemplate::kStrictDecimalWithLeadingZero) { | 862 if (message == MessageTemplate::kStrictDecimalWithLeadingZero) { |
863 impl()->CountUsage(v8::Isolate::kDecimalWithLeadingZeroInStrictMode); | 863 impl()->CountUsage(v8::Isolate::kDecimalWithLeadingZeroInStrictMode); |
864 } | 864 } |
865 *ok = false; | 865 *ok = false; |
866 } | 866 } |
867 } | 867 } |
868 | 868 |
869 inline void CheckStrictOctalLiteral(int beg_pos, int end_pos, bool* ok) { | 869 // Checks if an octal literal or an invalid hex or unicode escape sequence |
870 CheckOctalLiteral(beg_pos, end_pos, false, ok); | 870 // appears in a template literal. In the presence of such, either |
871 } | 871 // returns false or reports an error, depending on dont_throw. Otherwise |
872 | 872 // returns true. |
873 inline void CheckTemplateOctalLiteral(int beg_pos, int end_pos, bool* ok) { | 873 inline bool CheckTemplateEscapes(bool dont_throw, bool* ok) { |
874 CheckOctalLiteral(beg_pos, end_pos, true, ok); | 874 if (scanner()->has_invalid_template_escape()) { |
875 if (dont_throw) { | |
876 scanner()->clear_invalid_template_escape(); | |
877 return false; | |
878 } | |
879 impl()->ReportMessageAt(scanner()->invalid_template_escape_location(), | |
880 scanner()->invalid_template_escape_message()); | |
881 scanner()->clear_invalid_template_escape(); | |
882 *ok = false; | |
883 } | |
884 return true; | |
vogelheim
2017/02/20 11:23:20
style nitpick:
This code looks more complicated t
bakkot1
2017/02/21 21:54:15
Done. Or, well, not quite that, because you can't
| |
875 } | 885 } |
876 | 886 |
877 void CheckDestructuringElement(ExpressionT element, int beg_pos, int end_pos); | 887 void CheckDestructuringElement(ExpressionT element, int beg_pos, int end_pos); |
878 | 888 |
879 // Checking the name of a function literal. This has to be done after parsing | 889 // Checking the name of a function literal. This has to be done after parsing |
880 // the function, since the function can declare itself strict. | 890 // the function, since the function can declare itself strict. |
881 void CheckFunctionName(LanguageMode language_mode, IdentifierT function_name, | 891 void CheckFunctionName(LanguageMode language_mode, IdentifierT function_name, |
882 FunctionNameValidity function_name_validity, | 892 FunctionNameValidity function_name_validity, |
883 const Scanner::Location& function_name_loc, bool* ok) { | 893 const Scanner::Location& function_name_loc, bool* ok) { |
884 if (function_name_validity == kSkipFunctionNameCheck) return; | 894 if (function_name_validity == kSkipFunctionNameCheck) return; |
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1163 const FormalParametersT& parameters, | 1173 const FormalParametersT& parameters, |
1164 bool* ok); | 1174 bool* ok); |
1165 void ParseAsyncFunctionBody(Scope* scope, StatementListT body, | 1175 void ParseAsyncFunctionBody(Scope* scope, StatementListT body, |
1166 FunctionKind kind, FunctionBodyType type, | 1176 FunctionKind kind, FunctionBodyType type, |
1167 bool accept_IN, int pos, bool* ok); | 1177 bool accept_IN, int pos, bool* ok); |
1168 ExpressionT ParseAsyncFunctionLiteral(bool* ok); | 1178 ExpressionT ParseAsyncFunctionLiteral(bool* ok); |
1169 ExpressionT ParseClassLiteral(IdentifierT name, | 1179 ExpressionT ParseClassLiteral(IdentifierT name, |
1170 Scanner::Location class_name_location, | 1180 Scanner::Location class_name_location, |
1171 bool name_is_strict_reserved, | 1181 bool name_is_strict_reserved, |
1172 int class_token_pos, bool* ok); | 1182 int class_token_pos, bool* ok); |
1173 ExpressionT ParseTemplateLiteral(ExpressionT tag, int start, bool* ok); | 1183 ExpressionT ParseTemplateLiteral(ExpressionT tag, int start, bool tagged, |
1184 bool* ok); | |
1174 ExpressionT ParseSuperExpression(bool is_new, bool* ok); | 1185 ExpressionT ParseSuperExpression(bool is_new, bool* ok); |
1175 ExpressionT ParseDynamicImportExpression(bool* ok); | 1186 ExpressionT ParseDynamicImportExpression(bool* ok); |
1176 ExpressionT ParseNewTargetExpression(bool* ok); | 1187 ExpressionT ParseNewTargetExpression(bool* ok); |
1177 | 1188 |
1178 void ParseFormalParameter(FormalParametersT* parameters, bool* ok); | 1189 void ParseFormalParameter(FormalParametersT* parameters, bool* ok); |
1179 void ParseFormalParameterList(FormalParametersT* parameters, bool* ok); | 1190 void ParseFormalParameterList(FormalParametersT* parameters, bool* ok); |
1180 void CheckArityRestrictions(int param_count, FunctionKind function_type, | 1191 void CheckArityRestrictions(int param_count, FunctionKind function_type, |
1181 bool has_rest, int formals_start_pos, | 1192 bool has_rest, int formals_start_pos, |
1182 int formals_end_pos, bool* ok); | 1193 int formals_end_pos, bool* ok); |
1183 | 1194 |
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1475 bool allow_natives_; | 1486 bool allow_natives_; |
1476 bool allow_tailcalls_; | 1487 bool allow_tailcalls_; |
1477 bool allow_harmony_do_expressions_; | 1488 bool allow_harmony_do_expressions_; |
1478 bool allow_harmony_function_sent_; | 1489 bool allow_harmony_function_sent_; |
1479 bool allow_harmony_restrictive_generators_; | 1490 bool allow_harmony_restrictive_generators_; |
1480 bool allow_harmony_trailing_commas_; | 1491 bool allow_harmony_trailing_commas_; |
1481 bool allow_harmony_class_fields_; | 1492 bool allow_harmony_class_fields_; |
1482 bool allow_harmony_object_rest_spread_; | 1493 bool allow_harmony_object_rest_spread_; |
1483 bool allow_harmony_dynamic_import_; | 1494 bool allow_harmony_dynamic_import_; |
1484 bool allow_harmony_async_iteration_; | 1495 bool allow_harmony_async_iteration_; |
1496 bool allow_harmony_template_escapes_; | |
1485 | 1497 |
1486 friend class DiscardableZoneScope; | 1498 friend class DiscardableZoneScope; |
1487 }; | 1499 }; |
1488 | 1500 |
1489 template <typename Impl> | 1501 template <typename Impl> |
1490 ParserBase<Impl>::FunctionState::FunctionState( | 1502 ParserBase<Impl>::FunctionState::FunctionState( |
1491 FunctionState** function_state_stack, ScopeState** scope_stack, | 1503 FunctionState** function_state_stack, ScopeState** scope_stack, |
1492 DeclarationScope* scope) | 1504 DeclarationScope* scope) |
1493 : ScopeState(scope_stack, scope), | 1505 : ScopeState(scope_stack, scope), |
1494 next_materialized_literal_index_(0), | 1506 next_materialized_literal_index_(0), |
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1842 CHECK_OK); | 1854 CHECK_OK); |
1843 class_name_location = scanner()->location(); | 1855 class_name_location = scanner()->location(); |
1844 } | 1856 } |
1845 return ParseClassLiteral(name, class_name_location, | 1857 return ParseClassLiteral(name, class_name_location, |
1846 is_strict_reserved_name, class_token_pos, ok); | 1858 is_strict_reserved_name, class_token_pos, ok); |
1847 } | 1859 } |
1848 | 1860 |
1849 case Token::TEMPLATE_SPAN: | 1861 case Token::TEMPLATE_SPAN: |
1850 case Token::TEMPLATE_TAIL: | 1862 case Token::TEMPLATE_TAIL: |
1851 BindingPatternUnexpectedToken(); | 1863 BindingPatternUnexpectedToken(); |
1852 return ParseTemplateLiteral(impl()->NoTemplateTag(), beg_pos, ok); | 1864 return ParseTemplateLiteral(impl()->NoTemplateTag(), beg_pos, false, ok); |
1853 | 1865 |
1854 case Token::MOD: | 1866 case Token::MOD: |
1855 if (allow_natives() || extension_ != NULL) { | 1867 if (allow_natives() || extension_ != NULL) { |
1856 BindingPatternUnexpectedToken(); | 1868 BindingPatternUnexpectedToken(); |
1857 return ParseV8Intrinsic(ok); | 1869 return ParseV8Intrinsic(ok); |
1858 } | 1870 } |
1859 break; | 1871 break; |
1860 | 1872 |
1861 case Token::DO: | 1873 case Token::DO: |
1862 if (allow_harmony_do_expressions()) { | 1874 if (allow_harmony_do_expressions()) { |
(...skipping 1378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3241 result, factory()->NewStringLiteral(name, pos), pos); | 3253 result, factory()->NewStringLiteral(name, pos), pos); |
3242 impl()->PushLiteralName(name); | 3254 impl()->PushLiteralName(name); |
3243 break; | 3255 break; |
3244 } | 3256 } |
3245 | 3257 |
3246 case Token::TEMPLATE_SPAN: | 3258 case Token::TEMPLATE_SPAN: |
3247 case Token::TEMPLATE_TAIL: { | 3259 case Token::TEMPLATE_TAIL: { |
3248 impl()->RewriteNonPattern(CHECK_OK); | 3260 impl()->RewriteNonPattern(CHECK_OK); |
3249 BindingPatternUnexpectedToken(); | 3261 BindingPatternUnexpectedToken(); |
3250 ArrowFormalParametersUnexpectedToken(); | 3262 ArrowFormalParametersUnexpectedToken(); |
3251 result = ParseTemplateLiteral(result, position(), CHECK_OK); | 3263 result = ParseTemplateLiteral(result, position(), true, CHECK_OK); |
3252 break; | 3264 break; |
3253 } | 3265 } |
3254 | 3266 |
3255 default: | 3267 default: |
3256 return result; | 3268 return result; |
3257 } | 3269 } |
3258 } | 3270 } |
3259 } | 3271 } |
3260 | 3272 |
3261 template <typename Impl> | 3273 template <typename Impl> |
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3521 if (scanner()->current_token() == Token::IDENTIFIER) { | 3533 if (scanner()->current_token() == Token::IDENTIFIER) { |
3522 pos = position(); | 3534 pos = position(); |
3523 } else { | 3535 } else { |
3524 pos = peek_position(); | 3536 pos = peek_position(); |
3525 if (expression->IsFunctionLiteral()) { | 3537 if (expression->IsFunctionLiteral()) { |
3526 // If the tag function looks like an IIFE, set_parenthesized() to | 3538 // If the tag function looks like an IIFE, set_parenthesized() to |
3527 // force eager compilation. | 3539 // force eager compilation. |
3528 expression->AsFunctionLiteral()->SetShouldEagerCompile(); | 3540 expression->AsFunctionLiteral()->SetShouldEagerCompile(); |
3529 } | 3541 } |
3530 } | 3542 } |
3531 expression = ParseTemplateLiteral(expression, pos, CHECK_OK); | 3543 expression = ParseTemplateLiteral(expression, pos, true, CHECK_OK); |
3532 break; | 3544 break; |
3533 } | 3545 } |
3534 case Token::ILLEGAL: { | 3546 case Token::ILLEGAL: { |
3535 ReportUnexpectedTokenAt(scanner()->peek_location(), Token::ILLEGAL); | 3547 ReportUnexpectedTokenAt(scanner()->peek_location(), Token::ILLEGAL); |
3536 *ok = false; | 3548 *ok = false; |
3537 return impl()->EmptyExpression(); | 3549 return impl()->EmptyExpression(); |
3538 } | 3550 } |
3539 default: | 3551 default: |
3540 return expression; | 3552 return expression; |
3541 } | 3553 } |
(...skipping 859 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4401 } | 4413 } |
4402 return impl()->ParseFunctionLiteral( | 4414 return impl()->ParseFunctionLiteral( |
4403 name, scanner()->location(), | 4415 name, scanner()->location(), |
4404 is_strict_reserved ? kFunctionNameIsStrictReserved | 4416 is_strict_reserved ? kFunctionNameIsStrictReserved |
4405 : kFunctionNameValidityUnknown, | 4417 : kFunctionNameValidityUnknown, |
4406 FunctionKind::kAsyncFunction, pos, type, language_mode(), CHECK_OK); | 4418 FunctionKind::kAsyncFunction, pos, type, language_mode(), CHECK_OK); |
4407 } | 4419 } |
4408 | 4420 |
4409 template <typename Impl> | 4421 template <typename Impl> |
4410 typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseTemplateLiteral( | 4422 typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseTemplateLiteral( |
4411 ExpressionT tag, int start, bool* ok) { | 4423 ExpressionT tag, int start, bool tagged, bool* ok) { |
4412 // A TemplateLiteral is made up of 0 or more TEMPLATE_SPAN tokens (literal | 4424 // A TemplateLiteral is made up of 0 or more TEMPLATE_SPAN tokens (literal |
4413 // text followed by a substitution expression), finalized by a single | 4425 // text followed by a substitution expression), finalized by a single |
4414 // TEMPLATE_TAIL. | 4426 // TEMPLATE_TAIL. |
4415 // | 4427 // |
4416 // In terms of draft language, TEMPLATE_SPAN may be either the TemplateHead or | 4428 // In terms of draft language, TEMPLATE_SPAN may be either the TemplateHead or |
4417 // TemplateMiddle productions, while TEMPLATE_TAIL is either TemplateTail, or | 4429 // TemplateMiddle productions, while TEMPLATE_TAIL is either TemplateTail, or |
4418 // NoSubstitutionTemplate. | 4430 // NoSubstitutionTemplate. |
4419 // | 4431 // |
4420 // When parsing a TemplateLiteral, we must have scanned either an initial | 4432 // When parsing a TemplateLiteral, we must have scanned either an initial |
4421 // TEMPLATE_SPAN, or a TEMPLATE_TAIL. | 4433 // TEMPLATE_SPAN, or a TEMPLATE_TAIL. |
4422 CHECK(peek() == Token::TEMPLATE_SPAN || peek() == Token::TEMPLATE_TAIL); | 4434 CHECK(peek() == Token::TEMPLATE_SPAN || peek() == Token::TEMPLATE_TAIL); |
4423 | 4435 |
4436 bool allow_illegal_escapes = tagged && allow_harmony_template_escapes(); | |
4437 bool should_cook = true; | |
vogelheim
2017/02/20 11:23:20
naming/style nitpick: If I read this correctly, 's
| |
4438 | |
4424 // If we reach a TEMPLATE_TAIL first, we are parsing a NoSubstitutionTemplate. | 4439 // If we reach a TEMPLATE_TAIL first, we are parsing a NoSubstitutionTemplate. |
4425 // In this case we may simply consume the token and build a template with a | 4440 // In this case we may simply consume the token and build a template with a |
4426 // single TEMPLATE_SPAN and no expressions. | 4441 // single TEMPLATE_SPAN and no expressions. |
4427 if (peek() == Token::TEMPLATE_TAIL) { | 4442 if (peek() == Token::TEMPLATE_TAIL) { |
4428 Consume(Token::TEMPLATE_TAIL); | 4443 Consume(Token::TEMPLATE_TAIL); |
4429 int pos = position(); | 4444 int pos = position(); |
4430 CheckTemplateOctalLiteral(pos, peek_position(), CHECK_OK); | |
4431 typename Impl::TemplateLiteralState ts = impl()->OpenTemplateLiteral(pos); | 4445 typename Impl::TemplateLiteralState ts = impl()->OpenTemplateLiteral(pos); |
4432 impl()->AddTemplateSpan(&ts, true); | 4446 should_cook = CheckTemplateEscapes(allow_illegal_escapes, CHECK_OK); |
4447 impl()->AddTemplateSpan(&ts, should_cook, true); | |
4433 return impl()->CloseTemplateLiteral(&ts, start, tag); | 4448 return impl()->CloseTemplateLiteral(&ts, start, tag); |
4434 } | 4449 } |
4435 | 4450 |
4436 Consume(Token::TEMPLATE_SPAN); | 4451 Consume(Token::TEMPLATE_SPAN); |
4437 int pos = position(); | 4452 int pos = position(); |
4453 should_cook = CheckTemplateEscapes(allow_illegal_escapes, CHECK_OK); | |
4438 typename Impl::TemplateLiteralState ts = impl()->OpenTemplateLiteral(pos); | 4454 typename Impl::TemplateLiteralState ts = impl()->OpenTemplateLiteral(pos); |
4439 impl()->AddTemplateSpan(&ts, false); | 4455 impl()->AddTemplateSpan(&ts, should_cook, false); |
4440 Token::Value next; | 4456 Token::Value next; |
4441 | 4457 |
4442 // If we open with a TEMPLATE_SPAN, we must scan the subsequent expression, | 4458 // If we open with a TEMPLATE_SPAN, we must scan the subsequent expression, |
4443 // and repeat if the following token is a TEMPLATE_SPAN as well (in this | 4459 // and repeat if the following token is a TEMPLATE_SPAN as well (in this |
4444 // case, representing a TemplateMiddle). | 4460 // case, representing a TemplateMiddle). |
4445 | 4461 |
4446 do { | 4462 do { |
4447 CheckTemplateOctalLiteral(pos, peek_position(), CHECK_OK); | |
4448 next = peek(); | 4463 next = peek(); |
4449 if (next == Token::EOS) { | 4464 if (next == Token::EOS) { |
4450 impl()->ReportMessageAt(Scanner::Location(start, peek_position()), | 4465 impl()->ReportMessageAt(Scanner::Location(start, peek_position()), |
4451 MessageTemplate::kUnterminatedTemplate); | 4466 MessageTemplate::kUnterminatedTemplate); |
4452 *ok = false; | 4467 *ok = false; |
4453 return impl()->EmptyExpression(); | 4468 return impl()->EmptyExpression(); |
4454 } else if (next == Token::ILLEGAL) { | 4469 } else if (next == Token::ILLEGAL) { |
4455 impl()->ReportMessageAt( | 4470 impl()->ReportMessageAt( |
4456 Scanner::Location(position() + 1, peek_position()), | 4471 Scanner::Location(position() + 1, peek_position()), |
4457 MessageTemplate::kUnexpectedToken, "ILLEGAL", kSyntaxError); | 4472 MessageTemplate::kUnexpectedToken, "ILLEGAL", kSyntaxError); |
(...skipping 25 matching lines...) Expand all Loading... | |
4483 *ok = false; | 4498 *ok = false; |
4484 return impl()->EmptyExpression(); | 4499 return impl()->EmptyExpression(); |
4485 } else if (next == Token::ILLEGAL) { | 4500 } else if (next == Token::ILLEGAL) { |
4486 impl()->ReportMessageAt( | 4501 impl()->ReportMessageAt( |
4487 Scanner::Location(position() + 1, peek_position()), | 4502 Scanner::Location(position() + 1, peek_position()), |
4488 MessageTemplate::kUnexpectedToken, "ILLEGAL", kSyntaxError); | 4503 MessageTemplate::kUnexpectedToken, "ILLEGAL", kSyntaxError); |
4489 *ok = false; | 4504 *ok = false; |
4490 return impl()->EmptyExpression(); | 4505 return impl()->EmptyExpression(); |
4491 } | 4506 } |
4492 | 4507 |
4493 impl()->AddTemplateSpan(&ts, next == Token::TEMPLATE_TAIL); | 4508 should_cook = CheckTemplateEscapes(allow_illegal_escapes, CHECK_OK); |
4509 impl()->AddTemplateSpan(&ts, should_cook, next == Token::TEMPLATE_TAIL); | |
4494 } while (next == Token::TEMPLATE_SPAN); | 4510 } while (next == Token::TEMPLATE_SPAN); |
4495 | 4511 |
4496 DCHECK_EQ(next, Token::TEMPLATE_TAIL); | 4512 DCHECK_EQ(next, Token::TEMPLATE_TAIL); |
4497 CheckTemplateOctalLiteral(pos, peek_position(), CHECK_OK); | |
4498 // Once we've reached a TEMPLATE_TAIL, we can close the TemplateLiteral. | 4513 // Once we've reached a TEMPLATE_TAIL, we can close the TemplateLiteral. |
4499 return impl()->CloseTemplateLiteral(&ts, start, tag); | 4514 return impl()->CloseTemplateLiteral(&ts, start, tag); |
4500 } | 4515 } |
4501 | 4516 |
4502 template <typename Impl> | 4517 template <typename Impl> |
4503 typename ParserBase<Impl>::ExpressionT | 4518 typename ParserBase<Impl>::ExpressionT |
4504 ParserBase<Impl>::CheckAndRewriteReferenceExpression( | 4519 ParserBase<Impl>::CheckAndRewriteReferenceExpression( |
4505 ExpressionT expression, int beg_pos, int end_pos, | 4520 ExpressionT expression, int beg_pos, int end_pos, |
4506 MessageTemplate::Template message, bool* ok) { | 4521 MessageTemplate::Template message, bool* ok) { |
4507 return CheckAndRewriteReferenceExpression(expression, beg_pos, end_pos, | 4522 return CheckAndRewriteReferenceExpression(expression, beg_pos, end_pos, |
(...skipping 1364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5872 } | 5887 } |
5873 | 5888 |
5874 #undef CHECK_OK | 5889 #undef CHECK_OK |
5875 #undef CHECK_OK_CUSTOM | 5890 #undef CHECK_OK_CUSTOM |
5876 #undef CHECK_OK_VOID | 5891 #undef CHECK_OK_VOID |
5877 | 5892 |
5878 } // namespace internal | 5893 } // namespace internal |
5879 } // namespace v8 | 5894 } // namespace v8 |
5880 | 5895 |
5881 #endif // V8_PARSING_PARSER_BASE_H | 5896 #endif // V8_PARSING_PARSER_BASE_H |
OLD | NEW |