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

Unified Diff: runtime/vm/dart_api_impl.cc

Issue 10905251: Lazy peer API. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: runtime/vm/dart_api_impl.cc
diff --git a/runtime/vm/dart_api_impl.cc b/runtime/vm/dart_api_impl.cc
index f903beca54743ecf710db831d605c1357b066c21..bb0b51d0cbf834594bb5dc7c40c48502d04c29ec 100644
--- a/runtime/vm/dart_api_impl.cc
+++ b/runtime/vm/dart_api_impl.cc
@@ -4190,4 +4190,60 @@ DART_EXPORT void Dart_InitFlowGraphPrinting(Dart_FileWriterFunction function) {
Dart::set_flow_graph_writer(function);
}
+
+// --- Peer support ---
+
+
+DART_EXPORT Dart_Handle Dart_GetPeer(Dart_Handle object, void** peer) {
+ if (peer == NULL) {
+ RETURN_NULL_ERROR(peer);
+ }
+ Isolate* isolate = Isolate::Current();
+ const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(object));
+ if (obj.IsNull()) {
+ RETURN_TYPE_ERROR(isolate, object, Object);
+ }
+ if (obj.IsSmi()) {
Anton Muhin 2012/09/13 06:27:07 that's up to you, but this dependence on internal
cshapiro 2012/09/15 01:23:41 I think your suggestion to prohibit the bool type
+ const char* msg = "%s expects argument 'object' to be heap allocated.";
+ return Api::NewError(msg, CURRENT_FUNC);
+ }
+ {
+ NoGCScope no_gc;
+ RawObject* raw_obj = obj.raw();
+ *peer = isolate->heap()->GetPeer(raw_obj);
+ }
+ if (*peer == NULL) {
+ const char* msg = "%s: expects 'object' to have its peer value set";
+ return Api::NewError(msg, CURRENT_FUNC);
+ }
+ return Api::Success(isolate);
+}
+
+
+DART_EXPORT Dart_Handle Dart_SetPeer(Dart_Handle object, void* peer) {
+ Isolate* isolate = Isolate::Current();
+ const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(object));
+ if (obj.IsNull()) {
+ RETURN_TYPE_ERROR(isolate, object, Object);
+ }
+ if (obj.IsSmi()) {
+ const char* msg = "%s expects argument 'object' to be heap allocated.";
+ return Api::NewError(msg, CURRENT_FUNC);
+ }
+ {
+ NoGCScope no_gc;
+ RawObject* raw_obj = obj.raw();
+ isolate->heap()->SetPeer(raw_obj, peer);
+ }
+ return Api::Success(isolate);
+}
+
+
+DART_EXPORT bool Dart_HasPeer(Dart_Handle object) {
+ Isolate* isolate = Isolate::Current();
+ NoGCScope no_gc;
+ RawObject* raw_obj = Api::UnwrapHandle(object);
+ return raw_obj->IsHeapObject() && (isolate->heap()->GetPeer(raw_obj) != NULL);
+}
+
} // namespace dart

Powered by Google App Engine
This is Rietveld 408576698