| 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 3761 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3772 DARTSCOPE(isolate); | 3772 DARTSCOPE(isolate); |
| 3773 const Instance& instance = Api::UnwrapInstanceHandle(isolate, obj); | 3773 const Instance& instance = Api::UnwrapInstanceHandle(isolate, obj); |
| 3774 if (instance.IsNull()) { | 3774 if (instance.IsNull()) { |
| 3775 RETURN_TYPE_ERROR(isolate, obj, Instance); | 3775 RETURN_TYPE_ERROR(isolate, obj, Instance); |
| 3776 } | 3776 } |
| 3777 if (!instance.IsValidNativeIndex(index)) { | 3777 if (!instance.IsValidNativeIndex(index)) { |
| 3778 return Api::NewError( | 3778 return Api::NewError( |
| 3779 "%s: invalid index %d passed in to access native instance field", | 3779 "%s: invalid index %d passed in to access native instance field", |
| 3780 CURRENT_FUNC, index); | 3780 CURRENT_FUNC, index); |
| 3781 } | 3781 } |
| 3782 *value = instance.GetNativeField(isolate, index); | 3782 *value = instance.GetNativeField(index); |
| 3783 return Api::Success(); | 3783 return Api::Success(); |
| 3784 } | 3784 } |
| 3785 | 3785 |
| 3786 | 3786 |
| 3787 DART_EXPORT Dart_Handle Dart_SetNativeInstanceField(Dart_Handle obj, | 3787 DART_EXPORT Dart_Handle Dart_SetNativeInstanceField(Dart_Handle obj, |
| 3788 int index, | 3788 int index, |
| 3789 intptr_t value) { | 3789 intptr_t value) { |
| 3790 Isolate* isolate = Isolate::Current(); | 3790 Isolate* isolate = Isolate::Current(); |
| 3791 DARTSCOPE(isolate); | 3791 DARTSCOPE(isolate); |
| 3792 const Instance& instance = Api::UnwrapInstanceHandle(isolate, obj); | 3792 const Instance& instance = Api::UnwrapInstanceHandle(isolate, obj); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3824 } | 3824 } |
| 3825 | 3825 |
| 3826 | 3826 |
| 3827 DART_EXPORT int Dart_GetNativeArgumentCount(Dart_NativeArguments args) { | 3827 DART_EXPORT int Dart_GetNativeArgumentCount(Dart_NativeArguments args) { |
| 3828 TRACE_API_CALL(CURRENT_FUNC); | 3828 TRACE_API_CALL(CURRENT_FUNC); |
| 3829 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); | 3829 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); |
| 3830 return arguments->NativeArgCount(); | 3830 return arguments->NativeArgCount(); |
| 3831 } | 3831 } |
| 3832 | 3832 |
| 3833 | 3833 |
| 3834 DART_EXPORT Dart_Handle Dart_GetNativeFieldOfArgument(Dart_NativeArguments args, | 3834 DART_EXPORT Dart_Handle Dart_GetNativeFieldsOfArgument( |
| 3835 int arg_index, | 3835 Dart_NativeArguments args, |
| 3836 int fld_index, | 3836 int arg_index, |
| 3837 intptr_t* value) { | 3837 int num_fields, |
| 3838 intptr_t* field_values) { |
| 3838 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); | 3839 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); |
| 3839 if ((arg_index < 0) || (arg_index >= arguments->NativeArgCount())) { | 3840 if ((arg_index < 0) || (arg_index >= arguments->NativeArgCount())) { |
| 3840 return Api::NewError( | 3841 return Api::NewError( |
| 3841 "%s: argument 'arg_index' out of range. Expected 0..%d but saw %d.", | 3842 "%s: argument 'arg_index' out of range. Expected 0..%d but saw %d.", |
| 3842 CURRENT_FUNC, arguments->NativeArgCount() - 1, arg_index); | 3843 CURRENT_FUNC, arguments->NativeArgCount() - 1, arg_index); |
| 3843 } | 3844 } |
| 3845 if (field_values == NULL) { |
| 3846 RETURN_NULL_ERROR(field_values); |
| 3847 } |
| 3844 Isolate* isolate = arguments->isolate(); | 3848 Isolate* isolate = arguments->isolate(); |
| 3845 DARTSCOPE(isolate); | 3849 DARTSCOPE(isolate); |
| 3846 const Object& obj = Object::Handle(isolate, | 3850 ReusableObjectHandleScope reused_obj_handle(isolate); |
| 3847 arguments->NativeArgAt(arg_index)); | 3851 Object& obj = reused_obj_handle.Handle(); |
| 3852 obj = arguments->NativeArgAt(arg_index); |
| 3853 if (obj.IsNull()) { |
| 3854 for (intptr_t i = 0; i < num_fields; i++) { |
| 3855 field_values[i] = 0; |
| 3856 } |
| 3857 return Api::Success(); |
| 3858 } |
| 3848 if (!obj.IsInstance()) { | 3859 if (!obj.IsInstance()) { |
| 3849 return Api::NewError("%s expects argument at index '%d' to be of" | 3860 return Api::NewError("%s expects argument at index '%d' to be of" |
| 3850 " type Instance.", CURRENT_FUNC, arg_index); | 3861 " type Instance.", CURRENT_FUNC, arg_index); |
| 3851 } | 3862 } |
| 3852 if (obj.IsNull()) { | 3863 const Instance& instance = Instance::Cast(obj); |
| 3853 return Api::NewError("%s expects argument at index '%d' to be non-null.", | 3864 uint16_t field_count = instance.NumNativeFields(); |
| 3854 CURRENT_FUNC, arg_index); | 3865 if (num_fields != field_count) { |
| 3866 return Api::NewError( |
| 3867 "%s: invalid 'field_values' array specified for returning field values", |
| 3868 CURRENT_FUNC); |
| 3855 } | 3869 } |
| 3856 const Instance& instance = Instance::Cast(obj); | 3870 instance.GetNativeFields(num_fields, field_values); |
| 3857 if (!instance.IsValidNativeIndex(fld_index)) { | |
| 3858 return Api::NewError( | |
| 3859 "%s: invalid index %d passed in to access native instance field", | |
| 3860 CURRENT_FUNC, fld_index); | |
| 3861 } | |
| 3862 if (value == NULL) { | |
| 3863 RETURN_NULL_ERROR(value); | |
| 3864 } | |
| 3865 *value = instance.GetNativeField(isolate, fld_index); | |
| 3866 return Api::Success(); | 3871 return Api::Success(); |
| 3867 } | 3872 } |
| 3868 | 3873 |
| 3869 | 3874 |
| 3870 DART_EXPORT Dart_Handle Dart_GetNativeReceiver(Dart_NativeArguments args, | 3875 DART_EXPORT Dart_Handle Dart_GetNativeReceiver(Dart_NativeArguments args, |
| 3871 intptr_t* value) { | 3876 intptr_t* value) { |
| 3872 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); | 3877 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); |
| 3873 Isolate* isolate = arguments->isolate(); | 3878 Isolate* isolate = arguments->isolate(); |
| 3874 CHECK_ISOLATE(isolate); | 3879 CHECK_ISOLATE(isolate); |
| 3875 if (value == NULL) { | 3880 if (value == NULL) { |
| (...skipping 694 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4570 | 4575 |
| 4571 | 4576 |
| 4572 DART_EXPORT void Dart_RegisterRootServiceRequestCallback( | 4577 DART_EXPORT void Dart_RegisterRootServiceRequestCallback( |
| 4573 const char* name, | 4578 const char* name, |
| 4574 Dart_ServiceRequestCallback callback, | 4579 Dart_ServiceRequestCallback callback, |
| 4575 void* user_data) { | 4580 void* user_data) { |
| 4576 Service::RegisterRootEmbedderCallback(name, callback, user_data); | 4581 Service::RegisterRootEmbedderCallback(name, callback, user_data); |
| 4577 } | 4582 } |
| 4578 | 4583 |
| 4579 } // namespace dart | 4584 } // namespace dart |
| OLD | NEW |