Chromium Code Reviews| 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 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 159 ASSERT(Isolate::Current()->api_state()->IsValidPersistentHandle(object)); | 159 ASSERT(Isolate::Current()->api_state()->IsValidPersistentHandle(object)); |
| 160 return reinterpret_cast<PersistentHandle*>(object); | 160 return reinterpret_cast<PersistentHandle*>(object); |
| 161 } | 161 } |
| 162 | 162 |
| 163 | 163 |
| 164 FinalizablePersistentHandle* Api::UnwrapAsWeakPersistentHandle( | 164 FinalizablePersistentHandle* Api::UnwrapAsWeakPersistentHandle( |
| 165 Dart_WeakPersistentHandle object) { | 165 Dart_WeakPersistentHandle object) { |
| 166 ASSERT(Isolate::Current()->api_state()->IsValidWeakPersistentHandle(object) || | 166 ASSERT(Isolate::Current()->api_state()->IsValidWeakPersistentHandle(object) || |
| 167 Isolate::Current()->api_state()-> | 167 Isolate::Current()->api_state()-> |
| 168 IsValidPrologueWeakPersistentHandle(object)); | 168 IsValidPrologueWeakPersistentHandle(object)); |
| 169 return reinterpret_cast<FinalizablePersistentHandle*>(object); | 169 return FinalizablePersistentHandle::AsFinalizablePersistentHandle(object); |
| 170 } | |
| 171 | |
| 172 | |
| 173 FinalizablePersistentHandle* Api::UnwrapAsPrologueWeakPersistentHandle( | |
| 174 Dart_WeakPersistentHandle object) { | |
| 175 ASSERT(Isolate::Current()->api_state()->IsValidPrologueWeakPersistentHandle( | |
| 176 object)); | |
| 177 return reinterpret_cast<FinalizablePersistentHandle*>(object); | |
| 178 } | 170 } |
| 179 | 171 |
| 180 | 172 |
| 181 Dart_Handle Api::CheckIsolateState(Isolate* isolate) { | 173 Dart_Handle Api::CheckIsolateState(Isolate* isolate) { |
| 182 if (!isolate->AllowClassFinalization()) { | 174 if (!isolate->AllowClassFinalization()) { |
| 183 // Class finalization is blocked for the isolate. Do nothing. | 175 // Class finalization is blocked for the isolate. Do nothing. |
| 184 return Api::Success(); | 176 return Api::Success(); |
| 185 } | 177 } |
| 186 if (ClassFinalizer::ProcessPendingClasses()) { | 178 if (ClassFinalizer::ProcessPendingClasses()) { |
| 187 return Api::Success(); | 179 return Api::Success(); |
| (...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 561 return false; | 553 return false; |
| 562 } | 554 } |
| 563 | 555 |
| 564 | 556 |
| 565 DART_EXPORT Dart_Handle Dart_HandleFromPersistent( | 557 DART_EXPORT Dart_Handle Dart_HandleFromPersistent( |
| 566 Dart_PersistentHandle object) { | 558 Dart_PersistentHandle object) { |
| 567 Isolate* isolate = Isolate::Current(); | 559 Isolate* isolate = Isolate::Current(); |
| 568 CHECK_ISOLATE(isolate); | 560 CHECK_ISOLATE(isolate); |
| 569 ApiState* state = isolate->api_state(); | 561 ApiState* state = isolate->api_state(); |
| 570 ASSERT(state != NULL); | 562 ASSERT(state != NULL); |
| 571 ASSERT(state->IsValidPersistentHandle(object)); | 563 PersistentHandle* ref = Api::UnwrapAsPersistentHandle(object); |
| 572 return Api::NewHandle(isolate, | 564 return Api::NewHandle(isolate, ref->raw()); |
| 573 reinterpret_cast<PersistentHandle*>(object)->raw()); | |
| 574 } | 565 } |
| 575 | 566 |
| 576 | 567 |
| 577 DART_EXPORT Dart_Handle Dart_HandleFromWeakPersistent( | 568 DART_EXPORT Dart_Handle Dart_HandleFromWeakPersistent( |
| 578 Dart_WeakPersistentHandle object) { | 569 Dart_WeakPersistentHandle object) { |
| 579 Isolate* isolate = Isolate::Current(); | 570 Isolate* isolate = Isolate::Current(); |
| 580 CHECK_ISOLATE(isolate); | 571 CHECK_ISOLATE(isolate); |
| 581 ApiState* state = isolate->api_state(); | 572 ApiState* state = isolate->api_state(); |
| 582 ASSERT(state != NULL); | 573 ASSERT(state != NULL); |
| 583 ASSERT(state->IsValidWeakPersistentHandle(object) || | 574 FinalizablePersistentHandle* weak_ref = |
| 584 state->IsValidPrologueWeakPersistentHandle(object)); | 575 Api::UnwrapAsWeakPersistentHandle(object); |
| 585 return Api::NewHandle( | 576 return Api::NewHandle(isolate, weak_ref->raw()); |
| 586 isolate, reinterpret_cast<FinalizablePersistentHandle*>(object)->raw()); | |
| 587 } | 577 } |
| 588 | 578 |
| 589 | 579 |
| 590 DART_EXPORT Dart_PersistentHandle Dart_NewPersistentHandle(Dart_Handle object) { | 580 DART_EXPORT Dart_PersistentHandle Dart_NewPersistentHandle(Dart_Handle object) { |
| 591 Isolate* isolate = Isolate::Current(); | 581 Isolate* isolate = Isolate::Current(); |
| 592 DARTSCOPE(isolate); | 582 DARTSCOPE(isolate); |
| 593 ApiState* state = isolate->api_state(); | 583 ApiState* state = isolate->api_state(); |
| 594 ASSERT(state != NULL); | 584 ASSERT(state != NULL); |
| 595 const Object& old_ref = Object::Handle(isolate, Api::UnwrapHandle(object)); | 585 const Object& old_ref = Object::Handle(isolate, Api::UnwrapHandle(object)); |
| 596 PersistentHandle* new_ref = state->persistent_handles().AllocateHandle(); | 586 PersistentHandle* new_ref = state->persistent_handles().AllocateHandle(); |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 609 const Object& obj2_ref = Object::Handle(isolate, Api::UnwrapHandle(obj2)); | 599 const Object& obj2_ref = Object::Handle(isolate, Api::UnwrapHandle(obj2)); |
| 610 PersistentHandle* obj1_ref = Api::UnwrapAsPersistentHandle(obj1); | 600 PersistentHandle* obj1_ref = Api::UnwrapAsPersistentHandle(obj1); |
| 611 obj1_ref->set_raw(obj2_ref); | 601 obj1_ref->set_raw(obj2_ref); |
| 612 } | 602 } |
| 613 | 603 |
| 614 | 604 |
| 615 static Dart_WeakPersistentHandle AllocateFinalizableHandle( | 605 static Dart_WeakPersistentHandle AllocateFinalizableHandle( |
| 616 Isolate* isolate, | 606 Isolate* isolate, |
| 617 FinalizablePersistentHandles* handles, | 607 FinalizablePersistentHandles* handles, |
| 618 Dart_Handle object, | 608 Dart_Handle object, |
| 609 bool is_prologue, | |
| 619 void* peer, | 610 void* peer, |
| 620 Dart_WeakPersistentHandleFinalizer callback) { | 611 Dart_WeakPersistentHandleFinalizer callback) { |
| 621 ReusableObjectHandleScope reused_obj_handle(isolate); | 612 ReusableObjectHandleScope reused_obj_handle(isolate); |
| 622 Object& ref = reused_obj_handle.Handle(); | 613 Object& ref = reused_obj_handle.Handle(); |
| 623 ref = Api::UnwrapHandle(object); | 614 ref = Api::UnwrapHandle(object); |
| 624 FinalizablePersistentHandle* finalizable_ref = handles->AllocateHandle(); | 615 FinalizablePersistentHandle* finalizable_ref = handles->AllocateHandle(); |
|
Ivan Posva
2014/03/03 21:00:19
The list should also be selected by the is_prologu
siva
2014/03/04 00:24:48
Done.
| |
| 625 finalizable_ref->set_raw(ref); | 616 finalizable_ref->set_raw(ref); |
| 626 finalizable_ref->set_peer(peer); | 617 finalizable_ref->set_peer(peer); |
| 627 finalizable_ref->set_callback(callback); | 618 finalizable_ref->set_callback(callback); |
| 628 return reinterpret_cast<Dart_WeakPersistentHandle>(finalizable_ref); | 619 if (is_prologue) { |
| 620 return FinalizablePersistentHandle:: | |
| 621 AsDartPrologueWeakPersistentHandle(finalizable_ref); | |
| 622 } else { | |
| 623 return FinalizablePersistentHandle:: | |
| 624 AsDartWeakPersistentHandle(finalizable_ref); | |
| 625 } | |
| 629 } | 626 } |
| 630 | 627 |
| 631 | 628 |
| 632 DART_EXPORT Dart_WeakPersistentHandle Dart_NewWeakPersistentHandle( | 629 DART_EXPORT Dart_WeakPersistentHandle Dart_NewWeakPersistentHandle( |
| 633 Dart_Handle object, | 630 Dart_Handle object, |
| 634 void* peer, | 631 void* peer, |
| 635 Dart_WeakPersistentHandleFinalizer callback) { | 632 Dart_WeakPersistentHandleFinalizer callback) { |
| 636 Isolate* isolate = Isolate::Current(); | 633 Isolate* isolate = Isolate::Current(); |
| 637 CHECK_ISOLATE(isolate); | 634 CHECK_ISOLATE(isolate); |
| 638 ApiState* state = isolate->api_state(); | 635 ApiState* state = isolate->api_state(); |
| 639 ASSERT(state != NULL); | 636 ASSERT(state != NULL); |
| 640 return AllocateFinalizableHandle(isolate, | 637 return AllocateFinalizableHandle(isolate, |
| 641 &state->weak_persistent_handles(), | 638 &state->weak_persistent_handles(), |
| 642 object, | 639 object, |
| 640 false, | |
| 643 peer, | 641 peer, |
| 644 callback); | 642 callback); |
| 645 } | 643 } |
| 646 | 644 |
| 647 | 645 |
| 648 DART_EXPORT Dart_WeakPersistentHandle Dart_NewPrologueWeakPersistentHandle( | 646 DART_EXPORT Dart_WeakPersistentHandle Dart_NewPrologueWeakPersistentHandle( |
| 649 Dart_Handle object, | 647 Dart_Handle object, |
| 650 void* peer, | 648 void* peer, |
| 651 Dart_WeakPersistentHandleFinalizer callback) { | 649 Dart_WeakPersistentHandleFinalizer callback) { |
| 652 Isolate* isolate = Isolate::Current(); | 650 Isolate* isolate = Isolate::Current(); |
| 653 CHECK_ISOLATE(isolate); | 651 CHECK_ISOLATE(isolate); |
| 654 ApiState* state = isolate->api_state(); | 652 ApiState* state = isolate->api_state(); |
| 655 ASSERT(state != NULL); | 653 ASSERT(state != NULL); |
| 656 return AllocateFinalizableHandle(isolate, | 654 return AllocateFinalizableHandle(isolate, |
| 657 &state->prologue_weak_persistent_handles(), | 655 &state->prologue_weak_persistent_handles(), |
| 658 object, | 656 object, |
| 657 true, | |
| 659 peer, | 658 peer, |
| 660 callback); | 659 callback); |
| 661 } | 660 } |
| 662 | 661 |
| 663 | 662 |
| 664 DART_EXPORT void Dart_DeletePersistentHandle(Dart_PersistentHandle object) { | 663 DART_EXPORT void Dart_DeletePersistentHandle(Dart_PersistentHandle object) { |
| 665 Isolate* isolate = Isolate::Current(); | 664 Isolate* isolate = Isolate::Current(); |
| 666 CHECK_ISOLATE(isolate); | 665 CHECK_ISOLATE(isolate); |
| 667 ApiState* state = isolate->api_state(); | 666 ApiState* state = isolate->api_state(); |
| 668 ASSERT(state != NULL); | 667 ASSERT(state != NULL); |
| 669 PersistentHandle* ref = Api::UnwrapAsPersistentHandle(object); | 668 PersistentHandle* ref = Api::UnwrapAsPersistentHandle(object); |
| 670 ASSERT(!state->IsProtectedHandle(ref)); | 669 ASSERT(!state->IsProtectedHandle(ref)); |
| 671 if (!state->IsProtectedHandle(ref)) { | 670 if (!state->IsProtectedHandle(ref)) { |
| 672 state->persistent_handles().FreeHandle(ref); | 671 state->persistent_handles().FreeHandle(ref); |
| 673 } | 672 } |
| 674 } | 673 } |
| 675 | 674 |
| 676 | 675 |
| 677 DART_EXPORT void Dart_DeleteWeakPersistentHandle( | 676 DART_EXPORT void Dart_DeleteWeakPersistentHandle( |
| 678 Dart_WeakPersistentHandle object) { | 677 Dart_WeakPersistentHandle object) { |
| 679 Isolate* isolate = Isolate::Current(); | 678 Isolate* isolate = Isolate::Current(); |
| 680 CHECK_ISOLATE(isolate); | 679 CHECK_ISOLATE(isolate); |
| 681 ApiState* state = isolate->api_state(); | 680 ApiState* state = isolate->api_state(); |
| 682 ASSERT(state != NULL); | 681 ASSERT(state != NULL); |
| 683 if (state->IsValidPrologueWeakPersistentHandle(object)) { | 682 if (FinalizablePersistentHandle::IsPrologueWeakPersistentHandle(object)) { |
| 684 FinalizablePersistentHandle* prologue_weak_ref = | 683 ASSERT(state->IsValidPrologueWeakPersistentHandle(object)); |
| 685 Api::UnwrapAsPrologueWeakPersistentHandle(object); | 684 FinalizablePersistentHandle* weak_ref = |
| 686 state->prologue_weak_persistent_handles().FreeHandle(prologue_weak_ref); | 685 FinalizablePersistentHandle::AsFinalizablePersistentHandle(object); |
| 687 return; | 686 state->prologue_weak_persistent_handles().FreeHandle(weak_ref); |
| 687 } else { | |
| 688 ASSERT(!state->IsValidPrologueWeakPersistentHandle(object)); | |
| 689 FinalizablePersistentHandle* weak_ref = | |
| 690 FinalizablePersistentHandle::AsFinalizablePersistentHandle(object); | |
| 691 state->weak_persistent_handles().FreeHandle(weak_ref); | |
| 688 } | 692 } |
| 689 FinalizablePersistentHandle* weak_ref = | |
| 690 Api::UnwrapAsWeakPersistentHandle(object); | |
| 691 state->weak_persistent_handles().FreeHandle(weak_ref); | |
| 692 return; | |
| 693 } | 693 } |
| 694 | 694 |
| 695 | 695 |
| 696 DART_EXPORT bool Dart_IsPrologueWeakPersistentHandle( | 696 DART_EXPORT bool Dart_IsPrologueWeakPersistentHandle( |
| 697 Dart_WeakPersistentHandle object) { | 697 Dart_WeakPersistentHandle object) { |
| 698 #if defined(DEBUG) | |
| 698 Isolate* isolate = Isolate::Current(); | 699 Isolate* isolate = Isolate::Current(); |
| 699 CHECK_ISOLATE(isolate); | 700 CHECK_ISOLATE(isolate); |
| 700 ApiState* state = isolate->api_state(); | 701 ApiState* state = isolate->api_state(); |
| 701 ASSERT(state != NULL); | 702 ASSERT(state != NULL); |
| 702 return state->IsValidPrologueWeakPersistentHandle(object); | 703 ASSERT(state->IsValidPrologueWeakPersistentHandle(object) == |
| 704 FinalizablePersistentHandle::IsPrologueWeakPersistentHandle(object)); | |
| 705 #endif | |
| 706 return FinalizablePersistentHandle::IsPrologueWeakPersistentHandle(object); | |
| 703 } | 707 } |
| 704 | 708 |
| 705 | 709 |
| 706 DART_EXPORT Dart_Handle Dart_NewWeakReferenceSet( | 710 DART_EXPORT Dart_Handle Dart_NewWeakReferenceSet( |
| 707 Dart_WeakPersistentHandle* keys, | 711 Dart_WeakPersistentHandle* keys, |
| 708 intptr_t num_keys, | 712 intptr_t num_keys, |
| 709 Dart_WeakPersistentHandle* values, | 713 Dart_WeakPersistentHandle* values, |
| 710 intptr_t num_values) { | 714 intptr_t num_values) { |
| 711 Isolate* isolate = Isolate::Current(); | 715 Isolate* isolate = Isolate::Current(); |
| 712 CHECK_ISOLATE(isolate); | 716 CHECK_ISOLATE(isolate); |
| (...skipping 3894 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4607 | 4611 |
| 4608 | 4612 |
| 4609 DART_EXPORT void Dart_RegisterRootServiceRequestCallback( | 4613 DART_EXPORT void Dart_RegisterRootServiceRequestCallback( |
| 4610 const char* name, | 4614 const char* name, |
| 4611 Dart_ServiceRequestCallback callback, | 4615 Dart_ServiceRequestCallback callback, |
| 4612 void* user_data) { | 4616 void* user_data) { |
| 4613 Service::RegisterRootEmbedderCallback(name, callback, user_data); | 4617 Service::RegisterRootEmbedderCallback(name, callback, user_data); |
| 4614 } | 4618 } |
| 4615 | 4619 |
| 4616 } // namespace dart | 4620 } // namespace dart |
| OLD | NEW |