Chromium Code Reviews| Index: runtime/vm/dart_api_impl.h |
| diff --git a/runtime/vm/dart_api_impl.h b/runtime/vm/dart_api_impl.h |
| index f597ca29d4e782aec56cab3c99d5d6b0654985c4..a1b8ded132a8038969b0663283ab75f141fca62b 100644 |
| --- a/runtime/vm/dart_api_impl.h |
| +++ b/runtime/vm/dart_api_impl.h |
| @@ -9,6 +9,7 @@ |
| #include "vm/native_arguments.h" |
| #include "vm/object.h" |
| #include "vm/safepoint.h" |
| +#include "vm/thread_registry.h" |
| namespace dart { |
| @@ -18,6 +19,7 @@ class FinalizablePersistentHandle; |
| class LocalHandle; |
| class PersistentHandle; |
| class ReusableObjectHandleScope; |
| +class ThreadRegistry; |
| const char* CanonicalFunction(const char* func); |
| @@ -166,6 +168,18 @@ class Api : AllStatic { |
| return (ClassId(handle) >= kInstanceCid); |
| } |
| + // Returns true if the handle is non-dangling. |
| + static bool IsValid(Dart_Handle handle) { |
| + Isolate* isolate = Isolate::Current(); |
| + CHECK_ISOLATE(isolate); |
| + |
| + // Check against all of the handles in the current isolate as well as the |
| + // read-only handles. |
| + return isolate->thread_registry()->IsValidHandle(handle) || |
|
bkonyi
2017/01/18 00:44:47
I'm not sure if I should be checking to see if any
Cutch
2017/01/18 14:49:51
In general our API always interacts with the curre
|
| + Dart::IsReadOnlyApiHandle(handle) || |
| + Dart::IsReadOnlyHandle(reinterpret_cast<uword>(handle)); |
| + } |
| + |
| // Returns true if the handle holds an Error. |
| static bool IsError(Dart_Handle handle) { |
| return RawObject::IsErrorClassId(ClassId(handle)); |