Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(98)

Side by Side Diff: runtime/vm/dart_api_impl.cc

Issue 8984006: Implement weak persistent handles in the Dart API. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address review comments Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 #include "include/dart_api.h" 5 #include "include/dart_api.h"
6 6
7 #include "vm/bigint_operations.h" 7 #include "vm/bigint_operations.h"
8 #include "vm/class_finalizer.h" 8 #include "vm/class_finalizer.h"
9 #include "vm/compiler.h" 9 #include "vm/compiler.h"
10 #include "vm/dart.h" 10 #include "vm/dart.h"
(...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after
480 DART_EXPORT Dart_Handle Dart_IsSame(Dart_Handle obj1, Dart_Handle obj2, 480 DART_EXPORT Dart_Handle Dart_IsSame(Dart_Handle obj1, Dart_Handle obj2,
481 bool* value) { 481 bool* value) {
482 DARTSCOPE(Isolate::Current()); 482 DARTSCOPE(Isolate::Current());
483 const Object& expected = Object::Handle(Api::UnwrapHandle(obj1)); 483 const Object& expected = Object::Handle(Api::UnwrapHandle(obj1));
484 const Object& actual = Object::Handle(Api::UnwrapHandle(obj2)); 484 const Object& actual = Object::Handle(Api::UnwrapHandle(obj2));
485 *value = (expected.raw() == actual.raw()); 485 *value = (expected.raw() == actual.raw());
486 return Api::Success(); 486 return Api::Success();
487 } 487 }
488 488
489 489
490 DART_EXPORT Dart_Handle Dart_NewPersistentHandle(Dart_Handle object) { 490 static PersistentHandle* AllocatePersistentHandle(Dart_Handle object) {
491 Isolate* isolate = Isolate::Current(); 491 Isolate* isolate = Isolate::Current();
492 CHECK_ISOLATE(isolate); 492 CHECK_ISOLATE(isolate);
493 DARTSCOPE_NOCHECKS(isolate); 493 DARTSCOPE_NOCHECKS(isolate);
494 ApiState* state = isolate->api_state(); 494 ApiState* state = isolate->api_state();
495 ASSERT(state != NULL); 495 ASSERT(state != NULL);
496 const Object& old_ref = Object::Handle(Api::UnwrapHandle(object)); 496 const Object& old_ref = Object::Handle(Api::UnwrapHandle(object));
497 PersistentHandle* new_ref = state->persistent_handles().AllocateHandle(); 497 PersistentHandle* new_ref = state->persistent_handles().AllocateHandle();
498 new_ref->set_raw(old_ref); 498 new_ref->set_raw(old_ref);
499 return new_ref;
500 }
501
502
503 DART_EXPORT Dart_Handle Dart_NewPersistentHandle(Dart_Handle object) {
504 PersistentHandle* new_ref = AllocatePersistentHandle(object);
499 return reinterpret_cast<Dart_Handle>(new_ref); 505 return reinterpret_cast<Dart_Handle>(new_ref);
500 } 506 }
501 507
508
509 DART_EXPORT Dart_Handle Dart_NewWeakPersistentHandle(
510 Dart_Handle object,
511 void* peer,
512 Dart_PeerFinalizer callback) {
513 PersistentHandle* new_ref = AllocatePersistentHandle(object);
514 new_ref->set_kind(PersistentHandle::WeakReference);
515 new_ref->set_peer(peer);
516 new_ref->set_callback(callback);
517 return reinterpret_cast<Dart_Handle>(new_ref);
518 }
519
502 520
503 DART_EXPORT void Dart_DeletePersistentHandle(Dart_Handle object) { 521 DART_EXPORT void Dart_DeletePersistentHandle(Dart_Handle object) {
504 Isolate* isolate = Isolate::Current(); 522 Isolate* isolate = Isolate::Current();
505 CHECK_ISOLATE(isolate); 523 CHECK_ISOLATE(isolate);
506 ApiState* state = isolate->api_state(); 524 ApiState* state = isolate->api_state();
507 ASSERT(state != NULL); 525 ASSERT(state != NULL);
508 PersistentHandle* ref = Api::UnwrapAsPersistentHandle(*state, object); 526 PersistentHandle* ref = Api::UnwrapAsPersistentHandle(*state, object);
509 ASSERT(!ref->IsProtected()); 527 ASSERT(!ref->IsProtected());
510 if (!ref->IsProtected()) { 528 if (!ref->IsProtected()) {
511 state->persistent_handles().FreeHandle(ref); 529 state->persistent_handles().FreeHandle(ref);
512 } 530 }
513 } 531 }
514 532
515 533
516 DART_EXPORT Dart_Handle Dart_MakeWeakPersistentHandle(Dart_Handle object) { 534 DART_EXPORT bool Dart_IsWeakPersistentHandle(Dart_Handle object) {
517 UNIMPLEMENTED(); 535 Isolate* isolate = Isolate::Current();
518 return NULL; 536 CHECK_ISOLATE(isolate);
537 ApiState* state = isolate->api_state();
538 ASSERT(state != NULL);
539 if (state->IsValidPersistentHandle(object)) {
540 PersistentHandle* ref = Api::UnwrapAsPersistentHandle(*state, object);
541 return ref->kind() == PersistentHandle::WeakReference;
542 }
543 return false;
519 } 544 }
520 545
521 546
522 DART_EXPORT Dart_Handle Dart_MakePersistentHandle(Dart_Handle object) {
523 UNIMPLEMENTED();
524 return NULL;
525 }
526
527
528 // --- Initialization and Globals --- 547 // --- Initialization and Globals ---
529 548
530 549
531 DART_EXPORT bool Dart_Initialize(Dart_IsolateCreateCallback create, 550 DART_EXPORT bool Dart_Initialize(Dart_IsolateCreateCallback create,
532 Dart_IsolateInterruptCallback interrupt) { 551 Dart_IsolateInterruptCallback interrupt) {
533 return Dart::InitOnce(create, interrupt); 552 return Dart::InitOnce(create, interrupt);
534 } 553 }
535 554
536 DART_EXPORT bool Dart_SetVMFlags(int argc, const char** argv) { 555 DART_EXPORT bool Dart_SetVMFlags(int argc, const char** argv) {
537 return Flags::ProcessCommandLineFlags(argc, argv); 556 return Flags::ProcessCommandLineFlags(argc, argv);
(...skipping 1974 matching lines...) Expand 10 before | Expand all | Expand 10 after
2512 } 2531 }
2513 delete debug_region; 2532 delete debug_region;
2514 } else { 2533 } else {
2515 *buffer = NULL; 2534 *buffer = NULL;
2516 *buffer_size = 0; 2535 *buffer_size = 0;
2517 } 2536 }
2518 } 2537 }
2519 2538
2520 2539
2521 } // namespace dart 2540 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698