OLD | NEW |
---|---|
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 Loading... | |
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* iterator = factory()->NewVariableProxy( | |
Michael Starzinger
2013/04/17 13:43:48
Hehe, you really like calling generator objects "i
| |
2525 current_function_state_->generator_object_variable()); | |
2526 Expression* yield = factory()->NewYield( | |
2527 iterator, return_value, Yield::FINAL, RelocInfo::kNoPosition); | |
2528 result = factory()->NewExpressionStatement(yield); | |
Michael Starzinger
2013/04/17 13:43:48
Could we add parsing tests to generators-parsing.j
| |
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 Loading... | |
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 Loading... | |
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 |
4589 materialized_literal_count = function_state.materialized_literal_count(); | 4597 materialized_literal_count = function_state.materialized_literal_count(); |
4590 expected_property_count = function_state.expected_property_count(); | 4598 expected_property_count = function_state.expected_property_count(); |
4591 handler_count = function_state.handler_count(); | 4599 handler_count = function_state.handler_count(); |
4592 only_simple_this_property_assignments = | 4600 only_simple_this_property_assignments = |
4593 function_state.only_simple_this_property_assignments(); | 4601 function_state.only_simple_this_property_assignments(); |
(...skipping 1413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6007 ASSERT(info()->isolate()->has_pending_exception()); | 6015 ASSERT(info()->isolate()->has_pending_exception()); |
6008 } else { | 6016 } else { |
6009 result = ParseProgram(); | 6017 result = ParseProgram(); |
6010 } | 6018 } |
6011 } | 6019 } |
6012 info()->SetFunction(result); | 6020 info()->SetFunction(result); |
6013 return (result != NULL); | 6021 return (result != NULL); |
6014 } | 6022 } |
6015 | 6023 |
6016 } } // namespace v8::internal | 6024 } } // namespace v8::internal |
OLD | NEW |