Force eager compilation of some function literals.

In case a function literal is followed by parenthesis, we consider this
a hint that it will be called immediately. If we happen to have parsed
that function literal eagerly, we can also compile it eagerly.

R=ulan@chromium.org

Review URL: https://chromiumcodereview.appspot.com/10828227

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@12320 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent aaf403e9
......@@ -2091,9 +2091,17 @@ class FunctionLiteral: public Expression {
bool is_function() { return IsFunction::decode(bitfield_) == kIsFunction; }
// This is used as a heuristic on when to eagerly compile a function
// literal. We consider the following constructs as hints that the
// function will be called immediately:
// - (function() { ... })();
// - var x = function() { ... }();
bool is_parenthesized() {
return IsParenthesized::decode(bitfield_) == kIsParenthesized;
}
void set_parenthesized() {
bitfield_ = IsParenthesized::update(bitfield_, kIsParenthesized);
}
int ast_node_count() { return ast_properties_.node_count(); }
AstProperties::Flags* flags() { return ast_properties_.flags(); }
......
......@@ -707,7 +707,7 @@ FunctionLiteral* Parser::ParseLazy() {
if (FLAG_trace_parse && result != NULL) {
double ms = static_cast<double>(OS::Ticks() - start) / 1000;
SmartArrayPointer<char> name_chars = result->name()->ToCString();
SmartArrayPointer<char> name_chars = result->debug_name()->ToCString();
PrintF("[parsing function: %s - took %0.3f ms]\n", *name_chars, ms);
}
return result;
......@@ -3450,6 +3450,12 @@ Expression* Parser::ParseLeftHandSideExpression(bool* ok) {
// should not point to the closing brace otherwise it will intersect
// with positions recorded for function literal and confuse debugger.
pos = scanner().peek_location().beg_pos;
// Also the trailing parenthesis are a hint that the function will
// be called immediately. If we happen to have parsed a preceding
// function literal eagerly, we can also compile it eagerly.
if (result->IsFunctionLiteral() && mode() == PARSE_EAGERLY) {
result->AsFunctionLiteral()->set_parenthesized();
}
}
ZoneList<Expression*>* args = ParseArguments(CHECK_OK);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment