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" |
11 #include "vm/class_finalizer.h" | 11 #include "vm/class_finalizer.h" |
12 #include "vm/compiler.h" | 12 #include "vm/compiler.h" |
13 #include "vm/dart.h" | 13 #include "vm/dart.h" |
14 #include "vm/dart_api_impl.h" | 14 #include "vm/dart_api_impl.h" |
15 #include "vm/dart_api_message.h" | 15 #include "vm/dart_api_message.h" |
16 #include "vm/dart_api_state.h" | 16 #include "vm/dart_api_state.h" |
17 #include "vm/dart_entry.h" | 17 #include "vm/dart_entry.h" |
18 #include "vm/debuginfo.h" | 18 #include "vm/debuginfo.h" |
19 #include "vm/exceptions.h" | 19 #include "vm/exceptions.h" |
20 #include "vm/flags.h" | 20 #include "vm/flags.h" |
21 #include "vm/growable_array.h" | 21 #include "vm/growable_array.h" |
22 #include "vm/message.h" | 22 #include "vm/message.h" |
23 #include "vm/message_handler.h" | 23 #include "vm/message_handler.h" |
24 #include "vm/native_entry.h" | 24 #include "vm/native_entry.h" |
25 #include "vm/object.h" | 25 #include "vm/object.h" |
26 #include "vm/object_store.h" | 26 #include "vm/object_store.h" |
27 #include "vm/port.h" | 27 #include "vm/port.h" |
28 #include "vm/resolver.h" | 28 #include "vm/resolver.h" |
29 #include "vm/reusable_handles.h" | |
29 #include "vm/stack_frame.h" | 30 #include "vm/stack_frame.h" |
30 #include "vm/symbols.h" | 31 #include "vm/symbols.h" |
31 #include "vm/timer.h" | 32 #include "vm/timer.h" |
32 #include "vm/unicode.h" | 33 #include "vm/unicode.h" |
33 #include "vm/verifier.h" | 34 #include "vm/verifier.h" |
34 #include "vm/version.h" | 35 #include "vm/version.h" |
35 | 36 |
36 namespace dart { | 37 namespace dart { |
37 | 38 |
38 DECLARE_FLAG(bool, print_class_table); | 39 DECLARE_FLAG(bool, print_class_table); |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
255 reinterpret_cast<RawExternalTwoByteString*>(raw_obj)->ptr(); | 256 reinterpret_cast<RawExternalTwoByteString*>(raw_obj)->ptr(); |
256 ExternalStringData<uint16_t>* data = raw_string->external_data_; | 257 ExternalStringData<uint16_t>* data = raw_string->external_data_; |
257 *peer = data->peer(); | 258 *peer = data->peer(); |
258 return true; | 259 return true; |
259 } | 260 } |
260 } | 261 } |
261 return false; | 262 return false; |
262 } | 263 } |
263 | 264 |
264 | 265 |
266 void Api::SetWeakHandleReturnValue(NativeArguments* args, | |
267 Dart_WeakPersistentHandle retval) { | |
268 args->SetReturnUnsafe( | |
269 reinterpret_cast<FinalizablePersistentHandle*>(retval)->raw()); | |
270 } | |
271 | |
272 | |
265 // --- Handles --- | 273 // --- Handles --- |
266 | 274 |
267 DART_EXPORT bool Dart_IsError(Dart_Handle handle) { | 275 DART_EXPORT bool Dart_IsError(Dart_Handle handle) { |
268 return RawObject::IsErrorClassId(Api::ClassId(handle)); | 276 return RawObject::IsErrorClassId(Api::ClassId(handle)); |
269 } | 277 } |
270 | 278 |
271 | 279 |
272 DART_EXPORT bool Dart_IsApiError(Dart_Handle object) { | 280 DART_EXPORT bool Dart_IsApiError(Dart_Handle object) { |
273 return Api::ClassId(object) == kApiErrorCid; | 281 return Api::ClassId(object) == kApiErrorCid; |
274 } | 282 } |
(...skipping 850 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1125 // --- Objects ---- | 1133 // --- Objects ---- |
1126 | 1134 |
1127 DART_EXPORT Dart_Handle Dart_Null() { | 1135 DART_EXPORT Dart_Handle Dart_Null() { |
1128 Isolate* isolate = Isolate::Current(); | 1136 Isolate* isolate = Isolate::Current(); |
1129 CHECK_ISOLATE_SCOPE(isolate); | 1137 CHECK_ISOLATE_SCOPE(isolate); |
1130 return Api::Null(); | 1138 return Api::Null(); |
1131 } | 1139 } |
1132 | 1140 |
1133 | 1141 |
1134 DART_EXPORT bool Dart_IsNull(Dart_Handle object) { | 1142 DART_EXPORT bool Dart_IsNull(Dart_Handle object) { |
1135 return Api::ClassId(object) == kNullCid; | 1143 return Api::UnwrapHandle(object) == Object::null(); |
1136 } | 1144 } |
1137 | 1145 |
1138 | 1146 |
1139 DART_EXPORT Dart_Handle Dart_ObjectEquals(Dart_Handle obj1, Dart_Handle obj2, | 1147 DART_EXPORT Dart_Handle Dart_ObjectEquals(Dart_Handle obj1, Dart_Handle obj2, |
1140 bool* value) { | 1148 bool* value) { |
1141 Isolate* isolate = Isolate::Current(); | 1149 Isolate* isolate = Isolate::Current(); |
1142 DARTSCOPE(isolate); | 1150 DARTSCOPE(isolate); |
1143 CHECK_CALLBACK_STATE(isolate); | 1151 CHECK_CALLBACK_STATE(isolate); |
1144 const Instance& expected = | 1152 const Instance& expected = |
1145 Instance::CheckedHandle(isolate, Api::UnwrapHandle(obj1)); | 1153 Instance::CheckedHandle(isolate, Api::UnwrapHandle(obj1)); |
(...skipping 689 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1835 utf16_array[i] = static_cast<uint16_t>(str_obj.CharAt(i)); | 1843 utf16_array[i] = static_cast<uint16_t>(str_obj.CharAt(i)); |
1836 } | 1844 } |
1837 } | 1845 } |
1838 return Api::Null(); | 1846 return Api::Null(); |
1839 } | 1847 } |
1840 return Api::NewHandle(isolate, | 1848 return Api::NewHandle(isolate, |
1841 str_obj.MakeExternal(array, length, peer, cback)); | 1849 str_obj.MakeExternal(array, length, peer, cback)); |
1842 } | 1850 } |
1843 | 1851 |
1844 | 1852 |
1853 DART_EXPORT Dart_Handle Dart_StringGetProperties(Dart_Handle object, | |
1854 intptr_t* char_size, | |
1855 intptr_t* str_len, | |
1856 void** peer) { | |
1857 Isolate* isolate = Isolate::Current(); | |
1858 DARTSCOPE(isolate); | |
1859 const String& str = Api::UnwrapStringHandle(isolate, object); | |
vsm
2013/08/12 17:59:04
Do you need some error checking if the object is n
siva
2013/08/13 01:19:09
Done.
| |
1860 if (str.IsExternal()) { | |
1861 *peer = str.GetPeer(); | |
1862 ASSERT(*peer != 0); | |
srdjan
2013/08/12 18:09:57
Should this be 0 or NULL? (also below).
siva
2013/08/13 01:19:09
Done.
| |
1863 } else { | |
1864 *peer = 0; | |
1865 } | |
1866 *char_size = str.CharSize(); | |
1867 *str_len = str.Length(); | |
1868 return Api::Success(); | |
1869 } | |
1870 | |
1871 | |
1845 // --- Lists --- | 1872 // --- Lists --- |
1846 | 1873 |
1847 DART_EXPORT Dart_Handle Dart_NewList(intptr_t length) { | 1874 DART_EXPORT Dart_Handle Dart_NewList(intptr_t length) { |
1848 Isolate* isolate = Isolate::Current(); | 1875 Isolate* isolate = Isolate::Current(); |
1849 DARTSCOPE(isolate); | 1876 DARTSCOPE(isolate); |
1850 CHECK_LENGTH(length, Array::kMaxElements); | 1877 CHECK_LENGTH(length, Array::kMaxElements); |
1851 CHECK_CALLBACK_STATE(isolate); | 1878 CHECK_CALLBACK_STATE(isolate); |
1852 return Api::NewHandle(isolate, Array::New(length)); | 1879 return Api::NewHandle(isolate, Array::New(length)); |
1853 } | 1880 } |
1854 | 1881 |
(...skipping 1761 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3616 "%s: invalid index %d passed in to access native instance field", | 3643 "%s: invalid index %d passed in to access native instance field", |
3617 CURRENT_FUNC, fld_index); | 3644 CURRENT_FUNC, fld_index); |
3618 } | 3645 } |
3619 if (value == NULL) { | 3646 if (value == NULL) { |
3620 RETURN_NULL_ERROR(value); | 3647 RETURN_NULL_ERROR(value); |
3621 } | 3648 } |
3622 *value = instance.GetNativeField(isolate, fld_index); | 3649 *value = instance.GetNativeField(isolate, fld_index); |
3623 return Api::Success(); | 3650 return Api::Success(); |
3624 } | 3651 } |
3625 | 3652 |
3653 | |
3626 DART_EXPORT Dart_Handle Dart_GetNativeReceiver(Dart_NativeArguments args, | 3654 DART_EXPORT Dart_Handle Dart_GetNativeReceiver(Dart_NativeArguments args, |
3627 intptr_t* value) { | 3655 intptr_t* value) { |
3628 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); | 3656 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); |
3629 Isolate* isolate = arguments->isolate(); | 3657 Isolate* isolate = arguments->isolate(); |
3630 DARTSCOPE(isolate); | 3658 CHECK_ISOLATE(isolate); |
3631 const Object& obj = Object::Handle(isolate, arguments->NativeArgAt(0)); | 3659 ReusableObjectHandleScope reused_obj_handle(isolate); |
3660 Object& obj = reused_obj_handle.Handle(); | |
3661 obj = arguments->NativeArgAt(0); | |
3632 intptr_t cid = obj.GetClassId(); | 3662 intptr_t cid = obj.GetClassId(); |
3633 if (cid <= kNumPredefinedCids) { | 3663 if (cid <= kNumPredefinedCids) { |
3634 if (cid == kNullCid) { | 3664 if (cid == kNullCid) { |
3635 return Api::NewError("%s expects receiver argument to be non-null.", | 3665 return Api::NewError("%s expects receiver argument to be non-null.", |
3636 CURRENT_FUNC); | 3666 CURRENT_FUNC); |
3637 } | 3667 } |
3638 return Api::NewError("%s expects receiver argument to be of" | 3668 return Api::NewError("%s expects receiver argument to be of" |
3639 " type Instance.", CURRENT_FUNC); | 3669 " type Instance.", CURRENT_FUNC); |
3640 } | 3670 } |
3641 const Instance& instance = Instance::Cast(obj); | 3671 const Instance& instance = Instance::Cast(obj); |
3642 ASSERT(instance.IsValidNativeIndex(0)); | 3672 ASSERT(instance.IsValidNativeIndex(0)); |
3643 if (value == NULL) { | 3673 if (value == NULL) { |
3644 RETURN_NULL_ERROR(value); | 3674 RETURN_NULL_ERROR(value); |
3645 } | 3675 } |
3646 *value = instance.GetNativeField(isolate, 0); | 3676 *value = instance.GetNativeField(isolate, 0); |
3647 return Api::Success(); | 3677 return Api::Success(); |
3648 } | 3678 } |
3649 | 3679 |
3650 | 3680 |
3681 DART_EXPORT Dart_Handle Dart_GetNativeStringArgument(Dart_NativeArguments args, | |
3682 int arg_index, | |
3683 void** peer) { | |
3684 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); | |
3685 Isolate* isolate = arguments->isolate(); | |
3686 CHECK_ISOLATE(isolate); | |
3687 ReusableObjectHandleScope reused_obj_handle(isolate); | |
3688 Object& obj = reused_obj_handle.Handle(); | |
3689 obj = arguments->NativeArgAt(arg_index); | |
3690 intptr_t cid = obj.GetClassId(); | |
3691 if (RawObject::IsExternalStringClassId(cid)) { | |
3692 const String& str = String::Cast(obj); | |
3693 *peer = str.GetPeer(); | |
3694 ASSERT(*peer != 0); | |
srdjan
2013/08/12 18:09:57
ditto?
siva
2013/08/13 01:19:09
Done.
| |
3695 return Api::Success(); | |
3696 } | |
3697 *peer = 0; | |
srdjan
2013/08/12 18:09:57
ditto
siva
2013/08/13 01:19:09
Done.
| |
3698 if (RawObject::IsStringClassId(cid)) { | |
3699 return Api::NewHandle(isolate, obj.raw()); | |
3700 } | |
3701 return Api::NewError("%s expects argument to be of" | |
3702 " type String.", CURRENT_FUNC); | |
3703 } | |
3704 | |
3705 | |
3651 DART_EXPORT void Dart_SetReturnValue(Dart_NativeArguments args, | 3706 DART_EXPORT void Dart_SetReturnValue(Dart_NativeArguments args, |
3652 Dart_Handle retval) { | 3707 Dart_Handle retval) { |
3653 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); | 3708 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); |
3654 Isolate* isolate = arguments->isolate(); | 3709 Isolate* isolate = arguments->isolate(); |
3655 CHECK_ISOLATE(isolate); | 3710 CHECK_ISOLATE(isolate); |
3656 if ((retval != Api::Null()) && (!Api::IsInstance(retval))) { | 3711 if ((retval != Api::Null()) && (!Api::IsInstance(retval))) { |
3657 const Object& ret_obj = Object::Handle(Api::UnwrapHandle(retval)); | 3712 const Object& ret_obj = Object::Handle(Api::UnwrapHandle(retval)); |
3658 FATAL1("Return value check failed: saw '%s' expected a dart Instance.", | 3713 FATAL1("Return value check failed: saw '%s' expected a dart Instance.", |
3659 ret_obj.ToCString()); | 3714 ret_obj.ToCString()); |
3660 } | 3715 } |
3661 ASSERT(retval != 0); | 3716 ASSERT(retval != 0); |
3662 Api::SetReturnValue(arguments, retval); | 3717 Api::SetReturnValue(arguments, retval); |
3663 } | 3718 } |
3664 | 3719 |
3665 | 3720 |
3721 DART_EXPORT void Dart_SetWeakHandleReturnValue(Dart_NativeArguments args, | |
3722 Dart_WeakPersistentHandle rval) { | |
3723 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); | |
3724 Isolate* isolate = arguments->isolate(); | |
3725 CHECK_ISOLATE(isolate); | |
3726 ASSERT(isolate->api_state() != NULL && | |
3727 (isolate->api_state()->IsValidWeakPersistentHandle(rval) || | |
3728 isolate->api_state()->IsValidPrologueWeakPersistentHandle(rval))); | |
3729 Api::SetWeakHandleReturnValue(arguments, rval); | |
3730 } | |
3731 | |
3732 | |
3666 DART_EXPORT void Dart_SetBooleanReturnValue(Dart_NativeArguments args, | 3733 DART_EXPORT void Dart_SetBooleanReturnValue(Dart_NativeArguments args, |
3667 bool retval) { | 3734 bool retval) { |
3668 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); | 3735 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); |
3669 arguments->SetReturn(retval ? Bool::True() : Bool::False()); | 3736 arguments->SetReturn(retval ? Bool::True() : Bool::False()); |
3670 } | 3737 } |
3671 | 3738 |
3672 | 3739 |
3673 DART_EXPORT void Dart_SetIntegerReturnValue(Dart_NativeArguments args, | 3740 DART_EXPORT void Dart_SetIntegerReturnValue(Dart_NativeArguments args, |
3674 intptr_t retval) { | 3741 intptr_t retval) { |
3675 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); | 3742 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); |
(...skipping 490 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4166 } | 4233 } |
4167 { | 4234 { |
4168 NoGCScope no_gc; | 4235 NoGCScope no_gc; |
4169 RawObject* raw_obj = obj.raw(); | 4236 RawObject* raw_obj = obj.raw(); |
4170 isolate->heap()->SetPeer(raw_obj, peer); | 4237 isolate->heap()->SetPeer(raw_obj, peer); |
4171 } | 4238 } |
4172 return Api::Success(); | 4239 return Api::Success(); |
4173 } | 4240 } |
4174 | 4241 |
4175 } // namespace dart | 4242 } // namespace dart |
OLD | NEW |