| 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 "vm/bootstrap_natives.h" | 5 #include "vm/bootstrap_natives.h" |
| 6 | 6 |
| 7 #include "include/dart_api.h" | 7 #include "include/dart_api.h" |
| 8 | 8 |
| 9 #include "vm/bigint_operations.h" | 9 #include "vm/bigint_operations.h" |
| 10 #include "vm/exceptions.h" | 10 #include "vm/exceptions.h" |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 SetRangeCheck(dst_offset_in_bytes, | 103 SetRangeCheck(dst_offset_in_bytes, |
| 104 length_in_bytes, | 104 length_in_bytes, |
| 105 dst_array.LengthInBytes(), | 105 dst_array.LengthInBytes(), |
| 106 element_size_in_bytes); | 106 element_size_in_bytes); |
| 107 TypedData::Copy<DstType, SrcType>(dst_array, dst_offset_in_bytes, | 107 TypedData::Copy<DstType, SrcType>(dst_array, dst_offset_in_bytes, |
| 108 src_array, src_offset_in_bytes, | 108 src_array, src_offset_in_bytes, |
| 109 length_in_bytes); | 109 length_in_bytes); |
| 110 return Bool::True().raw(); | 110 return Bool::True().raw(); |
| 111 } | 111 } |
| 112 | 112 |
| 113 |
| 113 DEFINE_NATIVE_ENTRY(TypedData_setRange, 5) { | 114 DEFINE_NATIVE_ENTRY(TypedData_setRange, 5) { |
| 114 GET_NON_NULL_NATIVE_ARGUMENT(Instance, dst, arguments->NativeArgAt(0)); | 115 GET_NON_NULL_NATIVE_ARGUMENT(Instance, dst, arguments->NativeArgAt(0)); |
| 115 GET_NON_NULL_NATIVE_ARGUMENT(Smi, dst_start, arguments->NativeArgAt(1)); | 116 GET_NON_NULL_NATIVE_ARGUMENT(Smi, dst_start, arguments->NativeArgAt(1)); |
| 116 GET_NON_NULL_NATIVE_ARGUMENT(Smi, length, arguments->NativeArgAt(2)); | 117 GET_NON_NULL_NATIVE_ARGUMENT(Smi, length, arguments->NativeArgAt(2)); |
| 117 GET_NON_NULL_NATIVE_ARGUMENT(Instance, src, arguments->NativeArgAt(3)); | 118 GET_NON_NULL_NATIVE_ARGUMENT(Instance, src, arguments->NativeArgAt(3)); |
| 118 GET_NON_NULL_NATIVE_ARGUMENT(Smi, src_start, arguments->NativeArgAt(4)); | 119 GET_NON_NULL_NATIVE_ARGUMENT(Smi, src_start, arguments->NativeArgAt(4)); |
| 119 | 120 |
| 120 if (length.Value() < 0) { | 121 if (length.Value() < 0) { |
| 121 const String& error = String::Handle(String::NewFormatted( | 122 const String& error = String::Handle(String::NewFormatted( |
| 122 "length (%"Pd") must be non-negative", length.Value())); | 123 "length (%"Pd") must be non-negative", length.Value())); |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 const ExternalTypedData& array = ExternalTypedData::Cast(instance); \ | 249 const ExternalTypedData& array = ExternalTypedData::Cast(instance); \ |
| 249 ASSERT(RangeCheck(offsetInBytes.Value(), array.LengthInBytes())); \ | 250 ASSERT(RangeCheck(offsetInBytes.Value(), array.LengthInBytes())); \ |
| 250 value = array.getter(offsetInBytes.Value()); \ | 251 value = array.getter(offsetInBytes.Value()); \ |
| 251 } else { \ | 252 } else { \ |
| 252 const String& error = String::Handle(String::NewFormatted( \ | 253 const String& error = String::Handle(String::NewFormatted( \ |
| 253 "Expected a TypedData object but found %s", instance.ToCString())); \ | 254 "Expected a TypedData object but found %s", instance.ToCString())); \ |
| 254 const Array& args = Array::Handle(Array::New(1)); \ | 255 const Array& args = Array::Handle(Array::New(1)); \ |
| 255 args.SetAt(0, error); \ | 256 args.SetAt(0, error); \ |
| 256 Exceptions::ThrowByType(Exceptions::kArgument, args); \ | 257 Exceptions::ThrowByType(Exceptions::kArgument, args); \ |
| 257 } \ | 258 } \ |
| 258 Integer& result = Integer::Handle(); \ | 259 return Integer::NewFromUint64(value); \ |
| 259 if (value > static_cast<uint64_t>(Mint::kMaxValue)) { \ | |
| 260 result = BigintOperations::NewFromUint64(value); \ | |
| 261 } else { \ | |
| 262 result = Integer::New(value); \ | |
| 263 } \ | |
| 264 return result.raw(); \ | |
| 265 } \ | 260 } \ |
| 266 | 261 |
| 267 | 262 |
| 268 // TODO(asiva): Consider truncating the bigint value if it does not fit into | 263 // TODO(asiva): Consider truncating the bigint value if it does not fit into |
| 269 // a uint64_t value (see ASSERT(BigintOperations::FitsIntoUint64(bigint))). | 264 // a uint64_t value (see ASSERT(BigintOperations::FitsIntoUint64(bigint))). |
| 270 #define TYPED_DATA_UINT64_SETTER(setter, object) \ | 265 #define TYPED_DATA_UINT64_SETTER(setter, object) \ |
| 271 DEFINE_NATIVE_ENTRY(TypedData_##setter, 3) { \ | 266 DEFINE_NATIVE_ENTRY(TypedData_##setter, 3) { \ |
| 272 GET_NON_NULL_NATIVE_ARGUMENT(Instance, instance, arguments->NativeArgAt(0)); \ | 267 GET_NON_NULL_NATIVE_ARGUMENT(Instance, instance, arguments->NativeArgAt(0)); \ |
| 273 GET_NON_NULL_NATIVE_ARGUMENT(Smi, offsetInBytes, arguments->NativeArgAt(1)); \ | 268 GET_NON_NULL_NATIVE_ARGUMENT(Smi, offsetInBytes, arguments->NativeArgAt(1)); \ |
| 274 GET_NON_NULL_NATIVE_ARGUMENT(object, value, arguments->NativeArgAt(2)); \ | 269 GET_NON_NULL_NATIVE_ARGUMENT(object, value, arguments->NativeArgAt(2)); \ |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 398 value = BigintOperations::AbsToUint64(bigint); | 393 value = BigintOperations::AbsToUint64(bigint); |
| 399 } else { | 394 } else { |
| 400 ASSERT(host_value.IsMint() || host_value.IsSmi()); | 395 ASSERT(host_value.IsMint() || host_value.IsSmi()); |
| 401 value = host_value.AsInt64Value(); | 396 value = host_value.AsInt64Value(); |
| 402 } | 397 } |
| 403 if (little_endian.value()) { | 398 if (little_endian.value()) { |
| 404 value = Utils::HostToLittleEndian64(value); | 399 value = Utils::HostToLittleEndian64(value); |
| 405 } else { | 400 } else { |
| 406 value = Utils::HostToBigEndian64(value); | 401 value = Utils::HostToBigEndian64(value); |
| 407 } | 402 } |
| 408 if (value > static_cast<uint64_t>(Mint::kMaxValue)) { | 403 return Integer::NewFromUint64(value); |
| 409 return BigintOperations::NewFromUint64(value); | |
| 410 } | |
| 411 return Integer::New(value); | |
| 412 } | 404 } |
| 413 | 405 |
| 414 | 406 |
| 415 DEFINE_NATIVE_ENTRY(ByteData_ToEndianFloat32, 2) { | 407 DEFINE_NATIVE_ENTRY(ByteData_ToEndianFloat32, 2) { |
| 416 GET_NON_NULL_NATIVE_ARGUMENT(Double, host_value, arguments->NativeArgAt(0)); | 408 GET_NON_NULL_NATIVE_ARGUMENT(Double, host_value, arguments->NativeArgAt(0)); |
| 417 GET_NON_NULL_NATIVE_ARGUMENT(Bool, little_endian, arguments->NativeArgAt(1)); | 409 GET_NON_NULL_NATIVE_ARGUMENT(Bool, little_endian, arguments->NativeArgAt(1)); |
| 418 float value = host_value.value(); | 410 float value = host_value.value(); |
| 419 if (little_endian.value()) { | 411 if (little_endian.value()) { |
| 420 value = bit_cast<float>( | 412 value = bit_cast<float>( |
| 421 Utils::HostToLittleEndian32(bit_cast<uint32_t>(value))); | 413 Utils::HostToLittleEndian32(bit_cast<uint32_t>(value))); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 435 value = bit_cast<double>( | 427 value = bit_cast<double>( |
| 436 Utils::HostToLittleEndian64(bit_cast<uint64_t>(value))); | 428 Utils::HostToLittleEndian64(bit_cast<uint64_t>(value))); |
| 437 } else { | 429 } else { |
| 438 value = bit_cast<double>( | 430 value = bit_cast<double>( |
| 439 Utils::HostToBigEndian64(bit_cast<uint64_t>(value))); | 431 Utils::HostToBigEndian64(bit_cast<uint64_t>(value))); |
| 440 } | 432 } |
| 441 return Double::New(value); | 433 return Double::New(value); |
| 442 } | 434 } |
| 443 | 435 |
| 444 } // namespace dart | 436 } // namespace dart |
| OLD | NEW |