1 | // Copyright 2013 The Flutter Authors. All rights reserved. |
---|---|
2 | // Use of this source code is governed by a BSD-style license that can be |
3 | // found in the LICENSE file. |
4 | |
5 | #include "tonic/dart_list.h" |
6 | |
7 | #include "tonic/logging/dart_error.h" |
8 | |
9 | namespace tonic { |
10 | |
11 | DartList::DartList(Dart_Handle dart_handle) : dart_handle_(dart_handle) { |
12 | TONIC_DCHECK(Dart_IsList(dart_handle_)); |
13 | |
14 | intptr_t length; |
15 | is_valid_ = !LogIfError(Dart_ListLength(dart_handle_, &length)); |
16 | size_ = length; |
17 | } |
18 | |
19 | DartList::DartList() { |
20 | dart_handle_ = Dart_Null(); |
21 | size_ = 0; |
22 | is_valid_ = false; |
23 | } |
24 | |
25 | DartList::DartList(DartList&& other) |
26 | : dart_handle_(other.dart_handle_), |
27 | size_(other.size_), |
28 | is_valid_(other.is_valid_) { |
29 | other.dart_handle_ = nullptr; |
30 | other.size_ = 0; |
31 | other.is_valid_ = false; |
32 | } |
33 | |
34 | void DartList::Set(size_t index, Dart_Handle value) { |
35 | LogIfError(Dart_ListSetAt(dart_handle_, index, value)); |
36 | } |
37 | |
38 | DartList DartConverter<DartList>::FromArguments(Dart_NativeArguments args, |
39 | int index, |
40 | Dart_Handle& exception) { |
41 | Dart_Handle list = Dart_GetNativeArgument(args, index); |
42 | if (LogIfError(list) || !Dart_IsList(list)) { |
43 | exception = Dart_NewApiError("Invalid Argument"); |
44 | return DartList(); |
45 | } |
46 | |
47 | return DartList(list); |
48 | } |
49 | |
50 | } // namespace tonic |
51 |