Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 #include "platform/assert.h" | |
| 6 | |
| 7 #include "vm/assembler.h" | |
| 8 #include "vm/bootstrap_natives.h" | |
| 9 #include "vm/exceptions.h" | |
| 10 #include "vm/native_entry.h" | |
| 11 #include "vm/object.h" | |
| 12 | |
| 13 namespace dart { | |
| 14 | |
| 15 DEFINE_NATIVE_ENTRY(GrowableObjectArray_allocate, 2) { | |
| 16 const AbstractTypeArguments& type_arguments = | |
| 17 AbstractTypeArguments::CheckedHandle(arguments->At(0)); | |
| 18 ASSERT(type_arguments.IsNull() || | |
| 19 (type_arguments.IsInstantiated() && (type_arguments.Length() == 1))); | |
| 20 GET_NATIVE_ARGUMENT(Array, data, arguments->At(1)); | |
| 21 if ((data.Length() <= 0)) { | |
| 22 GrowableArray<const Object*> args; | |
| 23 args.Add(&data); | |
|
srdjan
2012/04/06 21:19:51
Should this be data.Length() (as smi) ?
siva
2012/04/09 20:57:24
Done.
| |
| 24 Exceptions::ThrowByType(Exceptions::kIndexOutOfRange, args); | |
| 25 } | |
| 26 const GrowableObjectArray& new_array = | |
| 27 GrowableObjectArray::Handle(GrowableObjectArray::New(data)); | |
| 28 new_array.SetTypeArguments(type_arguments); | |
| 29 arguments->SetReturn(new_array); | |
| 30 } | |
| 31 | |
| 32 | |
| 33 DEFINE_NATIVE_ENTRY(GrowableObjectArray_getIndexed, 2) { | |
| 34 GET_NATIVE_ARGUMENT(GrowableObjectArray, array, arguments->At(0)); | |
|
srdjan
2012/04/06 21:19:51
0 should be accessed via CheckedHandle, as it is t
siva
2012/04/09 20:57:24
Done.
| |
| 35 GET_NATIVE_ARGUMENT(Smi, index, arguments->At(1)); | |
| 36 if ((index.Value() < 0) || (index.Value() >= array.Length())) { | |
| 37 GrowableArray<const Object*> args; | |
| 38 args.Add(&index); | |
| 39 Exceptions::ThrowByType(Exceptions::kIndexOutOfRange, args); | |
| 40 } | |
| 41 const Instance& obj = Instance::CheckedHandle(array.At(index.Value())); | |
| 42 arguments->SetReturn(obj); | |
| 43 } | |
| 44 | |
| 45 | |
| 46 DEFINE_NATIVE_ENTRY(GrowableObjectArray_setIndexed, 3) { | |
| 47 GET_NATIVE_ARGUMENT(GrowableObjectArray, array, arguments->At(0)); | |
|
srdjan
2012/04/06 21:19:51
ditto and elsewhere
siva
2012/04/09 20:57:24
Done.
| |
| 48 GET_NATIVE_ARGUMENT(Smi, index, arguments->At(1)); | |
| 49 if ((index.Value() < 0) || (index.Value() >= array.Length())) { | |
| 50 GrowableArray<const Object*> args; | |
| 51 args.Add(&index); | |
| 52 Exceptions::ThrowByType(Exceptions::kIndexOutOfRange, args); | |
| 53 } | |
| 54 GET_NATIVE_ARGUMENT(Instance, value, arguments->At(2)); | |
| 55 array.SetAt(index.Value(), value); | |
| 56 } | |
| 57 | |
| 58 | |
| 59 DEFINE_NATIVE_ENTRY(GrowableObjectArray_getLength, 1) { | |
| 60 GET_NATIVE_ARGUMENT(GrowableObjectArray, array, arguments->At(0)); | |
| 61 const Smi& length = Smi::Handle(isolate, Smi::New(array.Length())); | |
| 62 arguments->SetReturn(length); | |
| 63 } | |
| 64 | |
| 65 | |
| 66 DEFINE_NATIVE_ENTRY(GrowableObjectArray_getCapacity, 1) { | |
| 67 GET_NATIVE_ARGUMENT(GrowableObjectArray, array, arguments->At(0)); | |
| 68 const Smi& capacity = Smi::Handle(isolate, Smi::New(array.Capacity())); | |
| 69 arguments->SetReturn(capacity); | |
| 70 } | |
| 71 | |
| 72 | |
| 73 DEFINE_NATIVE_ENTRY(GrowableObjectArray_setLength, 2) { | |
| 74 GET_NATIVE_ARGUMENT(GrowableObjectArray, array, arguments->At(0)); | |
| 75 GET_NATIVE_ARGUMENT(Smi, length, arguments->At(1)); | |
| 76 if ((length.Value() < 0) || (length.Value() > array.Capacity())) { | |
| 77 GrowableArray<const Object*> args; | |
| 78 args.Add(&length); | |
| 79 Exceptions::ThrowByType(Exceptions::kIndexOutOfRange, args); | |
| 80 } | |
| 81 array.SetLength(length.Value()); | |
| 82 } | |
| 83 | |
| 84 | |
| 85 DEFINE_NATIVE_ENTRY(GrowableObjectArray_setData, 2) { | |
| 86 GET_NATIVE_ARGUMENT(GrowableObjectArray, array, arguments->At(0)); | |
| 87 GET_NATIVE_ARGUMENT(Array, data, arguments->At(1)); | |
| 88 ASSERT(data.Length() > 0); | |
| 89 array.SetData(data); | |
| 90 } | |
| 91 | |
| 92 } // namespace dart | |
| OLD | NEW |