OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 "vm/exceptions.h" | 7 #include "vm/exceptions.h" |
8 #include "vm/native_entry.h" | 8 #include "vm/native_entry.h" |
9 #include "vm/object.h" | 9 #include "vm/object.h" |
10 | 10 |
(...skipping 14 matching lines...) Expand all Loading... |
25 Exceptions::ThrowByType(Exceptions::kIllegalArgument, args); | 25 Exceptions::ThrowByType(Exceptions::kIllegalArgument, args); |
26 } | 26 } |
27 const InternalByteArray& new_array = | 27 const InternalByteArray& new_array = |
28 InternalByteArray::Handle(InternalByteArray::New(length.Value())); | 28 InternalByteArray::Handle(InternalByteArray::New(length.Value())); |
29 arguments->SetReturn(new_array); | 29 arguments->SetReturn(new_array); |
30 } | 30 } |
31 | 31 |
32 | 32 |
33 static void RangeCheck(const ByteArray& array, const Smi& index, | 33 static void RangeCheck(const ByteArray& array, const Smi& index, |
34 intptr_t num_bytes) { | 34 intptr_t num_bytes) { |
35 if ((index.Value() < 0) || ((index.Value() + num_bytes) > array.Length())) { | 35 if (!Utils::RangeCheck(index.Value(), num_bytes, array.Length())) { |
36 GrowableArray<const Object*> arguments; | 36 GrowableArray<const Object*> arguments; |
37 arguments.Add(&index); | 37 arguments.Add(&index); |
38 Exceptions::ThrowByType(Exceptions::kIndexOutOfRange, arguments); | 38 Exceptions::ThrowByType(Exceptions::kIndexOutOfRange, arguments); |
39 } | 39 } |
40 } | 40 } |
41 | 41 |
42 | 42 |
| 43 DEFINE_NATIVE_ENTRY(ByteArray_setRange, 5) { |
| 44 ByteArray& dst = ByteArray::CheckedHandle(arguments->At(0)); |
| 45 GET_NATIVE_ARGUMENT(Smi, dst_start, arguments->At(1)); |
| 46 GET_NATIVE_ARGUMENT(Smi, length, arguments->At(2)); |
| 47 GET_NATIVE_ARGUMENT(ByteArray, src, arguments->At(3)); |
| 48 GET_NATIVE_ARGUMENT(Smi, src_start, arguments->At(4)); |
| 49 intptr_t length_value = length.Value(); |
| 50 intptr_t src_start_value = src_start.Value(); |
| 51 intptr_t dst_start_value = dst_start.Value(); |
| 52 if (length_value < 0) { |
| 53 GrowableArray<const Object*> args; |
| 54 Exceptions::ThrowByType(Exceptions::kIllegalArgument, args); |
| 55 } |
| 56 RangeCheck(src, src_start, length_value); |
| 57 RangeCheck(dst, dst_start, length_value); |
| 58 ByteArray::Copy(dst, dst_start_value, src, src_start_value, length_value); |
| 59 } |
| 60 |
| 61 |
43 #define GETTER(ArrayT, ObjectT, ValueT) \ | 62 #define GETTER(ArrayT, ObjectT, ValueT) \ |
44 GET_NATIVE_ARGUMENT(ArrayT, array, arguments->At(0)); \ | 63 GET_NATIVE_ARGUMENT(ArrayT, array, arguments->At(0)); \ |
45 GET_NATIVE_ARGUMENT(Smi, index, arguments->At(1)); \ | 64 GET_NATIVE_ARGUMENT(Smi, index, arguments->At(1)); \ |
46 RangeCheck(array, index, sizeof(ValueT)); \ | 65 RangeCheck(array, index, sizeof(ValueT)); \ |
47 ValueT result = array.UnalignedAt<ValueT>(index.Value()); \ | 66 ValueT result = array.UnalignedAt<ValueT>(index.Value()); \ |
48 arguments->SetReturn(ObjectT::Handle(ObjectT::New(result))); | 67 arguments->SetReturn(ObjectT::Handle(ObjectT::New(result))); |
49 | 68 |
50 | 69 |
51 #define SETTER(ArrayT, ObjectT, Getter, ValueT) \ | 70 #define SETTER(ArrayT, ObjectT, Getter, ValueT) \ |
52 GET_NATIVE_ARGUMENT(ArrayT, array, arguments->At(0)); \ | 71 GET_NATIVE_ARGUMENT(ArrayT, array, arguments->At(0)); \ |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 DEFINE_NATIVE_ENTRY(ExternalByteArray_getFloat64, 2) { | 268 DEFINE_NATIVE_ENTRY(ExternalByteArray_getFloat64, 2) { |
250 GETTER(ExternalByteArray, Double, double); | 269 GETTER(ExternalByteArray, Double, double); |
251 } | 270 } |
252 | 271 |
253 | 272 |
254 DEFINE_NATIVE_ENTRY(ExternalByteArray_setFloat64, 3) { | 273 DEFINE_NATIVE_ENTRY(ExternalByteArray_setFloat64, 3) { |
255 SETTER(ExternalByteArray, Double, value, double); | 274 SETTER(ExternalByteArray, Double, value, double); |
256 } | 275 } |
257 | 276 |
258 } // namespace dart | 277 } // namespace dart |
OLD | NEW |