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

Unified Diff: runtime/vm/dart_api_impl_test.cc

Issue 10831021: Added a test of Dart_FunctionParameterCounts against a closure inside an (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/vm/dart_api_impl.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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) {
« no previous file with comments | « runtime/vm/dart_api_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698