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

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

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.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 <memory> 7 #include <memory>
8 8
9 #include "src/api.h" 9 #include "src/api.h"
10 #include "src/ast/ast-expression-rewriter.h" 10 #include "src/ast/ast-expression-rewriter.h"
(...skipping 1454 matching lines...) Expand 10 before | Expand all | Expand 10 after
1465 void Parser::DeclareAndInitializeVariables( 1465 void Parser::DeclareAndInitializeVariables(
1466 Block* block, const DeclarationDescriptor* declaration_descriptor, 1466 Block* block, const DeclarationDescriptor* declaration_descriptor,
1467 const DeclarationParsingResult::Declaration* declaration, 1467 const DeclarationParsingResult::Declaration* declaration,
1468 ZoneList<const AstRawString*>* names, bool* ok) { 1468 ZoneList<const AstRawString*>* names, bool* ok) {
1469 DCHECK_NOT_NULL(block); 1469 DCHECK_NOT_NULL(block);
1470 PatternRewriter::DeclareAndInitializeVariables( 1470 PatternRewriter::DeclareAndInitializeVariables(
1471 this, block, declaration_descriptor, declaration, names, ok); 1471 this, block, declaration_descriptor, declaration, names, ok);
1472 } 1472 }
1473 1473
1474 Statement* Parser::DeclareFunction(const AstRawString* variable_name, 1474 Statement* Parser::DeclareFunction(const AstRawString* variable_name,
1475 FunctionLiteral* function, int pos, 1475 FunctionLiteral* function, VariableMode mode,
1476 bool is_generator, bool is_async, 1476 int pos, bool is_generator, bool is_async,
1477 bool is_sloppy_block_function,
1477 ZoneList<const AstRawString*>* names, 1478 ZoneList<const AstRawString*>* names,
1478 bool* ok) { 1479 bool* ok) {
1479 // In ES6, a function behaves as a lexical binding, except in
1480 // a script scope, or the initial scope of eval or another function.
1481 VariableMode mode =
1482 (!scope()->is_declaration_scope() || scope()->is_module_scope()) ? LET
1483 : VAR;
1484 VariableProxy* proxy = 1480 VariableProxy* proxy =
1485 factory()->NewVariableProxy(variable_name, NORMAL_VARIABLE); 1481 factory()->NewVariableProxy(variable_name, NORMAL_VARIABLE);
1486 Declaration* declaration = 1482 Declaration* declaration =
1487 factory()->NewFunctionDeclaration(proxy, function, scope(), pos); 1483 factory()->NewFunctionDeclaration(proxy, function, scope(), pos);
1488 Declare(declaration, DeclarationDescriptor::NORMAL, mode, kCreatedInitialized, 1484 Declare(declaration, DeclarationDescriptor::NORMAL, mode, kCreatedInitialized,
1489 CHECK_OK); 1485 CHECK_OK);
1490 if (names) names->Add(variable_name, zone()); 1486 if (names) names->Add(variable_name, zone());
1491 // Async functions don't undergo sloppy mode block scoped hoisting, and don't 1487 if (is_sloppy_block_function) {
1492 // allow duplicates in a block. Both are represented by the 1488 SloppyBlockFunctionStatement* statement =
1493 // sloppy_block_function_map. Don't add them to the map for async functions. 1489 factory()->NewSloppyBlockFunctionStatement();
1494 // Generators are also supposed to be prohibited; currently doing this behind
1495 // a flag and UseCounting violations to assess web compatibility.
1496 if (is_sloppy(language_mode()) && !scope()->is_declaration_scope() &&
1497 !is_async && !(allow_harmony_restrictive_generators() && is_generator)) {
1498 SloppyBlockFunctionStatement* delegate =
1499 factory()->NewSloppyBlockFunctionStatement(scope());
1500 DeclarationScope* target_scope = GetDeclarationScope(); 1490 DeclarationScope* target_scope = GetDeclarationScope();
1501 target_scope->DeclareSloppyBlockFunction(variable_name, delegate); 1491 target_scope->DeclareSloppyBlockFunction(variable_name, scope(), statement);
1502 return delegate; 1492 return statement;
1503 } 1493 }
1504 return factory()->NewEmptyStatement(kNoSourcePosition); 1494 return factory()->NewEmptyStatement(kNoSourcePosition);
1505 } 1495 }
1506 1496
1507 Statement* Parser::DeclareClass(const AstRawString* variable_name, 1497 Statement* Parser::DeclareClass(const AstRawString* variable_name,
1508 Expression* value, 1498 Expression* value,
1509 ZoneList<const AstRawString*>* names, 1499 ZoneList<const AstRawString*>* names,
1510 int class_token_pos, int end_pos, bool* ok) { 1500 int class_token_pos, int end_pos, bool* ok) {
1511 Declaration* decl = 1501 Declaration* decl =
1512 DeclareVariable(variable_name, LET, class_token_pos, CHECK_OK); 1502 DeclareVariable(variable_name, LET, class_token_pos, CHECK_OK);
(...skipping 3617 matching lines...) Expand 10 before | Expand all | Expand 10 after
5130 5120
5131 return final_loop; 5121 return final_loop;
5132 } 5122 }
5133 5123
5134 #undef CHECK_OK 5124 #undef CHECK_OK
5135 #undef CHECK_OK_VOID 5125 #undef CHECK_OK_VOID
5136 #undef CHECK_FAILED 5126 #undef CHECK_FAILED
5137 5127
5138 } // namespace internal 5128 } // namespace internal
5139 } // namespace v8 5129 } // namespace v8
OLDNEW
« no previous file with comments | « src/parsing/parser.h ('k') | src/parsing/parser-base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698