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

Side by Side Diff: src/parser.cc

Issue 5044003: Fix bug in parser that allows "(foo):42" as a labeled statement. (Closed)
Patch Set: Created 10 years, 1 month 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 | « no previous file | test/mjsunit/regress/regress-918.js » ('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 2010 the V8 project authors. All rights reserved. 1 // Copyright 2010 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 1674 matching lines...) Expand 10 before | Expand all | Expand 10 after
1685 1685
1686 return false; 1686 return false;
1687 } 1687 }
1688 1688
1689 1689
1690 Statement* Parser::ParseExpressionOrLabelledStatement(ZoneStringList* labels, 1690 Statement* Parser::ParseExpressionOrLabelledStatement(ZoneStringList* labels,
1691 bool* ok) { 1691 bool* ok) {
1692 // ExpressionStatement | LabelledStatement :: 1692 // ExpressionStatement | LabelledStatement ::
1693 // Expression ';' 1693 // Expression ';'
1694 // Identifier ':' Statement 1694 // Identifier ':' Statement
1695 1695 bool starts_with_idenfifier = (peek() == Token::IDENTIFIER);
1696 Expression* expr = ParseExpression(true, CHECK_OK); 1696 Expression* expr = ParseExpression(true, CHECK_OK);
1697 if (peek() == Token::COLON && expr && 1697 if (peek() == Token::COLON && starts_with_idenfifier && expr &&
1698 expr->AsVariableProxy() != NULL && 1698 expr->AsVariableProxy() != NULL &&
1699 !expr->AsVariableProxy()->is_this()) { 1699 !expr->AsVariableProxy()->is_this()) {
1700 // Expression is a single identifier, and not, e.g., a parenthesized
1701 // identifier.
1700 VariableProxy* var = expr->AsVariableProxy(); 1702 VariableProxy* var = expr->AsVariableProxy();
1701 Handle<String> label = var->name(); 1703 Handle<String> label = var->name();
1702 // TODO(1240780): We don't check for redeclaration of labels 1704 // TODO(1240780): We don't check for redeclaration of labels
1703 // during preparsing since keeping track of the set of active 1705 // during preparsing since keeping track of the set of active
1704 // labels requires nontrivial changes to the way scopes are 1706 // labels requires nontrivial changes to the way scopes are
1705 // structured. However, these are probably changes we want to 1707 // structured. However, these are probably changes we want to
1706 // make later anyway so we should go back and fix this then. 1708 // make later anyway so we should go back and fix this then.
1707 if (ContainsLabel(labels, label) || TargetStackContainsLabel(label)) { 1709 if (ContainsLabel(labels, label) || TargetStackContainsLabel(label)) {
1708 SmartPointer<char> c_string = label->ToCString(DISALLOW_NULLS); 1710 SmartPointer<char> c_string = label->ToCString(DISALLOW_NULLS);
1709 const char* elms[2] = { "Label", *c_string }; 1711 const char* elms[2] = { "Label", *c_string };
(...skipping 3022 matching lines...) Expand 10 before | Expand all | Expand 10 after
4732 Handle<String> source = Handle<String>(String::cast(script->source())); 4734 Handle<String> source = Handle<String>(String::cast(script->source()));
4733 result = parser.ParseProgram(source, info->is_global()); 4735 result = parser.ParseProgram(source, info->is_global());
4734 } 4736 }
4735 } 4737 }
4736 4738
4737 info->SetFunction(result); 4739 info->SetFunction(result);
4738 return (result != NULL); 4740 return (result != NULL);
4739 } 4741 }
4740 4742
4741 } } // namespace v8::internal 4743 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | test/mjsunit/regress/regress-918.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698