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,270 @@
1
+ # Copyright (c) Meta Platforms, Inc. and affiliates.
2
+ #
3
+ # This source code is licensed under the MIT license found in the
4
+ # LICENSE file in the root directory of this source tree.
5
+
6
+ import json
7
+ import os
8
+ import sys
9
+ from enum import Enum, unique
10
+ from pathlib import Path
11
+ from typing import cast, Dict, List, Optional, Pattern, Sequence, Tuple, Union
12
+
13
+ from .typing_defs import PathT, SkippedPathItem, SkippedPathsOrFeaturesDict
14
+ from .utils import list_all_matched_entries, TestCaseResult, TestResultCode
15
+
16
+
17
+ @unique
18
+ class SkipCategory(Enum):
19
+ MANUAL_SKIP_LIST = "manual_skip_list"
20
+ SKIP_LIST = "skip_list"
21
+ LAZY_SKIP_LIST = "lazy_skip_list"
22
+ PERMANENT_SKIP_LIST = "permanent_skip_list"
23
+ HANDLESAN_SKIP_LIST = "handlesan_skip_list"
24
+ UNSUPPORTED_FEATURES = "unsupported_features"
25
+ PERMANENT_UNSUPPORTED_FEATURES = "permanent_unsupported_features"
26
+ INTL_TESTS = "intl_tests"
27
+ PLATFORM_SKIP_LIST = "platform_skip_list"
28
+
29
+
30
+ SKIPCAT_TO_RETCODE = {
31
+ SkipCategory.MANUAL_SKIP_LIST: TestResultCode.TEST_SKIPPED,
32
+ SkipCategory.SKIP_LIST: TestResultCode.TEST_SKIPPED,
33
+ SkipCategory.LAZY_SKIP_LIST: TestResultCode.TEST_SKIPPED,
34
+ SkipCategory.PERMANENT_SKIP_LIST: TestResultCode.TEST_PERMANENTLY_SKIPPED,
35
+ SkipCategory.UNSUPPORTED_FEATURES: TestResultCode.TEST_SKIPPED,
36
+ SkipCategory.PERMANENT_UNSUPPORTED_FEATURES: TestResultCode.TEST_PERMANENTLY_SKIPPED,
37
+ SkipCategory.INTL_TESTS: TestResultCode.TEST_SKIPPED,
38
+ SkipCategory.PERMANENT_SKIP_LIST: TestResultCode.TEST_SKIPPED,
39
+ SkipCategory.PLATFORM_SKIP_LIST: TestResultCode.TEST_SKIPPED,
40
+ }
41
+ """Mapping from a skip category to result code."""
42
+
43
+
44
+ class SkippedPathsOrFeatures(object):
45
+ """
46
+ Manage skip list and unsupported features for testsuite.
47
+ """
48
+
49
+ def __init__(self, config_path: PathT):
50
+ with open(config_path, "rb") as f:
51
+ self.paths_features: SkippedPathsOrFeaturesDict = json.load(f)
52
+ self.config_path = config_path
53
+
54
+ def get_skiplist_for_cat(self, skip_cat: SkipCategory) -> List[SkippedPathItem]:
55
+ """
56
+ Get the skip list for given category. For PLATFORM_SKIP_LIST, get the
57
+ list for the host platform.
58
+ """
59
+ if skip_cat == SkipCategory.PLATFORM_SKIP_LIST:
60
+ platform_skip_list: Dict[str, List[SkippedPathItem]] = (
61
+ self.paths_features.get(skip_cat.value, {})
62
+ )
63
+ return platform_skip_list.get(sys.platform, [])
64
+ return self.paths_features.get(skip_cat.value, [])
65
+
66
+ def should_skip_cat(
67
+ self, test_or_feature: Union[str, Pattern[str]], skip_cat: SkipCategory
68
+ ) -> bool:
69
+ """
70
+ Check if we should skip this test/feature.
71
+
72
+ Args:
73
+ test_or_feature: either full path of test file, or the feature
74
+ listed in its metadata.
75
+ """
76
+
77
+ def should_skip(test_or_feature: Union[str, Pattern[str]], value: str) -> bool:
78
+ if isinstance(test_or_feature, str):
79
+ # Either filename or directory is specified.
80
+ if value in test_or_feature:
81
+ return True
82
+ # Do regex matching.
83
+ elif test_or_feature.search(value):
84
+ return True
85
+ return False
86
+
87
+ values: List[SkippedPathItem] = self.get_skiplist_for_cat(skip_cat)
88
+ for value in values:
89
+ if isinstance(value, dict):
90
+ for p in value.get("paths", []):
91
+ if should_skip(test_or_feature, p):
92
+ return True
93
+ else:
94
+ if should_skip(test_or_feature, value):
95
+ return True
96
+
97
+ return False
98
+
99
+ def try_skip(
100
+ self,
101
+ test_or_feature: Union[str, Pattern[str]],
102
+ cats: List[SkipCategory],
103
+ full_test_name: str,
104
+ ) -> Optional[TestCaseResult]:
105
+ """
106
+ Try if test_or_feature can be skipped.
107
+
108
+ Args:
109
+ test_or_feature: either full path of a test file, or the feature
110
+ listed in its metadata.
111
+ cats: SkipCategory to try.
112
+ rel_test_path: A relative path of the test file to create error
113
+ message.
114
+
115
+ Returns:
116
+ TestCaseResult with mapped result code and message, if skipped,
117
+ None otherwise.
118
+ """
119
+
120
+ # If it's full path of a test file, normalize the path to POSIX style
121
+ # since we use that style in skiplist.json.
122
+ if os.path.exists(test_or_feature):
123
+ test_or_feature = Path(test_or_feature).as_posix()
124
+
125
+ for cat in cats:
126
+ if self.should_skip_cat(test_or_feature, cat):
127
+ msg = f"SKIP: skipped by {cat.name} ({test_or_feature})"
128
+ return TestCaseResult(full_test_name, SKIPCAT_TO_RETCODE[cat], msg)
129
+ return None
130
+
131
+ def get_unfolded_path(
132
+ self, p: str, tests: Dict[str, str]
133
+ ) -> Optional[Tuple[PathT, str]]:
134
+ """
135
+ If path p is a directory, and any passed test is under it, we
136
+ should unfold it. If a path is a partial path, and any passed test
137
+ matches it, we should also unfold it.
138
+
139
+ Returns:
140
+ Absolute path of the directory or partial path and the suite
141
+ directory, if we should unfold it.
142
+ None, otherwise.
143
+ """
144
+
145
+ # Only directory or partial path should unfold.
146
+ if p.endswith(".js"):
147
+ return None
148
+ # We need the suite path to get the relative path for every file
149
+ # under or matches it.
150
+ for test, suite_dir in tests.items():
151
+ if test.startswith(p):
152
+ return os.fspath(Path(suite_dir).parent.joinpath(p)), suite_dir
153
+ return None
154
+
155
+ def unfold_top_level(
156
+ self, tests: Dict[str, str], paths: Sequence[SkippedPathItem]
157
+ ) -> List[SkippedPathItem]:
158
+ """
159
+ Subsitute the top level directory/partial paths (e.g., a SkippedPathItem
160
+ that is a str) with all files under/match them.
161
+ """
162
+
163
+ # Use list to keep the original order.
164
+ unfolded = []
165
+ # Each time we unfold a directory by one level, i.e., we replace the
166
+ # directory with files and directories directly under it. Keep unfolding
167
+ # until no directory path matches any passed test. This can save some
168
+ # syscalls compared to listing all files/directories with os.walk().
169
+ # For partial path, we replace it with all files match it at once.
170
+ while True:
171
+ for path in paths:
172
+ # PathsWithComment is handled separately.
173
+ if isinstance(path, dict):
174
+ unfolded.append(path)
175
+ continue
176
+ assert isinstance(path, str)
177
+ if dir_path_and_suite_path := self.get_unfolded_path(path, tests):
178
+ # Assignment expression does not support unpacking so do it here.
179
+ (dir_path, suite_path) = dir_path_and_suite_path
180
+ # Adding files/directories under or matches it.
181
+ unfolded.extend(
182
+ os.path.relpath(f, Path(suite_path).parent)
183
+ for f in list_all_matched_entries(dir_path)
184
+ )
185
+ else:
186
+ # If this path does not need to unfold, add it back.
187
+ unfolded.append(path)
188
+ # If the list size is the same, we have done all necessary
189
+ # unfolding.
190
+ if len(unfolded) == len(paths):
191
+ break
192
+ paths = unfolded
193
+ unfolded = []
194
+
195
+ return unfolded
196
+
197
+ def unfold(
198
+ self, tests: Dict[str, str], skipped_paths: List[SkippedPathItem]
199
+ ) -> List[SkippedPathItem]:
200
+ """
201
+ Some paths in the skiplist are directories. If we want to exclude
202
+ tests under those directories, we need to unfold them first. A few
203
+ paths are neither directories nor files, they are partial paths that
204
+ are prefix to other paths. We need to replace them with all matched
205
+ paths as well.
206
+
207
+ For example, if there is a test path "ES6/async" in skiplist, and a test
208
+ "ES6/async/001.js" under that directory passed, we will replace that
209
+ directory with all files (recursively) under it first, then exclude the
210
+ passed test. Another example, there is a test path "ES6/head-let-"
211
+ in the skiplist, and there are two files match it, "ES6/head-let-0.js"
212
+ and "ES6/head-let-1.js", if the first one passed, we will replace the
213
+ partial path with these two file paths, and exclude the first one
214
+ since it's passed.
215
+ """
216
+
217
+ # Unfold nested list first.
218
+ for path_item in skipped_paths:
219
+ if isinstance(path_item, str):
220
+ continue
221
+ # Explicit casting to make type checker happy.
222
+ path_item["paths"] = cast(
223
+ List[str], self.unfold_top_level(tests, path_item["paths"])
224
+ )
225
+ # Unfold directory paths directly included in the list.
226
+ return self.unfold_top_level(tests, skipped_paths)
227
+
228
+ def remove_tests_from_cat(self, tests: Dict[str, str], cat: SkipCategory) -> None:
229
+ """Remove given tests under given category from the skip list config."""
230
+
231
+ skipped_paths: List[SkippedPathItem] = self.paths_features.get(cat, [])
232
+ skipped_paths = self.unfold(tests, skipped_paths)
233
+ # Remove plain test paths that also exist in the given list.
234
+ skipped_paths = [
235
+ p for p in skipped_paths if isinstance(p, dict) or p not in tests
236
+ ]
237
+ result = []
238
+ for path_item in skipped_paths:
239
+ # For PathsWithComment, update its "paths" list.
240
+ if isinstance(path_item, dict):
241
+ path_item["paths"] = [p for p in path_item["paths"] if p not in tests]
242
+ # Ignore this item if all its nested paths have been removed.
243
+ if len(path_item["paths"]) > 0:
244
+ result.append(path_item)
245
+ else:
246
+ result.append(path_item)
247
+
248
+ self.paths_features[cat] = result
249
+
250
+ def remove_tests(self, tests: Dict[str, str]) -> None:
251
+ """
252
+ Remove given tests from the skip list config."""
253
+
254
+ # Only paths included in SKIP_LIST and PERMANENT_SKIP_LIST can be
255
+ # removed for now.
256
+ cats = [
257
+ SkipCategory.SKIP_LIST.value,
258
+ SkipCategory.PERMANENT_SKIP_LIST.value,
259
+ ]
260
+ for cat in cats:
261
+ self.remove_tests_from_cat(tests, cat)
262
+ self.persist()
263
+
264
+ def persist(self) -> None:
265
+ """
266
+ Write out the current skiplist to the original path.
267
+ """
268
+
269
+ with open(self.config_path, "w") as writer:
270
+ json.dump(self.paths_features, writer, indent=2)
@@ -0,0 +1,435 @@
1
+ # Copyright (c) Meta Platforms, Inc. and affiliates.
2
+ #
3
+ # This source code is licensed under the MIT license found in the
4
+ # LICENSE file in the root directory of this source tree.
5
+
6
+ from __future__ import annotations
7
+
8
+ import json
9
+ import os
10
+ from abc import ABC, abstractmethod
11
+ from copy import deepcopy
12
+ from dataclasses import dataclass
13
+ from typing import Optional
14
+
15
+ from .es_ast import diff
16
+ from .hermes import compile_and_run, CompileRunArgs, ExtraCompileVMArgs, generate_ast
17
+ from .preprocess import generate_source, StrictMode
18
+ from .skiplist import SkipCategory, SkippedPathsOrFeatures
19
+ from .typing_defs import PathT
20
+ from .utils import get_hermes_supported_test262_features, TestCaseResult, TestResultCode
21
+
22
+
23
+ @dataclass
24
+ class TestRunArgs(object):
25
+ """
26
+ Argument necessary to run a given test.
27
+ """
28
+
29
+ test_file: PathT
30
+ """Target test file."""
31
+ tests_home: PathT
32
+ """Common ancestor path of passed in file paths."""
33
+ work_dir: PathT
34
+ """Work directory to store preprocessed source."""
35
+ binary_directory: PathT
36
+ """Directory path that contains necessary hermes executables."""
37
+ skipped_paths_features: SkippedPathsOrFeatures
38
+ """Helper for skipping certain tests."""
39
+ test_skiplist: bool
40
+ """Whether to run tests in skiplist."""
41
+ bytecode_compat_check: bool
42
+ """Whether to run bytecode compatibility check."""
43
+ lazy: bool
44
+ """Whether to force lazy evaluation."""
45
+ shermes: bool
46
+ """Whether to test with shermes"""
47
+ opt: bool
48
+ """Whether to enable optimizer"""
49
+ extra_compile_vm_args: ExtraCompileVMArgs
50
+ """Extra compiler and VM arguments"""
51
+ timeout: int
52
+ """Timeout (in seconds) for compiling/running each test."""
53
+
54
+
55
+ class Suite(ABC):
56
+ def __init__(self, path: PathT) -> None:
57
+ self._path = path
58
+
59
+ @staticmethod
60
+ def create(path: PathT) -> Optional[Suite]:
61
+ """
62
+ Create a Suite object depending on which testsuite the given file
63
+ belongs to.
64
+ """
65
+
66
+ def get_suite_directory(s: str) -> PathT:
67
+ # Search from the end in case the path has repeated folder names.
68
+ return path[: path.rfind(s) + len(s)]
69
+
70
+ if "test262/" in path:
71
+ return Test262Suite(get_suite_directory("test262/"))
72
+ elif "mjsunit/" in path:
73
+ return MjsunitSuite(get_suite_directory("mjsunit/"))
74
+ elif "CVEs/" in path:
75
+ return CvesSuite(get_suite_directory("CVEs/"))
76
+ elif "esprima/" in path:
77
+ return EsprimaAstCheckSuite(get_suite_directory("esprima/"))
78
+ elif "flow/" in path:
79
+ # Use "flow/" to avoid matching flowtest/
80
+ return FlowAstCheckSuite(get_suite_directory("flow/"))
81
+ return None
82
+
83
+ @property
84
+ def directory(self) -> PathT:
85
+ """Return the testsuite directory path."""
86
+ return self._path
87
+
88
+ @property
89
+ @abstractmethod
90
+ def name(self) -> str:
91
+ """Short suite name, e.g., test262."""
92
+ raise NotImplementedError
93
+
94
+ def get_full_test_name(self, test_file: PathT) -> str:
95
+ """
96
+ Get the full test name. This is useful when printing a relatively
97
+ succinct test name.
98
+
99
+ It has form of:
100
+ {suite_name} :: {relative_path_to_suite_path}.
101
+
102
+ For example, mjsunit :: regress-011.js.
103
+ """
104
+ return f"{self.name} :: {os.path.relpath(test_file, self.directory)}"
105
+
106
+ @abstractmethod
107
+ async def run_test(self, args: TestRunArgs) -> TestCaseResult:
108
+ """
109
+ Callback function to be called in run(). This should be implemented
110
+ for each testsuite.
111
+
112
+ Args:
113
+ TestRunArgs: All arguments necessary to run the given test.
114
+
115
+ Returns:
116
+ TestCaseResult, indicating whether this test passes, if not, what is
117
+ the error message.
118
+ """
119
+ raise NotImplementedError
120
+
121
+
122
+ class Test262Suite(Suite):
123
+ """
124
+ Support running test262 testsuite. This is also used as base for the CVEs
125
+ testsuite since a few tests there use the same style frontmatter as test262.
126
+ """
127
+
128
+ @property
129
+ def name(self) -> str:
130
+ return "test262"
131
+
132
+ def generate_js_source(
133
+ self,
134
+ tmp_dir: PathT,
135
+ base_name_no_ext: str,
136
+ flags_str: str,
137
+ source: str,
138
+ is_strict: bool,
139
+ ) -> PathT:
140
+ """
141
+ Generate the JS source file to run, prepend the strict directive if
142
+ necessary. The returned path encodes its strict mode and flags.
143
+ """
144
+ strict_indicator = ".strict" if is_strict else ""
145
+ js_source = os.path.join(
146
+ tmp_dir, f"{base_name_no_ext}{strict_indicator}{flags_str}.js"
147
+ )
148
+ with open(js_source, "wb") as writer:
149
+ if is_strict:
150
+ # Add the directive for strict mode
151
+ writer.write("'use strict';\n".encode("utf-8"))
152
+ writer.write(source.encode("utf-8"))
153
+ return js_source
154
+
155
+ async def run_test(self, args: TestRunArgs) -> TestCaseResult:
156
+ """
157
+ Load and preprocess the test file, check if it's skipped. If not, run
158
+ the preprocessed source code, return the result.
159
+ """
160
+ with open(args.test_file, "rb") as reader:
161
+ content = reader.read().decode("utf-8")
162
+ full_test_name = self.get_full_test_name(args.test_file)
163
+ test_case = generate_source(content, self.directory, full_test_name)
164
+ if "testIntl.js" in test_case.includes:
165
+ msg = f"SKIP: No support for multiple Intl constructors in {full_test_name}"
166
+ return TestCaseResult(full_test_name, TestResultCode.TEST_SKIPPED, msg)
167
+
168
+ flags = test_case.flags
169
+ is_async = "async" in flags
170
+ if "module" in flags:
171
+ return TestCaseResult(
172
+ full_test_name,
173
+ TestResultCode.TEST_SKIPPED,
174
+ "SKIP: Test has `module` flag",
175
+ )
176
+ # Check if we need to skip this test due to unsupported features.
177
+ for f in test_case.features:
178
+ # If it's not running shermes test and this feature is specifically
179
+ # supported by the built hermes binary, we don't need to test if it
180
+ # is in the skiplist. We may still skip it due to the rest features
181
+ # of this test case though.
182
+ if not args.shermes and f in get_hermes_supported_test262_features(
183
+ args.binary_directory
184
+ ):
185
+ continue
186
+ if skip_result := args.skipped_paths_features.try_skip(
187
+ f,
188
+ [
189
+ SkipCategory.UNSUPPORTED_FEATURES,
190
+ SkipCategory.PERMANENT_UNSUPPORTED_FEATURES,
191
+ ],
192
+ full_test_name,
193
+ ):
194
+ if not args.test_skiplist:
195
+ return skip_result
196
+
197
+ base_name = os.path.basename(args.test_file)
198
+ base_name_no_ext = os.path.splitext(base_name)[0]
199
+
200
+ tmp_dir: PathT = os.path.join(
201
+ args.work_dir,
202
+ os.path.dirname(os.path.relpath(args.test_file, args.tests_home)),
203
+ )
204
+ os.makedirs(tmp_dir, exist_ok=True)
205
+ flags_str = ("." + "_".join(sorted(flags))) if len(flags) > 0 else ""
206
+ js_sources = []
207
+ if StrictMode.STRICT in test_case.strict_mode:
208
+ js_sources.append(
209
+ self.generate_js_source(
210
+ tmp_dir, base_name_no_ext, flags_str, test_case.source, True
211
+ )
212
+ )
213
+
214
+ if StrictMode.NO_STRICT in test_case.strict_mode:
215
+ js_sources.append(
216
+ self.generate_js_source(
217
+ tmp_dir, base_name_no_ext, flags_str, test_case.source, False
218
+ )
219
+ )
220
+
221
+ disable_handle_san = args.skipped_paths_features.should_skip_cat(
222
+ args.test_file, SkipCategory.HANDLESAN_SKIP_LIST
223
+ )
224
+
225
+ compile_run_args = CompileRunArgs(
226
+ full_test_name,
227
+ test_case.strict_mode,
228
+ args.binary_directory,
229
+ test_case.expected_failure,
230
+ disable_handle_san,
231
+ args.bytecode_compat_check,
232
+ args.lazy,
233
+ args.shermes,
234
+ args.opt,
235
+ args.timeout,
236
+ is_async,
237
+ args.extra_compile_vm_args,
238
+ )
239
+ return await compile_and_run(js_sources, compile_run_args)
240
+
241
+
242
+ class CvesSuite(Test262Suite):
243
+ """
244
+ Support running the CVE testsuite.
245
+ """
246
+
247
+ @property
248
+ def name(self) -> str:
249
+ return "CVEs"
250
+
251
+
252
+ class MjsunitSuite(Suite):
253
+ """
254
+ Support running mjsunit testsuite. This can be used to run any testsuite
255
+ that requires running source directly and checking compiler/runtime error.
256
+ """
257
+
258
+ @property
259
+ def name(self) -> str:
260
+ return "mjsunit"
261
+
262
+ async def run_test(self, args: TestRunArgs) -> TestCaseResult:
263
+ # Compute a temporary path to store preprocessed test code.
264
+ base_name = os.path.basename(args.test_file)
265
+ base_name_no_ext = os.path.splitext(base_name)[0]
266
+ tmp_dir: PathT = os.path.join(
267
+ args.work_dir,
268
+ os.path.dirname(os.path.relpath(args.test_file, args.tests_home)),
269
+ )
270
+ os.makedirs(tmp_dir, exist_ok=True)
271
+ js_source = os.path.join(tmp_dir, f"{base_name_no_ext}_generated.js")
272
+
273
+ # Read the original test source, preprocess it and save the preprocessed
274
+ # code to the temporary path.
275
+ with open(args.test_file, "rb") as reader:
276
+ content = reader.read().decode("utf-8")
277
+ full_test_name = self.get_full_test_name(args.test_file)
278
+ test_case = generate_source(content, self.directory, full_test_name)
279
+ with open(js_source, "wb") as writer:
280
+ writer.write(test_case.source.encode("utf-8"))
281
+
282
+ # Run Hermes on the generated temporary JS file.
283
+ disable_handle_san = args.skipped_paths_features.should_skip_cat(
284
+ args.test_file, SkipCategory.HANDLESAN_SKIP_LIST
285
+ )
286
+ extra_compile_vm_args = deepcopy(args.extra_compile_vm_args)
287
+ compile_run_args = CompileRunArgs(
288
+ full_test_name,
289
+ test_case.strict_mode,
290
+ args.binary_directory,
291
+ test_case.expected_failure,
292
+ disable_handle_san,
293
+ args.bytecode_compat_check,
294
+ args.lazy,
295
+ args.shermes,
296
+ args.opt,
297
+ args.timeout,
298
+ False,
299
+ extra_compile_vm_args,
300
+ )
301
+ return await compile_and_run([js_source], compile_run_args)
302
+
303
+
304
+ class AstCheckSuite(Suite):
305
+ """
306
+ This works for both ESPRIMA and FLOW test suites, which checks the
307
+ correctness of AST generated by Hermes.
308
+ """
309
+
310
+ @property
311
+ def is_flow(self) -> bool:
312
+ """We need to pass in different flags to Hermes for flow tests."""
313
+ return False
314
+
315
+ def get_expected_file_name(self, test_file: PathT) -> Optional[PathT]:
316
+ """
317
+ Get the expect file name, which could be one of following:
318
+ - *.tree.json
319
+ - *.failure.json (indicating failure)
320
+ - *.token.json (we don't support it for now)
321
+ If none is found, return None.
322
+ """
323
+
324
+ filename_stem = ""
325
+ if test_file.endswith(".source.js"):
326
+ filename_stem = test_file[:-10]
327
+ else:
328
+ # Must be *.js here
329
+ filename_stem = test_file[:-3]
330
+ tree_file = filename_stem + ".tree.json"
331
+ if os.path.isfile(tree_file):
332
+ return tree_file
333
+ failure_file = filename_stem + ".failure.json"
334
+ if os.path.isfile(failure_file):
335
+ return failure_file
336
+ token_file = filename_stem + ".tokens.json"
337
+ if os.path.isfile(token_file):
338
+ return token_file
339
+ return None
340
+
341
+ async def run_test(self, args: TestRunArgs) -> TestCaseResult:
342
+ # Check if the test file is valid and its expect file can be found.
343
+ full_test_name = self.get_full_test_name(args.test_file)
344
+ if not args.test_file.endswith(".js"):
345
+ msg = "FAIL: Invalid test case"
346
+ return TestCaseResult(full_test_name, TestResultCode.TEST_FAILED, msg)
347
+ expected_file = self.get_expected_file_name(args.test_file)
348
+ if not expected_file:
349
+ msg = "FAIL: Can't find expected file"
350
+ return TestCaseResult(
351
+ full_test_name,
352
+ TestResultCode.TEST_FAILED,
353
+ msg,
354
+ )
355
+
356
+ # Expect files end with ".tokens.json" expect the parser to produce
357
+ # tokens, which Hermes does not support, so skip them here.
358
+ if expected_file.endswith(".tokens.json"):
359
+ msg = "SKIP: Expect file *.tokens.json is not supported"
360
+ return TestCaseResult(full_test_name, TestResultCode.TEST_SKIPPED, msg)
361
+
362
+ # This expects a failure of the current test. If the result_code is not
363
+ # TEST_PASSED, rerun `generate_ast` with semantic validation and do
364
+ # the check again.
365
+ async def check_for_expected_failure(
366
+ result_code: TestResultCode,
367
+ ) -> TestCaseResult:
368
+ nonlocal args, full_test_name
369
+ if result_code == TestResultCode.TEST_PASSED:
370
+ # If it should error and it didn't, try again with
371
+ # semantic validation. Some tests only error in semantic
372
+ # validation, but we want to avoid running it because it
373
+ # also outputs errors for unsupported compiler features
374
+ # that Hermes does parse correctly.
375
+ result_code = (
376
+ await generate_ast(
377
+ full_test_name,
378
+ args.test_file,
379
+ args.binary_directory,
380
+ self.is_flow,
381
+ True,
382
+ args.timeout,
383
+ )
384
+ ).code
385
+ # Check again after possible retry.
386
+ if result_code != TestResultCode.TEST_PASSED:
387
+ msg = "PASS: Expected failure"
388
+ return TestCaseResult(full_test_name, TestResultCode.TEST_PASSED, msg)
389
+ else:
390
+ msg = "FAIL: Test is expected to fail"
391
+ return TestCaseResult(full_test_name, TestResultCode.TEST_FAILED, msg)
392
+
393
+ result = await generate_ast(
394
+ full_test_name,
395
+ args.test_file,
396
+ args.binary_directory,
397
+ self.is_flow,
398
+ False,
399
+ args.timeout,
400
+ )
401
+ if expected_file.endswith(".tree.json"):
402
+ try:
403
+ with open(expected_file, "r") as json_f:
404
+ expected_ast = json.load(json_f)
405
+ except (json.JSONDecodeError, OSError) as err:
406
+ msg = f"FAIL: Failed to load expected AST file: {err}"
407
+ return TestCaseResult(full_test_name, TestResultCode.TEST_FAILED, msg)
408
+
409
+ if isinstance(expected_ast, dict) and "errors" in expected_ast:
410
+ return await check_for_expected_failure(result.code)
411
+ return diff(result.output, full_test_name, expected_ast)
412
+ else:
413
+ assert expected_file.endswith(".failure.json")
414
+ return await check_for_expected_failure(result.code)
415
+
416
+
417
+ class FlowAstCheckSuite(AstCheckSuite):
418
+ @property
419
+ def name(self) -> str:
420
+ return "flow"
421
+
422
+ @property
423
+ def is_flow(self) -> bool:
424
+ return True
425
+
426
+
427
+ class EsprimaAstCheckSuite(AstCheckSuite):
428
+ @property
429
+ def name(self) -> str:
430
+ return "esprima"
431
+
432
+
433
+ def get_suite(filepath: PathT) -> Optional[Suite]:
434
+ """Get testsuite for given test file."""
435
+ return Suite.create(filepath)