Repository navigation
Commit b5eec4e
Forward createValueFromJsonUtf8 in RuntimeDecorator (#58960)
Summary:
Pull Request resolved: #58960
`RuntimeDecorator` doesn't forward `createValueFromJsonUtf8` to the plain runtime, so decorated runtimes use the `JSON.parse`-based default from jsi.cpp instead of the plain runtime's parser. For Hermes that means `makeThreadSafeHermesRuntime` and anything built on `WithRuntimeDecorator` never reach the native parser from a3f615cec.
I think this was missed rather than chosen. `WithRuntimeDecorator` already overrides it (added in c2a0da2ae as `Around` plus `RD::createValueFromJsonUtf8`), which only makes sense if `RuntimeDecorator` forwards it. Today that `RD::` call lands in the default, so it takes one `Around` plus several nested ones for `global`, `getProperty`, `createStringFromUtf8` and `call`. It's also observable: on a thread-safe runtime, after `JSON.parse = () => 'hijacked'`, `Value::createFromJsonUtf8` returns `'hijacked'`, and after `delete globalThis.JSON` it throws. A plain `HermesRuntime` parses normally in both cases.
`TracingRuntime` relies on the current behavior. JSON parsing only shows up in traces because the default splits into traced `global`/`getProperty`/`call` calls. Forwarding alone would hand back a value from the plain runtime with no def, and replay would hit the "has no def" assert in `useObjectID`. So `TracingRuntime` now overrides `createValueFromJsonUtf8` and calls `jsi::Runtime::createValueFromJsonUtf8` explicitly. That runs the same code as before, so traces are unchanged and there's no new record type. If you'd prefer a dedicated SynthTrace record I can do that instead.
A side effect: decorators that watched JSON parsing through `global`/`getProperty`/`call` now need to override `createValueFromJsonUtf8`, like every other forwarded method. For example, `TimedRuntime` no longer counts JSON parsing under its `call` timer. The other methods decorators don't forward yet are the `createError*` family (facebook/hermes#2203) and `String::length` (facebook/hermes#2205). React Native's `decorator.h` has the same gap.
X-link: facebook/hermes#2206
Test Plan:
New tests:
- `JSITest.CreateValueFromJsonUtf8Test` checks that parsing through a `RuntimeDecorator` reaches the wrapped runtime, and keeps coverage of the jsi.cpp default through a decorator that overrides back to it. It calls `outer.createValueFromJsonUtf8` directly to check that the override remains public.
- `HermesRuntimeTest.CreateValueFromJsonUtf8IgnoresGlobalJSON` replaces `JSON.parse` and checks that parsing still works, on the plain and thread-safe runtimes.
- `SynthTraceReplayTest.CreateValueFromJsonUtf8Replay` parses on the tracing runtime, uses the result from native code, and replays with verification.
Without the change the first two fail (the second only on the thread-safe runtime). With only the `decorator.h` part, the SynthTrace test aborts in `useObjectID`. With the full change all pass, and so does the full `APITests` binary (360 tests) in a Debug + ASan build. `APILeanTests` also passes.
The direct call fails to compile with the previous header because `createValueFromJsonUtf8` is protected. With this revision, `cmake --build cmake-build-asan --target check-hermes -j 12` passes in Debug + ASan: 4,126 expected passes, 6 expected failures, and 197 unsupported tests. Node-API checks: 41 passes and 23 skips.
Reviewed By: javache
Differential Revision: D124177263
Pulled By: lavenzg
fbshipit-source-id: 973dc8b3c69002a81e634bb6c992f5f167e13bf21 parent d4d0813 commit b5eec4e
14 files changed
Lines changed: 63 additions & 0 deletions
File tree
- packages/react-native/ReactCommon/jsi/jsi
- test
- scripts/cxx-api/api-snapshots
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
148 | 148 | | |
149 | 149 | | |
150 | 150 | | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
151 | 154 | | |
152 | 155 | | |
153 | 156 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2144 | 2144 | | |
2145 | 2145 | | |
2146 | 2146 | | |
| 2147 | + | |
| 2148 | + | |
| 2149 | + | |
| 2150 | + | |
| 2151 | + | |
| 2152 | + | |
| 2153 | + | |
| 2154 | + | |
| 2155 | + | |
| 2156 | + | |
| 2157 | + | |
| 2158 | + | |
| 2159 | + | |
| 2160 | + | |
| 2161 | + | |
| 2162 | + | |
| 2163 | + | |
| 2164 | + | |
| 2165 | + | |
| 2166 | + | |
| 2167 | + | |
| 2168 | + | |
| 2169 | + | |
| 2170 | + | |
| 2171 | + | |
| 2172 | + | |
| 2173 | + | |
| 2174 | + | |
| 2175 | + | |
| 2176 | + | |
| 2177 | + | |
| 2178 | + | |
| 2179 | + | |
| 2180 | + | |
| 2181 | + | |
| 2182 | + | |
| 2183 | + | |
| 2184 | + | |
| 2185 | + | |
| 2186 | + | |
| 2187 | + | |
| 2188 | + | |
| 2189 | + | |
| 2190 | + | |
| 2191 | + | |
| 2192 | + | |
| 2193 | + | |
| 2194 | + | |
2147 | 2195 | | |
2148 | 2196 | | |
2149 | 2197 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6198 | 6198 | | |
6199 | 6199 | | |
6200 | 6200 | | |
| 6201 | + | |
6201 | 6202 | | |
6202 | 6203 | | |
6203 | 6204 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10553 | 10553 | | |
10554 | 10554 | | |
10555 | 10555 | | |
| 10556 | + | |
10556 | 10557 | | |
10557 | 10558 | | |
10558 | 10559 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6047 | 6047 | | |
6048 | 6048 | | |
6049 | 6049 | | |
| 6050 | + | |
6050 | 6051 | | |
6051 | 6052 | | |
6052 | 6053 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6047 | 6047 | | |
6048 | 6048 | | |
6049 | 6049 | | |
| 6050 | + | |
6050 | 6051 | | |
6051 | 6052 | | |
6052 | 6053 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8009 | 8009 | | |
8010 | 8010 | | |
8011 | 8011 | | |
| 8012 | + | |
8012 | 8013 | | |
8013 | 8014 | | |
8014 | 8015 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12396 | 12396 | | |
12397 | 12397 | | |
12398 | 12398 | | |
| 12399 | + | |
12399 | 12400 | | |
12400 | 12401 | | |
12401 | 12402 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7860 | 7860 | | |
7861 | 7861 | | |
7862 | 7862 | | |
| 7863 | + | |
7863 | 7864 | | |
7864 | 7865 | | |
7865 | 7866 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7868 | 7868 | | |
7869 | 7869 | | |
7870 | 7870 | | |
| 7871 | + | |
7871 | 7872 | | |
7872 | 7873 | | |
7873 | 7874 | | |
| |||
0 commit comments