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

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

Issue 116473004: Add Dart API method Dart_SetPersistentHandle to enable setting the value of (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 11 months 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
« no previous file with comments | « runtime/include/dart_api.h ('k') | runtime/vm/dart_api_impl_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 560 matching lines...) Expand 10 before | Expand all | Expand 10 after
571 Isolate* isolate = Isolate::Current(); 571 Isolate* isolate = Isolate::Current();
572 DARTSCOPE(isolate); 572 DARTSCOPE(isolate);
573 ApiState* state = isolate->api_state(); 573 ApiState* state = isolate->api_state();
574 ASSERT(state != NULL); 574 ASSERT(state != NULL);
575 const Object& old_ref = Object::Handle(isolate, Api::UnwrapHandle(object)); 575 const Object& old_ref = Object::Handle(isolate, Api::UnwrapHandle(object));
576 PersistentHandle* new_ref = state->persistent_handles().AllocateHandle(); 576 PersistentHandle* new_ref = state->persistent_handles().AllocateHandle();
577 new_ref->set_raw(old_ref); 577 new_ref->set_raw(old_ref);
578 return reinterpret_cast<Dart_PersistentHandle>(new_ref); 578 return reinterpret_cast<Dart_PersistentHandle>(new_ref);
579 } 579 }
580 580
581
582 DART_EXPORT Dart_Handle Dart_SetPersistentHandle(Dart_PersistentHandle obj1,
583 Dart_Handle obj2) {
584 Isolate* isolate = Isolate::Current();
585 DARTSCOPE(isolate);
586 ApiState* state = isolate->api_state();
587 ASSERT(state != NULL);
588 if (!state->IsValidPersistentHandle(obj1)) {
Ivan Posva 2014/01/03 18:21:21 In other places we just assert on this instead of
siva 2014/01/03 18:33:49 Done.
589 return Api::NewError(
590 "%s expects argument 'obj1' to be a persistent handle.",
591 CURRENT_FUNC);
592 }
593 const Object& obj2_ref = Object::Handle(isolate, Api::UnwrapHandle(obj2));
594 PersistentHandle* obj1_ref = Api::UnwrapAsPersistentHandle(obj1);
595 obj1_ref->set_raw(obj2_ref);
596 return Api::Success();
Ivan Posva 2014/01/03 18:21:21 Then you can also change the signature of the func
siva 2014/01/03 18:33:49 Done.
597 }
598
599
581 static Dart_WeakPersistentHandle AllocateFinalizableHandle( 600 static Dart_WeakPersistentHandle AllocateFinalizableHandle(
582 Isolate* isolate, 601 Isolate* isolate,
583 FinalizablePersistentHandles* handles, 602 FinalizablePersistentHandles* handles,
584 Dart_Handle object, 603 Dart_Handle object,
585 void* peer, 604 void* peer,
586 Dart_WeakPersistentHandleFinalizer callback) { 605 Dart_WeakPersistentHandleFinalizer callback) {
587 const Object& ref = Object::Handle(isolate, Api::UnwrapHandle(object)); 606 const Object& ref = Object::Handle(isolate, Api::UnwrapHandle(object));
588 FinalizablePersistentHandle* finalizable_ref = handles->AllocateHandle(); 607 FinalizablePersistentHandle* finalizable_ref = handles->AllocateHandle();
589 finalizable_ref->set_raw(ref); 608 finalizable_ref->set_raw(ref);
590 finalizable_ref->set_peer(peer); 609 finalizable_ref->set_peer(peer);
(...skipping 3884 matching lines...) Expand 10 before | Expand all | Expand 10 after
4475 } 4494 }
4476 { 4495 {
4477 NoGCScope no_gc; 4496 NoGCScope no_gc;
4478 RawObject* raw_obj = obj.raw(); 4497 RawObject* raw_obj = obj.raw();
4479 isolate->heap()->SetPeer(raw_obj, peer); 4498 isolate->heap()->SetPeer(raw_obj, peer);
4480 } 4499 }
4481 return Api::Success(); 4500 return Api::Success();
4482 } 4501 }
4483 4502
4484 } // namespace dart 4503 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/include/dart_api.h ('k') | runtime/vm/dart_api_impl_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698