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

Side by Side Diff: src/preparser.cc

Issue 329413002: Throw syntax error when a getter/setter has the wrong number of params (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Add test exception Created 6 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « src/preparser.h ('k') | test/cctest/test-parsing.cc » ('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 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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 <cmath> 5 #include <cmath>
6 6
7 #include "include/v8stdint.h" 7 #include "include/v8stdint.h"
8 8
9 #include "src/allocation.h" 9 #include "src/allocation.h"
10 #include "src/checks.h" 10 #include "src/checks.h"
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 } 88 }
89 89
90 90
91 PreParserExpression PreParserTraits::ParseFunctionLiteral( 91 PreParserExpression PreParserTraits::ParseFunctionLiteral(
92 PreParserIdentifier name, 92 PreParserIdentifier name,
93 Scanner::Location function_name_location, 93 Scanner::Location function_name_location,
94 bool name_is_strict_reserved, 94 bool name_is_strict_reserved,
95 bool is_generator, 95 bool is_generator,
96 int function_token_position, 96 int function_token_position,
97 FunctionLiteral::FunctionType type, 97 FunctionLiteral::FunctionType type,
98 FunctionLiteral::ArityRestriction arity_restriction,
98 bool* ok) { 99 bool* ok) {
99 return pre_parser_->ParseFunctionLiteral( 100 return pre_parser_->ParseFunctionLiteral(
100 name, function_name_location, name_is_strict_reserved, is_generator, 101 name, function_name_location, name_is_strict_reserved, is_generator,
101 function_token_position, type, ok); 102 function_token_position, type, arity_restriction, ok);
102 } 103 }
103 104
104 105
105 PreParser::PreParseResult PreParser::PreParseLazyFunction( 106 PreParser::PreParseResult PreParser::PreParseLazyFunction(
106 StrictMode strict_mode, bool is_generator, ParserRecorder* log) { 107 StrictMode strict_mode, bool is_generator, ParserRecorder* log) {
107 log_ = log; 108 log_ = log;
108 // Lazy functions always have trivial outer scopes (no with/catch scopes). 109 // Lazy functions always have trivial outer scopes (no with/catch scopes).
109 PreParserScope top_scope(scope_, GLOBAL_SCOPE); 110 PreParserScope top_scope(scope_, GLOBAL_SCOPE);
110 FunctionState top_state(&function_state_, &scope_, &top_scope); 111 FunctionState top_state(&function_state_, &scope_, &top_scope);
111 scope_->SetStrictMode(strict_mode); 112 scope_->SetStrictMode(strict_mode);
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 bool is_generator = allow_generators() && Check(Token::MUL); 314 bool is_generator = allow_generators() && Check(Token::MUL);
314 bool is_strict_reserved = false; 315 bool is_strict_reserved = false;
315 Identifier name = ParseIdentifierOrStrictReservedWord( 316 Identifier name = ParseIdentifierOrStrictReservedWord(
316 &is_strict_reserved, CHECK_OK); 317 &is_strict_reserved, CHECK_OK);
317 ParseFunctionLiteral(name, 318 ParseFunctionLiteral(name,
318 scanner()->location(), 319 scanner()->location(),
319 is_strict_reserved, 320 is_strict_reserved,
320 is_generator, 321 is_generator,
321 pos, 322 pos,
322 FunctionLiteral::DECLARATION, 323 FunctionLiteral::DECLARATION,
324 FunctionLiteral::NORMAL_ARITY,
323 CHECK_OK); 325 CHECK_OK);
324 return Statement::FunctionDeclaration(); 326 return Statement::FunctionDeclaration();
325 } 327 }
326 328
327 329
328 PreParser::Statement PreParser::ParseBlock(bool* ok) { 330 PreParser::Statement PreParser::ParseBlock(bool* ok) {
329 // Block :: 331 // Block ::
330 // '{' Statement* '}' 332 // '{' Statement* '}'
331 333
332 // Note that a Block does not introduce a new execution scope! 334 // Note that a Block does not introduce a new execution scope!
(...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after
792 #undef DUMMY 794 #undef DUMMY
793 795
794 796
795 PreParser::Expression PreParser::ParseFunctionLiteral( 797 PreParser::Expression PreParser::ParseFunctionLiteral(
796 Identifier function_name, 798 Identifier function_name,
797 Scanner::Location function_name_location, 799 Scanner::Location function_name_location,
798 bool name_is_strict_reserved, 800 bool name_is_strict_reserved,
799 bool is_generator, 801 bool is_generator,
800 int function_token_pos, 802 int function_token_pos,
801 FunctionLiteral::FunctionType function_type, 803 FunctionLiteral::FunctionType function_type,
804 FunctionLiteral::ArityRestriction arity_restriction,
802 bool* ok) { 805 bool* ok) {
803 // Function :: 806 // Function ::
804 // '(' FormalParameterList? ')' '{' FunctionBody '}' 807 // '(' FormalParameterList? ')' '{' FunctionBody '}'
805 808
806 // Parse function body. 809 // Parse function body.
807 ScopeType outer_scope_type = scope_->type(); 810 ScopeType outer_scope_type = scope_->type();
808 PreParserScope function_scope(scope_, FUNCTION_SCOPE); 811 PreParserScope function_scope(scope_, FUNCTION_SCOPE);
809 FunctionState function_state(&function_state_, &scope_, &function_scope); 812 FunctionState function_state(&function_state_, &scope_, &function_scope);
810 function_state.set_is_generator(is_generator); 813 function_state.set_is_generator(is_generator);
811 // FormalParameterList :: 814 // FormalParameterList ::
812 // '(' (Identifier)*[','] ')' 815 // '(' (Identifier)*[','] ')'
813 Expect(Token::LPAREN, CHECK_OK); 816 Expect(Token::LPAREN, CHECK_OK);
814 int start_position = position(); 817 int start_position = position();
815 bool done = (peek() == Token::RPAREN);
816 DuplicateFinder duplicate_finder(scanner()->unicode_cache()); 818 DuplicateFinder duplicate_finder(scanner()->unicode_cache());
817 // We don't yet know if the function will be strict, so we cannot yet produce 819 // We don't yet know if the function will be strict, so we cannot yet produce
818 // errors for parameter names or duplicates. However, we remember the 820 // errors for parameter names or duplicates. However, we remember the
819 // locations of these errors if they occur and produce the errors later. 821 // locations of these errors if they occur and produce the errors later.
820 Scanner::Location eval_args_error_loc = Scanner::Location::invalid(); 822 Scanner::Location eval_args_error_loc = Scanner::Location::invalid();
821 Scanner::Location dupe_error_loc = Scanner::Location::invalid(); 823 Scanner::Location dupe_error_loc = Scanner::Location::invalid();
822 Scanner::Location reserved_error_loc = Scanner::Location::invalid(); 824 Scanner::Location reserved_error_loc = Scanner::Location::invalid();
825
826 bool done = arity_restriction == FunctionLiteral::GETTER_ARITY ||
827 (peek() == Token::RPAREN &&
828 arity_restriction != FunctionLiteral::SETTER_ARITY);
823 while (!done) { 829 while (!done) {
824 bool is_strict_reserved = false; 830 bool is_strict_reserved = false;
825 Identifier param_name = 831 Identifier param_name =
826 ParseIdentifierOrStrictReservedWord(&is_strict_reserved, CHECK_OK); 832 ParseIdentifierOrStrictReservedWord(&is_strict_reserved, CHECK_OK);
827 if (!eval_args_error_loc.IsValid() && param_name.IsEvalOrArguments()) { 833 if (!eval_args_error_loc.IsValid() && param_name.IsEvalOrArguments()) {
828 eval_args_error_loc = scanner()->location(); 834 eval_args_error_loc = scanner()->location();
829 } 835 }
830 if (!reserved_error_loc.IsValid() && is_strict_reserved) { 836 if (!reserved_error_loc.IsValid() && is_strict_reserved) {
831 reserved_error_loc = scanner()->location(); 837 reserved_error_loc = scanner()->location();
832 } 838 }
833 839
834 int prev_value = scanner()->FindSymbol(&duplicate_finder, 1); 840 int prev_value = scanner()->FindSymbol(&duplicate_finder, 1);
835 841
836 if (!dupe_error_loc.IsValid() && prev_value != 0) { 842 if (!dupe_error_loc.IsValid() && prev_value != 0) {
837 dupe_error_loc = scanner()->location(); 843 dupe_error_loc = scanner()->location();
838 } 844 }
839 845
846 if (arity_restriction == FunctionLiteral::SETTER_ARITY) break;
840 done = (peek() == Token::RPAREN); 847 done = (peek() == Token::RPAREN);
841 if (!done) { 848 if (!done) Expect(Token::COMMA, CHECK_OK);
842 Expect(Token::COMMA, CHECK_OK);
843 }
844 } 849 }
845 Expect(Token::RPAREN, CHECK_OK); 850 Expect(Token::RPAREN, CHECK_OK);
846 851
847 // See Parser::ParseFunctionLiteral for more information about lazy parsing 852 // See Parser::ParseFunctionLiteral for more information about lazy parsing
848 // and lazy compilation. 853 // and lazy compilation.
849 bool is_lazily_parsed = (outer_scope_type == GLOBAL_SCOPE && allow_lazy() && 854 bool is_lazily_parsed = (outer_scope_type == GLOBAL_SCOPE && allow_lazy() &&
850 !parenthesized_function_); 855 !parenthesized_function_);
851 parenthesized_function_ = false; 856 parenthesized_function_ = false;
852 857
853 Expect(Token::LBRACE, CHECK_OK); 858 Expect(Token::LBRACE, CHECK_OK);
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
922 ParseIdentifier(kAllowEvalOrArguments, CHECK_OK); 927 ParseIdentifier(kAllowEvalOrArguments, CHECK_OK);
923 ParseArguments(ok); 928 ParseArguments(ok);
924 929
925 return Expression::Default(); 930 return Expression::Default();
926 } 931 }
927 932
928 #undef CHECK_OK 933 #undef CHECK_OK
929 934
930 935
931 } } // v8::internal 936 } } // v8::internal
OLDNEW
« no previous file with comments | « src/preparser.h ('k') | test/cctest/test-parsing.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698