Skip to content

Commit 9faf256

Browse files
neildharfacebook-github-bot
authored andcommitted
Add simple constructor for JSError (facebook#39415)
Summary: Pull Request resolved: facebook#39415 Add a simple constructor for `JSError` which does not accept a `jsi::Runtime` and cannot call back into JSI. This guarantees that the constructor cannot recursively invoke itself, leading to stack overflows. Changelog: [Internal] Reviewed By: avp Differential Revision: D48796703 fbshipit-source-id: 1c134e8a59ff54be64a5da901e548436d512c21d
1 parent dce7242 commit 9faf256

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

packages/react-native/ReactCommon/jsi/jsi/jsi.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,12 @@ JSError::JSError(std::string what, Runtime& rt, Value&& value)
450450
setValue(rt, std::move(value));
451451
}
452452

453+
JSError::JSError(Value&& value, std::string message, std::string stack)
454+
: JSIException(message + "\n\n" + stack),
455+
value_(std::make_shared<Value>(std::move(value))),
456+
message_(std::move(message)),
457+
stack_(std::move(stack)) {}
458+
453459
void JSError::setValue(Runtime& rt, Value&& value) {
454460
value_ = std::make_shared<Value>(std::move(value));
455461

packages/react-native/ReactCommon/jsi/jsi/jsi.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1468,6 +1468,11 @@ class JSI_EXPORT JSError : public JSIException {
14681468
/// but necessary to avoid ambiguity with the above.
14691469
JSError(std::string what, Runtime& rt, Value&& value);
14701470

1471+
/// Creates a JSError referring to the provided value, message and stack. This
1472+
/// constructor does not take a Runtime parameter, and therefore cannot result
1473+
/// in recursively invoking the JSError constructor.
1474+
JSError(Value&& value, std::string message, std::string stack);
1475+
14711476
JSError(const JSError&) = default;
14721477

14731478
virtual ~JSError();

0 commit comments

Comments
 (0)