Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
third_party
dart-lang
sdk
runtime
vm
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
8
#include "
include/dart_native_api.h
"
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
16
namespace
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.
23
class
ApiObjectConverter
:
public
AllStatic
{
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)) {
45
c_obj->
type
=
Dart_CObject_kInt32
;
46
c_obj->
value
.
as_int32
=
static_cast<
int32_t
>
(
value
);
47
}
else
{
48
c_obj->
type
=
Dart_CObject_kInt64
;
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_
dart::AllStatic
Definition
allocation.h:33
dart::ApiObjectConverter
Definition
dart_api_message.h:23
dart::ApiObjectConverter::Convert
static bool Convert(const ObjectPtr raw_obj, Dart_CObject *c_obj)
Definition
dart_api_message.h:29
dart::ApiObjectConverter::CanConvert
static bool CanConvert(const ObjectPtr raw_obj)
Definition
dart_api_message.h:25
dart::ObjectPtr
Definition
tagged_pointer.h:101
dart::Object::null
static ObjectPtr null()
Definition
object.h:433
dart::Smi::Value
intptr_t Value() const
Definition
object.h:9969
dart::Utils::IsInt
static bool IsInt(intptr_t N, T value)
Definition
utils.h:298
dart_api_state.h
dart_native_api.h
Dart_CObject_kInt64
@ Dart_CObject_kInt64
Definition
dart_native_api.h:47
Dart_CObject_kNull
@ Dart_CObject_kNull
Definition
dart_native_api.h:44
Dart_CObject_kInt32
@ Dart_CObject_kInt32
Definition
dart_native_api.h:46
ASSERT
#define ASSERT(E)
Definition
entrypoints_verification_test.cc:25
value
uint8_t value
Definition
fl_standard_message_codec.cc:36
message.h
dart
Definition
dart_vm.cc:33
raw_object.h
utils.h
_Dart_CObject
Definition
dart_native_api.h:63
_Dart_CObject::as_int64
int64_t as_int64
Definition
dart_native_api.h:68
_Dart_CObject::value
union _Dart_CObject::@86 value
_Dart_CObject::type
Dart_CObject_Type type
Definition
dart_native_api.h:64
_Dart_CObject::as_int32
int32_t as_int32
Definition
dart_native_api.h:67
allocation.h
snapshot.h
Generated on Fri Apr 26 2024 06:15:05 for Flutter Engine by
1.9.8