Skip to content

Commit

Permalink
Ensure recursion is terminated on objects with cyclical references
Browse files Browse the repository at this point in the history
Reviewed By: spicyj

Differential Revision: D2922542

fb-gh-sync-id: 3820569027a5906ff844f1cda5e2e65c2692e235
shipit-source-id: 3820569027a5906ff844f1cda5e2e65c2692e235
  • Loading branch information
matthewwithanm authored and facebook-github-bot-5 committed Feb 12, 2016
1 parent 4b722d6 commit bb3d8d5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
6 changes: 5 additions & 1 deletion Libraries/ReactNative/ReactNativeBaseComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
8 changes: 7 additions & 1 deletion Libraries/Utilities/deepFreezeAndThrowOnMutationInDev.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
deepFreezeAndThrowOnMutationInDev(object[key]);
}
}

Object.freeze(object);
Object.seal(object);

for (var key in object) {
if (object.hasOwnProperty(key)) {
deepFreezeAndThrowOnMutationInDev(object[key]);
}
}
}
}

Expand Down

0 comments on commit bb3d8d5

Please sign in to comment.