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

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

Issue 186003002: Pass in the isolate parameter to the weak persistent callback handler so that (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 9 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') | runtime/vm/dart_api_state.h » ('j') | 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_debugger_api.h" 7 #include "include/dart_debugger_api.h"
8 #include "include/dart_mirrors_api.h" 8 #include "include/dart_mirrors_api.h"
9 #include "include/dart_native_api.h" 9 #include "include/dart_native_api.h"
10 #include "platform/assert.h" 10 #include "platform/assert.h"
(...skipping 1678 matching lines...) Expand 10 before | Expand all | Expand 10 after
1689 // Check that result is true. 1689 // Check that result is true.
1690 EXPECT_VALID(result); 1690 EXPECT_VALID(result);
1691 EXPECT(Dart_IsBoolean(result)); 1691 EXPECT(Dart_IsBoolean(result));
1692 bool value = false; 1692 bool value = false;
1693 result = Dart_BooleanValue(result, &value); 1693 result = Dart_BooleanValue(result, &value);
1694 EXPECT_VALID(result); 1694 EXPECT_VALID(result);
1695 EXPECT(value); 1695 EXPECT(value);
1696 } 1696 }
1697 1697
1698 1698
1699 static void ExternalTypedDataFinalizer(Dart_WeakPersistentHandle handle, 1699 static void ExternalTypedDataFinalizer(Dart_Isolate isolate,
1700 void* peer) { 1700 Dart_WeakPersistentHandle handle,
1701 Dart_DeleteWeakPersistentHandle(handle); 1701 void* peer) {
1702 Dart_DeleteWeakPersistentHandle(isolate, handle);
1702 *static_cast<int*>(peer) = 42; 1703 *static_cast<int*>(peer) = 42;
1703 } 1704 }
1704 1705
1705 1706
1706 TEST_CASE(ExternalTypedDataCallback) { 1707 TEST_CASE(ExternalTypedDataCallback) {
1707 int peer = 0; 1708 int peer = 0;
1708 { 1709 {
1709 Dart_EnterScope(); 1710 Dart_EnterScope();
1710 uint8_t data[] = { 1, 2, 3, 4 }; 1711 uint8_t data[] = { 1, 2, 3, 4 };
1711 Dart_Handle obj = Dart_NewExternalTypedData( 1712 Dart_Handle obj = Dart_NewExternalTypedData(
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
2044 { 2045 {
2045 Dart_EnterScope(); 2046 Dart_EnterScope();
2046 // Weak ref to old space object should now be cleared. 2047 // Weak ref to old space object should now be cleared.
2047 EXPECT_VALID(AsHandle(weak_new_ref)); 2048 EXPECT_VALID(AsHandle(weak_new_ref));
2048 EXPECT(Dart_IsNull(AsHandle(weak_new_ref))); 2049 EXPECT(Dart_IsNull(AsHandle(weak_new_ref)));
2049 EXPECT_VALID(AsHandle(weak_old_ref)); 2050 EXPECT_VALID(AsHandle(weak_old_ref));
2050 EXPECT(Dart_IsNull(AsHandle(weak_old_ref))); 2051 EXPECT(Dart_IsNull(AsHandle(weak_old_ref)));
2051 Dart_ExitScope(); 2052 Dart_ExitScope();
2052 } 2053 }
2053 2054
2054 Dart_DeleteWeakPersistentHandle(weak_new_ref); 2055 Dart_Isolate isolate = reinterpret_cast<Dart_Isolate>(Isolate::Current());
2055 Dart_DeleteWeakPersistentHandle(weak_old_ref); 2056 Dart_DeleteWeakPersistentHandle(isolate, weak_new_ref);
2057 Dart_DeleteWeakPersistentHandle(isolate, weak_old_ref);
2056 2058
2057 // Garbage collect one last time to revisit deleted handles. 2059 // Garbage collect one last time to revisit deleted handles.
2058 Isolate::Current()->heap()->CollectGarbage(Heap::kNew); 2060 Isolate::Current()->heap()->CollectGarbage(Heap::kNew);
2059 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); 2061 Isolate::Current()->heap()->CollectGarbage(Heap::kOld);
2060 } 2062 }
2061 2063
2062 2064
2063 static void WeakPersistentHandlePeerFinalizer( 2065 static void WeakPersistentHandlePeerFinalizer(Dart_Isolate isolate,
2064 Dart_WeakPersistentHandle handle, void* peer) { 2066 Dart_WeakPersistentHandle handle,
2067 void* peer) {
2065 *static_cast<int*>(peer) = 42; 2068 *static_cast<int*>(peer) = 42;
2066 } 2069 }
2067 2070
2068 2071
2069 TEST_CASE(WeakPersistentHandleCallback) { 2072 TEST_CASE(WeakPersistentHandleCallback) {
2070 Dart_WeakPersistentHandle weak_ref = NULL; 2073 Dart_WeakPersistentHandle weak_ref = NULL;
2071 int peer = 0; 2074 int peer = 0;
2072 { 2075 {
2073 Dart_EnterScope(); 2076 Dart_EnterScope();
2074 Dart_Handle obj = NewString("new string"); 2077 Dart_Handle obj = NewString("new string");
2075 EXPECT_VALID(obj); 2078 EXPECT_VALID(obj);
2076 weak_ref = Dart_NewWeakPersistentHandle(obj, &peer, 2079 weak_ref = Dart_NewWeakPersistentHandle(obj, &peer,
2077 WeakPersistentHandlePeerFinalizer); 2080 WeakPersistentHandlePeerFinalizer);
2078 EXPECT_VALID(AsHandle(weak_ref)); 2081 EXPECT_VALID(AsHandle(weak_ref));
2079 EXPECT(peer == 0); 2082 EXPECT(peer == 0);
2080 Dart_ExitScope(); 2083 Dart_ExitScope();
2081 } 2084 }
2082 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); 2085 Isolate::Current()->heap()->CollectGarbage(Heap::kOld);
2083 EXPECT(peer == 0); 2086 EXPECT(peer == 0);
2084 GCTestHelper::CollectNewSpace(Heap::kIgnoreApiCallbacks); 2087 GCTestHelper::CollectNewSpace(Heap::kIgnoreApiCallbacks);
2085 EXPECT(peer == 42); 2088 EXPECT(peer == 42);
2086 Dart_DeleteWeakPersistentHandle(weak_ref); 2089 Dart_Isolate isolate = reinterpret_cast<Dart_Isolate>(Isolate::Current());
2090 Dart_DeleteWeakPersistentHandle(isolate, weak_ref);
2087 } 2091 }
2088 2092
2089 2093
2090 TEST_CASE(WeakPersistentHandleNoCallback) { 2094 TEST_CASE(WeakPersistentHandleNoCallback) {
2091 Dart_WeakPersistentHandle weak_ref = NULL; 2095 Dart_WeakPersistentHandle weak_ref = NULL;
2092 int peer = 0; 2096 int peer = 0;
2093 { 2097 {
2094 Dart_EnterScope(); 2098 Dart_EnterScope();
2095 Dart_Handle obj = NewString("new string"); 2099 Dart_Handle obj = NewString("new string");
2096 EXPECT_VALID(obj); 2100 EXPECT_VALID(obj);
2097 weak_ref = Dart_NewWeakPersistentHandle(obj, &peer, 2101 weak_ref = Dart_NewWeakPersistentHandle(obj, &peer,
2098 WeakPersistentHandlePeerFinalizer); 2102 WeakPersistentHandlePeerFinalizer);
2099 Dart_ExitScope(); 2103 Dart_ExitScope();
2100 } 2104 }
2101 // A finalizer is not invoked on a deleted handle. Therefore, the 2105 // A finalizer is not invoked on a deleted handle. Therefore, the
2102 // peer value should not change after the referent is collected. 2106 // peer value should not change after the referent is collected.
2103 Dart_DeleteWeakPersistentHandle(weak_ref); 2107 Dart_Isolate isolate = reinterpret_cast<Dart_Isolate>(Isolate::Current());
2108 Dart_DeleteWeakPersistentHandle(isolate, weak_ref);
2104 EXPECT(peer == 0); 2109 EXPECT(peer == 0);
2105 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); 2110 Isolate::Current()->heap()->CollectGarbage(Heap::kOld);
2106 EXPECT(peer == 0); 2111 EXPECT(peer == 0);
2107 GCTestHelper::CollectNewSpace(Heap::kIgnoreApiCallbacks); 2112 GCTestHelper::CollectNewSpace(Heap::kIgnoreApiCallbacks);
2108 EXPECT(peer == 0); 2113 EXPECT(peer == 0);
2109 } 2114 }
2110 2115
2111 2116
2112 UNIT_TEST_CASE(WeakPersistentHandlesCallbackShutdown) { 2117 UNIT_TEST_CASE(WeakPersistentHandlesCallbackShutdown) {
2113 TestCase::CreateTestIsolate(); 2118 TestCase::CreateTestIsolate();
(...skipping 5798 matching lines...) Expand 10 before | Expand all | Expand 10 after
7912 NewString("main"), 7917 NewString("main"),
7913 1, 7918 1,
7914 dart_args); 7919 dart_args);
7915 int64_t value = 0; 7920 int64_t value = 0;
7916 result = Dart_IntegerToInt64(result, &value); 7921 result = Dart_IntegerToInt64(result, &value);
7917 EXPECT_VALID(result); 7922 EXPECT_VALID(result);
7918 EXPECT_EQ(6, value); 7923 EXPECT_EQ(6, value);
7919 } 7924 }
7920 7925
7921 } // namespace dart 7926 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/dart_api_impl.cc ('k') | runtime/vm/dart_api_state.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698