Flutter Engine
The Flutter Engine
dart_api_message.h
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#ifndef RUNTIME_VM_DART_API_MESSAGE_H_
6#define RUNTIME_VM_DART_API_MESSAGE_H_
7
9#include "platform/utils.h"
10#include "vm/allocation.h"
11#include "vm/dart_api_state.h"
12#include "vm/message.h"
13#include "vm/raw_object.h"
14#include "vm/snapshot.h"
15
16namespace dart {
17
18// This class handles translation of certain ObjectPtrs to CObjects for
19// NativeMessageHandlers.
20//
21// TODO(zra): Expand to support not only null, but also other VM heap objects
22// as well.
24 public:
25 static bool CanConvert(const ObjectPtr raw_obj) {
26 return !raw_obj->IsHeapObject() || (raw_obj == Object::null());
27 }
28
29 static bool Convert(const ObjectPtr raw_obj, Dart_CObject* c_obj) {
30 if (!raw_obj->IsHeapObject()) {
31 ConvertSmi(static_cast<const SmiPtr>(raw_obj), c_obj);
32 } else if (raw_obj == Object::null()) {
33 ConvertNull(c_obj);
34 } else {
35 return false;
36 }
37 return true;
38 }
39
40 private:
41 static void ConvertSmi(const SmiPtr raw_smi, Dart_CObject* c_obj) {
42 ASSERT(!raw_smi->IsHeapObject());
43 intptr_t value = Smi::Value(raw_smi);
44 if (Utils::IsInt(31, value)) {
46 c_obj->value.as_int32 = static_cast<int32_t>(value);
47 } else {
49 c_obj->value.as_int64 = static_cast<int64_t>(value);
50 }
51 }
52
53 static void ConvertNull(Dart_CObject* c_obj) {
54 c_obj->type = Dart_CObject_kNull;
55 c_obj->value.as_int64 = 0;
56 }
57};
58
59} // namespace dart
60
61#endif // RUNTIME_VM_DART_API_MESSAGE_H_
static bool Convert(const ObjectPtr raw_obj, Dart_CObject *c_obj)
static bool CanConvert(const ObjectPtr raw_obj)
static ObjectPtr null()
Definition: object.h:433
intptr_t Value() const
Definition: object.h:9990
static bool IsInt(intptr_t N, T value)
Definition: utils.h:313
@ Dart_CObject_kInt64
@ Dart_CObject_kNull
@ Dart_CObject_kInt32
#define ASSERT(E)
uint8_t value
Definition: dart_vm.cc:33
union _Dart_CObject::@86 value
Dart_CObject_Type type