From bb3d8d535000ad78a95776f2de9282130f80d0bd Mon Sep 17 00:00:00 2001 From: Matthew Dapena-Tretter Date: Fri, 12 Feb 2016 14:53:36 -0800 Subject: [PATCH] Ensure recursion is terminated on objects with cyclical references Reviewed By: spicyj Differential Revision: D2922542 fb-gh-sync-id: 3820569027a5906ff844f1cda5e2e65c2692e235 shipit-source-id: 3820569027a5906ff844f1cda5e2e65c2692e235 --- Libraries/ReactNative/ReactNativeBaseComponent.js | 6 +++++- .../Utilities/deepFreezeAndThrowOnMutationInDev.js | 10 ++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/Libraries/ReactNative/ReactNativeBaseComponent.js b/Libraries/ReactNative/ReactNativeBaseComponent.js index 0beef9334..ceb600aaa 100644 --- a/Libraries/ReactNative/ReactNativeBaseComponent.js +++ b/Libraries/ReactNative/ReactNativeBaseComponent.js @@ -115,7 +115,11 @@ ReactNativeBaseComponent.Mixin = { this._currentElement = nextElement; if (__DEV__) { - deepFreezeAndThrowOnMutationInDev(this._currentElement.props); + for (var key in this.viewConfig.validAttributes) { + if (nextElement.props.hasOwnProperty(key)) { + deepFreezeAndThrowOnMutationInDev(nextElement.props[key]); + } + } } var updatePayload = ReactNativeAttributePayload.diff( diff --git a/Libraries/Utilities/deepFreezeAndThrowOnMutationInDev.js b/Libraries/Utilities/deepFreezeAndThrowOnMutationInDev.js index 9263116ed..b1dac7777 100644 --- a/Libraries/Utilities/deepFreezeAndThrowOnMutationInDev.js +++ b/Libraries/Utilities/deepFreezeAndThrowOnMutationInDev.js @@ -42,11 +42,17 @@ function deepFreezeAndThrowOnMutationInDev(object: Object) { if (object.hasOwnProperty(key)) { object.__defineGetter__(key, identity.bind(null, object[key])); object.__defineSetter__(key, throwOnImmutableMutation.bind(null, key)); + } + } + + Object.freeze(object); + Object.seal(object); + + for (var key in object) { + if (object.hasOwnProperty(key)) { deepFreezeAndThrowOnMutationInDev(object[key]); } } - Object.freeze(object); - Object.seal(object); } }