Skip to content

Forward createValueFromJsonUtf8 in RuntimeDecorator - #2206

Closed
mrousavy wants to merge 2 commits into
meta:static_hfrom
mrousavy:decorator-json
Closed

mrousavy wants to merge 2 commits into
meta:static_hfrom
mrousavy:decorator-json

Conversation

@mrousavy

@mrousavy mrousavy commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Summary

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 a3f615c.

I think this was missed rather than chosen. WithRuntimeDecorator already overrides it (added in c2a0da2 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 (#2203) and String::length (#2205). React Native's decorator.h has the same gap.

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.

@meta-cla meta-cla Bot added the CLA Signed Do not delete this pull request or issue due to inactivity. label Sep 25, 2026
RuntimeDecorator does not forward createValueFromJsonUtf8 to the plain
runtime, so decorated runtimes (including WithRuntimeDecorator and the
thread-safe Hermes runtime) fall back to the JSON.parse based default in
jsi::Runtime instead of the plain runtime's implementation.

TracingRuntime relied on that fallback to record JSON parsing, so it now
overrides the method and keeps using the default explicitly. Traces are
unchanged.
Comment thread API/jsi/jsi/decorator.h Resolved
@meta-codesync

meta-codesync Bot commented Oct 8, 2026

Copy link
Copy Markdown

@lavenzg has imported this pull request. If you are a Meta employee, you can view this in D124177263.

meta-codesync Bot pushed a commit that referenced this pull request Oct 13, 2026
Summary:
X-link: react/react-native#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 a3f615c.

I think this was missed rather than chosen. `WithRuntimeDecorator` already overrides it (added in c2a0da2 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 (#2203) and `String::length` (#2205). React Native's `decorator.h` has the same gap.

Pull Request resolved: #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: 973dc8b3c69002a81e634bb6c992f5f167e13bf2
meta-codesync Bot pushed a commit that referenced this pull request Oct 13, 2026
Summary:
X-link: react/react-native#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 a3f615c.

I think this was missed rather than chosen. `WithRuntimeDecorator` already overrides it (added in c2a0da2 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 (#2203) and `String::length` (#2205). React Native's `decorator.h` has the same gap.

Pull Request resolved: #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: 973dc8b3c69002a81e634bb6c992f5f167e13bf2
@meta-codesync meta-codesync Bot closed this in 1d2fc48 Oct 13, 2026
@meta-codesync meta-codesync Bot added the Merged label Oct 13, 2026
@meta-codesync

meta-codesync Bot commented Oct 13, 2026

Copy link
Copy Markdown

@lavenzg merged this pull request in 1d2fc48.

meta-codesync Bot pushed a commit to react/react-native that referenced this pull request Oct 13, 2026
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 (meta/hermes#2203) and `String::length` (meta/hermes#2205). React Native's `decorator.h` has the same gap.

X-link: meta/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: 973dc8b3c69002a81e634bb6c992f5f167e13bf2
cipolleschi pushed a commit to react/react-native that referenced this pull request Oct 26, 2026
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 (meta/hermes#2203) and `String::length` (meta/hermes#2205). React Native's `decorator.h` has the same gap.

X-link: meta/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: 973dc8b3c69002a81e634bb6c992f5f167e13bf2
(cherry picked from commit b5eec4e)
tvinhas pushed a commit to tvinhas/react-native-macos that referenced this pull request Oct 28, 2026
Summary:
Pull Request resolved: react#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 (meta/hermes#2203) and `String::length` (meta/hermes#2205). React Native's `decorator.h` has the same gap.

X-link: meta/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: 973dc8b3c69002a81e634bb6c992f5f167e13bf2
(cherry picked from commit b5eec4e)

This branch was previously deployed

1 inactive deployment
npm-publish — d3ea5bf8 Deployed Oct 7, 2026 by mrousavy via publish #1549
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed Do not delete this pull request or issue due to inactivity. Merged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants