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 (count.Value() == 0) { | |
cshapiro
2012/01/28 02:25:48
technically, this is not needed. your call.
Anders Johnsen
2012/01/30 21:15:28
Done.
| |
44 return; | |
45 } | |
46 if ((src_start.Value() < 0) || | |
cshapiro
2012/01/28 02:25:48
This check must be improved. Ensure all of the fo
Anders Johnsen
2012/01/30 21:15:28
Done.
| |
47 ((src_start.Value() + count.Value()) > src.Length())) { | |
48 GrowableArray<const Object*> arguments; | |
49 arguments.Add(&src_start); | |
50 Exceptions::ThrowByType(Exceptions::kIndexOutOfRange, arguments); | |
51 } | |
52 if ((dst_start.Value() < 0) || | |
cshapiro
2012/01/28 02:25:48
Same here.
Anders Johnsen
2012/01/30 21:15:28
Done.
| |
53 ((dst_start.Value() + count.Value()) > dst.Length())) { | |
54 GrowableArray<const Object*> arguments; | |
55 arguments.Add(&dst_start); | |
56 Exceptions::ThrowByType(Exceptions::kIndexOutOfRange, arguments); | |
57 } | |
58 ByteArray::Copy( | |
59 dst, dst_start.Value(), src, src_start.Value(), count.Value()); | |
60 } | |
61 | |
62 | |
33 static void RangeCheck(const ByteArray& array, const Smi& index, | 63 static void RangeCheck(const ByteArray& array, const Smi& index, |
34 intptr_t num_bytes) { | 64 intptr_t num_bytes) { |
35 if ((index.Value() < 0) || ((index.Value() + num_bytes) > array.Length())) { | 65 if ((index.Value() < 0) || ((index.Value() + num_bytes) > array.Length())) { |
36 GrowableArray<const Object*> arguments; | 66 GrowableArray<const Object*> arguments; |
37 arguments.Add(&index); | 67 arguments.Add(&index); |
38 Exceptions::ThrowByType(Exceptions::kIndexOutOfRange, arguments); | 68 Exceptions::ThrowByType(Exceptions::kIndexOutOfRange, arguments); |
39 } | 69 } |
40 } | 70 } |
41 | 71 |
42 | 72 |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
249 DEFINE_NATIVE_ENTRY(ExternalByteArray_getFloat64, 2) { | 279 DEFINE_NATIVE_ENTRY(ExternalByteArray_getFloat64, 2) { |
250 GETTER(ExternalByteArray, Double, double); | 280 GETTER(ExternalByteArray, Double, double); |
251 } | 281 } |
252 | 282 |
253 | 283 |
254 DEFINE_NATIVE_ENTRY(ExternalByteArray_setFloat64, 3) { | 284 DEFINE_NATIVE_ENTRY(ExternalByteArray_setFloat64, 3) { |
255 SETTER(ExternalByteArray, Double, value, double); | 285 SETTER(ExternalByteArray, Double, value, double); |
256 } | 286 } |
257 | 287 |
258 } // namespace dart | 288 } // namespace dart |
OLD | NEW |