| 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/exceptions.h" | 8 #include "vm/exceptions.h" |
| 9 #include "vm/native_entry.h" | 9 #include "vm/native_entry.h" |
| 10 #include "vm/object.h" | 10 #include "vm/object.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 | 47 |
| 48 | 48 |
| 49 // ObjectArray src, int start, int count, bool needTypeArgument. | 49 // ObjectArray src, int start, int count, bool needTypeArgument. |
| 50 DEFINE_NATIVE_ENTRY(List_slice, 4) { | 50 DEFINE_NATIVE_ENTRY(List_slice, 4) { |
| 51 const Array& src = Array::CheckedHandle(arguments->NativeArgAt(0)); | 51 const Array& src = Array::CheckedHandle(arguments->NativeArgAt(0)); |
| 52 GET_NON_NULL_NATIVE_ARGUMENT(Smi, start, arguments->NativeArgAt(1)); | 52 GET_NON_NULL_NATIVE_ARGUMENT(Smi, start, arguments->NativeArgAt(1)); |
| 53 GET_NON_NULL_NATIVE_ARGUMENT(Smi, count, arguments->NativeArgAt(2)); | 53 GET_NON_NULL_NATIVE_ARGUMENT(Smi, count, arguments->NativeArgAt(2)); |
| 54 GET_NON_NULL_NATIVE_ARGUMENT(Bool, needs_type_arg, arguments->NativeArgAt(3)); | 54 GET_NON_NULL_NATIVE_ARGUMENT(Bool, needs_type_arg, arguments->NativeArgAt(3)); |
| 55 intptr_t istart = start.Value(); | 55 intptr_t istart = start.Value(); |
| 56 if ((istart < 0) || (istart > src.Length())) { | 56 if ((istart < 0) || (istart > src.Length())) { |
| 57 Exceptions::ThrowRangeError( | 57 Exceptions::ThrowRangeError("start", start, 0, src.Length()); |
| 58 "start", | |
| 59 start, | |
| 60 0, | |
| 61 src.Length()); | |
| 62 } | 58 } |
| 63 intptr_t icount = count.Value(); | 59 intptr_t icount = count.Value(); |
| 64 // Zero count should be handled outside already. | 60 // Zero count should be handled outside already. |
| 65 if ((icount <= 0) || (icount > src.Length())) { | 61 if ((icount <= 0) || (icount > src.Length())) { |
| 66 Exceptions::ThrowRangeError( | 62 Exceptions::ThrowRangeError("count", count, |
| 67 "count", | 63 0, // This is the limit the user sees. |
| 68 count, | 64 src.Length() - istart); |
| 69 0, // This is the limit the user sees. | |
| 70 src.Length() - istart); | |
| 71 } | 65 } |
| 72 | 66 |
| 73 return src.Slice(istart, icount, needs_type_arg.value()); | 67 return src.Slice(istart, icount, needs_type_arg.value()); |
| 74 } | 68 } |
| 75 | 69 |
| 76 | 70 |
| 77 // Private factory, expects correct arguments. | 71 // Private factory, expects correct arguments. |
| 78 DEFINE_NATIVE_ENTRY(ImmutableList_from, 4) { | 72 DEFINE_NATIVE_ENTRY(ImmutableList_from, 4) { |
| 79 // Ignore first argument of a thsi factory (type argument). | 73 // Ignore first argument of a thsi factory (type argument). |
| 80 const Array& from_array = Array::CheckedHandle(arguments->NativeArgAt(1)); | 74 const Array& from_array = Array::CheckedHandle(arguments->NativeArgAt(1)); |
| 81 const Smi& smi_offset = Smi::CheckedHandle(arguments->NativeArgAt(2)); | 75 const Smi& smi_offset = Smi::CheckedHandle(arguments->NativeArgAt(2)); |
| 82 const Smi& smi_length = Smi::CheckedHandle(arguments->NativeArgAt(3)); | 76 const Smi& smi_length = Smi::CheckedHandle(arguments->NativeArgAt(3)); |
| 83 const intptr_t length = smi_length.Value(); | 77 const intptr_t length = smi_length.Value(); |
| 84 const intptr_t offset = smi_offset.Value(); | 78 const intptr_t offset = smi_offset.Value(); |
| 85 const Array& result = Array::Handle(Array::New(length)); | 79 const Array& result = Array::Handle(Array::New(length)); |
| 86 Object& temp = Object::Handle(); | 80 Object& temp = Object::Handle(); |
| 87 for (intptr_t i = 0; i < length; i++) { | 81 for (intptr_t i = 0; i < length; i++) { |
| 88 temp = from_array.At(i + offset); | 82 temp = from_array.At(i + offset); |
| 89 result.SetAt(i, temp); | 83 result.SetAt(i, temp); |
| 90 } | 84 } |
| 91 result.MakeImmutable(); | 85 result.MakeImmutable(); |
| 92 return result.raw(); | 86 return result.raw(); |
| 93 } | 87 } |
| 94 | 88 |
| 95 } // namespace dart | 89 } // namespace dart |
| OLD | NEW |