Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1140)

Side by Side Diff: src/parser.cc

Issue 13704010: Generator objects can suspend (Closed) Base URL: git://github.com/v8/v8.git@master
Patch Set: Use sentinel values for continuations Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/objects-inl.h ('k') | src/runtime.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 2492 matching lines...) Expand 10 before | Expand all | Expand 10 after
2503 // ReturnStatement :: 2503 // ReturnStatement ::
2504 // 'return' Expression? ';' 2504 // 'return' Expression? ';'
2505 2505
2506 // Consume the return token. It is necessary to do the before 2506 // Consume the return token. It is necessary to do the before
2507 // reporting any errors on it, because of the way errors are 2507 // reporting any errors on it, because of the way errors are
2508 // reported (underlining). 2508 // reported (underlining).
2509 Expect(Token::RETURN, CHECK_OK); 2509 Expect(Token::RETURN, CHECK_OK);
2510 2510
2511 Token::Value tok = peek(); 2511 Token::Value tok = peek();
2512 Statement* result; 2512 Statement* result;
2513 Expression* return_value;
2513 if (scanner().HasAnyLineTerminatorBeforeNext() || 2514 if (scanner().HasAnyLineTerminatorBeforeNext() ||
2514 tok == Token::SEMICOLON || 2515 tok == Token::SEMICOLON ||
2515 tok == Token::RBRACE || 2516 tok == Token::RBRACE ||
2516 tok == Token::EOS) { 2517 tok == Token::EOS) {
2517 ExpectSemicolon(CHECK_OK); 2518 return_value = GetLiteralUndefined();
2518 result = factory()->NewReturnStatement(GetLiteralUndefined());
2519 } else { 2519 } else {
2520 Expression* expr = ParseExpression(true, CHECK_OK); 2520 return_value = ParseExpression(true, CHECK_OK);
2521 ExpectSemicolon(CHECK_OK); 2521 }
2522 result = factory()->NewReturnStatement(expr); 2522 ExpectSemicolon(CHECK_OK);
2523 if (is_generator()) {
2524 Expression* generator = factory()->NewVariableProxy(
2525 current_function_state_->generator_object_variable());
2526 Expression* yield = factory()->NewYield(
2527 generator, return_value, Yield::FINAL, RelocInfo::kNoPosition);
2528 result = factory()->NewExpressionStatement(yield);
2529 } else {
2530 result = factory()->NewReturnStatement(return_value);
2523 } 2531 }
2524 2532
2525 // An ECMAScript program is considered syntactically incorrect if it 2533 // An ECMAScript program is considered syntactically incorrect if it
2526 // contains a return statement that is not within the body of a 2534 // contains a return statement that is not within the body of a
2527 // function. See ECMA-262, section 12.9, page 67. 2535 // function. See ECMA-262, section 12.9, page 67.
2528 // 2536 //
2529 // To be consistent with KJS we report the syntax error at runtime. 2537 // To be consistent with KJS we report the syntax error at runtime.
2530 Scope* declaration_scope = top_scope_->DeclarationScope(); 2538 Scope* declaration_scope = top_scope_->DeclarationScope();
2531 if (declaration_scope->is_global_scope() || 2539 if (declaration_scope->is_global_scope() ||
2532 declaration_scope->is_eval_scope()) { 2540 declaration_scope->is_eval_scope()) {
(...skipping 559 matching lines...) Expand 10 before | Expand all | Expand 10 after
3092 3100
3093 return factory()->NewAssignment(op, expression, right, pos); 3101 return factory()->NewAssignment(op, expression, right, pos);
3094 } 3102 }
3095 3103
3096 3104
3097 Expression* Parser::ParseYieldExpression(bool* ok) { 3105 Expression* Parser::ParseYieldExpression(bool* ok) {
3098 // YieldExpression :: 3106 // YieldExpression ::
3099 // 'yield' '*'? AssignmentExpression 3107 // 'yield' '*'? AssignmentExpression
3100 int position = scanner().peek_location().beg_pos; 3108 int position = scanner().peek_location().beg_pos;
3101 Expect(Token::YIELD, CHECK_OK); 3109 Expect(Token::YIELD, CHECK_OK);
3102 bool is_yield_star = Check(Token::MUL); 3110 Yield::Kind kind =
3111 Check(Token::MUL) ? Yield::DELEGATING : Yield::SUSPEND;
3103 Expression* generator_object = factory()->NewVariableProxy( 3112 Expression* generator_object = factory()->NewVariableProxy(
3104 current_function_state_->generator_object_variable()); 3113 current_function_state_->generator_object_variable());
3105 Expression* expression = ParseAssignmentExpression(false, CHECK_OK); 3114 Expression* expression = ParseAssignmentExpression(false, CHECK_OK);
3106 return factory()->NewYield(generator_object, expression, is_yield_star, 3115 return factory()->NewYield(generator_object, expression, kind, position);
3107 position);
3108 } 3116 }
3109 3117
3110 3118
3111 // Precedence = 3 3119 // Precedence = 3
3112 Expression* Parser::ParseConditionalExpression(bool accept_IN, bool* ok) { 3120 Expression* Parser::ParseConditionalExpression(bool accept_IN, bool* ok) {
3113 // ConditionalExpression :: 3121 // ConditionalExpression ::
3114 // LogicalOrExpression 3122 // LogicalOrExpression
3115 // LogicalOrExpression '?' AssignmentExpression ':' AssignmentExpression 3123 // LogicalOrExpression '?' AssignmentExpression ':' AssignmentExpression
3116 3124
3117 // We start using the binary expression parser for prec >= 4 only! 3125 // We start using the binary expression parser for prec >= 4 only!
(...skipping 1455 matching lines...) Expand 10 before | Expand all | Expand 10 after
4573 isolate()->factory()->empty_string(), 4581 isolate()->factory()->empty_string(),
4574 Runtime::FunctionForId(Runtime::kCreateJSGeneratorObject), 4582 Runtime::FunctionForId(Runtime::kCreateJSGeneratorObject),
4575 arguments); 4583 arguments);
4576 VariableProxy* init_proxy = factory()->NewVariableProxy( 4584 VariableProxy* init_proxy = factory()->NewVariableProxy(
4577 current_function_state_->generator_object_variable()); 4585 current_function_state_->generator_object_variable());
4578 Assignment* assignment = factory()->NewAssignment( 4586 Assignment* assignment = factory()->NewAssignment(
4579 Token::INIT_VAR, init_proxy, allocation, RelocInfo::kNoPosition); 4587 Token::INIT_VAR, init_proxy, allocation, RelocInfo::kNoPosition);
4580 VariableProxy* get_proxy = factory()->NewVariableProxy( 4588 VariableProxy* get_proxy = factory()->NewVariableProxy(
4581 current_function_state_->generator_object_variable()); 4589 current_function_state_->generator_object_variable());
4582 Yield* yield = factory()->NewYield( 4590 Yield* yield = factory()->NewYield(
4583 get_proxy, assignment, false, RelocInfo::kNoPosition); 4591 get_proxy, assignment, Yield::INITIAL, RelocInfo::kNoPosition);
4584 body->Add(factory()->NewExpressionStatement(yield), zone()); 4592 body->Add(factory()->NewExpressionStatement(yield), zone());
4585 } 4593 }
4586 4594
4587 ParseSourceElements(body, Token::RBRACE, false, false, CHECK_OK); 4595 ParseSourceElements(body, Token::RBRACE, false, false, CHECK_OK);
4588 4596
4597 if (is_generator) {
4598 VariableProxy* get_proxy = factory()->NewVariableProxy(
4599 current_function_state_->generator_object_variable());
4600 Expression *undefined = factory()->NewLiteral(
4601 isolate()->factory()->undefined_value());
4602 Yield* yield = factory()->NewYield(
4603 get_proxy, undefined, Yield::FINAL, RelocInfo::kNoPosition);
4604 body->Add(factory()->NewExpressionStatement(yield), zone());
4605 }
4606
4589 materialized_literal_count = function_state.materialized_literal_count(); 4607 materialized_literal_count = function_state.materialized_literal_count();
4590 expected_property_count = function_state.expected_property_count(); 4608 expected_property_count = function_state.expected_property_count();
4591 handler_count = function_state.handler_count(); 4609 handler_count = function_state.handler_count();
4592 only_simple_this_property_assignments = 4610 only_simple_this_property_assignments =
4593 function_state.only_simple_this_property_assignments(); 4611 function_state.only_simple_this_property_assignments();
4594 this_property_assignments = function_state.this_property_assignments(); 4612 this_property_assignments = function_state.this_property_assignments();
4595 4613
4596 Expect(Token::RBRACE, CHECK_OK); 4614 Expect(Token::RBRACE, CHECK_OK);
4597 scope->set_end_position(scanner().location().end_pos); 4615 scope->set_end_position(scanner().location().end_pos);
4598 } 4616 }
(...skipping 1408 matching lines...) Expand 10 before | Expand all | Expand 10 after
6007 ASSERT(info()->isolate()->has_pending_exception()); 6025 ASSERT(info()->isolate()->has_pending_exception());
6008 } else { 6026 } else {
6009 result = ParseProgram(); 6027 result = ParseProgram();
6010 } 6028 }
6011 } 6029 }
6012 info()->SetFunction(result); 6030 info()->SetFunction(result);
6013 return (result != NULL); 6031 return (result != NULL);
6014 } 6032 }
6015 6033
6016 } } // namespace v8::internal 6034 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/objects-inl.h ('k') | src/runtime.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698