From 05c17c76da210fb66ea6c293dc11d9f5cbd9a89e Mon Sep 17 00:00:00 2001 From: Marc Horowitz Date: Sat, 14 Mar 2020 00:10:00 -0700 Subject: [PATCH] Add a little headroom to the stack when converting an exception JS -> C++ Summary: This was causing an exception cascade leading to production errors. Added a test which repros the problem and passes with the fix. Changelog: [Internal] Reviewed By: tmikov Differential Revision: D20408858 fbshipit-source-id: 3fa9b8669bf3bf7617bfc05ef8f23d52bc969b4e --- ReactCommon/jsi/jsi/test/testlib.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/ReactCommon/jsi/jsi/test/testlib.cpp b/ReactCommon/jsi/jsi/test/testlib.cpp index 320732f1dc3..ad3b9937584 100644 --- a/ReactCommon/jsi/jsi/test/testlib.cpp +++ b/ReactCommon/jsi/jsi/test/testlib.cpp @@ -1029,6 +1029,30 @@ TEST_P(JSITest, JSErrorDoesNotInfinitelyRecurse) { rt.global().setProperty(rt, "Error", globalError); } +TEST_P(JSITest, JSErrorStackOverflowHandling) { + rt.global().setProperty( + rt, + "callSomething", + Function::createFromHostFunction( + rt, + PropNameID::forAscii(rt, "callSomething"), + 0, + [this]( + Runtime& rt2, + const Value& thisVal, + const Value* args, + size_t count) { + EXPECT_EQ(&rt, &rt2); + return function("function() { return 0; }").call(rt); + })); + try { + eval("(function f() { callSomething(); f.apply(); })()"); + FAIL(); + } catch (const JSError& ex) { + EXPECT_NE(std::string(ex.what()).find("exceeded"), std::string::npos); + } +} + TEST_P(JSITest, ScopeDoesNotCrashTest) { Scope scope(rt); Object o(rt);