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

Side by Side Diff: src/parsing/parser.cc

Issue 1995863002: Improve strictness of Annex B 3.3 for generators and async functions (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: fix mixed duplicates Created 4 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
« no previous file with comments | « src/flag-definitions.h ('k') | src/parsing/parser-base.h » ('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/parsing/parser.h" 5 #include "src/parsing/parser.h"
6 6
7 #include "src/api.h" 7 #include "src/api.h"
8 #include "src/ast/ast.h" 8 #include "src/ast/ast.h"
9 #include "src/ast/ast-expression-rewriter.h" 9 #include "src/ast/ast-expression-rewriter.h"
10 #include "src/ast/ast-expression-visitor.h" 10 #include "src/ast/ast-expression-visitor.h"
(...skipping 785 matching lines...) Expand 10 before | Expand all | Expand 10 after
796 info->isolate()->is_tail_call_elimination_enabled()); 796 info->isolate()->is_tail_call_elimination_enabled());
797 set_allow_harmony_do_expressions(FLAG_harmony_do_expressions); 797 set_allow_harmony_do_expressions(FLAG_harmony_do_expressions);
798 set_allow_harmony_for_in(FLAG_harmony_for_in); 798 set_allow_harmony_for_in(FLAG_harmony_for_in);
799 set_allow_harmony_function_name(FLAG_harmony_function_name); 799 set_allow_harmony_function_name(FLAG_harmony_function_name);
800 set_allow_harmony_function_sent(FLAG_harmony_function_sent); 800 set_allow_harmony_function_sent(FLAG_harmony_function_sent);
801 set_allow_harmony_restrictive_declarations( 801 set_allow_harmony_restrictive_declarations(
802 FLAG_harmony_restrictive_declarations); 802 FLAG_harmony_restrictive_declarations);
803 set_allow_harmony_exponentiation_operator( 803 set_allow_harmony_exponentiation_operator(
804 FLAG_harmony_exponentiation_operator); 804 FLAG_harmony_exponentiation_operator);
805 set_allow_harmony_async_await(FLAG_harmony_async_await); 805 set_allow_harmony_async_await(FLAG_harmony_async_await);
806 set_allow_harmony_restrictive_generators(FLAG_harmony_restrictive_generators);
806 for (int feature = 0; feature < v8::Isolate::kUseCounterFeatureCount; 807 for (int feature = 0; feature < v8::Isolate::kUseCounterFeatureCount;
807 ++feature) { 808 ++feature) {
808 use_counts_[feature] = 0; 809 use_counts_[feature] = 0;
809 } 810 }
810 if (info->ast_value_factory() == NULL) { 811 if (info->ast_value_factory() == NULL) {
811 // info takes ownership of AstValueFactory. 812 // info takes ownership of AstValueFactory.
812 info->set_ast_value_factory(new AstValueFactory(zone(), info->hash_seed())); 813 info->set_ast_value_factory(new AstValueFactory(zone(), info->hash_seed()));
813 info->set_ast_value_factory_owned(); 814 info->set_ast_value_factory_owned();
814 ast_value_factory_ = info->ast_value_factory(); 815 ast_value_factory_ = info->ast_value_factory();
815 } 816 }
(...skipping 1148 matching lines...) Expand 10 before | Expand all | Expand 10 after
1964 // Declare the name. 1965 // Declare the name.
1965 Variable::Kind kind = Variable::NORMAL; 1966 Variable::Kind kind = Variable::NORMAL;
1966 if (is_function_declaration) { 1967 if (is_function_declaration) {
1967 kind = Variable::FUNCTION; 1968 kind = Variable::FUNCTION;
1968 } 1969 }
1969 var = declaration_scope->DeclareLocal( 1970 var = declaration_scope->DeclareLocal(
1970 name, mode, declaration->initialization(), kind, kNotAssigned); 1971 name, mode, declaration->initialization(), kind, kNotAssigned);
1971 } else if (IsLexicalVariableMode(mode) || 1972 } else if (IsLexicalVariableMode(mode) ||
1972 IsLexicalVariableMode(var->mode())) { 1973 IsLexicalVariableMode(var->mode())) {
1973 // Allow duplicate function decls for web compat, see bug 4693. 1974 // Allow duplicate function decls for web compat, see bug 4693.
1975 bool duplicate_allowed = false;
1974 if (is_sloppy(language_mode()) && is_function_declaration && 1976 if (is_sloppy(language_mode()) && is_function_declaration &&
1975 var->is_function()) { 1977 var->is_function()) {
1976 DCHECK(IsLexicalVariableMode(mode) && 1978 DCHECK(IsLexicalVariableMode(mode) &&
1977 IsLexicalVariableMode(var->mode())); 1979 IsLexicalVariableMode(var->mode()));
1980 // If the duplication is allowed, then the var will show up
1981 // in the SloppyBlockFunctionMap and the new FunctionKind
1982 // will be a permitted duplicate.
1983 FunctionKind function_kind =
1984 declaration->AsFunctionDeclaration()->fun()->kind();
1985 duplicate_allowed =
1986 scope->DeclarationScope()->sloppy_block_function_map()->Lookup(
1987 const_cast<AstRawString*>(name), name->hash()) != nullptr &&
1988 !IsAsyncFunction(function_kind) &&
1989 !(allow_harmony_restrictive_generators() &&
1990 IsGeneratorFunction(function_kind));
1991 }
1992 if (duplicate_allowed) {
1978 ++use_counts_[v8::Isolate::kSloppyModeBlockScopedFunctionRedefinition]; 1993 ++use_counts_[v8::Isolate::kSloppyModeBlockScopedFunctionRedefinition];
1979 } else { 1994 } else {
1980 // The name was declared in this scope before; check for conflicting 1995 // The name was declared in this scope before; check for conflicting
1981 // re-declarations. We have a conflict if either of the declarations 1996 // re-declarations. We have a conflict if either of the declarations
1982 // is not a var (in script scope, we also have to ignore legacy const 1997 // is not a var (in script scope, we also have to ignore legacy const
1983 // for compatibility). There is similar code in runtime.cc in the 1998 // for compatibility). There is similar code in runtime.cc in the
1984 // Declare functions. The function CheckConflictingVarDeclarations 1999 // Declare functions. The function CheckConflictingVarDeclarations
1985 // checks for var and let bindings from different scopes whereas this 2000 // checks for var and let bindings from different scopes whereas this
1986 // is a check for conflicting declarations within the same scope. This 2001 // is a check for conflicting declarations within the same scope. This
1987 // check also covers the special case 2002 // check also covers the special case
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
2181 // a script scope, or the initial scope of eval or another function. 2196 // a script scope, or the initial scope of eval or another function.
2182 VariableMode mode = 2197 VariableMode mode =
2183 (!scope_->is_declaration_scope() || scope_->is_module_scope()) ? LET 2198 (!scope_->is_declaration_scope() || scope_->is_module_scope()) ? LET
2184 : VAR; 2199 : VAR;
2185 VariableProxy* proxy = NewUnresolved(name, mode); 2200 VariableProxy* proxy = NewUnresolved(name, mode);
2186 Declaration* declaration = 2201 Declaration* declaration =
2187 factory()->NewFunctionDeclaration(proxy, mode, fun, scope_, pos); 2202 factory()->NewFunctionDeclaration(proxy, mode, fun, scope_, pos);
2188 Declare(declaration, DeclarationDescriptor::NORMAL, true, CHECK_OK); 2203 Declare(declaration, DeclarationDescriptor::NORMAL, true, CHECK_OK);
2189 if (names) names->Add(name, zone()); 2204 if (names) names->Add(name, zone());
2190 EmptyStatement* empty = factory()->NewEmptyStatement(RelocInfo::kNoPosition); 2205 EmptyStatement* empty = factory()->NewEmptyStatement(RelocInfo::kNoPosition);
2191 if (is_sloppy(language_mode()) && !scope_->is_declaration_scope()) { 2206 // Async functions don't undergo sloppy mode block scoped hoisting, and don't
2207 // allow duplicates in a block. Both are represented by the
2208 // sloppy_block_function_map. Don't add them to the map for async functions.
2209 // Generators are also supposed to be prohibited; currently doing this behind
2210 // a flag and UseCounting violations to assess web compatibility.
2211 if (is_sloppy(language_mode()) && !scope_->is_declaration_scope() &&
2212 !is_async && !(allow_harmony_restrictive_generators() && is_generator)) {
2192 SloppyBlockFunctionStatement* delegate = 2213 SloppyBlockFunctionStatement* delegate =
2193 factory()->NewSloppyBlockFunctionStatement(empty, scope_); 2214 factory()->NewSloppyBlockFunctionStatement(empty, scope_);
2194 scope_->DeclarationScope()->sloppy_block_function_map()->Declare(name, 2215 scope_->DeclarationScope()->sloppy_block_function_map()->Declare(name,
2195 delegate); 2216 delegate);
2196 return delegate; 2217 return delegate;
2197 } 2218 }
2198 return empty; 2219 return empty;
2199 } 2220 }
2200 2221
2201 2222
(...skipping 4710 matching lines...) Expand 10 before | Expand all | Expand 10 after
6912 try_block, target); 6933 try_block, target);
6913 final_loop = target; 6934 final_loop = target;
6914 } 6935 }
6915 6936
6916 return final_loop; 6937 return final_loop;
6917 } 6938 }
6918 6939
6919 6940
6920 } // namespace internal 6941 } // namespace internal
6921 } // namespace v8 6942 } // namespace v8
OLDNEW
« no previous file with comments | « src/flag-definitions.h ('k') | src/parsing/parser-base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698