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

Side by Side Diff: runtime/lib/growable_array.cc

Issue 533483003: Cleanup throwing of the RangeError in the runtime to remove duplicated code. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 3 months 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 | « runtime/lib/array.cc ('k') | runtime/lib/simd128.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 "platform/assert.h" 5 #include "platform/assert.h"
6 6
7 #include "vm/assembler.h" 7 #include "vm/assembler.h"
8 #include "vm/bootstrap_natives.h" 8 #include "vm/bootstrap_natives.h"
9 #include "vm/exceptions.h" 9 #include "vm/exceptions.h"
10 #include "vm/native_entry.h" 10 #include "vm/native_entry.h"
11 #include "vm/object.h" 11 #include "vm/object.h"
12 12
13 namespace dart { 13 namespace dart {
14 14
15 DEFINE_NATIVE_ENTRY(GrowableList_allocate, 2) { 15 DEFINE_NATIVE_ENTRY(GrowableList_allocate, 2) {
16 const TypeArguments& type_arguments = 16 const TypeArguments& type_arguments =
17 TypeArguments::CheckedHandle(arguments->NativeArgAt(0)); 17 TypeArguments::CheckedHandle(arguments->NativeArgAt(0));
18 GET_NON_NULL_NATIVE_ARGUMENT(Array, data, arguments->NativeArgAt(1)); 18 GET_NON_NULL_NATIVE_ARGUMENT(Array, data, arguments->NativeArgAt(1));
19 if ((data.Length() <= 0)) { 19 if (data.Length() <= 0) {
20 const Integer& index = Integer::Handle(Integer::New(data.Length())); 20 Exceptions::ThrowRangeError(
21 const Array& args = Array::Handle(Array::New(1)); 21 "length",
22 args.SetAt(0, index); 22 Integer::Handle(Integer::New(data.Length())),
23 Exceptions::ThrowByType(Exceptions::kRange, args); 23 1,
24 Array::kMaxElements);
24 } 25 }
25 const GrowableObjectArray& new_array = 26 const GrowableObjectArray& new_array =
26 GrowableObjectArray::Handle(GrowableObjectArray::New(data)); 27 GrowableObjectArray::Handle(GrowableObjectArray::New(data));
27 new_array.SetTypeArguments(type_arguments); 28 new_array.SetTypeArguments(type_arguments);
28 return new_array.raw(); 29 return new_array.raw();
29 } 30 }
30 31
31 32
32 DEFINE_NATIVE_ENTRY(GrowableList_getIndexed, 2) { 33 DEFINE_NATIVE_ENTRY(GrowableList_getIndexed, 2) {
33 const GrowableObjectArray& array = 34 const GrowableObjectArray& array =
34 GrowableObjectArray::CheckedHandle(arguments->NativeArgAt(0)); 35 GrowableObjectArray::CheckedHandle(arguments->NativeArgAt(0));
35 GET_NON_NULL_NATIVE_ARGUMENT(Smi, index, arguments->NativeArgAt(1)); 36 GET_NON_NULL_NATIVE_ARGUMENT(Smi, index, arguments->NativeArgAt(1));
36 if ((index.Value() < 0) || (index.Value() >= array.Length())) { 37 if ((index.Value() < 0) || (index.Value() >= array.Length())) {
37 const Array& args = Array::Handle(Array::New(1)); 38 Exceptions::ThrowRangeError("index", index, 0, array.Length());
38 args.SetAt(0, index);
39 Exceptions::ThrowByType(Exceptions::kRange, args);
40 } 39 }
41 const Instance& obj = Instance::CheckedHandle(array.At(index.Value())); 40 const Instance& obj = Instance::CheckedHandle(array.At(index.Value()));
42 return obj.raw(); 41 return obj.raw();
43 } 42 }
44 43
45 44
46 DEFINE_NATIVE_ENTRY(GrowableList_setIndexed, 3) { 45 DEFINE_NATIVE_ENTRY(GrowableList_setIndexed, 3) {
47 const GrowableObjectArray& array = 46 const GrowableObjectArray& array =
48 GrowableObjectArray::CheckedHandle(arguments->NativeArgAt(0)); 47 GrowableObjectArray::CheckedHandle(arguments->NativeArgAt(0));
49 GET_NON_NULL_NATIVE_ARGUMENT(Smi, index, arguments->NativeArgAt(1)); 48 GET_NON_NULL_NATIVE_ARGUMENT(Smi, index, arguments->NativeArgAt(1));
50 if ((index.Value() < 0) || (index.Value() >= array.Length())) { 49 if ((index.Value() < 0) || (index.Value() >= array.Length())) {
51 const Array& args = Array::Handle(Array::New(1)); 50 Exceptions::ThrowRangeError("index", index, 0, array.Length());
52 args.SetAt(0, index);
53 Exceptions::ThrowByType(Exceptions::kRange, args);
54 } 51 }
55 GET_NON_NULL_NATIVE_ARGUMENT(Instance, value, arguments->NativeArgAt(2)); 52 GET_NON_NULL_NATIVE_ARGUMENT(Instance, value, arguments->NativeArgAt(2));
56 array.SetAt(index.Value(), value); 53 array.SetAt(index.Value(), value);
57 return Object::null(); 54 return Object::null();
58 } 55 }
59 56
60 57
61 DEFINE_NATIVE_ENTRY(GrowableList_getLength, 1) { 58 DEFINE_NATIVE_ENTRY(GrowableList_getLength, 1) {
62 const GrowableObjectArray& array = 59 const GrowableObjectArray& array =
63 GrowableObjectArray::CheckedHandle(arguments->NativeArgAt(0)); 60 GrowableObjectArray::CheckedHandle(arguments->NativeArgAt(0));
(...skipping 28 matching lines...) Expand all
92 } 89 }
93 90
94 91
95 DEFINE_NATIVE_ENTRY(Internal_makeListFixedLength, 1) { 92 DEFINE_NATIVE_ENTRY(Internal_makeListFixedLength, 1) {
96 GET_NON_NULL_NATIVE_ARGUMENT(GrowableObjectArray, array, 93 GET_NON_NULL_NATIVE_ARGUMENT(GrowableObjectArray, array,
97 arguments->NativeArgAt(0)); 94 arguments->NativeArgAt(0));
98 return Array::MakeArray(array); 95 return Array::MakeArray(array);
99 } 96 }
100 97
101 } // namespace dart 98 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/lib/array.cc ('k') | runtime/lib/simd128.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698