OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <stdio.h> | 5 #include <stdio.h> |
6 #include <string.h> | 6 #include <string.h> |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 struct CloserCallbackPeer { | 120 struct CloserCallbackPeer { |
121 MojoHandle handle; | 121 MojoHandle handle; |
122 }; | 122 }; |
123 | 123 |
124 static void MojoHandleCloserCallback(void* isolate_data, | 124 static void MojoHandleCloserCallback(void* isolate_data, |
125 Dart_WeakPersistentHandle handle, | 125 Dart_WeakPersistentHandle handle, |
126 void* peer) { | 126 void* peer) { |
127 CloserCallbackPeer* callback_peer = | 127 CloserCallbackPeer* callback_peer = |
128 reinterpret_cast<CloserCallbackPeer*>(peer); | 128 reinterpret_cast<CloserCallbackPeer*>(peer); |
129 if (callback_peer->handle != MOJO_HANDLE_INVALID) { | 129 if (callback_peer->handle != MOJO_HANDLE_INVALID) { |
130 MojoResult res = MojoClose(callback_peer->handle); | 130 MojoClose(callback_peer->handle); |
131 if (res == MOJO_RESULT_OK) { | |
132 // If this finalizer callback successfully closes a handle, it means that | |
133 // the handle has leaked from the Dart code, which is an error. | |
134 MOJO_LOG(ERROR) << "Handle Finalizer closing handle:\n\tisolate: " | |
135 << "\n\thandle: " << callback_peer->handle; | |
136 } | |
137 } | 131 } |
138 delete callback_peer; | 132 delete callback_peer; |
139 } | 133 } |
140 | 134 |
141 // Setup a weak persistent handle for a MojoHandle that calls MojoClose on the | 135 // Setup a weak persistent handle for a MojoHandle that calls MojoClose on the |
142 // handle when the MojoHandle is GC'd or the VM is going down. | 136 // handle when the MojoHandle is GC'd or the VM is going down. |
143 void MojoHandle_RegisterFinalizer(Dart_NativeArguments arguments) { | 137 void MojoHandle_RegisterFinalizer(Dart_NativeArguments arguments) { |
144 Dart_Handle mojo_handle_instance = Dart_GetNativeArgument(arguments, 0); | 138 Dart_Handle mojo_handle_instance = Dart_GetNativeArgument(arguments, 0); |
145 if (!Dart_IsInstance(mojo_handle_instance)) { | 139 if (!Dart_IsInstance(mojo_handle_instance)) { |
146 SetInvalidArgumentReturn(arguments); | 140 SetInvalidArgumentReturn(arguments); |
(...skipping 869 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1016 mojo_control_handle = control_handle; | 1010 mojo_control_handle = control_handle; |
1017 Dart_SetIntegerReturnValue(arguments, static_cast<int64_t>(MOJO_RESULT_OK)); | 1011 Dart_SetIntegerReturnValue(arguments, static_cast<int64_t>(MOJO_RESULT_OK)); |
1018 } | 1012 } |
1019 | 1013 |
1020 void MojoHandleWatcher_GetControlHandle(Dart_NativeArguments arguments) { | 1014 void MojoHandleWatcher_GetControlHandle(Dart_NativeArguments arguments) { |
1021 Dart_SetIntegerReturnValue(arguments, mojo_control_handle); | 1015 Dart_SetIntegerReturnValue(arguments, mojo_control_handle); |
1022 } | 1016 } |
1023 | 1017 |
1024 } // namespace dart | 1018 } // namespace dart |
1025 } // namespace mojo | 1019 } // namespace mojo |
OLD | NEW |