Chromium Code Reviews| Index: runtime/vm/dart_api_impl_test.cc |
| =================================================================== |
| --- runtime/vm/dart_api_impl_test.cc (revision 9911) |
| +++ runtime/vm/dart_api_impl_test.cc (working copy) |
| @@ -3716,6 +3716,15 @@ |
| const char* kScriptChars = |
| "Function getClosure() {\n" |
| " return (x, y, [z]) => x + y + z;\n" |
| + "}\n" |
| + "class Foo {\n" |
| + " getInstanceClosure() {\n" |
| + " return (){return this;};\n" |
|
Ivan Posva
2012/07/26 01:01:09
Please add spaces between (), { and }.
|
| + " }\n" |
| + "}\n" |
| + "Function getInstanceClosure() {\n" |
| + " var f = new Foo();\n" |
| + " return f.getInstanceClosure();\n" |
| "}\n"; |
| Dart_Handle result; |
| DARTSCOPE_NOCHECKS(Isolate::Current()); |
| @@ -3734,8 +3743,8 @@ |
| result = Dart_ClosureFunction(retobj); |
| EXPECT_VALID(result); |
| EXPECT(Dart_IsFunction(result)); |
| - int64_t fixed_param_count = -1; |
| - int64_t opt_param_count = -1; |
| + int64_t fixed_param_count = -999; |
| + int64_t opt_param_count = -999; |
| result = Dart_FunctionParameterCounts(result, |
| &fixed_param_count, |
| &opt_param_count); |
| @@ -3746,6 +3755,26 @@ |
| // Try to retrieve function from a non-closure object |
| result = Dart_ClosureFunction(Dart_NewInteger(1)); |
| EXPECT(Dart_IsError(result)); |
| + |
| + // Invoke a function which returns an "instance" closure. |
| + retobj = Dart_Invoke(lib, Dart_NewString("getInstanceClosure"), 0, NULL); |
| + EXPECT_VALID(retobj); |
| + EXPECT(Dart_IsClosure(retobj)); |
| + |
| + // Retrieve the closure's function |
| + result = Dart_ClosureFunction(retobj); |
| + EXPECT_VALID(result); |
| + EXPECT(Dart_IsFunction(result)); |
| + // -999: We want to distinguish between a non-answer and a wrong answer, and |
| + // -1 has been a previous wrong answer |
| + fixed_param_count = -999; |
| + opt_param_count = -999; |
| + result = Dart_FunctionParameterCounts(result, |
| + &fixed_param_count, |
| + &opt_param_count); |
| + EXPECT_VALID(result); |
| + EXPECT_EQ(0, fixed_param_count); |
|
Ivan Posva
2012/07/26 01:01:09
We should also test with closures in statics and w
|
| + EXPECT_EQ(0, opt_param_count); |
| } |
| TEST_CASE(InvokeClosure) { |