Provide better ToCString description for closures (issue 2680).

Thanks to Ladislav Thon for the suggestion!
Review URL: https://chromiumcodereview.appspot.com//10188004

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@6861 260f80e4-7a28-3924-810f-c04153c831b5
This commit is contained in:
regis@google.com 2012-04-23 20:15:43 +00:00
parent 11d4d91b23
commit 0148376aa9
3 changed files with 14 additions and 3 deletions

View file

@ -8938,7 +8938,17 @@ void Closure::set_function(const Function& value) const {
const char* Closure::ToCString() const {
return "Closure";
const Function& fun = Function::Handle(function());
const bool is_implicit_closure = fun.IsImplicitClosureFunction();
const char* fun_sig = String::Handle(fun.Signature()).ToCString();
const char* from = is_implicit_closure ? " from " : "";
const char* fun_desc = is_implicit_closure ? fun.ToCString() : "";
const char* format = "Closure: %s%s%s";
intptr_t len = OS::SNPrint(NULL, 0, format, fun_sig, from, fun_desc) + 1;
char* chars = reinterpret_cast<char*>(
Isolate::Current()->current_zone()->Allocate(len));
OS::SNPrint(chars, len, format, fun_sig, from, fun_desc);
return chars;
}

View file

@ -22,7 +22,8 @@ class LocalFunction3Test {
exception_caught = true;
}
Expect.equals(false, exception_caught);
Expect.equals("Closure", f_string);
Expect.equals("", f_string);
Expect.equals(true, f_string.startsWith("Closure"));
}
static testMain() {

View file

@ -138,7 +138,7 @@ class LocalFunctionTest {
Expect.equals(2, f(1));
Expect.equals(true, f is Function);
Expect.equals(true, f is Object);
Expect.equals("Closure", f.toString());
Expect.equals(true, f.toString().startsWith("Closure"));
bool exception_caught = false;
try {
f(1, 2);