}
}
+ void RemoveLastFunction() {
+ if (IsOpen() && !funcs_to_infer_.is_empty()) {
+ funcs_to_infer_.RemoveLast();
+ }
+ }
+
// Infers a function name and leaves names collection state.
void Infer() {
ASSERT(IsOpen());
value->AsCall() == NULL &&
value->AsCallNew() == NULL) {
fni_->Infer();
+ } else {
+ fni_->RemoveLastFunction();
}
}
|| op == Token::ASSIGN)
&& (right->AsCall() == NULL && right->AsCallNew() == NULL)) {
fni_->Infer();
+ } else {
+ fni_->RemoveLastFunction();
}
fni_->Leave();
}
// Can't infer the function name statically.
CheckFunctionName(script, "return 1", "obj.(anonymous function)");
}
+
+
+TEST(GlobalAssignmentAndCall) {
+ InitializeVM();
+ v8::HandleScope scope;
+
+ v8::Handle<v8::Script> script = Compile(
+ "var Foo = function() {\n"
+ " return 1;\n"
+ "}();\n"
+ "var Baz = Bar = function() {\n"
+ " return 2;\n"
+ "}");
+ // The inferred name is empty, because this is an assignment of a result.
+ CheckFunctionName(script, "return 1", "");
+ // See MultipleAssignments test.
+ CheckFunctionName(script, "return 2", "Bar");
+}
+
+
+TEST(AssignmentAndCall) {
+ InitializeVM();
+ v8::HandleScope scope;
+
+ v8::Handle<v8::Script> script = Compile(
+ "(function Enclosing() {\n"
+ " var Foo;\n"
+ " Foo = function() {\n"
+ " return 1;\n"
+ " }();\n"
+ " var Baz = Bar = function() {\n"
+ " return 2;\n"
+ " }\n"
+ "})();");
+ // The inferred name is empty, because this is an assignment of a result.
+ CheckFunctionName(script, "return 1", "");
+ // See MultipleAssignments test.
+ CheckFunctionName(script, "return 2", "Enclosing.Bar");
+}