| 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 24 matching lines...) Expand all Loading... |
| 35 (length_in_bytes / element_size_in_bytes))); | 35 (length_in_bytes / element_size_in_bytes))); |
| 36 const Array& args = Array::Handle(Array::New(1)); | 36 const Array& args = Array::Handle(Array::New(1)); |
| 37 args.SetAt(0, error); | 37 args.SetAt(0, error); |
| 38 Exceptions::ThrowByType(Exceptions::kRange, args); | 38 Exceptions::ThrowByType(Exceptions::kRange, args); |
| 39 } | 39 } |
| 40 } | 40 } |
| 41 | 41 |
| 42 | 42 |
| 43 // Checks to see if a length will not result in an OOM error. | 43 // Checks to see if a length will not result in an OOM error. |
| 44 static void LengthCheck(intptr_t len, intptr_t max) { | 44 static void LengthCheck(intptr_t len, intptr_t max) { |
| 45 if (len > max) { | 45 if (len < 0 || len > max) { |
| 46 const String& error = String::Handle(String::NewFormatted( | 46 const String& error = String::Handle(String::NewFormatted( |
| 47 "insufficient memory to allocate a TypedData object of length (%"Pd")", | 47 "Length (%"Pd") of object must be in range [0..%"Pd"]", |
| 48 len)); | 48 len, max)); |
| 49 const Array& args = Array::Handle(Array::New(1)); | |
| 50 args.SetAt(0, error); | |
| 51 Exceptions::ThrowByType(Exceptions::kOutOfMemory, args); | |
| 52 } else if (len < 0) { | |
| 53 const String& error = String::Handle(String::NewFormatted( | |
| 54 "%"Pd" must be greater than 0", len)); | |
| 55 const Array& args = Array::Handle(Array::New(1)); | 49 const Array& args = Array::Handle(Array::New(1)); |
| 56 args.SetAt(0, error); | 50 args.SetAt(0, error); |
| 57 Exceptions::ThrowByType(Exceptions::kArgument, args); | 51 Exceptions::ThrowByType(Exceptions::kArgument, args); |
| 58 } | 52 } |
| 59 } | 53 } |
| 60 | 54 |
| 61 | 55 |
| 62 static void PeerFinalizer(Dart_WeakPersistentHandle handle, void* peer) { | 56 static void PeerFinalizer(Dart_WeakPersistentHandle handle, void* peer) { |
| 63 Dart_DeleteWeakPersistentHandle(handle); | 57 Dart_DeleteWeakPersistentHandle(handle); |
| 64 OS::AlignedFree(peer); | 58 OS::AlignedFree(peer); |
| (...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 427 value = bit_cast<double>( | 421 value = bit_cast<double>( |
| 428 Utils::HostToLittleEndian64(bit_cast<uint64_t>(value))); | 422 Utils::HostToLittleEndian64(bit_cast<uint64_t>(value))); |
| 429 } else { | 423 } else { |
| 430 value = bit_cast<double>( | 424 value = bit_cast<double>( |
| 431 Utils::HostToBigEndian64(bit_cast<uint64_t>(value))); | 425 Utils::HostToBigEndian64(bit_cast<uint64_t>(value))); |
| 432 } | 426 } |
| 433 return Double::New(value); | 427 return Double::New(value); |
| 434 } | 428 } |
| 435 | 429 |
| 436 } // namespace dart | 430 } // namespace dart |
| OLD | NEW |