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

Unified Diff: src/parser.cc

Issue 6311005: Don't lazily compile functions that are immediately receded by '('. (Closed)
Patch Set: Created 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/parser.h ('k') | src/preparser.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/parser.cc
diff --git a/src/parser.cc b/src/parser.cc
index 5ea1c5e083ac44a15ea4ac100f1f6848d9d4fffd..3730a4577cf6f1e70440637b575f8547d96892a0 100644
--- a/src/parser.cc
+++ b/src/parser.cc
@@ -600,7 +600,8 @@ Parser::Parser(Handle<Script> script,
extension_(extension),
pre_data_(pre_data),
fni_(NULL),
- stack_overflow_(false) {
+ stack_overflow_(false),
+ parenthesized_function_(false) {
AstNode::ResetIds();
}
@@ -2482,9 +2483,13 @@ Expression* Parser::ParseLeftHandSideExpression(bool* ok) {
// The calls that need special treatment are the
// direct (i.e. not aliased) eval calls. These calls are all of the
// form eval(...) with no explicit receiver object where eval is not
- // declared in the current scope chain. These calls are marked as
- // potentially direct eval calls. Whether they are actually direct calls
- // to eval is determined at run time.
+ // declared in the current scope chain.
+ // These calls are marked as potentially direct eval calls. Whether
+ // they are actually direct calls to eval is determined at run time.
+ // TODO(994): In ES5, it doesn't matter if the "eval" var is declared
+ // in the local scope chain. It only matters that it's called "eval",
+ // is called without a receiver and it refers to the original eval
+ // function.
VariableProxy* callee = result->AsVariableProxy();
if (callee != NULL && callee->IsVariable(Factory::eval_symbol())) {
Handle<String> name = callee->name();
@@ -2734,6 +2739,9 @@ Expression* Parser::ParsePrimaryExpression(bool* ok) {
case Token::LPAREN:
Consume(Token::LPAREN);
+ // Heuristically try to detect immediately called functions before
+ // seeing the call parentheses.
+ parenthesized_function_ = (peek() == Token::FUNCTION);
result = ParseExpression(true, CHECK_OK);
Expect(Token::RPAREN, CHECK_OK);
break;
@@ -3225,8 +3233,11 @@ FunctionLiteral* Parser::ParseFunctionLiteral(Handle<String> var_name,
// Determine if the function will be lazily compiled. The mode can
// only be PARSE_LAZILY if the --lazy flag is true.
- bool is_lazily_compiled =
- mode() == PARSE_LAZILY && top_scope_->HasTrivialOuterContext();
+ bool is_lazily_compiled = (mode() == PARSE_LAZILY &&
+ top_scope_->outer_scope()->is_global_scope() &&
+ top_scope_->HasTrivialOuterContext() &&
+ !parenthesized_function_);
+ parenthesized_function_ = false; // The bit was set for this function only.
int function_block_pos = scanner().location().beg_pos;
int materialized_literal_count;
« no previous file with comments | « src/parser.h ('k') | src/preparser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698