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 #include "src/parsing/parser.h" | 5 #include "src/parsing/parser.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "src/api.h" | 9 #include "src/api.h" |
10 #include "src/ast/ast-expression-rewriter.h" | 10 #include "src/ast/ast-expression-rewriter.h" |
(...skipping 536 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
547 set_allow_natives(FLAG_allow_natives_syntax || info->is_native()); | 547 set_allow_natives(FLAG_allow_natives_syntax || info->is_native()); |
548 set_allow_tailcalls(FLAG_harmony_tailcalls && !info->is_native() && | 548 set_allow_tailcalls(FLAG_harmony_tailcalls && !info->is_native() && |
549 info->isolate()->is_tail_call_elimination_enabled()); | 549 info->isolate()->is_tail_call_elimination_enabled()); |
550 set_allow_harmony_do_expressions(FLAG_harmony_do_expressions); | 550 set_allow_harmony_do_expressions(FLAG_harmony_do_expressions); |
551 set_allow_harmony_function_sent(FLAG_harmony_function_sent); | 551 set_allow_harmony_function_sent(FLAG_harmony_function_sent); |
552 set_allow_harmony_restrictive_generators(FLAG_harmony_restrictive_generators); | 552 set_allow_harmony_restrictive_generators(FLAG_harmony_restrictive_generators); |
553 set_allow_harmony_trailing_commas(FLAG_harmony_trailing_commas); | 553 set_allow_harmony_trailing_commas(FLAG_harmony_trailing_commas); |
554 set_allow_harmony_class_fields(FLAG_harmony_class_fields); | 554 set_allow_harmony_class_fields(FLAG_harmony_class_fields); |
555 set_allow_harmony_object_rest_spread(FLAG_harmony_object_rest_spread); | 555 set_allow_harmony_object_rest_spread(FLAG_harmony_object_rest_spread); |
556 set_allow_harmony_dynamic_import(FLAG_harmony_dynamic_import); | 556 set_allow_harmony_dynamic_import(FLAG_harmony_dynamic_import); |
| 557 set_allow_harmony_template_escapes(FLAG_harmony_template_escapes); |
557 for (int feature = 0; feature < v8::Isolate::kUseCounterFeatureCount; | 558 for (int feature = 0; feature < v8::Isolate::kUseCounterFeatureCount; |
558 ++feature) { | 559 ++feature) { |
559 use_counts_[feature] = 0; | 560 use_counts_[feature] = 0; |
560 } | 561 } |
561 if (info->ast_value_factory() == NULL) { | 562 if (info->ast_value_factory() == NULL) { |
562 // info takes ownership of AstValueFactory. | 563 // info takes ownership of AstValueFactory. |
563 info->set_ast_value_factory(new AstValueFactory( | 564 info->set_ast_value_factory(new AstValueFactory( |
564 zone(), info->isolate()->ast_string_constants(), info->hash_seed())); | 565 zone(), info->isolate()->ast_string_constants(), info->hash_seed())); |
565 info->set_ast_value_factory_owned(); | 566 info->set_ast_value_factory_owned(); |
566 ast_value_factory_ = info->ast_value_factory(); | 567 ast_value_factory_ = info->ast_value_factory(); |
(...skipping 2899 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3466 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("v8.runtime_stats"), | 3467 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("v8.runtime_stats"), |
3467 "V8.RuntimeStats", TRACE_EVENT_SCOPE_THREAD, | 3468 "V8.RuntimeStats", TRACE_EVENT_SCOPE_THREAD, |
3468 "runtime-call-stats", std::move(value)); | 3469 "runtime-call-stats", std::move(value)); |
3469 } | 3470 } |
3470 } | 3471 } |
3471 | 3472 |
3472 Parser::TemplateLiteralState Parser::OpenTemplateLiteral(int pos) { | 3473 Parser::TemplateLiteralState Parser::OpenTemplateLiteral(int pos) { |
3473 return new (zone()) TemplateLiteral(zone(), pos); | 3474 return new (zone()) TemplateLiteral(zone(), pos); |
3474 } | 3475 } |
3475 | 3476 |
3476 | 3477 void Parser::AddTemplateSpan(TemplateLiteralState* state, bool should_cook, |
3477 void Parser::AddTemplateSpan(TemplateLiteralState* state, bool tail) { | 3478 bool tail) { |
| 3479 DCHECK(should_cook || allow_harmony_template_escapes()); |
3478 int pos = scanner()->location().beg_pos; | 3480 int pos = scanner()->location().beg_pos; |
3479 int end = scanner()->location().end_pos - (tail ? 1 : 2); | 3481 int end = scanner()->location().end_pos - (tail ? 1 : 2); |
3480 const AstRawString* tv = scanner()->CurrentSymbol(ast_value_factory()); | |
3481 const AstRawString* trv = scanner()->CurrentRawSymbol(ast_value_factory()); | 3482 const AstRawString* trv = scanner()->CurrentRawSymbol(ast_value_factory()); |
3482 Literal* cooked = factory()->NewStringLiteral(tv, pos); | |
3483 Literal* raw = factory()->NewStringLiteral(trv, pos); | 3483 Literal* raw = factory()->NewStringLiteral(trv, pos); |
3484 (*state)->AddTemplateSpan(cooked, raw, end, zone()); | 3484 if (should_cook) { |
| 3485 const AstRawString* tv = scanner()->CurrentSymbol(ast_value_factory()); |
| 3486 Literal* cooked = factory()->NewStringLiteral(tv, pos); |
| 3487 (*state)->AddTemplateSpan(cooked, raw, end, zone()); |
| 3488 } else { |
| 3489 (*state)->AddTemplateSpan(GetLiteralUndefined(pos), raw, end, zone()); |
| 3490 } |
3485 } | 3491 } |
3486 | 3492 |
3487 | 3493 |
3488 void Parser::AddTemplateExpression(TemplateLiteralState* state, | 3494 void Parser::AddTemplateExpression(TemplateLiteralState* state, |
3489 Expression* expression) { | 3495 Expression* expression) { |
3490 (*state)->AddExpression(expression, zone()); | 3496 (*state)->AddExpression(expression, zone()); |
3491 } | 3497 } |
3492 | 3498 |
3493 | 3499 |
3494 Expression* Parser::CloseTemplateLiteral(TemplateLiteralState* state, int start, | 3500 Expression* Parser::CloseTemplateLiteral(TemplateLiteralState* state, int start, |
(...skipping 1532 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5027 | 5033 |
5028 return final_loop; | 5034 return final_loop; |
5029 } | 5035 } |
5030 | 5036 |
5031 #undef CHECK_OK | 5037 #undef CHECK_OK |
5032 #undef CHECK_OK_VOID | 5038 #undef CHECK_OK_VOID |
5033 #undef CHECK_FAILED | 5039 #undef CHECK_FAILED |
5034 | 5040 |
5035 } // namespace internal | 5041 } // namespace internal |
5036 } // namespace v8 | 5042 } // namespace v8 |
OLD | NEW |