| OLD | NEW |
| 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 2074 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2085 : kFunctionNameValidityUnknown, | 2085 : kFunctionNameValidityUnknown, |
| 2086 is_generator ? FunctionKind::kGeneratorFunction | 2086 is_generator ? FunctionKind::kGeneratorFunction |
| 2087 : FunctionKind::kNormalFunction, | 2087 : FunctionKind::kNormalFunction, |
| 2088 pos, FunctionLiteral::kDeclaration, language_mode(), CHECK_OK); | 2088 pos, FunctionLiteral::kDeclaration, language_mode(), CHECK_OK); |
| 2089 | 2089 |
| 2090 // Even if we're not at the top-level of the global or a function | 2090 // Even if we're not at the top-level of the global or a function |
| 2091 // scope, we treat it as such and introduce the function with its | 2091 // scope, we treat it as such and introduce the function with its |
| 2092 // initial value upon entering the corresponding scope. | 2092 // initial value upon entering the corresponding scope. |
| 2093 // In ES6, a function behaves as a lexical binding, except in | 2093 // In ES6, a function behaves as a lexical binding, except in |
| 2094 // a script scope, or the initial scope of eval or another function. | 2094 // a script scope, or the initial scope of eval or another function. |
| 2095 VariableMode mode = !scope_->is_declaration_scope() ? LET : VAR; | 2095 VariableMode mode = |
| 2096 (!scope_->is_declaration_scope() || scope_->is_module_scope()) ? LET |
| 2097 : VAR; |
| 2096 VariableProxy* proxy = NewUnresolved(name, mode); | 2098 VariableProxy* proxy = NewUnresolved(name, mode); |
| 2097 Declaration* declaration = | 2099 Declaration* declaration = |
| 2098 factory()->NewFunctionDeclaration(proxy, mode, fun, scope_, pos); | 2100 factory()->NewFunctionDeclaration(proxy, mode, fun, scope_, pos); |
| 2099 Declare(declaration, DeclarationDescriptor::NORMAL, true, CHECK_OK); | 2101 Declare(declaration, DeclarationDescriptor::NORMAL, true, CHECK_OK); |
| 2100 if (names) names->Add(name, zone()); | 2102 if (names) names->Add(name, zone()); |
| 2101 EmptyStatement* empty = factory()->NewEmptyStatement(RelocInfo::kNoPosition); | 2103 EmptyStatement* empty = factory()->NewEmptyStatement(RelocInfo::kNoPosition); |
| 2102 if (is_sloppy(language_mode()) && !scope_->is_declaration_scope()) { | 2104 if (is_sloppy(language_mode()) && !scope_->is_declaration_scope()) { |
| 2103 SloppyBlockFunctionStatement* delegate = | 2105 SloppyBlockFunctionStatement* delegate = |
| 2104 factory()->NewSloppyBlockFunctionStatement(empty, scope_); | 2106 factory()->NewSloppyBlockFunctionStatement(empty, scope_); |
| 2105 scope_->DeclarationScope()->sloppy_block_function_map()->Declare(name, | 2107 scope_->DeclarationScope()->sloppy_block_function_map()->Declare(name, |
| (...skipping 4681 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6787 try_block, target); | 6789 try_block, target); |
| 6788 final_loop = target; | 6790 final_loop = target; |
| 6789 } | 6791 } |
| 6790 | 6792 |
| 6791 return final_loop; | 6793 return final_loop; |
| 6792 } | 6794 } |
| 6793 | 6795 |
| 6794 | 6796 |
| 6795 } // namespace internal | 6797 } // namespace internal |
| 6796 } // namespace v8 | 6798 } // namespace v8 |
| OLD | NEW |