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 12 matching lines...) Expand all Loading... |
23 GrowableArray<const Object*> args; | 23 GrowableArray<const Object*> args; |
24 args.Add(&length); | 24 args.Add(&length); |
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 DEFINE_NATIVE_ENTRY(ByteArray_setRange, 5) { |
| 34 ByteArray& dst = ByteArray::CheckedHandle(arguments->At(0)); |
| 35 GET_NATIVE_ARGUMENT(ByteArray, src, arguments->At(1)); |
| 36 GET_NATIVE_ARGUMENT(Smi, src_start, arguments->At(2)); |
| 37 GET_NATIVE_ARGUMENT(Smi, dst_start, arguments->At(3)); |
| 38 GET_NATIVE_ARGUMENT(Smi, count, arguments->At(4)); |
| 39 if (count.Value() < 0) { |
| 40 GrowableArray<const Object*> args; |
| 41 Exceptions::ThrowByType(Exceptions::kIllegalArgument, args); |
| 42 } |
| 43 if (!dart::Utils::RangeCheck(src_start.Value(), |
| 44 count.Value(), |
| 45 src.Length())) { |
| 46 GrowableArray<const Object*> arguments; |
| 47 arguments.Add(&src_start); |
| 48 Exceptions::ThrowByType(Exceptions::kIndexOutOfRange, arguments); |
| 49 } |
| 50 if (!dart::Utils::RangeCheck(dst_start.Value(), |
| 51 count.Value(), |
| 52 dst.Length())) { |
| 53 GrowableArray<const Object*> arguments; |
| 54 arguments.Add(&dst_start); |
| 55 Exceptions::ThrowByType(Exceptions::kIndexOutOfRange, arguments); |
| 56 } |
| 57 ByteArray::Copy( |
| 58 dst, dst_start.Value(), src, src_start.Value(), count.Value()); |
| 59 } |
| 60 |
| 61 |
33 static void RangeCheck(const ByteArray& array, const Smi& index, | 62 static void RangeCheck(const ByteArray& array, const Smi& index, |
34 intptr_t num_bytes) { | 63 intptr_t num_bytes) { |
35 if ((index.Value() < 0) || ((index.Value() + num_bytes) > array.Length())) { | 64 if ((index.Value() < 0) || ((index.Value() + num_bytes) > array.Length())) { |
36 GrowableArray<const Object*> arguments; | 65 GrowableArray<const Object*> arguments; |
37 arguments.Add(&index); | 66 arguments.Add(&index); |
38 Exceptions::ThrowByType(Exceptions::kIndexOutOfRange, arguments); | 67 Exceptions::ThrowByType(Exceptions::kIndexOutOfRange, arguments); |
39 } | 68 } |
40 } | 69 } |
41 | 70 |
42 | 71 |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 DEFINE_NATIVE_ENTRY(ExternalByteArray_getFloat64, 2) { | 278 DEFINE_NATIVE_ENTRY(ExternalByteArray_getFloat64, 2) { |
250 GETTER(ExternalByteArray, Double, double); | 279 GETTER(ExternalByteArray, Double, double); |
251 } | 280 } |
252 | 281 |
253 | 282 |
254 DEFINE_NATIVE_ENTRY(ExternalByteArray_setFloat64, 3) { | 283 DEFINE_NATIVE_ENTRY(ExternalByteArray_setFloat64, 3) { |
255 SETTER(ExternalByteArray, Double, value, double); | 284 SETTER(ExternalByteArray, Double, value, double); |
256 } | 285 } |
257 | 286 |
258 } // namespace dart | 287 } // namespace dart |
OLD | NEW |