react-nitro-hermes 0.0.1-alpha.8 → 0.0.1-alpha.9

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 (181) hide show
  1. package/hermes/CMakeLists.txt +874 -0
  2. package/hermes/android/HostObjectJniTest.cpp +178 -0
  3. package/hermes/android/build-logic/build.gradle.kts +31 -0
  4. package/hermes/android/build-logic/settings.gradle.kts +17 -0
  5. package/hermes/android/build-logic/src/main/kotlin/com/facebook/hermes/helpers/internal/SerializeHermesCompilerPackageJson.kt +33 -0
  6. package/hermes/android/build-logic/src/main/kotlin/com/facebook/hermes/plugins/internal/TestUtilsPlugin.kt +80 -0
  7. package/hermes/android/build-logic/src/main/kotlin/com/facebook/hermes/tasks/internal/CustomExecTask.kt +46 -0
  8. package/hermes/android/build-logic/src/main/kotlin/publish.gradle.kts +82 -0
  9. package/hermes/android/build.gradle.kts +332 -0
  10. package/hermes/android/cppruntime/build.gradle +72 -0
  11. package/hermes/android/cppruntime/src/main/AndroidManifest.xml +2 -0
  12. package/hermes/android/cppruntime/src/main/cpp/CMakeLists.txt +8 -0
  13. package/hermes/android/cppruntime/src/main/cpp/stub.cpp +12 -0
  14. package/hermes/android/cross-compile/swift-libicu.patch +13 -0
  15. package/hermes/android/cross-compile/toolchain-android-arm-api13-gnustl.cmake +13 -0
  16. package/hermes/android/cross-compile/toolchain-android-arm-api15-gnustl.cmake +14 -0
  17. package/hermes/android/gradle/libs.versions.toml +30 -0
  18. package/hermes/android/gradle/wrapper/gradle-wrapper.jar +0 -0
  19. package/hermes/android/gradle/wrapper/gradle-wrapper.properties +7 -0
  20. package/hermes/android/gradle.properties +3 -0
  21. package/hermes/android/gradlew +248 -0
  22. package/hermes/android/gradlew.bat +93 -0
  23. package/hermes/android/intltest/build.gradle +147 -0
  24. package/hermes/android/intltest/java/com/facebook/hermes/test/CMakeLists.txt +45 -0
  25. package/hermes/android/intltest/java/com/facebook/hermes/test/HermesEpilogue.cpp +68 -0
  26. package/hermes/android/intltest/java/com/facebook/hermes/test/HermesEpilogue.h +44 -0
  27. package/hermes/android/intltest/java/com/facebook/hermes/test/HermesEpilogue.java +45 -0
  28. package/hermes/android/intltest/java/com/facebook/hermes/test/HermesEpilogueTestData.java +32 -0
  29. package/hermes/android/intltest/java/com/facebook/hermes/test/HermesInstrumentationTest.java +150 -0
  30. package/hermes/android/intltest/java/com/facebook/hermes/test/HermesIntlAndroidTest.java +147 -0
  31. package/hermes/android/intltest/java/com/facebook/hermes/test/HermesIntlTest262.java +470 -0
  32. package/hermes/android/intltest/java/com/facebook/hermes/test/HermesRuntimeFactory.cpp +73 -0
  33. package/hermes/android/intltest/java/com/facebook/hermes/test/JSRuntime.cpp +90 -0
  34. package/hermes/android/intltest/java/com/facebook/hermes/test/JSRuntime.h +62 -0
  35. package/hermes/android/intltest/java/com/facebook/hermes/test/JSRuntime.java +155 -0
  36. package/hermes/android/intltest/java/com/facebook/hermes/test/MappedFileBuffer.cpp +48 -0
  37. package/hermes/android/intltest/java/com/facebook/hermes/test/MappedFileBuffer.h +36 -0
  38. package/hermes/android/intltest/java/com/facebook/hermes/test/OnLoad.cpp +13 -0
  39. package/hermes/android/intltest/java/com/facebook/hermes/test/OnLoadEpilogue.cpp +13 -0
  40. package/hermes/android/intltest/src/main/AndroidManifest.xml +2 -0
  41. package/hermes/android/ios-artifacts/build.gradle.kts +65 -0
  42. package/hermes/android/settings.gradle.kts +27 -0
  43. package/hermes/cmake/modules/Hermes.cmake +481 -0
  44. package/hermes/cmake/modules/Lit.cmake +96 -0
  45. package/hermes/doc/Branches.md +38 -0
  46. package/hermes/doc/BuildingAndRunning.md +121 -0
  47. package/hermes/doc/CodingStandards.md +112 -0
  48. package/hermes/doc/CrossCompilation.md +79 -0
  49. package/hermes/doc/Design.md +217 -0
  50. package/hermes/doc/Emscripten.md +156 -0
  51. package/hermes/doc/Features.md +143 -0
  52. package/hermes/doc/GCSafeCoding.md +563 -0
  53. package/hermes/doc/GenGC.md +300 -0
  54. package/hermes/doc/Hades.md +344 -0
  55. package/hermes/doc/HighLevelOptimizations.md +37 -0
  56. package/hermes/doc/IR.md +1306 -0
  57. package/hermes/doc/IntlAPIs.md +196 -0
  58. package/hermes/doc/JIT.md +999 -0
  59. package/hermes/doc/LazyEvalCompilation.md +84 -0
  60. package/hermes/doc/MemoryProfilers.md +316 -0
  61. package/hermes/doc/Modules.md +144 -0
  62. package/hermes/doc/Optimizer.md +83 -0
  63. package/hermes/doc/PerfProfiling.md +29 -0
  64. package/hermes/doc/ProhibitInvoke.md +329 -0
  65. package/hermes/doc/ReactNative.md +40 -0
  66. package/hermes/doc/ReactNativeIntegration.md +94 -0
  67. package/hermes/doc/RegExp.md +24 -0
  68. package/hermes/doc/SpecIncompat.md +85 -0
  69. package/hermes/doc/Strings.md +140 -0
  70. package/hermes/doc/TypedLanguage.md +432 -0
  71. package/hermes/doc/VM.md +174 -0
  72. package/hermes/doc/blog/2024-11-09-octane-benchmark-jit-progress.md +17 -0
  73. package/hermes/doc/blog/2024-12-19-static-hermes-update-dec-2024.md +47 -0
  74. package/hermes/doc/blog/2024-12-23-compiling-javascript-to-wasm.md +267 -0
  75. package/hermes/doc/blog/2025-06-09-jsi-runtime-data-apis.md +23 -0
  76. package/hermes/doc/blog/2025-07-15-static-h-performance-june-2025.md +18 -0
  77. package/hermes/doc/blog/2025-11-02-hermes-compilation-runtime-modes.md +23 -0
  78. package/hermes/doc/blog/2025-11-06-hermes-memory-modes.md +35 -0
  79. package/hermes/doc/blog/2025-11-24-json-parsing-performance.md +17 -0
  80. package/hermes/doc/blog/2025-12-02-iserialization.md +11 -0
  81. package/hermes/doc/blog/2025-12-12-new-way-to-contribute.md +68 -0
  82. package/hermes/doc/blog/2026-06-05-new-hermes-stable-release.md +51 -0
  83. package/hermes/doc/blog/README.md +25 -0
  84. package/hermes/doc/blog/images/2024-11-09-octane-pi3.jpeg +0 -0
  85. package/hermes/doc/blog/images/2024-11-09-octane-pi5.jpeg +0 -0
  86. package/hermes/doc/blog/images/2025-07-15-perf-hv32-interpreter.jpeg +0 -0
  87. package/hermes/doc/blog/images/2025-07-15-perf-hv32-jit.jpeg +0 -0
  88. package/hermes/doc/icu_license.txt +420 -0
  89. package/hermes/doc/img/heap_snapshot_retainers.png +0 -0
  90. package/hermes/doc/img/logo.svg +1 -0
  91. package/hermes/doc/img/object_captured_by_environment.png +0 -0
  92. package/hermes/doc/img/root_categories.png +0 -0
  93. package/hermes/doc/plans/ir-type/flow-type-system.md +324 -0
  94. package/hermes/doc/plans/ir-type/ir-type-system-v2-design.md +652 -0
  95. package/hermes/doc/plans/ir-type/ir-type-system.md +220 -0
  96. package/hermes/doc/plans/ir-type/ir-type-v2-implementation.md +1187 -0
  97. package/hermes/doc/plans/ir-type/memory.md +48 -0
  98. package/hermes/doc/plans/ir-type/phase1-steps.md +512 -0
  99. package/hermes/doc/plans/ir-type/progress.md +239 -0
  100. package/hermes/doc/plans/ir-type/typeinference-primitive-fastpath-design.md +203 -0
  101. package/hermes/doc/plans/ir-type/typeinference-primitive-fastpath-results.md +71 -0
  102. package/hermes/doc/superpowers/plans/2026-07-28-worker-arraybuffer-input.md +597 -0
  103. package/hermes/doc/superpowers/plans/2026-08-18-jitemitter-split.md +1149 -0
  104. package/hermes/doc/superpowers/plans/2026-08-20-jit-type-asserts.md +969 -0
  105. package/hermes/doc/superpowers/plans/2026-08-23-jit-shared-compiler-driver.md +478 -0
  106. package/hermes/doc/superpowers/plans/2026-08-23-x86-64-jit-skeleton.md +797 -0
  107. package/hermes/doc/superpowers/plans/2026-08-24-x86-64-jit-arith.md +444 -0
  108. package/hermes/doc/superpowers/plans/2026-08-24-x86-64-jit-calls.md +261 -0
  109. package/hermes/doc/superpowers/plans/2026-08-24-x86-64-jit-props.md +240 -0
  110. package/hermes/doc/superpowers/plans/2026-10-26-regexp-bytecode-sharing.md +2197 -0
  111. package/hermes/doc/superpowers/plans/2026-10-28-regexp-start-filter-and-exec-fast-paths.md +3981 -0
  112. package/hermes/doc/superpowers/specs/2026-07-28-worker-arraybuffer-input-design.md +206 -0
  113. package/hermes/doc/superpowers/specs/2026-08-18-jitemitter-split-design.md +530 -0
  114. package/hermes/doc/superpowers/specs/2026-08-20-jit-type-asserts-design.md +360 -0
  115. package/hermes/doc/superpowers/specs/2026-08-23-x86-64-jit-design.md +246 -0
  116. package/hermes/doc/superpowers/specs/2026-08-26-icu-free-normalize-design.md +355 -0
  117. package/hermes/doc/superpowers/specs/2026-08-27-icu-free-convert-to-case-design.md +305 -0
  118. package/hermes/doc/superpowers/specs/2026-08-27-icu-free-locale-compare-design.md +429 -0
  119. package/hermes/doc/superpowers/specs/2026-08-29-icu-free-date-format-design.md +297 -0
  120. package/hermes/doc/superpowers/specs/2026-10-26-regexp-bytecode-sharing-design.md +605 -0
  121. package/hermes/doc/superpowers/specs/2026-10-28-regexp-start-filter-and-exec-fast-paths-design.md +551 -0
  122. package/hermes/doc/typescript-stripping.md +90 -0
  123. package/hermes/external/CMakeLists.txt +20 -0
  124. package/hermes/utils/IntlGen/IntlGen.java +531 -0
  125. package/hermes/utils/bench_with_stats.py +827 -0
  126. package/hermes/utils/build-apple-framework.sh +323 -0
  127. package/hermes/utils/chrome_snapshot_parser.py +210 -0
  128. package/hermes/utils/cmake-dev-build.sh +18 -0
  129. package/hermes/utils/commons.sh +55 -0
  130. package/hermes/utils/dump-cpp-funcs.sh +3 -0
  131. package/hermes/utils/es5objects.js +198 -0
  132. package/hermes/utils/format.sh +145 -0
  133. package/hermes/utils/gen-promise-internal-bc.sh +66 -0
  134. package/hermes/utils/genUnicodeTable.py +2503 -0
  135. package/hermes/utils/hermes-lit/CMakeLists.txt +22 -0
  136. package/hermes/utils/hermes-lit/hermes-lit.in +15 -0
  137. package/hermes/utils/jit/README.md +134 -0
  138. package/hermes/utils/jit/jit-diff.sh +160 -0
  139. package/hermes/utils/jit/jit-dump.sh +193 -0
  140. package/hermes/utils/lit-expect-gen/generate.py +217 -0
  141. package/hermes/utils/promise/index.js +15 -0
  142. package/hermes/utils/promise/package.json +13 -0
  143. package/hermes/utils/promise/rollup.config.js +19 -0
  144. package/hermes/utils/promise/yarn.lock +247 -0
  145. package/hermes/utils/scripts/hermes/consts.js +26 -0
  146. package/hermes/utils/scripts/hermes/create-tarball.js +75 -0
  147. package/hermes/utils/scripts/hermes/get-hermes-version.js +57 -0
  148. package/hermes/utils/scripts/hermes/hermes-utils.js +122 -0
  149. package/hermes/utils/scripts/hermes/package.json +6 -0
  150. package/hermes/utils/scripts/hermes/prepare-artifacts.js +113 -0
  151. package/hermes/utils/scripts/hermes/publish-artifacts.js +109 -0
  152. package/hermes/utils/scripts/hermes/publish-npm.js +96 -0
  153. package/hermes/utils/scripts/hermes/scm-utils.js +41 -0
  154. package/hermes/utils/scripts/hermes/set-artifacts-version.js +64 -0
  155. package/hermes/utils/scripts/hermes/version-utils.js +98 -0
  156. package/hermes/utils/scripts/hermes/yarn.lock +240 -0
  157. package/hermes/utils/summarize_sizes.py +184 -0
  158. package/hermes/utils/symbolicate-nativecall-stats.py +112 -0
  159. package/hermes/utils/test_runner.py +13 -0
  160. package/hermes/utils/testsuite/README.facebook +3 -0
  161. package/hermes/utils/testsuite/README.md +69 -0
  162. package/hermes/utils/testsuite/cli.py +547 -0
  163. package/hermes/utils/testsuite/es_ast.py +337 -0
  164. package/hermes/utils/testsuite/external/LICENSE +28 -0
  165. package/hermes/utils/testsuite/external/README.facebook +8 -0
  166. package/hermes/utils/testsuite/external/__init__.py +0 -0
  167. package/hermes/utils/testsuite/external/_monkeyYaml.py +164 -0
  168. package/hermes/utils/testsuite/external/parse_test262.py +141 -0
  169. package/hermes/utils/testsuite/hermes.py +522 -0
  170. package/hermes/utils/testsuite/preprocess.py +365 -0
  171. package/hermes/utils/testsuite/progress.py +377 -0
  172. package/hermes/utils/testsuite/skiplist.json +4356 -0
  173. package/hermes/utils/testsuite/skiplist.py +270 -0
  174. package/hermes/utils/testsuite/test_run_defs.py +435 -0
  175. package/hermes/utils/testsuite/typing_defs.py +52 -0
  176. package/hermes/utils/testsuite/utils.py +214 -0
  177. package/hermes/utils/tidy.sh +22 -0
  178. package/hermes/utils/update-fbcode-hermes.sh +53 -0
  179. package/hermes/utils/updateErrorTest.py +193 -0
  180. package/hermes/utils/wasm-compile.sh +65 -0
  181. package/package.json +1 -1
@@ -0,0 +1,377 @@
1
+ #!/usr/bin/env python3
2
+
3
+ # @lint-ignore-every LICENSELINT
4
+
5
+ # Source: http://code.activestate.com/recipes/475116/, with
6
+ # modifications by Daniel Dunbar.
7
+
8
+ import re
9
+ import sys
10
+ import time
11
+
12
+
13
+ def to_bytes(str):
14
+ # Encode to UTF-8 to get binary data.
15
+ return str.encode("utf-8")
16
+
17
+
18
+ class TerminalController:
19
+ """
20
+ A class that can be used to portably generate formatted output to
21
+ a terminal.
22
+
23
+ `TerminalController` defines a set of instance variables whose
24
+ values are initialized to the control sequence necessary to
25
+ perform a given action. These can be simply included in normal
26
+ output to the terminal:
27
+
28
+ >>> term = TerminalController()
29
+ >>> print('This is '+term.GREEN+'green'+term.NORMAL)
30
+
31
+ Alternatively, the `render()` method can used, which replaces
32
+ '${action}' with the string required to perform 'action':
33
+
34
+ >>> term = TerminalController()
35
+ >>> print(term.render('This is ${GREEN}green${NORMAL}'))
36
+
37
+ If the terminal doesn't support a given action, then the value of
38
+ the corresponding instance variable will be set to ''. As a
39
+ result, the above code will still work on terminals that do not
40
+ support color, except that their output will not be colored.
41
+ Also, this means that you can test whether the terminal supports a
42
+ given action by simply testing the truth value of the
43
+ corresponding instance variable:
44
+
45
+ >>> term = TerminalController()
46
+ >>> if term.CLEAR_SCREEN:
47
+ ... print('This terminal supports clearning the screen.')
48
+
49
+ Finally, if the width and height of the terminal are known, then
50
+ they will be stored in the `COLS` and `LINES` attributes.
51
+ """
52
+
53
+ # Cursor movement:
54
+ BOL = "" #: Move the cursor to the beginning of the line
55
+ UP = "" #: Move the cursor up one line
56
+ DOWN = "" #: Move the cursor down one line
57
+ LEFT = "" #: Move the cursor left one char
58
+ RIGHT = "" #: Move the cursor right one char
59
+
60
+ # Deletion:
61
+ CLEAR_SCREEN = "" #: Clear the screen and move to home position
62
+ CLEAR_EOL = "" #: Clear to the end of the line.
63
+ CLEAR_BOL = "" #: Clear to the beginning of the line.
64
+ CLEAR_EOS = "" #: Clear to the end of the screen
65
+
66
+ # Output modes:
67
+ BOLD = "" #: Turn on bold mode
68
+ BLINK = "" #: Turn on blink mode
69
+ DIM = "" #: Turn on half-bright mode
70
+ REVERSE = "" #: Turn on reverse-video mode
71
+ NORMAL = "" #: Turn off all modes
72
+
73
+ # Cursor display:
74
+ HIDE_CURSOR = "" #: Make the cursor invisible
75
+ SHOW_CURSOR = "" #: Make the cursor visible
76
+
77
+ # Terminal size:
78
+ COLS = None #: Width of the terminal (None for unknown)
79
+ LINES = None #: Height of the terminal (None for unknown)
80
+
81
+ # Foreground colors:
82
+ BLACK = BLUE = GREEN = CYAN = RED = MAGENTA = YELLOW = WHITE = ""
83
+
84
+ # Background colors:
85
+ BG_BLACK = BG_BLUE = BG_GREEN = BG_CYAN = ""
86
+ BG_RED = BG_MAGENTA = BG_YELLOW = BG_WHITE = ""
87
+
88
+ _STRING_CAPABILITIES = """
89
+ BOL=cr UP=cuu1 DOWN=cud1 LEFT=cub1 RIGHT=cuf1
90
+ CLEAR_SCREEN=clear CLEAR_EOL=el CLEAR_BOL=el1 CLEAR_EOS=ed BOLD=bold
91
+ BLINK=blink DIM=dim REVERSE=rev UNDERLINE=smul NORMAL=sgr0
92
+ HIDE_CURSOR=cinvis SHOW_CURSOR=cnorm""".split()
93
+ _COLORS = """BLACK BLUE GREEN CYAN RED MAGENTA YELLOW WHITE""".split()
94
+ _ANSICOLORS = "BLACK RED GREEN YELLOW BLUE MAGENTA CYAN WHITE".split()
95
+
96
+ def __init__(self, term_stream=sys.stdout):
97
+ """
98
+ Create a `TerminalController` and initialize its attributes
99
+ with appropriate values for the current terminal.
100
+ `term_stream` is the stream that will be used for terminal
101
+ output; if this stream is not a tty, then the terminal is
102
+ assumed to be a dumb terminal (i.e., have no capabilities).
103
+ """
104
+ # Curses isn't available on all platforms
105
+ try:
106
+ import curses
107
+ except Exception:
108
+ return
109
+
110
+ # If the stream isn't a tty, then assume it has no capabilities.
111
+ if not term_stream.isatty():
112
+ return
113
+
114
+ # Check the terminal type. If we fail, then assume that the
115
+ # terminal has no capabilities.
116
+ try:
117
+ curses.setupterm()
118
+ except Exception:
119
+ return
120
+
121
+ # Look up numeric capabilities.
122
+ self.COLS = curses.tigetnum("cols")
123
+ self.LINES = curses.tigetnum("lines")
124
+ self.XN = curses.tigetflag("xenl")
125
+
126
+ # Look up string capabilities.
127
+ for capability in self._STRING_CAPABILITIES:
128
+ (attrib, cap_name) = capability.split("=")
129
+ setattr(self, attrib, self._tigetstr(cap_name) or "")
130
+
131
+ # Colors
132
+ set_fg = self._tigetstr("setf")
133
+ if set_fg:
134
+ for i, color in zip(range(len(self._COLORS)), self._COLORS):
135
+ setattr(self, color, self._tparm(set_fg, i))
136
+ set_fg_ansi = self._tigetstr("setaf")
137
+ if set_fg_ansi:
138
+ for i, color in zip(range(len(self._ANSICOLORS)), self._ANSICOLORS):
139
+ setattr(self, color, self._tparm(set_fg_ansi, i))
140
+ set_bg = self._tigetstr("setb")
141
+ if set_bg:
142
+ for i, color in zip(range(len(self._COLORS)), self._COLORS):
143
+ setattr(self, "BG_" + color, self._tparm(set_bg, i))
144
+ set_bg_ansi = self._tigetstr("setab")
145
+ if set_bg_ansi:
146
+ for i, color in zip(range(len(self._ANSICOLORS)), self._ANSICOLORS):
147
+ setattr(self, "BG_" + color, self._tparm(set_bg_ansi, i))
148
+
149
+ def _tparm(self, arg, index):
150
+ import curses
151
+
152
+ return curses.tparm(to_bytes(arg), index).decode("utf-8") or ""
153
+
154
+ def _tigetstr(self, cap_name):
155
+ # String capabilities can include "delays" of the form "$<2>".
156
+ # For any modern terminal, we should be able to just ignore
157
+ # these, so strip them out.
158
+ import curses
159
+
160
+ cap = curses.tigetstr(cap_name)
161
+ if cap is None:
162
+ cap = ""
163
+ else:
164
+ cap = cap.decode("utf-8")
165
+ return re.sub(r"\$<\d+>[/*]?", "", cap)
166
+
167
+ def render(self, template):
168
+ """
169
+ Replace each $-substitutions in the given template string with
170
+ the corresponding terminal control string (if it's defined) or
171
+ '' (if it's not).
172
+ """
173
+ return re.sub(r"\$\$|\${\w+}", self._render_sub, template)
174
+
175
+ def _render_sub(self, match):
176
+ s = match.group()
177
+ if s == "$$":
178
+ return s
179
+ else:
180
+ return getattr(self, s[2:-1])
181
+
182
+
183
+ #######################################################################
184
+ # Example use case: progress bar
185
+ #######################################################################
186
+
187
+
188
+ class SimpleProgressBar:
189
+ """
190
+ A simple progress bar which doesn't need any terminal support.
191
+
192
+ This prints out a progress bar like:
193
+ 'Header: 0 .. 10.. 20.. ...'
194
+ """
195
+
196
+ def __init__(self, header):
197
+ self.header = header
198
+ self.atIndex = None
199
+
200
+ def update(self, percent, message):
201
+ if self.atIndex is None:
202
+ sys.stdout.write(self.header)
203
+ self.atIndex = 0
204
+
205
+ next = int(percent * 50)
206
+ if next == self.atIndex:
207
+ return
208
+
209
+ for i in range(self.atIndex, next):
210
+ idx = i % 5
211
+ if idx == 0:
212
+ sys.stdout.write("%-2d" % (i * 2))
213
+ elif idx == 1:
214
+ pass # Skip second char
215
+ elif idx < 4:
216
+ sys.stdout.write(".")
217
+ else:
218
+ sys.stdout.write(" ")
219
+ sys.stdout.flush()
220
+ self.atIndex = next
221
+
222
+ def clear(self):
223
+ if self.atIndex is not None:
224
+ sys.stdout.write("\n")
225
+ sys.stdout.flush()
226
+ self.atIndex = None
227
+
228
+
229
+ class ProgressBar:
230
+ """
231
+ A 3-line progress bar, which looks like::
232
+
233
+ Header
234
+ 20% [===========----------------------------------]
235
+ progress message
236
+
237
+ The progress bar is colored, if the terminal supports color
238
+ output; and adjusts to the width of the terminal.
239
+ """
240
+
241
+ BAR = "%s${GREEN}[${BOLD}%s%s${NORMAL}${GREEN}]${NORMAL}%s"
242
+ HEADER = "${BOLD}${CYAN}%s${NORMAL}\n\n"
243
+
244
+ def __init__(self, term, header, useETA=True):
245
+ self.term = term
246
+ if not (self.term.CLEAR_EOL and self.term.UP and self.term.BOL):
247
+ raise ValueError(
248
+ "Terminal isn't capable enough -- you "
249
+ "should use a simpler progress dispaly."
250
+ )
251
+ self.BOL = self.term.BOL # BoL from col#79
252
+ self.XNL = "\n" # Newline from col#79
253
+ if self.term.COLS:
254
+ self.width = self.term.COLS
255
+ if not self.term.XN:
256
+ self.BOL = self.term.UP + self.term.BOL
257
+ self.XNL = "" # Cursor must be fed to the next line
258
+ else:
259
+ self.width = 75
260
+ self.bar = term.render(self.BAR)
261
+ self.header = self.term.render(self.HEADER % header.center(self.width))
262
+ self.cleared = 1 #: true if we haven't drawn the bar yet.
263
+ self.useETA = useETA
264
+ if self.useETA:
265
+ self.startTime = time.time()
266
+ self.update(0, "")
267
+
268
+ def update(self, percent, message):
269
+ if self.cleared:
270
+ sys.stdout.write(self.header)
271
+ self.cleared = 0
272
+ prefix = "%3d%% " % (percent * 100,)
273
+ suffix = ""
274
+ if self.useETA:
275
+ elapsed = time.time() - self.startTime
276
+ if percent > 0.0001 and elapsed > 1:
277
+ total = elapsed / percent
278
+ eta = int(total - elapsed)
279
+ h = eta // 3600.0
280
+ m = (eta // 60) % 60
281
+ s = eta % 60
282
+ suffix = " ETA: %02d:%02d:%02d" % (h, m, s)
283
+ barWidth = self.width - len(prefix) - len(suffix) - 2
284
+ n = int(barWidth * percent)
285
+ if len(message) < self.width:
286
+ message = message + " " * (self.width - len(message))
287
+ else:
288
+ message = "... " + message[-(self.width - 4) :]
289
+ sys.stdout.write(
290
+ self.BOL
291
+ + self.term.UP
292
+ + self.term.CLEAR_EOL
293
+ + (self.bar % (prefix, "=" * n, "-" * (barWidth - n), suffix))
294
+ + self.XNL
295
+ + self.term.CLEAR_EOL
296
+ + message
297
+ )
298
+ if not self.term.XN:
299
+ sys.stdout.flush()
300
+
301
+ def clear(self):
302
+ if not self.cleared:
303
+ sys.stdout.write(
304
+ self.BOL
305
+ + self.term.CLEAR_EOL
306
+ + self.term.UP
307
+ + self.term.CLEAR_EOL
308
+ + self.term.UP
309
+ + self.term.CLEAR_EOL
310
+ )
311
+ sys.stdout.flush()
312
+ self.cleared = 1
313
+
314
+
315
+ ###############################################################################
316
+
317
+ # Progress display utility from LLVM LIT included in external/llvh/utils/lit.
318
+ # Modified to suit Hermes testsuite runner use case.
319
+
320
+ from .utils import TestCaseResult, TestResultCode
321
+
322
+
323
+ class TestingProgressDisplay(object):
324
+ def __init__(self, numTests, progressBar, verbose=False):
325
+ self.verbose = verbose
326
+ self.numTests = numTests
327
+ self.progressBar = progressBar
328
+ self.completed = 0
329
+
330
+ def finish(self):
331
+ self.progressBar.clear()
332
+
333
+ def update(self, test: TestCaseResult):
334
+ self.completed += 1
335
+
336
+ self.progressBar.update(float(self.completed) / self.numTests, test.test_name)
337
+
338
+ is_failure = test.code.is_failure
339
+ shouldShow = is_failure or self.verbose
340
+ if not shouldShow:
341
+ return
342
+
343
+ self.progressBar.clear()
344
+
345
+ # Show the test result line.
346
+ print(
347
+ "%s: %s (%d of %d)"
348
+ % (test.msg, test.test_name, self.completed, self.numTests)
349
+ )
350
+
351
+ # Show the test failure output, if requested.
352
+ if shouldShow:
353
+ if is_failure:
354
+ print("%s TEST '%s' FAILED %s" % ("*" * 20, test.test_name, "*" * 20))
355
+ print(test.output)
356
+ print("*" * 80)
357
+
358
+ # Ensure the output is flushed.
359
+ sys.stdout.flush()
360
+
361
+
362
+ def test_progress_display():
363
+ test_results = [
364
+ TestCaseResult("test1", TestResultCode.TEST_PASSED),
365
+ TestCaseResult("test2", TestResultCode.EXECUTE_FAILED, "FAIL", "Parse failure"),
366
+ ] + [TestCaseResult(f"test{i}", TestResultCode.TEST_PASSED) for i in range(3, 30)]
367
+ tc = TerminalController()
368
+ header = f"-- Testing: {len(test_results)} tests --"
369
+ p = ProgressBar(tc, header)
370
+ display = TestingProgressDisplay(len(test_results), p, True)
371
+ for test in test_results:
372
+ time.sleep(1)
373
+ display.update(test)
374
+
375
+
376
+ if __name__ == "__main__":
377
+ test_progress_display()