| 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 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 return result; | 270 return result; |
| 271 } | 271 } |
| 272 | 272 |
| 273 | 273 |
| 274 FunctionLiteral* Parser::DefaultConstructor(bool call_super, Scope* scope, | 274 FunctionLiteral* Parser::DefaultConstructor(bool call_super, Scope* scope, |
| 275 int pos, int end_pos) { | 275 int pos, int end_pos) { |
| 276 int materialized_literal_count = -1; | 276 int materialized_literal_count = -1; |
| 277 int expected_property_count = -1; | 277 int expected_property_count = -1; |
| 278 int handler_count = 0; | 278 int handler_count = 0; |
| 279 int parameter_count = 0; | 279 int parameter_count = 0; |
| 280 AstProperties ast_properties; | |
| 281 const AstRawString* name = ast_value_factory()->empty_string(); | 280 const AstRawString* name = ast_value_factory()->empty_string(); |
| 282 FunctionKind kind = call_super ? FunctionKind::kDefaultConstructorCallSuper | 281 FunctionKind kind = call_super ? FunctionKind::kDefaultConstructorCallSuper |
| 283 : FunctionKind::kDefaultConstructor; | 282 : FunctionKind::kDefaultConstructor; |
| 284 | 283 |
| 285 Scope* function_scope = NewScope(scope, FUNCTION_SCOPE); | 284 Scope* function_scope = NewScope(scope, FUNCTION_SCOPE); |
| 286 function_scope->SetStrictMode(STRICT); | 285 function_scope->SetStrictMode(STRICT); |
| 287 // Set start and end position to the same value | 286 // Set start and end position to the same value |
| 288 function_scope->set_start_position(pos); | 287 function_scope->set_start_position(pos); |
| 289 function_scope->set_end_position(pos); | 288 function_scope->set_end_position(pos); |
| 290 ZoneList<Statement*>* body = NULL; | 289 ZoneList<Statement*>* body = NULL; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 302 CallRuntime* call = factory()->NewCallRuntime( | 301 CallRuntime* call = factory()->NewCallRuntime( |
| 303 ast_value_factory()->empty_string(), | 302 ast_value_factory()->empty_string(), |
| 304 Runtime::FunctionForId(Runtime::kDefaultConstructorSuperCall), args, | 303 Runtime::FunctionForId(Runtime::kDefaultConstructorSuperCall), args, |
| 305 pos); | 304 pos); |
| 306 body->Add(factory()->NewExpressionStatement(call, pos), zone()); | 305 body->Add(factory()->NewExpressionStatement(call, pos), zone()); |
| 307 } | 306 } |
| 308 | 307 |
| 309 materialized_literal_count = function_state.materialized_literal_count(); | 308 materialized_literal_count = function_state.materialized_literal_count(); |
| 310 expected_property_count = function_state.expected_property_count(); | 309 expected_property_count = function_state.expected_property_count(); |
| 311 handler_count = function_state.handler_count(); | 310 handler_count = function_state.handler_count(); |
| 312 | |
| 313 ast_properties = *factory()->visitor()->ast_properties(); | |
| 314 } | 311 } |
| 315 | 312 |
| 316 FunctionLiteral* function_literal = factory()->NewFunctionLiteral( | 313 FunctionLiteral* function_literal = factory()->NewFunctionLiteral( |
| 317 name, ast_value_factory(), function_scope, body, | 314 name, ast_value_factory(), function_scope, body, |
| 318 materialized_literal_count, expected_property_count, handler_count, | 315 materialized_literal_count, expected_property_count, handler_count, |
| 319 parameter_count, FunctionLiteral::kNoDuplicateParameters, | 316 parameter_count, FunctionLiteral::kNoDuplicateParameters, |
| 320 FunctionLiteral::ANONYMOUS_EXPRESSION, FunctionLiteral::kIsFunction, | 317 FunctionLiteral::ANONYMOUS_EXPRESSION, FunctionLiteral::kIsFunction, |
| 321 FunctionLiteral::kNotParenthesized, kind, pos); | 318 FunctionLiteral::kNotParenthesized, kind, pos); |
| 322 | 319 |
| 323 function_literal->set_ast_properties(&ast_properties); | |
| 324 | |
| 325 return function_literal; | 320 return function_literal; |
| 326 } | 321 } |
| 327 | 322 |
| 328 | 323 |
| 329 // ---------------------------------------------------------------------------- | 324 // ---------------------------------------------------------------------------- |
| 330 // Target is a support class to facilitate manipulation of the | 325 // Target is a support class to facilitate manipulation of the |
| 331 // Parser's target_stack_ (the stack of potential 'break' and | 326 // Parser's target_stack_ (the stack of potential 'break' and |
| 332 // 'continue' statement targets). Upon construction, a new target is | 327 // 'continue' statement targets). Upon construction, a new target is |
| 333 // added; it is removed upon destruction. | 328 // added; it is removed upon destruction. |
| 334 | 329 |
| (...skipping 626 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 961 | 956 |
| 962 if (ok) { | 957 if (ok) { |
| 963 result = factory()->NewFunctionLiteral( | 958 result = factory()->NewFunctionLiteral( |
| 964 ast_value_factory()->empty_string(), ast_value_factory(), scope_, | 959 ast_value_factory()->empty_string(), ast_value_factory(), scope_, |
| 965 body, function_state.materialized_literal_count(), | 960 body, function_state.materialized_literal_count(), |
| 966 function_state.expected_property_count(), | 961 function_state.expected_property_count(), |
| 967 function_state.handler_count(), 0, | 962 function_state.handler_count(), 0, |
| 968 FunctionLiteral::kNoDuplicateParameters, | 963 FunctionLiteral::kNoDuplicateParameters, |
| 969 FunctionLiteral::ANONYMOUS_EXPRESSION, FunctionLiteral::kGlobalOrEval, | 964 FunctionLiteral::ANONYMOUS_EXPRESSION, FunctionLiteral::kGlobalOrEval, |
| 970 FunctionLiteral::kNotParenthesized, FunctionKind::kNormalFunction, 0); | 965 FunctionLiteral::kNotParenthesized, FunctionKind::kNormalFunction, 0); |
| 971 result->set_ast_properties(factory()->visitor()->ast_properties()); | |
| 972 } | 966 } |
| 973 } | 967 } |
| 974 | 968 |
| 975 // Make sure the target stack is empty. | 969 // Make sure the target stack is empty. |
| 976 DCHECK(target_stack_ == NULL); | 970 DCHECK(target_stack_ == NULL); |
| 977 | 971 |
| 978 return result; | 972 return result; |
| 979 } | 973 } |
| 980 | 974 |
| 981 | 975 |
| (...skipping 2565 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3547 : NewScope(scope_, FUNCTION_SCOPE); | 3541 : NewScope(scope_, FUNCTION_SCOPE); |
| 3548 ZoneList<Statement*>* body = NULL; | 3542 ZoneList<Statement*>* body = NULL; |
| 3549 int materialized_literal_count = -1; | 3543 int materialized_literal_count = -1; |
| 3550 int expected_property_count = -1; | 3544 int expected_property_count = -1; |
| 3551 int handler_count = 0; | 3545 int handler_count = 0; |
| 3552 FunctionLiteral::ParameterFlag duplicate_parameters = | 3546 FunctionLiteral::ParameterFlag duplicate_parameters = |
| 3553 FunctionLiteral::kNoDuplicateParameters; | 3547 FunctionLiteral::kNoDuplicateParameters; |
| 3554 FunctionLiteral::IsParenthesizedFlag parenthesized = parenthesized_function_ | 3548 FunctionLiteral::IsParenthesizedFlag parenthesized = parenthesized_function_ |
| 3555 ? FunctionLiteral::kIsParenthesized | 3549 ? FunctionLiteral::kIsParenthesized |
| 3556 : FunctionLiteral::kNotParenthesized; | 3550 : FunctionLiteral::kNotParenthesized; |
| 3557 AstProperties ast_properties; | |
| 3558 // Parse function body. | 3551 // Parse function body. |
| 3559 { | 3552 { |
| 3560 AstNodeFactory<AstConstructionVisitor> function_factory( | 3553 AstNodeFactory<AstConstructionVisitor> function_factory( |
| 3561 ast_value_factory()); | 3554 ast_value_factory()); |
| 3562 FunctionState function_state(&function_state_, &scope_, scope, | 3555 FunctionState function_state(&function_state_, &scope_, scope, |
| 3563 &function_factory); | 3556 &function_factory); |
| 3564 scope_->SetScopeName(function_name); | 3557 scope_->SetScopeName(function_name); |
| 3565 | 3558 |
| 3566 if (is_generator) { | 3559 if (is_generator) { |
| 3567 // For generators, allocating variables in contexts is currently a win | 3560 // For generators, allocating variables in contexts is currently a win |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3715 eval_args_error_log, | 3708 eval_args_error_log, |
| 3716 dupe_error_loc, | 3709 dupe_error_loc, |
| 3717 reserved_loc, | 3710 reserved_loc, |
| 3718 CHECK_OK); | 3711 CHECK_OK); |
| 3719 } | 3712 } |
| 3720 if (strict_mode() == STRICT) { | 3713 if (strict_mode() == STRICT) { |
| 3721 CheckOctalLiteral(scope->start_position(), | 3714 CheckOctalLiteral(scope->start_position(), |
| 3722 scope->end_position(), | 3715 scope->end_position(), |
| 3723 CHECK_OK); | 3716 CHECK_OK); |
| 3724 } | 3717 } |
| 3725 ast_properties = *factory()->visitor()->ast_properties(); | |
| 3726 | |
| 3727 if (allow_harmony_scoping() && strict_mode() == STRICT) { | 3718 if (allow_harmony_scoping() && strict_mode() == STRICT) { |
| 3728 CheckConflictingVarDeclarations(scope, CHECK_OK); | 3719 CheckConflictingVarDeclarations(scope, CHECK_OK); |
| 3729 } | 3720 } |
| 3730 } | 3721 } |
| 3731 | 3722 |
| 3732 FunctionLiteral* function_literal = factory()->NewFunctionLiteral( | 3723 FunctionLiteral* function_literal = factory()->NewFunctionLiteral( |
| 3733 function_name, ast_value_factory(), scope, body, | 3724 function_name, ast_value_factory(), scope, body, |
| 3734 materialized_literal_count, expected_property_count, handler_count, | 3725 materialized_literal_count, expected_property_count, handler_count, |
| 3735 num_parameters, duplicate_parameters, function_type, | 3726 num_parameters, duplicate_parameters, function_type, |
| 3736 FunctionLiteral::kIsFunction, parenthesized, kind, pos); | 3727 FunctionLiteral::kIsFunction, parenthesized, kind, pos); |
| 3737 function_literal->set_function_token_position(function_token_pos); | 3728 function_literal->set_function_token_position(function_token_pos); |
| 3738 function_literal->set_ast_properties(&ast_properties); | |
| 3739 | 3729 |
| 3740 if (fni_ != NULL && should_infer_name) fni_->AddFunction(function_literal); | 3730 if (fni_ != NULL && should_infer_name) fni_->AddFunction(function_literal); |
| 3741 return function_literal; | 3731 return function_literal; |
| 3742 } | 3732 } |
| 3743 | 3733 |
| 3744 | 3734 |
| 3745 void Parser::SkipLazyFunctionBody(const AstRawString* function_name, | 3735 void Parser::SkipLazyFunctionBody(const AstRawString* function_name, |
| 3746 int* materialized_literal_count, | 3736 int* materialized_literal_count, |
| 3747 int* expected_property_count, | 3737 int* expected_property_count, |
| 3748 bool* ok) { | 3738 bool* ok) { |
| (...skipping 1262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5011 | 5001 |
| 5012 // We cannot internalize on a background thread; a foreground task will take | 5002 // We cannot internalize on a background thread; a foreground task will take |
| 5013 // care of calling Parser::Internalize just before compilation. | 5003 // care of calling Parser::Internalize just before compilation. |
| 5014 | 5004 |
| 5015 if (compile_options() == ScriptCompiler::kProduceParserCache) { | 5005 if (compile_options() == ScriptCompiler::kProduceParserCache) { |
| 5016 if (result != NULL) *info_->cached_data() = recorder.GetScriptData(); | 5006 if (result != NULL) *info_->cached_data() = recorder.GetScriptData(); |
| 5017 log_ = NULL; | 5007 log_ = NULL; |
| 5018 } | 5008 } |
| 5019 } | 5009 } |
| 5020 } } // namespace v8::internal | 5010 } } // namespace v8::internal |
| OLD | NEW |