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

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

Issue 1819123002: Remove support for legacy const, part 1 (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Rebased, deleted one more file Created 4 years, 9 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/interpreter/bytecode-generator.cc ('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 "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 770 matching lines...) Expand 10 before | Expand all | Expand 10 after
781 // Even though we were passed ParseInfo, we should not store it in 781 // Even though we were passed ParseInfo, we should not store it in
782 // Parser - this makes sure that Isolate is not accidentally accessed via 782 // Parser - this makes sure that Isolate is not accidentally accessed via
783 // ParseInfo during background parsing. 783 // ParseInfo during background parsing.
784 DCHECK(!info->script().is_null() || info->source_stream() != NULL); 784 DCHECK(!info->script().is_null() || info->source_stream() != NULL);
785 set_allow_lazy(info->allow_lazy_parsing()); 785 set_allow_lazy(info->allow_lazy_parsing());
786 set_allow_natives(FLAG_allow_natives_syntax || info->is_native()); 786 set_allow_natives(FLAG_allow_natives_syntax || info->is_native());
787 set_allow_tailcalls(FLAG_harmony_tailcalls && !info->is_native()); 787 set_allow_tailcalls(FLAG_harmony_tailcalls && !info->is_native());
788 set_allow_harmony_sloppy(FLAG_harmony_sloppy); 788 set_allow_harmony_sloppy(FLAG_harmony_sloppy);
789 set_allow_harmony_sloppy_function(FLAG_harmony_sloppy_function); 789 set_allow_harmony_sloppy_function(FLAG_harmony_sloppy_function);
790 set_allow_harmony_sloppy_let(FLAG_harmony_sloppy_let); 790 set_allow_harmony_sloppy_let(FLAG_harmony_sloppy_let);
791 set_allow_legacy_const(FLAG_legacy_const);
792 set_allow_harmony_do_expressions(FLAG_harmony_do_expressions); 791 set_allow_harmony_do_expressions(FLAG_harmony_do_expressions);
793 set_allow_harmony_function_name(FLAG_harmony_function_name); 792 set_allow_harmony_function_name(FLAG_harmony_function_name);
794 set_allow_harmony_function_sent(FLAG_harmony_function_sent); 793 set_allow_harmony_function_sent(FLAG_harmony_function_sent);
795 set_allow_harmony_restrictive_declarations( 794 set_allow_harmony_restrictive_declarations(
796 FLAG_harmony_restrictive_declarations); 795 FLAG_harmony_restrictive_declarations);
797 set_allow_harmony_exponentiation_operator( 796 set_allow_harmony_exponentiation_operator(
798 FLAG_harmony_exponentiation_operator); 797 FLAG_harmony_exponentiation_operator);
799 for (int feature = 0; feature < v8::Isolate::kUseCounterFeatureCount; 798 for (int feature = 0; feature < v8::Isolate::kUseCounterFeatureCount;
800 ++feature) { 799 ++feature) {
801 use_counts_[feature] = 0; 800 use_counts_[feature] = 0;
(...skipping 1017 matching lines...) Expand 10 before | Expand all | Expand 10 after
1819 : MessageTemplate::kSloppyFunction); 1818 : MessageTemplate::kSloppyFunction);
1820 *ok = false; 1819 *ok = false;
1821 return nullptr; 1820 return nullptr;
1822 1821
1823 case Token::DEBUGGER: 1822 case Token::DEBUGGER:
1824 return ParseDebuggerStatement(ok); 1823 return ParseDebuggerStatement(ok);
1825 1824
1826 case Token::VAR: 1825 case Token::VAR:
1827 return ParseVariableStatement(kStatement, NULL, ok); 1826 return ParseVariableStatement(kStatement, NULL, ok);
1828 1827
1829 case Token::CONST:
1830 // In ES6 CONST is not allowed as a Statement, only as a
1831 // LexicalDeclaration, however we continue to allow it in sloppy mode for
1832 // backwards compatibility.
1833 if (is_sloppy(language_mode()) && allow_legacy_const()) {
1834 return ParseVariableStatement(kStatement, NULL, ok);
1835 }
1836
1837 // Fall through.
1838 default: 1828 default:
1839 return ParseExpressionOrLabelledStatement(labels, ok); 1829 return ParseExpressionOrLabelledStatement(labels, ok);
1840 } 1830 }
1841 } 1831 }
1842 1832
1843 Statement* Parser::ParseStatementAsUnlabelled( 1833 Statement* Parser::ParseStatementAsUnlabelled(
1844 ZoneList<const AstRawString*>* labels, bool* ok) { 1834 ZoneList<const AstRawString*>* labels, bool* ok) {
1845 switch (peek()) { 1835 switch (peek()) {
1846 case Token::CONTINUE: 1836 case Token::CONTINUE:
1847 return ParseContinueStatement(ok); 1837 return ParseContinueStatement(ok);
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
1911 // Declare the variable in the declaration scope. 1901 // Declare the variable in the declaration scope.
1912 var = declaration_scope->LookupLocal(name); 1902 var = declaration_scope->LookupLocal(name);
1913 if (var == NULL) { 1903 if (var == NULL) {
1914 // Declare the name. 1904 // Declare the name.
1915 Variable::Kind kind = Variable::NORMAL; 1905 Variable::Kind kind = Variable::NORMAL;
1916 if (is_function_declaration) { 1906 if (is_function_declaration) {
1917 kind = Variable::FUNCTION; 1907 kind = Variable::FUNCTION;
1918 } 1908 }
1919 var = declaration_scope->DeclareLocal( 1909 var = declaration_scope->DeclareLocal(
1920 name, mode, declaration->initialization(), kind, kNotAssigned); 1910 name, mode, declaration->initialization(), kind, kNotAssigned);
1921 } else if ((mode == CONST_LEGACY || var->mode() == CONST_LEGACY) &&
1922 !declaration_scope->is_script_scope()) {
1923 // Duplicate legacy const definitions throw at runtime.
1924 DCHECK(is_sloppy(language_mode()));
1925 Expression* expression = NewThrowSyntaxError(
1926 MessageTemplate::kVarRedeclaration, name, declaration->position());
1927 declaration_scope->SetIllegalRedeclaration(expression);
1928 } else if ((IsLexicalVariableMode(mode) || 1911 } else if ((IsLexicalVariableMode(mode) ||
1929 IsLexicalVariableMode(var->mode())) && 1912 IsLexicalVariableMode(var->mode())) &&
1930 // Lexical bindings may appear for some parameters in sloppy 1913 // Lexical bindings may appear for some parameters in sloppy
1931 // mode even with --harmony-sloppy off. 1914 // mode even with --harmony-sloppy off.
1932 (is_strict(language_mode()) || allow_harmony_sloppy())) { 1915 (is_strict(language_mode()) || allow_harmony_sloppy())) {
1933 // Allow duplicate function decls for web compat, see bug 4693. 1916 // Allow duplicate function decls for web compat, see bug 4693.
1934 if (is_sloppy(language_mode()) && is_function_declaration && 1917 if (is_sloppy(language_mode()) && is_function_declaration &&
1935 var->is_function()) { 1918 var->is_function()) {
1936 DCHECK(IsLexicalVariableMode(mode) && 1919 DCHECK(IsLexicalVariableMode(mode) &&
1937 IsLexicalVariableMode(var->mode())); 1920 IsLexicalVariableMode(var->mode()));
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after
2290 Block* init_block = nullptr; 2273 Block* init_block = nullptr;
2291 if (var_context != kForStatement) { 2274 if (var_context != kForStatement) {
2292 init_block = factory()->NewBlock( 2275 init_block = factory()->NewBlock(
2293 NULL, 1, true, parsing_result->descriptor.declaration_pos); 2276 NULL, 1, true, parsing_result->descriptor.declaration_pos);
2294 } 2277 }
2295 2278
2296 if (peek() == Token::VAR) { 2279 if (peek() == Token::VAR) {
2297 Consume(Token::VAR); 2280 Consume(Token::VAR);
2298 } else if (peek() == Token::CONST && allow_const()) { 2281 } else if (peek() == Token::CONST && allow_const()) {
2299 Consume(Token::CONST); 2282 Consume(Token::CONST);
2300 if (is_sloppy(language_mode()) && allow_legacy_const()) { 2283 DCHECK(is_strict(language_mode()) || allow_harmony_sloppy());
2301 parsing_result->descriptor.mode = CONST_LEGACY; 2284 DCHECK(var_context != kStatement);
2302 ++use_counts_[v8::Isolate::kLegacyConst]; 2285 parsing_result->descriptor.mode = CONST;
2303 } else {
2304 DCHECK(is_strict(language_mode()) || allow_harmony_sloppy());
2305 DCHECK(var_context != kStatement);
2306 parsing_result->descriptor.mode = CONST;
2307 }
2308 } else if (peek() == Token::LET && allow_let()) { 2286 } else if (peek() == Token::LET && allow_let()) {
2309 Consume(Token::LET); 2287 Consume(Token::LET);
2310 DCHECK(var_context != kStatement); 2288 DCHECK(var_context != kStatement);
2311 parsing_result->descriptor.mode = LET; 2289 parsing_result->descriptor.mode = LET;
2312 } else { 2290 } else {
2313 UNREACHABLE(); // by current callers 2291 UNREACHABLE(); // by current callers
2314 } 2292 }
2315 2293
2316 parsing_result->descriptor.scope = scope_; 2294 parsing_result->descriptor.scope = scope_;
2317 parsing_result->descriptor.hoist_scope = nullptr; 2295 parsing_result->descriptor.hoist_scope = nullptr;
(...skipping 2361 matching lines...) Expand 10 before | Expand all | Expand 10 after
4679 TRACE_EVENT0("v8", "V8.PreParse"); 4657 TRACE_EVENT0("v8", "V8.PreParse");
4680 4658
4681 DCHECK_EQ(Token::LBRACE, scanner()->current_token()); 4659 DCHECK_EQ(Token::LBRACE, scanner()->current_token());
4682 4660
4683 if (reusable_preparser_ == NULL) { 4661 if (reusable_preparser_ == NULL) {
4684 reusable_preparser_ = new PreParser(zone(), &scanner_, ast_value_factory(), 4662 reusable_preparser_ = new PreParser(zone(), &scanner_, ast_value_factory(),
4685 NULL, stack_limit_); 4663 NULL, stack_limit_);
4686 reusable_preparser_->set_allow_lazy(true); 4664 reusable_preparser_->set_allow_lazy(true);
4687 #define SET_ALLOW(name) reusable_preparser_->set_allow_##name(allow_##name()); 4665 #define SET_ALLOW(name) reusable_preparser_->set_allow_##name(allow_##name());
4688 SET_ALLOW(natives); 4666 SET_ALLOW(natives);
4689 SET_ALLOW(legacy_const);
4690 SET_ALLOW(harmony_sloppy); 4667 SET_ALLOW(harmony_sloppy);
4691 SET_ALLOW(harmony_sloppy_function); 4668 SET_ALLOW(harmony_sloppy_function);
4692 SET_ALLOW(harmony_sloppy_let); 4669 SET_ALLOW(harmony_sloppy_let);
4693 SET_ALLOW(harmony_do_expressions); 4670 SET_ALLOW(harmony_do_expressions);
4694 SET_ALLOW(harmony_function_name); 4671 SET_ALLOW(harmony_function_name);
4695 SET_ALLOW(harmony_function_sent); 4672 SET_ALLOW(harmony_function_sent);
4696 SET_ALLOW(harmony_exponentiation_operator); 4673 SET_ALLOW(harmony_exponentiation_operator);
4697 SET_ALLOW(harmony_restrictive_declarations); 4674 SET_ALLOW(harmony_restrictive_declarations);
4698 #undef SET_ALLOW 4675 #undef SET_ALLOW
4699 } 4676 }
(...skipping 2178 matching lines...) Expand 10 before | Expand all | Expand 10 after
6878 try_block, target); 6855 try_block, target);
6879 final_loop = target; 6856 final_loop = target;
6880 } 6857 }
6881 6858
6882 return final_loop; 6859 return final_loop;
6883 } 6860 }
6884 6861
6885 6862
6886 } // namespace internal 6863 } // namespace internal
6887 } // namespace v8 6864 } // namespace v8
OLDNEW
« no previous file with comments | « src/interpreter/bytecode-generator.cc ('k') | src/parsing/parser-base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698