OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 4503 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4514 VariableProxy* proxy = factory()->NewVariableProxy(fvar); | 4514 VariableProxy* proxy = factory()->NewVariableProxy(fvar); |
4515 VariableDeclaration* fvar_declaration = | 4515 VariableDeclaration* fvar_declaration = |
4516 factory()->NewVariableDeclaration(proxy, fvar_mode, top_scope_); | 4516 factory()->NewVariableDeclaration(proxy, fvar_mode, top_scope_); |
4517 top_scope_->DeclareFunctionVar(fvar_declaration); | 4517 top_scope_->DeclareFunctionVar(fvar_declaration); |
4518 } | 4518 } |
4519 | 4519 |
4520 // Determine whether the function will be lazily compiled. | 4520 // Determine whether the function will be lazily compiled. |
4521 // The heuristics are: | 4521 // The heuristics are: |
4522 // - It must not have been prohibited by the caller to Parse (some callers | 4522 // - It must not have been prohibited by the caller to Parse (some callers |
4523 // need a full AST). | 4523 // need a full AST). |
4524 // - The outer scope must be trivial (only global variables in scope). | |
4525 // - The function mustn't be a function expression with an open parenthesis | 4524 // - The function mustn't be a function expression with an open parenthesis |
4526 // before; we consider that a hint that the function will be called | 4525 // before; we consider that a hint that the function will be called |
4527 // immediately, and it would be a waste of time to make it lazily | 4526 // immediately, and it would be a waste of time to make it lazily |
4528 // compiled. | 4527 // compiled. |
4529 // These are all things we can know at this point, without looking at the | 4528 // These are all things we can know at this point, without looking at the |
4530 // function itself. | 4529 // function itself. |
4531 bool is_lazily_compiled = (mode() == PARSE_LAZILY && | 4530 bool is_lazily_compiled = (mode() == PARSE_LAZILY && |
4532 top_scope_->outer_scope()->is_global_scope() && | |
4533 top_scope_->HasTrivialOuterContext() && | |
4534 !parenthesized_function_); | 4531 !parenthesized_function_); |
4535 parenthesized_function_ = false; // The bit was set for this function only. | 4532 parenthesized_function_ = false; // The bit was set for this function only. |
4536 | 4533 |
4537 if (is_lazily_compiled) { | 4534 if (is_lazily_compiled) { |
4538 int function_block_pos = scanner().location().beg_pos; | 4535 int function_block_pos = scanner().location().beg_pos; |
4539 FunctionEntry entry; | 4536 FunctionEntry entry; |
4540 if (pre_data_ != NULL) { | 4537 if (pre_data_ != NULL) { |
4541 // If we have pre_data_, we use it to skip parsing the function body. | 4538 // If we have pre_data_, we use it to skip parsing the function body. |
4542 // the preparser data contains the information we need to construct the | 4539 // the preparser data contains the information we need to construct the |
4543 // lazy function. | 4540 // lazy function. |
(...skipping 1520 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6064 ASSERT(info->isolate()->has_pending_exception()); | 6061 ASSERT(info->isolate()->has_pending_exception()); |
6065 } else { | 6062 } else { |
6066 result = parser.ParseProgram(info); | 6063 result = parser.ParseProgram(info); |
6067 } | 6064 } |
6068 } | 6065 } |
6069 info->SetFunction(result); | 6066 info->SetFunction(result); |
6070 return (result != NULL); | 6067 return (result != NULL); |
6071 } | 6068 } |
6072 | 6069 |
6073 } } // namespace v8::internal | 6070 } } // namespace v8::internal |
OLD | NEW |