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

Side by Side Diff: src/parser.cc

Issue 1332873003: Implement sloppy-mode block-defined functions (Annex B 3.3) (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Improve type clarity Created 5 years, 3 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
« no previous file with comments | « src/parser.h ('k') | src/pattern-rewriter.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 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/parser.h" 5 #include "src/parser.h"
6 6
7 #include "src/api.h" 7 #include "src/api.h"
8 #include "src/ast.h" 8 #include "src/ast.h"
9 #include "src/ast-literal-reindexer.h" 9 #include "src/ast-literal-reindexer.h"
10 #include "src/bailout-reason.h" 10 #include "src/bailout-reason.h"
(...skipping 2241 matching lines...) Expand 10 before | Expand all | Expand 10 after
2252 ? CONST 2252 ? CONST
2253 : (is_strict(language_mode()) || allow_harmony_sloppy_function()) && 2253 : (is_strict(language_mode()) || allow_harmony_sloppy_function()) &&
2254 !scope_->is_declaration_scope() 2254 !scope_->is_declaration_scope()
2255 ? LET 2255 ? LET
2256 : VAR; 2256 : VAR;
2257 VariableProxy* proxy = NewUnresolved(name, mode); 2257 VariableProxy* proxy = NewUnresolved(name, mode);
2258 Declaration* declaration = 2258 Declaration* declaration =
2259 factory()->NewFunctionDeclaration(proxy, mode, fun, scope_, pos); 2259 factory()->NewFunctionDeclaration(proxy, mode, fun, scope_, pos);
2260 Declare(declaration, DeclarationDescriptor::NORMAL, true, CHECK_OK); 2260 Declare(declaration, DeclarationDescriptor::NORMAL, true, CHECK_OK);
2261 if (names) names->Add(name, zone()); 2261 if (names) names->Add(name, zone());
2262 return factory()->NewEmptyStatement(RelocInfo::kNoPosition); 2262 EmptyStatement* empty = factory()->NewEmptyStatement(RelocInfo::kNoPosition);
2263 if (is_sloppy(language_mode()) && allow_harmony_sloppy_function() &&
2264 !scope_->is_declaration_scope()) {
2265 SloppyBlockFunctionStatement* delegate =
2266 factory()->NewSloppyBlockFunctionStatement(empty, scope_);
2267 scope_->DeclarationScope()->sloppy_block_function_map()->Declare(name,
2268 delegate);
2269 return delegate;
2270 }
2271 return empty;
2263 } 2272 }
2264 2273
2265 2274
2266 Statement* Parser::ParseClassDeclaration(ZoneList<const AstRawString*>* names, 2275 Statement* Parser::ParseClassDeclaration(ZoneList<const AstRawString*>* names,
2267 bool* ok) { 2276 bool* ok) {
2268 // ClassDeclaration :: 2277 // ClassDeclaration ::
2269 // 'class' Identifier ('extends' LeftHandExpression)? '{' ClassBody '}' 2278 // 'class' Identifier ('extends' LeftHandExpression)? '{' ClassBody '}'
2270 // 2279 //
2271 // A ClassDeclaration 2280 // A ClassDeclaration
2272 // 2281 //
(...skipping 1997 matching lines...) Expand 10 before | Expand all | Expand 10 after
4270 function_name_location, CHECK_OK); 4279 function_name_location, CHECK_OK);
4271 const bool allow_duplicate_parameters = 4280 const bool allow_duplicate_parameters =
4272 is_sloppy(language_mode) && formals.is_simple && !IsConciseMethod(kind); 4281 is_sloppy(language_mode) && formals.is_simple && !IsConciseMethod(kind);
4273 ValidateFormalParameters(&formals_classifier, language_mode, 4282 ValidateFormalParameters(&formals_classifier, language_mode,
4274 allow_duplicate_parameters, CHECK_OK); 4283 allow_duplicate_parameters, CHECK_OK);
4275 4284
4276 if (is_strict(language_mode)) { 4285 if (is_strict(language_mode)) {
4277 CheckStrictOctalLiteral(scope->start_position(), scope->end_position(), 4286 CheckStrictOctalLiteral(scope->start_position(), scope->end_position(),
4278 CHECK_OK); 4287 CHECK_OK);
4279 } 4288 }
4289 if (is_sloppy(language_mode) && allow_harmony_sloppy_function()) {
4290 InsertSloppyBlockFunctionVarBindings(scope, CHECK_OK);
4291 }
4280 if (is_strict(language_mode) || allow_harmony_sloppy()) { 4292 if (is_strict(language_mode) || allow_harmony_sloppy()) {
4281 CheckConflictingVarDeclarations(scope, CHECK_OK); 4293 CheckConflictingVarDeclarations(scope, CHECK_OK);
4282 } 4294 }
4283 } 4295 }
4284 4296
4285 bool has_duplicate_parameters = 4297 bool has_duplicate_parameters =
4286 !formals_classifier.is_valid_formal_parameter_list_without_duplicates(); 4298 !formals_classifier.is_valid_formal_parameter_list_without_duplicates();
4287 FunctionLiteral::ParameterFlag duplicate_parameters = 4299 FunctionLiteral::ParameterFlag duplicate_parameters =
4288 has_duplicate_parameters ? FunctionLiteral::kHasDuplicateParameters 4300 has_duplicate_parameters ? FunctionLiteral::kHasDuplicateParameters
4289 : FunctionLiteral::kNoDuplicateParameters; 4301 : FunctionLiteral::kNoDuplicateParameters;
(...skipping 642 matching lines...) Expand 10 before | Expand all | Expand 10 after
4932 Scanner::Location location = position == RelocInfo::kNoPosition 4944 Scanner::Location location = position == RelocInfo::kNoPosition
4933 ? Scanner::Location::invalid() 4945 ? Scanner::Location::invalid()
4934 : Scanner::Location(position, position + 1); 4946 : Scanner::Location(position, position + 1);
4935 ParserTraits::ReportMessageAt(location, MessageTemplate::kVarRedeclaration, 4947 ParserTraits::ReportMessageAt(location, MessageTemplate::kVarRedeclaration,
4936 name); 4948 name);
4937 *ok = false; 4949 *ok = false;
4938 } 4950 }
4939 } 4951 }
4940 4952
4941 4953
4954 void Parser::InsertSloppyBlockFunctionVarBindings(Scope* scope, bool* ok) {
4955 // For each variable which is used as a function declaration in a sloppy
4956 // block,
4957 DCHECK(scope->is_declaration_scope());
4958 SloppyBlockFunctionMap* map = scope->sloppy_block_function_map();
4959 for (ZoneHashMap::Entry* p = map->Start(); p != nullptr; p = map->Next(p)) {
4960 AstRawString* name = static_cast<AstRawString*>(p->key);
4961 // If the variable wouldn't conflict with a lexical declaration,
4962 Variable* var = scope->LookupLocal(name);
4963 if (var == nullptr || !IsLexicalVariableMode(var->mode())) {
4964 // Declare a var-style binding for the function in the outer scope
4965 VariableProxy* proxy = scope->NewUnresolved(factory(), name);
4966 Declaration* declaration = factory()->NewVariableDeclaration(
4967 proxy, VAR, scope, RelocInfo::kNoPosition);
4968 Declare(declaration, DeclarationDescriptor::NORMAL, true, ok, scope);
4969 DCHECK(ok); // Based on the preceding check, this should not fail
4970 if (!ok) return;
4971
4972 // Write in assignments to var for each block-scoped function declaration
4973 auto delegates = static_cast<SloppyBlockFunctionMap::Vector*>(p->value);
4974 for (SloppyBlockFunctionStatement* delegate : *delegates) {
4975 // Read from the local lexical scope and write to the function scope
4976 VariableProxy* to = scope->NewUnresolved(factory(), name);
4977 VariableProxy* from = delegate->scope()->NewUnresolved(factory(), name);
4978 Expression* assignment = factory()->NewAssignment(
4979 Token::ASSIGN, to, from, RelocInfo::kNoPosition);
4980 Statement* statement = factory()->NewExpressionStatement(
4981 assignment, RelocInfo::kNoPosition);
4982 delegate->set_statement(statement);
4983 }
4984 }
4985 }
4986 }
4987
4988
4942 // ---------------------------------------------------------------------------- 4989 // ----------------------------------------------------------------------------
4943 // Parser support 4990 // Parser support
4944 4991
4945 bool Parser::TargetStackContainsLabel(const AstRawString* label) { 4992 bool Parser::TargetStackContainsLabel(const AstRawString* label) {
4946 for (Target* t = target_stack_; t != NULL; t = t->previous()) { 4993 for (Target* t = target_stack_; t != NULL; t = t->previous()) {
4947 if (ContainsLabel(t->statement()->labels(), label)) return true; 4994 if (ContainsLabel(t->statement()->labels(), label)) return true;
4948 } 4995 }
4949 return false; 4996 return false;
4950 } 4997 }
4951 4998
(...skipping 1291 matching lines...) Expand 10 before | Expand all | Expand 10 after
6243 6290
6244 Expression* Parser::SpreadCallNew(Expression* function, 6291 Expression* Parser::SpreadCallNew(Expression* function,
6245 ZoneList<v8::internal::Expression*>* args, 6292 ZoneList<v8::internal::Expression*>* args,
6246 int pos) { 6293 int pos) {
6247 args->InsertAt(0, function, zone()); 6294 args->InsertAt(0, function, zone());
6248 6295
6249 return factory()->NewCallRuntime(Context::REFLECT_CONSTRUCT_INDEX, args, pos); 6296 return factory()->NewCallRuntime(Context::REFLECT_CONSTRUCT_INDEX, args, pos);
6250 } 6297 }
6251 } // namespace internal 6298 } // namespace internal
6252 } // namespace v8 6299 } // namespace v8
OLDNEW
« no previous file with comments | « src/parser.h ('k') | src/pattern-rewriter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698