@nativue/core 0.1.0 → 0.2.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.
@@ -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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nativue/core",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Vue rendering real native views on iOS and Android",
5
5
  "keywords": [
6
6
  "vue",