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" |
(...skipping 4188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4199 is_lazily_parsed = false; | 4199 is_lazily_parsed = false; |
4200 | 4200 |
4201 // This is probably an initialization function. Inform the compiler it | 4201 // This is probably an initialization function. Inform the compiler it |
4202 // should also eager-compile this function, and that we expect it to be | 4202 // should also eager-compile this function, and that we expect it to be |
4203 // used once. | 4203 // used once. |
4204 eager_compile_hint = FunctionLiteral::kShouldEagerCompile; | 4204 eager_compile_hint = FunctionLiteral::kShouldEagerCompile; |
4205 should_be_used_once_hint = true; | 4205 should_be_used_once_hint = true; |
4206 } | 4206 } |
4207 } | 4207 } |
4208 if (!is_lazily_parsed) { | 4208 if (!is_lazily_parsed) { |
4209 // Determine whether the function body can be discarded after parsing. | |
4210 // The preconditions are: | |
4211 // - Lazy compilation has to be enabled. | |
4212 // - Neither V8 natives nor native function declarations can be allowed, | |
4213 // since parsing one would retroactively force the function to be | |
4214 // eagerly compiled. | |
4215 // - The invoker of this parser can't depend on the AST being eagerly | |
4216 // built (either because the function is about to be compiled, or | |
4217 // because the AST is going to be inspected for some reason). | |
4218 // - Because of the above, we can't be attempting to parse a | |
4219 // FunctionExpression; even without enclosing parentheses it might be | |
4220 // immediately invoked. | |
4221 // - The function literal shouldn't be hinted to eagerly compile. | |
4222 bool can_use_temp_zone = | |
4223 FLAG_lazy && !allow_natives() && extension_ == NULL && allow_lazy() && | |
4224 function_type == FunctionLiteral::DECLARATION && | |
4225 eager_compile_hint != FunctionLiteral::kShouldEagerCompile; | |
4226 Zone* outer_zone = factory()->zone(); | |
4227 Zone temp_zone; | |
4228 if (can_use_temp_zone) { | |
4229 // For the purpose of scope analysis, some HeapObjects allocated by the | |
4230 // factory must persist after the function body is thrown away and | |
4231 // temp_zone is deallocated. These objects are instead allocated in a | |
4232 // parser-persistent zone (see parser_zone_ in AstNodeFactory). | |
4233 factory()->set_zone(&temp_zone); | |
4234 } | |
4209 body = ParseEagerFunctionBody(function_name, pos, formals, kind, | 4235 body = ParseEagerFunctionBody(function_name, pos, formals, kind, |
4210 function_type, CHECK_OK); | 4236 function_type, CHECK_OK); |
4211 materialized_literal_count = function_state.materialized_literal_count(); | 4237 materialized_literal_count = function_state.materialized_literal_count(); |
4212 expected_property_count = function_state.expected_property_count(); | 4238 expected_property_count = function_state.expected_property_count(); |
4239 if (can_use_temp_zone) { | |
4240 body = NULL; | |
4241 factory()->set_zone(outer_zone); | |
Michael Starzinger
2015/09/10 12:16:54
Suggestion as discsussed offline: This explicit re
conradw
2015/09/10 13:12:40
Sounds good! Done.
| |
4242 } | |
4213 } | 4243 } |
4214 | 4244 |
4215 // Parsing the body may change the language mode in our scope. | 4245 // Parsing the body may change the language mode in our scope. |
4216 language_mode = scope->language_mode(); | 4246 language_mode = scope->language_mode(); |
4217 | 4247 |
4218 if (is_strong(language_mode) && IsSubclassConstructor(kind)) { | 4248 if (is_strong(language_mode) && IsSubclassConstructor(kind)) { |
4219 if (!function_state.super_location().IsValid()) { | 4249 if (!function_state.super_location().IsValid()) { |
4220 ReportMessageAt(function_name_location, | 4250 ReportMessageAt(function_name_location, |
4221 MessageTemplate::kStrongSuperCallMissing, | 4251 MessageTemplate::kStrongSuperCallMissing, |
4222 kReferenceError); | 4252 kReferenceError); |
(...skipping 1981 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6204 | 6234 |
6205 Expression* Parser::SpreadCallNew(Expression* function, | 6235 Expression* Parser::SpreadCallNew(Expression* function, |
6206 ZoneList<v8::internal::Expression*>* args, | 6236 ZoneList<v8::internal::Expression*>* args, |
6207 int pos) { | 6237 int pos) { |
6208 args->InsertAt(0, function, zone()); | 6238 args->InsertAt(0, function, zone()); |
6209 | 6239 |
6210 return factory()->NewCallRuntime(Context::REFLECT_CONSTRUCT_INDEX, args, pos); | 6240 return factory()->NewCallRuntime(Context::REFLECT_CONSTRUCT_INDEX, args, pos); |
6211 } | 6241 } |
6212 } // namespace internal | 6242 } // namespace internal |
6213 } // namespace v8 | 6243 } // namespace v8 |
OLD | NEW |