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

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

Issue 1895123002: Prevent un-parsed LiteralFunction reaching the compiler. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix test. (eager_compile_hint used function_state_ of parent function.) Created 4 years, 8 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 | « no previous file | 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 3975 matching lines...) Expand 10 before | Expand all | Expand 10 after
3986 function_name = ast_value_factory()->empty_string(); 3986 function_name = ast_value_factory()->empty_string();
3987 } 3987 }
3988 3988
3989 Scope* scope = NewScope(scope_, FUNCTION_SCOPE, kind); 3989 Scope* scope = NewScope(scope_, FUNCTION_SCOPE, kind);
3990 SetLanguageMode(scope, language_mode); 3990 SetLanguageMode(scope, language_mode);
3991 ZoneList<Statement*>* body = NULL; 3991 ZoneList<Statement*>* body = NULL;
3992 int arity = -1; 3992 int arity = -1;
3993 int materialized_literal_count = -1; 3993 int materialized_literal_count = -1;
3994 int expected_property_count = -1; 3994 int expected_property_count = -1;
3995 DuplicateFinder duplicate_finder(scanner()->unicode_cache()); 3995 DuplicateFinder duplicate_finder(scanner()->unicode_cache());
3996 FunctionLiteral::EagerCompileHint eager_compile_hint =
3997 parenthesized_function_ ? FunctionLiteral::kShouldEagerCompile
3998 : FunctionLiteral::kShouldLazyCompile;
3999 bool should_be_used_once_hint = false; 3996 bool should_be_used_once_hint = false;
4000 bool has_duplicate_parameters; 3997 bool has_duplicate_parameters;
3998 FunctionLiteral::EagerCompileHint eager_compile_hint;
3999
4001 // Parse function. 4000 // Parse function.
4002 { 4001 {
4003 AstNodeFactory function_factory(ast_value_factory()); 4002 AstNodeFactory function_factory(ast_value_factory());
4004 FunctionState function_state(&function_state_, &scope_, scope, kind, 4003 FunctionState function_state(&function_state_, &scope_, scope, kind,
4005 &function_factory); 4004 &function_factory);
4006 scope_->SetScopeName(function_name); 4005 scope_->SetScopeName(function_name);
4007 ExpressionClassifier formals_classifier(this, &duplicate_finder); 4006 ExpressionClassifier formals_classifier(this, &duplicate_finder);
4008 4007
4008 eager_compile_hint = function_state_->this_function_is_parenthesized()
4009 ? FunctionLiteral::kShouldEagerCompile
4010 : FunctionLiteral::kShouldLazyCompile;
4011
4009 if (is_generator) { 4012 if (is_generator) {
4010 // For generators, allocating variables in contexts is currently a win 4013 // For generators, allocating variables in contexts is currently a win
4011 // because it minimizes the work needed to suspend and resume an 4014 // because it minimizes the work needed to suspend and resume an
4012 // activation. The machine code produced for generators (by full-codegen) 4015 // activation. The machine code produced for generators (by full-codegen)
4013 // relies on this forced context allocation, but not in an essential way. 4016 // relies on this forced context allocation, but not in an essential way.
4014 scope_->ForceContextAllocation(); 4017 scope_->ForceContextAllocation();
4015 4018
4016 // Calling a generator returns a generator object. That object is stored 4019 // Calling a generator returns a generator object. That object is stored
4017 // in a temporary variable, a definition that is used by "yield" 4020 // in a temporary variable, a definition that is used by "yield"
4018 // expressions. This also marks the FunctionState as a generator. 4021 // expressions. This also marks the FunctionState as a generator.
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
4067 // Now foo will be parsed eagerly and compiled eagerly (optimization: assume 4070 // Now foo will be parsed eagerly and compiled eagerly (optimization: assume
4068 // parenthesis before the function means that it will be called 4071 // parenthesis before the function means that it will be called
4069 // immediately). The inner function *must* be parsed eagerly to resolve the 4072 // immediately). The inner function *must* be parsed eagerly to resolve the
4070 // possible reference to the variable in foo's scope. However, it's possible 4073 // possible reference to the variable in foo's scope. However, it's possible
4071 // that it will be compiled lazily. 4074 // that it will be compiled lazily.
4072 4075
4073 // To make this additional case work, both Parser and PreParser implement a 4076 // To make this additional case work, both Parser and PreParser implement a
4074 // logic where only top-level functions will be parsed lazily. 4077 // logic where only top-level functions will be parsed lazily.
4075 bool is_lazily_parsed = mode() == PARSE_LAZILY && 4078 bool is_lazily_parsed = mode() == PARSE_LAZILY &&
4076 scope_->AllowsLazyParsing() && 4079 scope_->AllowsLazyParsing() &&
4077 !parenthesized_function_; 4080 !function_state_->this_function_is_parenthesized();
4078 parenthesized_function_ = false; // The bit was set for this function only.
4079 4081
4080 // Eager or lazy parse? 4082 // Eager or lazy parse?
4081 // If is_lazily_parsed, we'll parse lazy. If we can set a bookmark, we'll 4083 // If is_lazily_parsed, we'll parse lazy. If we can set a bookmark, we'll
4082 // pass it to SkipLazyFunctionBody, which may use it to abort lazy 4084 // pass it to SkipLazyFunctionBody, which may use it to abort lazy
4083 // parsing if it suspect that wasn't a good idea. If so, or if we didn't 4085 // parsing if it suspect that wasn't a good idea. If so, or if we didn't
4084 // try to lazy parse in the first place, we'll have to parse eagerly. 4086 // try to lazy parse in the first place, we'll have to parse eagerly.
4085 Scanner::BookmarkScope bookmark(scanner()); 4087 Scanner::BookmarkScope bookmark(scanner());
4086 if (is_lazily_parsed) { 4088 if (is_lazily_parsed) {
4087 Scanner::BookmarkScope* maybe_bookmark = 4089 Scanner::BookmarkScope* maybe_bookmark =
4088 bookmark.Set() ? &bookmark : nullptr; 4090 bookmark.Set() ? &bookmark : nullptr;
(...skipping 2693 matching lines...) Expand 10 before | Expand all | Expand 10 after
6782 try_block, target); 6784 try_block, target);
6783 final_loop = target; 6785 final_loop = target;
6784 } 6786 }
6785 6787
6786 return final_loop; 6788 return final_loop;
6787 } 6789 }
6788 6790
6789 6791
6790 } // namespace internal 6792 } // namespace internal
6791 } // namespace v8 6793 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | src/parsing/parser-base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698