Skip to content

Use createError in JSError and forward it in RuntimeDecorator - #58961

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

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

Conversation

@lavenzg

@lavenzg lavenzg commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

Summary:
JSError(rt, message) still creates its value by looking up globalThis.Error and calling it, which predates IRuntime::createError. It now uses rt.createError(...) like the JSError::createXError factories, with the same try/catch fallback. The default Runtime::createError makes the same global call, so runtimes without a native implementation behave as before. On Hermes every JSError thrown from native code skips a global lookup and a JS call, and message, stack and what() come out the same.

RuntimeDecorator and WithRuntimeDecorator didn't forward the createError family, so decorated runtimes (the thread-safe runtime, TracingRuntime) quietly fell back to the global constructor calls. They forward to plain() now, through Around for WithRuntimeDecorator, and they're public like in jsi::Runtime.

One visible difference on Hermes, same as the other createXError APIs: if user code replaced or deleted globalThis.Error, JSError(rt, message) no longer calls the replacement and creates a real Error anyway.

X-link: facebook/hermes#2203

Differential Revision: D124178378

Pulled By: lavenzg

Summary:
`JSError(rt, message)` still creates its value by looking up `globalThis.Error` and calling it, which predates `IRuntime::createError`. It now uses `rt.createError(...)` like the `JSError::createXError` factories, with the same try/catch fallback. The default `Runtime::createError` makes the same global call, so runtimes without a native implementation behave as before. On Hermes every `JSError` thrown from native code skips a global lookup and a JS call, and `message`, `stack` and `what()` come out the same.

`RuntimeDecorator` and `WithRuntimeDecorator` didn't forward the `createError` family, so decorated runtimes (the thread-safe runtime, `TracingRuntime`) quietly fell back to the global constructor calls. They forward to `plain()` now, through `Around` for `WithRuntimeDecorator`, and they're public like in `jsi::Runtime`.

One visible difference on Hermes, same as the other `createXError` APIs: if user code replaced or deleted `globalThis.Error`, `JSError(rt, message)` no longer calls the replacement and creates a real `Error` anyway.

X-link: facebook/hermes#2203

Differential Revision: D124178378

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
@facebook-github-tools facebook-github-tools Bot added p: Facebook Partner: Facebook Partner labels 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 D124178378.

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