Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(89)

Side by Side Diff: runtime/vm/dart_api_impl.cc

Issue 282883002: Add a new API function to extract all the native arguments into an array (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 TypeArguments::Handle(isolate), 74 TypeArguments::Handle(isolate),
75 &malformed_type_error)) { 75 &malformed_type_error)) {
76 ASSERT(malformed_type_error.IsNull()); // Type is a raw List. 76 ASSERT(malformed_type_error.IsNull()); // Type is a raw List.
77 return instance.raw(); 77 return instance.raw();
78 } 78 }
79 } 79 }
80 return Instance::null(); 80 return Instance::null();
81 } 81 }
82 82
83 83
84 static bool GetNativeStringArgument(NativeArguments* arguments,
85 int arg_index,
86 Dart_Handle* str,
87 void** peer) {
88 ASSERT(peer != NULL);
89 if (Api::StringGetPeerHelper(arguments, arg_index, peer)) {
90 *str = NULL;
91 return true;
92 }
93 Isolate* isolate = arguments->isolate();
94 ASSERT(isolate == Isolate::Current());
95 *peer = NULL;
96 REUSABLE_OBJECT_HANDLESCOPE(isolate);
97 Object& obj = isolate->ObjectHandle();
98 obj = arguments->NativeArgAt(arg_index);
99 if (RawObject::IsStringClassId(obj.GetClassId())) {
100 ASSERT(isolate->api_state() &&
101 isolate->api_state()->top_scope() != NULL);
102 *str = Api::NewHandle(isolate, obj.raw());
103 return true;
104 }
105 if (obj.IsNull()) {
106 *str = Api::Null();
107 return true;
108 }
109 return false;
110 }
111
112
113 static bool GetNativeIntegerArgument(NativeArguments* arguments,
114 int arg_index,
115 int64_t* value) {
116 ASSERT(value != NULL);
117 if (Api::GetNativeIntegerArgument(arguments, arg_index, value)) {
118 return true;
119 }
120 Isolate* isolate = arguments->isolate();
121 ASSERT(isolate == Isolate::Current());
122 REUSABLE_OBJECT_HANDLESCOPE(isolate);
123 Object& obj = isolate->ObjectHandle();
124 obj = arguments->NativeArgAt(arg_index);
125 intptr_t cid = obj.GetClassId();
126 if (cid == kBigintCid) {
127 const Bigint& bigint = Bigint::Cast(obj);
128 if (BigintOperations::FitsIntoInt64(bigint)) {
129 *value = BigintOperations::ToInt64(bigint);
Ivan Posva 2014/05/20 19:27:03 What if we wanted a uint64_t? Will this still "fit
siva 2014/05/21 23:56:54 No for the uint64_t I added a new GetNativeUnsigne
130 return true;
131 }
132 }
133 return false;
134 }
135
136
137 static bool GetNativeDoubleArgument(NativeArguments* arguments,
138 int arg_index,
139 double* value) {
140 ASSERT(value != NULL);
141 if (Api::GetNativeDoubleArgument(arguments, arg_index, value)) {
142 return true;
143 }
144 Isolate* isolate = arguments->isolate();
145 ASSERT(isolate == Isolate::Current());
146 REUSABLE_OBJECT_HANDLESCOPE(isolate);
147 Object& obj = isolate->ObjectHandle();
148 obj = arguments->NativeArgAt(arg_index);
149 intptr_t cid = obj.GetClassId();
150 if (cid == kBigintCid) {
151 *value = Bigint::Cast(obj).AsDoubleValue();
152 return true;
153 }
154 return false;
155 }
156
157
158 static Dart_Handle GetNativeFieldsOfArgument(NativeArguments* arguments,
159 int arg_index,
160 int num_fields,
161 intptr_t* field_values,
162 const char* current_func) {
163 ASSERT(field_values != NULL);
164 if (Api::GetNativeFieldsOfArgument(arguments,
165 arg_index,
166 num_fields,
167 field_values)) {
168 return Api::Success();
169 }
170 Isolate* isolate = arguments->isolate();
171 ASSERT(isolate == Isolate::Current());
172 REUSABLE_OBJECT_HANDLESCOPE(isolate);
173 Object& obj = isolate->ObjectHandle();
174 obj = arguments->NativeArgAt(arg_index);
175 if (obj.IsNull()) {
176 memset(field_values, 0, (num_fields * sizeof(field_values[0])));
177 return Api::Success();
178 }
179 // We did not succeed in extracting the native fields report the
180 // appropriate error.
181 if (!obj.IsInstance()) {
182 return Api::NewError("%s expects argument at index '%d' to be of"
183 " type Instance.", current_func, arg_index);
184 }
185 const Instance& instance = Instance::Cast(obj);
186 int field_count = instance.NumNativeFields();
187 ASSERT(num_fields != field_count);
188 return Api::NewError(
189 "%s: expected %d 'num_fields' but was passed in %d.",
190 current_func, field_count, num_fields);
191 }
192
193
84 Heap::Space SpaceForExternal(Isolate* isolate, intptr_t size) { 194 Heap::Space SpaceForExternal(Isolate* isolate, intptr_t size) {
85 Heap* heap = isolate->heap(); 195 Heap* heap = isolate->heap();
86 // If 'size' would be a significant fraction of new space, then use old. 196 // If 'size' would be a significant fraction of new space, then use old.
87 static const int kExtNewRatio = 16; 197 static const int kExtNewRatio = 16;
88 if (size > (heap->CapacityInWords(Heap::kNew) * kWordSize) / kExtNewRatio) { 198 if (size > (heap->CapacityInWords(Heap::kNew) * kWordSize) / kExtNewRatio) {
89 return Heap::kOld; 199 return Heap::kOld;
90 } else { 200 } else {
91 return Heap::kNew; 201 return Heap::kNew;
92 } 202 }
93 } 203 }
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 } 459 }
350 if (cid == kNullCid) { 460 if (cid == kNullCid) {
351 *value = false; 461 *value = false;
352 return true; 462 return true;
353 } 463 }
354 } 464 }
355 return false; 465 return false;
356 } 466 }
357 467
358 468
469 bool Api::GetNativeIntegerArgument(NativeArguments* arguments,
470 int arg_index,
471 int64_t* value) {
472 NoGCScope no_gc_scope;
473 RawObject* raw_obj = arguments->NativeArgAt(arg_index);
474 if (raw_obj->IsHeapObject()) {
475 intptr_t cid = raw_obj->GetClassId();
476 if (cid == kMintCid) {
477 *value = reinterpret_cast<RawMint*>(raw_obj)->ptr()->value_;
478 return true;
479 }
480 return false;
481 }
482 *value = Smi::Value(reinterpret_cast<RawSmi*>(raw_obj));
483 return true;
484 }
485
486
487 bool Api::GetNativeDoubleArgument(NativeArguments* arguments,
488 int arg_index,
489 double* value) {
490 NoGCScope no_gc_scope;
491 RawObject* raw_obj = arguments->NativeArgAt(arg_index);
492 if (raw_obj->IsHeapObject()) {
493 intptr_t cid = raw_obj->GetClassId();
494 if (cid == kDoubleCid) {
495 *value = reinterpret_cast<RawDouble*>(raw_obj)->ptr()->value_;
496 return true;
497 }
498 if (cid == kMintCid) {
499 *value = static_cast<double>(
500 reinterpret_cast<RawMint*>(raw_obj)->ptr()->value_);
501 return true;
502 }
503 return false;
504 }
505 *value = static_cast<double>(Smi::Value(reinterpret_cast<RawSmi*>(raw_obj)));
506 return true;
507 }
508
509
510 bool Api::GetNativeFieldsOfArgument(NativeArguments* arguments,
511 int arg_index,
512 int num_fields,
513 intptr_t* field_values) {
514 NoGCScope no_gc_scope;
515 RawObject* raw_obj = arguments->NativeArgAt(arg_index);
516 if (raw_obj->IsHeapObject()) {
517 intptr_t cid = raw_obj->GetClassId();
518 if (cid > kNumPredefinedCids) {
519 RawTypedData* native_fields = *reinterpret_cast<RawTypedData**>(
520 RawObject::ToAddr(raw_obj) + sizeof(RawObject));
521 if (native_fields == TypedData::null()) {
522 memset(field_values, 0, (num_fields * sizeof(field_values[0])));
523 } else if (num_fields == Smi::Value(native_fields->ptr()->length_)) {
524 intptr_t* native_values =
525 bit_cast<intptr_t*, uint8_t*>(native_fields->ptr()->data_);
526 memmove(field_values,
527 native_values,
528 (num_fields * sizeof(field_values[0])));
529 }
530 return true;
531 }
532 }
533 return false;
534 }
535
536
359 void Api::SetWeakHandleReturnValue(NativeArguments* args, 537 void Api::SetWeakHandleReturnValue(NativeArguments* args,
360 Dart_WeakPersistentHandle retval) { 538 Dart_WeakPersistentHandle retval) {
361 args->SetReturnUnsafe(FinalizablePersistentHandle::Cast(retval)->raw()); 539 args->SetReturnUnsafe(FinalizablePersistentHandle::Cast(retval)->raw());
362 } 540 }
363 541
364 542
365 PersistentHandle* PersistentHandle::Cast(Dart_PersistentHandle handle) { 543 PersistentHandle* PersistentHandle::Cast(Dart_PersistentHandle handle) {
366 ASSERT(Isolate::Current()->api_state()->IsValidPersistentHandle(handle)); 544 ASSERT(Isolate::Current()->api_state()->IsValidPersistentHandle(handle));
367 return reinterpret_cast<PersistentHandle*>(handle); 545 return reinterpret_cast<PersistentHandle*>(handle);
368 } 546 }
(...skipping 3636 matching lines...) Expand 10 before | Expand all | Expand 10 after
4005 4183
4006 4184
4007 DART_EXPORT void* Dart_GetNativeIsolateData(Dart_NativeArguments args) { 4185 DART_EXPORT void* Dart_GetNativeIsolateData(Dart_NativeArguments args) {
4008 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); 4186 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args);
4009 Isolate* isolate = arguments->isolate(); 4187 Isolate* isolate = arguments->isolate();
4010 ASSERT(isolate == Isolate::Current()); 4188 ASSERT(isolate == Isolate::Current());
4011 return isolate->init_callback_data(); 4189 return isolate->init_callback_data();
4012 } 4190 }
4013 4191
4014 4192
4193 DART_EXPORT Dart_Handle Dart_GetNativeArguments(
4194 Dart_NativeArguments args,
4195 int num_arguments,
4196 const uint8_t* argument_descriptors,
4197 Dart_NativeArgument_Value* arg_values) {
4198 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args);
4199 ASSERT(arguments->isolate() == Isolate::Current());
4200 if (arg_values == NULL) {
4201 RETURN_NULL_ERROR(arg_values);
4202 }
4203 for (int i = 0; i < num_arguments; i++) {
4204 uint8_t desc = argument_descriptors[i];
4205 Dart_NativeArgument_Type arg_type = static_cast<Dart_NativeArgument_Type>(
4206 ((desc >> kNativeArgTypePos) & BITMASK(kNativeArgTypeSize)));
4207 int arg_index = (desc & BITMASK(kNativeArgNumberSize));
4208 ASSERT(arg_index >= 0 && arg_index < arguments->NativeArgCount());
4209 Dart_NativeArgument_Value* val = &(arg_values[i]);
Ivan Posva 2014/05/20 19:27:03 val and value below are easy to confuse. How about
siva 2014/05/21 23:56:54 renamed val to native_value On 2014/05/20 19:27:0
4210 switch (arg_type) {
4211 case Dart_NativeArgument_kBool:
4212 if (!Api::GetNativeBooleanArgument(arguments,
4213 arg_index,
4214 &(val->as_bool))) {
4215 return Api::NewError("%s: expects argument at index %d to be of"
4216 " type Boolean.", CURRENT_FUNC, i);
4217 }
4218 break;
4219
4220 case Dart_NativeArgument_kInt32: {
4221 int64_t value = 0;
4222 if (!GetNativeIntegerArgument(arguments,
4223 arg_index,
4224 &value)) {
4225 return Api::NewError("%s: expects argument at index %d to be of"
4226 " type Integer.", CURRENT_FUNC, i);
4227 }
4228 if (value < INT_MIN || value > INT_MAX) {
4229 return Api::NewError("%s: argument value at index %d is out of range",
4230 CURRENT_FUNC, i);
4231 }
4232 val->as_int32 = value;
Ivan Posva 2014/05/20 19:27:03 ditto from below.
siva 2014/05/21 23:56:54 Done.
4233 break;
4234 }
4235
4236 case Dart_NativeArgument_kUint32: {
4237 int64_t value = 0;
4238 if (!GetNativeIntegerArgument(arguments,
4239 arg_index,
4240 &value)) {
4241 return Api::NewError("%s: expects argument at index %d to be of"
4242 " type Integer.", CURRENT_FUNC, i);
4243 }
4244 if (value < 0 || value > UINT_MAX) {
4245 return Api::NewError("%s: argument value at index %d is out of range",
4246 CURRENT_FUNC, i);
4247 }
4248 val->as_uint32 = value;
Ivan Posva 2014/05/20 19:27:03 static_cast<uint32_t> would make it clearer.
siva 2014/05/21 23:56:54 Done.
4249 break;
4250 }
4251
4252 case Dart_NativeArgument_kInt64: {
4253 int64_t value = 0;
4254 if (!GetNativeIntegerArgument(arguments,
4255 arg_index,
4256 &value)) {
4257 return Api::NewError("%s: expects argument at index %d to be of"
4258 " type Integer.", CURRENT_FUNC, i);
4259 }
4260 val->as_int64 = value;
4261 break;
4262 }
4263
4264 case Dart_NativeArgument_kUint64: {
4265 int64_t value = 0;
4266 if (!GetNativeIntegerArgument(arguments,
4267 arg_index,
4268 &value)) {
4269 return Api::NewError("%s: expects argument at index %d to be of"
4270 " type Integer.", CURRENT_FUNC, i);
4271 }
4272 if (value < 0) {
4273 return Api::NewError("%s: argument value at index %d is out of range",
4274 CURRENT_FUNC, i);
4275 }
4276 val->as_uint64 = value;
Ivan Posva 2014/05/20 19:27:03 ditto.
siva 2014/05/21 23:56:54 Uses uint64_t value = 0; On 2014/05/20 19:27:03,
4277 break;
4278 }
4279
4280 case Dart_NativeArgument_kDouble:
4281 if (!GetNativeDoubleArgument(arguments,
4282 arg_index,
4283 &(val->as_double))) {
4284 return Api::NewError("%s: expects argument at index %d to be of"
4285 " type Double.", CURRENT_FUNC, i);
4286 }
4287 break;
4288
4289 case Dart_NativeArgument_kString:
4290 if (!GetNativeStringArgument(arguments,
4291 arg_index,
4292 &(val->as_string.dart_str),
4293 &(val->as_string.peer))) {
4294 return Api::NewError("%s: expects argument at index %d to be of"
4295 " type String.", CURRENT_FUNC, i);
4296 }
4297 break;
4298
4299 case Dart_NativeArgument_kNativeFields: {
4300 Dart_Handle result = GetNativeFieldsOfArgument(
4301 arguments,
4302 arg_index,
4303 val->as_native_fields.num_fields,
4304 val->as_native_fields.values,
4305 CURRENT_FUNC);
4306 if (result != Api::Success()) {
4307 return result;
4308 }
4309 break;
4310 }
4311
4312 case Dart_NativeArgument_kInstance: {
4313 Isolate* isolate = arguments->isolate();
4314 ASSERT(isolate == Isolate::Current());
4315 ASSERT(isolate->api_state() &&
4316 isolate->api_state()->top_scope() != NULL);
4317 val->as_instance =
4318 Api::NewHandle(isolate, arguments->NativeArgAt(arg_index));
4319 break;
4320 }
4321
4322 default:
4323 return Api::NewError("%s: invalid argument type %d.",
4324 CURRENT_FUNC, arg_type);
4325 }
4326 }
4327 return Api::Success();
4328 }
4329
4330
4015 DART_EXPORT Dart_Handle Dart_GetNativeArgument(Dart_NativeArguments args, 4331 DART_EXPORT Dart_Handle Dart_GetNativeArgument(Dart_NativeArguments args,
4016 int index) { 4332 int index) {
4017 TRACE_API_CALL(CURRENT_FUNC); 4333 TRACE_API_CALL(CURRENT_FUNC);
4018 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); 4334 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args);
4019 if ((index < 0) || (index >= arguments->NativeArgCount())) { 4335 if ((index < 0) || (index >= arguments->NativeArgCount())) {
4020 return Api::NewError( 4336 return Api::NewError(
4021 "%s: argument 'index' out of range. Expected 0..%d but saw %d.", 4337 "%s: argument 'index' out of range. Expected 0..%d but saw %d.",
4022 CURRENT_FUNC, arguments->NativeArgCount() - 1, index); 4338 CURRENT_FUNC, arguments->NativeArgCount() - 1, index);
4023 } 4339 }
4024 return Api::NewHandle(arguments->isolate(), arguments->NativeArgAt(index)); 4340 return Api::NewHandle(arguments->isolate(), arguments->NativeArgAt(index));
(...skipping 14 matching lines...) Expand all
4039 intptr_t* field_values) { 4355 intptr_t* field_values) {
4040 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); 4356 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args);
4041 if ((arg_index < 0) || (arg_index >= arguments->NativeArgCount())) { 4357 if ((arg_index < 0) || (arg_index >= arguments->NativeArgCount())) {
4042 return Api::NewError( 4358 return Api::NewError(
4043 "%s: argument 'arg_index' out of range. Expected 0..%d but saw %d.", 4359 "%s: argument 'arg_index' out of range. Expected 0..%d but saw %d.",
4044 CURRENT_FUNC, arguments->NativeArgCount() - 1, arg_index); 4360 CURRENT_FUNC, arguments->NativeArgCount() - 1, arg_index);
4045 } 4361 }
4046 if (field_values == NULL) { 4362 if (field_values == NULL) {
4047 RETURN_NULL_ERROR(field_values); 4363 RETURN_NULL_ERROR(field_values);
4048 } 4364 }
4049 Isolate* isolate = arguments->isolate(); 4365 return GetNativeFieldsOfArgument(arguments,
4050 ASSERT(isolate == Isolate::Current()); 4366 arg_index,
4051 REUSABLE_OBJECT_HANDLESCOPE(isolate); 4367 num_fields,
4052 Object& obj = isolate->ObjectHandle(); 4368 field_values,
4053 obj = arguments->NativeArgAt(arg_index); 4369 CURRENT_FUNC);
4054 if (obj.IsNull()) {
4055 for (intptr_t i = 0; i < num_fields; i++) {
4056 field_values[i] = 0;
4057 }
4058 return Api::Success();
4059 }
4060 if (!obj.IsInstance()) {
4061 return Api::NewError("%s expects argument at index '%d' to be of"
4062 " type Instance.", CURRENT_FUNC, arg_index);
4063 }
4064 const Instance& instance = Instance::Cast(obj);
4065 uint16_t field_count = instance.NumNativeFields();
4066 if (num_fields != field_count) {
4067 return Api::NewError(
4068 "%s: invalid 'field_values' array specified for returning field values",
4069 CURRENT_FUNC);
4070 }
4071 instance.GetNativeFields(num_fields, field_values);
4072 return Api::Success();
4073 } 4370 }
4074 4371
4075 4372
4076 DART_EXPORT Dart_Handle Dart_GetNativeReceiver(Dart_NativeArguments args, 4373 DART_EXPORT Dart_Handle Dart_GetNativeReceiver(Dart_NativeArguments args,
4077 intptr_t* value) { 4374 intptr_t* value) {
4078 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); 4375 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args);
4079 ASSERT(arguments->isolate() == Isolate::Current()); 4376 ASSERT(arguments->isolate() == Isolate::Current());
4080 if (value == NULL) { 4377 if (value == NULL) {
4081 RETURN_NULL_ERROR(value); 4378 RETURN_NULL_ERROR(value);
4082 } 4379 }
4083 if (Api::GetNativeReceiver(arguments, value)) { 4380 if (Api::GetNativeReceiver(arguments, value)) {
4084 return Api::Success(); 4381 return Api::Success();
4085 } 4382 }
4086 return Api::NewError("%s expects receiver argument to be non-null and of" 4383 return Api::NewError("%s expects receiver argument to be non-null and of"
4087 " type Instance.", CURRENT_FUNC); 4384 " type Instance.", CURRENT_FUNC);
4088 } 4385 }
4089 4386
4090 4387
4091 DART_EXPORT Dart_Handle Dart_GetNativeStringArgument(Dart_NativeArguments args, 4388 DART_EXPORT Dart_Handle Dart_GetNativeStringArgument(Dart_NativeArguments args,
4092 int arg_index, 4389 int arg_index,
4093 void** peer) { 4390 void** peer) {
4094 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); 4391 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args);
4095 Isolate* isolate = arguments->isolate(); 4392 Dart_Handle result = Api::Null();
4096 ASSERT(isolate == Isolate::Current()); 4393 if (!GetNativeStringArgument(arguments, arg_index, &result, peer)) {
4097 if (Api::StringGetPeerHelper(arguments, arg_index, peer)) { 4394 return Api::NewError("%s expects argument at %d to be of"
4098 return Api::Success(); 4395 " type String.", CURRENT_FUNC, arg_index);
4099 } 4396 }
4100 *peer = NULL; 4397 return result;
4101 REUSABLE_OBJECT_HANDLESCOPE(isolate);
4102 Object& obj = isolate->ObjectHandle();
4103 obj = arguments->NativeArgAt(arg_index);
4104 if (RawObject::IsStringClassId(obj.GetClassId())) {
4105 return Api::NewHandle(isolate, obj.raw());
4106 }
4107 if (obj.IsNull()) {
4108 return Api::Null();
4109 }
4110 return Api::NewError("%s expects argument to be of"
4111 " type String.", CURRENT_FUNC);
4112 } 4398 }
4113 4399
4114 4400
4115 DART_EXPORT Dart_Handle Dart_GetNativeIntegerArgument(Dart_NativeArguments args, 4401 DART_EXPORT Dart_Handle Dart_GetNativeIntegerArgument(Dart_NativeArguments args,
4116 int index, 4402 int index,
4117 int64_t* value) { 4403 int64_t* value) {
4118 TRACE_API_CALL(CURRENT_FUNC); 4404 TRACE_API_CALL(CURRENT_FUNC);
4119 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); 4405 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args);
4120 if ((index < 0) || (index >= arguments->NativeArgCount())) { 4406 if ((index < 0) || (index >= arguments->NativeArgCount())) {
4121 return Api::NewError( 4407 return Api::NewError(
4122 "%s: argument 'index' out of range. Expected 0..%d but saw %d.", 4408 "%s: argument 'index' out of range. Expected 0..%d but saw %d.",
4123 CURRENT_FUNC, arguments->NativeArgCount() - 1, index); 4409 CURRENT_FUNC, arguments->NativeArgCount() - 1, index);
4124 } 4410 }
4125 Isolate* isolate = arguments->isolate(); 4411 if (!GetNativeIntegerArgument(arguments, index, value)) {
4126 ASSERT(isolate == Isolate::Current()); 4412 return Api::NewError("%s: expects argument at %d to be of"
4127 REUSABLE_OBJECT_HANDLESCOPE(isolate); 4413 " type Integer.", CURRENT_FUNC, index);
4128 Object& obj = isolate->ObjectHandle();
4129 obj = arguments->NativeArgAt(index);
4130 intptr_t cid = obj.GetClassId();
4131 if (cid == kSmiCid) {
4132 *value = Smi::Cast(obj).Value();
4133 return Api::Success();
4134 } 4414 }
4135 if (cid == kMintCid) { 4415 return Api::Success();
4136 *value = Mint::Cast(obj).value();
4137 return Api::Success();
4138 }
4139 if (cid == kBigintCid) {
4140 const Bigint& bigint = Bigint::Cast(obj);
4141 if (BigintOperations::FitsIntoInt64(bigint)) {
4142 *value = BigintOperations::ToInt64(bigint);
4143 return Api::Success();
4144 }
4145 return Api::NewError(
4146 "%s: argument %d is a big integer that does not fit in 'value'.",
4147 CURRENT_FUNC, index);
4148 }
4149 return Api::NewError(
4150 "%s: argument %d is not an Integer argument.",
4151 CURRENT_FUNC, index);
4152 } 4416 }
4153 4417
4154 4418
4155 DART_EXPORT Dart_Handle Dart_GetNativeBooleanArgument(Dart_NativeArguments args, 4419 DART_EXPORT Dart_Handle Dart_GetNativeBooleanArgument(Dart_NativeArguments args,
4156 int index, 4420 int index,
4157 bool* value) { 4421 bool* value) {
4158 TRACE_API_CALL(CURRENT_FUNC); 4422 TRACE_API_CALL(CURRENT_FUNC);
4159 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); 4423 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args);
4160 if ((index < 0) || (index >= arguments->NativeArgCount())) { 4424 if ((index < 0) || (index >= arguments->NativeArgCount())) {
4161 return Api::NewError( 4425 return Api::NewError(
4162 "%s: argument 'index' out of range. Expected 0..%d but saw %d.", 4426 "%s: argument 'index' out of range. Expected 0..%d but saw %d.",
4163 CURRENT_FUNC, arguments->NativeArgCount() - 1, index); 4427 CURRENT_FUNC, arguments->NativeArgCount() - 1, index);
4164 } 4428 }
4165 if (Api::GetNativeBooleanArgument(arguments, index, value)) { 4429 if (!Api::GetNativeBooleanArgument(arguments, index, value)) {
4166 return Api::Success(); 4430 return Api::NewError("%s: expects argument at %d to be of type Boolean.",
4431 CURRENT_FUNC, index);
4167 } 4432 }
4168 return Api::NewError("%s: argument %d is not a Boolean argument.", 4433 return Api::Success();
4169 CURRENT_FUNC, index);
4170 } 4434 }
4171 4435
4172 4436
4173 DART_EXPORT Dart_Handle Dart_GetNativeDoubleArgument(Dart_NativeArguments args, 4437 DART_EXPORT Dart_Handle Dart_GetNativeDoubleArgument(Dart_NativeArguments args,
4174 int index, 4438 int index,
4175 double* value) { 4439 double* value) {
4176 TRACE_API_CALL(CURRENT_FUNC); 4440 TRACE_API_CALL(CURRENT_FUNC);
4177 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); 4441 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args);
4178 if ((index < 0) || (index >= arguments->NativeArgCount())) { 4442 if ((index < 0) || (index >= arguments->NativeArgCount())) {
4179 return Api::NewError( 4443 return Api::NewError(
4180 "%s: argument 'index' out of range. Expected 0..%d but saw %d.", 4444 "%s: argument 'index' out of range. Expected 0..%d but saw %d.",
4181 CURRENT_FUNC, arguments->NativeArgCount() - 1, index); 4445 CURRENT_FUNC, arguments->NativeArgCount() - 1, index);
4182 } 4446 }
4183 Isolate* isolate = arguments->isolate(); 4447 if (!GetNativeDoubleArgument(arguments, index, value)) {
4184 ASSERT(isolate == Isolate::Current()); 4448 return Api::NewError("%s: expects argument at %d to be of"
4185 REUSABLE_OBJECT_HANDLESCOPE(isolate); 4449 " type Double.", CURRENT_FUNC, index);
4186 Object& obj = isolate->ObjectHandle();
4187 obj = arguments->NativeArgAt(index);
4188 intptr_t cid = obj.GetClassId();
4189 if (cid == kDoubleCid) {
4190 *value = Double::Cast(obj).value();
4191 return Api::Success();
4192 } 4450 }
4193 if (cid == kSmiCid) { 4451 return Api::Success();
4194 *value = Smi::Cast(obj).AsDoubleValue();
4195 return Api::Success();
4196 }
4197 if (cid == kMintCid) {
4198 *value = Mint::Cast(obj).AsDoubleValue();
4199 return Api::Success();
4200 }
4201 if (cid == kBigintCid) {
4202 *value = Bigint::Cast(obj).AsDoubleValue();
4203 return Api::Success();
4204 }
4205 return Api::NewError(
4206 "%s: argument %d is not a Double argument.",
4207 CURRENT_FUNC, index);
4208 } 4452 }
4209 4453
4210 4454
4211 DART_EXPORT void Dart_SetReturnValue(Dart_NativeArguments args, 4455 DART_EXPORT void Dart_SetReturnValue(Dart_NativeArguments args,
4212 Dart_Handle retval) { 4456 Dart_Handle retval) {
4213 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); 4457 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args);
4214 ASSERT(arguments->isolate() == Isolate::Current()); 4458 ASSERT(arguments->isolate() == Isolate::Current());
4215 if ((retval != Api::Null()) && (!Api::IsInstance(retval))) { 4459 if ((retval != Api::Null()) && (!Api::IsInstance(retval))) {
4216 const Object& ret_obj = Object::Handle(Api::UnwrapHandle(retval)); 4460 const Object& ret_obj = Object::Handle(Api::UnwrapHandle(retval));
4217 FATAL1("Return value check failed: saw '%s' expected a dart Instance.", 4461 FATAL1("Return value check failed: saw '%s' expected a dart Instance.",
(...skipping 565 matching lines...) Expand 10 before | Expand all | Expand 10 after
4783 5027
4784 5028
4785 DART_EXPORT void Dart_RegisterRootServiceRequestCallback( 5029 DART_EXPORT void Dart_RegisterRootServiceRequestCallback(
4786 const char* name, 5030 const char* name,
4787 Dart_ServiceRequestCallback callback, 5031 Dart_ServiceRequestCallback callback,
4788 void* user_data) { 5032 void* user_data) {
4789 Service::RegisterRootEmbedderCallback(name, callback, user_data); 5033 Service::RegisterRootEmbedderCallback(name, callback, user_data);
4790 } 5034 }
4791 5035
4792 } // namespace dart 5036 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698