Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(355)

Side by Side Diff: lib/byte_array.cc

Issue 11639007: Cleanup the exceptions create code to use Arrays instead GrowableArrays so (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « lib/array.cc ('k') | lib/date.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/bigint_operations.h" 7 #include "vm/bigint_operations.h"
8 #include "vm/exceptions.h" 8 #include "vm/exceptions.h"
9 #include "vm/native_entry.h" 9 #include "vm/native_entry.h"
10 #include "vm/object.h" 10 #include "vm/object.h"
11 11
12 namespace dart { 12 namespace dart {
13 13
14 // ByteArray 14 // ByteArray
15 15
16 // Checks to see if (index * num_bytes) is in the range 16 // Checks to see if (index * num_bytes) is in the range
17 // [0..array.ByteLength()). without the risk of integer overflow. If 17 // [0..array.ByteLength()). without the risk of integer overflow. If
18 // the index is out of range, then a RangeError is thrown. 18 // the index is out of range, then a RangeError is thrown.
19 static void RangeCheck(const ByteArray& array, 19 static void RangeCheck(const ByteArray& array,
20 intptr_t index, 20 intptr_t index,
21 intptr_t num_bytes) { 21 intptr_t num_bytes) {
22 if (!Utils::RangeCheck(index, num_bytes, array.ByteLength())) { 22 if (!Utils::RangeCheck(index, num_bytes, array.ByteLength())) {
23 const String& error = String::Handle(String::NewFormatted( 23 const String& error = String::Handle(String::NewFormatted(
24 "index (%"Pd") must be in the range [0..%"Pd")", 24 "index (%"Pd") must be in the range [0..%"Pd")",
25 index, (array.ByteLength() / num_bytes))); 25 index, (array.ByteLength() / num_bytes)));
26 GrowableArray<const Object*> args; 26 const Array& args = Array::Handle(Array::New(1));
27 args.Add(&error); 27 args.SetAt(0, error);
28 Exceptions::ThrowByType(Exceptions::kRange, args); 28 Exceptions::ThrowByType(Exceptions::kRange, args);
29 } 29 }
30 } 30 }
31 31
32 32
33 // Checks to see if a length is in the range [0..max]. If the length 33 // Checks to see if a length is in the range [0..max]. If the length
34 // is out of range, then an ArgumentError is thrown. 34 // is out of range, then an ArgumentError is thrown.
35 static void LengthCheck(intptr_t len, intptr_t max) { 35 static void LengthCheck(intptr_t len, intptr_t max) {
36 if (len < 0 || len > max) { 36 if (len < 0 || len > max) {
37 const String& error = String::Handle(String::NewFormatted( 37 const String& error = String::Handle(String::NewFormatted(
38 "length (%"Pd") must be in the range [0..%"Pd"]", len, max)); 38 "length (%"Pd") must be in the range [0..%"Pd"]", len, max));
39 GrowableArray<const Object*> args; 39 const Array& args = Array::Handle(Array::New(1));
40 args.Add(&error); 40 args.SetAt(0, error);
41 Exceptions::ThrowByType(Exceptions::kArgument, args); 41 Exceptions::ThrowByType(Exceptions::kArgument, args);
42 } 42 }
43 } 43 }
44 44
45 45
46 #define GETTER_ARGUMENTS(ArrayT, ValueT) \ 46 #define GETTER_ARGUMENTS(ArrayT, ValueT) \
47 GET_NON_NULL_NATIVE_ARGUMENT(ArrayT, array, arguments->NativeArgAt(0)); \ 47 GET_NON_NULL_NATIVE_ARGUMENT(ArrayT, array, arguments->NativeArgAt(0)); \
48 GET_NON_NULL_NATIVE_ARGUMENT(Smi, index, arguments->NativeArgAt(1)); 48 GET_NON_NULL_NATIVE_ARGUMENT(Smi, index, arguments->NativeArgAt(1));
49 49
50 50
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 GET_NON_NULL_NATIVE_ARGUMENT(Smi, dst_start, arguments->NativeArgAt(1)); 258 GET_NON_NULL_NATIVE_ARGUMENT(Smi, dst_start, arguments->NativeArgAt(1));
259 GET_NON_NULL_NATIVE_ARGUMENT(Smi, length, arguments->NativeArgAt(2)); 259 GET_NON_NULL_NATIVE_ARGUMENT(Smi, length, arguments->NativeArgAt(2));
260 GET_NON_NULL_NATIVE_ARGUMENT(ByteArray, src, arguments->NativeArgAt(3)); 260 GET_NON_NULL_NATIVE_ARGUMENT(ByteArray, src, arguments->NativeArgAt(3));
261 GET_NON_NULL_NATIVE_ARGUMENT(Smi, src_start, arguments->NativeArgAt(4)); 261 GET_NON_NULL_NATIVE_ARGUMENT(Smi, src_start, arguments->NativeArgAt(4));
262 intptr_t length_value = length.Value(); 262 intptr_t length_value = length.Value();
263 intptr_t src_start_value = src_start.Value(); 263 intptr_t src_start_value = src_start.Value();
264 intptr_t dst_start_value = dst_start.Value(); 264 intptr_t dst_start_value = dst_start.Value();
265 if (length_value < 0) { 265 if (length_value < 0) {
266 const String& error = String::Handle(String::NewFormatted( 266 const String& error = String::Handle(String::NewFormatted(
267 "length (%"Pd") must be non-negative", length_value)); 267 "length (%"Pd") must be non-negative", length_value));
268 GrowableArray<const Object*> args; 268 const Array& args = Array::Handle(Array::New(1));
269 args.Add(&error); 269 args.SetAt(0, error);
270 Exceptions::ThrowByType(Exceptions::kArgument, args); 270 Exceptions::ThrowByType(Exceptions::kArgument, args);
271 } 271 }
272 RangeCheck(src, src_start_value, length_value); 272 RangeCheck(src, src_start_value, length_value);
273 RangeCheck(dst, dst_start_value, length_value); 273 RangeCheck(dst, dst_start_value, length_value);
274 ByteArray::Copy(dst, dst_start_value, src, src_start_value, length_value); 274 ByteArray::Copy(dst, dst_start_value, src, src_start_value, length_value);
275 return Object::null(); 275 return Object::null();
276 } 276 }
277 277
278 278
279 // Int8Array 279 // Int8Array
(...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after
763 DEFINE_NATIVE_ENTRY(ExternalFloat64Array_getIndexed, 2) { 763 DEFINE_NATIVE_ENTRY(ExternalFloat64Array_getIndexed, 2) {
764 GETTER(ExternalFloat64Array, Double, double); 764 GETTER(ExternalFloat64Array, Double, double);
765 } 765 }
766 766
767 767
768 DEFINE_NATIVE_ENTRY(ExternalFloat64Array_setIndexed, 3) { 768 DEFINE_NATIVE_ENTRY(ExternalFloat64Array_setIndexed, 3) {
769 SETTER(ExternalFloat64Array, Double, value, double); 769 SETTER(ExternalFloat64Array, Double, value, double);
770 } 770 }
771 771
772 } // namespace dart 772 } // namespace dart
OLDNEW
« no previous file with comments | « lib/array.cc ('k') | lib/date.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698