From 167d7861cbf72658efacd329536a46b5dc069076 Mon Sep 17 00:00:00 2001 From: Elliott Sprehn Date: Mon, 10 Dec 2018 05:54:14 -0800 Subject: [PATCH] Don't crash on second resolve or reject in PromiseImpl. (#20303) Summary: Promise semantics per JS should allow calling resolve or reject repeatedly without crashing. Only the first one should do anything, but others should be allowed. This change fixes the Java bridge for Android. A separate change is needed for iOS. Issue #20262 Pull Request resolved: https://github.com/facebook/react-native/pull/20303 Differential Revision: D13396975 Pulled By: cpojer fbshipit-source-id: 81f14f73654fa7c44e043f574a39fda481ace44b --- .../src/main/java/com/facebook/react/bridge/PromiseImpl.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ReactAndroid/src/main/java/com/facebook/react/bridge/PromiseImpl.java b/ReactAndroid/src/main/java/com/facebook/react/bridge/PromiseImpl.java index de4f7c4b4..98a46f9af 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/bridge/PromiseImpl.java +++ b/ReactAndroid/src/main/java/com/facebook/react/bridge/PromiseImpl.java @@ -28,6 +28,8 @@ public class PromiseImpl implements Promise { public void resolve(Object value) { if (mResolve != null) { mResolve.invoke(value); + mResolve = null; + mReject = null; } } @@ -67,5 +69,7 @@ public class PromiseImpl implements Promise { // TODO(8850038): add the stack trace info in, need to figure out way to serialize that mReject.invoke(errorInfo); } + mResolve = null; + mReject = null; } }