Skip to content
This repository was archived by the owner on Nov 25, 2020. It is now read-only.

Commit c8d2c2f

Browse files
committed
User.js Detect and log circular references
Fix circular references in AjxpTabulator (init Tab with object clone).
1 parent d53be73 commit c8d2c2f

File tree

3 files changed

+36
-5
lines changed

3 files changed

+36
-5
lines changed

core/src/plugins/gui.ajax/res/js/ajaxplorer.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/src/plugins/gui.ajax/res/js/ajaxplorer/class.AjxpTabulator.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -641,11 +641,14 @@ Class.create("AjxpTabulator", AjxpPane, {
641641
pair.value.TAB.dontFocus = true;
642642
window.setTimeout(function(){
643643
if(!$(this.htmlElement)) return;
644-
this.addTab(pair.value.TAB, pair.value.PANE, true);
644+
this.addTab(Object.clone(pair.value.TAB), Object.clone(pair.value.PANE), true);
645+
if(pair.value.DATA){
646+
var object = this.getAjxpObjectByTabId(pair.key);
647+
if(object && object.loadStateData) object.loadStateData(pair.value.DATA);
648+
}
645649
}.bind(this), index * 2000);
646650
index ++;
647-
}
648-
if(pair.value.DATA){
651+
}else if(pair.value.DATA){
649652
var object = this.getAjxpObjectByTabId(pair.key);
650653
if(object && object.loadStateData) object.loadStateData(pair.value.DATA);
651654
}

core/src/plugins/gui.ajax/res/js/ajaxplorer/class.User.js

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,35 @@ Class.create("User", {
182182
setPreference : function(prefName, prefValue, toJSON){
183183
if(toJSON){
184184
this._parsedJSONCache.unset(prefName);
185-
prefValue = Object.toJSON(prefValue);
185+
try{
186+
prefValue = Object.toJSON(prefValue);
187+
}catch (e){
188+
if(console) {
189+
function isCyclic (obj) {
190+
var seenObjects = [];
191+
192+
function detect (obj) {
193+
if (obj && typeof obj === 'object') {
194+
if (seenObjects.indexOf(obj) !== -1) {
195+
return true;
196+
}
197+
seenObjects.push(obj);
198+
for (var key in obj) {
199+
if (obj.hasOwnProperty(key) && detect(obj[key])) {
200+
console.log(obj, 'cycle at ' + key);
201+
return true;
202+
}
203+
}
204+
}
205+
return false;
206+
}
207+
return detect(obj);
208+
}
209+
console.log("Caught toJSON error " + e.message, prefValue, isCyclic(prefValue));
210+
211+
}
212+
return;
213+
}
186214
}
187215
this.preferences.set(prefName, prefValue);
188216
},

0 commit comments

Comments
 (0)