Flutter Engine
The Flutter Engine
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"
7#include "vm/exceptions.h"
8#include "vm/native_entry.h"
9#include "vm/object.h"
10
11namespace dart {
12
13DEFINE_NATIVE_ENTRY(List_allocate, 0, 2) {
14 // Implemented in FlowGraphBuilder::VisitNativeBody.
16 return Object::null();
17}
18
19DEFINE_NATIVE_ENTRY(List_setIndexed, 0, 3) {
20 const Array& array = Array::CheckedHandle(zone, arguments->NativeArgAt(0));
21 GET_NON_NULL_NATIVE_ARGUMENT(Smi, index, arguments->NativeArgAt(1));
22 const Instance& value =
23 Instance::CheckedHandle(zone, arguments->NativeArgAt(2));
24 if ((index.Value() < 0) || (index.Value() >= array.Length())) {
25 Exceptions::ThrowRangeError("index", index, 0, array.Length() - 1);
26 }
27 array.SetAt(index.Value(), value);
28 return Object::null();
29}
30
31DEFINE_NATIVE_ENTRY(List_getLength, 0, 1) {
32 const Array& array = Array::CheckedHandle(zone, arguments->NativeArgAt(0));
33 return Smi::New(array.Length());
34}
35
36// ObjectArray src, int start, int count, bool needTypeArgument.
37DEFINE_NATIVE_ENTRY(List_slice, 0, 4) {
38 const Array& src = Array::CheckedHandle(zone, arguments->NativeArgAt(0));
39 GET_NON_NULL_NATIVE_ARGUMENT(Smi, start, arguments->NativeArgAt(1));
40 GET_NON_NULL_NATIVE_ARGUMENT(Smi, count, arguments->NativeArgAt(2));
41 GET_NON_NULL_NATIVE_ARGUMENT(Bool, needs_type_arg, arguments->NativeArgAt(3));
42 intptr_t istart = start.Value();
43 if ((istart < 0) || (istart > src.Length())) {
44 Exceptions::ThrowRangeError("start", start, 0, src.Length());
45 }
46 intptr_t icount = count.Value();
47 // Zero count should be handled outside already.
48 if ((icount <= 0) || (icount > src.Length())) {
50 0, // This is the limit the user sees.
51 src.Length() - istart);
52 }
53
54 return src.Slice(istart, icount, needs_type_arg.value());
55}
56
57// Private factory, expects correct arguments.
58DEFINE_NATIVE_ENTRY(ImmutableList_from, 0, 4) {
59 // Ignore first argument of this factory (type argument).
60 const Array& from_array =
61 Array::CheckedHandle(zone, arguments->NativeArgAt(1));
62 const Smi& smi_offset = Smi::CheckedHandle(zone, arguments->NativeArgAt(2));
63 const Smi& smi_length = Smi::CheckedHandle(zone, arguments->NativeArgAt(3));
64 const intptr_t length = smi_length.Value();
65 const intptr_t offset = smi_offset.Value();
67 Object& temp = Object::Handle();
68 for (intptr_t i = 0; i < length; i++) {
69 temp = from_array.At(i + offset);
70 result.SetAt(i, temp);
71 }
72 result.MakeImmutable();
73 return result.ptr();
74}
75
76} // namespace dart
int count
Definition: FontMgrTest.cpp:50
#define UNREACHABLE()
Definition: assert.h:248
static ArrayPtr New(intptr_t len, Heap::Space space=Heap::kNew)
Definition: object.h:10959
ObjectPtr At(intptr_t index) const
Definition: object.h:10875
intptr_t Length() const
Definition: object.h:10829
void SetAt(intptr_t index, const Object &value) const
Definition: object.h:10880
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
static ObjectPtr null()
Definition: object.h:433
static Object & Handle()
Definition: object.h:407
static SmiPtr New(intptr_t value)
Definition: object.h:10006
intptr_t Value() const
Definition: object.h:9990
uint8_t value
GAsyncResult * result
size_t length
Definition: dart_vm.cc:33
DEFINE_NATIVE_ENTRY(List_allocate, 0, 2)
Definition: array.cc:13
#define GET_NON_NULL_NATIVE_ARGUMENT(type, name, value)
Definition: native_entry.h:74
SeparatedVector2 offset