| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 "include/dart_api.h" | 5 #include "include/dart_api.h" |
| 6 #include "include/dart_mirrors_api.h" | 6 #include "include/dart_mirrors_api.h" |
| 7 #include "include/dart_native_api.h" | 7 #include "include/dart_native_api.h" |
| 8 | 8 |
| 9 #include "platform/assert.h" | 9 #include "platform/assert.h" |
| 10 #include "vm/bigint_operations.h" | 10 #include "vm/bigint_operations.h" |
| (...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 364 ApiState* state = Isolate::Current()->api_state(); | 364 ApiState* state = Isolate::Current()->api_state(); |
| 365 ASSERT(state->IsValidWeakPersistentHandle(handle) || | 365 ASSERT(state->IsValidWeakPersistentHandle(handle) || |
| 366 state->IsValidPrologueWeakPersistentHandle(handle)); | 366 state->IsValidPrologueWeakPersistentHandle(handle)); |
| 367 #endif | 367 #endif |
| 368 uword addr = reinterpret_cast<uword>(handle); | 368 uword addr = reinterpret_cast<uword>(handle); |
| 369 return reinterpret_cast<FinalizablePersistentHandle*>( | 369 return reinterpret_cast<FinalizablePersistentHandle*>( |
| 370 addr & ~kWeakPersistentTagMask); | 370 addr & ~kWeakPersistentTagMask); |
| 371 } | 371 } |
| 372 | 372 |
| 373 | 373 |
| 374 void FinalizablePersistentHandle::Finalize(Isolate* isolate, |
| 375 FinalizablePersistentHandle* handle, |
| 376 bool is_prologue_weak) { |
| 377 if (!handle->raw()->IsHeapObject()) { |
| 378 return; |
| 379 } |
| 380 Dart_WeakPersistentHandleFinalizer callback = handle->callback(); |
| 381 ASSERT(callback != NULL); |
| 382 void* peer = handle->peer(); |
| 383 Dart_WeakPersistentHandle object = is_prologue_weak ? |
| 384 handle->apiPrologueHandle() : |
| 385 handle->apiHandle(); |
| 386 (*callback)(isolate->init_callback_data(), object, peer); |
| 387 ApiState* state = isolate->api_state(); |
| 388 ASSERT(state != NULL); |
| 389 if (is_prologue_weak) { |
| 390 state->prologue_weak_persistent_handles().FreeHandle(handle); |
| 391 } else { |
| 392 state->weak_persistent_handles().FreeHandle(handle); |
| 393 } |
| 394 } |
| 395 |
| 396 |
| 374 // --- Handles --- | 397 // --- Handles --- |
| 375 | 398 |
| 376 DART_EXPORT bool Dart_IsError(Dart_Handle handle) { | 399 DART_EXPORT bool Dart_IsError(Dart_Handle handle) { |
| 377 TRACE_API_CALL(CURRENT_FUNC); | 400 TRACE_API_CALL(CURRENT_FUNC); |
| 378 return RawObject::IsErrorClassId(Api::ClassId(handle)); | 401 return RawObject::IsErrorClassId(Api::ClassId(handle)); |
| 379 } | 402 } |
| 380 | 403 |
| 381 | 404 |
| 382 DART_EXPORT bool Dart_IsApiError(Dart_Handle object) { | 405 DART_EXPORT bool Dart_IsApiError(Dart_Handle object) { |
| 383 TRACE_API_CALL(CURRENT_FUNC); | 406 TRACE_API_CALL(CURRENT_FUNC); |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 647 } | 670 } |
| 648 | 671 |
| 649 | 672 |
| 650 DART_EXPORT Dart_WeakPersistentHandle Dart_NewWeakPersistentHandle( | 673 DART_EXPORT Dart_WeakPersistentHandle Dart_NewWeakPersistentHandle( |
| 651 Dart_Handle object, | 674 Dart_Handle object, |
| 652 void* peer, | 675 void* peer, |
| 653 intptr_t external_allocation_size, | 676 intptr_t external_allocation_size, |
| 654 Dart_WeakPersistentHandleFinalizer callback) { | 677 Dart_WeakPersistentHandleFinalizer callback) { |
| 655 Isolate* isolate = Isolate::Current(); | 678 Isolate* isolate = Isolate::Current(); |
| 656 CHECK_ISOLATE(isolate); | 679 CHECK_ISOLATE(isolate); |
| 680 if (callback == NULL) { |
| 681 return NULL; |
| 682 } |
| 657 return AllocateFinalizableHandle(isolate, | 683 return AllocateFinalizableHandle(isolate, |
| 658 object, | 684 object, |
| 659 false, | 685 false, |
| 660 peer, | 686 peer, |
| 661 external_allocation_size, | 687 external_allocation_size, |
| 662 callback); | 688 callback); |
| 663 } | 689 } |
| 664 | 690 |
| 665 | 691 |
| 666 DART_EXPORT Dart_WeakPersistentHandle Dart_NewPrologueWeakPersistentHandle( | 692 DART_EXPORT Dart_WeakPersistentHandle Dart_NewPrologueWeakPersistentHandle( |
| 667 Dart_Handle object, | 693 Dart_Handle object, |
| 668 void* peer, | 694 void* peer, |
| 669 intptr_t external_allocation_size, | 695 intptr_t external_allocation_size, |
| 670 Dart_WeakPersistentHandleFinalizer callback) { | 696 Dart_WeakPersistentHandleFinalizer callback) { |
| 671 Isolate* isolate = Isolate::Current(); | 697 Isolate* isolate = Isolate::Current(); |
| 672 CHECK_ISOLATE(isolate); | 698 CHECK_ISOLATE(isolate); |
| 699 if (callback == NULL) { |
| 700 return NULL; |
| 701 } |
| 673 return AllocateFinalizableHandle(isolate, | 702 return AllocateFinalizableHandle(isolate, |
| 674 object, | 703 object, |
| 675 true, | 704 true, |
| 676 peer, | 705 peer, |
| 677 external_allocation_size, | 706 external_allocation_size, |
| 678 callback); | 707 callback); |
| 679 } | 708 } |
| 680 | 709 |
| 681 | 710 |
| 682 DART_EXPORT void Dart_DeletePersistentHandle(Dart_PersistentHandle object) { | 711 DART_EXPORT void Dart_DeletePersistentHandle(Dart_PersistentHandle object) { |
| (...skipping 3945 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4628 | 4657 |
| 4629 | 4658 |
| 4630 DART_EXPORT void Dart_RegisterRootServiceRequestCallback( | 4659 DART_EXPORT void Dart_RegisterRootServiceRequestCallback( |
| 4631 const char* name, | 4660 const char* name, |
| 4632 Dart_ServiceRequestCallback callback, | 4661 Dart_ServiceRequestCallback callback, |
| 4633 void* user_data) { | 4662 void* user_data) { |
| 4634 Service::RegisterRootEmbedderCallback(name, callback, user_data); | 4663 Service::RegisterRootEmbedderCallback(name, callback, user_data); |
| 4635 } | 4664 } |
| 4636 | 4665 |
| 4637 } // namespace dart | 4666 } // namespace dart |
| OLD | NEW |