Chromium Code Reviews| 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 } | |
| 3751 return Api::NewError( | |
| 3752 "%s: argument %d is not an Integer argument.", | |
|
srdjan
2013/08/21 22:58:43
Is that correct error message for kBigint that doe
siva
2013/08/21 23:08:57
Good point.
I will add a new error return inside
i
| |
| 3753 CURRENT_FUNC, index); | |
| 3754 } | |
| 3755 | |
| 3756 | |
| 3757 DART_EXPORT Dart_Handle Dart_GetNativeBooleanArgument(Dart_NativeArguments args, | |
| 3758 int index, | |
| 3759 bool* value) { | |
| 3760 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); | |
| 3761 if ((index < 0) || (index >= arguments->NativeArgCount())) { | |
| 3762 return Api::NewError( | |
| 3763 "%s: argument 'index' out of range. Expected 0..%d but saw %d.", | |
| 3764 CURRENT_FUNC, arguments->NativeArgCount() - 1, index); | |
| 3765 } | |
| 3766 Isolate* isolate = arguments->isolate(); | |
| 3767 ReusableObjectHandleScope reused_obj_handle(isolate); | |
| 3768 Object& obj = reused_obj_handle.Handle(); | |
| 3769 obj = arguments->NativeArgAt(index); | |
| 3770 intptr_t cid = obj.GetClassId(); | |
| 3771 if (cid == kBoolCid) { | |
| 3772 *value = Bool::Cast(obj).value(); | |
| 3773 return Api::Success(); | |
| 3774 } | |
| 3775 if (obj.IsNull()) { | |
| 3776 *value = false; | |
| 3777 return Api::Success(); | |
| 3778 } | |
| 3779 return Api::NewError( | |
| 3780 "%s: argument %d is not a Boolean argument.", | |
| 3781 CURRENT_FUNC, index); | |
| 3782 } | |
| 3783 | |
| 3784 | |
| 3785 DART_EXPORT Dart_Handle Dart_GetNativeDoubleArgument(Dart_NativeArguments args, | |
| 3786 int index, | |
| 3787 double* value) { | |
| 3788 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); | |
| 3789 if ((index < 0) || (index >= arguments->NativeArgCount())) { | |
| 3790 return Api::NewError( | |
| 3791 "%s: argument 'index' out of range. Expected 0..%d but saw %d.", | |
| 3792 CURRENT_FUNC, arguments->NativeArgCount() - 1, index); | |
| 3793 } | |
| 3794 Isolate* isolate = arguments->isolate(); | |
| 3795 ReusableObjectHandleScope reused_obj_handle(isolate); | |
| 3796 Object& obj = reused_obj_handle.Handle(); | |
| 3797 obj = arguments->NativeArgAt(index); | |
| 3798 intptr_t cid = obj.GetClassId(); | |
| 3799 if (cid == kDoubleCid) { | |
| 3800 *value = Double::Cast(obj).value(); | |
| 3801 return Api::Success(); | |
| 3802 } | |
| 3803 if (cid == kSmiCid) { | |
| 3804 *value = Smi::Cast(obj).AsDoubleValue(); | |
| 3805 return Api::Success(); | |
| 3806 } | |
| 3807 if (cid == kMintCid) { | |
| 3808 *value = Mint::Cast(obj).AsDoubleValue(); | |
| 3809 return Api::Success(); | |
| 3810 } | |
| 3811 if (cid == kBigintCid) { | |
| 3812 *value = Bigint::Cast(obj).AsDoubleValue(); | |
| 3813 return Api::Success(); | |
| 3814 } | |
| 3815 return Api::NewError( | |
| 3816 "%s: argument %d is not a Double argument.", | |
| 3817 CURRENT_FUNC, index); | |
| 3818 } | |
| 3819 | |
| 3820 | |
| 3722 DART_EXPORT void Dart_SetReturnValue(Dart_NativeArguments args, | 3821 DART_EXPORT void Dart_SetReturnValue(Dart_NativeArguments args, |
| 3723 Dart_Handle retval) { | 3822 Dart_Handle retval) { |
| 3724 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); | 3823 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); |
| 3725 Isolate* isolate = arguments->isolate(); | 3824 Isolate* isolate = arguments->isolate(); |
| 3726 CHECK_ISOLATE(isolate); | 3825 CHECK_ISOLATE(isolate); |
| 3727 if ((retval != Api::Null()) && (!Api::IsInstance(retval))) { | 3826 if ((retval != Api::Null()) && (!Api::IsInstance(retval))) { |
| 3728 const Object& ret_obj = Object::Handle(Api::UnwrapHandle(retval)); | 3827 const Object& ret_obj = Object::Handle(Api::UnwrapHandle(retval)); |
| 3729 FATAL1("Return value check failed: saw '%s' expected a dart Instance.", | 3828 FATAL1("Return value check failed: saw '%s' expected a dart Instance.", |
| 3730 ret_obj.ToCString()); | 3829 ret_obj.ToCString()); |
| 3731 } | 3830 } |
| (...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4249 } | 4348 } |
| 4250 { | 4349 { |
| 4251 NoGCScope no_gc; | 4350 NoGCScope no_gc; |
| 4252 RawObject* raw_obj = obj.raw(); | 4351 RawObject* raw_obj = obj.raw(); |
| 4253 isolate->heap()->SetPeer(raw_obj, peer); | 4352 isolate->heap()->SetPeer(raw_obj, peer); |
| 4254 } | 4353 } |
| 4255 return Api::Success(); | 4354 return Api::Success(); |
| 4256 } | 4355 } |
| 4257 | 4356 |
| 4258 } // namespace dart | 4357 } // namespace dart |
| OLD | NEW |