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

Side by Side Diff: src/parser.cc

Issue 1274193004: Let eval scope (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix another test Created 5 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
« no previous file with comments | « no previous file | test/mjsunit/harmony/block-conflicts-sloppy.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 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/v8.h" 5 #include "src/v8.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 1995 matching lines...) Expand 10 before | Expand all | Expand 10 after
2006 VariableMode mode = declaration->mode(); 2006 VariableMode mode = declaration->mode();
2007 Scope* declaration_scope = DeclarationScope(mode); 2007 Scope* declaration_scope = DeclarationScope(mode);
2008 Variable* var = NULL; 2008 Variable* var = NULL;
2009 2009
2010 // If a suitable scope exists, then we can statically declare this 2010 // If a suitable scope exists, then we can statically declare this
2011 // variable and also set its mode. In any case, a Declaration node 2011 // variable and also set its mode. In any case, a Declaration node
2012 // will be added to the scope so that the declaration can be added 2012 // will be added to the scope so that the declaration can be added
2013 // to the corresponding activation frame at runtime if necessary. 2013 // to the corresponding activation frame at runtime if necessary.
2014 // For instance declarations inside an eval scope need to be added 2014 // For instance declarations inside an eval scope need to be added
2015 // to the calling function context. 2015 // to the calling function context.
2016 // Similarly, strict mode eval scope does not leak variable declarations to 2016 // Similarly, strict mode eval scope does not leak variable declarations to
adamk 2015/08/11 01:17:43 This comment's getting pretty outdated, but if you
2017 // the caller's scope so we declare all locals, too. 2017 // the caller's scope so we declare all locals, too.
2018 if (declaration_scope->is_function_scope() || 2018 if (declaration_scope->is_function_scope() ||
2019 declaration_scope->is_strict_eval_scope() || 2019 declaration_scope->is_strict_eval_scope() ||
adamk 2015/08/11 01:17:43 I think it would be clearer to get rid of this lin
Dan Ehrenberg 2015/08/11 20:57:02 Done
2020 declaration_scope->is_block_scope() || 2020 declaration_scope->is_block_scope() ||
2021 declaration_scope->is_module_scope() || 2021 declaration_scope->is_module_scope() ||
2022 declaration_scope->is_script_scope()) { 2022 declaration_scope->is_script_scope() ||
2023 (declaration_scope->is_eval_scope() && IsLexicalVariableMode(mode))) {
adamk 2015/08/11 01:17:43 ...and replace this condition with: (declaration_
Dan Ehrenberg 2015/08/11 20:57:02 Done
2023 // Declare the variable in the declaration scope. 2024 // Declare the variable in the declaration scope.
2024 var = declaration_scope->LookupLocal(name); 2025 var = declaration_scope->LookupLocal(name);
2025 if (var == NULL) { 2026 if (var == NULL) {
2026 // Declare the name. 2027 // Declare the name.
2027 Variable::Kind kind = Variable::NORMAL; 2028 Variable::Kind kind = Variable::NORMAL;
2028 int declaration_group_start = -1; 2029 int declaration_group_start = -1;
2029 if (declaration->IsFunctionDeclaration()) { 2030 if (declaration->IsFunctionDeclaration()) {
2030 kind = Variable::FUNCTION; 2031 kind = Variable::FUNCTION;
2031 } else if (declaration->IsVariableDeclaration() && 2032 } else if (declaration->IsVariableDeclaration() &&
2032 declaration->AsVariableDeclaration()->is_class_declaration()) { 2033 declaration->AsVariableDeclaration()->is_class_declaration()) {
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
2092 // RuntimeHidden_DeclareLookupSlot calls. 2093 // RuntimeHidden_DeclareLookupSlot calls.
2093 declaration_scope->AddDeclaration(declaration); 2094 declaration_scope->AddDeclaration(declaration);
2094 2095
2095 if (mode == CONST_LEGACY && declaration_scope->is_script_scope()) { 2096 if (mode == CONST_LEGACY && declaration_scope->is_script_scope()) {
2096 // For global const variables we bind the proxy to a variable. 2097 // For global const variables we bind the proxy to a variable.
2097 DCHECK(resolve); // should be set by all callers 2098 DCHECK(resolve); // should be set by all callers
2098 Variable::Kind kind = Variable::NORMAL; 2099 Variable::Kind kind = Variable::NORMAL;
2099 var = new (zone()) Variable(declaration_scope, name, mode, kind, 2100 var = new (zone()) Variable(declaration_scope, name, mode, kind,
2100 kNeedsInitialization, kNotAssigned); 2101 kNeedsInitialization, kNotAssigned);
2101 } else if (declaration_scope->is_eval_scope() && 2102 } else if (declaration_scope->is_eval_scope() &&
2102 is_sloppy(declaration_scope->language_mode())) { 2103 is_sloppy(declaration_scope->language_mode()) &&
2104 !IsLexicalVariableMode(mode)) {
adamk 2015/08/11 01:17:43 It's weird that this isn't part of an else/if clau
Dan Ehrenberg 2015/08/11 20:57:02 Good point; moved it to an else clause above. The
2103 // For variable declarations in a sloppy eval scope the proxy is bound 2105 // For variable declarations in a sloppy eval scope the proxy is bound
2104 // to a lookup variable to force a dynamic declaration using the 2106 // to a lookup variable to force a dynamic declaration using the
2105 // DeclareLookupSlot runtime function. 2107 // DeclareLookupSlot runtime function.
2106 Variable::Kind kind = Variable::NORMAL; 2108 Variable::Kind kind = Variable::NORMAL;
2107 // TODO(sigurds) figure out if kNotAssigned is OK here 2109 // TODO(sigurds) figure out if kNotAssigned is OK here
2108 var = new (zone()) Variable(declaration_scope, name, mode, kind, 2110 var = new (zone()) Variable(declaration_scope, name, mode, kind,
2109 declaration->initialization(), kNotAssigned); 2111 declaration->initialization(), kNotAssigned);
2110 var->AllocateTo(VariableLocation::LOOKUP, -1); 2112 var->AllocateTo(VariableLocation::LOOKUP, -1);
2111 resolve = true; 2113 resolve = true;
2112 } 2114 }
(...skipping 3897 matching lines...) Expand 10 before | Expand all | Expand 10 after
6010 Expression* Parser::SpreadCallNew(Expression* function, 6012 Expression* Parser::SpreadCallNew(Expression* function,
6011 ZoneList<v8::internal::Expression*>* args, 6013 ZoneList<v8::internal::Expression*>* args,
6012 int pos) { 6014 int pos) {
6013 args->InsertAt(0, function, zone()); 6015 args->InsertAt(0, function, zone());
6014 6016
6015 return factory()->NewCallRuntime( 6017 return factory()->NewCallRuntime(
6016 ast_value_factory()->reflect_construct_string(), NULL, args, pos); 6018 ast_value_factory()->reflect_construct_string(), NULL, args, pos);
6017 } 6019 }
6018 } // namespace internal 6020 } // namespace internal
6019 } // namespace v8 6021 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | test/mjsunit/harmony/block-conflicts-sloppy.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698