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 body = ParseEagerFunctionBody(function_name, pos, formals, kind, | 4209 // Determine whether the function body can be discarded after parsing. |
4210 function_type, CHECK_OK); | 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 // Open a new BodyScope, which sets our AstNodeFactory to allocate in the |
| 4227 // new temporary zone if the preconditions are satisfied, and ensures that |
| 4228 // the previous zone is always restored after parsing the body. |
| 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 { |
| 4234 Zone temp_zone; |
| 4235 AstNodeFactory::BodyScope(factory(), &temp_zone, can_use_temp_zone); |
| 4236 |
| 4237 body = ParseEagerFunctionBody(function_name, pos, formals, kind, |
| 4238 function_type, CHECK_OK); |
| 4239 } |
4211 materialized_literal_count = function_state.materialized_literal_count(); | 4240 materialized_literal_count = function_state.materialized_literal_count(); |
4212 expected_property_count = function_state.expected_property_count(); | 4241 expected_property_count = function_state.expected_property_count(); |
| 4242 if (can_use_temp_zone) { |
| 4243 // If the preconditions are correct the function body should never be |
| 4244 // accessed, but do this anyway for better behaviour if they're wrong. |
| 4245 body = NULL; |
| 4246 } |
4213 } | 4247 } |
4214 | 4248 |
4215 // Parsing the body may change the language mode in our scope. | 4249 // Parsing the body may change the language mode in our scope. |
4216 language_mode = scope->language_mode(); | 4250 language_mode = scope->language_mode(); |
4217 | 4251 |
4218 if (is_strong(language_mode) && IsSubclassConstructor(kind)) { | 4252 if (is_strong(language_mode) && IsSubclassConstructor(kind)) { |
4219 if (!function_state.super_location().IsValid()) { | 4253 if (!function_state.super_location().IsValid()) { |
4220 ReportMessageAt(function_name_location, | 4254 ReportMessageAt(function_name_location, |
4221 MessageTemplate::kStrongSuperCallMissing, | 4255 MessageTemplate::kStrongSuperCallMissing, |
4222 kReferenceError); | 4256 kReferenceError); |
(...skipping 1981 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6204 | 6238 |
6205 Expression* Parser::SpreadCallNew(Expression* function, | 6239 Expression* Parser::SpreadCallNew(Expression* function, |
6206 ZoneList<v8::internal::Expression*>* args, | 6240 ZoneList<v8::internal::Expression*>* args, |
6207 int pos) { | 6241 int pos) { |
6208 args->InsertAt(0, function, zone()); | 6242 args->InsertAt(0, function, zone()); |
6209 | 6243 |
6210 return factory()->NewCallRuntime(Context::REFLECT_CONSTRUCT_INDEX, args, pos); | 6244 return factory()->NewCallRuntime(Context::REFLECT_CONSTRUCT_INDEX, args, pos); |
6211 } | 6245 } |
6212 } // namespace internal | 6246 } // namespace internal |
6213 } // namespace v8 | 6247 } // namespace v8 |
OLD | NEW |