Chromium Code Reviews| 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 797 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 808 pre_parse_timer_(NULL) { | 808 pre_parse_timer_(NULL) { |
| 809 DCHECK(!script().is_null() || info->source_stream() != NULL); | 809 DCHECK(!script().is_null() || info->source_stream() != NULL); |
| 810 set_allow_harmony_scoping(!info->is_native() && FLAG_harmony_scoping); | 810 set_allow_harmony_scoping(!info->is_native() && FLAG_harmony_scoping); |
| 811 set_allow_modules(!info->is_native() && FLAG_harmony_modules); | 811 set_allow_modules(!info->is_native() && FLAG_harmony_modules); |
| 812 set_allow_natives_syntax(FLAG_allow_natives_syntax || info->is_native()); | 812 set_allow_natives_syntax(FLAG_allow_natives_syntax || info->is_native()); |
| 813 set_allow_lazy(false); // Must be explicitly enabled. | 813 set_allow_lazy(false); // Must be explicitly enabled. |
| 814 set_allow_arrow_functions(FLAG_harmony_arrow_functions); | 814 set_allow_arrow_functions(FLAG_harmony_arrow_functions); |
| 815 set_allow_harmony_numeric_literals(FLAG_harmony_numeric_literals); | 815 set_allow_harmony_numeric_literals(FLAG_harmony_numeric_literals); |
| 816 set_allow_classes(FLAG_harmony_classes); | 816 set_allow_classes(FLAG_harmony_classes); |
| 817 set_allow_harmony_object_literals(FLAG_harmony_object_literals); | 817 set_allow_harmony_object_literals(FLAG_harmony_object_literals); |
| 818 set_allow_harmony_templates(FLAG_harmony_templates); | |
| 818 for (int feature = 0; feature < v8::Isolate::kUseCounterFeatureCount; | 819 for (int feature = 0; feature < v8::Isolate::kUseCounterFeatureCount; |
| 819 ++feature) { | 820 ++feature) { |
| 820 use_counts_[feature] = 0; | 821 use_counts_[feature] = 0; |
| 821 } | 822 } |
| 822 if (info->ast_value_factory() == NULL) { | 823 if (info->ast_value_factory() == NULL) { |
| 823 // info takes ownership of AstValueFactory. | 824 // info takes ownership of AstValueFactory. |
| 824 info->SetAstValueFactory( | 825 info->SetAstValueFactory( |
| 825 new AstValueFactory(zone(), parse_info->hash_seed)); | 826 new AstValueFactory(zone(), parse_info->hash_seed)); |
| 826 } | 827 } |
| 827 } | 828 } |
| (...skipping 3075 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3903 reusable_preparser_ = new PreParser(&scanner_, NULL, stack_limit_); | 3904 reusable_preparser_ = new PreParser(&scanner_, NULL, stack_limit_); |
| 3904 reusable_preparser_->set_allow_harmony_scoping(allow_harmony_scoping()); | 3905 reusable_preparser_->set_allow_harmony_scoping(allow_harmony_scoping()); |
| 3905 reusable_preparser_->set_allow_modules(allow_modules()); | 3906 reusable_preparser_->set_allow_modules(allow_modules()); |
| 3906 reusable_preparser_->set_allow_natives_syntax(allow_natives_syntax()); | 3907 reusable_preparser_->set_allow_natives_syntax(allow_natives_syntax()); |
| 3907 reusable_preparser_->set_allow_lazy(true); | 3908 reusable_preparser_->set_allow_lazy(true); |
| 3908 reusable_preparser_->set_allow_arrow_functions(allow_arrow_functions()); | 3909 reusable_preparser_->set_allow_arrow_functions(allow_arrow_functions()); |
| 3909 reusable_preparser_->set_allow_harmony_numeric_literals( | 3910 reusable_preparser_->set_allow_harmony_numeric_literals( |
| 3910 allow_harmony_numeric_literals()); | 3911 allow_harmony_numeric_literals()); |
| 3911 reusable_preparser_->set_allow_classes(allow_classes()); | 3912 reusable_preparser_->set_allow_classes(allow_classes()); |
| 3912 reusable_preparser_->set_allow_harmony_object_literals( | 3913 reusable_preparser_->set_allow_harmony_object_literals( |
| 3913 allow_harmony_object_literals()); | 3914 allow_harmony_object_literals()); |
|
marja
2014/11/12 09:23:21
Here you need to set the allow_templates flag to r
caitp (gmail)
2014/11/12 13:33:12
Done.
| |
| 3914 } | 3915 } |
| 3915 PreParser::PreParseResult result = | 3916 PreParser::PreParseResult result = |
| 3916 reusable_preparser_->PreParseLazyFunction(strict_mode(), | 3917 reusable_preparser_->PreParseLazyFunction(strict_mode(), |
| 3917 is_generator(), | 3918 is_generator(), |
| 3918 logger); | 3919 logger); |
| 3919 if (pre_parse_timer_ != NULL) { | 3920 if (pre_parse_timer_ != NULL) { |
| 3920 pre_parse_timer_->Stop(); | 3921 pre_parse_timer_->Stop(); |
| 3921 } | 3922 } |
| 3922 return result; | 3923 return result; |
| 3923 } | 3924 } |
| (...skipping 1098 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5022 info()->SetFunction(result); | 5023 info()->SetFunction(result); |
| 5023 | 5024 |
| 5024 // We cannot internalize on a background thread; a foreground task will take | 5025 // We cannot internalize on a background thread; a foreground task will take |
| 5025 // care of calling Parser::Internalize just before compilation. | 5026 // care of calling Parser::Internalize just before compilation. |
| 5026 | 5027 |
| 5027 if (compile_options() == ScriptCompiler::kProduceParserCache) { | 5028 if (compile_options() == ScriptCompiler::kProduceParserCache) { |
| 5028 if (result != NULL) *info_->cached_data() = recorder.GetScriptData(); | 5029 if (result != NULL) *info_->cached_data() = recorder.GetScriptData(); |
| 5029 log_ = NULL; | 5030 log_ = NULL; |
| 5030 } | 5031 } |
| 5031 } | 5032 } |
| 5033 | |
| 5034 | |
| 5035 ParserTraits::TemplateLiteralState Parser::OpenTemplateLiteral(int pos) { | |
| 5036 return new (zone()) ParserTraits::TemplateLiteral(zone(), pos); | |
| 5037 } | |
| 5038 | |
| 5039 | |
| 5040 void Parser::AddTemplateSpan(TemplateLiteralState* state, bool tail) { | |
| 5041 int pos = scanner()->location().beg_pos; | |
| 5042 int end = scanner()->location().end_pos - (tail ? 1 : 2); | |
| 5043 const AstRawString* tv = scanner()->CurrentSymbol(ast_value_factory()); | |
| 5044 Literal* cooked = factory()->NewStringLiteral(tv, pos); | |
| 5045 (*state)->AddTemplateSpan(cooked, end, zone()); | |
| 5046 } | |
| 5047 | |
| 5048 | |
| 5049 void Parser::AddTemplateExpression(TemplateLiteralState* state, | |
| 5050 Expression* expression) { | |
| 5051 (*state)->AddExpression(expression, zone()); | |
| 5052 } | |
| 5053 | |
| 5054 | |
| 5055 Expression* Parser::CloseTemplateLiteral(TemplateLiteralState* state, | |
| 5056 int start, Expression* tag) { | |
| 5057 #define COOKED_STRING(i) cookedStrings->at(i) | |
| 5058 #define POS(i) cookedStrings->at(i)->position() | |
| 5059 #define EXPR(i) expressions->at(i) | |
| 5060 TemplateLiteral* lit = *state; | |
| 5061 int pos = lit->position(); | |
| 5062 const ZoneList<Expression*>* cookedStrings = lit->cooked(); | |
|
marja
2014/11/12 09:23:21
Style: cookedStrings -> cooked_strings (+ other va
caitp (gmail)
2014/11/12 13:33:12
Done.
| |
| 5063 const ZoneList<Expression*>* expressions = lit->expressions(); | |
| 5064 CHECK(cookedStrings->length() == (expressions->length() + 1)); | |
| 5065 | |
| 5066 if (!tag) { | |
| 5067 // Build tree of BinaryOps to simplify code-generation | |
| 5068 Expression* expr = NULL; | |
| 5069 | |
| 5070 if (!expressions->length()) { | |
|
marja
2014/11/12 09:23:21
Style nit: if (expressions->length() == 0)
caitp (gmail)
2014/11/12 13:33:12
Done.
| |
| 5071 // Simple case: treat as string literal | |
| 5072 expr = COOKED_STRING(0); | |
| 5073 } else { | |
| 5074 int i; | |
| 5075 expr = factory()->NewBinaryOperation(Token::ADD, | |
| 5076 COOKED_STRING(0), EXPR(0), POS(0)); | |
| 5077 for (i = 1; i < expressions->length(); ++i) { | |
| 5078 expr = factory()->NewBinaryOperation(Token::ADD, | |
| 5079 expr, factory()->NewBinaryOperation(Token::ADD, COOKED_STRING(i), | |
| 5080 EXPR(i), POS(i)), POS(i)); | |
| 5081 } | |
| 5082 expr = factory()->NewBinaryOperation(Token::ADD, expr, COOKED_STRING(i), | |
| 5083 POS(i)); | |
| 5084 } | |
| 5085 return expr; | |
| 5086 } else { | |
| 5087 const ZoneList<int>* lengths = lit->lengths(); | |
| 5088 ZoneList<Expression*>* rawStrings = new (zone()) ZoneList<Expression*>( | |
|
marja
2014/11/12 09:23:21
raw_strings
| |
| 5089 cookedStrings->length(), zone()); | |
| 5090 Handle<String> source(String::cast(script()->source())); | |
| 5091 | |
| 5092 // Build raw strings | |
| 5093 for (int i = 0; i < cookedStrings->length(); ++i) { | |
|
marja
2014/11/12 09:23:21
Gets confusing with i, c and j; could you rename i
caitp (gmail)
2014/11/12 13:33:12
Done. (I'm not sure this is much easier to read, t
marja
2014/11/12 13:41:14
Yeah, they're kinda long. How about just to_index
| |
| 5094 int offset = POS(i); | |
| 5095 int length = lengths->at(i); | |
| 5096 SmartArrayPointer<char> rawChars = source->ToCString( | |
| 5097 ALLOW_NULLS, FAST_STRING_TRAVERSAL, offset + 1, length - 1, &length); | |
| 5098 int c = 0; | |
| 5099 int j = 0; | |
| 5100 | |
| 5101 // Normalize line endings | |
|
marja
2014/11/12 09:23:21
You could expand this comment to say what exactly
caitp (gmail)
2014/11/12 13:33:12
Done.
| |
| 5102 for (; j < length; ++j) { | |
| 5103 char ch = rawChars[j]; | |
| 5104 if (ch == '\r') { | |
| 5105 rawChars[c++] = '\n'; | |
| 5106 if (j < length - 1 && rawChars[j + 1] == '\n') { | |
| 5107 ++j; | |
| 5108 } | |
| 5109 } else { | |
| 5110 rawChars[c++] = ch; | |
| 5111 } | |
| 5112 } | |
| 5113 rawStrings->Add(factory()->NewStringLiteral( | |
| 5114 ast_value_factory()->GetOneByteString( | |
| 5115 OneByteVector(rawChars.get(), c)), offset), zone()); | |
| 5116 } | |
| 5117 | |
|
marja
2014/11/12 09:23:21
I like this version of raw string building thing b
| |
| 5118 int cooked_idx = function_state_->NextMaterializedLiteralIndex(); | |
| 5119 int raw_idx = function_state_->NextMaterializedLiteralIndex(); | |
| 5120 | |
| 5121 // GetTemplateCallSite | |
| 5122 ZoneList<Expression*>* args = new (zone()) ZoneList<Expression*>(4, zone()); | |
| 5123 args->Add(factory()->NewArrayLiteral( | |
| 5124 const_cast<ZoneList<Expression*>*>(cookedStrings), cooked_idx, pos), | |
| 5125 zone()); | |
| 5126 args->Add(factory()->NewArrayLiteral( | |
| 5127 const_cast<ZoneList<Expression*>*>(rawStrings), raw_idx, pos), zone()); | |
| 5128 this->CheckPossibleEvalCall(tag, scope_); | |
| 5129 Expression* expr = factory()->NewCallRuntime( | |
| 5130 ast_value_factory()->get_template_callsite_string(), NULL, args, start); | |
| 5131 | |
| 5132 // Call TagFn | |
| 5133 ZoneList<Expression*>* callArgs = new (zone()) ZoneList<Expression*>( | |
|
marja
2014/11/12 09:23:21
call_args
| |
| 5134 expressions->length() + 1, zone()); | |
| 5135 callArgs->Add(expr, zone()); | |
| 5136 callArgs->AddAll(*expressions, zone()); | |
| 5137 expr = factory()->NewCall(tag, callArgs, pos); | |
| 5138 return expr; | |
| 5139 } | |
| 5140 #undef COOKED_STRING | |
| 5141 #undef POS | |
| 5142 #undef EXPR | |
| 5143 } | |
| 5144 | |
| 5032 } } // namespace v8::internal | 5145 } } // namespace v8::internal |
| OLD | NEW |