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

Side by Side Diff: runtime/vm/dart_api_impl_test.cc

Issue 10916185: New test case to ensure finalizers are not invoked on deleted handles. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: address review comments Created 8 years, 3 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 | « no previous file | 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/json.h" 7 #include "platform/json.h"
8 #include "platform/utils.h" 8 #include "platform/utils.h"
9 #include "vm/class_finalizer.h" 9 #include "vm/class_finalizer.h"
10 #include "vm/dart_api_impl.h" 10 #include "vm/dart_api_impl.h"
(...skipping 1400 matching lines...) Expand 10 before | Expand all | Expand 10 after
1411 1411
1412 1412
1413 static void WeakPersistentHandlePeerFinalizer(Dart_Handle handle, void* peer) { 1413 static void WeakPersistentHandlePeerFinalizer(Dart_Handle handle, void* peer) {
1414 *static_cast<int*>(peer) = 42; 1414 *static_cast<int*>(peer) = 42;
1415 } 1415 }
1416 1416
1417 1417
1418 TEST_CASE(WeakPersistentHandleCallback) { 1418 TEST_CASE(WeakPersistentHandleCallback) {
1419 Dart_Handle weak_ref = Dart_Null(); 1419 Dart_Handle weak_ref = Dart_Null();
1420 EXPECT(Dart_IsNull(weak_ref)); 1420 EXPECT(Dart_IsNull(weak_ref));
1421 int* peer = new int(); 1421 int peer = 0;
1422 { 1422 {
1423 Dart_EnterScope(); 1423 Dart_EnterScope();
1424 Dart_Handle obj = Dart_NewString("new string"); 1424 Dart_Handle obj = Dart_NewString("new string");
1425 EXPECT_VALID(obj); 1425 EXPECT_VALID(obj);
1426 weak_ref = Dart_NewWeakPersistentHandle(obj, peer, 1426 weak_ref = Dart_NewWeakPersistentHandle(obj, &peer,
1427 WeakPersistentHandlePeerFinalizer); 1427 WeakPersistentHandlePeerFinalizer);
1428 Dart_ExitScope(); 1428 Dart_ExitScope();
1429 } 1429 }
1430 EXPECT_VALID(weak_ref); 1430 EXPECT_VALID(weak_ref);
1431 EXPECT(*peer == 0); 1431 EXPECT(peer == 0);
1432 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); 1432 Isolate::Current()->heap()->CollectGarbage(Heap::kOld);
1433 EXPECT(*peer == 0); 1433 EXPECT(peer == 0);
1434 GCTestHelper::CollectNewSpace(Heap::kIgnoreApiCallbacks); 1434 GCTestHelper::CollectNewSpace(Heap::kIgnoreApiCallbacks);
1435 EXPECT(*peer == 42); 1435 EXPECT(peer == 42);
1436 delete peer;
1437 Dart_DeletePersistentHandle(weak_ref); 1436 Dart_DeletePersistentHandle(weak_ref);
1438 } 1437 }
1439 1438
1440 1439
1440 TEST_CASE(WeakPersistentHandleNoCallback) {
1441 Dart_Handle weak_ref = Dart_Null();
1442 EXPECT(Dart_IsNull(weak_ref));
1443 int peer = 0;
1444 {
1445 Dart_EnterScope();
1446 Dart_Handle obj = Dart_NewString("new string");
1447 EXPECT_VALID(obj);
1448 weak_ref = Dart_NewWeakPersistentHandle(obj, &peer,
1449 WeakPersistentHandlePeerFinalizer);
1450 Dart_ExitScope();
1451 }
1452 // A finalizer is not invoked on a deleted handle. Therefore, the
1453 // peer value should not change after the referent is collected.
1454 Dart_DeletePersistentHandle(weak_ref);
1455 EXPECT_VALID(weak_ref);
1456 EXPECT(peer == 0);
1457 Isolate::Current()->heap()->CollectGarbage(Heap::kOld);
1458 EXPECT(peer == 0);
1459 GCTestHelper::CollectNewSpace(Heap::kIgnoreApiCallbacks);
1460 EXPECT(peer == 0);
1461 }
1462
1463
1441 TEST_CASE(ObjectGroups) { 1464 TEST_CASE(ObjectGroups) {
1442 Dart_Handle strong = Dart_Null(); 1465 Dart_Handle strong = Dart_Null();
1443 EXPECT(Dart_IsNull(strong)); 1466 EXPECT(Dart_IsNull(strong));
1444 1467
1445 Dart_Handle weak1 = Dart_Null(); 1468 Dart_Handle weak1 = Dart_Null();
1446 EXPECT(Dart_IsNull(weak1)); 1469 EXPECT(Dart_IsNull(weak1));
1447 1470
1448 Dart_Handle weak2 = Dart_Null(); 1471 Dart_Handle weak2 = Dart_Null();
1449 EXPECT(Dart_IsNull(weak2)); 1472 EXPECT(Dart_IsNull(weak2));
1450 1473
(...skipping 5041 matching lines...) Expand 10 before | Expand all | Expand 10 after
6492 EXPECT(Dart_IsString(str)); 6515 EXPECT(Dart_IsString(str));
6493 len = -1; 6516 len = -1;
6494 EXPECT_VALID(Dart_StringLength(str, &len)); 6517 EXPECT_VALID(Dart_StringLength(str, &len));
6495 EXPECT_EQ(0, len); 6518 EXPECT_EQ(0, len);
6496 } 6519 }
6497 6520
6498 6521
6499 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). 6522 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64).
6500 6523
6501 } // namespace dart 6524 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698