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/v8.h" | 5 #include "src/v8.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/bailout-reason.h" | 9 #include "src/bailout-reason.h" |
10 #include "src/base/platform/platform.h" | 10 #include "src/base/platform/platform.h" |
(...skipping 734 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
745 pre_parse_timer_(NULL) { | 745 pre_parse_timer_(NULL) { |
746 DCHECK(!script().is_null() || info->source_stream() != NULL); | 746 DCHECK(!script().is_null() || info->source_stream() != NULL); |
747 set_allow_harmony_scoping(!info->is_native() && FLAG_harmony_scoping); | 747 set_allow_harmony_scoping(!info->is_native() && FLAG_harmony_scoping); |
748 set_allow_modules(!info->is_native() && FLAG_harmony_modules); | 748 set_allow_modules(!info->is_native() && FLAG_harmony_modules); |
749 set_allow_natives_syntax(FLAG_allow_natives_syntax || info->is_native()); | 749 set_allow_natives_syntax(FLAG_allow_natives_syntax || info->is_native()); |
750 set_allow_lazy(false); // Must be explicitly enabled. | 750 set_allow_lazy(false); // Must be explicitly enabled. |
751 set_allow_arrow_functions(FLAG_harmony_arrow_functions); | 751 set_allow_arrow_functions(FLAG_harmony_arrow_functions); |
752 set_allow_harmony_numeric_literals(FLAG_harmony_numeric_literals); | 752 set_allow_harmony_numeric_literals(FLAG_harmony_numeric_literals); |
753 set_allow_classes(FLAG_harmony_classes); | 753 set_allow_classes(FLAG_harmony_classes); |
754 set_allow_harmony_object_literals(FLAG_harmony_object_literals); | 754 set_allow_harmony_object_literals(FLAG_harmony_object_literals); |
| 755 set_allow_harmony_templates(FLAG_harmony_templates); |
755 for (int feature = 0; feature < v8::Isolate::kUseCounterFeatureCount; | 756 for (int feature = 0; feature < v8::Isolate::kUseCounterFeatureCount; |
756 ++feature) { | 757 ++feature) { |
757 use_counts_[feature] = 0; | 758 use_counts_[feature] = 0; |
758 } | 759 } |
759 if (info->ast_value_factory() == NULL) { | 760 if (info->ast_value_factory() == NULL) { |
760 // info takes ownership of AstValueFactory. | 761 // info takes ownership of AstValueFactory. |
761 info->SetAstValueFactory( | 762 info->SetAstValueFactory( |
762 new AstValueFactory(zone(), parse_info->hash_seed)); | 763 new AstValueFactory(zone(), parse_info->hash_seed)); |
763 } | 764 } |
764 } | 765 } |
(...skipping 4189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4954 info()->SetFunction(result); | 4955 info()->SetFunction(result); |
4955 | 4956 |
4956 // We cannot internalize on a background thread; a foreground task will take | 4957 // We cannot internalize on a background thread; a foreground task will take |
4957 // care of calling Parser::Internalize just before compilation. | 4958 // care of calling Parser::Internalize just before compilation. |
4958 | 4959 |
4959 if (compile_options() == ScriptCompiler::kProduceParserCache) { | 4960 if (compile_options() == ScriptCompiler::kProduceParserCache) { |
4960 if (result != NULL) *info_->cached_data() = recorder.GetScriptData(); | 4961 if (result != NULL) *info_->cached_data() = recorder.GetScriptData(); |
4961 log_ = NULL; | 4962 log_ = NULL; |
4962 } | 4963 } |
4963 } | 4964 } |
| 4965 |
| 4966 |
| 4967 ParserTraits::TemplateLiteralState Parser::OpenTemplateLiteral(int pos) { |
| 4968 return new (zone()) ParserTraits::TemplateLiteral(zone(), pos); |
| 4969 } |
| 4970 |
| 4971 |
| 4972 void Parser::AddTemplateSpan(TemplateLiteralState* state) { |
| 4973 int pos = scanner()->location().beg_pos; |
| 4974 const AstRawString* tv = scanner()->CurrentSymbol(ast_value_factory()); |
| 4975 const AstRawString* trv = scanner()->CurrentRawSymbol(ast_value_factory()); |
| 4976 Literal* cooked = factory()->NewStringLiteral(tv, pos); |
| 4977 Literal* raw = factory()->NewStringLiteral(trv, pos); |
| 4978 (*state)->AddTemplateSpan(cooked, raw, zone()); |
| 4979 } |
| 4980 |
| 4981 |
| 4982 void Parser::AddTemplateExpression(TemplateLiteralState* state, |
| 4983 Expression* expression) { |
| 4984 (*state)->AddExpression(expression, zone()); |
| 4985 } |
| 4986 |
| 4987 |
| 4988 Expression* Parser::CloseTemplateLiteral(TemplateLiteralState* state, |
| 4989 int start, Expression* tag) { |
| 4990 #define COOKED_STRING(i) cookedStrings->at(i) |
| 4991 #define POS(i) cookedStrings->at(i)->position() |
| 4992 #define EXPR(i) expressions->at(i) |
| 4993 TemplateLiteral* lit = *state; |
| 4994 int pos = lit->position(); |
| 4995 const ZoneList<Expression*>* cookedStrings = lit->cooked(); |
| 4996 const ZoneList<Expression*>* expressions = lit->expressions(); |
| 4997 CHECK(cookedStrings->length() == (expressions->length() + 1)); |
| 4998 |
| 4999 if (!tag) { |
| 5000 // Build tree of BinaryOps to simplify code-generation |
| 5001 Expression* expr = NULL; |
| 5002 |
| 5003 if (!expressions->length()) { |
| 5004 // Simple case: treat as string literal |
| 5005 expr = COOKED_STRING(0); |
| 5006 } else { |
| 5007 int i; |
| 5008 expr = factory()->NewBinaryOperation(Token::ADD, |
| 5009 COOKED_STRING(0), EXPR(0), POS(0)); |
| 5010 for (i = 1; i < expressions->length(); ++i) { |
| 5011 expr = factory()->NewBinaryOperation(Token::ADD, |
| 5012 expr, factory()->NewBinaryOperation(Token::ADD, COOKED_STRING(i), |
| 5013 EXPR(i), POS(i)), POS(i)); |
| 5014 } |
| 5015 expr = factory()->NewBinaryOperation(Token::ADD, expr, COOKED_STRING(i), |
| 5016 POS(i)); |
| 5017 } |
| 5018 return expr; |
| 5019 } else { |
| 5020 const ZoneList<Expression*>* rawStrings = lit->raw(); |
| 5021 int cooked_idx = function_state_->NextMaterializedLiteralIndex(); |
| 5022 int raw_idx = function_state_->NextMaterializedLiteralIndex(); |
| 5023 |
| 5024 // GetTemplateCallSite |
| 5025 ZoneList<Expression*>* args = new (zone()) ZoneList<Expression*>(4, zone()); |
| 5026 args->Add(factory()->NewArrayLiteral( |
| 5027 const_cast<ZoneList<Expression*>*>(cookedStrings), cooked_idx, pos), |
| 5028 zone()); |
| 5029 args->Add(factory()->NewArrayLiteral( |
| 5030 const_cast<ZoneList<Expression*>*>(rawStrings), raw_idx, pos), zone()); |
| 5031 this->CheckPossibleEvalCall(tag, scope_); |
| 5032 Expression* expr = factory()->NewCallRuntime( |
| 5033 ast_value_factory()->GetTemplateCallSite_string(), NULL, args, start); |
| 5034 |
| 5035 // Call TagFn |
| 5036 ZoneList<Expression*>* callArgs = new (zone()) ZoneList<Expression*>( |
| 5037 expressions->length() + 1, zone()); |
| 5038 callArgs->Add(expr, zone()); |
| 5039 callArgs->AddAll(*expressions, zone()); |
| 5040 expr = factory()->NewCall(tag, callArgs, pos); |
| 5041 if (fni_ != NULL) fni_->RemoveLastFunction(); |
| 5042 return expr; |
| 5043 } |
| 5044 #undef COOKED_STRING |
| 5045 #undef POS |
| 5046 #undef EXPR |
| 5047 } |
| 5048 |
4964 } } // namespace v8::internal | 5049 } } // namespace v8::internal |
OLD | NEW |