| 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 3701 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3712 Object& obj = reused_obj_handle.Handle(); | 3712 Object& obj = reused_obj_handle.Handle(); |
| 3713 obj = arguments->NativeArgAt(arg_index); | 3713 obj = arguments->NativeArgAt(arg_index); |
| 3714 if (RawObject::IsStringClassId(obj.GetClassId())) { | 3714 if (RawObject::IsStringClassId(obj.GetClassId())) { |
| 3715 return Api::NewHandle(isolate, obj.raw()); | 3715 return Api::NewHandle(isolate, obj.raw()); |
| 3716 } | 3716 } |
| 3717 return Api::NewError("%s expects argument to be of" | 3717 return Api::NewError("%s expects argument to be of" |
| 3718 " type String.", CURRENT_FUNC); | 3718 " type String.", CURRENT_FUNC); |
| 3719 } | 3719 } |
| 3720 | 3720 |
| 3721 | 3721 |
| 3722 DART_EXPORT Dart_Handle Dart_GetNativeIntegerArgument(Dart_NativeArguments args, |
| 3723 int index, |
| 3724 int64_t* value) { |
| 3725 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); |
| 3726 if ((index < 0) || (index >= arguments->NativeArgCount())) { |
| 3727 return Api::NewError( |
| 3728 "%s: argument 'index' out of range. Expected 0..%d but saw %d.", |
| 3729 CURRENT_FUNC, arguments->NativeArgCount() - 1, index); |
| 3730 } |
| 3731 Isolate* isolate = arguments->isolate(); |
| 3732 ReusableObjectHandleScope reused_obj_handle(isolate); |
| 3733 Object& obj = reused_obj_handle.Handle(); |
| 3734 obj = arguments->NativeArgAt(index); |
| 3735 intptr_t cid = obj.GetClassId(); |
| 3736 if (cid == kSmiCid) { |
| 3737 *value = Smi::Cast(obj).Value(); |
| 3738 return Api::Success(); |
| 3739 } |
| 3740 if (cid == kMintCid) { |
| 3741 *value = Mint::Cast(obj).value(); |
| 3742 return Api::Success(); |
| 3743 } |
| 3744 if (cid == kBigintCid) { |
| 3745 const Bigint& bigint = Bigint::Cast(obj); |
| 3746 if (BigintOperations::FitsIntoInt64(bigint)) { |
| 3747 *value = BigintOperations::ToInt64(bigint); |
| 3748 return Api::Success(); |
| 3749 } |
| 3750 return Api::NewError( |
| 3751 "%s: argument %d is a big integer that does not fit in 'value'.", |
| 3752 CURRENT_FUNC, index); |
| 3753 } |
| 3754 return Api::NewError( |
| 3755 "%s: argument %d is not an Integer argument.", |
| 3756 CURRENT_FUNC, index); |
| 3757 } |
| 3758 |
| 3759 |
| 3760 DART_EXPORT Dart_Handle Dart_GetNativeBooleanArgument(Dart_NativeArguments args, |
| 3761 int index, |
| 3762 bool* value) { |
| 3763 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); |
| 3764 if ((index < 0) || (index >= arguments->NativeArgCount())) { |
| 3765 return Api::NewError( |
| 3766 "%s: argument 'index' out of range. Expected 0..%d but saw %d.", |
| 3767 CURRENT_FUNC, arguments->NativeArgCount() - 1, index); |
| 3768 } |
| 3769 Isolate* isolate = arguments->isolate(); |
| 3770 ReusableObjectHandleScope reused_obj_handle(isolate); |
| 3771 Object& obj = reused_obj_handle.Handle(); |
| 3772 obj = arguments->NativeArgAt(index); |
| 3773 intptr_t cid = obj.GetClassId(); |
| 3774 if (cid == kBoolCid) { |
| 3775 *value = Bool::Cast(obj).value(); |
| 3776 return Api::Success(); |
| 3777 } |
| 3778 if (obj.IsNull()) { |
| 3779 *value = false; |
| 3780 return Api::Success(); |
| 3781 } |
| 3782 return Api::NewError( |
| 3783 "%s: argument %d is not a Boolean argument.", |
| 3784 CURRENT_FUNC, index); |
| 3785 } |
| 3786 |
| 3787 |
| 3788 DART_EXPORT Dart_Handle Dart_GetNativeDoubleArgument(Dart_NativeArguments args, |
| 3789 int index, |
| 3790 double* value) { |
| 3791 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); |
| 3792 if ((index < 0) || (index >= arguments->NativeArgCount())) { |
| 3793 return Api::NewError( |
| 3794 "%s: argument 'index' out of range. Expected 0..%d but saw %d.", |
| 3795 CURRENT_FUNC, arguments->NativeArgCount() - 1, index); |
| 3796 } |
| 3797 Isolate* isolate = arguments->isolate(); |
| 3798 ReusableObjectHandleScope reused_obj_handle(isolate); |
| 3799 Object& obj = reused_obj_handle.Handle(); |
| 3800 obj = arguments->NativeArgAt(index); |
| 3801 intptr_t cid = obj.GetClassId(); |
| 3802 if (cid == kDoubleCid) { |
| 3803 *value = Double::Cast(obj).value(); |
| 3804 return Api::Success(); |
| 3805 } |
| 3806 if (cid == kSmiCid) { |
| 3807 *value = Smi::Cast(obj).AsDoubleValue(); |
| 3808 return Api::Success(); |
| 3809 } |
| 3810 if (cid == kMintCid) { |
| 3811 *value = Mint::Cast(obj).AsDoubleValue(); |
| 3812 return Api::Success(); |
| 3813 } |
| 3814 if (cid == kBigintCid) { |
| 3815 *value = Bigint::Cast(obj).AsDoubleValue(); |
| 3816 return Api::Success(); |
| 3817 } |
| 3818 return Api::NewError( |
| 3819 "%s: argument %d is not a Double argument.", |
| 3820 CURRENT_FUNC, index); |
| 3821 } |
| 3822 |
| 3823 |
| 3722 DART_EXPORT void Dart_SetReturnValue(Dart_NativeArguments args, | 3824 DART_EXPORT void Dart_SetReturnValue(Dart_NativeArguments args, |
| 3723 Dart_Handle retval) { | 3825 Dart_Handle retval) { |
| 3724 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); | 3826 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); |
| 3725 Isolate* isolate = arguments->isolate(); | 3827 Isolate* isolate = arguments->isolate(); |
| 3726 CHECK_ISOLATE(isolate); | 3828 CHECK_ISOLATE(isolate); |
| 3727 if ((retval != Api::Null()) && (!Api::IsInstance(retval))) { | 3829 if ((retval != Api::Null()) && (!Api::IsInstance(retval))) { |
| 3728 const Object& ret_obj = Object::Handle(Api::UnwrapHandle(retval)); | 3830 const Object& ret_obj = Object::Handle(Api::UnwrapHandle(retval)); |
| 3729 FATAL1("Return value check failed: saw '%s' expected a dart Instance.", | 3831 FATAL1("Return value check failed: saw '%s' expected a dart Instance.", |
| 3730 ret_obj.ToCString()); | 3832 ret_obj.ToCString()); |
| 3731 } | 3833 } |
| (...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4249 } | 4351 } |
| 4250 { | 4352 { |
| 4251 NoGCScope no_gc; | 4353 NoGCScope no_gc; |
| 4252 RawObject* raw_obj = obj.raw(); | 4354 RawObject* raw_obj = obj.raw(); |
| 4253 isolate->heap()->SetPeer(raw_obj, peer); | 4355 isolate->heap()->SetPeer(raw_obj, peer); |
| 4254 } | 4356 } |
| 4255 return Api::Success(); | 4357 return Api::Success(); |
| 4256 } | 4358 } |
| 4257 | 4359 |
| 4258 } // namespace dart | 4360 } // namespace dart |
| OLD | NEW |