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 12 matching lines...) Expand all Loading... |
23 } | 23 } |
24 | 24 |
25 | 25 |
26 // Checks to see if offsetInBytes + num_bytes is in the range. | 26 // Checks to see if offsetInBytes + num_bytes is in the range. |
27 static void SetRangeCheck(intptr_t offset_in_bytes, | 27 static void SetRangeCheck(intptr_t offset_in_bytes, |
28 intptr_t num_bytes, | 28 intptr_t num_bytes, |
29 intptr_t length_in_bytes, | 29 intptr_t length_in_bytes, |
30 intptr_t element_size_in_bytes) { | 30 intptr_t element_size_in_bytes) { |
31 if (!Utils::RangeCheck(offset_in_bytes, num_bytes, length_in_bytes)) { | 31 if (!Utils::RangeCheck(offset_in_bytes, num_bytes, length_in_bytes)) { |
32 const String& error = String::Handle(String::NewFormatted( | 32 const String& error = String::Handle(String::NewFormatted( |
33 "index (%"Pd") must be in the range [0..%"Pd")", | 33 "index (%" Pd ") must be in the range [0..%" Pd ")", |
34 (offset_in_bytes / element_size_in_bytes), | 34 (offset_in_bytes / element_size_in_bytes), |
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 < 0 || 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 "Length (%"Pd") of object must be in range [0..%"Pd"]", | 47 "Length (%" Pd ") of object must be in range [0..%" Pd "]", |
48 len, max)); | 48 len, max)); |
49 const Array& args = Array::Handle(Array::New(1)); | 49 const Array& args = Array::Handle(Array::New(1)); |
50 args.SetAt(0, error); | 50 args.SetAt(0, error); |
51 Exceptions::ThrowByType(Exceptions::kArgument, args); | 51 Exceptions::ThrowByType(Exceptions::kArgument, args); |
52 } | 52 } |
53 } | 53 } |
54 | 54 |
55 | 55 |
56 static void PeerFinalizer(Dart_WeakPersistentHandle handle, void* peer) { | 56 static void PeerFinalizer(Dart_WeakPersistentHandle handle, void* peer) { |
57 Dart_DeleteWeakPersistentHandle(handle); | 57 Dart_DeleteWeakPersistentHandle(handle); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 | 107 |
108 DEFINE_NATIVE_ENTRY(TypedData_setRange, 5) { | 108 DEFINE_NATIVE_ENTRY(TypedData_setRange, 5) { |
109 GET_NON_NULL_NATIVE_ARGUMENT(Instance, dst, arguments->NativeArgAt(0)); | 109 GET_NON_NULL_NATIVE_ARGUMENT(Instance, dst, arguments->NativeArgAt(0)); |
110 GET_NON_NULL_NATIVE_ARGUMENT(Smi, dst_start, arguments->NativeArgAt(1)); | 110 GET_NON_NULL_NATIVE_ARGUMENT(Smi, dst_start, arguments->NativeArgAt(1)); |
111 GET_NON_NULL_NATIVE_ARGUMENT(Smi, length, arguments->NativeArgAt(2)); | 111 GET_NON_NULL_NATIVE_ARGUMENT(Smi, length, arguments->NativeArgAt(2)); |
112 GET_NON_NULL_NATIVE_ARGUMENT(Instance, src, arguments->NativeArgAt(3)); | 112 GET_NON_NULL_NATIVE_ARGUMENT(Instance, src, arguments->NativeArgAt(3)); |
113 GET_NON_NULL_NATIVE_ARGUMENT(Smi, src_start, arguments->NativeArgAt(4)); | 113 GET_NON_NULL_NATIVE_ARGUMENT(Smi, src_start, arguments->NativeArgAt(4)); |
114 | 114 |
115 if (length.Value() < 0) { | 115 if (length.Value() < 0) { |
116 const String& error = String::Handle(String::NewFormatted( | 116 const String& error = String::Handle(String::NewFormatted( |
117 "length (%"Pd") must be non-negative", length.Value())); | 117 "length (%" Pd ") must be non-negative", length.Value())); |
118 const Array& args = Array::Handle(Array::New(1)); | 118 const Array& args = Array::Handle(Array::New(1)); |
119 args.SetAt(0, error); | 119 args.SetAt(0, error); |
120 Exceptions::ThrowByType(Exceptions::kArgument, args); | 120 Exceptions::ThrowByType(Exceptions::kArgument, args); |
121 } | 121 } |
122 if (dst.IsTypedData()) { | 122 if (dst.IsTypedData()) { |
123 if (src.IsTypedData()) { | 123 if (src.IsTypedData()) { |
124 return CopyData<TypedData, TypedData>( | 124 return CopyData<TypedData, TypedData>( |
125 dst, src, dst_start, src_start, length); | 125 dst, src, dst_start, src_start, length); |
126 } else if (src.IsExternalTypedData()) { | 126 } else if (src.IsExternalTypedData()) { |
127 return CopyData<TypedData, ExternalTypedData>( | 127 return CopyData<TypedData, ExternalTypedData>( |
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
421 value = bit_cast<double>( | 421 value = bit_cast<double>( |
422 Utils::HostToLittleEndian64(bit_cast<uint64_t>(value))); | 422 Utils::HostToLittleEndian64(bit_cast<uint64_t>(value))); |
423 } else { | 423 } else { |
424 value = bit_cast<double>( | 424 value = bit_cast<double>( |
425 Utils::HostToBigEndian64(bit_cast<uint64_t>(value))); | 425 Utils::HostToBigEndian64(bit_cast<uint64_t>(value))); |
426 } | 426 } |
427 return Double::New(value); | 427 return Double::New(value); |
428 } | 428 } |
429 | 429 |
430 } // namespace dart | 430 } // namespace dart |
OLD | NEW |