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/parser.h" | 5 #include "src/parser.h" |
6 | 6 |
7 #include "src/api.h" | 7 #include "src/api.h" |
8 #include "src/ast.h" | 8 #include "src/ast.h" |
9 #include "src/ast-literal-reindexer.h" | 9 #include "src/ast-literal-reindexer.h" |
10 #include "src/bailout-reason.h" | 10 #include "src/bailout-reason.h" |
11 #include "src/base/platform/platform.h" | 11 #include "src/base/platform/platform.h" |
12 #include "src/bootstrapper.h" | 12 #include "src/bootstrapper.h" |
13 #include "src/char-predicates-inl.h" | 13 #include "src/char-predicates-inl.h" |
14 #include "src/codegen.h" | 14 #include "src/codegen.h" |
15 #include "src/compiler.h" | 15 #include "src/compiler.h" |
16 #include "src/messages.h" | 16 #include "src/messages.h" |
17 #include "src/preparser.h" | 17 #include "src/preparser.h" |
| 18 #include "src/rewriter.h" |
18 #include "src/runtime/runtime.h" | 19 #include "src/runtime/runtime.h" |
19 #include "src/scanner-character-streams.h" | 20 #include "src/scanner-character-streams.h" |
20 #include "src/scopeinfo.h" | 21 #include "src/scopeinfo.h" |
21 #include "src/string-stream.h" | 22 #include "src/string-stream.h" |
22 | 23 |
23 namespace v8 { | 24 namespace v8 { |
24 namespace internal { | 25 namespace internal { |
25 | 26 |
26 ScriptData::ScriptData(const byte* data, int length) | 27 ScriptData::ScriptData(const byte* data, int length) |
27 : owns_data_(false), rejected_(false), data_(data), length_(length) { | 28 : owns_data_(false), rejected_(false), data_(data), length_(length) { |
(...skipping 889 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
917 set_allow_harmony_sloppy_function(FLAG_harmony_sloppy_function); | 918 set_allow_harmony_sloppy_function(FLAG_harmony_sloppy_function); |
918 set_allow_harmony_sloppy_let(FLAG_harmony_sloppy_let); | 919 set_allow_harmony_sloppy_let(FLAG_harmony_sloppy_let); |
919 set_allow_harmony_rest_parameters(FLAG_harmony_rest_parameters); | 920 set_allow_harmony_rest_parameters(FLAG_harmony_rest_parameters); |
920 set_allow_harmony_default_parameters(FLAG_harmony_default_parameters); | 921 set_allow_harmony_default_parameters(FLAG_harmony_default_parameters); |
921 set_allow_harmony_spread_calls(FLAG_harmony_spread_calls); | 922 set_allow_harmony_spread_calls(FLAG_harmony_spread_calls); |
922 set_allow_harmony_destructuring(FLAG_harmony_destructuring); | 923 set_allow_harmony_destructuring(FLAG_harmony_destructuring); |
923 set_allow_harmony_spread_arrays(FLAG_harmony_spread_arrays); | 924 set_allow_harmony_spread_arrays(FLAG_harmony_spread_arrays); |
924 set_allow_harmony_new_target(FLAG_harmony_new_target); | 925 set_allow_harmony_new_target(FLAG_harmony_new_target); |
925 set_allow_strong_mode(FLAG_strong_mode); | 926 set_allow_strong_mode(FLAG_strong_mode); |
926 set_allow_legacy_const(FLAG_legacy_const); | 927 set_allow_legacy_const(FLAG_legacy_const); |
| 928 set_allow_harmony_do_expressions(FLAG_harmony_do_expressions); |
927 for (int feature = 0; feature < v8::Isolate::kUseCounterFeatureCount; | 929 for (int feature = 0; feature < v8::Isolate::kUseCounterFeatureCount; |
928 ++feature) { | 930 ++feature) { |
929 use_counts_[feature] = 0; | 931 use_counts_[feature] = 0; |
930 } | 932 } |
931 if (info->ast_value_factory() == NULL) { | 933 if (info->ast_value_factory() == NULL) { |
932 // info takes ownership of AstValueFactory. | 934 // info takes ownership of AstValueFactory. |
933 info->set_ast_value_factory(new AstValueFactory(zone(), info->hash_seed())); | 935 info->set_ast_value_factory(new AstValueFactory(zone(), info->hash_seed())); |
934 info->set_ast_value_factory_owned(); | 936 info->set_ast_value_factory_owned(); |
935 ast_value_factory_ = info->ast_value_factory(); | 937 ast_value_factory_ = info->ast_value_factory(); |
936 } | 938 } |
(...skipping 3083 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4020 DCHECK(parser_->allow_harmony_default_parameters()); | 4022 DCHECK(parser_->allow_harmony_default_parameters()); |
4021 DCHECK(!assignment->is_compound()); | 4023 DCHECK(!assignment->is_compound()); |
4022 initializer = assignment->value(); | 4024 initializer = assignment->value(); |
4023 expr = assignment->target(); | 4025 expr = assignment->target(); |
4024 } | 4026 } |
4025 | 4027 |
4026 AddFormalParameter(parameters, expr, initializer, is_rest); | 4028 AddFormalParameter(parameters, expr, initializer, is_rest); |
4027 } | 4029 } |
4028 | 4030 |
4029 | 4031 |
| 4032 DoExpression* Parser::ParseDoExpression(bool* ok) { |
| 4033 // AssignmentExpression :: |
| 4034 // do '{' StatementList '}' |
| 4035 int pos = peek_position(); |
| 4036 |
| 4037 Expect(Token::DO, CHECK_OK); |
| 4038 Variable* result = |
| 4039 scope_->NewTemporary(ast_value_factory()->dot_result_string()); |
| 4040 Block* block = ParseScopedBlock(nullptr, CHECK_OK); |
| 4041 DoExpression* expr = factory()->NewDoExpression(block, result, pos); |
| 4042 if (!Rewriter::Rewrite(this, expr, ast_value_factory())) { |
| 4043 *ok = false; |
| 4044 return nullptr; |
| 4045 } |
| 4046 return expr; |
| 4047 } |
| 4048 |
| 4049 |
4030 void ParserTraits::ParseArrowFunctionFormalParameterList( | 4050 void ParserTraits::ParseArrowFunctionFormalParameterList( |
4031 ParserFormalParameters* parameters, Expression* expr, | 4051 ParserFormalParameters* parameters, Expression* expr, |
4032 const Scanner::Location& params_loc, | 4052 const Scanner::Location& params_loc, |
4033 Scanner::Location* duplicate_loc, bool* ok) { | 4053 Scanner::Location* duplicate_loc, bool* ok) { |
4034 if (expr->IsEmptyParentheses()) return; | 4054 if (expr->IsEmptyParentheses()) return; |
4035 | 4055 |
4036 ParseArrowFunctionFormalParameters(parameters, expr, params_loc, ok); | 4056 ParseArrowFunctionFormalParameters(parameters, expr, params_loc, ok); |
4037 if (!*ok) return; | 4057 if (!*ok) return; |
4038 | 4058 |
4039 ExpressionClassifier classifier; | 4059 ExpressionClassifier classifier; |
(...skipping 719 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4759 SET_ALLOW(natives); | 4779 SET_ALLOW(natives); |
4760 SET_ALLOW(harmony_sloppy); | 4780 SET_ALLOW(harmony_sloppy); |
4761 SET_ALLOW(harmony_sloppy_let); | 4781 SET_ALLOW(harmony_sloppy_let); |
4762 SET_ALLOW(harmony_rest_parameters); | 4782 SET_ALLOW(harmony_rest_parameters); |
4763 SET_ALLOW(harmony_default_parameters); | 4783 SET_ALLOW(harmony_default_parameters); |
4764 SET_ALLOW(harmony_spread_calls); | 4784 SET_ALLOW(harmony_spread_calls); |
4765 SET_ALLOW(harmony_destructuring); | 4785 SET_ALLOW(harmony_destructuring); |
4766 SET_ALLOW(harmony_spread_arrays); | 4786 SET_ALLOW(harmony_spread_arrays); |
4767 SET_ALLOW(harmony_new_target); | 4787 SET_ALLOW(harmony_new_target); |
4768 SET_ALLOW(strong_mode); | 4788 SET_ALLOW(strong_mode); |
| 4789 SET_ALLOW(harmony_do_expressions); |
4769 #undef SET_ALLOW | 4790 #undef SET_ALLOW |
4770 } | 4791 } |
4771 PreParser::PreParseResult result = reusable_preparser_->PreParseLazyFunction( | 4792 PreParser::PreParseResult result = reusable_preparser_->PreParseLazyFunction( |
4772 language_mode(), function_state_->kind(), scope_->has_simple_parameters(), | 4793 language_mode(), function_state_->kind(), scope_->has_simple_parameters(), |
4773 logger, bookmark); | 4794 logger, bookmark); |
4774 if (pre_parse_timer_ != NULL) { | 4795 if (pre_parse_timer_ != NULL) { |
4775 pre_parse_timer_->Stop(); | 4796 pre_parse_timer_->Stop(); |
4776 } | 4797 } |
4777 return result; | 4798 return result; |
4778 } | 4799 } |
(...skipping 1558 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6337 | 6358 |
6338 Expression* Parser::SpreadCallNew(Expression* function, | 6359 Expression* Parser::SpreadCallNew(Expression* function, |
6339 ZoneList<v8::internal::Expression*>* args, | 6360 ZoneList<v8::internal::Expression*>* args, |
6340 int pos) { | 6361 int pos) { |
6341 args->InsertAt(0, function, zone()); | 6362 args->InsertAt(0, function, zone()); |
6342 | 6363 |
6343 return factory()->NewCallRuntime(Context::REFLECT_CONSTRUCT_INDEX, args, pos); | 6364 return factory()->NewCallRuntime(Context::REFLECT_CONSTRUCT_INDEX, args, pos); |
6344 } | 6365 } |
6345 } // namespace internal | 6366 } // namespace internal |
6346 } // namespace v8 | 6367 } // namespace v8 |
OLD | NEW |