| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 "vm/bootstrap_natives.h" | 5 #include "vm/bootstrap_natives.h" |
| 6 | 6 |
| 7 #include "vm/assembler.h" | 7 #include "vm/assembler.h" |
| 8 #include "vm/assert.h" | 8 #include "vm/assert.h" |
| 9 #include "vm/bigint_operations.h" | 9 #include "vm/bigint_operations.h" |
| 10 #include "vm/exceptions.h" | 10 #include "vm/exceptions.h" |
| 11 #include "vm/native_entry.h" | 11 #include "vm/native_entry.h" |
| 12 #include "vm/object.h" | 12 #include "vm/object.h" |
| 13 | 13 |
| 14 namespace dart { | 14 namespace dart { |
| 15 | 15 |
| 16 DEFINE_NATIVE_ENTRY(ObjectArray_allocate, 2) { | 16 DEFINE_NATIVE_ENTRY(ObjectArray_allocate, 2) { |
| 17 const TypeArguments& type_arguments = | 17 const TypeArguments& type_arguments = |
| 18 TypeArguments::CheckedHandle(arguments->At(0)); | 18 TypeArguments::CheckedHandle(arguments->At(0)); |
| 19 const Instance& length_instance = Instance::CheckedHandle(arguments->At(1)); | |
| 20 if (!length_instance.IsSmi()) { | |
| 21 GrowableArray<const Object*> args; | |
| 22 args.Add(&length_instance); | |
| 23 Exceptions::ThrowByType(Exceptions::kIllegalArgument, args); | |
| 24 } | |
| 25 Smi& length = Smi::Handle(); | |
| 26 length ^= length_instance.raw(); | |
| 27 ASSERT(type_arguments.IsNull() || | 19 ASSERT(type_arguments.IsNull() || |
| 28 (type_arguments.IsInstantiated() && (type_arguments.Length() == 1))); | 20 (type_arguments.IsInstantiated() && (type_arguments.Length() == 1))); |
| 29 if (length.IsNull() || (length.Value() < 0)) { | 21 GET_NATIVE_ARGUMENT(Smi, length, arguments->At(1)); |
| 22 if (length.Value() < 0) { |
| 30 GrowableArray<const Object*> args; | 23 GrowableArray<const Object*> args; |
| 31 args.Add(&length); | 24 args.Add(&length); |
| 32 Exceptions::ThrowByType(Exceptions::kIllegalArgument, args); | 25 Exceptions::ThrowByType(Exceptions::kIllegalArgument, args); |
| 33 } | 26 } |
| 34 const Array& new_array = Array::Handle(Array::New(length.Value())); | 27 const Array& new_array = Array::Handle(Array::New(length.Value())); |
| 35 new_array.SetTypeArguments(type_arguments); | 28 new_array.SetTypeArguments(type_arguments); |
| 36 arguments->SetReturn(new_array); | 29 arguments->SetReturn(new_array); |
| 37 } | 30 } |
| 38 | 31 |
| 39 | 32 |
| 40 DEFINE_NATIVE_ENTRY(ObjectArray_getIndexed, 2) { | 33 DEFINE_NATIVE_ENTRY(ObjectArray_getIndexed, 2) { |
| 41 const Array& array = Array::CheckedHandle(arguments->At(0)); | 34 const Array& array = Array::CheckedHandle(arguments->At(0)); |
| 42 const Instance& index_instance = Instance::CheckedHandle(arguments->At(1)); | 35 GET_NATIVE_ARGUMENT(Smi, index, arguments->At(1)); |
| 43 if (!index_instance.IsSmi()) { | |
| 44 GrowableArray<const Object*> args; | |
| 45 args.Add(&index_instance); | |
| 46 Exceptions::ThrowByType(Exceptions::kIllegalArgument, args); | |
| 47 } | |
| 48 Smi& index = Smi::Handle(); | |
| 49 index ^= index_instance.raw(); | |
| 50 if (array.IsNull() || index.IsNull()) { | |
| 51 // TODO(asiva): Need to handle error cases. | |
| 52 UNIMPLEMENTED(); | |
| 53 return; | |
| 54 } | |
| 55 if ((index.Value() < 0) || (index.Value() >= array.Length())) { | 36 if ((index.Value() < 0) || (index.Value() >= array.Length())) { |
| 56 GrowableArray<const Object*> arguments; | 37 GrowableArray<const Object*> arguments; |
| 57 arguments.Add(&index); | 38 arguments.Add(&index); |
| 58 Exceptions::ThrowByType(Exceptions::kIndexOutOfRange, arguments); | 39 Exceptions::ThrowByType(Exceptions::kIndexOutOfRange, arguments); |
| 59 } | 40 } |
| 60 const Instance& obj = Instance::CheckedHandle(array.At(index.Value())); | 41 const Instance& obj = Instance::CheckedHandle(array.At(index.Value())); |
| 61 arguments->SetReturn(obj); | 42 arguments->SetReturn(obj); |
| 62 } | 43 } |
| 63 | 44 |
| 64 | 45 |
| 65 DEFINE_NATIVE_ENTRY(ObjectArray_setIndexed, 3) { | 46 DEFINE_NATIVE_ENTRY(ObjectArray_setIndexed, 3) { |
| 66 const Array& array = Array::CheckedHandle(arguments->At(0)); | 47 const Array& array = Array::CheckedHandle(arguments->At(0)); |
| 67 const Instance& index_instance = Instance::CheckedHandle(arguments->At(1)); | 48 GET_NATIVE_ARGUMENT(Smi, index, arguments->At(1)); |
| 68 if (!index_instance.IsSmi()) { | |
| 69 GrowableArray<const Object*> args; | |
| 70 args.Add(&index_instance); | |
| 71 Exceptions::ThrowByType(Exceptions::kIllegalArgument, args); | |
| 72 } | |
| 73 Smi& index = Smi::Handle(); | |
| 74 index ^= index_instance.raw(); | |
| 75 const Instance& value = Instance::CheckedHandle(arguments->At(2)); | 49 const Instance& value = Instance::CheckedHandle(arguments->At(2)); |
| 76 if (array.IsNull() || index.IsNull()) { | |
| 77 // TODO(asiva): Need to handle error cases. | |
| 78 UNIMPLEMENTED(); | |
| 79 return; | |
| 80 } | |
| 81 if ((index.Value() < 0) || (index.Value() >= array.Length())) { | 50 if ((index.Value() < 0) || (index.Value() >= array.Length())) { |
| 82 GrowableArray<const Object*> arguments; | 51 GrowableArray<const Object*> arguments; |
| 83 arguments.Add(&index); | 52 arguments.Add(&index); |
| 84 Exceptions::ThrowByType(Exceptions::kIndexOutOfRange, arguments); | 53 Exceptions::ThrowByType(Exceptions::kIndexOutOfRange, arguments); |
| 85 } | 54 } |
| 86 array.SetAt(index.Value(), value); | 55 array.SetAt(index.Value(), value); |
| 87 } | 56 } |
| 88 | 57 |
| 89 | 58 |
| 90 DEFINE_NATIVE_ENTRY(ObjectArray_getLength, 1) { | 59 DEFINE_NATIVE_ENTRY(ObjectArray_getLength, 1) { |
| 91 const Array& array = Array::CheckedHandle(arguments->At(0)); | 60 const Array& array = Array::CheckedHandle(arguments->At(0)); |
| 92 if (array.IsNull()) { | |
| 93 // TODO(asiva): Need to handle error cases. | |
| 94 UNIMPLEMENTED(); | |
| 95 return; | |
| 96 } | |
| 97 const Smi& length = Smi::Handle(Smi::New(array.Length())); | 61 const Smi& length = Smi::Handle(Smi::New(array.Length())); |
| 98 arguments->SetReturn(length); | 62 arguments->SetReturn(length); |
| 99 } | 63 } |
| 100 | 64 |
| 101 | 65 |
| 102 // ObjectArray src, int srcStart, int dstStart, int count. | 66 // ObjectArray src, int srcStart, int dstStart, int count. |
| 103 DEFINE_NATIVE_ENTRY(ObjectArray_copyFromObjectArray, 5) { | 67 DEFINE_NATIVE_ENTRY(ObjectArray_copyFromObjectArray, 5) { |
| 104 const Array& dest = Array::CheckedHandle(arguments->At(0)); | 68 const Array& dest = Array::CheckedHandle(arguments->At(0)); |
| 105 const Array& source = Array::CheckedHandle(arguments->At(1)); | 69 GET_NATIVE_ARGUMENT(Array, source, arguments->At(1)); |
| 106 const Smi& src_start = Smi::CheckedHandle(arguments->At(2)); | 70 GET_NATIVE_ARGUMENT(Smi, src_start, arguments->At(2)); |
| 107 const Smi& dst_start = Smi::CheckedHandle(arguments->At(3)); | 71 GET_NATIVE_ARGUMENT(Smi, dst_start, arguments->At(3)); |
| 108 const Smi& count = Smi::CheckedHandle(arguments->At(4)); | 72 GET_NATIVE_ARGUMENT(Smi, count, arguments->At(4)); |
| 109 if (dest.IsNull() || source.IsNull() || src_start.IsNull() || | |
| 110 dst_start.IsNull() || count.IsNull()) { | |
| 111 GrowableArray<const Object*> args; | |
| 112 Exceptions::ThrowByType(Exceptions::kIllegalArgument, args); | |
| 113 } | |
| 114 intptr_t icount = count.Value(); | 73 intptr_t icount = count.Value(); |
| 115 if (icount < 0) { | 74 if (icount < 0) { |
| 116 GrowableArray<const Object*> args; | 75 GrowableArray<const Object*> args; |
| 117 Exceptions::ThrowByType(Exceptions::kIllegalArgument, args); | 76 Exceptions::ThrowByType(Exceptions::kIllegalArgument, args); |
| 118 } | 77 } |
| 119 if (icount == 0) { | 78 if (icount == 0) { |
| 120 return; | 79 return; |
| 121 } | 80 } |
| 122 intptr_t isrc_start = src_start.Value(); | 81 intptr_t isrc_start = src_start.Value(); |
| 123 intptr_t idst_start = dst_start.Value(); | 82 intptr_t idst_start = dst_start.Value(); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 140 } | 99 } |
| 141 } else { | 100 } else { |
| 142 for (intptr_t i = 0; i < icount; i++) { | 101 for (intptr_t i = 0; i < icount; i++) { |
| 143 src_obj = source.At(isrc_start + i); | 102 src_obj = source.At(isrc_start + i); |
| 144 dest.SetAt(idst_start + i, src_obj); | 103 dest.SetAt(idst_start + i, src_obj); |
| 145 } | 104 } |
| 146 } | 105 } |
| 147 } | 106 } |
| 148 | 107 |
| 149 } // namespace dart | 108 } // namespace dart |
| OLD | NEW |