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

Side by Side Diff: src/parsing/parser-base.h

Issue 2636543002: PreParser scope analysis: sloppy block funcs. (Closed)
Patch Set: proactive code review Created 3 years, 11 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/parsing/parser.cc ('k') | src/parsing/preparser.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 #ifndef V8_PARSING_PARSER_BASE_H 5 #ifndef V8_PARSING_PARSER_BASE_H
6 #define V8_PARSING_PARSER_BASE_H 6 #define V8_PARSING_PARSER_BASE_H
7 7
8 #include "src/ast/ast.h" 8 #include "src/ast/ast.h"
9 #include "src/ast/scopes.h" 9 #include "src/ast/scopes.h"
10 #include "src/bailout-reason.h" 10 #include "src/bailout-reason.h"
(...skipping 3762 matching lines...) Expand 10 before | Expand all | Expand 10 after
3773 FuncNameInferrer::State fni_state(fni_); 3773 FuncNameInferrer::State fni_state(fni_);
3774 impl()->PushEnclosingName(name); 3774 impl()->PushEnclosingName(name);
3775 FunctionLiteralT function = impl()->ParseFunctionLiteral( 3775 FunctionLiteralT function = impl()->ParseFunctionLiteral(
3776 name, scanner()->location(), name_validity, 3776 name, scanner()->location(), name_validity,
3777 is_generator ? FunctionKind::kGeneratorFunction 3777 is_generator ? FunctionKind::kGeneratorFunction
3778 : is_async ? FunctionKind::kAsyncFunction 3778 : is_async ? FunctionKind::kAsyncFunction
3779 : FunctionKind::kNormalFunction, 3779 : FunctionKind::kNormalFunction,
3780 pos, FunctionLiteral::kDeclaration, language_mode(), 3780 pos, FunctionLiteral::kDeclaration, language_mode(),
3781 CHECK_OK_CUSTOM(NullStatement)); 3781 CHECK_OK_CUSTOM(NullStatement));
3782 3782
3783 return impl()->DeclareFunction(variable_name, function, pos, is_generator, 3783 // In ES6, a function behaves as a lexical binding, except in
3784 is_async, names, ok); 3784 // a script scope, or the initial scope of eval or another function.
3785 VariableMode mode =
3786 (!scope()->is_declaration_scope() || scope()->is_module_scope()) ? LET
3787 : VAR;
3788 // Async functions don't undergo sloppy mode block scoped hoisting, and don't
3789 // allow duplicates in a block. Both are represented by the
3790 // sloppy_block_function_map. Don't add them to the map for async functions.
3791 // Generators are also supposed to be prohibited; currently doing this behind
3792 // a flag and UseCounting violations to assess web compatibility.
3793 bool is_sloppy_block_function =
3794 is_sloppy(language_mode()) && !scope()->is_declaration_scope() &&
3795 !is_async && !(allow_harmony_restrictive_generators() && is_generator);
3796
3797 return impl()->DeclareFunction(variable_name, function, mode, pos,
3798 is_generator, is_async,
3799 is_sloppy_block_function, names, ok);
3785 } 3800 }
3786 3801
3787 template <typename Impl> 3802 template <typename Impl>
3788 typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseClassDeclaration( 3803 typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseClassDeclaration(
3789 ZoneList<const AstRawString*>* names, bool default_export, bool* ok) { 3804 ZoneList<const AstRawString*>* names, bool default_export, bool* ok) {
3790 // ClassDeclaration :: 3805 // ClassDeclaration ::
3791 // 'class' Identifier ('extends' LeftHandExpression)? '{' ClassBody '}' 3806 // 'class' Identifier ('extends' LeftHandExpression)? '{' ClassBody '}'
3792 // 'class' ('extends' LeftHandExpression)? '{' ClassBody '}' 3807 // 'class' ('extends' LeftHandExpression)? '{' ClassBody '}'
3793 // 3808 //
3794 // The anonymous form is allowed iff [default_export] is true. 3809 // The anonymous form is allowed iff [default_export] is true.
(...skipping 1734 matching lines...) Expand 10 before | Expand all | Expand 10 after
5529 has_seen_constructor_ = true; 5544 has_seen_constructor_ = true;
5530 return; 5545 return;
5531 } 5546 }
5532 } 5547 }
5533 5548
5534 5549
5535 } // namespace internal 5550 } // namespace internal
5536 } // namespace v8 5551 } // namespace v8
5537 5552
5538 #endif // V8_PARSING_PARSER_BASE_H 5553 #endif // V8_PARSING_PARSER_BASE_H
OLDNEW
« no previous file with comments | « src/parsing/parser.cc ('k') | src/parsing/preparser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698