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

Side by Side Diff: src/func-name-inferrer.cc

Issue 7206015: Fix issue 1354: Bad function name inference. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 9 years, 6 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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 16 matching lines...) Expand all
27 27
28 #include "v8.h" 28 #include "v8.h"
29 29
30 #include "ast.h" 30 #include "ast.h"
31 #include "func-name-inferrer.h" 31 #include "func-name-inferrer.h"
32 #include "list-inl.h" 32 #include "list-inl.h"
33 33
34 namespace v8 { 34 namespace v8 {
35 namespace internal { 35 namespace internal {
36 36
37 const char* const FuncNameInferrer::kAnonymousFunctionName =
38 "(anonymous function)";
39
40 FuncNameInferrer::FuncNameInferrer()
41 : entries_stack_(10),
42 names_stack_(5),
43 funcs_to_infer_(4),
44 dot_(FACTORY->NewStringFromAscii(CStrVector("."))),
45 anonymous_function_(
46 FACTORY->NewStringFromAscii(CStrVector(kAnonymousFunctionName))) {
47 }
48
37 49
38 void FuncNameInferrer::PushEnclosingName(Handle<String> name) { 50 void FuncNameInferrer::PushEnclosingName(Handle<String> name) {
39 // Enclosing name is a name of a constructor function. To check 51 // Enclosing name is a name of a constructor function. To check
40 // that it is really a constructor, we check that it is not empty 52 // that it is really a constructor, we check that it is not empty
41 // and starts with a capital letter. 53 // and starts with a capital letter.
42 if (name->length() > 0 && Runtime::IsUpperCaseChar( 54 if (name->length() > 0 && Runtime::IsUpperCaseChar(
43 Isolate::Current()->runtime_state(), name->Get(0))) { 55 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.
44 names_stack_.Add(name); 56 names_stack_.Add(Name(name, kEnclosingConstructorName));
45 } 57 }
46 } 58 }
47 59
48 60
49 void FuncNameInferrer::PushLiteralName(Handle<String> name) { 61 void FuncNameInferrer::PushLiteralName(Handle<String> name) {
50 if (IsOpen() && !HEAP->prototype_symbol()->Equals(*name)) { 62 if (IsOpen() && !HEAP->prototype_symbol()->Equals(*name)) {
51 names_stack_.Add(name); 63 names_stack_.Add(Name(name, kLiteralName));
52 } 64 }
53 } 65 }
54 66
55 67
56 void FuncNameInferrer::PushVariableName(Handle<String> name) { 68 void FuncNameInferrer::PushVariableName(Handle<String> name) {
57 if (IsOpen() && !HEAP->result_symbol()->Equals(*name)) { 69 if (IsOpen() && !HEAP->result_symbol()->Equals(*name)) {
58 names_stack_.Add(name); 70 names_stack_.Add(Name(name, kVariableName));
59 } 71 }
60 } 72 }
61 73
62 74
63 Handle<String> FuncNameInferrer::MakeNameFromStack() { 75 Handle<String> FuncNameInferrer::MakeNameFromStack() {
64 if (names_stack_.is_empty()) { 76 return MakeNameFromStackHelper(0, FACTORY->empty_string());
65 return FACTORY->empty_string();
66 } else {
67 return MakeNameFromStackHelper(1, names_stack_.at(0));
68 }
69 } 77 }
70 78
71 79
72 Handle<String> FuncNameInferrer::MakeNameFromStackHelper(int pos, 80 Handle<String> FuncNameInferrer::MakeNameFromStackHelper(int pos,
73 Handle<String> prev) { 81 Handle<String> prev) {
74 if (pos >= names_stack_.length()) { 82 if (pos >= names_stack_.length()) return prev;
75 return prev; 83 if (pos < names_stack_.length() - 1 &&
84 names_stack_.at(pos).type == kVariableName &&
85 names_stack_.at(pos + 1).type == kVariableName) {
86 // Skip consecutive variable declarations.
87 return MakeNameFromStackHelper(pos + 1, prev);
76 } else { 88 } else {
77 Handle<String> curr = FACTORY->NewConsString(dot_, names_stack_.at(pos)); 89 if (prev->length() > 0) {
78 return MakeNameFromStackHelper(pos + 1, FACTORY->NewConsString(prev, curr)); 90 Handle<String> curr =
91 FACTORY->NewConsString(dot_, names_stack_.at(pos).name);
92 return MakeNameFromStackHelper(pos + 1,
93 FACTORY->NewConsString(prev, curr));
94 } else {
95 return MakeNameFromStackHelper(pos + 1, names_stack_.at(pos).name);
96 }
79 } 97 }
80 } 98 }
81 99
82 100
83 void FuncNameInferrer::InferFunctionsNames() { 101 void FuncNameInferrer::InferFunctionsNames() {
84 Handle<String> func_name = MakeNameFromStack(); 102 Handle<String> func_name = MakeNameFromStack();
85 for (int i = 0; i < funcs_to_infer_.length(); ++i) { 103 for (int i = 0; i < funcs_to_infer_.length(); ++i) {
86 funcs_to_infer_[i]->set_inferred_name(func_name); 104 funcs_to_infer_[i]->set_inferred_name(func_name);
87 } 105 }
88 funcs_to_infer_.Rewind(0); 106 funcs_to_infer_.Rewind(0);
89 } 107 }
90 108
91 109
92 } } // namespace v8::internal 110 } } // namespace v8::internal
OLDNEW
« src/func-name-inferrer.h ('K') | « src/func-name-inferrer.h ('k') | src/parser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698