| OLD | NEW |
| 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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 TypeArguments::Handle(isolate), | 70 TypeArguments::Handle(isolate), |
| 71 &malformed_type_error)) { | 71 &malformed_type_error)) { |
| 72 ASSERT(malformed_type_error.IsNull()); // Type is a raw List. | 72 ASSERT(malformed_type_error.IsNull()); // Type is a raw List. |
| 73 return instance.raw(); | 73 return instance.raw(); |
| 74 } | 74 } |
| 75 } | 75 } |
| 76 return Instance::null(); | 76 return Instance::null(); |
| 77 } | 77 } |
| 78 | 78 |
| 79 | 79 |
| 80 Dart_Handle Api::NewHandle(Isolate* isolate, RawObject* raw) { | 80 Dart_Handle Api::InitNewHandle(Isolate* isolate, RawObject* raw) { |
| 81 LocalHandles* local_handles = Api::TopScope(isolate)->local_handles(); | 81 LocalHandles* local_handles = Api::TopScope(isolate)->local_handles(); |
| 82 ASSERT(local_handles != NULL); | 82 ASSERT(local_handles != NULL); |
| 83 LocalHandle* ref = local_handles->AllocateHandle(); | 83 LocalHandle* ref = local_handles->AllocateHandle(); |
| 84 ref->set_raw(raw); | 84 ref->set_raw(raw); |
| 85 return reinterpret_cast<Dart_Handle>(ref); | 85 return reinterpret_cast<Dart_Handle>(ref); |
| 86 } | 86 } |
| 87 | 87 |
| 88 | 88 |
| 89 Dart_Handle Api::NewHandle(Isolate* isolate, RawObject* raw) { |
| 90 if (raw == Object::null()) { |
| 91 return Null(); |
| 92 } |
| 93 if (raw == Bool::True().raw()) { |
| 94 return True(); |
| 95 } |
| 96 if (raw == Bool::False().raw()) { |
| 97 return False(); |
| 98 } |
| 99 return InitNewHandle(isolate, raw); |
| 100 } |
| 101 |
| 102 |
| 89 RawObject* Api::UnwrapHandle(Dart_Handle object) { | 103 RawObject* Api::UnwrapHandle(Dart_Handle object) { |
| 90 #if defined(DEBUG) | 104 #if defined(DEBUG) |
| 91 Isolate* isolate = Isolate::Current(); | 105 Isolate* isolate = Isolate::Current(); |
| 92 ASSERT(isolate != NULL); | 106 ASSERT(isolate != NULL); |
| 93 ApiState* state = isolate->api_state(); | 107 ApiState* state = isolate->api_state(); |
| 94 ASSERT(state != NULL); | 108 ASSERT(state != NULL); |
| 95 ASSERT(!FLAG_verify_handles || | 109 ASSERT(!FLAG_verify_handles || |
| 96 state->IsValidLocalHandle(object) || | 110 state->IsValidLocalHandle(object) || |
| 97 Dart::vm_isolate()->api_state()->IsValidLocalHandle(object)); | 111 Dart::vm_isolate()->api_state()->IsValidLocalHandle(object)); |
| 98 ASSERT(FinalizablePersistentHandle::raw_offset() == 0 && | 112 ASSERT(FinalizablePersistentHandle::raw_offset() == 0 && |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 } | 241 } |
| 228 | 242 |
| 229 | 243 |
| 230 void Api::InitHandles() { | 244 void Api::InitHandles() { |
| 231 Isolate* isolate = Isolate::Current(); | 245 Isolate* isolate = Isolate::Current(); |
| 232 ASSERT(isolate != NULL); | 246 ASSERT(isolate != NULL); |
| 233 ASSERT(isolate == Dart::vm_isolate()); | 247 ASSERT(isolate == Dart::vm_isolate()); |
| 234 ApiState* state = isolate->api_state(); | 248 ApiState* state = isolate->api_state(); |
| 235 ASSERT(state != NULL); | 249 ASSERT(state != NULL); |
| 236 ASSERT(true_handle_ == NULL); | 250 ASSERT(true_handle_ == NULL); |
| 237 true_handle_ = Api::NewHandle(isolate, Bool::True().raw()); | 251 true_handle_ = Api::InitNewHandle(isolate, Bool::True().raw()); |
| 238 | 252 |
| 239 ASSERT(false_handle_ == NULL); | 253 ASSERT(false_handle_ == NULL); |
| 240 false_handle_ = Api::NewHandle(isolate, Bool::False().raw()); | 254 false_handle_ = Api::InitNewHandle(isolate, Bool::False().raw()); |
| 241 | 255 |
| 242 ASSERT(null_handle_ == NULL); | 256 ASSERT(null_handle_ == NULL); |
| 243 null_handle_ = Api::NewHandle(isolate, Object::null()); | 257 null_handle_ = Api::InitNewHandle(isolate, Object::null()); |
| 244 } | 258 } |
| 245 | 259 |
| 246 | 260 |
| 247 bool Api::StringGetPeerHelper(Dart_NativeArguments args, | 261 bool Api::StringGetPeerHelper(Dart_NativeArguments args, |
| 248 int arg_index, | 262 int arg_index, |
| 249 void** peer) { | 263 void** peer) { |
| 250 NoGCScope no_gc_scope; | 264 NoGCScope no_gc_scope; |
| 251 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); | 265 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); |
| 252 RawObject* raw_obj = arguments->NativeArgAt(arg_index); | 266 RawObject* raw_obj = arguments->NativeArgAt(arg_index); |
| 253 intptr_t cid = raw_obj->GetClassId(); | 267 intptr_t cid = raw_obj->GetClassId(); |
| (...skipping 946 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1200 } else if (result.IsError()) { | 1214 } else if (result.IsError()) { |
| 1201 return Api::NewHandle(isolate, result.raw()); | 1215 return Api::NewHandle(isolate, result.raw()); |
| 1202 } else { | 1216 } else { |
| 1203 return Api::NewError("Expected boolean result from =="); | 1217 return Api::NewError("Expected boolean result from =="); |
| 1204 } | 1218 } |
| 1205 } | 1219 } |
| 1206 | 1220 |
| 1207 | 1221 |
| 1208 // TODO(iposva): This call actually implements IsInstanceOfClass. | 1222 // TODO(iposva): This call actually implements IsInstanceOfClass. |
| 1209 // Do we also need a real Dart_IsInstanceOf, which should take an instance | 1223 // Do we also need a real Dart_IsInstanceOf, which should take an instance |
| 1210 // rather than an object and a type rather than a class? | 1224 // rather than an object? |
| 1211 DART_EXPORT Dart_Handle Dart_ObjectIsType(Dart_Handle object, | 1225 DART_EXPORT Dart_Handle Dart_ObjectIsType(Dart_Handle object, |
| 1212 Dart_Handle type, | 1226 Dart_Handle type, |
| 1213 bool* value) { | 1227 bool* value) { |
| 1214 Isolate* isolate = Isolate::Current(); | 1228 Isolate* isolate = Isolate::Current(); |
| 1215 DARTSCOPE(isolate); | 1229 DARTSCOPE(isolate); |
| 1216 | 1230 |
| 1217 Type& type_obj = Type::Handle(); | 1231 const Type& type_obj = Api::UnwrapTypeHandle(isolate, type); |
| 1218 Object& obj = Object::Handle(isolate, Api::UnwrapHandle(type)); | 1232 if (type_obj.IsNull()) { |
| 1219 if (obj.IsNull()) { | 1233 *value = false; |
| 1220 RETURN_NULL_ERROR(type); | 1234 RETURN_TYPE_ERROR(isolate, type, Type); |
| 1221 } | 1235 } |
| 1222 if (obj.IsType()) { | 1236 if (object == Api::Null()) { |
| 1223 type_obj ^= obj.raw(); | 1237 *value = false; |
| 1224 } else { | 1238 return Api::Success(); |
| 1225 if (!obj.IsClass()) { | |
| 1226 RETURN_TYPE_ERROR(isolate, type, Type); | |
| 1227 } | |
| 1228 type_obj ^= Type::NewNonParameterizedType(Class::Cast(obj)); | |
| 1229 } | 1239 } |
| 1230 obj = Api::UnwrapHandle(object); | 1240 const Instance& instance = Api::UnwrapInstanceHandle(isolate, object); |
| 1231 if (obj.IsError()) { | 1241 if (instance.IsNull()) { |
| 1232 return object; | 1242 *value = false; |
| 1233 } else if (!obj.IsNull() && !obj.IsInstance()) { | 1243 RETURN_TYPE_ERROR(isolate, object, Instance); |
| 1234 return Api::NewError( | |
| 1235 "%s expects argument 'object' to be an instance of Object.", | |
| 1236 CURRENT_FUNC); | |
| 1237 } | 1244 } |
| 1238 // Finalize all classes. | 1245 // Finalize all classes. |
| 1239 Dart_Handle state = Api::CheckIsolateState(isolate); | 1246 Dart_Handle state = Api::CheckIsolateState(isolate); |
| 1240 if (::Dart_IsError(state)) { | 1247 if (::Dart_IsError(state)) { |
| 1248 *value = false; |
| 1241 return state; | 1249 return state; |
| 1242 } | 1250 } |
| 1243 if (obj.IsInstance()) { | 1251 CHECK_CALLBACK_STATE(isolate); |
| 1244 CHECK_CALLBACK_STATE(isolate); | 1252 Error& malformed_type_error = Error::Handle(isolate); |
| 1245 Error& malformed_type_error = Error::Handle(isolate); | 1253 *value = instance.IsInstanceOf(type_obj, |
| 1246 *value = Instance::Cast(obj).IsInstanceOf(type_obj, | 1254 Object::null_abstract_type_arguments(), |
| 1247 TypeArguments::Handle(isolate), | 1255 &malformed_type_error); |
| 1248 &malformed_type_error); | 1256 ASSERT(malformed_type_error.IsNull()); // Type was created from a class. |
| 1249 ASSERT(malformed_type_error.IsNull()); // Type was created from a class. | |
| 1250 } else { | |
| 1251 *value = false; | |
| 1252 } | |
| 1253 return Api::Success(); | 1257 return Api::Success(); |
| 1254 } | 1258 } |
| 1255 | 1259 |
| 1256 | 1260 |
| 1257 DART_EXPORT bool Dart_IsInstance(Dart_Handle object) { | 1261 DART_EXPORT bool Dart_IsInstance(Dart_Handle object) { |
| 1258 Isolate* isolate = Isolate::Current(); | 1262 Isolate* isolate = Isolate::Current(); |
| 1259 DARTSCOPE(isolate); | 1263 DARTSCOPE(isolate); |
| 1260 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(object)); | 1264 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(object)); |
| 1261 return obj.IsInstance(); | 1265 return obj.IsInstance(); |
| 1262 } | 1266 } |
| (...skipping 3169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4432 } | 4436 } |
| 4433 { | 4437 { |
| 4434 NoGCScope no_gc; | 4438 NoGCScope no_gc; |
| 4435 RawObject* raw_obj = obj.raw(); | 4439 RawObject* raw_obj = obj.raw(); |
| 4436 isolate->heap()->SetPeer(raw_obj, peer); | 4440 isolate->heap()->SetPeer(raw_obj, peer); |
| 4437 } | 4441 } |
| 4438 return Api::Success(); | 4442 return Api::Success(); |
| 4439 } | 4443 } |
| 4440 | 4444 |
| 4441 } // namespace dart | 4445 } // namespace dart |
| OLD | NEW |