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

Side by Side Diff: vm/dart_api_impl_test.cc

Issue 10196003: Dart_IsSame -> Dart_IdentityEquals. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 8 years, 8 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 | « 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 "include/dart_api.h" 5 #include "include/dart_api.h"
6 #include "platform/assert.h" 6 #include "platform/assert.h"
7 #include "platform/utils.h" 7 #include "platform/utils.h"
8 #include "vm/class_finalizer.h" 8 #include "vm/class_finalizer.h"
9 #include "vm/dart_api_impl.h" 9 #include "vm/dart_api_impl.h"
10 #include "vm/dart_api_state.h" 10 #include "vm/dart_api_state.h"
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 Dart_Handle null = Dart_Null(); 124 Dart_Handle null = Dart_Null();
125 EXPECT_VALID(null); 125 EXPECT_VALID(null);
126 EXPECT(Dart_IsNull(null)); 126 EXPECT(Dart_IsNull(null));
127 127
128 Dart_Handle str = Dart_NewString("test"); 128 Dart_Handle str = Dart_NewString("test");
129 EXPECT_VALID(str); 129 EXPECT_VALID(str);
130 EXPECT(!Dart_IsNull(str)); 130 EXPECT(!Dart_IsNull(str));
131 } 131 }
132 132
133 133
134 TEST_CASE(IsSame) { 134 TEST_CASE(IdentityEquals) {
135 bool same = false;
136 Dart_Handle five = Dart_NewString("5"); 135 Dart_Handle five = Dart_NewString("5");
137 Dart_Handle five_again = Dart_NewString("5"); 136 Dart_Handle five_again = Dart_NewString("5");
138 Dart_Handle seven = Dart_NewString("7"); 137 Dart_Handle seven = Dart_NewString("7");
139 138
140 // Same objects. 139 // Same objects.
141 EXPECT_VALID(Dart_IsSame(five, five, &same)); 140 EXPECT(Dart_IdentityEquals(five, five));
142 EXPECT(same);
143 141
144 // Equal objects. 142 // Equal objects.
145 EXPECT_VALID(Dart_IsSame(five, five_again, &same)); 143 EXPECT(!Dart_IdentityEquals(five, five_again));
146 EXPECT(!same);
147 144
148 // Different objects. 145 // Different objects.
149 EXPECT_VALID(Dart_IsSame(five, seven, &same)); 146 EXPECT(!Dart_IdentityEquals(five, seven));
150 EXPECT(!same);
151 147
152 // Non-instance objects. 148 // Non-instance objects.
153 { 149 {
154 Isolate* isolate = Isolate::Current(); 150 Isolate* isolate = Isolate::Current();
155 DARTSCOPE_NOCHECKS(isolate); 151 DARTSCOPE_NOCHECKS(isolate);
156 Dart_Handle class1 = Api::NewHandle(isolate, Object::null_class()); 152 Dart_Handle class1 = Api::NewHandle(isolate, Object::null_class());
157 Dart_Handle class2 = Api::NewHandle(isolate, Object::class_class()); 153 Dart_Handle class2 = Api::NewHandle(isolate, Object::class_class());
158 154
159 EXPECT_VALID(Dart_IsSame(class1, class1, &same)); 155 EXPECT(Dart_IdentityEquals(class1, class1));
160 EXPECT(same);
161 156
162 EXPECT_VALID(Dart_IsSame(class1, class2, &same)); 157 EXPECT(!Dart_IdentityEquals(class1, class2));
163 EXPECT(!same);
164 } 158 }
165 } 159 }
166 160
167 161
168 // Only ia32 and x64 can run execution tests. 162 // Only ia32 and x64 can run execution tests.
169 #if defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64) 163 #if defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64)
170 164
171 TEST_CASE(ObjectEquals) { 165 TEST_CASE(ObjectEquals) {
172 bool equal = false; 166 bool equal = false;
173 Dart_Handle five = Dart_NewString("5"); 167 Dart_Handle five = Dart_NewString("5");
(...skipping 1020 matching lines...) Expand 10 before | Expand all | Expand 10 after
1194 // Only ia32 and x64 can run execution tests. 1188 // Only ia32 and x64 can run execution tests.
1195 #if defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64) 1189 #if defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64)
1196 1190
1197 TEST_CASE(WeakPersistentHandle) { 1191 TEST_CASE(WeakPersistentHandle) {
1198 Dart_Handle weak_new_ref = Dart_Null(); 1192 Dart_Handle weak_new_ref = Dart_Null();
1199 EXPECT(Dart_IsNull(weak_new_ref)); 1193 EXPECT(Dart_IsNull(weak_new_ref));
1200 1194
1201 Dart_Handle weak_old_ref = Dart_Null(); 1195 Dart_Handle weak_old_ref = Dart_Null();
1202 EXPECT(Dart_IsNull(weak_old_ref)); 1196 EXPECT(Dart_IsNull(weak_old_ref));
1203 1197
1204 bool is_same;
1205
1206 { 1198 {
1207 Dart_EnterScope(); 1199 Dart_EnterScope();
1208 1200
1209 // create an object in new space 1201 // create an object in new space
1210 Dart_Handle new_ref = Dart_NewString("new string"); 1202 Dart_Handle new_ref = Dart_NewString("new string");
1211 EXPECT_VALID(new_ref); 1203 EXPECT_VALID(new_ref);
1212 1204
1213 // create an object in old space 1205 // create an object in old space
1214 Dart_Handle old_ref; 1206 Dart_Handle old_ref;
1215 { 1207 {
(...skipping 17 matching lines...) Expand all
1233 Isolate::Current()->heap()->CollectGarbage(Heap::kNew); 1225 Isolate::Current()->heap()->CollectGarbage(Heap::kNew);
1234 1226
1235 // nothing should be invalidated or cleared 1227 // nothing should be invalidated or cleared
1236 EXPECT_VALID(new_ref); 1228 EXPECT_VALID(new_ref);
1237 EXPECT(!Dart_IsNull(new_ref)); 1229 EXPECT(!Dart_IsNull(new_ref));
1238 EXPECT_VALID(old_ref); 1230 EXPECT_VALID(old_ref);
1239 EXPECT(!Dart_IsNull(old_ref)); 1231 EXPECT(!Dart_IsNull(old_ref));
1240 1232
1241 EXPECT_VALID(weak_new_ref); 1233 EXPECT_VALID(weak_new_ref);
1242 EXPECT(!Dart_IsNull(weak_new_ref)); 1234 EXPECT(!Dart_IsNull(weak_new_ref));
1243 is_same = false; 1235 EXPECT(Dart_IdentityEquals(new_ref, weak_new_ref));
1244 EXPECT_VALID(Dart_IsSame(new_ref, weak_new_ref, &is_same));
1245 EXPECT(is_same);
1246 1236
1247 EXPECT_VALID(weak_old_ref); 1237 EXPECT_VALID(weak_old_ref);
1248 EXPECT(!Dart_IsNull(weak_old_ref)); 1238 EXPECT(!Dart_IsNull(weak_old_ref));
1249 is_same = false; 1239 EXPECT(Dart_IdentityEquals(old_ref, weak_old_ref));
1250 EXPECT_VALID(Dart_IsSame(old_ref, weak_old_ref, &is_same));
1251 EXPECT(is_same);
1252 1240
1253 // garbage collect old space 1241 // garbage collect old space
1254 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); 1242 Isolate::Current()->heap()->CollectGarbage(Heap::kOld);
1255 1243
1256 // nothing should be invalidated or cleared 1244 // nothing should be invalidated or cleared
1257 EXPECT_VALID(new_ref); 1245 EXPECT_VALID(new_ref);
1258 EXPECT(!Dart_IsNull(new_ref)); 1246 EXPECT(!Dart_IsNull(new_ref));
1259 EXPECT_VALID(old_ref); 1247 EXPECT_VALID(old_ref);
1260 EXPECT(!Dart_IsNull(old_ref)); 1248 EXPECT(!Dart_IsNull(old_ref));
1261 1249
1262 EXPECT_VALID(weak_new_ref); 1250 EXPECT_VALID(weak_new_ref);
1263 EXPECT(!Dart_IsNull(weak_new_ref)); 1251 EXPECT(!Dart_IsNull(weak_new_ref));
1264 is_same = false; 1252 EXPECT(Dart_IdentityEquals(new_ref, weak_new_ref));
1265 EXPECT_VALID(Dart_IsSame(new_ref, weak_new_ref, &is_same));
1266 EXPECT(is_same);
1267 1253
1268 EXPECT_VALID(weak_old_ref); 1254 EXPECT_VALID(weak_old_ref);
1269 EXPECT(!Dart_IsNull(weak_old_ref)); 1255 EXPECT(!Dart_IsNull(weak_old_ref));
1270 is_same = false; 1256 EXPECT(Dart_IdentityEquals(old_ref, weak_old_ref));
1271 EXPECT_VALID(Dart_IsSame(old_ref, weak_old_ref, &is_same));
1272 EXPECT(is_same);
1273 1257
1274 // delete local (strong) references 1258 // delete local (strong) references
1275 Dart_ExitScope(); 1259 Dart_ExitScope();
1276 } 1260 }
1277 1261
1278 // garbage collect new space again 1262 // garbage collect new space again
1279 Isolate::Current()->heap()->CollectGarbage(Heap::kNew); 1263 Isolate::Current()->heap()->CollectGarbage(Heap::kNew);
1280 1264
1281 // weak ref to new space object should now be cleared 1265 // weak ref to new space object should now be cleared
1282 EXPECT_VALID(weak_new_ref); 1266 EXPECT_VALID(weak_new_ref);
(...skipping 2755 matching lines...) Expand 10 before | Expand all | Expand 10 after
4038 Dart_GetError(result)); 4022 Dart_GetError(result));
4039 4023
4040 result = Dart_LoadSource(lib, error, source); 4024 result = Dart_LoadSource(lib, error, source);
4041 EXPECT(Dart_IsError(result)); 4025 EXPECT(Dart_IsError(result));
4042 EXPECT_STREQ("incoming error", Dart_GetError(result)); 4026 EXPECT_STREQ("incoming error", Dart_GetError(result));
4043 4027
4044 // Success. 4028 // Success.
4045 result = Dart_LoadSource(lib, url, source); 4029 result = Dart_LoadSource(lib, url, source);
4046 EXPECT_VALID(result); 4030 EXPECT_VALID(result);
4047 EXPECT(Dart_IsLibrary(result)); 4031 EXPECT(Dart_IsLibrary(result));
4048 bool same = false; 4032 EXPECT(Dart_IdentityEquals(lib, result));
4049 EXPECT_VALID(Dart_IsSame(lib, result, &same));
4050 EXPECT(same);
4051 4033
4052 // Duplicate calls are okay. 4034 // Duplicate calls are okay.
4053 result = Dart_LoadSource(lib, url, source); 4035 result = Dart_LoadSource(lib, url, source);
4054 EXPECT_VALID(result); 4036 EXPECT_VALID(result);
4055 EXPECT(Dart_IsLibrary(result)); 4037 EXPECT(Dart_IsLibrary(result));
4056 same = false; 4038 EXPECT(Dart_IdentityEquals(lib, result));
4057 EXPECT_VALID(Dart_IsSame(lib, result, &same));
4058 EXPECT(same);
4059 4039
4060 // Language errors are detected. 4040 // Language errors are detected.
4061 source = Dart_NewString(kBadSourceChars); 4041 source = Dart_NewString(kBadSourceChars);
4062 result = Dart_LoadSource(lib, url, source); 4042 result = Dart_LoadSource(lib, url, source);
4063 EXPECT(Dart_IsError(result)); 4043 EXPECT(Dart_IsError(result));
4064 } 4044 }
4065 4045
4066 4046
4067 static void MyNativeFunction1(Dart_NativeArguments args) { 4047 static void MyNativeFunction1(Dart_NativeArguments args) {
4068 Dart_EnterScope(); 4048 Dart_EnterScope();
(...skipping 737 matching lines...) Expand 10 before | Expand all | Expand 10 after
4806 EXPECT_VALID(result); 4786 EXPECT_VALID(result);
4807 EXPECT(Dart_IsDouble(result)); 4787 EXPECT(Dart_IsDouble(result));
4808 double out; 4788 double out;
4809 result = Dart_DoubleValue(result, &out); 4789 result = Dart_DoubleValue(result, &out);
4810 fprintf(stderr, "Benchmark_UseDartApi: %f us per iteration\n", out); 4790 fprintf(stderr, "Benchmark_UseDartApi: %f us per iteration\n", out);
4811 } 4791 }
4812 4792
4813 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). 4793 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64).
4814 4794
4815 } // namespace dart 4795 } // namespace dart
OLDNEW
« no previous file with comments | « vm/dart_api_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698