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

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: Fix whitespace. 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);
505 new_ref->set_kind(PersistentHandle::StrongReference);
499 return reinterpret_cast<Dart_Handle>(new_ref); 506 return reinterpret_cast<Dart_Handle>(new_ref);
500 } 507 }
501 508
509
510 DART_EXPORT Dart_Handle Dart_NewWeakPersistentHandle(
511 Dart_Handle object,
512 Dart_PeerFinalizer callback) {
Ivan Posva 2011/12/19 22:41:36 We will need to add the peer pointer here.
cshapiro 2011/12/20 00:58:57 Sure. I was going to leave this for the next chan
513 PersistentHandle* new_ref = AllocatePersistentHandle(object);
514 new_ref->set_kind(PersistentHandle::WeakReference);
515 new_ref->set_callback(reinterpret_cast<void*>(callback));
516 return reinterpret_cast<Dart_Handle>(new_ref);
517 }
518
502 519
503 DART_EXPORT void Dart_DeletePersistentHandle(Dart_Handle object) { 520 DART_EXPORT void Dart_DeletePersistentHandle(Dart_Handle object) {
504 Isolate* isolate = Isolate::Current(); 521 Isolate* isolate = Isolate::Current();
505 CHECK_ISOLATE(isolate); 522 CHECK_ISOLATE(isolate);
506 ApiState* state = isolate->api_state(); 523 ApiState* state = isolate->api_state();
507 ASSERT(state != NULL); 524 ASSERT(state != NULL);
508 PersistentHandle* ref = Api::UnwrapAsPersistentHandle(*state, object); 525 PersistentHandle* ref = Api::UnwrapAsPersistentHandle(*state, object);
509 ASSERT(!ref->IsProtected()); 526 ASSERT(!ref->IsProtected());
510 if (!ref->IsProtected()) { 527 if (!ref->IsProtected()) {
511 state->persistent_handles().FreeHandle(ref); 528 state->persistent_handles().FreeHandle(ref);
512 } 529 }
513 } 530 }
514 531
515 532
516 DART_EXPORT Dart_Handle Dart_MakeWeakPersistentHandle(Dart_Handle object) { 533 DART_EXPORT bool Dart_IsWeakPersistentHandle(Dart_Handle object) {
517 UNIMPLEMENTED(); 534 Isolate* isolate = Isolate::Current();
518 return NULL; 535 CHECK_ISOLATE(isolate);
536 ApiState* state = isolate->api_state();
537 ASSERT(state != NULL);
538 if (state->IsValidPersistentHandle(object)) {
539 PersistentHandle* ref = Api::UnwrapAsPersistentHandle(*state, object);
540 return ref->kind() == PersistentHandle::WeakReference;
541 }
542 return false;
519 } 543 }
520 544
521 545
522 DART_EXPORT Dart_Handle Dart_MakePersistentHandle(Dart_Handle object) {
523 UNIMPLEMENTED();
524 return NULL;
525 }
526
527
528 // --- Initialization and Globals --- 546 // --- Initialization and Globals ---
529 547
530 548
531 DART_EXPORT bool Dart_Initialize(Dart_IsolateCreateCallback create, 549 DART_EXPORT bool Dart_Initialize(Dart_IsolateCreateCallback create,
532 Dart_IsolateInterruptCallback interrupt) { 550 Dart_IsolateInterruptCallback interrupt) {
533 return Dart::InitOnce(create, interrupt); 551 return Dart::InitOnce(create, interrupt);
534 } 552 }
535 553
536 DART_EXPORT bool Dart_SetVMFlags(int argc, const char** argv) { 554 DART_EXPORT bool Dart_SetVMFlags(int argc, const char** argv) {
537 return Flags::ProcessCommandLineFlags(argc, argv); 555 return Flags::ProcessCommandLineFlags(argc, argv);
(...skipping 1974 matching lines...) Expand 10 before | Expand all | Expand 10 after
2512 } 2530 }
2513 delete debug_region; 2531 delete debug_region;
2514 } else { 2532 } else {
2515 *buffer = NULL; 2533 *buffer = NULL;
2516 *buffer_size = 0; 2534 *buffer_size = 0;
2517 } 2535 }
2518 } 2536 }
2519 2537
2520 2538
2521 } // namespace dart 2539 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698