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

Unified Diff: runtime/vm/dart_api_impl_test.cc

Issue 10800065: Added ClosureMirror to dart:mirrors. Added Dart_ClosureFunction to the (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
« runtime/lib/mirrors.cc ('K') | « 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 9796)
+++ runtime/vm/dart_api_impl_test.cc (working copy)
@@ -3712,7 +3712,42 @@
"did not find top-level function '_imported'");
}
+TEST_CASE(ClosureFunction) {
+ const char* kScriptChars =
+ "Function getClosure() {\n"
+ " return (x, y, [z]) => x + y + z;\n"
+ "}\n";
+ Dart_Handle result;
+ DARTSCOPE_NOCHECKS(Isolate::Current());
+ // Create a test library and Load up a test script in it.
+ Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
+
+ // Invoke a function which returns a closure.
+ Dart_Handle retobj = Dart_Invoke(lib, Dart_NewString("getClosure"), 0, NULL);
+ EXPECT_VALID(retobj);
+
+ EXPECT(Dart_IsClosure(retobj));
+ EXPECT(!Dart_IsClosure(Dart_NewInteger(101)));
+
+ // Retrieve the closure's function
+ result = Dart_ClosureFunction(retobj);
+ EXPECT_VALID(result);
+ EXPECT(Dart_IsFunction(result));
+ int64_t fixed_param_count = -1;
+ int64_t opt_param_count = -1;
+ result = Dart_FunctionParameterCounts(result,
+ &fixed_param_count,
+ &opt_param_count);
+ EXPECT_VALID(result);
+ EXPECT_EQ(2, fixed_param_count);
+ EXPECT_EQ(1, opt_param_count);
+
+ // Try to retrieve function from a non-closure object
+ result = Dart_ClosureFunction(Dart_NewInteger(1));
+ EXPECT(Dart_IsError(result));
+}
+
TEST_CASE(InvokeClosure) {
const char* kScriptChars =
"class InvokeClosure {\n"
« runtime/lib/mirrors.cc ('K') | « runtime/vm/dart_api_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698