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,329 @@
1
+ ---
2
+ id: prohibit-invoke
3
+ title: Valid-invocation enforcement (prohibitInvoke and the constructor rule)
4
+ ---
5
+
6
+ ### Introduction
7
+
8
+ Hermes enforces two kinds of "you cannot invoke this function that way" rules:
9
+
10
+ 1. **`prohibitInvoke`** — a per-JS-function flag that says the function is
11
+ constructor-only or call-only (e.g. an ES6 class constructor cannot be
12
+ called without `new`; an arrow function, method, generator, or async
13
+ function cannot be called with `new`).
14
+ 2. **The "a `NativeFunction` cannot be used as a constructor" rule** — a
15
+ `CellKind`-based rule that rejects `new`ing a plain C++ builtin that is not
16
+ a `NativeConstructor`.
17
+
18
+ These two mechanisms are **orthogonal** and fire at different times: the
19
+ `prohibitInvoke` check runs at the **callee entry** and is keyed on a per-function
20
+ flag; the constructor rule runs **caller-side** at the `new` site (when `this` is
21
+ created) and is keyed on the callee's `CellKind`. This document describes both,
22
+ and how each is realized across the four execution paths: the bytecode
23
+ interpreter, the JIT, C++ builtins, and the Static Hermes (SH) native C backend.
24
+
25
+ ---
26
+
27
+ ## Part 1 — `prohibitInvoke` (the per-function flag)
28
+
29
+ ### The two enums
30
+
31
+ There are two `ProhibitInvoke` enums, with **deliberately different value
32
+ orderings**, bridged by `computeProhibitInvoke()`.
33
+
34
+ IR-level (`include/hermes/IR/IR.h`):
35
+
36
+ ```cpp
37
+ enum class ProhibitInvoke {
38
+ ProhibitNone, // = 0
39
+ ProhibitConstruct, // = 1
40
+ ProhibitCall, // = 2
41
+ };
42
+ ```
43
+
44
+ Backend/runtime (`include/hermes/BCGen/FunctionInfo.h`):
45
+
46
+ ```cpp
47
+ enum ProhibitInvoke {
48
+ Call = 0, // regular (non-new) calls prohibited => constructor-only
49
+ Construct = 1, // construct (new) calls prohibited => call-only
50
+ None = 2,
51
+ };
52
+ ```
53
+
54
+ > **Gotcha:** in the backend enum the names denote *which kind of invocation is
55
+ > prohibited*, and the numeric values are inverted relative to the IR enum.
56
+ > Always convert via `computeProhibitInvoke()` (`FunctionInfo.h`); never assume
57
+ > the numeric values of the two enums line up.
58
+
59
+ ### How the restriction is decided
60
+
61
+ The restriction is derived from the function's definition kind in
62
+ `Function::getProhibitInvoke()` (`lib/IR/IR.cpp`):
63
+
64
+ - ES6 base/derived constructors → `ProhibitCall` (must use `new`).
65
+ - Generators, async functions, arrow functions, and object/class methods →
66
+ `ProhibitConstruct` (cannot use `new`).
67
+ - Everything else → `ProhibitNone`.
68
+
69
+ ### Where it is stored
70
+
71
+ The value lives in one of two places, depending on the function kind:
72
+
73
+ - **Bytecode functions:** a 2-bit field in the `FunctionHeaderFlag` byte of the
74
+ code block header (`include/hermes/BCGen/HBC/BytecodeFileFormat.h`), written
75
+ during bytecode generation (`lib/BCGen/HBC/BytecodeGenerator.cpp`). Bit
76
+ layout within the flags byte (LSB first): bits 0-1 `ProhibitInvoke`, bit 2
77
+ `StrictMode`, bit 3 `HasExceptionHandler`, bit 4 `HasDebugInfo`, bit 5
78
+ `Overflowed`, bits 6-7 `Kind`.
79
+ - **SH/native-compiled functions (`NativeJSFunction`):** a 2-bit
80
+ `prohibit_invoke` field in `SHNativeFuncInfo` (`include/hermes/VM/static_h.h`),
81
+ emitted into the generated C function-info table (`lib/BCGen/SH/SH.cpp`).
82
+ - **C++ builtins (`NativeFunction` / `NativeConstructor`):** no flag at all —
83
+ for these, invocation validity is handled by the constructor rule (Part 2)
84
+ and by hand-written checks in the builtin body.
85
+
86
+ The central predicate for the flag (`BytecodeFileFormat.h`):
87
+
88
+ ```cpp
89
+ bool isCallProhibited(bool construct) const {
90
+ return getProhibitInvoke() == (uint8_t)construct;
91
+ }
92
+ ```
93
+
94
+ This exploits the backend enum values: for a construct call
95
+ (`construct == true == 1`) it matches `Construct(1)`; for a plain call
96
+ (`construct == false == 0`) it matches `Call(0)`; `None(2)` never matches
97
+ either, so one comparison covers both directions.
98
+
99
+ ### Enforcement — a callee-entry check
100
+
101
+ The `prohibitInvoke` flag is checked at the **callee entry**, keyed on the
102
+ *callee's* own flags. There is no central gate: `Callable::call` (the vtable
103
+ funnel), `Interpreter::handleCallSlowPath`, and the SH `doCall` / `_sh_ljs_call`
104
+ helpers all deliberately do *not* check the flag; they only dispatch. Being a
105
+ callee-entry check keyed on the callee is exactly what makes it caller-agnostic
106
+ for bytecode functions.
107
+
108
+ | Callee kind | Flag enforced at entry? | Where |
109
+ |---|---|---|
110
+ | Bytecode (interpreted) | Yes | `interpretFunction` entry preamble and inline Call fast-path (`lib/VM/Interpreter.cpp`) |
111
+ | Bytecode (JIT-compiled) | Yes | Inline in the compiled prologue (`lib/VM/JIT/arm64/JitEmitter.cpp`) → shared slow-path helpers |
112
+ | C++ builtin | N/A (no flag) | Constructor rule (Part 2) + manual body checks |
113
+ | SH-compiled (`NativeJSFunction`) | No | Flag is stored but never checked at call time |
114
+
115
+ #### Interpreter (bytecode callees)
116
+
117
+ Two sites, both raising the same two errors:
118
+
119
+ - Entry preamble of `Interpreter::interpretFunction` (`lib/VM/Interpreter.cpp`):
120
+ checks `curCodeBlock->getHeaderFlags().isCallProhibited(newFrame.isConstructorCall())`.
121
+ Done before the callee frame is fully set up, so the exception appears to
122
+ come from the call site.
123
+ - Inline Call fast-path (`lib/VM/Interpreter.cpp`): checks
124
+ `calleeBlock->getHeaderFlags().isCallProhibited(isCtorCall)`, where
125
+ `isCtorCall` is (`new.target` is not undefined).
126
+ - Messages: `"Function is not a constructor"` /
127
+ `"Class constructor invoked without new"`.
128
+
129
+ The inline fast path is taken only for `JSFunction` callees *without* a JIT
130
+ pointer; when the callee is JIT-compiled, the interpreter skips its own check
131
+ because the JIT prologue self-checks.
132
+
133
+ #### JIT (bytecode callees; arm64 only)
134
+
135
+ Emitted **inline at the compiled function's own prologue**
136
+ (`lib/VM/JIT/arm64/JitEmitter.cpp`): reads
137
+ `getHeaderFlags().getProhibitInvoke()`, loads `new.target`, compares to
138
+ undefined, and branches to an out-of-line slow path that calls the shared
139
+ helpers `_sh_throw_invalid_call` / `_sh_throw_invalid_construct`
140
+ (`lib/VM/JIT/JitHandlers.cpp`) — same two error messages. Complete and
141
+ caller-agnostic. (arm64 is the only JIT backend present.)
142
+
143
+ #### SH native backend (`NativeJSFunction` callees) — flag enforcement gap
144
+
145
+ The SH C backend **records** `prohibit_invoke` in `SHNativeFuncInfo` and uses it
146
+ for `isConstructor()` (`lib/VM/Operations.cpp`) and `.prototype` suppression
147
+ (`lib/VM/Callable.cpp`), but **emits no callee-entry guard** for it:
148
+
149
+ - The generated function prologue (`lib/BCGen/SH/SH.cpp`) emits
150
+ stack-overflow / frame / try setup but no `new.target`/prohibit check.
151
+ - Call lowering → `_sh_ljs_call` → `doCall` →
152
+ `NativeJSFunction::_legacyCall` (just `functionPtr_(shr)`) — no flag check.
153
+ - The code flags this as unfinished:
154
+ `TODO(T168592126) standardize on where we perform function call validation
155
+ for the native backend.`
156
+ - Consistent with the gap, there is no SH-backend test for `prohibitInvoke`;
157
+ the existing `test/hermes/prohibit-invoke.js` runs under the interpreter.
158
+
159
+ Note this gap is specifically about the *flag*. The caller-side constructor rule
160
+ (Part 2) *is* present in the SH backend via `_sh_ljs_create_this`.
161
+
162
+ ---
163
+
164
+ ## Part 2 — The constructor rule (`NativeFunction` cannot be `new`ed)
165
+
166
+ This is a separate, `CellKind`-based rule enforced **caller-side** at the `new`
167
+ site, when `this` is created — before the callee frame is set up. It rejects
168
+ `new`ing a plain C++ builtin (`NativeFunction`) that is not a `NativeConstructor`.
169
+ It does **not** consult the `prohibitInvoke` flag.
170
+
171
+ ### Interpreter: `CreateThisForNew` / `CreateThisForSuper` → `createThisImpl`
172
+
173
+ For `new X()`, the compiler emits a `CreateThisForNew` opcode (and
174
+ `CreateThisForSuper` for `super()` in derived constructors) *before* the actual
175
+ `Construct`. The interpreter handlers (`lib/VM/Interpreter.cpp`) call
176
+ `Interpreter::createThisImpl` (`lib/VM/Interpreter-slowpaths.cpp`), which
177
+ classifies the callee by `CellKind`:
178
+
179
+ - `>= CallableExpectsThisKind_first` (`JSFunction`, `NativeJSFunction`): the
180
+ callee wants a pre-made `this` → allocate the object.
181
+ - `>= CallableMakesThisKind_first` (`NativeConstructor`,
182
+ `FinalizableNativeFunction`, `JSCallableProxy`, `NativeJSClass`, `JSClass`):
183
+ the callee makes its own `this` → return `undefined`.
184
+ - `>= CallableUnknownMakesThisKind_first` (`BoundFunction`, `NativeFunction`):
185
+ walk the bound-function target chain, then re-check. If after unwrapping the
186
+ target is still a plain `NativeFunction` (not promoted into the "makes this"
187
+ range where `NativeConstructor` lives), throw
188
+ `"This function cannot be used as a constructor."`
189
+ - else (not a `Callable` / not an object): throw via `raiseTypeErrorForValue`
190
+ with `" cannot be used as a constructor."`.
191
+
192
+ The ordered `CellKind` ranges that make the `>=` comparisons work are defined in
193
+ `include/hermes/VM/CellKinds.def` (`CallableUnknownMakesThis = {BoundFunction,
194
+ NativeFunction}`, `CallableMakesThis` starts at `NativeConstructor`,
195
+ `CallableExpectsThis = {JSFunction, NativeJSFunction}`), with contiguity enforced
196
+ by static_asserts in `include/hermes/VM/CellKind.h`.
197
+
198
+ ### SH backend: `_sh_ljs_create_this`
199
+
200
+ `_sh_ljs_create_this` (`lib/VM/StaticH.cpp`) is the SH analog with identical
201
+ `CellKind` logic and the same `"This function cannot be used as a constructor."`
202
+ throw. It additionally validates up front that `new.target` is a `Callable`
203
+ (`" invalid new.target."`). It is emitted by `generateCreateThisInst`
204
+ (`lib/BCGen/SH/SH.cpp`), and the JIT emits it too
205
+ (`lib/VM/JIT/arm64/JitEmitter.cpp`). So the constructor rule is present in all
206
+ backends — this is the caller-side construct gate the SH `prohibitInvoke` gap
207
+ does *not* affect.
208
+
209
+ ### C++ builtins also self-check
210
+
211
+ Beyond the `CellKind` rule, dual/opposite-mode builtins enforce their own
212
+ contract in their body by inspecting `args.isConstructorCall()`, e.g.:
213
+
214
+ ```cpp
215
+ if (args.isConstructorCall())
216
+ return runtime.raiseTypeError("BigInt is not a constructor"); // BigInt.cpp
217
+ if (!args.isConstructorCall())
218
+ return runtime.raiseTypeError("ArrayBuffer() called ..."); // ArrayBuffer.cpp
219
+ ```
220
+
221
+ Dual-mode builtins (Array, Date, Error, Boolean) branch on
222
+ `args.isConstructorCall()` internally. `NativeConstructor` itself is largely a
223
+ marker subclass (its `_callImpl` only *asserts* invariants in debug builds).
224
+
225
+ ---
226
+
227
+ ## How the two mechanisms combine
228
+
229
+ During `new X()` the two checks fire in order:
230
+
231
+ 1. **Caller-side (constructor rule).** `CreateThisForNew` / `createThisImpl`
232
+ (interpreter) or `_sh_ljs_create_this` (SH/JIT) runs first, classifies the
233
+ callee by `CellKind`, and either allocates `this`, returns `undefined`, or
234
+ throws `"This function cannot be used as a constructor."` for a plain
235
+ `NativeFunction`. No call frame exists yet.
236
+ 2. **Callee-entry (`prohibitInvoke` flag).** The subsequent `Construct` performs
237
+ the call; on entry the callee's `prohibitInvoke` flag is checked via
238
+ `isCallProhibited(isCtorCall)`, throwing `"Function is not a constructor"` /
239
+ `"Class constructor invoked without new"`.
240
+
241
+ They catch different things and are complementary rather than redundant:
242
+
243
+ | | Caller-side constructor rule | Callee-entry `prohibitInvoke` |
244
+ |---|---|---|
245
+ | Mechanism | `CellKind` range check | `prohibit_invoke` / header-flag bit |
246
+ | Catches | plain `NativeFunction` used with `new` | JS/native function whose flag forbids that invocation (arrow/method/generator/async/class ctor) |
247
+ | Timing | at the `new` site, before the frame exists | when the callee frame is set up |
248
+ | Message | `"This function cannot be used as a constructor."` | `"Function is not a constructor"` / `"Class constructor invoked without new"` |
249
+ | Sites | `createThisImpl` (interp), `_sh_ljs_create_this` (SH/JIT) | `Interpreter.cpp` entry/fast-path, JIT prologue |
250
+
251
+ ### `isConstructor` — the unified predicate
252
+
253
+ `isConstructor` (`lib/VM/Operations.cpp`) is the one place that layers both
254
+ mechanisms together. It walks the `JSCallableProxy` and `BoundFunction` target
255
+ chains to the eventual target, then:
256
+
257
+ - for a `JSFunction` (bytecode), consults the flag via
258
+ `!isCallProhibited(/*construct=*/true)`;
259
+ - for a `NativeJSFunction`, consults `prohibit_invoke != ProhibitInvoke::Construct`;
260
+ - otherwise applies the `CellKind` rule: a plain `NativeFunction` is not a
261
+ constructor unless it is a `FinalizableNativeFunction` or `NativeConstructor`.
262
+
263
+ Note that `createThisImpl` / `_sh_ljs_create_this` do **not** call
264
+ `isConstructor` and do **not** check the flag — they only do the `CellKind`
265
+ check. `isConstructor` is used by RJS/spec operations (e.g. `Reflect.construct`,
266
+ `instanceof` helpers), not as the `new`-site gate.
267
+
268
+ ---
269
+
270
+ ## Cross-calling behavior
271
+
272
+ Because the `prohibitInvoke` check is at the callee entry and keyed on the
273
+ callee's own flags, and the constructor rule is at the `new` site keyed on the
274
+ callee's `CellKind`, both hold uniformly regardless of the caller:
275
+
276
+ - Interpreter → bytecode: flag enforced (interpreter entry / fast path);
277
+ constructor rule enforced at `CreateThisForNew`.
278
+ - JIT → bytecode, and anyone → JIT-compiled bytecode: flag enforced (JIT
279
+ prologue self-checks); constructor rule enforced via emitted
280
+ `_sh_ljs_create_this`.
281
+ - SH → bytecode: flag enforced — `doCall` routes `JSFunction` callees to their
282
+ JIT pointer or `_interpret`, both of which carry the callee-entry check;
283
+ constructor rule enforced via `_sh_ljs_create_this`.
284
+ - Anyone → C++ builtin: the constructor rule (caller-side `CellKind` check)
285
+ rejects `new`ing a non-constructor builtin; call/construct contracts beyond
286
+ that rely on the builtin's own manual checks.
287
+ - Anyone → SH-compiled `NativeJSFunction`: the constructor rule still applies
288
+ caller-side, but the `prohibitInvoke` *flag* is **not** enforced at
289
+ invocation time. This is the one real hole (`TODO(T168592126)`).
290
+
291
+ ---
292
+
293
+ ## Other consumers (not enforcement)
294
+
295
+ - `.prototype` setup: `lib/VM/Callable.cpp` suppresses `.prototype` on
296
+ call-only (`ProhibitInvoke::Construct`) non-generator functions.
297
+ - Inliner: `lib/Optimizer/Scalar/Inlining.cpp` refuses to inline a construct
298
+ call into a `ProhibitConstruct` function, and vice versa for `ProhibitCall`.
299
+ - InstSimplify: `lib/Optimizer/Scalar/InstSimplify.cpp` can drop an unused
300
+ `new.target` when `ProhibitNone`.
301
+ - Disassembler: `lib/BCGen/HBC/BytecodeDisassembler.cpp` prints `Constructor`
302
+ for `ProhibitInvoke::Call` and `NCFunction` for `ProhibitInvoke::Construct`.
303
+
304
+ ---
305
+
306
+ ## Quick reference
307
+
308
+ `prohibitInvoke` (per-function flag, callee-entry):
309
+
310
+ - Enums: `include/hermes/IR/IR.h`, `include/hermes/BCGen/FunctionInfo.h`
311
+ - Decision logic: `lib/IR/IR.cpp` (`Function::getProhibitInvoke()`)
312
+ - Predicate: `include/hermes/BCGen/HBC/BytecodeFileFormat.h` (`isCallProhibited`)
313
+ - Set: `lib/BCGen/HBC/BytecodeGenerator.cpp` (bytecode), `lib/BCGen/SH/SH.cpp` (SH)
314
+ - Interpreter enforcement: `lib/VM/Interpreter.cpp`
315
+ - JIT enforcement: `lib/VM/JIT/arm64/JitEmitter.cpp`, `lib/VM/JIT/JitHandlers.cpp`
316
+ - SH flag gap: `lib/BCGen/SH/SH.cpp`, `lib/VM/StaticH.cpp` (`TODO(T168592126)`)
317
+
318
+ Constructor rule (`CellKind`-based, caller-side):
319
+
320
+ - Interpreter: `CreateThisForNew`/`CreateThisForSuper` in `lib/VM/Interpreter.cpp`
321
+ → `createThisImpl` in `lib/VM/Interpreter-slowpaths.cpp`
322
+ - SH/JIT: `_sh_ljs_create_this` in `lib/VM/StaticH.cpp`, emitted by
323
+ `lib/BCGen/SH/SH.cpp` and `lib/VM/JIT/arm64/JitEmitter.cpp`
324
+ - CellKind ranges: `include/hermes/VM/CellKinds.def`, `include/hermes/VM/CellKind.h`
325
+ - Manual builtin checks: `lib/VM/JSLib/{BigInt,ArrayBuffer,DataView,Boolean,Array,Date,Error}.cpp`
326
+
327
+ Unified predicate:
328
+
329
+ - `isConstructor`: `lib/VM/Operations.cpp`
@@ -0,0 +1,40 @@
1
+ ---
2
+ id: react-native
3
+ title: Hermes and React Native
4
+ ---
5
+
6
+ Hermes is the default JavaScript engine in React Native. This page collects
7
+ the React Native specific information; the rest of the documentation treats
8
+ Hermes as a standalone engine.
9
+
10
+ ## Using Hermes in an app
11
+
12
+ You do not need this repository or a Hermes build. React Native bundles a
13
+ matching Hermes with every release. Follow the
14
+ [React Native Hermes guide](https://reactnative.dev/docs/hermes).
15
+
16
+ ## Versions
17
+
18
+ Each React Native version pins a specific Hermes build. Hermes bytecode and
19
+ the engine ABI change between versions, so mixing a Hermes from one release
20
+ with a React Native from another can crash at start-up. Use the Hermes that
21
+ your React Native version ships with. Release notes are on the
22
+ [releases page](https://github.com/facebook/hermes/releases).
23
+
24
+ ## Hermes V1
25
+
26
+ "Hermes V1" is what React Native calls releases from this repository's
27
+ `static_h` branch, versioned independently of React Native by branch date and
28
+ bytecode version (for example 260318099.0.0) instead of the legacy 0.x. React
29
+ Native 0.82 added it as an opt-in and later versions use it by default. See
30
+ [Branches.md](Branches.md) for how the branches and version numbers relate.
31
+
32
+ To move an app on an older React Native onto a current Hermes V1, see
33
+ [rn-0.xx-hermes-v1](https://github.com/tmikov/rn-0.xx-hermes-v1), a guide
34
+ with worked examples for each starting version.
35
+
36
+ ## Custom builds and native crashes
37
+
38
+ To use a Hermes you built yourself in a React Native app, and to symbolicate
39
+ native crashes in Hermes, see
40
+ [ReactNativeIntegration.md](ReactNativeIntegration.md).
@@ -0,0 +1,94 @@
1
+ ---
2
+ id: react-native-integration
3
+ title: React Native Integration
4
+ ---
5
+
6
+ ## Using a custom Hermes build in a React Native app
7
+
8
+ Since React Native 0.69, Hermes is shipped as part of the React Native distribution. We call this [bundled hermes](https://reactnative.dev/architecture/bundled-hermes).
9
+
10
+ If you wish to customize Hermes and use it inside your React Native app, you can do so by using the `REACT_NATIVE_OVERRIDE_HERMES_DIR` environment variable. This variable allows you to specify a folder where you can store your custom copy of the Hermes repository.
11
+
12
+ ```bash
13
+ export REACT_NATIVE_OVERRIDE_HERMES_DIR=/path/to/your/hermes/repo
14
+ ```
15
+
16
+ If you set this variable, React Native will use the Hermes build from the specified directory instead of the one that comes with the React Native distribution.
17
+
18
+ > [!NOTE]
19
+ > If you are making changes to the compiler in Hermes, be sure to make sure you test your app in release mode as this enables bytecode compilation in advance.
20
+
21
+ ### Instructions for Android
22
+
23
+ On Android, once you set the `REACT_NATIVE_OVERRIDE_HERMES_DIR` environment variable, make sure you also:
24
+
25
+ 1. Enable a build from source following the instructions in the [React Native website](https://reactnative.dev/contributing/how-to-build-from-source#update-your-project-to-build-from-source).
26
+ 2. Re-run the Android app with the `yarn android` command.
27
+
28
+ ### Instructions for iOS
29
+
30
+ On iOS, once you set the `REACT_NATIVE_OVERRIDE_HERMES_DIR` environment variable, make sure you also:
31
+
32
+ 1. Disable React Native's Default Hermes Pod: Ensure that the `:hermes_enabled` flag is set to `false` in `ios/Podfile`.
33
+ ```ruby
34
+ use_react_native!(
35
+ :path => config[:reactNativePath],
36
+ :hermes_enabled => false,
37
+ # ... other configurations
38
+ )
39
+ ```
40
+
41
+ 2. Enable a build from source by installing the pods as follows:
42
+ ```bash
43
+ BUILD_FROM_SOURCE=true bundle exec pod install
44
+ ```
45
+ 3. Re-run the iOS app with the `yarn ios` command.
46
+
47
+ ## Reporting native crashes
48
+
49
+ If Hermes causes a native crash in your application, a stack trace is critical for us to be able to understand where the crash occurred.
50
+
51
+ If you have a native crash to report, please be aware that in most cases, it is not feasible for us to debug crashes in earlier versions of Hermes. Please update your app to the latest React Native version, as that contains the latest hermes-engine versions. Specifically since React Native 0.69, Hermes is now coming [bundled together with React Native](https://reactnative.dev/architecture/bundled-hermes).
52
+
53
+ Including the symbolicated stack trace will make it easier for us to address your bug report more quickly.
54
+
55
+ ### How to symbolicate a native crash on Android
56
+
57
+ To symbolicate a native crash on Android, you need to use the [`ndk-stack`](https://developer.android.com/ndk/guides/ndk-stack) command.
58
+ This command is part of the Android SDK and you should be able to access with `$ANDROID_HOME/ndk/<ndk_version>/ndk-stack` (provided you replace the URL with your NDK version like `$ANDROID_HOME/ndk/21.4.7075529/ndk-stack`).
59
+
60
+ To use the `ndk-stack` command you will need the debug symbols (check the paragraph below to see where to find them).
61
+
62
+ You can then symbolicate a stacktrace as follows:
63
+
64
+ ```bash
65
+ $ANDROID_HOME/ndk/21.4.7075529/ndk-stack -sym ./<path-to-debug-symbols>/obj/local/arm64-v8a < crash.txt
66
+ ```
67
+
68
+ provided that `crash.txt` contains your stacktrace in plain text, and you replace `armeabi-v7a` with the correct architecture you used when the native crash was recorded.
69
+
70
+ As an alternative, you can trigger a crash and have a symbolicated logcat in real time with the following command:
71
+
72
+ ```bash
73
+ adb logcat | $ANDROID_HOME/ndk/21.4.7075529/ndk-stack -sym ./<path-to-debug-symbols>/obj/local/arm64-v8a
74
+ ```
75
+
76
+ ### Where to find the debug symbols
77
+
78
+ #### React Native < 0.69
79
+
80
+ For React Native versions before 0.69 (i.e. hermes-engine 0.11.0 and previous versions), you can find the debug symbols in the [GitHub release](https://github.com/facebook/hermes/releases) corresponding to the Hermes NPM you used to build your application.
81
+
82
+ Download the `hermes-runtime-android-vX.Y.Z.tar.gz` file for your version, unpack the tar file, then run `ndk-stack` using the contained directory as described in the paragraph above.
83
+
84
+ #### React Native 0.69 and 0.70
85
+
86
+ For React Native versions 0.69 and 0.70, you can find the debug symbols in the [GitHub release](https://github.com/facebook/react-native/releases) corresponding to the React Native version you used to build your application.
87
+
88
+ For instance for [React Native 0.70.6](https://github.com/facebook/react-native/releases/tag/v0.70.6), you can find the `hermes-native-symbols-v0.70.6.zip` file with the debug symbols inside.
89
+
90
+ #### React Native >= 0.71
91
+
92
+ For React Native versions 0.71 and above, the debug symbols are uploaded to Maven Central together with the `react-native` and `hermes-engine` artifacts. You don't need to manually download the debug symbols at all, as they will be available to you when you build your apps locally.
93
+
94
+ You can just invoke the `ndk-stack` command suggested above and the symbolication will just work.
@@ -0,0 +1,24 @@
1
+ ---
2
+ id: regexp
3
+ title: RegExp
4
+ ---
5
+
6
+ ## RegExp
7
+
8
+ The Hermes regexp engine is a traditional engine using a backtracking stack. It compiles a regexp into bytecode which can be executed efficiently. For regexp literals like `/abc/`, this occurs at compile time: the regexp bytecode is embedded into the Hermes bytecode file. Note regexp bytecode is distinct from Hermes bytescode.
9
+
10
+ The regexp engine proceeds as follows:
11
+
12
+ 1. *Parse phase.* The regexp parser emits a tree of nodes, effectively an IR.
13
+ 1. *Optimization phase.* The node tree is traversed and optimized in various ways.
14
+ 1. *Emitting phase.* The node tree is traversed and emits regexp bytecode.
15
+ 1. *Execution phase.* The bytecode is executed against an input string.
16
+
17
+ ## Supported Syntax
18
+
19
+ As of this writing, Hermes regexp supports
20
+
21
+ 1. All of ES6, including global, case-insensitive, multiline, sticky, and Unicode (and legacy).
22
+ 1. ES9 lookbehinds.
23
+ 1. Named capture groups.
24
+ 1. Unicode property escapes.
@@ -0,0 +1,85 @@
1
+ # Incompatibilities With The JavaScript Spec
2
+
3
+ This documents aims to collect and explain deliberate differences between Static Hermes and the JavaScript spec.
4
+
5
+ ## Arguments Object
6
+
7
+ ### "Mapped" Arguments Object in Loose Mode
8
+
9
+ In loose mode, updates to the arguments object are not reflected in the function parameter values and vice versa.
10
+ ```javascript
11
+ function foo(param) {
12
+ arguments[0] = 10;
13
+ print(param, arguments[0]); // Prints different values in SH
14
+ }
15
+ ```
16
+
17
+ Motivation: this is a very rare case. Implementing it correctly is expensive and would impose cost on the majority of usages which do not depend on this behavior. Optimizing it, so it doesn't regress legitimate cases is possible, but complex.
18
+
19
+ This is "implementable", but with very low priority.
20
+
21
+ ### Assigning to Arguments in Loose Mode
22
+
23
+ Assignment to `arguments` is prohibited in loose mode.
24
+ ```javascript
25
+ function foo() {
26
+ arguments = 0; // Allowed by the spec, but prohibited in Static Hermes
27
+ }
28
+ ```
29
+
30
+ Motivation: this is a very rare case, not generally useful. Implementing it correctly is possible, but complex, with very little benefit.
31
+
32
+ This is "implementable", but with very low priority.
33
+
34
+ ### Aliasing Arguments With a Var Declaration in Loose Mode
35
+
36
+ In loose mode declaring `var arguments` does not alias the arguments object. Instead it simply creates a new declaration that *shadows* the arguments object, similar to `let`.
37
+ ```javascript
38
+ function foo() {
39
+ var arguments;
40
+ print(arguments); // Prints undefined in Static Hermes
41
+ }
42
+ ```
43
+
44
+ Motivation: similar to assigning to `arguments`, this is a very rare case, with no uses that we are aware of.
45
+
46
+ This is "implementable", but with very low priority.
47
+
48
+ ## `String.prototype.localeCompare` Ignores the Locale
49
+
50
+ `localeCompare` ignores its `locales` and `options` arguments. Its ordering is the DUCET root collation of Unicode Technical Standard #10, not the host locale's.
51
+
52
+ ```javascript
53
+ // Swedish sorts "z" before "ä"; the root collation does not.
54
+ print("ä".localeCompare("z", "sv")); // Prints -1 in Static Hermes
55
+ ```
56
+
57
+ ECMA-262 permits this: without ECMA-402, `localeCompare` need only be a consistent comparison function. It is still worth knowing about, and it is a change from earlier versions, which forwarded to ICU and so did pick up the host locale on Linux and Windows.
58
+
59
+ Two further properties of the ordering:
60
+
61
+ - It is plain DUCET, not the CLDR root that ICU and the platform collators use. CLDR retailors the root in a few places, so some pairs sort differently on Android and Apple, which still use their platform collators.
62
+ - Comparison stops at the tertiary level; there is no identical level. Canonically equivalent strings compare equal, as do strings differing only by a completely ignorable character such as U+0000.
63
+
64
+ Motivation: locale-tailored collation means shipping CLDR tailoring data and a locale database. The root collation table is about 110 KB, needs no system library, and removes the last dependency on ICU for string comparison.
65
+
66
+ ## Full Scoped Function Promotion Semantics in Loose Mode
67
+
68
+ Static Hermes implements most of the scoped function promotion semantics in loose mode, but some corner cases are not spec compliant yet.
69
+
70
+ ```javascript
71
+ function g() {
72
+ {
73
+ function f() { return 1; }
74
+ {
75
+ function f() { return 2; }
76
+ }
77
+ }
78
+ print(f());
79
+ }
80
+ g();
81
+ ```
82
+
83
+ Apparently the spec requires this example to print "1", because the second `f()` shouldn't be promoted to function scope. Shermes prints "2". In our (quick and incomplete) tests, other major engines also print "2".
84
+
85
+ Motivation: these are very rare cases. Loose mode itself is rare. While we intend to address them, the priority is low.