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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/vm/dart_api_impl.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "bin/builtin.h" 5 #include "bin/builtin.h"
6 #include "include/dart_api.h" 6 #include "include/dart_api.h"
7 #include "include/dart_mirrors_api.h" 7 #include "include/dart_mirrors_api.h"
8 #include "include/dart_native_api.h" 8 #include "include/dart_native_api.h"
9 #include "platform/assert.h" 9 #include "platform/assert.h"
10 #include "platform/json.h" 10 #include "platform/json.h"
(...skipping 3826 matching lines...) Expand 10 before | Expand all | Expand 10 after
3837 EXPECT_VALID(result); 3837 EXPECT_VALID(result);
3838 bool instanceof = false; 3838 bool instanceof = false;
3839 EXPECT_VALID(Dart_ObjectIsType(result, type, &instanceof)); 3839 EXPECT_VALID(Dart_ObjectIsType(result, type, &instanceof));
3840 EXPECT(instanceof); 3840 EXPECT(instanceof);
3841 int64_t int_value = 0; 3841 int64_t int_value = 0;
3842 Dart_Handle foo = Dart_GetField(result, NewString("foo")); 3842 Dart_Handle foo = Dart_GetField(result, NewString("foo"));
3843 EXPECT_VALID(Dart_IntegerToInt64(foo, &int_value)); 3843 EXPECT_VALID(Dart_IntegerToInt64(foo, &int_value));
3844 EXPECT_EQ(7, int_value); 3844 EXPECT_EQ(7, int_value);
3845 3845
3846 // Allocate without a constructor. 3846 // Allocate without a constructor.
3847 result = Dart_Allocate(type); 3847 Dart_Handle obj = Dart_Allocate(type);
3848 EXPECT_VALID(result); 3848 EXPECT_VALID(obj);
3849 instanceof = false; 3849 instanceof = false;
3850 EXPECT_VALID(Dart_ObjectIsType(result, type, &instanceof)); 3850 EXPECT_VALID(Dart_ObjectIsType(obj, type, &instanceof));
3851 EXPECT(instanceof); 3851 EXPECT(instanceof);
3852 foo = Dart_GetField(result, NewString("foo")); 3852 foo = Dart_GetField(obj, NewString("foo"));
3853 EXPECT(Dart_IsNull(foo)); 3853 EXPECT(Dart_IsNull(foo));
3854 3854
3855 // Invoke the unnamed constructor with an empty string. 3855 // Invoke the unnamed constructor with an empty string.
3856 result = Dart_New(type, NewString(""), 0, NULL); 3856 result = Dart_New(type, NewString(""), 0, NULL);
3857 EXPECT_VALID(result); 3857 EXPECT_VALID(result);
3858 instanceof = false; 3858 instanceof = false;
3859 EXPECT_VALID(Dart_ObjectIsType(result, type, &instanceof)); 3859 EXPECT_VALID(Dart_ObjectIsType(result, type, &instanceof));
3860 EXPECT(instanceof); 3860 EXPECT(instanceof);
3861 int_value = 0; 3861 int_value = 0;
3862 foo = Dart_GetField(result, NewString("foo")); 3862 foo = Dart_GetField(result, NewString("foo"));
3863 EXPECT_VALID(Dart_IntegerToInt64(foo, &int_value)); 3863 EXPECT_VALID(Dart_IntegerToInt64(foo, &int_value));
3864 EXPECT_EQ(7, int_value); 3864 EXPECT_EQ(7, int_value);
3865 3865
3866 // Allocate object and invoke the unnamed constructor with an empty string.
3867 obj = Dart_Allocate(type);
3868 EXPECT_VALID(obj);
3869 instanceof = false;
3870 EXPECT_VALID(Dart_ObjectIsType(obj, type, &instanceof));
3871 EXPECT(instanceof);
3872 result = Dart_InvokeConstructor(obj, NewString(""), 0, NULL);
3873 EXPECT_VALID(result);
3874 int_value = 0;
3875 foo = Dart_GetField(result, NewString("foo"));
3876 EXPECT_VALID(Dart_IntegerToInt64(foo, &int_value));
3877 EXPECT_EQ(7, int_value);
3878
3866 // Invoke a named constructor. 3879 // Invoke a named constructor.
3867 result = Dart_New(type, NewString("named"), 1, args); 3880 result = Dart_New(type, NewString("named"), 1, args);
3868 EXPECT_VALID(result); 3881 EXPECT_VALID(result);
3869 EXPECT_VALID(Dart_ObjectIsType(result, type, &instanceof)); 3882 EXPECT_VALID(Dart_ObjectIsType(result, type, &instanceof));
3870 EXPECT(instanceof); 3883 EXPECT(instanceof);
3871 int_value = 0; 3884 int_value = 0;
3872 foo = Dart_GetField(result, NewString("foo")); 3885 foo = Dart_GetField(result, NewString("foo"));
3873 EXPECT_VALID(Dart_IntegerToInt64(foo, &int_value)); 3886 EXPECT_VALID(Dart_IntegerToInt64(foo, &int_value));
3874 EXPECT_EQ(11, int_value); 3887 EXPECT_EQ(11, int_value);
3875 3888
3889 // Allocate object and invoke a named constructor.
3890 obj = Dart_Allocate(type);
3891 EXPECT_VALID(obj);
3892 instanceof = false;
3893 EXPECT_VALID(Dart_ObjectIsType(obj, type, &instanceof));
3894 EXPECT(instanceof);
3895 result = Dart_InvokeConstructor(obj, NewString("named"), 1, args);
3896 EXPECT_VALID(result);
3897 int_value = 0;
3898 foo = Dart_GetField(result, NewString("foo"));
3899 EXPECT_VALID(Dart_IntegerToInt64(foo, &int_value));
3900 EXPECT_EQ(11, int_value);
3901
3876 // Invoke a hidden named constructor. 3902 // Invoke a hidden named constructor.
3877 result = Dart_New(type, NewString("_hidden"), 1, args); 3903 result = Dart_New(type, NewString("_hidden"), 1, args);
3878 EXPECT_VALID(result); 3904 EXPECT_VALID(result);
3879 EXPECT_VALID(Dart_ObjectIsType(result, type, &instanceof)); 3905 EXPECT_VALID(Dart_ObjectIsType(result, type, &instanceof));
3880 EXPECT(instanceof); 3906 EXPECT(instanceof);
3881 int_value = 0; 3907 int_value = 0;
3882 foo = Dart_GetField(result, NewString("foo")); 3908 foo = Dart_GetField(result, NewString("foo"));
3883 EXPECT_VALID(Dart_IntegerToInt64(foo, &int_value)); 3909 EXPECT_VALID(Dart_IntegerToInt64(foo, &int_value));
3884 EXPECT_EQ(-11, int_value); 3910 EXPECT_EQ(-11, int_value);
3885 3911
3912 // Allocate object and invoke a hidden named constructor.
3913 obj = Dart_Allocate(type);
3914 EXPECT_VALID(obj);
3915 instanceof = false;
3916 EXPECT_VALID(Dart_ObjectIsType(obj, type, &instanceof));
3917 EXPECT(instanceof);
3918 result = Dart_InvokeConstructor(obj, NewString("_hidden"), 1, args);
3919 EXPECT_VALID(result);
3920 int_value = 0;
3921 foo = Dart_GetField(result, NewString("foo"));
3922 EXPECT_VALID(Dart_IntegerToInt64(foo, &int_value));
3923 EXPECT_EQ(-11, int_value);
3924
3925 // Allocate object and Invoke a constructor which throws an exception.
3926 obj = Dart_Allocate(type);
3927 EXPECT_VALID(obj);
3928 instanceof = false;
3929 EXPECT_VALID(Dart_ObjectIsType(obj, type, &instanceof));
3930 EXPECT(instanceof);
3931 result = Dart_InvokeConstructor(obj, NewString("exception"), 1, args);
3932 EXPECT_ERROR(result, "ConstructorDeath");
3933
3886 // Invoke a factory constructor. 3934 // Invoke a factory constructor.
3887 result = Dart_New(type, NewString("multiply"), 1, args); 3935 result = Dart_New(type, NewString("multiply"), 1, args);
3888 EXPECT_VALID(result); 3936 EXPECT_VALID(result);
3889 EXPECT_VALID(Dart_ObjectIsType(result, type, &instanceof)); 3937 EXPECT_VALID(Dart_ObjectIsType(result, type, &instanceof));
3890 EXPECT(instanceof); 3938 EXPECT(instanceof);
3891 int_value = 0; 3939 int_value = 0;
3892 foo = Dart_GetField(result, NewString("foo")); 3940 foo = Dart_GetField(result, NewString("foo"));
3893 EXPECT_VALID(Dart_IntegerToInt64(foo, &int_value)); 3941 EXPECT_VALID(Dart_IntegerToInt64(foo, &int_value));
3894 EXPECT_EQ(1100, int_value); 3942 EXPECT_EQ(1100, int_value);
3895 3943
(...skipping 3416 matching lines...) Expand 10 before | Expand all | Expand 10 after
7312 NewString("main"), 7360 NewString("main"),
7313 0, 7361 0,
7314 NULL); 7362 NULL);
7315 int64_t value = 0; 7363 int64_t value = 0;
7316 result = Dart_IntegerToInt64(result, &value); 7364 result = Dart_IntegerToInt64(result, &value);
7317 EXPECT_VALID(result); 7365 EXPECT_VALID(result);
7318 EXPECT_EQ(8, value); 7366 EXPECT_EQ(8, value);
7319 } 7367 }
7320 7368
7321 } // namespace dart 7369 } // namespace dart
OLDNEW
« 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