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 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
126 const Object& obj = Object::Handle(iso, Api::UnwrapHandle(dart_handle)); \ | 126 const Object& obj = Object::Handle(iso, Api::UnwrapHandle(dart_handle)); \ |
127 if (obj.Is##type()) { \ | 127 if (obj.Is##type()) { \ |
128 return type::Cast(obj); \ | 128 return type::Cast(obj); \ |
129 } \ | 129 } \ |
130 return type::Handle(iso); \ | 130 return type::Handle(iso); \ |
131 } | 131 } |
132 CLASS_LIST_FOR_HANDLES(DEFINE_UNWRAP) | 132 CLASS_LIST_FOR_HANDLES(DEFINE_UNWRAP) |
133 #undef DEFINE_UNWRAP | 133 #undef DEFINE_UNWRAP |
134 | 134 |
135 | 135 |
136 const String& Api::UnwrapStringHandle(const ReusableObjectHandleScope& reuse, | |
137 Dart_Handle dart_handle) { | |
138 Object& ref = reuse.Handle(); | |
139 ref = Api::UnwrapHandle(dart_handle); | |
140 if (ref.IsString()) { | |
141 return String::Cast(ref); | |
142 } | |
143 return Object::null_string(); | |
144 } | |
145 | |
146 | |
147 const Instance& Api::UnwrapInstanceHandle( | |
148 const ReusableObjectHandleScope& reuse, Dart_Handle dart_handle) { | |
149 Object& ref = reuse.Handle(); | |
150 ref = Api::UnwrapHandle(dart_handle); | |
151 if (ref.IsInstance()) { | |
152 return Instance::Cast(ref); | |
153 } | |
154 return Object::null_instance(); | |
155 } | |
156 | |
157 | |
136 PersistentHandle* Api::UnwrapAsPersistentHandle(Dart_PersistentHandle object) { | 158 PersistentHandle* Api::UnwrapAsPersistentHandle(Dart_PersistentHandle object) { |
137 ASSERT(Isolate::Current()->api_state()->IsValidPersistentHandle(object)); | 159 ASSERT(Isolate::Current()->api_state()->IsValidPersistentHandle(object)); |
138 return reinterpret_cast<PersistentHandle*>(object); | 160 return reinterpret_cast<PersistentHandle*>(object); |
139 } | 161 } |
140 | 162 |
141 | 163 |
142 FinalizablePersistentHandle* Api::UnwrapAsWeakPersistentHandle( | 164 FinalizablePersistentHandle* Api::UnwrapAsWeakPersistentHandle( |
143 Dart_WeakPersistentHandle object) { | 165 Dart_WeakPersistentHandle object) { |
144 ASSERT(Isolate::Current()->api_state()->IsValidWeakPersistentHandle(object) || | 166 ASSERT(Isolate::Current()->api_state()->IsValidWeakPersistentHandle(object) || |
145 Isolate::Current()->api_state()-> | 167 Isolate::Current()->api_state()-> |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
254 true_handle_ = Api::InitNewHandle(isolate, Bool::True().raw()); | 276 true_handle_ = Api::InitNewHandle(isolate, Bool::True().raw()); |
255 | 277 |
256 ASSERT(false_handle_ == NULL); | 278 ASSERT(false_handle_ == NULL); |
257 false_handle_ = Api::InitNewHandle(isolate, Bool::False().raw()); | 279 false_handle_ = Api::InitNewHandle(isolate, Bool::False().raw()); |
258 | 280 |
259 ASSERT(null_handle_ == NULL); | 281 ASSERT(null_handle_ == NULL); |
260 null_handle_ = Api::InitNewHandle(isolate, Object::null()); | 282 null_handle_ = Api::InitNewHandle(isolate, Object::null()); |
261 } | 283 } |
262 | 284 |
263 | 285 |
264 bool Api::StringGetPeerHelper(Dart_NativeArguments args, | 286 bool Api::StringGetPeerHelper(NativeArguments* arguments, |
265 int arg_index, | 287 int arg_index, |
266 void** peer) { | 288 void** peer) { |
267 NoGCScope no_gc_scope; | 289 NoGCScope no_gc_scope; |
268 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); | |
269 RawObject* raw_obj = arguments->NativeArgAt(arg_index); | 290 RawObject* raw_obj = arguments->NativeArgAt(arg_index); |
270 if (!raw_obj->IsHeapObject()) { | 291 if (!raw_obj->IsHeapObject()) { |
271 return false; | 292 return false; |
272 } | 293 } |
273 intptr_t cid = raw_obj->GetClassId(); | 294 intptr_t cid = raw_obj->GetClassId(); |
274 if (cid == kExternalOneByteStringCid) { | 295 if (cid == kExternalOneByteStringCid) { |
275 RawExternalOneByteString* raw_string = | 296 RawExternalOneByteString* raw_string = |
276 reinterpret_cast<RawExternalOneByteString*>(raw_obj)->ptr(); | 297 reinterpret_cast<RawExternalOneByteString*>(raw_obj)->ptr(); |
277 ExternalStringData<uint8_t>* data = raw_string->external_data_; | 298 ExternalStringData<uint8_t>* data = raw_string->external_data_; |
278 *peer = data->peer(); | 299 *peer = data->peer(); |
279 return true; | 300 return true; |
280 } | 301 } |
281 if (cid == kOneByteStringCid || cid == kTwoByteStringCid) { | 302 if (cid == kOneByteStringCid || cid == kTwoByteStringCid) { |
282 Isolate* isolate = arguments->isolate(); | 303 Isolate* isolate = arguments->isolate(); |
283 *peer = isolate->heap()->GetPeer(raw_obj); | 304 *peer = isolate->heap()->GetPeer(raw_obj); |
284 return (*peer != 0); | 305 return (*peer != 0); |
285 } | 306 } |
286 if (cid == kExternalTwoByteStringCid) { | 307 if (cid == kExternalTwoByteStringCid) { |
287 RawExternalTwoByteString* raw_string = | 308 RawExternalTwoByteString* raw_string = |
288 reinterpret_cast<RawExternalTwoByteString*>(raw_obj)->ptr(); | 309 reinterpret_cast<RawExternalTwoByteString*>(raw_obj)->ptr(); |
289 ExternalStringData<uint16_t>* data = raw_string->external_data_; | 310 ExternalStringData<uint16_t>* data = raw_string->external_data_; |
290 *peer = data->peer(); | 311 *peer = data->peer(); |
291 return true; | 312 return true; |
292 } | 313 } |
293 return false; | 314 return false; |
294 } | 315 } |
295 | 316 |
296 | 317 |
297 bool Api::GetNativeReceiver(Dart_NativeArguments args, intptr_t* value) { | 318 bool Api::GetNativeReceiver(NativeArguments* arguments, intptr_t* value) { |
298 NoGCScope no_gc_scope; | 319 NoGCScope no_gc_scope; |
299 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); | |
300 RawObject* raw_obj = arguments->NativeArg0(); | 320 RawObject* raw_obj = arguments->NativeArg0(); |
301 if (raw_obj->IsHeapObject()) { | 321 if (raw_obj->IsHeapObject()) { |
302 intptr_t cid = raw_obj->GetClassId(); | 322 intptr_t cid = raw_obj->GetClassId(); |
303 if (cid > kNumPredefinedCids) { | 323 if (cid > kNumPredefinedCids) { |
304 ASSERT(Instance::Cast(Object::Handle(raw_obj)).IsValidNativeIndex(0)); | 324 ASSERT(Instance::Cast(Object::Handle(raw_obj)).IsValidNativeIndex(0)); |
305 RawTypedData* native_fields = *reinterpret_cast<RawTypedData**>( | 325 RawTypedData* native_fields = *reinterpret_cast<RawTypedData**>( |
306 RawObject::ToAddr(raw_obj) + sizeof(RawObject)); | 326 RawObject::ToAddr(raw_obj) + sizeof(RawObject)); |
307 if (native_fields == TypedData::null()) { | 327 if (native_fields == TypedData::null()) { |
308 *value = 0; | 328 *value = 0; |
309 } else { | 329 } else { |
310 *value = *bit_cast<intptr_t*, uint8_t*>(native_fields->ptr()->data_); | 330 *value = *bit_cast<intptr_t*, uint8_t*>(native_fields->ptr()->data_); |
311 } | 331 } |
312 return true; | 332 return true; |
313 } | 333 } |
314 } | 334 } |
315 return false; | 335 return false; |
316 } | 336 } |
317 | 337 |
318 | 338 |
319 bool Api::GetNativeBooleanArgument(Dart_NativeArguments args, | 339 bool Api::GetNativeBooleanArgument(NativeArguments* arguments, |
320 int arg_index, | 340 int arg_index, |
321 bool* value) { | 341 bool* value) { |
322 NoGCScope no_gc_scope; | 342 NoGCScope no_gc_scope; |
323 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); | |
324 RawObject* raw_obj = arguments->NativeArgAt(arg_index); | 343 RawObject* raw_obj = arguments->NativeArgAt(arg_index); |
325 if (raw_obj->IsHeapObject()) { | 344 if (raw_obj->IsHeapObject()) { |
326 intptr_t cid = raw_obj->GetClassId(); | 345 intptr_t cid = raw_obj->GetClassId(); |
327 if (cid == kBoolCid) { | 346 if (cid == kBoolCid) { |
328 *value = (raw_obj == Object::bool_true().raw()); | 347 *value = (raw_obj == Object::bool_true().raw()); |
329 return true; | 348 return true; |
330 } | 349 } |
331 if (cid == kNullCid) { | 350 if (cid == kNullCid) { |
332 *value = false; | 351 *value = false; |
333 return true; | 352 return true; |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
592 obj1_ref->set_raw(obj2_ref); | 611 obj1_ref->set_raw(obj2_ref); |
593 } | 612 } |
594 | 613 |
595 | 614 |
596 static Dart_WeakPersistentHandle AllocateFinalizableHandle( | 615 static Dart_WeakPersistentHandle AllocateFinalizableHandle( |
597 Isolate* isolate, | 616 Isolate* isolate, |
598 FinalizablePersistentHandles* handles, | 617 FinalizablePersistentHandles* handles, |
599 Dart_Handle object, | 618 Dart_Handle object, |
600 void* peer, | 619 void* peer, |
601 Dart_WeakPersistentHandleFinalizer callback) { | 620 Dart_WeakPersistentHandleFinalizer callback) { |
602 const Object& ref = Object::Handle(isolate, Api::UnwrapHandle(object)); | 621 ReusableObjectHandleScope reused_obj_handle(isolate); |
622 Object& ref = reused_obj_handle.Handle(); | |
623 ref = Api::UnwrapHandle(object); | |
603 FinalizablePersistentHandle* finalizable_ref = handles->AllocateHandle(); | 624 FinalizablePersistentHandle* finalizable_ref = handles->AllocateHandle(); |
604 finalizable_ref->set_raw(ref); | 625 finalizable_ref->set_raw(ref); |
605 finalizable_ref->set_peer(peer); | 626 finalizable_ref->set_peer(peer); |
606 finalizable_ref->set_callback(callback); | 627 finalizable_ref->set_callback(callback); |
607 return reinterpret_cast<Dart_WeakPersistentHandle>(finalizable_ref); | 628 return reinterpret_cast<Dart_WeakPersistentHandle>(finalizable_ref); |
608 } | 629 } |
609 | 630 |
610 | 631 |
611 DART_EXPORT Dart_WeakPersistentHandle Dart_NewWeakPersistentHandle( | 632 DART_EXPORT Dart_WeakPersistentHandle Dart_NewWeakPersistentHandle( |
612 Dart_Handle object, | 633 Dart_Handle object, |
613 void* peer, | 634 void* peer, |
614 Dart_WeakPersistentHandleFinalizer callback) { | 635 Dart_WeakPersistentHandleFinalizer callback) { |
615 Isolate* isolate = Isolate::Current(); | 636 Isolate* isolate = Isolate::Current(); |
616 DARTSCOPE(isolate); | 637 CHECK_ISOLATE(isolate); |
617 ApiState* state = isolate->api_state(); | 638 ApiState* state = isolate->api_state(); |
618 ASSERT(state != NULL); | 639 ASSERT(state != NULL); |
619 return AllocateFinalizableHandle(isolate, | 640 return AllocateFinalizableHandle(isolate, |
620 &state->weak_persistent_handles(), | 641 &state->weak_persistent_handles(), |
621 object, | 642 object, |
622 peer, | 643 peer, |
623 callback); | 644 callback); |
624 } | 645 } |
625 | 646 |
626 | 647 |
627 DART_EXPORT Dart_WeakPersistentHandle Dart_NewPrologueWeakPersistentHandle( | 648 DART_EXPORT Dart_WeakPersistentHandle Dart_NewPrologueWeakPersistentHandle( |
628 Dart_Handle object, | 649 Dart_Handle object, |
629 void* peer, | 650 void* peer, |
630 Dart_WeakPersistentHandleFinalizer callback) { | 651 Dart_WeakPersistentHandleFinalizer callback) { |
631 Isolate* isolate = Isolate::Current(); | 652 Isolate* isolate = Isolate::Current(); |
632 DARTSCOPE(isolate); | 653 CHECK_ISOLATE(isolate); |
633 ApiState* state = isolate->api_state(); | 654 ApiState* state = isolate->api_state(); |
634 ASSERT(state != NULL); | 655 ASSERT(state != NULL); |
635 return AllocateFinalizableHandle(isolate, | 656 return AllocateFinalizableHandle(isolate, |
636 &state->prologue_weak_persistent_handles(), | 657 &state->prologue_weak_persistent_handles(), |
637 object, | 658 object, |
638 peer, | 659 peer, |
639 callback); | 660 callback); |
640 } | 661 } |
641 | 662 |
642 | 663 |
(...skipping 696 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1339 Error& malformed_type_error = Error::Handle(isolate); | 1360 Error& malformed_type_error = Error::Handle(isolate); |
1340 *value = instance.IsInstanceOf(type_obj, | 1361 *value = instance.IsInstanceOf(type_obj, |
1341 Object::null_type_arguments(), | 1362 Object::null_type_arguments(), |
1342 &malformed_type_error); | 1363 &malformed_type_error); |
1343 ASSERT(malformed_type_error.IsNull()); // Type was created from a class. | 1364 ASSERT(malformed_type_error.IsNull()); // Type was created from a class. |
1344 return Api::Success(); | 1365 return Api::Success(); |
1345 } | 1366 } |
1346 | 1367 |
1347 | 1368 |
1348 DART_EXPORT bool Dart_IsInstance(Dart_Handle object) { | 1369 DART_EXPORT bool Dart_IsInstance(Dart_Handle object) { |
1349 Isolate* isolate = Isolate::Current(); | 1370 Isolate* isolate = Isolate::Current(); |
Ivan Posva
2014/02/28 04:41:36
Could we before doing any of the work below just d
| |
1350 DARTSCOPE(isolate); | 1371 CHECK_ISOLATE(isolate); |
1351 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(object)); | 1372 ReusableObjectHandleScope reused_obj_handle(isolate); |
1352 return obj.IsInstance(); | 1373 Object& ref = reused_obj_handle.Handle(); |
1374 ref = Api::UnwrapHandle(object); | |
1375 return ref.IsInstance(); | |
1353 } | 1376 } |
1354 | 1377 |
1355 | 1378 |
1356 DART_EXPORT bool Dart_IsNumber(Dart_Handle object) { | 1379 DART_EXPORT bool Dart_IsNumber(Dart_Handle object) { |
1357 TRACE_API_CALL(CURRENT_FUNC); | 1380 TRACE_API_CALL(CURRENT_FUNC); |
1358 return RawObject::IsNumberClassId(Api::ClassId(object)); | 1381 return RawObject::IsNumberClassId(Api::ClassId(object)); |
1359 } | 1382 } |
1360 | 1383 |
1361 | 1384 |
1362 DART_EXPORT bool Dart_IsInteger(Dart_Handle object) { | 1385 DART_EXPORT bool Dart_IsInteger(Dart_Handle object) { |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1435 DART_EXPORT bool Dart_IsTypeVariable(Dart_Handle handle) { | 1458 DART_EXPORT bool Dart_IsTypeVariable(Dart_Handle handle) { |
1436 TRACE_API_CALL(CURRENT_FUNC); | 1459 TRACE_API_CALL(CURRENT_FUNC); |
1437 return Api::ClassId(handle) == kTypeParameterCid; | 1460 return Api::ClassId(handle) == kTypeParameterCid; |
1438 } | 1461 } |
1439 | 1462 |
1440 | 1463 |
1441 DART_EXPORT bool Dart_IsClosure(Dart_Handle object) { | 1464 DART_EXPORT bool Dart_IsClosure(Dart_Handle object) { |
1442 // We can't use a fast class index check here because there are many | 1465 // We can't use a fast class index check here because there are many |
1443 // different signature classes for closures. | 1466 // different signature classes for closures. |
1444 Isolate* isolate = Isolate::Current(); | 1467 Isolate* isolate = Isolate::Current(); |
1445 DARTSCOPE(isolate); | 1468 CHECK_ISOLATE(isolate); |
1446 const Instance& closure_obj = Api::UnwrapInstanceHandle(isolate, object); | 1469 ReusableObjectHandleScope reused_obj_handle(isolate); |
1470 const Instance& closure_obj = | |
1471 Api::UnwrapInstanceHandle(reused_obj_handle, object); | |
1447 return (!closure_obj.IsNull() && closure_obj.IsClosure()); | 1472 return (!closure_obj.IsNull() && closure_obj.IsClosure()); |
1448 } | 1473 } |
1449 | 1474 |
1450 | 1475 |
1451 // --- Instances ---- | 1476 // --- Instances ---- |
1452 | 1477 |
1453 DART_EXPORT Dart_Handle Dart_InstanceGetType(Dart_Handle instance) { | 1478 DART_EXPORT Dart_Handle Dart_InstanceGetType(Dart_Handle instance) { |
1454 Isolate* isolate = Isolate::Current(); | 1479 Isolate* isolate = Isolate::Current(); |
1455 DARTSCOPE(isolate); | 1480 DARTSCOPE(isolate); |
1456 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(instance)); | 1481 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(instance)); |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1683 *value = obj.value(); | 1708 *value = obj.value(); |
1684 return Api::Success(); | 1709 return Api::Success(); |
1685 } | 1710 } |
1686 | 1711 |
1687 | 1712 |
1688 // --- Strings --- | 1713 // --- Strings --- |
1689 | 1714 |
1690 | 1715 |
1691 DART_EXPORT Dart_Handle Dart_StringLength(Dart_Handle str, intptr_t* len) { | 1716 DART_EXPORT Dart_Handle Dart_StringLength(Dart_Handle str, intptr_t* len) { |
1692 Isolate* isolate = Isolate::Current(); | 1717 Isolate* isolate = Isolate::Current(); |
1693 DARTSCOPE(isolate); | 1718 CHECK_ISOLATE(isolate); |
1694 const String& str_obj = Api::UnwrapStringHandle(isolate, str); | 1719 ReusableObjectHandleScope reused_obj_handle(isolate); |
1720 const String& str_obj = Api::UnwrapStringHandle(reused_obj_handle, str); | |
1695 if (str_obj.IsNull()) { | 1721 if (str_obj.IsNull()) { |
1696 RETURN_TYPE_ERROR(isolate, str, String); | 1722 RETURN_TYPE_ERROR(isolate, str, String); |
1697 } | 1723 } |
1698 *len = str_obj.Length(); | 1724 *len = str_obj.Length(); |
1699 return Api::Success(); | 1725 return Api::Success(); |
1700 } | 1726 } |
1701 | 1727 |
1702 | 1728 |
1703 DART_EXPORT Dart_Handle Dart_NewStringFromCString(const char* str) { | 1729 DART_EXPORT Dart_Handle Dart_NewStringFromCString(const char* str) { |
1704 Isolate* isolate = Isolate::Current(); | 1730 Isolate* isolate = Isolate::Current(); |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1880 utf16_array[i] = static_cast<uint16_t>(str_obj.CharAt(i)); | 1906 utf16_array[i] = static_cast<uint16_t>(str_obj.CharAt(i)); |
1881 } | 1907 } |
1882 *length = copy_len; | 1908 *length = copy_len; |
1883 return Api::Success(); | 1909 return Api::Success(); |
1884 } | 1910 } |
1885 | 1911 |
1886 | 1912 |
1887 DART_EXPORT Dart_Handle Dart_StringStorageSize(Dart_Handle str, | 1913 DART_EXPORT Dart_Handle Dart_StringStorageSize(Dart_Handle str, |
1888 intptr_t* size) { | 1914 intptr_t* size) { |
1889 Isolate* isolate = Isolate::Current(); | 1915 Isolate* isolate = Isolate::Current(); |
1890 DARTSCOPE(isolate); | 1916 CHECK_ISOLATE(isolate); |
1891 const String& str_obj = Api::UnwrapStringHandle(isolate, str); | 1917 ReusableObjectHandleScope reused_obj_handle(isolate); |
1918 const String& str_obj = Api::UnwrapStringHandle(reused_obj_handle, str); | |
1892 if (str_obj.IsNull()) { | 1919 if (str_obj.IsNull()) { |
1893 RETURN_TYPE_ERROR(isolate, str, String); | 1920 RETURN_TYPE_ERROR(isolate, str, String); |
1894 } | 1921 } |
1895 if (size == NULL) { | 1922 if (size == NULL) { |
1896 RETURN_NULL_ERROR(size); | 1923 RETURN_NULL_ERROR(size); |
1897 } | 1924 } |
1898 *size = (str_obj.Length() * str_obj.CharSize()); | 1925 *size = (str_obj.Length() * str_obj.CharSize()); |
1899 return Api::Success(); | 1926 return Api::Success(); |
1900 } | 1927 } |
1901 | 1928 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1952 return Api::NewHandle(isolate, | 1979 return Api::NewHandle(isolate, |
1953 str_obj.MakeExternal(array, length, peer, cback)); | 1980 str_obj.MakeExternal(array, length, peer, cback)); |
1954 } | 1981 } |
1955 | 1982 |
1956 | 1983 |
1957 DART_EXPORT Dart_Handle Dart_StringGetProperties(Dart_Handle object, | 1984 DART_EXPORT Dart_Handle Dart_StringGetProperties(Dart_Handle object, |
1958 intptr_t* char_size, | 1985 intptr_t* char_size, |
1959 intptr_t* str_len, | 1986 intptr_t* str_len, |
1960 void** peer) { | 1987 void** peer) { |
1961 Isolate* isolate = Isolate::Current(); | 1988 Isolate* isolate = Isolate::Current(); |
1962 DARTSCOPE(isolate); | 1989 CHECK_ISOLATE(isolate); |
1963 const String& str = Api::UnwrapStringHandle(isolate, object); | 1990 ReusableObjectHandleScope reused_obj_handle(isolate); |
1991 const String& str = Api::UnwrapStringHandle(reused_obj_handle, object); | |
1964 if (str.IsNull()) { | 1992 if (str.IsNull()) { |
1965 RETURN_TYPE_ERROR(isolate, object, String); | 1993 RETURN_TYPE_ERROR(isolate, object, String); |
1966 } | 1994 } |
1967 if (str.IsExternal()) { | 1995 if (str.IsExternal()) { |
1968 *peer = str.GetPeer(); | 1996 *peer = str.GetPeer(); |
1969 ASSERT(*peer != NULL); | 1997 ASSERT(*peer != NULL); |
1970 } else { | 1998 } else { |
1971 NoGCScope no_gc_scope; | 1999 NoGCScope no_gc_scope; |
1972 *peer = isolate->heap()->GetPeer(str.raw()); | 2000 *peer = isolate->heap()->GetPeer(str.raw()); |
1973 } | 2001 } |
(...skipping 1773 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3747 return Api::NewError( | 3775 return Api::NewError( |
3748 "Unable to create native wrapper class : already exists"); | 3776 "Unable to create native wrapper class : already exists"); |
3749 } | 3777 } |
3750 return Api::NewHandle(isolate, cls.RareType()); | 3778 return Api::NewHandle(isolate, cls.RareType()); |
3751 } | 3779 } |
3752 | 3780 |
3753 | 3781 |
3754 DART_EXPORT Dart_Handle Dart_GetNativeInstanceFieldCount(Dart_Handle obj, | 3782 DART_EXPORT Dart_Handle Dart_GetNativeInstanceFieldCount(Dart_Handle obj, |
3755 int* count) { | 3783 int* count) { |
3756 Isolate* isolate = Isolate::Current(); | 3784 Isolate* isolate = Isolate::Current(); |
3757 DARTSCOPE(isolate); | 3785 CHECK_ISOLATE(isolate); |
3758 const Instance& instance = Api::UnwrapInstanceHandle(isolate, obj); | 3786 ReusableObjectHandleScope reused_obj_handle(isolate); |
3787 const Instance& instance = Api::UnwrapInstanceHandle(reused_obj_handle, obj); | |
3759 if (instance.IsNull()) { | 3788 if (instance.IsNull()) { |
3760 RETURN_TYPE_ERROR(isolate, obj, Instance); | 3789 RETURN_TYPE_ERROR(isolate, obj, Instance); |
3761 } | 3790 } |
3762 const Class& cls = Class::Handle(isolate, instance.clazz()); | 3791 const Class& cls = Class::Handle(isolate, instance.clazz()); |
3763 *count = cls.num_native_fields(); | 3792 *count = cls.num_native_fields(); |
3764 return Api::Success(); | 3793 return Api::Success(); |
3765 } | 3794 } |
3766 | 3795 |
3767 | 3796 |
3768 DART_EXPORT Dart_Handle Dart_GetNativeInstanceField(Dart_Handle obj, | 3797 DART_EXPORT Dart_Handle Dart_GetNativeInstanceField(Dart_Handle obj, |
3769 int index, | 3798 int index, |
3770 intptr_t* value) { | 3799 intptr_t* value) { |
3771 Isolate* isolate = Isolate::Current(); | 3800 Isolate* isolate = Isolate::Current(); |
3772 DARTSCOPE(isolate); | 3801 CHECK_ISOLATE(isolate); |
3773 const Instance& instance = Api::UnwrapInstanceHandle(isolate, obj); | 3802 ReusableObjectHandleScope reused_obj_handle(isolate); |
3803 const Instance& instance = Api::UnwrapInstanceHandle(reused_obj_handle, obj); | |
3774 if (instance.IsNull()) { | 3804 if (instance.IsNull()) { |
3775 RETURN_TYPE_ERROR(isolate, obj, Instance); | 3805 RETURN_TYPE_ERROR(isolate, obj, Instance); |
3776 } | 3806 } |
3777 if (!instance.IsValidNativeIndex(index)) { | 3807 if (!instance.IsValidNativeIndex(index)) { |
3778 return Api::NewError( | 3808 return Api::NewError( |
3779 "%s: invalid index %d passed in to access native instance field", | 3809 "%s: invalid index %d passed in to access native instance field", |
3780 CURRENT_FUNC, index); | 3810 CURRENT_FUNC, index); |
3781 } | 3811 } |
3782 *value = instance.GetNativeField(index); | 3812 *value = instance.GetNativeField(index); |
3783 return Api::Success(); | 3813 return Api::Success(); |
3784 } | 3814 } |
3785 | 3815 |
3786 | 3816 |
3787 DART_EXPORT Dart_Handle Dart_SetNativeInstanceField(Dart_Handle obj, | 3817 DART_EXPORT Dart_Handle Dart_SetNativeInstanceField(Dart_Handle obj, |
3788 int index, | 3818 int index, |
3789 intptr_t value) { | 3819 intptr_t value) { |
3790 Isolate* isolate = Isolate::Current(); | 3820 Isolate* isolate = Isolate::Current(); |
3791 DARTSCOPE(isolate); | 3821 CHECK_ISOLATE(isolate); |
3792 const Instance& instance = Api::UnwrapInstanceHandle(isolate, obj); | 3822 ReusableObjectHandleScope reused_obj_handle(isolate); |
3823 const Instance& instance = Api::UnwrapInstanceHandle(reused_obj_handle, obj); | |
3793 if (instance.IsNull()) { | 3824 if (instance.IsNull()) { |
3794 RETURN_TYPE_ERROR(isolate, obj, Instance); | 3825 RETURN_TYPE_ERROR(isolate, obj, Instance); |
3795 } | 3826 } |
3796 if (!instance.IsValidNativeIndex(index)) { | 3827 if (!instance.IsValidNativeIndex(index)) { |
3797 return Api::NewError( | 3828 return Api::NewError( |
3798 "%s: invalid index %d passed in to set native instance field", | 3829 "%s: invalid index %d passed in to set native instance field", |
3799 CURRENT_FUNC, index); | 3830 CURRENT_FUNC, index); |
3800 } | 3831 } |
3801 instance.SetNativeField(index, value); | 3832 instance.SetNativeField(index, value); |
3802 return Api::Success(); | 3833 return Api::Success(); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3839 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); | 3870 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); |
3840 if ((arg_index < 0) || (arg_index >= arguments->NativeArgCount())) { | 3871 if ((arg_index < 0) || (arg_index >= arguments->NativeArgCount())) { |
3841 return Api::NewError( | 3872 return Api::NewError( |
3842 "%s: argument 'arg_index' out of range. Expected 0..%d but saw %d.", | 3873 "%s: argument 'arg_index' out of range. Expected 0..%d but saw %d.", |
3843 CURRENT_FUNC, arguments->NativeArgCount() - 1, arg_index); | 3874 CURRENT_FUNC, arguments->NativeArgCount() - 1, arg_index); |
3844 } | 3875 } |
3845 if (field_values == NULL) { | 3876 if (field_values == NULL) { |
3846 RETURN_NULL_ERROR(field_values); | 3877 RETURN_NULL_ERROR(field_values); |
3847 } | 3878 } |
3848 Isolate* isolate = arguments->isolate(); | 3879 Isolate* isolate = arguments->isolate(); |
3849 DARTSCOPE(isolate); | 3880 CHECK_ISOLATE(isolate); |
3850 ReusableObjectHandleScope reused_obj_handle(isolate); | 3881 ReusableObjectHandleScope reused_obj_handle(isolate); |
3851 Object& obj = reused_obj_handle.Handle(); | 3882 Object& obj = reused_obj_handle.Handle(); |
3852 obj = arguments->NativeArgAt(arg_index); | 3883 obj = arguments->NativeArgAt(arg_index); |
3853 if (obj.IsNull()) { | 3884 if (obj.IsNull()) { |
3854 for (intptr_t i = 0; i < num_fields; i++) { | 3885 for (intptr_t i = 0; i < num_fields; i++) { |
3855 field_values[i] = 0; | 3886 field_values[i] = 0; |
3856 } | 3887 } |
3857 return Api::Success(); | 3888 return Api::Success(); |
3858 } | 3889 } |
3859 if (!obj.IsInstance()) { | 3890 if (!obj.IsInstance()) { |
(...skipping 13 matching lines...) Expand all Loading... | |
3873 | 3904 |
3874 | 3905 |
3875 DART_EXPORT Dart_Handle Dart_GetNativeReceiver(Dart_NativeArguments args, | 3906 DART_EXPORT Dart_Handle Dart_GetNativeReceiver(Dart_NativeArguments args, |
3876 intptr_t* value) { | 3907 intptr_t* value) { |
3877 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); | 3908 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); |
3878 Isolate* isolate = arguments->isolate(); | 3909 Isolate* isolate = arguments->isolate(); |
3879 CHECK_ISOLATE(isolate); | 3910 CHECK_ISOLATE(isolate); |
3880 if (value == NULL) { | 3911 if (value == NULL) { |
3881 RETURN_NULL_ERROR(value); | 3912 RETURN_NULL_ERROR(value); |
3882 } | 3913 } |
3883 if (Api::GetNativeReceiver(args, value)) { | 3914 if (Api::GetNativeReceiver(arguments, value)) { |
3884 return Api::Success(); | 3915 return Api::Success(); |
3885 } | 3916 } |
3886 return Api::NewError("%s expects receiver argument to be non-null and of" | 3917 return Api::NewError("%s expects receiver argument to be non-null and of" |
3887 " type Instance.", CURRENT_FUNC); | 3918 " type Instance.", CURRENT_FUNC); |
3888 } | 3919 } |
3889 | 3920 |
3890 | 3921 |
3891 DART_EXPORT Dart_Handle Dart_GetNativeStringArgument(Dart_NativeArguments args, | 3922 DART_EXPORT Dart_Handle Dart_GetNativeStringArgument(Dart_NativeArguments args, |
3892 int arg_index, | 3923 int arg_index, |
3893 void** peer) { | 3924 void** peer) { |
3894 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); | 3925 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); |
3895 Isolate* isolate = arguments->isolate(); | 3926 Isolate* isolate = arguments->isolate(); |
3896 CHECK_ISOLATE(isolate); | 3927 CHECK_ISOLATE(isolate); |
3897 if (Api::StringGetPeerHelper(args, arg_index, peer)) { | 3928 if (Api::StringGetPeerHelper(arguments, arg_index, peer)) { |
3898 return Api::Success(); | 3929 return Api::Success(); |
3899 } | 3930 } |
3900 *peer = NULL; | 3931 *peer = NULL; |
3901 ReusableObjectHandleScope reused_obj_handle(isolate); | 3932 ReusableObjectHandleScope reused_obj_handle(isolate); |
3902 Object& obj = reused_obj_handle.Handle(); | 3933 Object& obj = reused_obj_handle.Handle(); |
3903 obj = arguments->NativeArgAt(arg_index); | 3934 obj = arguments->NativeArgAt(arg_index); |
3904 if (RawObject::IsStringClassId(obj.GetClassId())) { | 3935 if (RawObject::IsStringClassId(obj.GetClassId())) { |
3905 return Api::NewHandle(isolate, obj.raw()); | 3936 return Api::NewHandle(isolate, obj.raw()); |
3906 } | 3937 } |
3907 if (obj.IsNull()) { | 3938 if (obj.IsNull()) { |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3954 DART_EXPORT Dart_Handle Dart_GetNativeBooleanArgument(Dart_NativeArguments args, | 3985 DART_EXPORT Dart_Handle Dart_GetNativeBooleanArgument(Dart_NativeArguments args, |
3955 int index, | 3986 int index, |
3956 bool* value) { | 3987 bool* value) { |
3957 TRACE_API_CALL(CURRENT_FUNC); | 3988 TRACE_API_CALL(CURRENT_FUNC); |
3958 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); | 3989 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); |
3959 if ((index < 0) || (index >= arguments->NativeArgCount())) { | 3990 if ((index < 0) || (index >= arguments->NativeArgCount())) { |
3960 return Api::NewError( | 3991 return Api::NewError( |
3961 "%s: argument 'index' out of range. Expected 0..%d but saw %d.", | 3992 "%s: argument 'index' out of range. Expected 0..%d but saw %d.", |
3962 CURRENT_FUNC, arguments->NativeArgCount() - 1, index); | 3993 CURRENT_FUNC, arguments->NativeArgCount() - 1, index); |
3963 } | 3994 } |
3964 if (Api::GetNativeBooleanArgument(args, index, value)) { | 3995 if (Api::GetNativeBooleanArgument(arguments, index, value)) { |
3965 return Api::Success(); | 3996 return Api::Success(); |
3966 } | 3997 } |
3967 return Api::NewError("%s: argument %d is not a Boolean argument.", | 3998 return Api::NewError("%s: argument %d is not a Boolean argument.", |
3968 CURRENT_FUNC, index); | 3999 CURRENT_FUNC, index); |
3969 } | 4000 } |
3970 | 4001 |
3971 | 4002 |
3972 DART_EXPORT Dart_Handle Dart_GetNativeDoubleArgument(Dart_NativeArguments args, | 4003 DART_EXPORT Dart_Handle Dart_GetNativeDoubleArgument(Dart_NativeArguments args, |
3973 int index, | 4004 int index, |
3974 double* value) { | 4005 double* value) { |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4204 } | 4235 } |
4205 library ^= tmp.raw(); | 4236 library ^= tmp.raw(); |
4206 library.set_debuggable(true); | 4237 library.set_debuggable(true); |
4207 isolate->object_store()->set_root_library(library); | 4238 isolate->object_store()->set_root_library(library); |
4208 return Api::NewHandle(isolate, library.raw()); | 4239 return Api::NewHandle(isolate, library.raw()); |
4209 } | 4240 } |
4210 | 4241 |
4211 | 4242 |
4212 DART_EXPORT Dart_Handle Dart_RootLibrary() { | 4243 DART_EXPORT Dart_Handle Dart_RootLibrary() { |
4213 Isolate* isolate = Isolate::Current(); | 4244 Isolate* isolate = Isolate::Current(); |
4214 DARTSCOPE(isolate); | 4245 CHECK_ISOLATE(isolate); |
4215 Library& library = | 4246 return Api::NewHandle(isolate, isolate->object_store()->root_library()); |
4216 Library::Handle(isolate, isolate->object_store()->root_library()); | |
4217 return Api::NewHandle(isolate, library.raw()); | |
4218 } | 4247 } |
4219 | 4248 |
4220 | 4249 |
4221 DART_EXPORT Dart_Handle Dart_GetClass(Dart_Handle library, | 4250 DART_EXPORT Dart_Handle Dart_GetClass(Dart_Handle library, |
4222 Dart_Handle class_name) { | 4251 Dart_Handle class_name) { |
4223 Isolate* isolate = Isolate::Current(); | 4252 Isolate* isolate = Isolate::Current(); |
4224 DARTSCOPE(isolate); | 4253 DARTSCOPE(isolate); |
4225 const Library& lib = Api::UnwrapLibraryHandle(isolate, library); | 4254 const Library& lib = Api::UnwrapLibraryHandle(isolate, library); |
4226 if (lib.IsNull()) { | 4255 if (lib.IsNull()) { |
4227 RETURN_TYPE_ERROR(isolate, library, Library); | 4256 RETURN_TYPE_ERROR(isolate, library, Library); |
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4513 } | 4542 } |
4514 | 4543 |
4515 | 4544 |
4516 // --- Peer support --- | 4545 // --- Peer support --- |
4517 | 4546 |
4518 DART_EXPORT Dart_Handle Dart_GetPeer(Dart_Handle object, void** peer) { | 4547 DART_EXPORT Dart_Handle Dart_GetPeer(Dart_Handle object, void** peer) { |
4519 if (peer == NULL) { | 4548 if (peer == NULL) { |
4520 RETURN_NULL_ERROR(peer); | 4549 RETURN_NULL_ERROR(peer); |
4521 } | 4550 } |
4522 Isolate* isolate = Isolate::Current(); | 4551 Isolate* isolate = Isolate::Current(); |
4523 DARTSCOPE(isolate); | 4552 CHECK_ISOLATE(isolate); |
4524 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(object)); | 4553 ReusableObjectHandleScope reused_obj_handle(isolate); |
4554 Object& obj = reused_obj_handle.Handle(); | |
4555 obj = Api::UnwrapHandle(object); | |
4525 if (obj.IsNull() || obj.IsNumber() || obj.IsBool()) { | 4556 if (obj.IsNull() || obj.IsNumber() || obj.IsBool()) { |
4526 const char* msg = | 4557 const char* msg = |
4527 "%s: argument 'object' cannot be a subtype of Null, num, or bool"; | 4558 "%s: argument 'object' cannot be a subtype of Null, num, or bool"; |
4528 return Api::NewError(msg, CURRENT_FUNC); | 4559 return Api::NewError(msg, CURRENT_FUNC); |
4529 } | 4560 } |
4530 { | 4561 { |
4531 NoGCScope no_gc; | 4562 NoGCScope no_gc; |
4532 RawObject* raw_obj = obj.raw(); | 4563 RawObject* raw_obj = obj.raw(); |
4533 *peer = isolate->heap()->GetPeer(raw_obj); | 4564 *peer = isolate->heap()->GetPeer(raw_obj); |
4534 } | 4565 } |
4535 return Api::Success(); | 4566 return Api::Success(); |
4536 } | 4567 } |
4537 | 4568 |
4538 | 4569 |
4539 DART_EXPORT Dart_Handle Dart_SetPeer(Dart_Handle object, void* peer) { | 4570 DART_EXPORT Dart_Handle Dart_SetPeer(Dart_Handle object, void* peer) { |
4540 Isolate* isolate = Isolate::Current(); | 4571 Isolate* isolate = Isolate::Current(); |
4541 DARTSCOPE(isolate); | 4572 CHECK_ISOLATE(isolate); |
4542 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(object)); | 4573 ReusableObjectHandleScope reused_obj_handle(isolate); |
4574 Object& obj = reused_obj_handle.Handle(); | |
4575 obj = Api::UnwrapHandle(object); | |
4543 if (obj.IsNull() || obj.IsNumber() || obj.IsBool()) { | 4576 if (obj.IsNull() || obj.IsNumber() || obj.IsBool()) { |
4544 const char* msg = | 4577 const char* msg = |
4545 "%s: argument 'object' cannot be a subtype of Null, num, or bool"; | 4578 "%s: argument 'object' cannot be a subtype of Null, num, or bool"; |
4546 return Api::NewError(msg, CURRENT_FUNC); | 4579 return Api::NewError(msg, CURRENT_FUNC); |
4547 } | 4580 } |
4548 { | 4581 { |
4549 NoGCScope no_gc; | 4582 NoGCScope no_gc; |
4550 RawObject* raw_obj = obj.raw(); | 4583 RawObject* raw_obj = obj.raw(); |
4551 isolate->heap()->SetPeer(raw_obj, peer); | 4584 isolate->heap()->SetPeer(raw_obj, peer); |
4552 } | 4585 } |
(...skipping 22 matching lines...) Expand all Loading... | |
4575 | 4608 |
4576 | 4609 |
4577 DART_EXPORT void Dart_RegisterRootServiceRequestCallback( | 4610 DART_EXPORT void Dart_RegisterRootServiceRequestCallback( |
4578 const char* name, | 4611 const char* name, |
4579 Dart_ServiceRequestCallback callback, | 4612 Dart_ServiceRequestCallback callback, |
4580 void* user_data) { | 4613 void* user_data) { |
4581 Service::RegisterRootEmbedderCallback(name, callback, user_data); | 4614 Service::RegisterRootEmbedderCallback(name, callback, user_data); |
4582 } | 4615 } |
4583 | 4616 |
4584 } // namespace dart | 4617 } // namespace dart |
OLD | NEW |