Index: src/func-name-inferrer.cc |
diff --git a/src/func-name-inferrer.cc b/src/func-name-inferrer.cc |
index ebac4b9bff7a5b04f4711425dfb16760471829e9..0d75bd141ae2ed4e2661c8c717c0be1e724b4e57 100644 |
--- a/src/func-name-inferrer.cc |
+++ b/src/func-name-inferrer.cc |
@@ -34,6 +34,18 @@ |
namespace v8 { |
namespace internal { |
+const char* const FuncNameInferrer::kAnonymousFunctionName = |
+ "(anonymous function)"; |
+ |
+FuncNameInferrer::FuncNameInferrer() |
+ : entries_stack_(10), |
+ names_stack_(5), |
+ funcs_to_infer_(4), |
+ dot_(FACTORY->NewStringFromAscii(CStrVector("."))), |
+ anonymous_function_( |
+ FACTORY->NewStringFromAscii(CStrVector(kAnonymousFunctionName))) { |
+} |
+ |
void FuncNameInferrer::PushEnclosingName(Handle<String> name) { |
// Enclosing name is a name of a constructor function. To check |
@@ -41,41 +53,47 @@ void FuncNameInferrer::PushEnclosingName(Handle<String> name) { |
// and starts with a capital letter. |
if (name->length() > 0 && Runtime::IsUpperCaseChar( |
Isolate::Current()->runtime_state(), name->Get(0))) { |
Vitaly Repeshko
2011/06/22 13:21:30
While we're here, let's fix the extra TLS loads by
mnaganov (inactive)
2011/06/22 20:21:08
Done.
|
- names_stack_.Add(name); |
+ names_stack_.Add(Name(name, kEnclosingConstructorName)); |
} |
} |
void FuncNameInferrer::PushLiteralName(Handle<String> name) { |
if (IsOpen() && !HEAP->prototype_symbol()->Equals(*name)) { |
- names_stack_.Add(name); |
+ names_stack_.Add(Name(name, kLiteralName)); |
} |
} |
void FuncNameInferrer::PushVariableName(Handle<String> name) { |
if (IsOpen() && !HEAP->result_symbol()->Equals(*name)) { |
- names_stack_.Add(name); |
+ names_stack_.Add(Name(name, kVariableName)); |
} |
} |
Handle<String> FuncNameInferrer::MakeNameFromStack() { |
- if (names_stack_.is_empty()) { |
- return FACTORY->empty_string(); |
- } else { |
- return MakeNameFromStackHelper(1, names_stack_.at(0)); |
- } |
+ return MakeNameFromStackHelper(0, FACTORY->empty_string()); |
} |
Handle<String> FuncNameInferrer::MakeNameFromStackHelper(int pos, |
Handle<String> prev) { |
- if (pos >= names_stack_.length()) { |
- return prev; |
+ if (pos >= names_stack_.length()) return prev; |
+ if (pos < names_stack_.length() - 1 && |
+ names_stack_.at(pos).type == kVariableName && |
+ names_stack_.at(pos + 1).type == kVariableName) { |
+ // Skip consecutive variable declarations. |
+ return MakeNameFromStackHelper(pos + 1, prev); |
} else { |
- Handle<String> curr = FACTORY->NewConsString(dot_, names_stack_.at(pos)); |
- return MakeNameFromStackHelper(pos + 1, FACTORY->NewConsString(prev, curr)); |
+ if (prev->length() > 0) { |
+ Handle<String> curr = |
+ FACTORY->NewConsString(dot_, names_stack_.at(pos).name); |
+ return MakeNameFromStackHelper(pos + 1, |
+ FACTORY->NewConsString(prev, curr)); |
+ } else { |
+ return MakeNameFromStackHelper(pos + 1, names_stack_.at(pos).name); |
+ } |
} |
} |