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

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

Issue 11293290: Fix native argument handling (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 1 month 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/byte_array.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 #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->At(0)); 17 AbstractTypeArguments::CheckedHandle(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_NATIVE_ARGUMENT(Smi, length, arguments->At(1)); 20 GET_NATIVE_ARGUMENT(Smi, length, arguments->NativeArgAt(1));
21 intptr_t len = length.Value(); 21 intptr_t len = length.Value();
22 if (len < 0 || len > Array::kMaxElements) { 22 if (len < 0 || len > Array::kMaxElements) {
23 const String& error = String::Handle(String::NewFormatted( 23 const String& error = String::Handle(String::NewFormatted(
24 "length (%"Pd") must be in the range [0..%"Pd"]", 24 "length (%"Pd") must be in the range [0..%"Pd"]",
25 len, Array::kMaxElements)); 25 len, Array::kMaxElements));
26 GrowableArray<const Object*> args; 26 GrowableArray<const Object*> args;
27 args.Add(&error); 27 args.Add(&error);
28 Exceptions::ThrowByType(Exceptions::kArgument, args); 28 Exceptions::ThrowByType(Exceptions::kArgument, args);
29 } 29 }
30 const Array& new_array = Array::Handle(Array::New(length.Value())); 30 const Array& new_array = Array::Handle(Array::New(length.Value()));
31 new_array.SetTypeArguments(type_arguments); 31 new_array.SetTypeArguments(type_arguments);
32 return new_array.raw(); 32 return new_array.raw();
33 } 33 }
34 34
35 35
36 DEFINE_NATIVE_ENTRY(ObjectArray_getIndexed, 2) { 36 DEFINE_NATIVE_ENTRY(ObjectArray_getIndexed, 2) {
37 const Array& array = Array::CheckedHandle(arguments->At(0)); 37 const Array& array = Array::CheckedHandle(arguments->NativeArgAt(0));
38 GET_NATIVE_ARGUMENT(Smi, index, arguments->At(1)); 38 GET_NATIVE_ARGUMENT(Smi, index, arguments->NativeArgAt(1));
39 if ((index.Value() < 0) || (index.Value() >= array.Length())) { 39 if ((index.Value() < 0) || (index.Value() >= array.Length())) {
40 GrowableArray<const Object*> arguments; 40 GrowableArray<const Object*> arguments;
41 arguments.Add(&index); 41 arguments.Add(&index);
42 Exceptions::ThrowByType(Exceptions::kRange, arguments); 42 Exceptions::ThrowByType(Exceptions::kRange, arguments);
43 } 43 }
44 return array.At(index.Value()); 44 return array.At(index.Value());
45 } 45 }
46 46
47 47
48 DEFINE_NATIVE_ENTRY(ObjectArray_setIndexed, 3) { 48 DEFINE_NATIVE_ENTRY(ObjectArray_setIndexed, 3) {
49 const Array& array = Array::CheckedHandle(arguments->At(0)); 49 const Array& array = Array::CheckedHandle(arguments->NativeArgAt(0));
50 GET_NATIVE_ARGUMENT(Smi, index, arguments->At(1)); 50 GET_NATIVE_ARGUMENT(Smi, index, arguments->NativeArgAt(1));
51 const Instance& value = Instance::CheckedHandle(arguments->At(2)); 51 const Instance& value = Instance::CheckedHandle(arguments->NativeArgAt(2));
52 if ((index.Value() < 0) || (index.Value() >= array.Length())) { 52 if ((index.Value() < 0) || (index.Value() >= array.Length())) {
53 GrowableArray<const Object*> arguments; 53 GrowableArray<const Object*> arguments;
54 arguments.Add(&index); 54 arguments.Add(&index);
55 Exceptions::ThrowByType(Exceptions::kRange, arguments); 55 Exceptions::ThrowByType(Exceptions::kRange, arguments);
56 } 56 }
57 array.SetAt(index.Value(), value); 57 array.SetAt(index.Value(), value);
58 return Object::null(); 58 return Object::null();
59 } 59 }
60 60
61 61
62 DEFINE_NATIVE_ENTRY(ObjectArray_getLength, 1) { 62 DEFINE_NATIVE_ENTRY(ObjectArray_getLength, 1) {
63 const Array& array = Array::CheckedHandle(arguments->At(0)); 63 const Array& array = Array::CheckedHandle(arguments->NativeArgAt(0));
64 return Smi::New(array.Length()); 64 return Smi::New(array.Length());
65 } 65 }
66 66
67 67
68 // ObjectArray src, int srcStart, int dstStart, int count. 68 // ObjectArray src, int srcStart, int dstStart, int count.
69 DEFINE_NATIVE_ENTRY(ObjectArray_copyFromObjectArray, 5) { 69 DEFINE_NATIVE_ENTRY(ObjectArray_copyFromObjectArray, 5) {
70 const Array& dest = Array::CheckedHandle(arguments->At(0)); 70 const Array& dest = Array::CheckedHandle(arguments->NativeArgAt(0));
71 GET_NATIVE_ARGUMENT(Array, source, arguments->At(1)); 71 GET_NATIVE_ARGUMENT(Array, source, arguments->NativeArgAt(1));
72 GET_NATIVE_ARGUMENT(Smi, src_start, arguments->At(2)); 72 GET_NATIVE_ARGUMENT(Smi, src_start, arguments->NativeArgAt(2));
73 GET_NATIVE_ARGUMENT(Smi, dst_start, arguments->At(3)); 73 GET_NATIVE_ARGUMENT(Smi, dst_start, arguments->NativeArgAt(3));
74 GET_NATIVE_ARGUMENT(Smi, count, arguments->At(4)); 74 GET_NATIVE_ARGUMENT(Smi, count, arguments->NativeArgAt(4));
75 intptr_t icount = count.Value(); 75 intptr_t icount = count.Value();
76 if (icount < 0) { 76 if (icount < 0) {
77 GrowableArray<const Object*> args; 77 GrowableArray<const Object*> args;
78 Exceptions::ThrowByType(Exceptions::kArgument, args); 78 Exceptions::ThrowByType(Exceptions::kArgument, args);
79 } 79 }
80 if (icount == 0) { 80 if (icount == 0) {
81 return Object::null(); 81 return Object::null();
82 } 82 }
83 intptr_t isrc_start = src_start.Value(); 83 intptr_t isrc_start = src_start.Value();
84 intptr_t idst_start = dst_start.Value(); 84 intptr_t idst_start = dst_start.Value();
(...skipping 17 matching lines...) Expand all
102 } else { 102 } else {
103 for (intptr_t i = 0; i < icount; i++) { 103 for (intptr_t i = 0; i < icount; i++) {
104 src_obj = source.At(isrc_start + i); 104 src_obj = source.At(isrc_start + i);
105 dest.SetAt(idst_start + i, src_obj); 105 dest.SetAt(idst_start + i, src_obj);
106 } 106 }
107 } 107 }
108 return Object::null(); 108 return Object::null();
109 } 109 }
110 110
111 } // namespace dart 111 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | runtime/lib/byte_array.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698