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

Side by Side Diff: runtime/lib/growable_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 | « runtime/lib/error.cc ('k') | runtime/lib/integers.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(GrowableObjectArray_allocate, 2) { 15 DEFINE_NATIVE_ENTRY(GrowableObjectArray_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(Array, data, arguments->At(1)); 20 GET_NATIVE_ARGUMENT(Array, data, arguments->NativeArgAt(1));
21 if ((data.Length() <= 0)) { 21 if ((data.Length() <= 0)) {
22 const Integer& index = Integer::Handle(Integer::New(data.Length())); 22 const Integer& index = Integer::Handle(Integer::New(data.Length()));
23 GrowableArray<const Object*> args; 23 GrowableArray<const Object*> args;
24 args.Add(&index); 24 args.Add(&index);
25 Exceptions::ThrowByType(Exceptions::kRange, args); 25 Exceptions::ThrowByType(Exceptions::kRange, args);
26 } 26 }
27 const GrowableObjectArray& new_array = 27 const GrowableObjectArray& new_array =
28 GrowableObjectArray::Handle(GrowableObjectArray::New(data)); 28 GrowableObjectArray::Handle(GrowableObjectArray::New(data));
29 new_array.SetTypeArguments(type_arguments); 29 new_array.SetTypeArguments(type_arguments);
30 return new_array.raw(); 30 return new_array.raw();
31 } 31 }
32 32
33 33
34 DEFINE_NATIVE_ENTRY(GrowableObjectArray_getIndexed, 2) { 34 DEFINE_NATIVE_ENTRY(GrowableObjectArray_getIndexed, 2) {
35 const GrowableObjectArray& array = 35 const GrowableObjectArray& array =
36 GrowableObjectArray::CheckedHandle(arguments->At(0)); 36 GrowableObjectArray::CheckedHandle(arguments->NativeArgAt(0));
37 GET_NATIVE_ARGUMENT(Smi, index, arguments->At(1)); 37 GET_NATIVE_ARGUMENT(Smi, index, arguments->NativeArgAt(1));
38 if ((index.Value() < 0) || (index.Value() >= array.Length())) { 38 if ((index.Value() < 0) || (index.Value() >= array.Length())) {
39 GrowableArray<const Object*> args; 39 GrowableArray<const Object*> args;
40 args.Add(&index); 40 args.Add(&index);
41 Exceptions::ThrowByType(Exceptions::kRange, args); 41 Exceptions::ThrowByType(Exceptions::kRange, args);
42 } 42 }
43 const Instance& obj = Instance::CheckedHandle(array.At(index.Value())); 43 const Instance& obj = Instance::CheckedHandle(array.At(index.Value()));
44 return obj.raw(); 44 return obj.raw();
45 } 45 }
46 46
47 47
48 DEFINE_NATIVE_ENTRY(GrowableObjectArray_setIndexed, 3) { 48 DEFINE_NATIVE_ENTRY(GrowableObjectArray_setIndexed, 3) {
49 const GrowableObjectArray& array = 49 const GrowableObjectArray& array =
50 GrowableObjectArray::CheckedHandle(arguments->At(0)); 50 GrowableObjectArray::CheckedHandle(arguments->NativeArgAt(0));
51 GET_NATIVE_ARGUMENT(Smi, index, arguments->At(1)); 51 GET_NATIVE_ARGUMENT(Smi, index, arguments->NativeArgAt(1));
52 if ((index.Value() < 0) || (index.Value() >= array.Length())) { 52 if ((index.Value() < 0) || (index.Value() >= array.Length())) {
53 GrowableArray<const Object*> args; 53 GrowableArray<const Object*> args;
54 args.Add(&index); 54 args.Add(&index);
55 Exceptions::ThrowByType(Exceptions::kRange, args); 55 Exceptions::ThrowByType(Exceptions::kRange, args);
56 } 56 }
57 GET_NATIVE_ARGUMENT(Instance, value, arguments->At(2)); 57 GET_NATIVE_ARGUMENT(Instance, value, arguments->NativeArgAt(2));
58 array.SetAt(index.Value(), value); 58 array.SetAt(index.Value(), value);
59 return Object::null(); 59 return Object::null();
60 } 60 }
61 61
62 62
63 DEFINE_NATIVE_ENTRY(GrowableObjectArray_getLength, 1) { 63 DEFINE_NATIVE_ENTRY(GrowableObjectArray_getLength, 1) {
64 const GrowableObjectArray& array = 64 const GrowableObjectArray& array =
65 GrowableObjectArray::CheckedHandle(arguments->At(0)); 65 GrowableObjectArray::CheckedHandle(arguments->NativeArgAt(0));
66 return Smi::New(array.Length()); 66 return Smi::New(array.Length());
67 } 67 }
68 68
69 69
70 DEFINE_NATIVE_ENTRY(GrowableObjectArray_getCapacity, 1) { 70 DEFINE_NATIVE_ENTRY(GrowableObjectArray_getCapacity, 1) {
71 const GrowableObjectArray& array = 71 const GrowableObjectArray& array =
72 GrowableObjectArray::CheckedHandle(arguments->At(0)); 72 GrowableObjectArray::CheckedHandle(arguments->NativeArgAt(0));
73 return Smi::New(array.Capacity()); 73 return Smi::New(array.Capacity());
74 } 74 }
75 75
76 76
77 DEFINE_NATIVE_ENTRY(GrowableObjectArray_setLength, 2) { 77 DEFINE_NATIVE_ENTRY(GrowableObjectArray_setLength, 2) {
78 const GrowableObjectArray& array = 78 const GrowableObjectArray& array =
79 GrowableObjectArray::CheckedHandle(arguments->At(0)); 79 GrowableObjectArray::CheckedHandle(arguments->NativeArgAt(0));
80 GET_NATIVE_ARGUMENT(Smi, length, arguments->At(1)); 80 GET_NATIVE_ARGUMENT(Smi, length, arguments->NativeArgAt(1));
81 if ((length.Value() < 0) || (length.Value() > array.Capacity())) { 81 if ((length.Value() < 0) || (length.Value() > array.Capacity())) {
82 GrowableArray<const Object*> args; 82 GrowableArray<const Object*> args;
83 args.Add(&length); 83 args.Add(&length);
84 Exceptions::ThrowByType(Exceptions::kRange, args); 84 Exceptions::ThrowByType(Exceptions::kRange, args);
85 } 85 }
86 array.SetLength(length.Value()); 86 array.SetLength(length.Value());
87 return Object::null(); 87 return Object::null();
88 } 88 }
89 89
90 90
91 DEFINE_NATIVE_ENTRY(GrowableObjectArray_setData, 2) { 91 DEFINE_NATIVE_ENTRY(GrowableObjectArray_setData, 2) {
92 const GrowableObjectArray& array = 92 const GrowableObjectArray& array =
93 GrowableObjectArray::CheckedHandle(arguments->At(0)); 93 GrowableObjectArray::CheckedHandle(arguments->NativeArgAt(0));
94 GET_NATIVE_ARGUMENT(Array, data, arguments->At(1)); 94 GET_NATIVE_ARGUMENT(Array, data, arguments->NativeArgAt(1));
95 ASSERT(data.Length() > 0); 95 ASSERT(data.Length() > 0);
96 array.SetData(data); 96 array.SetData(data);
97 return Object::null(); 97 return Object::null();
98 } 98 }
99 99
100 } // namespace dart 100 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/lib/error.cc ('k') | runtime/lib/integers.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698