Flutter Engine
The Flutter Engine
growable_array.cc
Go to the documentation of this 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
3// BSD-style license that can be found in the LICENSE file.
4
5#include "platform/assert.h"
6
8#include "vm/exceptions.h"
9#include "vm/native_entry.h"
10#include "vm/object.h"
12
13namespace dart {
14
15DEFINE_NATIVE_ENTRY(GrowableList_allocate, 0, 2) {
16 const TypeArguments& type_arguments =
17 TypeArguments::CheckedHandle(zone, arguments->NativeArgAt(0));
18 GET_NON_NULL_NATIVE_ARGUMENT(Array, data, arguments->NativeArgAt(1));
19 if (data.Length() < 0) {
22 0, // This is the limit the user sees.
24 }
25 const GrowableObjectArray& new_array =
27 new_array.SetTypeArguments(type_arguments);
28 return new_array.ptr();
29}
30
31DEFINE_NATIVE_ENTRY(GrowableList_setIndexed, 0, 3) {
32 const GrowableObjectArray& array =
33 GrowableObjectArray::CheckedHandle(zone, arguments->NativeArgAt(0));
34 GET_NON_NULL_NATIVE_ARGUMENT(Smi, index, arguments->NativeArgAt(1));
35 if ((index.Value() < 0) || (index.Value() >= array.Length())) {
36 Exceptions::ThrowRangeError("index", index, 0, array.Length() - 1);
37 }
38 GET_NON_NULL_NATIVE_ARGUMENT(Instance, value, arguments->NativeArgAt(2));
39 array.SetAt(index.Value(), value);
40 return Object::null();
41}
42
43DEFINE_NATIVE_ENTRY(GrowableList_getLength, 0, 1) {
44 const GrowableObjectArray& array =
45 GrowableObjectArray::CheckedHandle(zone, arguments->NativeArgAt(0));
46 return Smi::New(array.Length());
47}
48
49DEFINE_NATIVE_ENTRY(GrowableList_getCapacity, 0, 1) {
50 const GrowableObjectArray& array =
51 GrowableObjectArray::CheckedHandle(zone, arguments->NativeArgAt(0));
52 return Smi::New(array.Capacity());
53}
54
55DEFINE_NATIVE_ENTRY(GrowableList_setLength, 0, 2) {
56 const GrowableObjectArray& array =
57 GrowableObjectArray::CheckedHandle(zone, arguments->NativeArgAt(0));
58 GET_NON_NULL_NATIVE_ARGUMENT(Smi, length, arguments->NativeArgAt(1));
59 ASSERT((length.Value() >= 0) && (length.Value() <= array.Capacity()));
60 array.SetLength(length.Value());
61 return Object::null();
62}
63
64DEFINE_NATIVE_ENTRY(GrowableList_setData, 0, 2) {
65 const GrowableObjectArray& array =
66 GrowableObjectArray::CheckedHandle(zone, arguments->NativeArgAt(0));
67 GET_NON_NULL_NATIVE_ARGUMENT(Array, data, arguments->NativeArgAt(1));
68 ASSERT(data.Length() >= 0);
69 array.SetData(data);
70 return Object::null();
71}
72
73DEFINE_NATIVE_ENTRY(Internal_makeListFixedLength, 0, 1) {
75 arguments->NativeArgAt(0));
76 return Array::MakeFixedLength(array, /* unique = */ true);
77}
78
79DEFINE_NATIVE_ENTRY(Internal_makeFixedListUnmodifiable, 0, 1) {
80 GET_NON_NULL_NATIVE_ARGUMENT(Array, array, arguments->NativeArgAt(0));
81 array.MakeImmutable();
82 return array.ptr();
83}
84
85} // namespace dart
static constexpr intptr_t kMaxElements
Definition: object.h:10924
static ArrayPtr MakeFixedLength(const GrowableObjectArray &growable_array, bool unique=false)
Definition: object.cc:24935
static DART_NORETURN void ThrowRangeError(const char *argument_name, const Integer &argument_value, intptr_t expected_from, intptr_t expected_to)
Definition: exceptions.cc:1094
void SetData(const Array &value) const
Definition: object.h:11083
void SetLength(intptr_t value) const
Definition: object.h:11076
virtual void SetTypeArguments(const TypeArguments &value) const
Definition: object.h:11107
static GrowableObjectArrayPtr New(Heap::Space space=Heap::kNew)
Definition: object.h:11144
intptr_t Length() const
Definition: object.h:11072
void SetAt(intptr_t index, const Object &value) const
Definition: object.h:11091
intptr_t Capacity() const
Definition: object.h:11067
static IntegerPtr New(const String &str, Heap::Space space=Heap::kNew)
Definition: object.cc:22984
static ObjectPtr null()
Definition: object.h:433
ObjectPtr ptr() const
Definition: object.h:332
static Object & Handle()
Definition: object.h:407
static SmiPtr New(intptr_t value)
Definition: object.h:10006
#define ASSERT(E)
uint8_t value
size_t length
Definition: dart_vm.cc:33
DEFINE_NATIVE_ENTRY(List_allocate, 0, 2)
Definition: array.cc:13
static int8_t data[kExtLength]
#define GET_NON_NULL_NATIVE_ARGUMENT(type, name, value)
Definition: native_entry.h:74