| 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 <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "src/api.h" | 9 #include "src/api.h" |
| 10 #include "src/ast/ast.h" | 10 #include "src/ast/ast.h" |
| (...skipping 1970 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1981 Declaration* declaration = | 1981 Declaration* declaration = |
| 1982 factory()->NewVariableDeclaration(proxy, scope(), pos); | 1982 factory()->NewVariableDeclaration(proxy, scope(), pos); |
| 1983 Declare(declaration, DeclarationDescriptor::NORMAL, mode, init, CHECK_OK); | 1983 Declare(declaration, DeclarationDescriptor::NORMAL, mode, init, CHECK_OK); |
| 1984 return declaration; | 1984 return declaration; |
| 1985 } | 1985 } |
| 1986 | 1986 |
| 1987 Variable* Parser::Declare(Declaration* declaration, | 1987 Variable* Parser::Declare(Declaration* declaration, |
| 1988 DeclarationDescriptor::Kind declaration_kind, | 1988 DeclarationDescriptor::Kind declaration_kind, |
| 1989 VariableMode mode, InitializationFlag init, bool* ok, | 1989 VariableMode mode, InitializationFlag init, bool* ok, |
| 1990 Scope* scope) { | 1990 Scope* scope) { |
| 1991 DCHECK(IsDeclaredVariableMode(mode) && mode != CONST_LEGACY); | 1991 DCHECK(IsDeclaredVariableMode(mode)); |
| 1992 | 1992 |
| 1993 VariableProxy* proxy = declaration->proxy(); | 1993 VariableProxy* proxy = declaration->proxy(); |
| 1994 DCHECK(proxy->raw_name() != NULL); | 1994 DCHECK(proxy->raw_name() != NULL); |
| 1995 const AstRawString* name = proxy->raw_name(); | 1995 const AstRawString* name = proxy->raw_name(); |
| 1996 | 1996 |
| 1997 if (scope == nullptr) scope = this->scope(); | 1997 if (scope == nullptr) scope = this->scope(); |
| 1998 if (mode == VAR) scope = scope->GetDeclarationScope(); | 1998 if (mode == VAR) scope = scope->GetDeclarationScope(); |
| 1999 DCHECK(!scope->is_catch_scope()); | 1999 DCHECK(!scope->is_catch_scope()); |
| 2000 DCHECK(!scope->is_with_scope()); | 2000 DCHECK(!scope->is_with_scope()); |
| 2001 DCHECK(scope->is_declaration_scope() || | 2001 DCHECK(scope->is_declaration_scope() || |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2042 const_cast<AstRawString*>(name), name->hash()) != nullptr && | 2042 const_cast<AstRawString*>(name), name->hash()) != nullptr && |
| 2043 !IsAsyncFunction(function_kind) && | 2043 !IsAsyncFunction(function_kind) && |
| 2044 !(allow_harmony_restrictive_generators() && | 2044 !(allow_harmony_restrictive_generators() && |
| 2045 IsGeneratorFunction(function_kind)); | 2045 IsGeneratorFunction(function_kind)); |
| 2046 } | 2046 } |
| 2047 if (duplicate_allowed) { | 2047 if (duplicate_allowed) { |
| 2048 ++use_counts_[v8::Isolate::kSloppyModeBlockScopedFunctionRedefinition]; | 2048 ++use_counts_[v8::Isolate::kSloppyModeBlockScopedFunctionRedefinition]; |
| 2049 } else { | 2049 } else { |
| 2050 // The name was declared in this scope before; check for conflicting | 2050 // The name was declared in this scope before; check for conflicting |
| 2051 // re-declarations. We have a conflict if either of the declarations | 2051 // re-declarations. We have a conflict if either of the declarations |
| 2052 // is not a var (in script scope, we also have to ignore legacy const | 2052 // is not a var. There is similar code in runtime.cc in the |
| 2053 // for compatibility). There is similar code in runtime.cc in the | |
| 2054 // Declare functions. The function CheckConflictingVarDeclarations | 2053 // Declare functions. The function CheckConflictingVarDeclarations |
| 2055 // checks for var and let bindings from different scopes whereas this | 2054 // checks for var and let bindings from different scopes whereas this |
| 2056 // is a check for conflicting declarations within the same scope. This | 2055 // is a check for conflicting declarations within the same scope. This |
| 2057 // check also covers the special case | 2056 // check also covers the special case |
| 2058 // | 2057 // |
| 2059 // function () { let x; { var x; } } | 2058 // function () { let x; { var x; } } |
| 2060 // | 2059 // |
| 2061 // because the var declaration is hoisted to the function scope where | 2060 // because the var declaration is hoisted to the function scope where |
| 2062 // 'x' is already bound. | 2061 // 'x' is already bound. |
| 2063 DCHECK(IsDeclaredVariableMode(var->mode())); | 2062 DCHECK(IsDeclaredVariableMode(var->mode())); |
| (...skipping 5019 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7083 node->Print(Isolate::Current()); | 7082 node->Print(Isolate::Current()); |
| 7084 } | 7083 } |
| 7085 #endif // DEBUG | 7084 #endif // DEBUG |
| 7086 | 7085 |
| 7087 #undef CHECK_OK | 7086 #undef CHECK_OK |
| 7088 #undef CHECK_OK_VOID | 7087 #undef CHECK_OK_VOID |
| 7089 #undef CHECK_FAILED | 7088 #undef CHECK_FAILED |
| 7090 | 7089 |
| 7091 } // namespace internal | 7090 } // namespace internal |
| 7092 } // namespace v8 | 7091 } // namespace v8 |
| OLD | NEW |