Skip to content

Forward createValueFromJsonUtf8 in RuntimeDecorator - #58960

Open
lavenzg wants to merge 1 commit into
react:mainfrom
lavenzg:export-D124177263
Open

lavenzg wants to merge 1 commit into
react:mainfrom
lavenzg:export-D124177263

Conversation

@lavenzg

@lavenzg lavenzg commented Oct 8, 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 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

Differential Revision: D124177263

Pulled By: lavenzg

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

Differential Revision: D124177263

Pulled By: lavenzg
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Oct 8, 2026
@meta-codesync

meta-codesync Bot commented Oct 8, 2026

Copy link
Copy Markdown

@lavenzg has exported this pull request. If you are a Meta employee, you can view the originating Diff in D124177263.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. meta-exported p: Facebook Partner: Facebook Partner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants