Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 638 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 649 FunctionLiteral* result = NULL; | 649 FunctionLiteral* result = NULL; |
| 650 { Scope* scope = NewScope(top_scope_, GLOBAL_SCOPE); | 650 { Scope* scope = NewScope(top_scope_, GLOBAL_SCOPE); |
| 651 info->SetGlobalScope(scope); | 651 info->SetGlobalScope(scope); |
| 652 if (!info->is_global()) { | 652 if (!info->is_global()) { |
| 653 scope = Scope::DeserializeScopeChain(*info->calling_context(), scope); | 653 scope = Scope::DeserializeScopeChain(*info->calling_context(), scope); |
| 654 scope = NewScope(scope, EVAL_SCOPE); | 654 scope = NewScope(scope, EVAL_SCOPE); |
| 655 } | 655 } |
| 656 scope->set_start_position(0); | 656 scope->set_start_position(0); |
| 657 scope->set_end_position(source->length()); | 657 scope->set_end_position(source->length()); |
| 658 FunctionState function_state(this, scope, isolate()); | 658 FunctionState function_state(this, scope, isolate()); |
| 659 int ast_nodes_before = isolate()->ast_node_count(); | |
|
Kevin Millikin (Chromium)
2011/11/28 12:11:59
It seems overly complicated to use the global coun
ulan
2011/11/29 14:06:52
Done.
| |
| 660 int non_primitive_ast_nodes_before = | |
| 661 isolate()->non_primitive_ast_node_count(); | |
|
Kevin Millikin (Chromium)
2011/11/28 12:11:59
There's no need to count them is there? If not, i
ulan
2011/11/29 14:06:52
Done.
| |
| 659 top_scope_->SetStrictModeFlag(info->strict_mode_flag()); | 662 top_scope_->SetStrictModeFlag(info->strict_mode_flag()); |
| 660 ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(16); | 663 ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(16); |
| 661 bool ok = true; | 664 bool ok = true; |
| 662 int beg_loc = scanner().location().beg_pos; | 665 int beg_loc = scanner().location().beg_pos; |
| 663 ParseSourceElements(body, Token::EOS, &ok); | 666 ParseSourceElements(body, Token::EOS, &ok); |
| 664 if (ok && top_scope_->is_strict_mode()) { | 667 if (ok && top_scope_->is_strict_mode()) { |
| 665 CheckOctalLiteral(beg_loc, scanner().location().end_pos, &ok); | 668 CheckOctalLiteral(beg_loc, scanner().location().end_pos, &ok); |
| 666 } | 669 } |
| 667 | 670 |
| 668 if (ok && harmony_scoping_) { | 671 if (ok && harmony_scoping_) { |
| 669 CheckConflictingVarDeclarations(scope, &ok); | 672 CheckConflictingVarDeclarations(scope, &ok); |
| 670 } | 673 } |
| 671 | 674 |
| 675 int ast_nodes_added = isolate()->ast_node_count() - ast_nodes_before + 1; | |
| 676 bool is_primitive = (isolate()->non_primitive_ast_node_count() - | |
| 677 non_primitive_ast_nodes_before == 0); | |
| 678 | |
| 672 if (ok) { | 679 if (ok) { |
| 673 result = new(zone()) FunctionLiteral( | 680 result = new(zone()) FunctionLiteral( |
| 674 isolate(), | 681 isolate(), |
| 675 no_name, | 682 no_name, |
| 676 top_scope_, | 683 top_scope_, |
| 677 body, | 684 body, |
| 678 function_state.materialized_literal_count(), | 685 function_state.materialized_literal_count(), |
| 679 function_state.expected_property_count(), | 686 function_state.expected_property_count(), |
| 680 function_state.handler_count(), | 687 function_state.handler_count(), |
| 681 function_state.only_simple_this_property_assignments(), | 688 function_state.only_simple_this_property_assignments(), |
| 682 function_state.this_property_assignments(), | 689 function_state.this_property_assignments(), |
| 683 0, | 690 0, |
| 684 FunctionLiteral::ANONYMOUS_EXPRESSION, | 691 FunctionLiteral::ANONYMOUS_EXPRESSION, |
| 685 false); // Does not have duplicate parameters. | 692 false, // Does not have duplicate parameters. |
| 693 ast_nodes_added, | |
| 694 is_primitive); | |
| 686 } else if (stack_overflow_) { | 695 } else if (stack_overflow_) { |
| 687 isolate()->StackOverflow(); | 696 isolate()->StackOverflow(); |
| 688 } | 697 } |
| 689 } | 698 } |
| 690 | 699 |
| 691 // Make sure the target stack is empty. | 700 // Make sure the target stack is empty. |
| 692 ASSERT(target_stack_ == NULL); | 701 ASSERT(target_stack_ == NULL); |
| 693 | 702 |
| 694 // If there was a syntax error we have to get rid of the AST | 703 // If there was a syntax error we have to get rid of the AST |
| 695 // and it is not safe to do so before the scope has been deleted. | 704 // and it is not safe to do so before the scope has been deleted. |
| (...skipping 1480 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2176 Expect(Token::RPAREN, CHECK_OK); | 2185 Expect(Token::RPAREN, CHECK_OK); |
| 2177 | 2186 |
| 2178 top_scope_->DeclarationScope()->RecordWithStatement(); | 2187 top_scope_->DeclarationScope()->RecordWithStatement(); |
| 2179 Scope* with_scope = NewScope(top_scope_, WITH_SCOPE); | 2188 Scope* with_scope = NewScope(top_scope_, WITH_SCOPE); |
| 2180 Statement* stmt; | 2189 Statement* stmt; |
| 2181 { BlockState block_state(this, with_scope); | 2190 { BlockState block_state(this, with_scope); |
| 2182 with_scope->set_start_position(scanner().peek_location().beg_pos); | 2191 with_scope->set_start_position(scanner().peek_location().beg_pos); |
| 2183 stmt = ParseStatement(labels, CHECK_OK); | 2192 stmt = ParseStatement(labels, CHECK_OK); |
| 2184 with_scope->set_end_position(scanner().location().end_pos); | 2193 with_scope->set_end_position(scanner().location().end_pos); |
| 2185 } | 2194 } |
| 2186 return new(zone()) WithStatement(expr, stmt); | 2195 return new(zone()) WithStatement(isolate(), expr, stmt); |
| 2187 } | 2196 } |
| 2188 | 2197 |
| 2189 | 2198 |
| 2190 CaseClause* Parser::ParseCaseClause(bool* default_seen_ptr, bool* ok) { | 2199 CaseClause* Parser::ParseCaseClause(bool* default_seen_ptr, bool* ok) { |
| 2191 // CaseClause :: | 2200 // CaseClause :: |
| 2192 // 'case' Expression ':' Statement* | 2201 // 'case' Expression ':' Statement* |
| 2193 // 'default' ':' Statement* | 2202 // 'default' ':' Statement* |
| 2194 | 2203 |
| 2195 Expression* label = NULL; // NULL expression indicates default case | 2204 Expression* label = NULL; // NULL expression indicates default case |
| 2196 if (peek() == Token::CASE) { | 2205 if (peek() == Token::CASE) { |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2342 | 2351 |
| 2343 // Simplify the AST nodes by converting: | 2352 // Simplify the AST nodes by converting: |
| 2344 // 'try B0 catch B1 finally B2' | 2353 // 'try B0 catch B1 finally B2' |
| 2345 // to: | 2354 // to: |
| 2346 // 'try { try B0 catch B1 } finally B2' | 2355 // 'try { try B0 catch B1 } finally B2' |
| 2347 | 2356 |
| 2348 if (catch_block != NULL && finally_block != NULL) { | 2357 if (catch_block != NULL && finally_block != NULL) { |
| 2349 // If we have both, create an inner try/catch. | 2358 // If we have both, create an inner try/catch. |
| 2350 ASSERT(catch_scope != NULL && catch_variable != NULL); | 2359 ASSERT(catch_scope != NULL && catch_variable != NULL); |
| 2351 int index = current_function_state_->NextHandlerIndex(); | 2360 int index = current_function_state_->NextHandlerIndex(); |
| 2352 TryCatchStatement* statement = new(zone()) TryCatchStatement(index, | 2361 TryCatchStatement* statement = new(zone()) TryCatchStatement(isolate(), |
| 2362 index, | |
| 2353 try_block, | 2363 try_block, |
| 2354 catch_scope, | 2364 catch_scope, |
| 2355 catch_variable, | 2365 catch_variable, |
| 2356 catch_block); | 2366 catch_block); |
| 2357 statement->set_escaping_targets(try_collector.targets()); | 2367 statement->set_escaping_targets(try_collector.targets()); |
| 2358 try_block = new(zone()) Block(isolate(), NULL, 1, false); | 2368 try_block = new(zone()) Block(isolate(), NULL, 1, false); |
| 2359 try_block->AddStatement(statement); | 2369 try_block->AddStatement(statement); |
| 2360 catch_block = NULL; // Clear to indicate it's been handled. | 2370 catch_block = NULL; // Clear to indicate it's been handled. |
| 2361 } | 2371 } |
| 2362 | 2372 |
| 2363 TryStatement* result = NULL; | 2373 TryStatement* result = NULL; |
| 2364 if (catch_block != NULL) { | 2374 if (catch_block != NULL) { |
| 2365 ASSERT(finally_block == NULL); | 2375 ASSERT(finally_block == NULL); |
| 2366 ASSERT(catch_scope != NULL && catch_variable != NULL); | 2376 ASSERT(catch_scope != NULL && catch_variable != NULL); |
| 2367 int index = current_function_state_->NextHandlerIndex(); | 2377 int index = current_function_state_->NextHandlerIndex(); |
| 2368 result = new(zone()) TryCatchStatement(index, | 2378 result = new(zone()) TryCatchStatement(isolate(), |
| 2379 index, | |
| 2369 try_block, | 2380 try_block, |
| 2370 catch_scope, | 2381 catch_scope, |
| 2371 catch_variable, | 2382 catch_variable, |
| 2372 catch_block); | 2383 catch_block); |
| 2373 } else { | 2384 } else { |
| 2374 ASSERT(finally_block != NULL); | 2385 ASSERT(finally_block != NULL); |
| 2375 int index = current_function_state_->NextHandlerIndex(); | 2386 int index = current_function_state_->NextHandlerIndex(); |
| 2376 result = new(zone()) TryFinallyStatement(index, | 2387 result = new(zone()) TryFinallyStatement(isolate(), |
| 2388 index, | |
| 2377 try_block, | 2389 try_block, |
| 2378 finally_block); | 2390 finally_block); |
| 2379 // Combine the jump targets of the try block and the possible catch block. | 2391 // Combine the jump targets of the try block and the possible catch block. |
| 2380 try_collector.targets()->AddAll(*catch_collector.targets()); | 2392 try_collector.targets()->AddAll(*catch_collector.targets()); |
| 2381 } | 2393 } |
| 2382 | 2394 |
| 2383 result->set_escaping_targets(try_collector.targets()); | 2395 result->set_escaping_targets(try_collector.targets()); |
| 2384 return result; | 2396 return result; |
| 2385 } | 2397 } |
| 2386 | 2398 |
| (...skipping 1544 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3931 // Function declarations are function scoped in normal mode, so they are | 3943 // Function declarations are function scoped in normal mode, so they are |
| 3932 // hoisted. In harmony block scoping mode they are block scoped, so they | 3944 // hoisted. In harmony block scoping mode they are block scoped, so they |
| 3933 // are not hoisted. | 3945 // are not hoisted. |
| 3934 Scope* scope = (type == FunctionLiteral::DECLARATION && !harmony_scoping_) | 3946 Scope* scope = (type == FunctionLiteral::DECLARATION && !harmony_scoping_) |
| 3935 ? NewScope(top_scope_->DeclarationScope(), FUNCTION_SCOPE) | 3947 ? NewScope(top_scope_->DeclarationScope(), FUNCTION_SCOPE) |
| 3936 : NewScope(top_scope_, FUNCTION_SCOPE); | 3948 : NewScope(top_scope_, FUNCTION_SCOPE); |
| 3937 ZoneList<Statement*>* body = NULL; | 3949 ZoneList<Statement*>* body = NULL; |
| 3938 int materialized_literal_count; | 3950 int materialized_literal_count; |
| 3939 int expected_property_count; | 3951 int expected_property_count; |
| 3940 int handler_count = 0; | 3952 int handler_count = 0; |
| 3953 int ast_node_count_before = isolate_->ast_node_count(); | |
| 3954 int non_primitive_ast_node_count_before = | |
| 3955 isolate_->non_primitive_ast_node_count(); | |
| 3941 bool only_simple_this_property_assignments; | 3956 bool only_simple_this_property_assignments; |
| 3942 Handle<FixedArray> this_property_assignments; | 3957 Handle<FixedArray> this_property_assignments; |
| 3943 bool has_duplicate_parameters = false; | 3958 bool has_duplicate_parameters = false; |
| 3944 // Parse function body. | 3959 // Parse function body. |
| 3945 { FunctionState function_state(this, scope, isolate()); | 3960 { FunctionState function_state(this, scope, isolate()); |
| 3946 top_scope_->SetScopeName(function_name); | 3961 top_scope_->SetScopeName(function_name); |
| 3947 | 3962 |
| 3948 // FormalParameterList :: | 3963 // FormalParameterList :: |
| 3949 // '(' (Identifier)*[','] ')' | 3964 // '(' (Identifier)*[','] ')' |
| 3950 Expect(Token::LPAREN, CHECK_OK); | 3965 Expect(Token::LPAREN, CHECK_OK); |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4112 CheckOctalLiteral(scope->start_position(), | 4127 CheckOctalLiteral(scope->start_position(), |
| 4113 scope->end_position(), | 4128 scope->end_position(), |
| 4114 CHECK_OK); | 4129 CHECK_OK); |
| 4115 } | 4130 } |
| 4116 } | 4131 } |
| 4117 | 4132 |
| 4118 if (harmony_scoping_) { | 4133 if (harmony_scoping_) { |
| 4119 CheckConflictingVarDeclarations(scope, CHECK_OK); | 4134 CheckConflictingVarDeclarations(scope, CHECK_OK); |
| 4120 } | 4135 } |
| 4121 | 4136 |
| 4137 int ast_nodes_added = isolate_->ast_node_count() - ast_node_count_before + 1; | |
| 4138 bool is_primitive = (isolate_->non_primitive_ast_node_count() - | |
| 4139 non_primitive_ast_node_count_before == 0); | |
| 4140 | |
| 4122 FunctionLiteral* function_literal = | 4141 FunctionLiteral* function_literal = |
| 4123 new(zone()) FunctionLiteral(isolate(), | 4142 new(zone()) FunctionLiteral(isolate(), |
| 4124 function_name, | 4143 function_name, |
| 4125 scope, | 4144 scope, |
| 4126 body, | 4145 body, |
| 4127 materialized_literal_count, | 4146 materialized_literal_count, |
| 4128 expected_property_count, | 4147 expected_property_count, |
| 4129 handler_count, | 4148 handler_count, |
| 4130 only_simple_this_property_assignments, | 4149 only_simple_this_property_assignments, |
| 4131 this_property_assignments, | 4150 this_property_assignments, |
| 4132 num_parameters, | 4151 num_parameters, |
| 4133 type, | 4152 type, |
| 4134 has_duplicate_parameters); | 4153 has_duplicate_parameters, |
| 4154 ast_nodes_added, | |
| 4155 is_primitive); | |
| 4135 function_literal->set_function_token_position(function_token_position); | 4156 function_literal->set_function_token_position(function_token_position); |
| 4136 | 4157 |
| 4137 if (fni_ != NULL && should_infer_name) fni_->AddFunction(function_literal); | 4158 if (fni_ != NULL && should_infer_name) fni_->AddFunction(function_literal); |
| 4138 return function_literal; | 4159 return function_literal; |
| 4139 } | 4160 } |
| 4140 | 4161 |
| 4141 | 4162 |
| 4142 Expression* Parser::ParseV8Intrinsic(bool* ok) { | 4163 Expression* Parser::ParseV8Intrinsic(bool* ok) { |
| 4143 // CallRuntime :: | 4164 // CallRuntime :: |
| 4144 // '%' Identifier Arguments | 4165 // '%' Identifier Arguments |
| (...skipping 1314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5459 ASSERT(info->isolate()->has_pending_exception()); | 5480 ASSERT(info->isolate()->has_pending_exception()); |
| 5460 } else { | 5481 } else { |
| 5461 result = parser.ParseProgram(info); | 5482 result = parser.ParseProgram(info); |
| 5462 } | 5483 } |
| 5463 } | 5484 } |
| 5464 info->SetFunction(result); | 5485 info->SetFunction(result); |
| 5465 return (result != NULL); | 5486 return (result != NULL); |
| 5466 } | 5487 } |
| 5467 | 5488 |
| 5468 } } // namespace v8::internal | 5489 } } // namespace v8::internal |
| OLD | NEW |