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

Side by Side 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 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/class_finalizer.h" 10 #include "vm/class_finalizer.h"
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 64
65 static RawInstance* GetListInstance(Isolate* isolate, const Object& obj) { 65 static RawInstance* GetListInstance(Isolate* isolate, const Object& obj) {
66 if (obj.IsInstance()) { 66 if (obj.IsInstance()) {
67 const Library& core_lib = Library::Handle(Library::CoreLibrary()); 67 const Library& core_lib = Library::Handle(Library::CoreLibrary());
68 const Class& list_class = 68 const Class& list_class =
69 Class::Handle(core_lib.LookupClass(Symbols::List())); 69 Class::Handle(core_lib.LookupClass(Symbols::List()));
70 ASSERT(!list_class.IsNull()); 70 ASSERT(!list_class.IsNull());
71 const Instance& instance = Instance::Cast(obj); 71 const Instance& instance = Instance::Cast(obj);
72 const Class& obj_class = Class::Handle(isolate, obj.clazz()); 72 const Class& obj_class = Class::Handle(isolate, obj.clazz());
73 Error& malformed_type_error = Error::Handle(isolate); 73 Error& malformed_type_error = Error::Handle(isolate);
74 if (obj_class.IsSubtypeOf(TypeArguments::Handle(isolate), 74 if (obj_class.IsSubtypeOf(Object::null_type_arguments(),
75 list_class, 75 list_class,
76 TypeArguments::Handle(isolate), 76 Object::null_type_arguments(),
77 &malformed_type_error)) { 77 &malformed_type_error)) {
78 ASSERT(malformed_type_error.IsNull()); // Type is a raw List. 78 ASSERT(malformed_type_error.IsNull()); // Type is a raw List.
79 return instance.raw(); 79 return instance.raw();
80 } 80 }
81 } 81 }
82 return Instance::null(); 82 return Instance::null();
83 } 83 }
84 84
85 static RawInstance* GetMapInstance(Isolate* isolate, const Object& obj) { 85 static RawInstance* GetMapInstance(Isolate* isolate, const Object& obj) {
86 if (obj.IsInstance()) { 86 if (obj.IsInstance()) {
87 const Library& core_lib = Library::Handle(Library::CoreLibrary()); 87 const Library& core_lib = Library::Handle(Library::CoreLibrary());
88 const Class& map_class = 88 const Class& map_class =
89 Class::Handle(core_lib.LookupClass(Symbols::Map())); 89 Class::Handle(core_lib.LookupClass(Symbols::Map()));
90 ASSERT(!map_class.IsNull()); 90 ASSERT(!map_class.IsNull());
91 const Instance& instance = Instance::Cast(obj); 91 const Instance& instance = Instance::Cast(obj);
92 const Class& obj_class = Class::Handle(isolate, obj.clazz()); 92 const Class& obj_class = Class::Handle(isolate, obj.clazz());
93 Error& malformed_type_error = Error::Handle(isolate); 93 Error& malformed_type_error = Error::Handle(isolate);
94 if (obj_class.IsSubtypeOf(TypeArguments::Handle(isolate), 94 if (obj_class.IsSubtypeOf(Object::null_type_arguments(),
95 map_class, 95 map_class,
96 TypeArguments::Handle(isolate), 96 Object::null_type_arguments(),
97 &malformed_type_error)) { 97 &malformed_type_error)) {
98 ASSERT(malformed_type_error.IsNull()); // Type is a raw Map. 98 ASSERT(malformed_type_error.IsNull()); // Type is a raw Map.
99 return instance.raw(); 99 return instance.raw();
100 } 100 }
101 } 101 }
102 return Instance::null(); 102 return Instance::null();
103 } 103 }
104 104
105 105
106 static bool GetNativeStringArgument(NativeArguments* arguments, 106 static bool GetNativeStringArgument(NativeArguments* arguments,
(...skipping 1756 matching lines...) Expand 10 before | Expand all | Expand 10 after
1863 RawObject::IsTypedDataViewClassId(cid); 1863 RawObject::IsTypedDataViewClassId(cid);
1864 } 1864 }
1865 1865
1866 1866
1867 DART_EXPORT bool Dart_IsByteBuffer(Dart_Handle handle) { 1867 DART_EXPORT bool Dart_IsByteBuffer(Dart_Handle handle) {
1868 TRACE_API_CALL(CURRENT_FUNC); 1868 TRACE_API_CALL(CURRENT_FUNC);
1869 return Api::ClassId(handle) == kByteBufferCid; 1869 return Api::ClassId(handle) == kByteBufferCid;
1870 } 1870 }
1871 1871
1872 1872
1873 DART_EXPORT bool Dart_IsFuture(Dart_Handle handle) {
1874 TRACE_API_CALL(CURRENT_FUNC);
1875 Isolate* isolate = Isolate::Current();
1876 DARTSCOPE(isolate);
1877 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(handle));
1878 if (obj.IsInstance()) {
1879 const Library& async_lib =
1880 Library::Handle(isolate, Library::AsyncLibrary());
1881 const Class& future_class =
1882 Class::Handle(isolate, async_lib.LookupClass(Symbols::Future()));
1883 ASSERT(!future_class.IsNull());
1884 const Class& obj_class = Class::Handle(isolate, obj.clazz());
1885 Error& malformed_type_error = Error::Handle(isolate);
1886 bool is_future = obj_class.IsSubtypeOf(Object::null_type_arguments(),
1887 future_class,
1888 Object::null_type_arguments(),
1889 &malformed_type_error);
1890 ASSERT(malformed_type_error.IsNull()); // Type is a raw Future.
1891 return is_future;
1892 }
1893 return false;
1894 }
1895
1896
1873 // --- Instances ---- 1897 // --- Instances ----
1874 1898
1875 DART_EXPORT Dart_Handle Dart_InstanceGetType(Dart_Handle instance) { 1899 DART_EXPORT Dart_Handle Dart_InstanceGetType(Dart_Handle instance) {
1876 Isolate* isolate = Isolate::Current(); 1900 Isolate* isolate = Isolate::Current();
1877 DARTSCOPE(isolate); 1901 DARTSCOPE(isolate);
1878 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(instance)); 1902 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(instance));
1879 if (obj.IsNull()) { 1903 if (obj.IsNull()) {
1880 return Api::NewHandle(isolate, isolate->object_store()->null_type()); 1904 return Api::NewHandle(isolate, isolate->object_store()->null_type());
1881 } 1905 }
1882 if (!obj.IsInstance()) { 1906 if (!obj.IsInstance()) {
(...skipping 3501 matching lines...) Expand 10 before | Expand all | Expand 10 after
5384 5408
5385 5409
5386 DART_EXPORT void Dart_RegisterRootServiceRequestCallback( 5410 DART_EXPORT void Dart_RegisterRootServiceRequestCallback(
5387 const char* name, 5411 const char* name,
5388 Dart_ServiceRequestCallback callback, 5412 Dart_ServiceRequestCallback callback,
5389 void* user_data) { 5413 void* user_data) {
5390 Service::RegisterRootEmbedderCallback(name, callback, user_data); 5414 Service::RegisterRootEmbedderCallback(name, callback, user_data);
5391 } 5415 }
5392 5416
5393 } // namespace dart 5417 } // 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