| 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 return Object::null(); | 44 return Object::null(); |
| 45 } | 45 } |
| 46 | 46 |
| 47 | 47 |
| 48 DEFINE_NATIVE_ENTRY(List_getLength, 1) { | 48 DEFINE_NATIVE_ENTRY(List_getLength, 1) { |
| 49 const Array& array = Array::CheckedHandle(arguments->NativeArgAt(0)); | 49 const Array& array = Array::CheckedHandle(arguments->NativeArgAt(0)); |
| 50 return Smi::New(array.Length()); | 50 return Smi::New(array.Length()); |
| 51 } | 51 } |
| 52 | 52 |
| 53 | 53 |
| 54 // ObjectArray src, int srcStart, int dstStart, int count. | 54 // ObjectArray src, int start, int count, bool needTypeArgument. |
| 55 DEFINE_NATIVE_ENTRY(List_copyFromObjectArray, 5) { | 55 DEFINE_NATIVE_ENTRY(List_slice, 4) { |
| 56 const Array& dest = Array::CheckedHandle(arguments->NativeArgAt(0)); | 56 const Array& src = Array::CheckedHandle(arguments->NativeArgAt(0)); |
| 57 GET_NON_NULL_NATIVE_ARGUMENT(Array, source, arguments->NativeArgAt(1)); | 57 GET_NON_NULL_NATIVE_ARGUMENT(Smi, start, arguments->NativeArgAt(1)); |
| 58 GET_NON_NULL_NATIVE_ARGUMENT(Smi, src_start, arguments->NativeArgAt(2)); | 58 GET_NON_NULL_NATIVE_ARGUMENT(Smi, count, arguments->NativeArgAt(2)); |
| 59 GET_NON_NULL_NATIVE_ARGUMENT(Smi, dst_start, arguments->NativeArgAt(3)); | 59 GET_NON_NULL_NATIVE_ARGUMENT(Bool, needs_type_arg, arguments->NativeArgAt(3)); |
| 60 GET_NON_NULL_NATIVE_ARGUMENT(Smi, count, arguments->NativeArgAt(4)); | |
| 61 intptr_t icount = count.Value(); | 60 intptr_t icount = count.Value(); |
| 62 if (icount < 0) { | 61 // Zero count should be handled outside already. |
| 62 if ((icount <= 0) || (icount >= Array::kMaxElements)) { |
| 63 Exceptions::ThrowByType(Exceptions::kArgument, Object::empty_array()); | 63 Exceptions::ThrowByType(Exceptions::kArgument, Object::empty_array()); |
| 64 } | 64 } |
| 65 if (icount == 0) { | 65 intptr_t istart = start.Value(); |
| 66 return Object::null(); | 66 if ((istart < 0) || ((istart + icount) > src.Length())) { |
| 67 } | |
| 68 intptr_t isrc_start = src_start.Value(); | |
| 69 intptr_t idst_start = dst_start.Value(); | |
| 70 if ((isrc_start < 0) || ((isrc_start + icount) > source.Length())) { | |
| 71 const Array& args = Array::Handle(Array::New(1)); | 67 const Array& args = Array::Handle(Array::New(1)); |
| 72 args.SetAt(0, src_start); | 68 args.SetAt(0, start); |
| 73 Exceptions::ThrowByType(Exceptions::kRange, args); | |
| 74 } | |
| 75 if ((idst_start < 0) || ((idst_start + icount) > dest.Length())) { | |
| 76 const Array& args = Array::Handle(Array::New(1)); | |
| 77 args.SetAt(0, dst_start); | |
| 78 Exceptions::ThrowByType(Exceptions::kRange, args); | 69 Exceptions::ThrowByType(Exceptions::kRange, args); |
| 79 } | 70 } |
| 80 | 71 |
| 81 Object& src_obj = Object::Handle(); | 72 return src.Slice(istart, icount, needs_type_arg.value()); |
| 82 if (isrc_start < idst_start) { | |
| 83 for (intptr_t i = icount - 1; i >= 0; i--) { | |
| 84 src_obj = source.At(isrc_start + i); | |
| 85 dest.SetAt(idst_start + i, src_obj); | |
| 86 } | |
| 87 } else { | |
| 88 for (intptr_t i = 0; i < icount; i++) { | |
| 89 src_obj = source.At(isrc_start + i); | |
| 90 dest.SetAt(idst_start + i, src_obj); | |
| 91 } | |
| 92 } | |
| 93 return Object::null(); | |
| 94 } | 73 } |
| 95 | 74 |
| 96 | 75 |
| 97 // Private factory, expects correct arguments. | 76 // Private factory, expects correct arguments. |
| 98 DEFINE_NATIVE_ENTRY(ImmutableList_from, 4) { | 77 DEFINE_NATIVE_ENTRY(ImmutableList_from, 4) { |
| 99 // Ignore first argument of a thsi factory (type argument). | 78 // Ignore first argument of a thsi factory (type argument). |
| 100 const Array& from_array = Array::CheckedHandle(arguments->NativeArgAt(1)); | 79 const Array& from_array = Array::CheckedHandle(arguments->NativeArgAt(1)); |
| 101 const Smi& smi_offset = Smi::CheckedHandle(arguments->NativeArgAt(2)); | 80 const Smi& smi_offset = Smi::CheckedHandle(arguments->NativeArgAt(2)); |
| 102 const Smi& smi_length = Smi::CheckedHandle(arguments->NativeArgAt(3)); | 81 const Smi& smi_length = Smi::CheckedHandle(arguments->NativeArgAt(3)); |
| 103 const intptr_t length = smi_length.Value(); | 82 const intptr_t length = smi_length.Value(); |
| 104 const intptr_t offset = smi_offset.Value(); | 83 const intptr_t offset = smi_offset.Value(); |
| 105 const Array& result = Array::Handle(Array::New(length)); | 84 const Array& result = Array::Handle(Array::New(length)); |
| 106 Object& temp = Object::Handle(); | 85 Object& temp = Object::Handle(); |
| 107 for (intptr_t i = 0; i < length; i++) { | 86 for (intptr_t i = 0; i < length; i++) { |
| 108 temp = from_array.At(i + offset); | 87 temp = from_array.At(i + offset); |
| 109 result.SetAt(i, temp); | 88 result.SetAt(i, temp); |
| 110 } | 89 } |
| 111 result.MakeImmutable(); | 90 result.MakeImmutable(); |
| 112 return result.raw(); | 91 return result.raw(); |
| 113 } | 92 } |
| 114 | 93 |
| 115 } // namespace dart | 94 } // namespace dart |
| OLD | NEW |