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/parsing/parser.h" | 5 #include "src/parsing/parser.h" |
6 | 6 |
7 #include "src/api.h" | 7 #include "src/api.h" |
8 #include "src/ast/ast.h" | 8 #include "src/ast/ast.h" |
9 #include "src/ast/ast-expression-rewriter.h" | 9 #include "src/ast/ast-expression-rewriter.h" |
10 #include "src/ast/ast-expression-visitor.h" | 10 #include "src/ast/ast-expression-visitor.h" |
(...skipping 2369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2380 if (labels != NULL) { | 2380 if (labels != NULL) { |
2381 for (int i = labels->length(); i-- > 0; ) { | 2381 for (int i = labels->length(); i-- > 0; ) { |
2382 if (labels->at(i) == label) { | 2382 if (labels->at(i) == label) { |
2383 return true; | 2383 return true; |
2384 } | 2384 } |
2385 } | 2385 } |
2386 } | 2386 } |
2387 return false; | 2387 return false; |
2388 } | 2388 } |
2389 | 2389 |
2390 Statement* Parser::ParseOnlyFunctionDeclaration(bool* ok) { | |
2391 Consume(Token::FUNCTION); | |
2392 int pos = position(); | |
2393 bool is_generator = Check(Token::MUL); | |
2394 if (allow_harmony_restrictive_declarations() && is_generator) { | |
2395 ParserTraits::ReportMessageAt( | |
2396 scanner()->location(), | |
2397 MessageTemplate::kGeneratorInLegacyContext); | |
2398 *ok = false; | |
2399 return nullptr; | |
2400 } | |
2401 return ParseFunctionDeclaration(pos, is_generator, NULL, CHECK_OK); | |
adamk
2016/04/20 19:09:28
Nit: nullptr
Dan Ehrenberg
2016/04/26 22:24:18
Fixed
| |
2402 } | |
2403 | |
2390 Statement* Parser::ParseExpressionOrLabelledStatement( | 2404 Statement* Parser::ParseExpressionOrLabelledStatement( |
2391 ZoneList<const AstRawString*>* labels, | 2405 ZoneList<const AstRawString*>* labels, |
2392 AllowLabelledFunctionStatement allow_function, bool* ok) { | 2406 AllowLabelledFunctionStatement allow_function, bool* ok) { |
2393 // ExpressionStatement | LabelledStatement :: | 2407 // ExpressionStatement | LabelledStatement :: |
2394 // Expression ';' | 2408 // Expression ';' |
2395 // Identifier ':' Statement | 2409 // Identifier ':' Statement |
2396 // | 2410 // |
2397 // ExpressionStatement[Yield] : | 2411 // ExpressionStatement[Yield] : |
2398 // [lookahead ∉ {{, function, class, let [}] Expression[In, ?Yield] ; | 2412 // [lookahead ∉ {{, function, class, let [}] Expression[In, ?Yield] ; |
2399 | 2413 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2436 } | 2450 } |
2437 labels->Add(label, zone()); | 2451 labels->Add(label, zone()); |
2438 // Remove the "ghost" variable that turned out to be a label | 2452 // Remove the "ghost" variable that turned out to be a label |
2439 // from the top scope. This way, we don't try to resolve it | 2453 // from the top scope. This way, we don't try to resolve it |
2440 // during the scope processing. | 2454 // during the scope processing. |
2441 scope_->RemoveUnresolved(var); | 2455 scope_->RemoveUnresolved(var); |
2442 Expect(Token::COLON, CHECK_OK); | 2456 Expect(Token::COLON, CHECK_OK); |
2443 // ES#sec-labelled-function-declarations Labelled Function Declarations | 2457 // ES#sec-labelled-function-declarations Labelled Function Declarations |
2444 if (peek() == Token::FUNCTION && is_sloppy(language_mode())) { | 2458 if (peek() == Token::FUNCTION && is_sloppy(language_mode())) { |
2445 if (allow_function == kAllowLabelledFunctionStatement) { | 2459 if (allow_function == kAllowLabelledFunctionStatement) { |
2446 return ParseFunctionDeclaration(labels, ok); | 2460 return ParseOnlyFunctionDeclaration(ok); |
adamk
2016/04/20 19:09:28
Was this passing of labels just wrong?
Dan Ehrenberg
2016/04/26 22:24:18
Actually, yes. We were confusing labels for export
| |
2447 } else { | 2461 } else { |
2448 return ParseScopedStatement(labels, true, ok); | 2462 return ParseScopedStatement(labels, true, ok); |
2449 } | 2463 } |
2450 } | 2464 } |
2451 return ParseStatement(labels, kDisallowLabelledFunctionStatement, ok); | 2465 return ParseStatement(labels, kDisallowLabelledFunctionStatement, ok); |
2452 } | 2466 } |
2453 | 2467 |
2454 // If we have an extension, we allow a native function declaration. | 2468 // If we have an extension, we allow a native function declaration. |
2455 // A native function declaration starts with "native function" with | 2469 // A native function declaration starts with "native function" with |
2456 // no line-terminator between the two words. | 2470 // no line-terminator between the two words. |
(...skipping 973 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3430 return ParseSubStatement(labels, kDisallowLabelledFunctionStatement, ok); | 3444 return ParseSubStatement(labels, kDisallowLabelledFunctionStatement, ok); |
3431 } else { | 3445 } else { |
3432 if (legacy) { | 3446 if (legacy) { |
3433 ++use_counts_[v8::Isolate::kLegacyFunctionDeclaration]; | 3447 ++use_counts_[v8::Isolate::kLegacyFunctionDeclaration]; |
3434 } | 3448 } |
3435 // Make a block around the statement for a lexical binding | 3449 // Make a block around the statement for a lexical binding |
3436 // is introduced by a FunctionDeclaration. | 3450 // is introduced by a FunctionDeclaration. |
3437 Scope* body_scope = NewScope(scope_, BLOCK_SCOPE); | 3451 Scope* body_scope = NewScope(scope_, BLOCK_SCOPE); |
3438 BlockState block_state(&scope_, body_scope); | 3452 BlockState block_state(&scope_, body_scope); |
3439 Block* block = factory()->NewBlock(NULL, 1, false, RelocInfo::kNoPosition); | 3453 Block* block = factory()->NewBlock(NULL, 1, false, RelocInfo::kNoPosition); |
3440 Statement* body = ParseFunctionDeclaration(NULL, CHECK_OK); | 3454 Statement* body = ParseOnlyFunctionDeclaration(CHECK_OK); |
3441 block->statements()->Add(body, zone()); | 3455 block->statements()->Add(body, zone()); |
3442 body_scope->set_end_position(scanner()->location().end_pos); | 3456 body_scope->set_end_position(scanner()->location().end_pos); |
3443 body_scope = body_scope->FinalizeBlockScope(); | 3457 body_scope = body_scope->FinalizeBlockScope(); |
3444 block->set_scope(body_scope); | 3458 block->set_scope(body_scope); |
3445 return block; | 3459 return block; |
3446 } | 3460 } |
3447 } | 3461 } |
3448 | 3462 |
3449 Statement* Parser::ParseForStatement(ZoneList<const AstRawString*>* labels, | 3463 Statement* Parser::ParseForStatement(ZoneList<const AstRawString*>* labels, |
3450 bool* ok) { | 3464 bool* ok) { |
(...skipping 3334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6785 try_block, target); | 6799 try_block, target); |
6786 final_loop = target; | 6800 final_loop = target; |
6787 } | 6801 } |
6788 | 6802 |
6789 return final_loop; | 6803 return final_loop; |
6790 } | 6804 } |
6791 | 6805 |
6792 | 6806 |
6793 } // namespace internal | 6807 } // namespace internal |
6794 } // namespace v8 | 6808 } // namespace v8 |
OLD | NEW |