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

Unified Diff: runtime/vm/dart_api_impl.cc

Issue 585643004: Add Dart_IsFuture. To be used in Dartium implementation of Promises. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 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 d354726ad32fc1ed15a940ca264be2b9e9582e1f..24ec09d5621d05aef4591a065457f819b04b5273 100644
--- a/runtime/vm/dart_api_impl.cc
+++ b/runtime/vm/dart_api_impl.cc
@@ -1870,6 +1870,29 @@ DART_EXPORT bool Dart_IsByteBuffer(Dart_Handle handle) {
}
+DART_EXPORT bool Dart_IsFuture(Dart_Handle handle) {
+ TRACE_API_CALL(CURRENT_FUNC);
+ Isolate* isolate = Isolate::Current();
+ DARTSCOPE(isolate);
+ const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(handle));
+ if (obj.IsInstance()) {
siva 2014/09/19 17:38:35 ReusableObjectHandleScope reused_obj_handle(isolat
rmacnak 2014/09/19 21:32:02 Trips the assert as the reusable handle is used in
siva 2014/09/19 21:59:37 In that case you could restructure it as: Class o
+ const Library& core_lib = Library::Handle(Library::AsyncLibrary());
siva 2014/09/19 17:38:35 replace core_lib with async_lib for the variable n
rmacnak 2014/09/19 21:32:03 Done.
+ const Class& future_class =
+ Class::Handle(core_lib.LookupClass(Symbols::Future()));
siva 2014/09/19 17:38:35 Class::Handle(isolate, ....);
rmacnak 2014/09/19 21:32:02 Done.
+ ASSERT(!future_class.IsNull());
+ const Class& obj_class = Class::Handle(isolate, obj.clazz());
+ Error& malformed_type_error = Error::Handle(isolate);
+ bool is_future = obj_class.IsSubtypeOf(TypeArguments::Handle(isolate),
siva 2014/09/19 17:38:36 IsSubTypeOf(Object::null_type_arguments(),
rmacnak 2014/09/19 21:32:02 Done. (And two other occurrences in this file.)
+ future_class,
+ TypeArguments::Handle(isolate),
+ &malformed_type_error);
+ ASSERT(malformed_type_error.IsNull()); // Type is a raw Future.
+ return is_future;
+ }
+ return false;
+}
+
+
// --- Instances ----
DART_EXPORT Dart_Handle Dart_InstanceGetType(Dart_Handle instance) {

Powered by Google App Engine
This is Rietveld 408576698