@qalqi/headless-hermes-linux-x64 0.0.0-stage → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/BUILD-INFO.txt +5 -0
- package/LICENSE +176 -0
- package/LICENSE-hermes +21 -0
- package/bin/hermes +0 -0
- package/bin/hermesc +0 -0
- package/include/hermes/Public/CrashManager.h +107 -0
- package/include/hermes/Public/CtorConfig.h +236 -0
- package/include/hermes/Public/DebuggerTypes.h +193 -0
- package/include/hermes/Public/GCConfig.h +217 -0
- package/include/hermes/Public/GCTripwireContext.h +40 -0
- package/include/hermes/Public/HermesExport.h +14 -0
- package/include/hermes/Public/JSOutOfMemoryError.h +27 -0
- package/include/hermes/Public/RuntimeConfig.h +184 -0
- package/include/hermes/Public/SamplingProfiler.h +270 -0
- package/include/hermes/hermes.h +242 -0
- package/include/hermes/napi/js_native_api.h +618 -0
- package/include/hermes/napi/js_native_api_types.h +227 -0
- package/include/hermes/napi/node_api.h +265 -0
- package/include/hermes/napi/node_api_types.h +56 -0
- package/include/jsi/JSIDynamic.h +26 -0
- package/include/jsi/decorator.h +1221 -0
- package/include/jsi/hermes-interfaces.h +242 -0
- package/include/jsi/instrumentation.h +132 -0
- package/include/jsi/jsi-inl.h +434 -0
- package/include/jsi/jsi.h +2266 -0
- package/include/jsi/jsilib.h +59 -0
- package/include/jsi/threadsafe.h +79 -0
- package/include/napi/hermes_napi.h +277 -0
- package/include/napi/hermes_napi_compile.h +61 -0
- package/lib/libhermesvm.so +0 -0
- package/package.json +9 -4
- package/README.md +0 -3
package/BUILD-INFO.txt
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
Hermes commit: d41288df5432666c832abc2b2d8d53a14c1ec3de (https://github.com/facebook/hermes/commit/d41288df5432666c832abc2b2d8d53a14c1ec3de)
|
|
2
|
+
Platform: linux-x64
|
|
3
|
+
Build type: Release
|
|
4
|
+
Built by: headless-hermes-jsi-node-api scripts/build-hermes.sh and scripts/package.sh
|
|
5
|
+
Hermes is licensed under MIT (LICENSE-hermes); the packaging scripts under Apache-2.0 (LICENSE).
|
package/LICENSE
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
package/LICENSE-hermes
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/bin/hermes
ADDED
|
Binary file
|
package/bin/hermesc
ADDED
|
Binary file
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
#ifndef HERMES_PUBLIC_CRASHMANAGER_H
|
|
9
|
+
#define HERMES_PUBLIC_CRASHMANAGER_H
|
|
10
|
+
|
|
11
|
+
#include <hermes/Public/HermesExport.h>
|
|
12
|
+
|
|
13
|
+
#include <cstddef>
|
|
14
|
+
#include <functional>
|
|
15
|
+
|
|
16
|
+
namespace hermes {
|
|
17
|
+
namespace vm {
|
|
18
|
+
|
|
19
|
+
/// A CrashManager provides functions that determine what memory and data is
|
|
20
|
+
/// included in dumps in case of crashes.
|
|
21
|
+
class HERMES_EXPORT CrashManager {
|
|
22
|
+
public:
|
|
23
|
+
/// CallbackKey is the type of an identifier for a callback supplied to the
|
|
24
|
+
/// CrashManager.
|
|
25
|
+
using CallbackKey = int;
|
|
26
|
+
/// Type for the callback function invoked on crash. The fd supplied is a raw
|
|
27
|
+
/// file stream an implementation should write a JSON object to.
|
|
28
|
+
using CallbackFunc = std::function<void(int fd)>;
|
|
29
|
+
|
|
30
|
+
/// Registers some memory to be included in any crash dump that occurs.
|
|
31
|
+
/// \param mem A pointer to allocated memory. It must be unregistered
|
|
32
|
+
/// before being freed.
|
|
33
|
+
/// \param length The number of bytes the memory controls.
|
|
34
|
+
virtual void registerMemory(void *mem, size_t length) = 0;
|
|
35
|
+
|
|
36
|
+
/// Unregisters some memory from being included in any crash dump that occurs.
|
|
37
|
+
virtual void unregisterMemory(void *mem) = 0;
|
|
38
|
+
|
|
39
|
+
/// Registers custom data to be included in any crash dump that occurs.
|
|
40
|
+
/// Calling \c setCustomData on the same key twice will overwrite the previous
|
|
41
|
+
/// value.
|
|
42
|
+
/// \param key A tag to look for in the custom data output. Distinguishes
|
|
43
|
+
/// between multiple values.
|
|
44
|
+
/// \param val The value to store for the given key.
|
|
45
|
+
virtual void setCustomData(const char *key, const char *val) = 0;
|
|
46
|
+
|
|
47
|
+
/// If the given \p key has an associated custom data string, remove the
|
|
48
|
+
/// association. If the key hasn't been set before, is a no-op.
|
|
49
|
+
virtual void removeCustomData(const char *key) = 0;
|
|
50
|
+
|
|
51
|
+
/// Same as \c setCustomData, except it is only set for the current thread.
|
|
52
|
+
virtual void setContextualCustomData(const char *key, const char *val) = 0;
|
|
53
|
+
|
|
54
|
+
/// Same as \c removeCustomData, except it is for keys set with \c
|
|
55
|
+
/// setContextualCustomData.
|
|
56
|
+
virtual void removeContextualCustomData(const char *key) = 0;
|
|
57
|
+
|
|
58
|
+
/// Registers a function to be called after a crash has occurred. This
|
|
59
|
+
/// function can examine memory and serialize this to a JSON output stream.
|
|
60
|
+
/// Implmentations decide where the stream is routed to.
|
|
61
|
+
/// \param callback A function to called after a crash.
|
|
62
|
+
/// \return A CallbackKey representing the function you provided. Pass this
|
|
63
|
+
/// key into unregisterCallback when it that callback is no longer needed.
|
|
64
|
+
virtual CallbackKey registerCallback(CallbackFunc callback) = 0;
|
|
65
|
+
|
|
66
|
+
/// Unregisters a previously registered callback. After this function returns,
|
|
67
|
+
/// the previously registered function will not be executed by this
|
|
68
|
+
/// CrashManager during a crash.
|
|
69
|
+
virtual void unregisterCallback(CallbackKey key) = 0;
|
|
70
|
+
|
|
71
|
+
/// the heap information.
|
|
72
|
+
struct HeapInformation {
|
|
73
|
+
/// The amount of memory that is currently in use
|
|
74
|
+
size_t used_{0};
|
|
75
|
+
/// The amount of memory that can currently be allocated
|
|
76
|
+
/// before a full GC is triggered.
|
|
77
|
+
size_t size_{0};
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
/// Record the heap information.
|
|
81
|
+
/// \param heapInfo The current heap information
|
|
82
|
+
virtual void setHeapInfo(const HeapInformation &heapInfo) = 0;
|
|
83
|
+
|
|
84
|
+
virtual ~CrashManager();
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
/// A CrashManager that does nothing.
|
|
88
|
+
class HERMES_EXPORT NopCrashManager final : public CrashManager {
|
|
89
|
+
public:
|
|
90
|
+
void registerMemory(void *, size_t) override {}
|
|
91
|
+
void unregisterMemory(void *) override {}
|
|
92
|
+
void setCustomData(const char *, const char *) override {}
|
|
93
|
+
void removeCustomData(const char *) override {}
|
|
94
|
+
void setContextualCustomData(const char *, const char *) override {}
|
|
95
|
+
void removeContextualCustomData(const char *) override {}
|
|
96
|
+
CallbackKey registerCallback(CallbackFunc /*callback*/) override {
|
|
97
|
+
return 0;
|
|
98
|
+
}
|
|
99
|
+
void unregisterCallback(CallbackKey /*key*/) override {}
|
|
100
|
+
void setHeapInfo(const HeapInformation & /*heapInfo*/) override {}
|
|
101
|
+
|
|
102
|
+
~NopCrashManager() override;
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
} // namespace vm
|
|
106
|
+
} // namespace hermes
|
|
107
|
+
#endif
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
|
|
10
|
+
#include <cstdint>
|
|
11
|
+
#include <utility>
|
|
12
|
+
|
|
13
|
+
/// Defines a new class, called \p NAME representing a constructor config, and
|
|
14
|
+
/// an associated builder class.
|
|
15
|
+
///
|
|
16
|
+
/// The ABI version is encoded in \p VERSION. The fields of the class (along
|
|
17
|
+
/// with their types and default values) are encoded in the \p FIELDS parameter,
|
|
18
|
+
/// and any logic to be run whilst building the config can be passed as a code
|
|
19
|
+
/// block in \p BUILD_BODY.
|
|
20
|
+
///
|
|
21
|
+
/// Fields may be appended without changing \p VERSION. Any other change that
|
|
22
|
+
/// affects the layout, including changing the layout of a field stored by
|
|
23
|
+
/// value, requires a new version.
|
|
24
|
+
///
|
|
25
|
+
/// Example:
|
|
26
|
+
///
|
|
27
|
+
/// Suppose we wish to define a configuration class called Foo, with the
|
|
28
|
+
/// following fields and default values:
|
|
29
|
+
///
|
|
30
|
+
/// int A = 0;
|
|
31
|
+
/// int B = 42;
|
|
32
|
+
/// std::string C = "hello";
|
|
33
|
+
///
|
|
34
|
+
/// Such that the value in A is at most the length of \c C.
|
|
35
|
+
///
|
|
36
|
+
/// We can do so with the following declaration:
|
|
37
|
+
///
|
|
38
|
+
/// " #define FIELDS(F) \ "
|
|
39
|
+
/// " F(int, A) \ "
|
|
40
|
+
/// " F(int, B, 42) \ "
|
|
41
|
+
/// " F(std::string, C, "hello") "
|
|
42
|
+
/// " "
|
|
43
|
+
/// " _HERMES_CTORCONFIG_STRUCT(Foo, 1, FIELDS, { "
|
|
44
|
+
/// " A_ = std::min(A_, C_.length()); "
|
|
45
|
+
/// " }); "
|
|
46
|
+
///
|
|
47
|
+
/// N.B.
|
|
48
|
+
/// - The definition of A does not mention any value -- meaning it is
|
|
49
|
+
/// default initialised.
|
|
50
|
+
/// - References to the fields in the validation logic have a trailling
|
|
51
|
+
/// underscore.
|
|
52
|
+
///
|
|
53
|
+
#define _HERMES_CTORCONFIG_STRUCT(NAME, VERSION, FIELDS, BUILD_BODY) \
|
|
54
|
+
class NAME { \
|
|
55
|
+
enum class FieldIndex : uint32_t { \
|
|
56
|
+
FIELDS(_HERMES_CTORCONFIG_FIELD_INDEX) count, \
|
|
57
|
+
}; \
|
|
58
|
+
\
|
|
59
|
+
static constexpr uint32_t kVersion = VERSION; \
|
|
60
|
+
static constexpr uint32_t kNumFields = \
|
|
61
|
+
static_cast<uint32_t>(FieldIndex::count); \
|
|
62
|
+
\
|
|
63
|
+
uint32_t version_{kVersion}; \
|
|
64
|
+
uint32_t numFields_{kNumFields}; \
|
|
65
|
+
FIELDS(_HERMES_CTORCONFIG_FIELD_DECL) \
|
|
66
|
+
\
|
|
67
|
+
bool containsField(FieldIndex field) const { \
|
|
68
|
+
return version_ == kVersion && \
|
|
69
|
+
numFields_ > static_cast<uint32_t>(field); \
|
|
70
|
+
} \
|
|
71
|
+
\
|
|
72
|
+
void copyFieldsFrom(const NAME &other) { \
|
|
73
|
+
FIELDS(_HERMES_CTORCONFIG_COPY_FIELD) \
|
|
74
|
+
} \
|
|
75
|
+
\
|
|
76
|
+
void moveFieldsFrom(NAME &other) { \
|
|
77
|
+
FIELDS(_HERMES_CTORCONFIG_MOVE_FIELD) \
|
|
78
|
+
} \
|
|
79
|
+
\
|
|
80
|
+
public: \
|
|
81
|
+
NAME() = default; \
|
|
82
|
+
\
|
|
83
|
+
NAME(const NAME &other) { \
|
|
84
|
+
copyFieldsFrom(other); \
|
|
85
|
+
} \
|
|
86
|
+
\
|
|
87
|
+
NAME &operator=(const NAME &other) { \
|
|
88
|
+
copyFieldsFrom(other); \
|
|
89
|
+
version_ = kVersion; \
|
|
90
|
+
numFields_ = kNumFields; \
|
|
91
|
+
return *this; \
|
|
92
|
+
} \
|
|
93
|
+
\
|
|
94
|
+
NAME(NAME &&other) { \
|
|
95
|
+
moveFieldsFrom(other); \
|
|
96
|
+
} \
|
|
97
|
+
\
|
|
98
|
+
NAME &operator=(NAME &&other) { \
|
|
99
|
+
if (this != &other) { \
|
|
100
|
+
moveFieldsFrom(other); \
|
|
101
|
+
} \
|
|
102
|
+
version_ = kVersion; \
|
|
103
|
+
numFields_ = kNumFields; \
|
|
104
|
+
return *this; \
|
|
105
|
+
} \
|
|
106
|
+
\
|
|
107
|
+
class Builder; \
|
|
108
|
+
friend Builder; \
|
|
109
|
+
\
|
|
110
|
+
/** Return the ABI version recorded in this config. */ \
|
|
111
|
+
uint32_t getVersion() const { \
|
|
112
|
+
return version_; \
|
|
113
|
+
} \
|
|
114
|
+
\
|
|
115
|
+
/** Return the recorded field count, excluding metadata. */ \
|
|
116
|
+
uint32_t getNumFields() const { \
|
|
117
|
+
return numFields_; \
|
|
118
|
+
} \
|
|
119
|
+
\
|
|
120
|
+
/** Return the ABI version expected by this definition. */ \
|
|
121
|
+
static constexpr uint32_t getCurrentVersion() { \
|
|
122
|
+
return kVersion; \
|
|
123
|
+
} \
|
|
124
|
+
\
|
|
125
|
+
/** Return the declared field count, excluding metadata. */ \
|
|
126
|
+
static constexpr uint32_t getCurrentNumFields() { \
|
|
127
|
+
return kNumFields; \
|
|
128
|
+
} \
|
|
129
|
+
\
|
|
130
|
+
FIELDS(_HERMES_CTORCONFIG_GETTER) \
|
|
131
|
+
\
|
|
132
|
+
/* returns a Builder that starts with the current config. */ \
|
|
133
|
+
inline Builder rebuild() const; \
|
|
134
|
+
\
|
|
135
|
+
private: \
|
|
136
|
+
inline void doBuild(const Builder &builder); \
|
|
137
|
+
}; \
|
|
138
|
+
\
|
|
139
|
+
class NAME::Builder { \
|
|
140
|
+
NAME config_; \
|
|
141
|
+
\
|
|
142
|
+
FIELDS(_HERMES_CTORCONFIG_FIELD_EXPLICIT_BOOL_DECL) \
|
|
143
|
+
\
|
|
144
|
+
public: \
|
|
145
|
+
Builder() = default; \
|
|
146
|
+
\
|
|
147
|
+
explicit Builder(const NAME &config) : config_(config) {} \
|
|
148
|
+
\
|
|
149
|
+
inline const NAME build() { \
|
|
150
|
+
config_.doBuild(*this); \
|
|
151
|
+
return config_; \
|
|
152
|
+
} \
|
|
153
|
+
\
|
|
154
|
+
/* The explicitly set fields of \p newconfig update \
|
|
155
|
+
* the corresponding fields of \p this. */ \
|
|
156
|
+
inline Builder update(const NAME::Builder &newConfig); \
|
|
157
|
+
\
|
|
158
|
+
FIELDS(_HERMES_CTORCONFIG_SETTER) \
|
|
159
|
+
FIELDS(_HERMES_CTORCONFIG_FIELD_EXPLICIT_BOOL_ACCESSOR) \
|
|
160
|
+
}; \
|
|
161
|
+
\
|
|
162
|
+
NAME::Builder NAME::rebuild() const { \
|
|
163
|
+
return Builder(*this); \
|
|
164
|
+
} \
|
|
165
|
+
\
|
|
166
|
+
NAME::Builder NAME::Builder::update(const NAME::Builder &newConfig) { \
|
|
167
|
+
FIELDS(_HERMES_CTORCONFIG_UPDATE) \
|
|
168
|
+
return *this; \
|
|
169
|
+
} \
|
|
170
|
+
\
|
|
171
|
+
void NAME::doBuild(const NAME::Builder &builder) { \
|
|
172
|
+
(void)builder; \
|
|
173
|
+
BUILD_BODY \
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/// Helper Macros
|
|
177
|
+
|
|
178
|
+
#define _HERMES_CTORCONFIG_FIELD_INDEX(CX, TYPE, NAME, ...) NAME,
|
|
179
|
+
|
|
180
|
+
#define _HERMES_CTORCONFIG_FIELD_DECL(CX, TYPE, NAME, ...) \
|
|
181
|
+
TYPE NAME##_{__VA_ARGS__};
|
|
182
|
+
|
|
183
|
+
#define _HERMES_CTORCONFIG_COPY_FIELD(CX, TYPE, NAME, ...) \
|
|
184
|
+
NAME##_ = other.get##NAME();
|
|
185
|
+
|
|
186
|
+
#define _HERMES_CTORCONFIG_MOVE_FIELD(CX, TYPE, NAME, ...) \
|
|
187
|
+
if (other.containsField(FieldIndex::NAME)) { \
|
|
188
|
+
NAME##_ = std::move(other.NAME##_); \
|
|
189
|
+
} else { \
|
|
190
|
+
NAME##_ = getDefault##NAME(); \
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/// This ignores the first and trailing arguments, and defines a member
|
|
194
|
+
/// indicating whether field NAME was set explicitly.
|
|
195
|
+
#define _HERMES_CTORCONFIG_FIELD_EXPLICIT_BOOL_DECL(CX, TYPE, NAME, ...) \
|
|
196
|
+
bool NAME##Explicit_{false};
|
|
197
|
+
|
|
198
|
+
/// This defines an accessor for the "Explicit_" fields defined above.
|
|
199
|
+
#define _HERMES_CTORCONFIG_FIELD_EXPLICIT_BOOL_ACCESSOR(CX, TYPE, NAME, ...) \
|
|
200
|
+
bool has##NAME() const { \
|
|
201
|
+
return NAME##Explicit_; \
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/// Placeholder token for fields whose defaults are not constexpr, to make the
|
|
205
|
+
/// listings more readable.
|
|
206
|
+
#define HERMES_NON_CONSTEXPR
|
|
207
|
+
|
|
208
|
+
#define _HERMES_CTORCONFIG_GETTER(CX, TYPE, NAME, ...) \
|
|
209
|
+
inline TYPE get##NAME() const { \
|
|
210
|
+
if (!containsField(FieldIndex::NAME)) { \
|
|
211
|
+
return getDefault##NAME(); \
|
|
212
|
+
} \
|
|
213
|
+
return NAME##_; \
|
|
214
|
+
} \
|
|
215
|
+
static CX TYPE getDefault##NAME() { \
|
|
216
|
+
/* Instead of parens around TYPE (non-standard) */ \
|
|
217
|
+
using TypeAsSingleToken = TYPE; \
|
|
218
|
+
return TypeAsSingleToken{__VA_ARGS__}; \
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
#define _HERMES_CTORCONFIG_SETTER(CX, TYPE, NAME, ...) \
|
|
222
|
+
inline auto with##NAME(TYPE NAME) -> decltype(*this) { \
|
|
223
|
+
config_.NAME##_ = std::move(NAME); \
|
|
224
|
+
NAME##Explicit_ = true; \
|
|
225
|
+
return *this; \
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
#define _HERMES_CTORCONFIG_BUILDER_GETTER(CX, TYPE, NAME, ...) \
|
|
229
|
+
TYPE get##NAME() const { \
|
|
230
|
+
return config_.NAME##_; \
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
#define _HERMES_CTORCONFIG_UPDATE(CX, TYPE, NAME, ...) \
|
|
234
|
+
if (newConfig.has##NAME()) { \
|
|
235
|
+
with##NAME(newConfig.config_.get##NAME()); \
|
|
236
|
+
}
|