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_copyFromByteArray, 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 intptr_t icount = count.Value(); | |
cshapiro
2012/01/27 23:00:04
I think the Value() calls are compiled away so you
Anders Johnsen
2012/01/27 23:42:39
Done.
| |
40 if (icount < 0) { | |
41 GrowableArray<const Object*> args; | |
42 Exceptions::ThrowByType(Exceptions::kIllegalArgument, args); | |
43 } | |
44 if (icount == 0) { | |
45 return; | |
46 } | |
47 intptr_t isrc_start = src_start.Value(); | |
48 intptr_t idst_start = dst_start.Value(); | |
49 if ((isrc_start < 0) || ((isrc_start + icount) > src.Length())) { | |
50 GrowableArray<const Object*> arguments; | |
51 arguments.Add(&src_start); | |
52 Exceptions::ThrowByType(Exceptions::kIndexOutOfRange, arguments); | |
53 } | |
54 if ((idst_start < 0) || ((idst_start + icount) > dst.Length())) { | |
55 GrowableArray<const Object*> arguments; | |
56 arguments.Add(&dst_start); | |
57 Exceptions::ThrowByType(Exceptions::kIndexOutOfRange, arguments); | |
58 } | |
59 ByteArray::Copy(dst, idst_start, src, isrc_start, icount); | |
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 |