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 3912 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3923 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); | 3923 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); |
| 3924 if ((arg_index < 0) || (arg_index >= arguments->NativeArgCount())) { | 3924 if ((arg_index < 0) || (arg_index >= arguments->NativeArgCount())) { |
| 3925 return Api::NewError( | 3925 return Api::NewError( |
| 3926 "%s: argument 'arg_index' out of range. Expected 0..%d but saw %d.", | 3926 "%s: argument 'arg_index' out of range. Expected 0..%d but saw %d.", |
| 3927 CURRENT_FUNC, arguments->NativeArgCount() - 1, arg_index); | 3927 CURRENT_FUNC, arguments->NativeArgCount() - 1, arg_index); |
| 3928 } | 3928 } |
| 3929 if (field_values == NULL) { | 3929 if (field_values == NULL) { |
| 3930 RETURN_NULL_ERROR(field_values); | 3930 RETURN_NULL_ERROR(field_values); |
| 3931 } | 3931 } |
| 3932 Isolate* isolate = arguments->isolate(); | 3932 Isolate* isolate = arguments->isolate(); |
| 3933 CHECK_ISOLATE(isolate); | 3933 ASSERT(isolate != NULL); |
|
Ivan Posva
2014/03/27 21:05:43
How about ASSERT(isolate == Isolate:Current())?
siva
2014/03/27 21:55:46
Good point, I will modify the asserts to this form
| |
| 3934 REUSABLE_OBJECT_HANDLESCOPE(isolate); | 3934 REUSABLE_OBJECT_HANDLESCOPE(isolate); |
| 3935 Object& obj = isolate->ObjectHandle(); | 3935 Object& obj = isolate->ObjectHandle(); |
| 3936 obj = arguments->NativeArgAt(arg_index); | 3936 obj = arguments->NativeArgAt(arg_index); |
| 3937 if (obj.IsNull()) { | 3937 if (obj.IsNull()) { |
| 3938 for (intptr_t i = 0; i < num_fields; i++) { | 3938 for (intptr_t i = 0; i < num_fields; i++) { |
| 3939 field_values[i] = 0; | 3939 field_values[i] = 0; |
| 3940 } | 3940 } |
| 3941 return Api::Success(); | 3941 return Api::Success(); |
| 3942 } | 3942 } |
| 3943 if (!obj.IsInstance()) { | 3943 if (!obj.IsInstance()) { |
| 3944 return Api::NewError("%s expects argument at index '%d' to be of" | 3944 return Api::NewError("%s expects argument at index '%d' to be of" |
| 3945 " type Instance.", CURRENT_FUNC, arg_index); | 3945 " type Instance.", CURRENT_FUNC, arg_index); |
| 3946 } | 3946 } |
| 3947 const Instance& instance = Instance::Cast(obj); | 3947 const Instance& instance = Instance::Cast(obj); |
| 3948 uint16_t field_count = instance.NumNativeFields(); | 3948 uint16_t field_count = instance.NumNativeFields(); |
| 3949 if (num_fields != field_count) { | 3949 if (num_fields != field_count) { |
| 3950 return Api::NewError( | 3950 return Api::NewError( |
| 3951 "%s: invalid 'field_values' array specified for returning field values", | 3951 "%s: invalid 'field_values' array specified for returning field values", |
| 3952 CURRENT_FUNC); | 3952 CURRENT_FUNC); |
| 3953 } | 3953 } |
| 3954 instance.GetNativeFields(num_fields, field_values); | 3954 instance.GetNativeFields(num_fields, field_values); |
| 3955 return Api::Success(); | 3955 return Api::Success(); |
| 3956 } | 3956 } |
| 3957 | 3957 |
| 3958 | 3958 |
| 3959 DART_EXPORT Dart_Handle Dart_GetNativeReceiver(Dart_NativeArguments args, | 3959 DART_EXPORT Dart_Handle Dart_GetNativeReceiver(Dart_NativeArguments args, |
| 3960 intptr_t* value) { | 3960 intptr_t* value) { |
| 3961 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); | 3961 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); |
| 3962 Isolate* isolate = arguments->isolate(); | 3962 ASSERT(arguments->isolate() != NULL); |
| 3963 CHECK_ISOLATE(isolate); | |
| 3964 if (value == NULL) { | 3963 if (value == NULL) { |
| 3965 RETURN_NULL_ERROR(value); | 3964 RETURN_NULL_ERROR(value); |
| 3966 } | 3965 } |
| 3967 if (Api::GetNativeReceiver(arguments, value)) { | 3966 if (Api::GetNativeReceiver(arguments, value)) { |
| 3968 return Api::Success(); | 3967 return Api::Success(); |
| 3969 } | 3968 } |
| 3970 return Api::NewError("%s expects receiver argument to be non-null and of" | 3969 return Api::NewError("%s expects receiver argument to be non-null and of" |
| 3971 " type Instance.", CURRENT_FUNC); | 3970 " type Instance.", CURRENT_FUNC); |
| 3972 } | 3971 } |
| 3973 | 3972 |
| 3974 | 3973 |
| 3975 DART_EXPORT Dart_Handle Dart_GetNativeStringArgument(Dart_NativeArguments args, | 3974 DART_EXPORT Dart_Handle Dart_GetNativeStringArgument(Dart_NativeArguments args, |
| 3976 int arg_index, | 3975 int arg_index, |
| 3977 void** peer) { | 3976 void** peer) { |
| 3978 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); | 3977 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); |
| 3979 Isolate* isolate = arguments->isolate(); | 3978 Isolate* isolate = arguments->isolate(); |
| 3980 CHECK_ISOLATE(isolate); | 3979 ASSERT(isolate != NULL); |
| 3981 if (Api::StringGetPeerHelper(arguments, arg_index, peer)) { | 3980 if (Api::StringGetPeerHelper(arguments, arg_index, peer)) { |
| 3982 return Api::Success(); | 3981 return Api::Success(); |
| 3983 } | 3982 } |
| 3984 *peer = NULL; | 3983 *peer = NULL; |
| 3985 REUSABLE_OBJECT_HANDLESCOPE(isolate); | 3984 REUSABLE_OBJECT_HANDLESCOPE(isolate); |
| 3986 Object& obj = isolate->ObjectHandle(); | 3985 Object& obj = isolate->ObjectHandle(); |
| 3987 obj = arguments->NativeArgAt(arg_index); | 3986 obj = arguments->NativeArgAt(arg_index); |
| 3988 if (RawObject::IsStringClassId(obj.GetClassId())) { | 3987 if (RawObject::IsStringClassId(obj.GetClassId())) { |
| 3989 return Api::NewHandle(isolate, obj.raw()); | 3988 return Api::NewHandle(isolate, obj.raw()); |
| 3990 } | 3989 } |
| 3991 if (obj.IsNull()) { | 3990 if (obj.IsNull()) { |
| 3992 return Api::Null(); | 3991 return Api::Null(); |
| 3993 } | 3992 } |
| 3994 return Api::NewError("%s expects argument to be of" | 3993 return Api::NewError("%s expects argument to be of" |
| 3995 " type String.", CURRENT_FUNC); | 3994 " type String.", CURRENT_FUNC); |
| 3996 } | 3995 } |
| 3997 | 3996 |
| 3998 | 3997 |
| 3999 DART_EXPORT Dart_Handle Dart_GetNativeIntegerArgument(Dart_NativeArguments args, | 3998 DART_EXPORT Dart_Handle Dart_GetNativeIntegerArgument(Dart_NativeArguments args, |
| 4000 int index, | 3999 int index, |
| 4001 int64_t* value) { | 4000 int64_t* value) { |
| 4002 TRACE_API_CALL(CURRENT_FUNC); | 4001 TRACE_API_CALL(CURRENT_FUNC); |
| 4003 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); | 4002 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); |
| 4004 if ((index < 0) || (index >= arguments->NativeArgCount())) { | 4003 if ((index < 0) || (index >= arguments->NativeArgCount())) { |
| 4005 return Api::NewError( | 4004 return Api::NewError( |
| 4006 "%s: argument 'index' out of range. Expected 0..%d but saw %d.", | 4005 "%s: argument 'index' out of range. Expected 0..%d but saw %d.", |
| 4007 CURRENT_FUNC, arguments->NativeArgCount() - 1, index); | 4006 CURRENT_FUNC, arguments->NativeArgCount() - 1, index); |
| 4008 } | 4007 } |
| 4009 Isolate* isolate = arguments->isolate(); | 4008 Isolate* isolate = arguments->isolate(); |
| 4009 ASSERT(isolate != NULL); | |
| 4010 REUSABLE_OBJECT_HANDLESCOPE(isolate); | 4010 REUSABLE_OBJECT_HANDLESCOPE(isolate); |
| 4011 Object& obj = isolate->ObjectHandle(); | 4011 Object& obj = isolate->ObjectHandle(); |
| 4012 obj = arguments->NativeArgAt(index); | 4012 obj = arguments->NativeArgAt(index); |
| 4013 intptr_t cid = obj.GetClassId(); | 4013 intptr_t cid = obj.GetClassId(); |
| 4014 if (cid == kSmiCid) { | 4014 if (cid == kSmiCid) { |
| 4015 *value = Smi::Cast(obj).Value(); | 4015 *value = Smi::Cast(obj).Value(); |
| 4016 return Api::Success(); | 4016 return Api::Success(); |
| 4017 } | 4017 } |
| 4018 if (cid == kMintCid) { | 4018 if (cid == kMintCid) { |
| 4019 *value = Mint::Cast(obj).value(); | 4019 *value = Mint::Cast(obj).value(); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4057 int index, | 4057 int index, |
| 4058 double* value) { | 4058 double* value) { |
| 4059 TRACE_API_CALL(CURRENT_FUNC); | 4059 TRACE_API_CALL(CURRENT_FUNC); |
| 4060 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); | 4060 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); |
| 4061 if ((index < 0) || (index >= arguments->NativeArgCount())) { | 4061 if ((index < 0) || (index >= arguments->NativeArgCount())) { |
| 4062 return Api::NewError( | 4062 return Api::NewError( |
| 4063 "%s: argument 'index' out of range. Expected 0..%d but saw %d.", | 4063 "%s: argument 'index' out of range. Expected 0..%d but saw %d.", |
| 4064 CURRENT_FUNC, arguments->NativeArgCount() - 1, index); | 4064 CURRENT_FUNC, arguments->NativeArgCount() - 1, index); |
| 4065 } | 4065 } |
| 4066 Isolate* isolate = arguments->isolate(); | 4066 Isolate* isolate = arguments->isolate(); |
| 4067 ASSERT(isolate != NULL); | |
| 4067 REUSABLE_OBJECT_HANDLESCOPE(isolate); | 4068 REUSABLE_OBJECT_HANDLESCOPE(isolate); |
| 4068 Object& obj = isolate->ObjectHandle(); | 4069 Object& obj = isolate->ObjectHandle(); |
| 4069 obj = arguments->NativeArgAt(index); | 4070 obj = arguments->NativeArgAt(index); |
| 4070 intptr_t cid = obj.GetClassId(); | 4071 intptr_t cid = obj.GetClassId(); |
| 4071 if (cid == kDoubleCid) { | 4072 if (cid == kDoubleCid) { |
| 4072 *value = Double::Cast(obj).value(); | 4073 *value = Double::Cast(obj).value(); |
| 4073 return Api::Success(); | 4074 return Api::Success(); |
| 4074 } | 4075 } |
| 4075 if (cid == kSmiCid) { | 4076 if (cid == kSmiCid) { |
| 4076 *value = Smi::Cast(obj).AsDoubleValue(); | 4077 *value = Smi::Cast(obj).AsDoubleValue(); |
| 4077 return Api::Success(); | 4078 return Api::Success(); |
| 4078 } | 4079 } |
| 4079 if (cid == kMintCid) { | 4080 if (cid == kMintCid) { |
| 4080 *value = Mint::Cast(obj).AsDoubleValue(); | 4081 *value = Mint::Cast(obj).AsDoubleValue(); |
| 4081 return Api::Success(); | 4082 return Api::Success(); |
| 4082 } | 4083 } |
| 4083 if (cid == kBigintCid) { | 4084 if (cid == kBigintCid) { |
| 4084 *value = Bigint::Cast(obj).AsDoubleValue(); | 4085 *value = Bigint::Cast(obj).AsDoubleValue(); |
| 4085 return Api::Success(); | 4086 return Api::Success(); |
| 4086 } | 4087 } |
| 4087 return Api::NewError( | 4088 return Api::NewError( |
| 4088 "%s: argument %d is not a Double argument.", | 4089 "%s: argument %d is not a Double argument.", |
| 4089 CURRENT_FUNC, index); | 4090 CURRENT_FUNC, index); |
| 4090 } | 4091 } |
| 4091 | 4092 |
| 4092 | 4093 |
| 4093 DART_EXPORT void Dart_SetReturnValue(Dart_NativeArguments args, | 4094 DART_EXPORT void Dart_SetReturnValue(Dart_NativeArguments args, |
| 4094 Dart_Handle retval) { | 4095 Dart_Handle retval) { |
| 4095 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); | 4096 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); |
| 4096 Isolate* isolate = arguments->isolate(); | 4097 ASSERT(arguments->isolate() != NULL); |
| 4097 CHECK_ISOLATE(isolate); | |
| 4098 if ((retval != Api::Null()) && (!Api::IsInstance(retval))) { | 4098 if ((retval != Api::Null()) && (!Api::IsInstance(retval))) { |
| 4099 const Object& ret_obj = Object::Handle(Api::UnwrapHandle(retval)); | 4099 const Object& ret_obj = Object::Handle(Api::UnwrapHandle(retval)); |
| 4100 FATAL1("Return value check failed: saw '%s' expected a dart Instance.", | 4100 FATAL1("Return value check failed: saw '%s' expected a dart Instance.", |
| 4101 ret_obj.ToCString()); | 4101 ret_obj.ToCString()); |
| 4102 } | 4102 } |
| 4103 ASSERT(retval != 0); | 4103 ASSERT(retval != 0); |
| 4104 Api::SetReturnValue(arguments, retval); | 4104 Api::SetReturnValue(arguments, retval); |
| 4105 } | 4105 } |
| 4106 | 4106 |
| 4107 | 4107 |
| 4108 DART_EXPORT void Dart_SetWeakHandleReturnValue(Dart_NativeArguments args, | 4108 DART_EXPORT void Dart_SetWeakHandleReturnValue(Dart_NativeArguments args, |
| 4109 Dart_WeakPersistentHandle rval) { | 4109 Dart_WeakPersistentHandle rval) { |
| 4110 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); | 4110 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); |
| 4111 #if defined(DEBUG) | |
| 4111 Isolate* isolate = arguments->isolate(); | 4112 Isolate* isolate = arguments->isolate(); |
| 4112 CHECK_ISOLATE(isolate); | 4113 ASSERT(isolate != NULL); |
| 4113 ASSERT(isolate->api_state() != NULL && | 4114 ASSERT(isolate->api_state() != NULL && |
| 4114 (isolate->api_state()->IsValidWeakPersistentHandle(rval) || | 4115 (isolate->api_state()->IsValidWeakPersistentHandle(rval) || |
| 4115 isolate->api_state()->IsValidPrologueWeakPersistentHandle(rval))); | 4116 isolate->api_state()->IsValidPrologueWeakPersistentHandle(rval))); |
| 4117 #endif | |
|
Ivan Posva
2014/03/27 21:05:43
#endif // defined(DEBUG)
| |
| 4116 Api::SetWeakHandleReturnValue(arguments, rval); | 4118 Api::SetWeakHandleReturnValue(arguments, rval); |
| 4117 } | 4119 } |
| 4118 | 4120 |
| 4119 | 4121 |
| 4120 // --- Environment --- | 4122 // --- Environment --- |
| 4121 DART_EXPORT Dart_Handle Dart_SetEnvironmentCallback( | 4123 DART_EXPORT Dart_Handle Dart_SetEnvironmentCallback( |
| 4122 Dart_EnvironmentCallback callback) { | 4124 Dart_EnvironmentCallback callback) { |
| 4123 Isolate* isolate = Isolate::Current(); | 4125 Isolate* isolate = Isolate::Current(); |
| 4124 CHECK_ISOLATE(isolate); | 4126 CHECK_ISOLATE(isolate); |
| 4125 isolate->set_environment_callback(callback); | 4127 isolate->set_environment_callback(callback); |
| 4126 return Api::Success(); | 4128 return Api::Success(); |
| 4127 } | 4129 } |
| 4128 | 4130 |
| 4129 | 4131 |
| 4130 // --- Scripts and Libraries --- | 4132 // --- Scripts and Libraries --- |
| 4131 DART_EXPORT void Dart_SetBooleanReturnValue(Dart_NativeArguments args, | 4133 DART_EXPORT void Dart_SetBooleanReturnValue(Dart_NativeArguments args, |
| 4132 bool retval) { | 4134 bool retval) { |
| 4133 TRACE_API_CALL(CURRENT_FUNC); | 4135 TRACE_API_CALL(CURRENT_FUNC); |
| 4134 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); | 4136 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); |
| 4135 arguments->SetReturn(Bool::Get(retval)); | 4137 arguments->SetReturn(Bool::Get(retval)); |
| 4136 } | 4138 } |
| 4137 | 4139 |
| 4138 | 4140 |
| 4139 DART_EXPORT void Dart_SetIntegerReturnValue(Dart_NativeArguments args, | 4141 DART_EXPORT void Dart_SetIntegerReturnValue(Dart_NativeArguments args, |
| 4140 int64_t retval) { | 4142 int64_t retval) { |
| 4141 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); | 4143 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); |
| 4142 Isolate* isolate = arguments->isolate(); | 4144 ASSERT(arguments->isolate() != NULL); |
| 4143 CHECK_ISOLATE(isolate); | |
| 4144 if (Smi::IsValid64(retval)) { | 4145 if (Smi::IsValid64(retval)) { |
| 4145 Api::SetSmiReturnValue(arguments, retval); | 4146 Api::SetSmiReturnValue(arguments, retval); |
| 4146 } else { | 4147 } else { |
| 4147 // Slow path for Mints and Bigints. | 4148 // Slow path for Mints and Bigints. |
| 4148 ASSERT_CALLBACK_STATE(isolate); | 4149 ASSERT_CALLBACK_STATE(arguments->isolate()); |
| 4149 Api::SetIntegerReturnValue(arguments, retval); | 4150 Api::SetIntegerReturnValue(arguments, retval); |
| 4150 } | 4151 } |
| 4151 } | 4152 } |
| 4152 | 4153 |
| 4153 | 4154 |
| 4154 DART_EXPORT void Dart_SetDoubleReturnValue(Dart_NativeArguments args, | 4155 DART_EXPORT void Dart_SetDoubleReturnValue(Dart_NativeArguments args, |
| 4155 double retval) { | 4156 double retval) { |
| 4156 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); | 4157 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); |
| 4158 #if defined(DEBUG) | |
| 4157 Isolate* isolate = arguments->isolate(); | 4159 Isolate* isolate = arguments->isolate(); |
| 4158 CHECK_ISOLATE(isolate); | 4160 ASSERT(isolate != NULL); |
| 4159 ASSERT_CALLBACK_STATE(isolate); | 4161 ASSERT_CALLBACK_STATE(isolate); |
| 4162 #endif | |
| 4160 Api::SetDoubleReturnValue(arguments, retval); | 4163 Api::SetDoubleReturnValue(arguments, retval); |
| 4161 } | 4164 } |
| 4162 | 4165 |
| 4163 | 4166 |
| 4164 // --- Scripts and Libraries --- | 4167 // --- Scripts and Libraries --- |
| 4165 | 4168 |
| 4166 DART_EXPORT Dart_Handle Dart_SetLibraryTagHandler( | 4169 DART_EXPORT Dart_Handle Dart_SetLibraryTagHandler( |
| 4167 Dart_LibraryTagHandler handler) { | 4170 Dart_LibraryTagHandler handler) { |
| 4168 Isolate* isolate = Isolate::Current(); | 4171 Isolate* isolate = Isolate::Current(); |
| 4169 CHECK_ISOLATE(isolate); | 4172 CHECK_ISOLATE(isolate); |
| (...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4661 | 4664 |
| 4662 | 4665 |
| 4663 DART_EXPORT void Dart_RegisterRootServiceRequestCallback( | 4666 DART_EXPORT void Dart_RegisterRootServiceRequestCallback( |
| 4664 const char* name, | 4667 const char* name, |
| 4665 Dart_ServiceRequestCallback callback, | 4668 Dart_ServiceRequestCallback callback, |
| 4666 void* user_data) { | 4669 void* user_data) { |
| 4667 Service::RegisterRootEmbedderCallback(name, callback, user_data); | 4670 Service::RegisterRootEmbedderCallback(name, callback, user_data); |
| 4668 } | 4671 } |
| 4669 | 4672 |
| 4670 } // namespace dart | 4673 } // namespace dart |
| OLD | NEW |