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

Unified Diff: runtime/vm/dart_api_impl_test.cc

Issue 25675009: Allow invocation of constructors using Dart_Invoke. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 2 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 28275)
+++ runtime/vm/dart_api_impl_test.cc (working copy)
@@ -3844,12 +3844,12 @@
EXPECT_EQ(7, int_value);
// Allocate without a constructor.
- result = Dart_Allocate(type);
- EXPECT_VALID(result);
+ Dart_Handle obj = Dart_Allocate(type);
+ EXPECT_VALID(obj);
instanceof = false;
- EXPECT_VALID(Dart_ObjectIsType(result, type, &instanceof));
+ EXPECT_VALID(Dart_ObjectIsType(obj, type, &instanceof));
EXPECT(instanceof);
- foo = Dart_GetField(result, NewString("foo"));
+ foo = Dart_GetField(obj, NewString("foo"));
EXPECT(Dart_IsNull(foo));
// Invoke the unnamed constructor with an empty string.
@@ -3863,6 +3863,19 @@
EXPECT_VALID(Dart_IntegerToInt64(foo, &int_value));
EXPECT_EQ(7, int_value);
+ // Allocate object and invoke the unnamed constructor with an empty string.
+ obj = Dart_Allocate(type);
+ EXPECT_VALID(obj);
+ instanceof = false;
+ EXPECT_VALID(Dart_ObjectIsType(obj, type, &instanceof));
+ EXPECT(instanceof);
+ result = Dart_InvokeConstructor(obj, NewString(""), 0, NULL);
+ EXPECT_VALID(result);
+ int_value = 0;
+ foo = Dart_GetField(result, NewString("foo"));
+ EXPECT_VALID(Dart_IntegerToInt64(foo, &int_value));
+ EXPECT_EQ(7, int_value);
+
// Invoke a named constructor.
result = Dart_New(type, NewString("named"), 1, args);
EXPECT_VALID(result);
@@ -3873,6 +3886,19 @@
EXPECT_VALID(Dart_IntegerToInt64(foo, &int_value));
EXPECT_EQ(11, int_value);
+ // Allocate object and invoke a named constructor.
+ obj = Dart_Allocate(type);
+ EXPECT_VALID(obj);
+ instanceof = false;
+ EXPECT_VALID(Dart_ObjectIsType(obj, type, &instanceof));
+ EXPECT(instanceof);
+ result = Dart_InvokeConstructor(obj, NewString("named"), 1, args);
+ EXPECT_VALID(result);
+ int_value = 0;
+ foo = Dart_GetField(result, NewString("foo"));
+ EXPECT_VALID(Dart_IntegerToInt64(foo, &int_value));
+ EXPECT_EQ(11, int_value);
+
// Invoke a hidden named constructor.
result = Dart_New(type, NewString("_hidden"), 1, args);
EXPECT_VALID(result);
@@ -3883,6 +3909,28 @@
EXPECT_VALID(Dart_IntegerToInt64(foo, &int_value));
EXPECT_EQ(-11, int_value);
+ // Allocate object and invoke a hidden named constructor.
+ obj = Dart_Allocate(type);
+ EXPECT_VALID(obj);
+ instanceof = false;
+ EXPECT_VALID(Dart_ObjectIsType(obj, type, &instanceof));
+ EXPECT(instanceof);
+ result = Dart_InvokeConstructor(obj, NewString("_hidden"), 1, args);
+ EXPECT_VALID(result);
+ int_value = 0;
+ foo = Dart_GetField(result, NewString("foo"));
+ EXPECT_VALID(Dart_IntegerToInt64(foo, &int_value));
+ EXPECT_EQ(-11, int_value);
+
+ // Allocate object and Invoke a constructor which throws an exception.
+ obj = Dart_Allocate(type);
+ EXPECT_VALID(obj);
+ instanceof = false;
+ EXPECT_VALID(Dart_ObjectIsType(obj, type, &instanceof));
+ EXPECT(instanceof);
+ result = Dart_InvokeConstructor(obj, NewString("exception"), 1, args);
+ EXPECT_ERROR(result, "ConstructorDeath");
+
// Invoke a factory constructor.
result = Dart_New(type, NewString("multiply"), 1, args);
EXPECT_VALID(result);
« 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