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

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

Issue 1621663003: Version 4.9.385.11 (cherry-pick) (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@4.9
Patch Set: Created 4 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 | « include/v8-version.h ('k') | test/mjsunit/regress/regress-4693.js » ('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-visitor.h" 9 #include "src/ast/ast-expression-visitor.h"
10 #include "src/ast/ast-literal-reindexer.h" 10 #include "src/ast/ast-literal-reindexer.h"
(...skipping 1877 matching lines...) Expand 10 before | Expand all | Expand 10 after
1888 } 1888 }
1889 1889
1890 1890
1891 Variable* Parser::Declare(Declaration* declaration, 1891 Variable* Parser::Declare(Declaration* declaration,
1892 DeclarationDescriptor::Kind declaration_kind, 1892 DeclarationDescriptor::Kind declaration_kind,
1893 bool resolve, bool* ok, Scope* scope) { 1893 bool resolve, bool* ok, Scope* scope) {
1894 VariableProxy* proxy = declaration->proxy(); 1894 VariableProxy* proxy = declaration->proxy();
1895 DCHECK(proxy->raw_name() != NULL); 1895 DCHECK(proxy->raw_name() != NULL);
1896 const AstRawString* name = proxy->raw_name(); 1896 const AstRawString* name = proxy->raw_name();
1897 VariableMode mode = declaration->mode(); 1897 VariableMode mode = declaration->mode();
1898 bool is_function_declaration = declaration->IsFunctionDeclaration();
1898 if (scope == nullptr) scope = scope_; 1899 if (scope == nullptr) scope = scope_;
1899 Scope* declaration_scope = 1900 Scope* declaration_scope =
1900 IsLexicalVariableMode(mode) ? scope : scope->DeclarationScope(); 1901 IsLexicalVariableMode(mode) ? scope : scope->DeclarationScope();
1901 Variable* var = NULL; 1902 Variable* var = NULL;
1902 1903
1903 // If a suitable scope exists, then we can statically declare this 1904 // If a suitable scope exists, then we can statically declare this
1904 // variable and also set its mode. In any case, a Declaration node 1905 // variable and also set its mode. In any case, a Declaration node
1905 // will be added to the scope so that the declaration can be added 1906 // will be added to the scope so that the declaration can be added
1906 // to the corresponding activation frame at runtime if necessary. 1907 // to the corresponding activation frame at runtime if necessary.
1907 // For instance, var declarations inside a sloppy eval scope need 1908 // For instance, var declarations inside a sloppy eval scope need
1908 // to be added to the calling function context. Similarly, strict 1909 // to be added to the calling function context. Similarly, strict
1909 // mode eval scope and lexical eval bindings do not leak variable 1910 // mode eval scope and lexical eval bindings do not leak variable
1910 // declarations to the caller's scope so we declare all locals, too. 1911 // declarations to the caller's scope so we declare all locals, too.
1911 if (declaration_scope->is_function_scope() || 1912 if (declaration_scope->is_function_scope() ||
1912 declaration_scope->is_block_scope() || 1913 declaration_scope->is_block_scope() ||
1913 declaration_scope->is_module_scope() || 1914 declaration_scope->is_module_scope() ||
1914 declaration_scope->is_script_scope() || 1915 declaration_scope->is_script_scope() ||
1915 (declaration_scope->is_eval_scope() && 1916 (declaration_scope->is_eval_scope() &&
1916 (is_strict(declaration_scope->language_mode()) || 1917 (is_strict(declaration_scope->language_mode()) ||
1917 IsLexicalVariableMode(mode)))) { 1918 IsLexicalVariableMode(mode)))) {
1918 // Declare the variable in the declaration scope. 1919 // Declare the variable in the declaration scope.
1919 var = declaration_scope->LookupLocal(name); 1920 var = declaration_scope->LookupLocal(name);
1920 if (var == NULL) { 1921 if (var == NULL) {
1921 // Declare the name. 1922 // Declare the name.
1922 Variable::Kind kind = Variable::NORMAL; 1923 Variable::Kind kind = Variable::NORMAL;
1923 int declaration_group_start = -1; 1924 int declaration_group_start = -1;
1924 if (declaration->IsFunctionDeclaration()) { 1925 if (is_function_declaration) {
1925 kind = Variable::FUNCTION; 1926 kind = Variable::FUNCTION;
1926 } else if (declaration->IsVariableDeclaration() && 1927 } else if (declaration->IsVariableDeclaration() &&
1927 declaration->AsVariableDeclaration()->is_class_declaration()) { 1928 declaration->AsVariableDeclaration()->is_class_declaration()) {
1928 kind = Variable::CLASS; 1929 kind = Variable::CLASS;
1929 declaration_group_start = 1930 declaration_group_start =
1930 declaration->AsVariableDeclaration()->declaration_group_start(); 1931 declaration->AsVariableDeclaration()->declaration_group_start();
1931 } 1932 }
1932 var = declaration_scope->DeclareLocal( 1933 var = declaration_scope->DeclareLocal(
1933 name, mode, declaration->initialization(), kind, kNotAssigned, 1934 name, mode, declaration->initialization(), kind, kNotAssigned,
1934 declaration_group_start); 1935 declaration_group_start);
1935 } else if (IsLexicalVariableMode(mode) || 1936 } else if (((IsLexicalVariableMode(mode) ||
1936 IsLexicalVariableMode(var->mode()) || 1937 IsLexicalVariableMode(var->mode())) &&
1938 // Allow duplicate function decls for web compat, see bug 4693.
1939 (is_strict(language_mode()) || !is_function_declaration ||
1940 !var->is_function())) ||
1937 ((mode == CONST_LEGACY || var->mode() == CONST_LEGACY) && 1941 ((mode == CONST_LEGACY || var->mode() == CONST_LEGACY) &&
1938 !declaration_scope->is_script_scope())) { 1942 !declaration_scope->is_script_scope())) {
1939 // The name was declared in this scope before; check for conflicting 1943 // The name was declared in this scope before; check for conflicting
1940 // re-declarations. We have a conflict if either of the declarations is 1944 // re-declarations. We have a conflict if either of the declarations is
1941 // not a var (in script scope, we also have to ignore legacy const for 1945 // not a var (in script scope, we also have to ignore legacy const for
1942 // compatibility). There is similar code in runtime.cc in the Declare 1946 // compatibility). There is similar code in runtime.cc in the Declare
1943 // functions. The function CheckConflictingVarDeclarations checks for 1947 // functions. The function CheckConflictingVarDeclarations checks for
1944 // var and let bindings from different scopes whereas this is a check for 1948 // var and let bindings from different scopes whereas this is a check for
1945 // conflicting declarations within the same scope. This check also covers 1949 // conflicting declarations within the same scope. This check also covers
1946 // the special case 1950 // the special case
(...skipping 3588 matching lines...) Expand 10 before | Expand all | Expand 10 after
5535 auto class_literal = value->AsClassLiteral(); 5539 auto class_literal = value->AsClassLiteral();
5536 if (class_literal->raw_name() == nullptr) { 5540 if (class_literal->raw_name() == nullptr) {
5537 class_literal->set_raw_name(name); 5541 class_literal->set_raw_name(name);
5538 } 5542 }
5539 } 5543 }
5540 } 5544 }
5541 5545
5542 5546
5543 } // namespace internal 5547 } // namespace internal
5544 } // namespace v8 5548 } // namespace v8
OLDNEW
« no previous file with comments | « include/v8-version.h ('k') | test/mjsunit/regress/regress-4693.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698