v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
message-macros.h
Go to the documentation of this file.
1// Copyright 2019 the V8 project 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#ifndef V8_TORQUE_LS_MESSAGE_MACROS_H_
6#define V8_TORQUE_LS_MESSAGE_MACROS_H_
7
8namespace v8 {
9namespace internal {
10namespace torque {
11namespace ls {
12
13#define JSON_STRING_ACCESSORS(name) \
14 inline const std::string& name() const { \
15 return object().at(#name).ToString(); \
16 } \
17 inline void set_##name(const std::string& str) { \
18 object()[#name] = JsonValue::From(str); \
19 } \
20 inline bool has_##name() const { \
21 return object().find(#name) != object().end(); \
22 }
23
24#define JSON_BOOL_ACCESSORS(name) \
25 inline bool name() const { return object().at(#name).ToBool(); } \
26 inline void set_##name(bool b) { object()[#name] = JsonValue::From(b); }
27
28#define JSON_INT_ACCESSORS(name) \
29 inline int name() const { return object().at(#name).ToNumber(); } \
30 inline void set_##name(int n) { \
31 object()[#name] = JsonValue::From(static_cast<double>(n)); \
32 }
33
34#define JSON_OBJECT_ACCESSORS(type, name) \
35 inline type name() { return GetObject<type>(#name); }
36
37#define JSON_DYNAMIC_OBJECT_ACCESSORS(name) \
38 template <class T> \
39 inline T name() { \
40 return GetObject<T>(#name); \
41 }
42
43#define JSON_ARRAY_OBJECT_ACCESSORS(type, name) \
44 inline type add_##name() { \
45 JsonObject& new_element = AddObjectElementToArrayProperty(#name); \
46 return type(new_element); \
47 } \
48 inline std::size_t name##_size() { return GetArrayProperty(#name).size(); } \
49 inline type name(size_t idx) { \
50 CHECK(idx < name##_size()); \
51 return type(GetArrayProperty(#name)[idx].ToObject()); \
52 }
53
54} // namespace ls
55} // namespace torque
56} // namespace internal
57} // namespace v8
58
59#endif // V8_TORQUE_LS_MESSAGE_MACROS_H_