Index: mojo/dart/embedder/mojo_natives.cc |
diff --git a/mojo/dart/embedder/mojo_natives.cc b/mojo/dart/embedder/mojo_natives.cc |
index 2546dece72632f441f6e4178fff22a938426b3f3..530945ca8ea8eee664b0fe758b5bfe93b3510f9b 100644 |
--- a/mojo/dart/embedder/mojo_natives.cc |
+++ b/mojo/dart/embedder/mojo_natives.cc |
@@ -4,6 +4,7 @@ |
#include <stdio.h> |
#include <string.h> |
+#include <set> |
#include <vector> |
#include "base/logging.h" |
@@ -11,6 +12,7 @@ |
#include "base/memory/scoped_ptr.h" |
#include "dart/runtime/include/dart_api.h" |
#include "mojo/dart/embedder/builtin.h" |
+#include "mojo/dart/embedder/isolate_data.h" |
#include "mojo/public/c/system/core.h" |
#include "mojo/public/cpp/system/core.h" |
@@ -122,7 +124,11 @@ static void MojoHandleCloserCallback(void* isolate_data, |
CloserCallbackPeer* callback_peer = |
reinterpret_cast<CloserCallbackPeer*>(peer); |
if (callback_peer->handle != MOJO_HANDLE_INVALID) { |
- MojoClose(callback_peer->handle); |
+ MojoResult res = MojoClose(callback_peer->handle); |
+ if (res == MOJO_RESULT_OK) { |
+ LOG(ERROR) << "Handle Finalizer closing handle:\n\tisolate: " |
sky
2015/03/11 17:17:57
Why the LOG(ERROR) here? Doesn't MOJO_RESULT_OK me
zra
2015/03/11 18:58:20
If the finalizer callback successfully closes a ha
|
+ << "\n\thandle: " << callback_peer->handle; |
+ } |
} |
delete callback_peer; |
} |
@@ -167,6 +173,13 @@ void MojoHandle_Register(Dart_NativeArguments arguments) { |
return; |
} |
+ // Add the handle to this isolate's set. |
+ Dart_Isolate isolate = Dart_CurrentIsolate(); |
+ void* data = Dart_IsolateData(isolate); |
+ IsolateData* isolate_data = reinterpret_cast<IsolateData*>(data); |
+ isolate_data->unclosed_handles.insert(raw_handle); |
+ |
+ // Set up a finalizer. |
CloserCallbackPeer* callback_peer = new CloserCallbackPeer(); |
callback_peer->handle = static_cast<MojoHandle>(raw_handle); |
Dart_NewWeakPersistentHandle(mojo_handle_instance, |
@@ -180,6 +193,12 @@ void MojoHandle_Close(Dart_NativeArguments arguments) { |
int64_t handle; |
CHECK_INTEGER_ARGUMENT(arguments, 0, &handle, InvalidArgument); |
+ // Remove the handle from this isolate's set. |
+ Dart_Isolate isolate = Dart_CurrentIsolate(); |
+ void* data = Dart_IsolateData(isolate); |
+ IsolateData* isolate_data = reinterpret_cast<IsolateData*>(data); |
+ isolate_data->unclosed_handles.erase(handle); |
+ |
MojoResult res = MojoClose(static_cast<MojoHandle>(handle)); |
Dart_SetIntegerReturnValue(arguments, static_cast<int64_t>(res)); |