Skip to content

Commit

Permalink
fix(android): avoid infinite recursion in tab/tabgroup toJSON()
Browse files Browse the repository at this point in the history
  • Loading branch information
sgtcoolguy committed Jan 10, 2020
1 parent fc11337 commit 7280fcc
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions android/modules/ui/src/js/tabgroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,4 +164,42 @@ exports.bootstrap = function (Titanium) {
Object.defineProperty(TabGroup.prototype, 'tabs', { get: TabGroup.prototype.getTabs, set: TabGroup.prototype.setTabs });
Object.defineProperty(TabGroup.prototype, 'activeTab', { get: TabGroup.prototype.getActiveTab, set: TabGroup.prototype.setActiveTab });

// Avoid circular loops in toJSON()
Object.defineProperty(TabGroup.prototype, 'toJSON', {
value: function () {
const keys = Object.keys(this);
const keyCount = keys.length;
const serialized = {};

for (let i = 0; i < keyCount; i++) {
const k = keys[i];
if (k === 'activity' || k.charAt(0) === '_') {
continue;
}
serialized[k] = this[k];
}

return serialized;
},
enumerable: false
});

Object.defineProperty(Titanium.UI.Tab.prototype, 'toJSON', {
value: function () {
const keys = Object.keys(this);
const keyCount = keys.length;
const serialized = {};

for (let i = 0; i < keyCount; i++) {
const k = keys[i];
if (k === 'window' || k === 'tabGroup' || k.charAt(0) === '_') {
continue;
}
serialized[k] = this[k];
}

return serialized;
},
enumerable: false
});
};

0 comments on commit 7280fcc

Please sign in to comment.