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

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

Issue 12335146: - Do not use the ? operator in the List factory. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 9 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 | « no previous file | runtime/lib/array.dart » ('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 #include "vm/bootstrap_natives.h" 6 #include "vm/bootstrap_natives.h"
7 #include "vm/assembler.h" 7 #include "vm/assembler.h"
8 #include "vm/bigint_operations.h" 8 #include "vm/bigint_operations.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(ObjectArray_allocate, 2) { 15 DEFINE_NATIVE_ENTRY(ObjectArray_allocate, 2) {
16 const AbstractTypeArguments& type_arguments = 16 const AbstractTypeArguments& type_arguments =
17 AbstractTypeArguments::CheckedHandle(arguments->NativeArgAt(0)); 17 AbstractTypeArguments::CheckedHandle(isolate, arguments->NativeArgAt(0));
18 ASSERT(type_arguments.IsNull() || 18 ASSERT(type_arguments.IsNull() ||
19 (type_arguments.IsInstantiated() && (type_arguments.Length() == 1))); 19 (type_arguments.IsInstantiated() && (type_arguments.Length() == 1)));
20 GET_NON_NULL_NATIVE_ARGUMENT(Smi, length, arguments->NativeArgAt(1)); 20 const Instance& length = Instance::CheckedHandle(
21 intptr_t len = length.Value(); 21 isolate, arguments->NativeArgAt(1));
22 if (!length.IsSmi()) {
23 const String& error = String::Handle(String::NewFormatted(
24 "Length must be an integer in the range [0..%"Pd"].",
25 Array::kMaxElements));
26 const Array& args = Array::Handle(Array::New(1));
27 args.SetAt(0, error);
28 Exceptions::ThrowByType(Exceptions::kArgument, args);
29 }
30 intptr_t len = Smi::Cast(length).Value();
22 if (len < 0 || len > Array::kMaxElements) { 31 if (len < 0 || len > Array::kMaxElements) {
23 const String& error = String::Handle(String::NewFormatted( 32 const String& error = String::Handle(String::NewFormatted(
24 "length (%"Pd") must be in the range [0..%"Pd"]", 33 "Length (%"Pd") must be an integer in the range [0..%"Pd"].",
25 len, Array::kMaxElements)); 34 len, Array::kMaxElements));
26 const Array& args = Array::Handle(Array::New(1)); 35 const Array& args = Array::Handle(Array::New(1));
27 args.SetAt(0, error); 36 args.SetAt(0, error);
28 Exceptions::ThrowByType(Exceptions::kArgument, args); 37 Exceptions::ThrowByType(Exceptions::kArgument, args);
29 } 38 }
30 const Array& new_array = Array::Handle(Array::New(length.Value())); 39 const Array& new_array = Array::Handle(Array::New(len));
31 new_array.SetTypeArguments(type_arguments); 40 new_array.SetTypeArguments(type_arguments);
32 return new_array.raw(); 41 return new_array.raw();
33 } 42 }
34 43
35 44
36 DEFINE_NATIVE_ENTRY(ObjectArray_getIndexed, 2) { 45 DEFINE_NATIVE_ENTRY(ObjectArray_getIndexed, 2) {
37 const Array& array = Array::CheckedHandle(arguments->NativeArgAt(0)); 46 const Array& array = Array::CheckedHandle(arguments->NativeArgAt(0));
38 GET_NON_NULL_NATIVE_ARGUMENT(Smi, index, arguments->NativeArgAt(1)); 47 GET_NON_NULL_NATIVE_ARGUMENT(Smi, index, arguments->NativeArgAt(1));
39 if ((index.Value() < 0) || (index.Value() >= array.Length())) { 48 if ((index.Value() < 0) || (index.Value() >= array.Length())) {
40 const Array& args = Array::Handle(Array::New(1)); 49 const Array& args = Array::Handle(Array::New(1));
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 } else { 110 } else {
102 for (intptr_t i = 0; i < icount; i++) { 111 for (intptr_t i = 0; i < icount; i++) {
103 src_obj = source.At(isrc_start + i); 112 src_obj = source.At(isrc_start + i);
104 dest.SetAt(idst_start + i, src_obj); 113 dest.SetAt(idst_start + i, src_obj);
105 } 114 }
106 } 115 }
107 return Object::null(); 116 return Object::null();
108 } 117 }
109 118
110 } // namespace dart 119 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | runtime/lib/array.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698