OLD | NEW |
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" |
(...skipping 11 matching lines...) Expand all Loading... |
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 (%ld) must be in the range [0..%ld]", | 24 "length (%ld) must be in the range [0..%ld]", |
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::kIllegalArgument, args); | 28 Exceptions::ThrowByType(Exceptions::kIllegalArgument, 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 arguments->SetReturn(new_array); | 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->At(0)); |
38 GET_NATIVE_ARGUMENT(Smi, index, arguments->At(1)); | 38 GET_NATIVE_ARGUMENT(Smi, index, arguments->At(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::kIndexOutOfRange, arguments); | 42 Exceptions::ThrowByType(Exceptions::kIndexOutOfRange, arguments); |
43 } | 43 } |
44 const Instance& obj = Instance::CheckedHandle(array.At(index.Value())); | 44 return array.At(index.Value()); |
45 arguments->SetReturn(obj); | |
46 } | 45 } |
47 | 46 |
48 | 47 |
49 DEFINE_NATIVE_ENTRY(ObjectArray_setIndexed, 3) { | 48 DEFINE_NATIVE_ENTRY(ObjectArray_setIndexed, 3) { |
50 const Array& array = Array::CheckedHandle(arguments->At(0)); | 49 const Array& array = Array::CheckedHandle(arguments->At(0)); |
51 GET_NATIVE_ARGUMENT(Smi, index, arguments->At(1)); | 50 GET_NATIVE_ARGUMENT(Smi, index, arguments->At(1)); |
52 const Instance& value = Instance::CheckedHandle(arguments->At(2)); | 51 const Instance& value = Instance::CheckedHandle(arguments->At(2)); |
53 if ((index.Value() < 0) || (index.Value() >= array.Length())) { | 52 if ((index.Value() < 0) || (index.Value() >= array.Length())) { |
54 GrowableArray<const Object*> arguments; | 53 GrowableArray<const Object*> arguments; |
55 arguments.Add(&index); | 54 arguments.Add(&index); |
56 Exceptions::ThrowByType(Exceptions::kIndexOutOfRange, arguments); | 55 Exceptions::ThrowByType(Exceptions::kIndexOutOfRange, arguments); |
57 } | 56 } |
58 array.SetAt(index.Value(), value); | 57 array.SetAt(index.Value(), value); |
| 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->At(0)); |
64 const Smi& length = Smi::Handle(Smi::New(array.Length())); | 64 return Smi::New(array.Length()); |
65 arguments->SetReturn(length); | |
66 } | 65 } |
67 | 66 |
68 | 67 |
69 // ObjectArray src, int srcStart, int dstStart, int count. | 68 // ObjectArray src, int srcStart, int dstStart, int count. |
70 DEFINE_NATIVE_ENTRY(ObjectArray_copyFromObjectArray, 5) { | 69 DEFINE_NATIVE_ENTRY(ObjectArray_copyFromObjectArray, 5) { |
71 const Array& dest = Array::CheckedHandle(arguments->At(0)); | 70 const Array& dest = Array::CheckedHandle(arguments->At(0)); |
72 GET_NATIVE_ARGUMENT(Array, source, arguments->At(1)); | 71 GET_NATIVE_ARGUMENT(Array, source, arguments->At(1)); |
73 GET_NATIVE_ARGUMENT(Smi, src_start, arguments->At(2)); | 72 GET_NATIVE_ARGUMENT(Smi, src_start, arguments->At(2)); |
74 GET_NATIVE_ARGUMENT(Smi, dst_start, arguments->At(3)); | 73 GET_NATIVE_ARGUMENT(Smi, dst_start, arguments->At(3)); |
75 GET_NATIVE_ARGUMENT(Smi, count, arguments->At(4)); | 74 GET_NATIVE_ARGUMENT(Smi, count, arguments->At(4)); |
76 intptr_t icount = count.Value(); | 75 intptr_t icount = count.Value(); |
77 if (icount < 0) { | 76 if (icount < 0) { |
78 GrowableArray<const Object*> args; | 77 GrowableArray<const Object*> args; |
79 Exceptions::ThrowByType(Exceptions::kIllegalArgument, args); | 78 Exceptions::ThrowByType(Exceptions::kIllegalArgument, args); |
80 } | 79 } |
81 if (icount == 0) { | 80 if (icount == 0) { |
82 return; | 81 return Object::null(); |
83 } | 82 } |
84 intptr_t isrc_start = src_start.Value(); | 83 intptr_t isrc_start = src_start.Value(); |
85 intptr_t idst_start = dst_start.Value(); | 84 intptr_t idst_start = dst_start.Value(); |
86 if ((isrc_start < 0) || ((isrc_start + icount) > source.Length())) { | 85 if ((isrc_start < 0) || ((isrc_start + icount) > source.Length())) { |
87 GrowableArray<const Object*> arguments; | 86 GrowableArray<const Object*> arguments; |
88 arguments.Add(&src_start); | 87 arguments.Add(&src_start); |
89 Exceptions::ThrowByType(Exceptions::kIndexOutOfRange, arguments); | 88 Exceptions::ThrowByType(Exceptions::kIndexOutOfRange, arguments); |
90 } | 89 } |
91 if ((idst_start < 0) || ((idst_start + icount) > dest.Length())) { | 90 if ((idst_start < 0) || ((idst_start + icount) > dest.Length())) { |
92 GrowableArray<const Object*> arguments; | 91 GrowableArray<const Object*> arguments; |
93 arguments.Add(&dst_start); | 92 arguments.Add(&dst_start); |
94 Exceptions::ThrowByType(Exceptions::kIndexOutOfRange, arguments); | 93 Exceptions::ThrowByType(Exceptions::kIndexOutOfRange, arguments); |
95 } | 94 } |
96 | 95 |
97 Object& src_obj = Object::Handle(); | 96 Object& src_obj = Object::Handle(); |
98 if (isrc_start < idst_start) { | 97 if (isrc_start < idst_start) { |
99 for (intptr_t i = icount - 1; i >= 0; i--) { | 98 for (intptr_t i = icount - 1; i >= 0; i--) { |
100 src_obj = source.At(isrc_start + i); | 99 src_obj = source.At(isrc_start + i); |
101 dest.SetAt(idst_start + i, src_obj); | 100 dest.SetAt(idst_start + i, src_obj); |
102 } | 101 } |
103 } else { | 102 } else { |
104 for (intptr_t i = 0; i < icount; i++) { | 103 for (intptr_t i = 0; i < icount; i++) { |
105 src_obj = source.At(isrc_start + i); | 104 src_obj = source.At(isrc_start + i); |
106 dest.SetAt(idst_start + i, src_obj); | 105 dest.SetAt(idst_start + i, src_obj); |
107 } | 106 } |
108 } | 107 } |
| 108 return Object::null(); |
109 } | 109 } |
110 | 110 |
111 } // namespace dart | 111 } // namespace dart |
OLD | NEW |