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

Side by Side Diff: src/preparser.cc

Issue 477263002: ES6: Add support for method shorthand in object literals (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Add strict formal param checking Created 6 years, 4 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
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/base/logging.h" 10 #include "src/base/logging.h"
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 return PreParserExpression::StringLiteral(); 90 return PreParserExpression::StringLiteral();
91 } 91 }
92 92
93 93
94 PreParserExpression PreParserTraits::ParseV8Intrinsic(bool* ok) { 94 PreParserExpression PreParserTraits::ParseV8Intrinsic(bool* ok) {
95 return pre_parser_->ParseV8Intrinsic(ok); 95 return pre_parser_->ParseV8Intrinsic(ok);
96 } 96 }
97 97
98 98
99 PreParserExpression PreParserTraits::ParseFunctionLiteral( 99 PreParserExpression PreParserTraits::ParseFunctionLiteral(
100 PreParserIdentifier name, 100 PreParserIdentifier name, Scanner::Location function_name_location,
101 Scanner::Location function_name_location, 101 bool name_is_strict_reserved, FunctionLiteral::IsGeneratorFlag is_generator,
102 bool name_is_strict_reserved, 102 FunctionLiteral::IsArrowFlag is_arrow,
103 bool is_generator, 103 FunctionLiteral::IsConciseMethodFlag is_concise_method,
104 int function_token_position, 104 int function_token_position, FunctionLiteral::FunctionType type,
105 FunctionLiteral::FunctionType type, 105 FunctionLiteral::ArityRestriction arity_restriction, bool* ok) {
106 FunctionLiteral::ArityRestriction arity_restriction,
107 bool* ok) {
108 return pre_parser_->ParseFunctionLiteral( 106 return pre_parser_->ParseFunctionLiteral(
109 name, function_name_location, name_is_strict_reserved, is_generator, 107 name, function_name_location, name_is_strict_reserved, is_generator,
110 function_token_position, type, arity_restriction, ok); 108 is_arrow, is_concise_method, function_token_position, type,
109 arity_restriction, ok);
111 } 110 }
112 111
113 112
114 PreParser::PreParseResult PreParser::PreParseLazyFunction( 113 PreParser::PreParseResult PreParser::PreParseLazyFunction(
115 StrictMode strict_mode, bool is_generator, ParserRecorder* log) { 114 StrictMode strict_mode, bool is_generator, ParserRecorder* log) {
116 log_ = log; 115 log_ = log;
117 // Lazy functions always have trivial outer scopes (no with/catch scopes). 116 // Lazy functions always have trivial outer scopes (no with/catch scopes).
118 PreParserScope top_scope(scope_, GLOBAL_SCOPE); 117 PreParserScope top_scope(scope_, GLOBAL_SCOPE);
119 FunctionState top_state(&function_state_, &scope_, &top_scope, NULL, 118 FunctionState top_state(&function_state_, &scope_, &top_scope, NULL,
120 this->ast_value_factory()); 119 this->ast_value_factory());
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 // 'function' Identifier '(' FormalParameterListopt ')' '{' FunctionBody '}' 327 // 'function' Identifier '(' FormalParameterListopt ')' '{' FunctionBody '}'
329 // GeneratorDeclaration :: 328 // GeneratorDeclaration ::
330 // 'function' '*' Identifier '(' FormalParameterListopt ')' 329 // 'function' '*' Identifier '(' FormalParameterListopt ')'
331 // '{' FunctionBody '}' 330 // '{' FunctionBody '}'
332 Expect(Token::FUNCTION, CHECK_OK); 331 Expect(Token::FUNCTION, CHECK_OK);
333 int pos = position(); 332 int pos = position();
334 bool is_generator = allow_generators() && Check(Token::MUL); 333 bool is_generator = allow_generators() && Check(Token::MUL);
335 bool is_strict_reserved = false; 334 bool is_strict_reserved = false;
336 Identifier name = ParseIdentifierOrStrictReservedWord( 335 Identifier name = ParseIdentifierOrStrictReservedWord(
337 &is_strict_reserved, CHECK_OK); 336 &is_strict_reserved, CHECK_OK);
338 ParseFunctionLiteral(name, 337 ParseFunctionLiteral(
339 scanner()->location(), 338 name, scanner()->location(), is_strict_reserved,
340 is_strict_reserved, 339 is_generator ? FunctionLiteral::kIsGenerator
341 is_generator, 340 : FunctionLiteral::kNotGenerator,
342 pos, 341 FunctionLiteral::kNotArrow, FunctionLiteral::kNotConciseMethod, pos,
343 FunctionLiteral::DECLARATION, 342 FunctionLiteral::DECLARATION, FunctionLiteral::NORMAL_ARITY, CHECK_OK);
344 FunctionLiteral::NORMAL_ARITY,
345 CHECK_OK);
346 return Statement::FunctionDeclaration(); 343 return Statement::FunctionDeclaration();
347 } 344 }
348 345
349 346
350 PreParser::Statement PreParser::ParseBlock(bool* ok) { 347 PreParser::Statement PreParser::ParseBlock(bool* ok) {
351 // Block :: 348 // Block ::
352 // '{' Statement* '}' 349 // '{' Statement* '}'
353 350
354 // Note that a Block does not introduce a new execution scope! 351 // Note that a Block does not introduce a new execution scope!
355 // (ECMA-262, 3rd, 12.2) 352 // (ECMA-262, 3rd, 12.2)
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after
793 790
794 #undef CHECK_OK 791 #undef CHECK_OK
795 #define CHECK_OK ok); \ 792 #define CHECK_OK ok); \
796 if (!*ok) return Expression::Default(); \ 793 if (!*ok) return Expression::Default(); \
797 ((void)0 794 ((void)0
798 #define DUMMY ) // to make indentation work 795 #define DUMMY ) // to make indentation work
799 #undef DUMMY 796 #undef DUMMY
800 797
801 798
802 PreParser::Expression PreParser::ParseFunctionLiteral( 799 PreParser::Expression PreParser::ParseFunctionLiteral(
803 Identifier function_name, 800 Identifier function_name, Scanner::Location function_name_location,
804 Scanner::Location function_name_location, 801 bool name_is_strict_reserved, FunctionLiteral::IsGeneratorFlag is_generator,
805 bool name_is_strict_reserved, 802 FunctionLiteral::IsArrowFlag is_arrow,
806 bool is_generator, 803 FunctionLiteral::IsConciseMethodFlag is_concise_method,
807 int function_token_pos, 804 int function_token_pos, FunctionLiteral::FunctionType function_type,
808 FunctionLiteral::FunctionType function_type, 805 FunctionLiteral::ArityRestriction arity_restriction, bool* ok) {
809 FunctionLiteral::ArityRestriction arity_restriction,
810 bool* ok) {
811 // Function :: 806 // Function ::
812 // '(' FormalParameterList? ')' '{' FunctionBody '}' 807 // '(' FormalParameterList? ')' '{' FunctionBody '}'
813 808
814 // Parse function body. 809 // Parse function body.
815 ScopeType outer_scope_type = scope_->type(); 810 ScopeType outer_scope_type = scope_->type();
816 PreParserScope function_scope(scope_, FUNCTION_SCOPE); 811 PreParserScope function_scope(scope_, FUNCTION_SCOPE);
817 FunctionState function_state(&function_state_, &scope_, &function_scope, NULL, 812 FunctionState function_state(&function_state_, &scope_, &function_scope, NULL,
818 this->ast_value_factory()); 813 this->ast_value_factory());
819 function_state.set_is_generator(is_generator); 814 function_state.set_is_generator(is_generator);
820 // FormalParameterList :: 815 // FormalParameterList ::
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
864 Expect(Token::LBRACE, CHECK_OK); 859 Expect(Token::LBRACE, CHECK_OK);
865 if (is_lazily_parsed) { 860 if (is_lazily_parsed) {
866 ParseLazyFunctionLiteralBody(CHECK_OK); 861 ParseLazyFunctionLiteralBody(CHECK_OK);
867 } else { 862 } else {
868 ParseSourceElements(Token::RBRACE, ok); 863 ParseSourceElements(Token::RBRACE, ok);
869 } 864 }
870 Expect(Token::RBRACE, CHECK_OK); 865 Expect(Token::RBRACE, CHECK_OK);
871 866
872 // Validate strict mode. We can do this only after parsing the function, 867 // Validate strict mode. We can do this only after parsing the function,
873 // since the function can declare itself strict. 868 // since the function can declare itself strict.
874 if (strict_mode() == STRICT) { 869 // Concise methods use StrictFormalParameters.
870 if (strict_mode() == STRICT || is_concise_method) {
875 if (function_name.IsEvalOrArguments()) { 871 if (function_name.IsEvalOrArguments()) {
876 ReportMessageAt(function_name_location, "strict_eval_arguments"); 872 ReportMessageAt(function_name_location, "strict_eval_arguments");
877 *ok = false; 873 *ok = false;
878 return Expression::Default(); 874 return Expression::Default();
879 } 875 }
880 if (name_is_strict_reserved) { 876 if (name_is_strict_reserved) {
881 ReportMessageAt(function_name_location, "unexpected_strict_reserved"); 877 ReportMessageAt(function_name_location, "unexpected_strict_reserved");
882 *ok = false; 878 *ok = false;
883 return Expression::Default(); 879 return Expression::Default();
884 } 880 }
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
933 ParseIdentifier(kAllowEvalOrArguments, CHECK_OK); 929 ParseIdentifier(kAllowEvalOrArguments, CHECK_OK);
934 ParseArguments(ok); 930 ParseArguments(ok);
935 931
936 return Expression::Default(); 932 return Expression::Default();
937 } 933 }
938 934
939 #undef CHECK_OK 935 #undef CHECK_OK
940 936
941 937
942 } } // v8::internal 938 } } // v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698