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" |
11 #include "vm/native_entry.h" | 11 #include "vm/native_entry.h" |
12 #include "vm/object.h" | 12 #include "vm/object.h" |
13 | 13 |
14 namespace dart { | 14 namespace dart { |
15 | 15 |
16 // TypedData. | 16 // TypedData. |
17 | 17 |
18 // Checks to see if offsetInBytes + num_bytes is in the range. | 18 // Checks to see if offsetInBytes + num_bytes is in the range. |
19 static void RangeCheck(intptr_t offset_in_bytes, | 19 static void RangeCheck(intptr_t offset_in_bytes, |
20 intptr_t access_size, | 20 intptr_t access_size, |
21 intptr_t length_in_bytes, | 21 intptr_t length_in_bytes, |
22 intptr_t element_size_in_bytes) { | 22 intptr_t element_size_in_bytes) { |
23 if (!Utils::RangeCheck(offset_in_bytes, access_size, length_in_bytes)) { | 23 if (!Utils::RangeCheck(offset_in_bytes, access_size, length_in_bytes)) { |
24 const String& error = String::Handle(String::NewFormatted( | 24 const String& error = String::Handle(String::NewFormatted( |
25 "index (%" Pd ") must be in the range [0..%" Pd ")", | 25 "index (%" Pd ") must be in the range [0..%" Pd ")", |
26 (offset_in_bytes + access_size) / element_size_in_bytes, | 26 (offset_in_bytes + access_size) / element_size_in_bytes, |
27 (length_in_bytes / element_size_in_bytes))); | 27 (length_in_bytes / element_size_in_bytes))); |
28 const Array& args = Array::Handle(Array::New(1)); | 28 Exceptions::ThrowRangeError(error); |
29 args.SetAt(0, error); | |
30 Exceptions::ThrowByType(Exceptions::kRange, args); | |
31 } | 29 } |
32 } | 30 } |
33 | 31 |
34 | 32 |
35 // Checks to see if a length will not result in an OOM error. | 33 // Checks to see if a length will not result in an OOM error. |
36 static void LengthCheck(intptr_t len, intptr_t max) { | 34 static void LengthCheck(intptr_t len, intptr_t max) { |
37 if (len < 0 || len > max) { | 35 if (len < 0 || len > max) { |
38 const String& error = String::Handle(String::NewFormatted( | 36 const String& error = String::Handle(String::NewFormatted( |
39 "Length (%" Pd ") of object must be in range [0..%" Pd "]", | 37 "Length (%" Pd ") of object must be in range [0..%" Pd "]", |
40 len, max)); | 38 len, max)); |
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
454 value = bit_cast<double>( | 452 value = bit_cast<double>( |
455 Utils::HostToLittleEndian64(bit_cast<uint64_t>(value))); | 453 Utils::HostToLittleEndian64(bit_cast<uint64_t>(value))); |
456 } else { | 454 } else { |
457 value = bit_cast<double>( | 455 value = bit_cast<double>( |
458 Utils::HostToBigEndian64(bit_cast<uint64_t>(value))); | 456 Utils::HostToBigEndian64(bit_cast<uint64_t>(value))); |
459 } | 457 } |
460 return Double::New(value); | 458 return Double::New(value); |
461 } | 459 } |
462 | 460 |
463 } // namespace dart | 461 } // namespace dart |
OLD | NEW |