@elurjs/android 0.0.0-stage → 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.
Files changed (145) hide show
  1. package/README.md +10 -2
  2. package/index.mjs +11 -0
  3. package/package.json +29 -4
  4. package/template/.gitkeep +0 -0
  5. package/template/app/build.gradle.kts +192 -0
  6. package/template/app/proguard-rules-elur.pro +12 -0
  7. package/template/app/proguard-rules.pro +3 -0
  8. package/template/app/src/main/AndroidManifest.xml +81 -0
  9. package/template/app/src/main/assets/oss-notices.txt +153 -0
  10. package/template/app/src/main/assets/tck_pixel.png +0 -0
  11. package/template/app/src/main/cpp/CMakeLists.txt +117 -0
  12. package/template/app/src/main/cpp/dlEncoder.h +117 -0
  13. package/template/app/src/main/cpp/dlEncoderJsi.cpp +315 -0
  14. package/template/app/src/main/cpp/dlEncoderQjs.cpp +394 -0
  15. package/template/app/src/main/cpp/dlOps.inc +145 -0
  16. package/template/app/src/main/cpp/elurBridge.cpp +1350 -0
  17. package/template/app/src/main/cpp/elurBridgeHermes.cpp +1294 -0
  18. package/template/app/src/main/cpp/elurSkia.cpp +287 -0
  19. package/template/app/src/main/cpp/elurSkiaTree.cpp +448 -0
  20. package/template/app/src/main/cpp/elurUiWorklet.cpp +1233 -0
  21. package/template/app/src/main/cpp/elurYoga.cpp +1060 -0
  22. package/template/app/src/main/cpp/elurYoga.h +82 -0
  23. package/template/app/src/main/cpp/hermes-libs/LICENSE +21 -0
  24. package/template/app/src/main/cpp/hermes-libs/arm64-v8a/libhermesvm.so +0 -0
  25. package/template/app/src/main/cpp/hermes-libs/include/hermes/AsyncDebuggerAPI.h +276 -0
  26. package/template/app/src/main/cpp/hermes-libs/include/hermes/CompileJS.h +97 -0
  27. package/template/app/src/main/cpp/hermes-libs/include/hermes/DebuggerAPI.h +502 -0
  28. package/template/app/src/main/cpp/hermes-libs/include/hermes/Public/CrashManager.h +107 -0
  29. package/template/app/src/main/cpp/hermes-libs/include/hermes/Public/CtorConfig.h +145 -0
  30. package/template/app/src/main/cpp/hermes-libs/include/hermes/Public/DebuggerTypes.h +193 -0
  31. package/template/app/src/main/cpp/hermes-libs/include/hermes/Public/GCConfig.h +211 -0
  32. package/template/app/src/main/cpp/hermes-libs/include/hermes/Public/GCTripwireContext.h +40 -0
  33. package/template/app/src/main/cpp/hermes-libs/include/hermes/Public/HermesExport.h +14 -0
  34. package/template/app/src/main/cpp/hermes-libs/include/hermes/Public/JSOutOfMemoryError.h +27 -0
  35. package/template/app/src/main/cpp/hermes-libs/include/hermes/Public/RuntimeConfig.h +141 -0
  36. package/template/app/src/main/cpp/hermes-libs/include/hermes/Public/SamplingProfiler.h +270 -0
  37. package/template/app/src/main/cpp/hermes-libs/include/hermes/RuntimeTaskRunner.h +64 -0
  38. package/template/app/src/main/cpp/hermes-libs/include/hermes/SynthTrace.h +1566 -0
  39. package/template/app/src/main/cpp/hermes-libs/include/hermes/SynthTraceParser.h +37 -0
  40. package/template/app/src/main/cpp/hermes-libs/include/hermes/ThreadSafetyAnalysis.h +75 -0
  41. package/template/app/src/main/cpp/hermes-libs/include/hermes/TimerStats.h +23 -0
  42. package/template/app/src/main/cpp/hermes-libs/include/hermes/TraceInterpreter.h +334 -0
  43. package/template/app/src/main/cpp/hermes-libs/include/hermes/TracingRuntime.h +328 -0
  44. package/template/app/src/main/cpp/hermes-libs/include/hermes/cdp/CDPAgent.h +131 -0
  45. package/template/app/src/main/cpp/hermes-libs/include/hermes/cdp/CDPDebugAPI.h +73 -0
  46. package/template/app/src/main/cpp/hermes-libs/include/hermes/cdp/CallbackOStream.h +89 -0
  47. package/template/app/src/main/cpp/hermes-libs/include/hermes/cdp/ConsoleMessage.h +135 -0
  48. package/template/app/src/main/cpp/hermes-libs/include/hermes/cdp/DebuggerDomainAgent.h +280 -0
  49. package/template/app/src/main/cpp/hermes-libs/include/hermes/cdp/DebuggerDomainCoordinator.h +137 -0
  50. package/template/app/src/main/cpp/hermes-libs/include/hermes/cdp/DomainAgent.h +107 -0
  51. package/template/app/src/main/cpp/hermes-libs/include/hermes/cdp/DomainState.h +140 -0
  52. package/template/app/src/main/cpp/hermes-libs/include/hermes/cdp/HeapProfilerDomainAgent.h +71 -0
  53. package/template/app/src/main/cpp/hermes-libs/include/hermes/cdp/JSONValueInterfaces.h +40 -0
  54. package/template/app/src/main/cpp/hermes-libs/include/hermes/cdp/MessageConverters.h +82 -0
  55. package/template/app/src/main/cpp/hermes-libs/include/hermes/cdp/MessageInterfaces.h +72 -0
  56. package/template/app/src/main/cpp/hermes-libs/include/hermes/cdp/MessageTypes.h +1279 -0
  57. package/template/app/src/main/cpp/hermes-libs/include/hermes/cdp/MessageTypesInlines.h +313 -0
  58. package/template/app/src/main/cpp/hermes-libs/include/hermes/cdp/ProfilerDomainAgent.h +38 -0
  59. package/template/app/src/main/cpp/hermes-libs/include/hermes/cdp/RemoteObjectConverters.h +77 -0
  60. package/template/app/src/main/cpp/hermes-libs/include/hermes/cdp/RemoteObjectsTable.h +127 -0
  61. package/template/app/src/main/cpp/hermes-libs/include/hermes/cdp/RuntimeDomainAgent.h +138 -0
  62. package/template/app/src/main/cpp/hermes-libs/include/hermes/extensions/Dummy.h +24 -0
  63. package/template/app/src/main/cpp/hermes-libs/include/hermes/extensions/Extensions.h +20 -0
  64. package/template/app/src/main/cpp/hermes-libs/include/hermes/extensions/ExtensionsBytecode.h +23 -0
  65. package/template/app/src/main/cpp/hermes-libs/include/hermes/extensions/Intrinsics.h +44 -0
  66. package/template/app/src/main/cpp/hermes-libs/include/hermes/extensions/JSIUtils.h +123 -0
  67. package/template/app/src/main/cpp/hermes-libs/include/hermes/extensions/TextEncoder.h +29 -0
  68. package/template/app/src/main/cpp/hermes-libs/include/hermes/extensions/contrib/ContribDummy.h +24 -0
  69. package/template/app/src/main/cpp/hermes-libs/include/hermes/extensions/contrib/ContribExtensions.h +23 -0
  70. package/template/app/src/main/cpp/hermes-libs/include/hermes/extensions/contrib/TextDecoder.h +30 -0
  71. package/template/app/src/main/cpp/hermes-libs/include/hermes/extensions/contrib/TextDecoderUtils.h +113 -0
  72. package/template/app/src/main/cpp/hermes-libs/include/hermes/hermes.h +242 -0
  73. package/template/app/src/main/cpp/hermes-libs/include/hermes/hermes_tracing.h +52 -0
  74. package/template/app/src/main/cpp/hermes-libs/include/hermes_abi/HermesABIHelpers.h +295 -0
  75. package/template/app/src/main/cpp/hermes-libs/include/hermes_abi/HermesABIRuntimeWrapper.h +25 -0
  76. package/template/app/src/main/cpp/hermes-libs/include/hermes_abi/hermes_abi.h +642 -0
  77. package/template/app/src/main/cpp/hermes-libs/include/hermes_abi/hermes_vtable.h +29 -0
  78. package/template/app/src/main/cpp/hermes-libs/include/hermes_sandbox/HermesSandboxRuntime.h +41 -0
  79. package/template/app/src/main/cpp/hermes-libs/include/hermes_sandbox/external/hermes_sandbox_impl_compiled.h +12 -0
  80. package/template/app/src/main/cpp/hermes-libs/include/hermes_sandbox/external/hermes_sandbox_impl_dbg_compiled-impl.h +8516 -0
  81. package/template/app/src/main/cpp/hermes-libs/include/hermes_sandbox/external/hermes_sandbox_impl_dbg_compiled.h +137 -0
  82. package/template/app/src/main/cpp/hermes-libs/include/hermes_sandbox/external/hermes_sandbox_impl_opt_compiled-impl.h +3945 -0
  83. package/template/app/src/main/cpp/hermes-libs/include/hermes_sandbox/external/hermes_sandbox_impl_opt_compiled.h +119 -0
  84. package/template/app/src/main/cpp/hermes-libs/include/hermes_sandbox/external/wasm-rt-fb.h +124 -0
  85. package/template/app/src/main/cpp/hermes-libs/include/hermes_sandbox/external/wasm-rt-impl.h +66 -0
  86. package/template/app/src/main/cpp/hermes-libs/include/hermes_sandbox/external/wasm-rt.h +456 -0
  87. package/template/app/src/main/cpp/hermes-libs/include/jsi/JSIDynamic.h +26 -0
  88. package/template/app/src/main/cpp/hermes-libs/include/jsi/decorator.h +1157 -0
  89. package/template/app/src/main/cpp/hermes-libs/include/jsi/hermes-interfaces.h +242 -0
  90. package/template/app/src/main/cpp/hermes-libs/include/jsi/instrumentation.h +132 -0
  91. package/template/app/src/main/cpp/hermes-libs/include/jsi/jsi-inl.h +434 -0
  92. package/template/app/src/main/cpp/hermes-libs/include/jsi/jsi.h +2266 -0
  93. package/template/app/src/main/cpp/hermes-libs/include/jsi/jsilib.h +59 -0
  94. package/template/app/src/main/cpp/hermes-libs/include/jsi/threadsafe.h +79 -0
  95. package/template/app/src/main/cpp/hermes-libs/jsi-impl/jsi.cpp +1111 -0
  96. package/template/app/src/main/cpp/hermes-libs/x86_64/libhermesvm.so +0 -0
  97. package/template/app/src/main/java/com/elur/universal/BinaryCodec.kt +121 -0
  98. package/template/app/src/main/java/com/elur/universal/DlDecoder.kt +260 -0
  99. package/template/app/src/main/java/com/elur/universal/DlOpsDecode.kt +158 -0
  100. package/template/app/src/main/java/com/elur/universal/ElurBoxDrawable.kt +161 -0
  101. package/template/app/src/main/java/com/elur/universal/ElurBridge.kt +238 -0
  102. package/template/app/src/main/java/com/elur/universal/ElurBridgeHermes.kt +223 -0
  103. package/template/app/src/main/java/com/elur/universal/ElurCanvasView.kt +202 -0
  104. package/template/app/src/main/java/com/elur/universal/ElurCryptoModule.kt +206 -0
  105. package/template/app/src/main/java/com/elur/universal/ElurCustomLayout.kt +185 -0
  106. package/template/app/src/main/java/com/elur/universal/ElurEditText.kt +17 -0
  107. package/template/app/src/main/java/com/elur/universal/ElurFontRegistry.kt +190 -0
  108. package/template/app/src/main/java/com/elur/universal/ElurHttpModule.kt +306 -0
  109. package/template/app/src/main/java/com/elur/universal/ElurImageService.kt +348 -0
  110. package/template/app/src/main/java/com/elur/universal/ElurLicensesActivity.kt +84 -0
  111. package/template/app/src/main/java/com/elur/universal/ElurListView.kt +954 -0
  112. package/template/app/src/main/java/com/elur/universal/ElurManifest.kt +117 -0
  113. package/template/app/src/main/java/com/elur/universal/ElurMetrics.kt +325 -0
  114. package/template/app/src/main/java/com/elur/universal/ElurModuleRegistrar.kt +14 -0
  115. package/template/app/src/main/java/com/elur/universal/ElurPermissionGate.kt +36 -0
  116. package/template/app/src/main/java/com/elur/universal/ElurRenderer.kt +6164 -0
  117. package/template/app/src/main/java/com/elur/universal/ElurRowYoga.kt +130 -0
  118. package/template/app/src/main/java/com/elur/universal/ElurScrollView.kt +240 -0
  119. package/template/app/src/main/java/com/elur/universal/ElurShellView.kt +117 -0
  120. package/template/app/src/main/java/com/elur/universal/ElurSkiaCanvasView.kt +162 -0
  121. package/template/app/src/main/java/com/elur/universal/ElurSkiaTreeRenderer.kt +968 -0
  122. package/template/app/src/main/java/com/elur/universal/ElurStateModule.kt +69 -0
  123. package/template/app/src/main/java/com/elur/universal/ElurSwipeDriver.kt +34 -0
  124. package/template/app/src/main/java/com/elur/universal/ElurTckModule.kt +99 -0
  125. package/template/app/src/main/java/com/elur/universal/ElurTextMeasure.kt +16 -0
  126. package/template/app/src/main/java/com/elur/universal/ElurTrace.kt +24 -0
  127. package/template/app/src/main/java/com/elur/universal/ElurUiModule.kt +48 -0
  128. package/template/app/src/main/java/com/elur/universal/ElurUiWorklet.kt +305 -0
  129. package/template/app/src/main/java/com/elur/universal/JsBridge.kt +67 -0
  130. package/template/app/src/main/java/com/elur/universal/JsThread.kt +189 -0
  131. package/template/app/src/main/java/com/elur/universal/MainActivity.kt +844 -0
  132. package/template/app/src/main/java/com/elur/universal/ModuleRegistry.kt +701 -0
  133. package/template/app/src/main/java/com/elur/universal/YogaRowScope.kt +97 -0
  134. package/template/app/src/main/res/values/ids.xml +10 -0
  135. package/template/app/src/main/res/values/strings.xml +8 -0
  136. package/template/app/src/main/res/values-es/strings.xml +5 -0
  137. package/template/app/src/main/res/xml/network_security_config.xml +10 -0
  138. package/template/build.gradle.kts +5 -0
  139. package/template/gradle/libs.versions.toml +12 -0
  140. package/template/gradle/wrapper/gradle-wrapper.jar +0 -0
  141. package/template/gradle/wrapper/gradle-wrapper.properties +8 -0
  142. package/template/gradle.properties +23 -0
  143. package/template/gradlew +251 -0
  144. package/template/gradlew.bat +94 -0
  145. package/template/settings.gradle.kts +32 -0
@@ -0,0 +1,141 @@
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/CrashManager.h"
11
+ #include "hermes/Public/CtorConfig.h"
12
+ #include "hermes/Public/GCConfig.h"
13
+
14
+ #include <cstdint>
15
+ #include <memory>
16
+
17
+ namespace hermes {
18
+ namespace vm {
19
+
20
+ enum CompilationMode {
21
+ SmartCompilation,
22
+ ForceEagerCompilation,
23
+ ForceLazyCompilation
24
+ };
25
+
26
+ enum class SynthTraceMode : int8_t {
27
+ None,
28
+ Replaying,
29
+ Tracing,
30
+ TracingAndReplaying,
31
+ };
32
+
33
+ class PinnedHermesValue;
34
+
35
+ // Parameters for Runtime initialisation. Check documentation in README.md
36
+ // constexpr indicates that the default value is constexpr.
37
+ #define RUNTIME_FIELDS(F) \
38
+ /* Parameters to be passed on to the GC. */ \
39
+ F(HERMES_NON_CONSTEXPR, vm::GCConfig, GCConfig) \
40
+ \
41
+ /* Pre-allocated Register Stack */ \
42
+ F(constexpr, PinnedHermesValue *, RegisterStack, nullptr) \
43
+ \
44
+ /* Register Stack Size */ \
45
+ F(constexpr, unsigned, MaxNumRegisters, 128 * 1024) \
46
+ \
47
+ /* Native stack remaining before assuming overflow */ \
48
+ F(constexpr, unsigned, NativeStackGap, 64 * 1024) \
49
+ \
50
+ /* Whether or not the JIT is enabled */ \
51
+ F(constexpr, bool, EnableJIT, false) \
52
+ \
53
+ /* Whether to allow eval and Function ctor */ \
54
+ F(constexpr, bool, EnableEval, true) \
55
+ \
56
+ /* Whether to verify the IR generated by eval and Function ctor */ \
57
+ F(constexpr, bool, VerifyEvalIR, false) \
58
+ \
59
+ /* Whether to optimize the code inside eval and Function ctor */ \
60
+ F(constexpr, bool, OptimizedEval, false) \
61
+ \
62
+ /* Whether to emit async break check instructions in eval code */ \
63
+ F(constexpr, bool, AsyncBreakCheckInEval, true) \
64
+ \
65
+ /* Support for ES6 Proxy. */ \
66
+ F(constexpr, bool, ES6Proxy, true) \
67
+ \
68
+ /* Support for ES6 block scoping. */ \
69
+ F(constexpr, bool, ES6BlockScoping, false) \
70
+ \
71
+ /* Support for async generators in eval. */ \
72
+ F(constexpr, bool, EnableAsyncGenerators, false) \
73
+ \
74
+ /* Support for ECMA-402 Intl APIs. */ \
75
+ F(constexpr, bool, Intl, true) \
76
+ \
77
+ /* Support for using microtasks. */ \
78
+ F(constexpr, bool, MicrotaskQueue, false) \
79
+ \
80
+ /* Runtime set up for synth trace. */ \
81
+ F(constexpr, SynthTraceMode, SynthTraceMode, SynthTraceMode::None) \
82
+ \
83
+ /* Enable sampling certain statistics. */ \
84
+ F(constexpr, bool, EnableSampledStats, false) \
85
+ \
86
+ /* Whether to enable automatic sampling profiler registration */ \
87
+ F(constexpr, bool, EnableSampleProfiling, false) \
88
+ \
89
+ /* Whether to randomize stack placement etc. */ \
90
+ F(constexpr, bool, RandomizeMemoryLayout, false) \
91
+ \
92
+ /* Eagerly read bytecode into page cache. */ \
93
+ F(constexpr, unsigned, BytecodeWarmupPercent, 0) \
94
+ \
95
+ /* Signal-based I/O tracking. Slows down execution. If enabled, */ \
96
+ /* all bytecode buffers > 64 kB passed to Hermes must be mmap:ed. */ \
97
+ F(constexpr, bool, TrackIO, false) \
98
+ \
99
+ /* Enable contents of HermesInternal */ \
100
+ F(constexpr, bool, EnableHermesInternal, true) \
101
+ \
102
+ /* Enable methods exposed to JS for testing */ \
103
+ F(constexpr, bool, EnableHermesInternalTestMethods, false) \
104
+ \
105
+ /* Choose lazy/eager compilation mode. */ \
106
+ F(constexpr, \
107
+ CompilationMode, \
108
+ CompilationMode, \
109
+ CompilationMode::SmartCompilation) \
110
+ \
111
+ /* Choose whether generators are enabled. */ \
112
+ F(constexpr, bool, EnableGenerator, true) \
113
+ \
114
+ /* An interface for managing crashes. */ \
115
+ F(HERMES_NON_CONSTEXPR, \
116
+ std::shared_ptr<CrashManager>, \
117
+ CrashMgr, \
118
+ new NopCrashManager) \
119
+ \
120
+ /* The flags passed from a VM experiment */ \
121
+ F(constexpr, uint32_t, VMExperimentFlags, 0) \
122
+ \
123
+ /* Force JIT compilation on all functions. */ \
124
+ F(constexpr, bool, ForceJIT, false) \
125
+ \
126
+ /* JIT compilation threshold (number of calls before JIT'ing). */ \
127
+ F(constexpr, uint32_t, JITThreshold, 1 << 5) \
128
+ \
129
+ /* JIT memory limit, after which no more code will be JIT'ed. */ \
130
+ F(constexpr, uint32_t, JITMemoryLimit, 32u << 20) \
131
+ \
132
+ /* Increase compliance with test262 (stricter checks at runtime). */ \
133
+ F(constexpr, bool, Test262, false) \
134
+ /* RUNTIME_FIELDS END */
135
+
136
+ _HERMES_CTORCONFIG_STRUCT(RuntimeConfig, RUNTIME_FIELDS, {})
137
+
138
+ #undef RUNTIME_FIELDS
139
+
140
+ } // namespace vm
141
+ } // namespace hermes
@@ -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,64 @@
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/AsyncDebuggerAPI.h>
11
+
12
+ namespace facebook {
13
+ namespace hermes {
14
+ namespace debugger {
15
+
16
+ using RuntimeTask = std::function<void(HermesRuntime &)>;
17
+ using EnqueueRuntimeTaskFunc = std::function<void(RuntimeTask)>;
18
+
19
+ enum class TaskQueues {
20
+ All,
21
+ Integrator,
22
+ };
23
+
24
+ /// Helper for users of AsyncDebuggerAPI that makes it easy to find the
25
+ /// earliest opportunity to use the runtime. There are two ways to become
26
+ /// the exclusive user of the runtime:
27
+ /// - Ask the AsyncDebuggerAPI to interrupt execution and provide a reference
28
+ /// to the runtime. Interrupting will only succeed when JavaScript is
29
+ /// running, so this method won't produce a prompt response if JavaScript is
30
+ /// not running.
31
+ /// - Ask the owner of the runtime to provide a reference to the runtime. If
32
+ /// the owner is currently running JavaScript (e.g. via a call to
33
+ /// evaluateJavaScript), this method won't produce a prompt response.
34
+ /// To cover both cases (when JavaScript is running, and when JavaScript isn't
35
+ /// running), this helper requests the runtime from both sources, executes the
36
+ /// task via the first responder, and sets a flag to indicate to the second
37
+ /// responder that nothing more needs to be done.
38
+ class RuntimeTaskRunner
39
+ : public std::enable_shared_from_this<RuntimeTaskRunner> {
40
+ public:
41
+ RuntimeTaskRunner(
42
+ debugger::AsyncDebuggerAPI &debugger,
43
+ EnqueueRuntimeTaskFunc enqueueRuntimeTaskFunc);
44
+ ~RuntimeTaskRunner();
45
+
46
+ /// Schedule a task to be run with access to the runtime at the earliest
47
+ /// opportunity. Before returning, the task is added to the relevant task
48
+ /// queues managed by the \p AsyncDebuggerAPI and/or the intergator, with no
49
+ /// lingering references to the \p RuntimeTaskRunner. Thus, tasks can be
50
+ /// enqueued even if the task runner will be destroyed shortly after.
51
+ void enqueueTask(RuntimeTask task, TaskQueues queues = TaskQueues::All);
52
+
53
+ private:
54
+ /// API where the runtime can be obtained when JavaScript is running.
55
+ debugger::AsyncDebuggerAPI &debugger_;
56
+
57
+ /// Function provided by the integrator that enqueues a task to be run
58
+ /// when JavaScript is not running.
59
+ EnqueueRuntimeTaskFunc enqueueRuntimeTask_;
60
+ };
61
+
62
+ } // namespace debugger
63
+ } // namespace hermes
64
+ } // namespace facebook