@qalqi/headless-hermes-linux-x64 0.0.0-stage → 0.1.0
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
|
@@ -0,0 +1,270 @@
|
|
|
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 <hermes/Public/HermesExport.h>
|
|
11
|
+
|
|
12
|
+
#include <cstdint>
|
|
13
|
+
#include <deque>
|
|
14
|
+
#include <memory>
|
|
15
|
+
#include <optional>
|
|
16
|
+
#include <string>
|
|
17
|
+
#include <variant>
|
|
18
|
+
#include <vector>
|
|
19
|
+
|
|
20
|
+
namespace facebook {
|
|
21
|
+
namespace hermes {
|
|
22
|
+
namespace sampling_profiler {
|
|
23
|
+
|
|
24
|
+
/// Helper-class that represents a pair of iterators, which form a range to
|
|
25
|
+
/// iterate over.
|
|
26
|
+
template <typename Iterator>
|
|
27
|
+
class Range {
|
|
28
|
+
public:
|
|
29
|
+
Range(Iterator begin, Iterator end) : begin_(begin), end_(end) {}
|
|
30
|
+
|
|
31
|
+
Iterator begin() const {
|
|
32
|
+
return begin_;
|
|
33
|
+
}
|
|
34
|
+
Iterator end() const {
|
|
35
|
+
return end_;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
private:
|
|
39
|
+
Iterator begin_;
|
|
40
|
+
Iterator end_;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
/// Helper for creating Range and deducing the type based on input.
|
|
44
|
+
template <typename Iterator>
|
|
45
|
+
Range<Iterator> makeRange(Iterator begin, Iterator end) {
|
|
46
|
+
return Range<Iterator>(begin, end);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/// JavaScript function frame. Guaranteed to have function name, potentially
|
|
50
|
+
/// an empty string, if function is anonymous or if function names were filtered
|
|
51
|
+
/// out during bytecode compilation. Could have scriptId, url, line and column
|
|
52
|
+
/// numbers, if debug source location is available.
|
|
53
|
+
class HERMES_EXPORT ProfileSampleCallStackJSFunctionFrame {
|
|
54
|
+
public:
|
|
55
|
+
explicit ProfileSampleCallStackJSFunctionFrame(
|
|
56
|
+
std::string_view functionName,
|
|
57
|
+
uint32_t scriptId,
|
|
58
|
+
const std::optional<std::string_view> &scriptUrl = std::nullopt,
|
|
59
|
+
const std::optional<uint32_t> &lineNumber = std::nullopt,
|
|
60
|
+
const std::optional<uint32_t> &columnNumber = std::nullopt)
|
|
61
|
+
: functionName_(functionName),
|
|
62
|
+
scriptId_(scriptId),
|
|
63
|
+
scriptUrl_(scriptUrl),
|
|
64
|
+
lineNumber_(lineNumber),
|
|
65
|
+
columnNumber_(columnNumber) {}
|
|
66
|
+
|
|
67
|
+
/// \return name of the function that represents call frame.
|
|
68
|
+
std::string_view getFunctionName() const {
|
|
69
|
+
return functionName_;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/// \return id of the corresponding script in the VM.
|
|
73
|
+
uint32_t getScriptId() const {
|
|
74
|
+
return scriptId_;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
bool hasScriptUrl() const {
|
|
78
|
+
return scriptUrl_.has_value();
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/// \return source url of the corresponding script in the VM.
|
|
82
|
+
std::string_view getScriptUrl() const {
|
|
83
|
+
return scriptUrl_.value();
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
bool hasFunctionLineNumber() const {
|
|
87
|
+
return lineNumber_.has_value();
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/// \return 1-based line number of the location where the function definition
|
|
91
|
+
/// starts.
|
|
92
|
+
uint32_t getFunctionLineNumber() const {
|
|
93
|
+
return lineNumber_.value();
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
bool hasFunctionColumnNumber() const {
|
|
97
|
+
return columnNumber_.has_value();
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/// \return 1-based column number of the location where the function
|
|
101
|
+
/// definition starts.
|
|
102
|
+
uint32_t getFunctionColumnNumber() const {
|
|
103
|
+
return columnNumber_.value();
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
private:
|
|
107
|
+
std::string_view functionName_;
|
|
108
|
+
uint32_t scriptId_;
|
|
109
|
+
std::optional<std::string_view> scriptUrl_;
|
|
110
|
+
std::optional<uint32_t> lineNumber_;
|
|
111
|
+
std::optional<uint32_t> columnNumber_;
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
/// Native (Hermes) function frame. Example: implementation of a built-in
|
|
115
|
+
/// Array.prototype.map.
|
|
116
|
+
class HERMES_EXPORT ProfileSampleCallStackNativeFunctionFrame {
|
|
117
|
+
public:
|
|
118
|
+
explicit ProfileSampleCallStackNativeFunctionFrame(
|
|
119
|
+
std::string_view functionName)
|
|
120
|
+
: functionName_(functionName) {}
|
|
121
|
+
|
|
122
|
+
/// \return name of the function that represents call frame.
|
|
123
|
+
std::string_view getFunctionName() const {
|
|
124
|
+
return functionName_;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
private:
|
|
128
|
+
std::string_view functionName_;
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
/// Host function frame. Native functions defined by the integrator. Example:
|
|
132
|
+
/// for React Native, this could be performance.measure or console.log.
|
|
133
|
+
class HERMES_EXPORT ProfileSampleCallStackHostFunctionFrame {
|
|
134
|
+
public:
|
|
135
|
+
explicit ProfileSampleCallStackHostFunctionFrame(
|
|
136
|
+
std::string_view functionName)
|
|
137
|
+
: functionName_(functionName) {}
|
|
138
|
+
|
|
139
|
+
/// \return name of the function that represents call frame.
|
|
140
|
+
std::string_view getFunctionName() const {
|
|
141
|
+
return functionName_;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
private:
|
|
145
|
+
std::string_view functionName_;
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
/// Frame that suspends the execution of the VM: could be GC, Debugger or
|
|
149
|
+
/// combination of them.
|
|
150
|
+
class HERMES_EXPORT ProfileSampleCallStackSuspendFrame {
|
|
151
|
+
public:
|
|
152
|
+
/// Subtype of the Suspend frame.
|
|
153
|
+
enum class SuspendFrameKind {
|
|
154
|
+
GC, /// Frame that suspends the execution of the VM due to GC.
|
|
155
|
+
Debugger, /// Frame that suspends the execution of the VM due to debugger.
|
|
156
|
+
Multiple, /// Multiple suspensions have occurred.
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
explicit ProfileSampleCallStackSuspendFrame(
|
|
160
|
+
const SuspendFrameKind suspendFrameKind)
|
|
161
|
+
: suspendFrameKind_(suspendFrameKind) {}
|
|
162
|
+
|
|
163
|
+
/// \return subtype of the suspend frame.
|
|
164
|
+
SuspendFrameKind getSuspendFrameKind() const {
|
|
165
|
+
return suspendFrameKind_;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
private:
|
|
169
|
+
SuspendFrameKind suspendFrameKind_;
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
/// Variant of all possible call stack frames options.
|
|
173
|
+
using ProfileSampleCallStackFrame = std::variant<
|
|
174
|
+
ProfileSampleCallStackSuspendFrame,
|
|
175
|
+
ProfileSampleCallStackNativeFunctionFrame,
|
|
176
|
+
ProfileSampleCallStackHostFunctionFrame,
|
|
177
|
+
ProfileSampleCallStackJSFunctionFrame>;
|
|
178
|
+
|
|
179
|
+
/// A pair of a timestamp and a snapshot of the call stack at this point in
|
|
180
|
+
/// time.
|
|
181
|
+
class HERMES_EXPORT ProfileSample {
|
|
182
|
+
public:
|
|
183
|
+
using CallStackFrameIterator =
|
|
184
|
+
std::vector<ProfileSampleCallStackFrame>::const_iterator;
|
|
185
|
+
|
|
186
|
+
ProfileSample(
|
|
187
|
+
uint64_t timestamp,
|
|
188
|
+
uint64_t threadId,
|
|
189
|
+
std::vector<ProfileSampleCallStackFrame> callStack)
|
|
190
|
+
: timestamp_(timestamp),
|
|
191
|
+
threadId_(threadId),
|
|
192
|
+
callStack_(std::move(callStack)) {}
|
|
193
|
+
|
|
194
|
+
/// \return serialized unix timestamp in microseconds granularity. The
|
|
195
|
+
/// moment when this sample was recorded.
|
|
196
|
+
uint64_t getTimestamp() const {
|
|
197
|
+
return timestamp_;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/// \return thread id where sample was recorded.
|
|
201
|
+
uint64_t getThreadId() const {
|
|
202
|
+
return threadId_;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/// \return a pair of iterators that can be used for iterating over call stack
|
|
206
|
+
/// frames, the order will be from callee to caller.
|
|
207
|
+
Range<CallStackFrameIterator> getCallStackFramesRange() const {
|
|
208
|
+
return makeRange(callStack_.begin(), callStack_.end());
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/// \return the number of frames inside the call stack of this sample.
|
|
212
|
+
size_t getCallStackFramesCount() const {
|
|
213
|
+
return callStack_.size();
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
private:
|
|
217
|
+
/// When the call stack snapshot was taken (μs).
|
|
218
|
+
uint64_t timestamp_;
|
|
219
|
+
/// Thread id where sample was recorded.
|
|
220
|
+
uint64_t threadId_;
|
|
221
|
+
/// Snapshot of the call stack. The first element of the vector is
|
|
222
|
+
/// the lowest frame in the stack.
|
|
223
|
+
std::vector<ProfileSampleCallStackFrame> callStack_;
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
/// Contains relevant information about the sampled trace from start to finish.
|
|
227
|
+
class HERMES_EXPORT Profile {
|
|
228
|
+
public:
|
|
229
|
+
using SampleIterator = std::vector<ProfileSample>::const_iterator;
|
|
230
|
+
|
|
231
|
+
Profile(
|
|
232
|
+
std::vector<ProfileSample> samples,
|
|
233
|
+
std::unique_ptr<std::deque<std::string>> stringStorage)
|
|
234
|
+
: samples_(std::move(samples)),
|
|
235
|
+
stringStorage_(std::move(stringStorage)) {}
|
|
236
|
+
|
|
237
|
+
Profile(Profile &&) = default;
|
|
238
|
+
Profile &operator=(Profile &&) = default;
|
|
239
|
+
|
|
240
|
+
/// Not copyable, maintains the ownership of the storage of strings.
|
|
241
|
+
Profile(const Profile &) = delete;
|
|
242
|
+
Profile &operator=(const Profile &) = delete;
|
|
243
|
+
|
|
244
|
+
~Profile() = default;
|
|
245
|
+
|
|
246
|
+
/// \return a pair of iterators that can be used for iterating over recorded
|
|
247
|
+
/// samples, will happen in chronological order.
|
|
248
|
+
Range<SampleIterator> getSamplesRange() const {
|
|
249
|
+
return makeRange(samples_.begin(), samples_.end());
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/// \return the number of recorded samples.
|
|
253
|
+
size_t getSamplesCount() const {
|
|
254
|
+
return samples_.size();
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
private:
|
|
258
|
+
/// List of recorded samples, should be chronologically sorted.
|
|
259
|
+
std::vector<ProfileSample> samples_;
|
|
260
|
+
/// Smart pointer to the string storage, owns the strings.
|
|
261
|
+
/// Frames inside this Profile keep a reference to the storage and know how to
|
|
262
|
+
/// get std::string_view to the actual string.
|
|
263
|
+
/// The storage lifetime is tied to the lifetime of the Profile. Samples and
|
|
264
|
+
/// Frames should not outlive the Profile.
|
|
265
|
+
std::unique_ptr<std::deque<std::string>> stringStorage_;
|
|
266
|
+
};
|
|
267
|
+
|
|
268
|
+
} // namespace sampling_profiler
|
|
269
|
+
} // namespace hermes
|
|
270
|
+
} // namespace facebook
|
|
@@ -0,0 +1,242 @@
|
|
|
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 <exception>
|
|
11
|
+
#include <list>
|
|
12
|
+
#include <map>
|
|
13
|
+
#include <memory>
|
|
14
|
+
#include <ostream>
|
|
15
|
+
#include <string>
|
|
16
|
+
|
|
17
|
+
#include <hermes/Public/HermesExport.h>
|
|
18
|
+
#include <hermes/Public/RuntimeConfig.h>
|
|
19
|
+
#include <hermes/Public/SamplingProfiler.h>
|
|
20
|
+
#include <jsi/hermes-interfaces.h>
|
|
21
|
+
#include <jsi/jsi.h>
|
|
22
|
+
#include <unordered_map>
|
|
23
|
+
|
|
24
|
+
struct HermesTestHelper;
|
|
25
|
+
struct SHUnit;
|
|
26
|
+
struct SHRuntime;
|
|
27
|
+
|
|
28
|
+
namespace hermes {
|
|
29
|
+
namespace vm {
|
|
30
|
+
class GCExecTrace;
|
|
31
|
+
class Runtime;
|
|
32
|
+
class SerializedValue;
|
|
33
|
+
} // namespace vm
|
|
34
|
+
} // namespace hermes
|
|
35
|
+
|
|
36
|
+
namespace facebook {
|
|
37
|
+
namespace jsi {
|
|
38
|
+
|
|
39
|
+
class ThreadSafeRuntime;
|
|
40
|
+
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
namespace hermes {
|
|
44
|
+
|
|
45
|
+
namespace debugger {
|
|
46
|
+
class Debugger;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
class HermesRuntime;
|
|
50
|
+
/// The Hermes Root API interface. This is the entry point to create the Hermes
|
|
51
|
+
/// runtime and to access Hermes-specific methods that do not rely on a runtime
|
|
52
|
+
/// instance.
|
|
53
|
+
class HERMES_EXPORT IHermesRootAPI : public jsi::ICast {
|
|
54
|
+
public:
|
|
55
|
+
static constexpr jsi::UUID uuid{
|
|
56
|
+
0xb654d898,
|
|
57
|
+
0xdfad,
|
|
58
|
+
0x11ef,
|
|
59
|
+
0x859a,
|
|
60
|
+
0x325096b39f47};
|
|
61
|
+
|
|
62
|
+
// Returns an instance of Hermes Runtime.
|
|
63
|
+
virtual std::unique_ptr<HermesRuntime> makeHermesRuntime(
|
|
64
|
+
const ::hermes::vm::RuntimeConfig &runtimeConfig) = 0;
|
|
65
|
+
|
|
66
|
+
virtual bool isHermesBytecode(const uint8_t *data, size_t len) = 0;
|
|
67
|
+
|
|
68
|
+
// Returns the supported bytecode version.
|
|
69
|
+
virtual uint32_t getBytecodeVersion() = 0;
|
|
70
|
+
|
|
71
|
+
// (EXPERIMENTAL) Issues madvise calls for portions of the given
|
|
72
|
+
// bytecode file that will likely be used when loading the bytecode
|
|
73
|
+
// file and running its global function.
|
|
74
|
+
virtual void prefetchHermesBytecode(const uint8_t *data, size_t len) = 0;
|
|
75
|
+
|
|
76
|
+
// Returns whether the data is valid HBC with more extensive checks than
|
|
77
|
+
// isHermesBytecode and returns why it isn't in errorMessage (if nonnull)
|
|
78
|
+
// if not.
|
|
79
|
+
virtual bool hermesBytecodeSanityCheck(
|
|
80
|
+
const uint8_t *data,
|
|
81
|
+
size_t len,
|
|
82
|
+
std::string *errorMessage = nullptr) = 0;
|
|
83
|
+
|
|
84
|
+
/// Sets a global fatal handler that is shared across all active Hermes
|
|
85
|
+
/// runtimes. Setting fatal handler in multiple places will override the
|
|
86
|
+
/// previous fatal handler set by this functionality.
|
|
87
|
+
/// The fatal handler must not throw exceptions, as Hermes is compiled without
|
|
88
|
+
/// exceptions.
|
|
89
|
+
virtual void setFatalHandler(void (*handler)(const std::string &)) = 0;
|
|
90
|
+
|
|
91
|
+
// Assuming that \p data is valid HBC bytecode data, returns a pointer to the
|
|
92
|
+
// first element of the epilogue, data append to the end of the bytecode
|
|
93
|
+
// stream. Return pair contain ptr to data and header.
|
|
94
|
+
virtual std::pair<const uint8_t *, size_t> getBytecodeEpilogue(
|
|
95
|
+
const uint8_t *data,
|
|
96
|
+
size_t len) = 0;
|
|
97
|
+
|
|
98
|
+
/// Enable sampling profiler.
|
|
99
|
+
/// Starts a separate thread that polls VM state with \p meanHzFreq frequency.
|
|
100
|
+
/// Any subsequent call to \c enableSamplingProfiler() is ignored until
|
|
101
|
+
/// next call to \c disableSamplingProfiler()
|
|
102
|
+
virtual void enableSamplingProfiler(double meanHzFreq = 100) = 0;
|
|
103
|
+
|
|
104
|
+
/// Disable the sampling profiler
|
|
105
|
+
virtual void disableSamplingProfiler() = 0;
|
|
106
|
+
|
|
107
|
+
/// Dump sampled stack trace to the given file name.
|
|
108
|
+
virtual void dumpSampledTraceToFile(const std::string &fileName) = 0;
|
|
109
|
+
|
|
110
|
+
/// Dump sampled stack trace to the given stream.
|
|
111
|
+
virtual void dumpSampledTraceToStream(std::ostream &stream) = 0;
|
|
112
|
+
|
|
113
|
+
/// Return the executed JavaScript function info.
|
|
114
|
+
/// This information holds the segmentID, Virtualoffset and sourceURL.
|
|
115
|
+
/// This information is needed specifically to be able to symbolicate non-CJS
|
|
116
|
+
/// bundles correctly. This API will be simplified later to simply return a
|
|
117
|
+
/// segmentID and virtualOffset, when we are able to only support CJS bundles.
|
|
118
|
+
virtual std::unordered_map<std::string, std::vector<std::string>>
|
|
119
|
+
getExecutedFunctions() = 0;
|
|
120
|
+
|
|
121
|
+
/// \return whether code coverage profiler is enabled or not.
|
|
122
|
+
virtual bool isCodeCoverageProfilerEnabled() = 0;
|
|
123
|
+
|
|
124
|
+
/// Enable code coverage profiler.
|
|
125
|
+
virtual void enableCodeCoverageProfiler() = 0;
|
|
126
|
+
|
|
127
|
+
/// Disable code coverage profiler.
|
|
128
|
+
virtual void disableCodeCoverageProfiler() = 0;
|
|
129
|
+
|
|
130
|
+
protected:
|
|
131
|
+
/// The destructor is protected as delete calls on interfaces must not occur.
|
|
132
|
+
/// It is also non-virtual to simplify the v-table.
|
|
133
|
+
~IHermesRootAPI() {}
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
/// The setFatalHandler functionality has global effects, which may cause
|
|
137
|
+
/// unintended or surprising behavior for users of this API. For this reason, it
|
|
138
|
+
/// is not recommended and the functionality is provided by the optional
|
|
139
|
+
/// interface ISetFatalHandler.
|
|
140
|
+
class HERMES_EXPORT ISetFatalHandler : public jsi::ICast {
|
|
141
|
+
public:
|
|
142
|
+
static constexpr jsi::UUID uuid{
|
|
143
|
+
0xda98a610,
|
|
144
|
+
0x09cb,
|
|
145
|
+
0x11f0,
|
|
146
|
+
0x87bf,
|
|
147
|
+
0x325096b39f47};
|
|
148
|
+
/// Sets a global fatal handler that is shared across all active Hermes
|
|
149
|
+
/// runtimes. Setting fatal handler in multiple places will override the
|
|
150
|
+
/// previous fatal handler set by this functionality.
|
|
151
|
+
/// The fatal handler must not throw exceptions, as Hermes is compiled without
|
|
152
|
+
/// exceptions.
|
|
153
|
+
virtual void setFatalHandler(void (*handler)(const std::string &)) = 0;
|
|
154
|
+
|
|
155
|
+
protected:
|
|
156
|
+
~ISetFatalHandler() = default;
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
/// Interface for methods that are exposed for test purposes.
|
|
160
|
+
class HERMES_EXPORT IHermesTestHelpers : public jsi::ICast {
|
|
161
|
+
public:
|
|
162
|
+
static constexpr jsi::UUID uuid{
|
|
163
|
+
0x664e489a,
|
|
164
|
+
0xf941,
|
|
165
|
+
0x11ef,
|
|
166
|
+
0xa44c,
|
|
167
|
+
0x325096b39f47};
|
|
168
|
+
|
|
169
|
+
virtual size_t rootsListLengthForTests() const = 0;
|
|
170
|
+
|
|
171
|
+
protected:
|
|
172
|
+
~IHermesTestHelpers() = default;
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
#ifdef JSI_UNSTABLE
|
|
176
|
+
// Interface for methods that are exposed for tracing purposes.
|
|
177
|
+
class IHermesTracingHelpers : public jsi::ICast {
|
|
178
|
+
public:
|
|
179
|
+
static constexpr jsi::UUID uuid{
|
|
180
|
+
0x74ac2c4e,
|
|
181
|
+
0xc660,
|
|
182
|
+
0x11f0,
|
|
183
|
+
0x8de9,
|
|
184
|
+
0x0242ac120002};
|
|
185
|
+
|
|
186
|
+
// Returns the secret for obtaining the underlying SerializedValue object
|
|
187
|
+
virtual const ::hermes::vm::SerializedValue *getHermesSerializedValue(
|
|
188
|
+
const jsi::Serialized &serialized) const = 0;
|
|
189
|
+
virtual const std::shared_ptr<jsi::Serialized> makeSerialized(
|
|
190
|
+
::hermes::vm::SerializedValue &value) const = 0;
|
|
191
|
+
|
|
192
|
+
protected:
|
|
193
|
+
~IHermesTracingHelpers() = default;
|
|
194
|
+
};
|
|
195
|
+
#endif
|
|
196
|
+
|
|
197
|
+
class HermesRuntime : public jsi::Runtime,
|
|
198
|
+
public IHermes,
|
|
199
|
+
public IHermesSHUnit {
|
|
200
|
+
public:
|
|
201
|
+
/// Similar to jsi::Runtime, HermesRuntime is treated as an object, rather
|
|
202
|
+
/// than a pure interface. This is to prevent breaking usages of
|
|
203
|
+
/// HermesRuntime prior to the introduction of jsi::IRuntime, IHermes, and
|
|
204
|
+
/// other interfaces.
|
|
205
|
+
~HermesRuntime() override = default;
|
|
206
|
+
|
|
207
|
+
using jsi::Runtime::castInterface;
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
/// Returns a pointer to an object that can be cast into IHermesRootAPI, which
|
|
211
|
+
/// can be used to create a Hermes runtime and to access global Hermes-specific
|
|
212
|
+
/// methods. This object has static lifetime.
|
|
213
|
+
HERMES_EXPORT jsi::ICast *makeHermesRootAPI();
|
|
214
|
+
|
|
215
|
+
/// Return a RuntimeConfig that is more suited for running untrusted JS than
|
|
216
|
+
/// the default config. Disables some language features and may trade off some
|
|
217
|
+
/// performance for security.
|
|
218
|
+
///
|
|
219
|
+
/// Can serve as a starting point with tweaks to re-enable needed features:
|
|
220
|
+
/// auto conf = hardenedHermesRuntimeConfig().rebuild();
|
|
221
|
+
/// conf.withArrayBuffer(true);
|
|
222
|
+
/// ...
|
|
223
|
+
/// auto runtime = makeHermesRuntime(conf.build());
|
|
224
|
+
HERMES_EXPORT ::hermes::vm::RuntimeConfig hardenedHermesRuntimeConfig();
|
|
225
|
+
|
|
226
|
+
HERMES_EXPORT std::unique_ptr<HermesRuntime> makeHermesRuntime(
|
|
227
|
+
const ::hermes::vm::RuntimeConfig &runtimeConfig =
|
|
228
|
+
::hermes::vm::RuntimeConfig());
|
|
229
|
+
|
|
230
|
+
/// Create a HermesRuntime for the given config without throwing any exceptions.
|
|
231
|
+
/// This is safe to be called from code that is compiled without exceptions.
|
|
232
|
+
/// Returns nullptr on failure.
|
|
233
|
+
HERMES_EXPORT std::unique_ptr<HermesRuntime> makeHermesRuntimeNoThrow(
|
|
234
|
+
const ::hermes::vm::RuntimeConfig &runtimeConfig =
|
|
235
|
+
::hermes::vm::RuntimeConfig()) noexcept;
|
|
236
|
+
|
|
237
|
+
HERMES_EXPORT std::unique_ptr<jsi::ThreadSafeRuntime>
|
|
238
|
+
makeThreadSafeHermesRuntime(
|
|
239
|
+
const ::hermes::vm::RuntimeConfig &runtimeConfig =
|
|
240
|
+
::hermes::vm::RuntimeConfig());
|
|
241
|
+
} // namespace hermes
|
|
242
|
+
} // namespace facebook
|