From ea30aa0fa4aed0ba17b2a88ef0f6ea2ea871bf06 Mon Sep 17 00:00:00 2001 From: Oleg Lokhvitsky Date: Thu, 6 Apr 2017 13:43:54 -0700 Subject: [PATCH] Fixed crash when forwarding already existing property from ReactNativeInternal to ReactNative Reviewed By: ericvicenti Differential Revision: D4843917 fbshipit-source-id: 6cdbac28d8a220a6ac289e8b98d9d50eca35e176 --- Libraries/react-native/react-native-implementation.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Libraries/react-native/react-native-implementation.js b/Libraries/react-native/react-native-implementation.js index 8f61726e7..e38853640 100644 --- a/Libraries/react-native/react-native-implementation.js +++ b/Libraries/react-native/react-native-implementation.js @@ -150,6 +150,14 @@ function applyForwarding(key) { ); return; } + if (ReactNative.hasOwnProperty(key)) { + // WARNING! ReactNative has read-only keys. So, if ReactNativeInternal + // has any duplicate key that ReactNative already has, this assignment + // would fail with "Attempted to assign to readonly property." + // So, if the key already exists on ReactNative, we assume that it's the + // correct module and skip re-assigning it. + return; + } ReactNative[key] = ReactNativeInternal[key]; } for (const key in ReactNativeInternal) {