Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 #ifndef RUNTIME_VM_DART_API_IMPL_H_ | 5 #ifndef RUNTIME_VM_DART_API_IMPL_H_ |
| 6 #define RUNTIME_VM_DART_API_IMPL_H_ | 6 #define RUNTIME_VM_DART_API_IMPL_H_ |
| 7 | 7 |
| 8 #include "vm/allocation.h" | 8 #include "vm/allocation.h" |
| 9 #include "vm/native_arguments.h" | 9 #include "vm/native_arguments.h" |
| 10 #include "vm/object.h" | 10 #include "vm/object.h" |
| 11 #include "vm/safepoint.h" | 11 #include "vm/safepoint.h" |
| 12 #include "vm/thread_registry.h" | |
| 12 | 13 |
| 13 namespace dart { | 14 namespace dart { |
| 14 | 15 |
| 15 class ApiLocalScope; | 16 class ApiLocalScope; |
| 16 class ApiState; | 17 class ApiState; |
| 17 class FinalizablePersistentHandle; | 18 class FinalizablePersistentHandle; |
| 18 class LocalHandle; | 19 class LocalHandle; |
| 19 class PersistentHandle; | 20 class PersistentHandle; |
| 20 class ReusableObjectHandleScope; | 21 class ReusableObjectHandleScope; |
| 22 class ThreadRegistry; | |
| 21 | 23 |
| 22 const char* CanonicalFunction(const char* func); | 24 const char* CanonicalFunction(const char* func); |
| 23 | 25 |
| 24 #define CURRENT_FUNC CanonicalFunction(__FUNCTION__) | 26 #define CURRENT_FUNC CanonicalFunction(__FUNCTION__) |
| 25 | 27 |
| 26 // Checks that the current isolate is not NULL. | 28 // Checks that the current isolate is not NULL. |
| 27 #define CHECK_ISOLATE(isolate) \ | 29 #define CHECK_ISOLATE(isolate) \ |
| 28 do { \ | 30 do { \ |
| 29 if ((isolate) == NULL) { \ | 31 if ((isolate) == NULL) { \ |
| 30 FATAL1( \ | 32 FATAL1( \ |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 159 // TODO(turnidge): Assumes RawObject* is at offset zero. Fix. | 161 // TODO(turnidge): Assumes RawObject* is at offset zero. Fix. |
| 160 RawObject* raw = *(reinterpret_cast<RawObject**>(handle)); | 162 RawObject* raw = *(reinterpret_cast<RawObject**>(handle)); |
| 161 return !raw->IsHeapObject(); | 163 return !raw->IsHeapObject(); |
| 162 } | 164 } |
| 163 | 165 |
| 164 // Returns true if the handle holds a Dart Instance. | 166 // Returns true if the handle holds a Dart Instance. |
| 165 static bool IsInstance(Dart_Handle handle) { | 167 static bool IsInstance(Dart_Handle handle) { |
| 166 return (ClassId(handle) >= kInstanceCid); | 168 return (ClassId(handle) >= kInstanceCid); |
| 167 } | 169 } |
| 168 | 170 |
| 171 // Returns true if the handle is non-dangling. | |
| 172 static bool IsValid(Dart_Handle handle) { | |
| 173 Isolate* isolate = Isolate::Current(); | |
| 174 CHECK_ISOLATE(isolate); | |
| 175 | |
| 176 // Check against all of the handles in the current isolate as well as the | |
| 177 // read-only handles. | |
| 178 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
| |
| 179 Dart::IsReadOnlyApiHandle(handle) || | |
| 180 Dart::IsReadOnlyHandle(reinterpret_cast<uword>(handle)); | |
| 181 } | |
| 182 | |
| 169 // Returns true if the handle holds an Error. | 183 // Returns true if the handle holds an Error. |
| 170 static bool IsError(Dart_Handle handle) { | 184 static bool IsError(Dart_Handle handle) { |
| 171 return RawObject::IsErrorClassId(ClassId(handle)); | 185 return RawObject::IsErrorClassId(ClassId(handle)); |
| 172 } | 186 } |
| 173 | 187 |
| 174 // Returns the value of a Smi. | 188 // Returns the value of a Smi. |
| 175 static intptr_t SmiValue(Dart_Handle handle) { | 189 static intptr_t SmiValue(Dart_Handle handle) { |
| 176 // TODO(turnidge): Assumes RawObject* is at offset zero. Fix. | 190 // TODO(turnidge): Assumes RawObject* is at offset zero. Fix. |
| 177 uword value = *(reinterpret_cast<uword*>(handle)); | 191 uword value = *(reinterpret_cast<uword*>(handle)); |
| 178 return Smi::ValueFromRaw(value); | 192 return Smi::ValueFromRaw(value); |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 291 return Api::NewError("%s: Cannot load after Dart_Precompile", \ | 305 return Api::NewError("%s: Cannot load after Dart_Precompile", \ |
| 292 CURRENT_FUNC); \ | 306 CURRENT_FUNC); \ |
| 293 } | 307 } |
| 294 | 308 |
| 295 #define ASSERT_CALLBACK_STATE(thread) \ | 309 #define ASSERT_CALLBACK_STATE(thread) \ |
| 296 ASSERT(thread->no_callback_scope_depth() == 0) | 310 ASSERT(thread->no_callback_scope_depth() == 0) |
| 297 | 311 |
| 298 } // namespace dart. | 312 } // namespace dart. |
| 299 | 313 |
| 300 #endif // RUNTIME_VM_DART_API_IMPL_H_ | 314 #endif // RUNTIME_VM_DART_API_IMPL_H_ |
| OLD | NEW |