Improve error description of self-reference for js-data model object

It would be better to get a more descriptive exception when a self-reference occurred when handling a js-data model object.
Currently the JsObjectConverter methods leaves the code run itself into a StackOveflowError, like we can see below:

But it would be great if we have some better error handling, like in Firefox:
[Sorry, new users can only put one image in a post.]

My suggestion is to get track of ScriptObjectMirror that have already been converted and throw a more descriptive error to help out developers solving that problem. For example, pointing out the object node where a self-reference starts. Some projects have big objects to handle, and it’s very hard to achieve a good debugging without automation.

Example js object:

var jsObject = {
	"tourRelatedContent": {
		"itineraries": []
	},
	"alternatives": [],
	"selectedItinerary": {
		"loop": []
	}
};

jsObject.tourRelatedContent.itineraries = jsObject.tourRelatedContent.itineraries || []; // Assure array exists
var itineraries = jsObject.tourRelatedContent.itineraries;
jsObject.alternatives = itineraries; //Redundancy 1
itineraries.push(jsObject.selectedItinerary); //Redundancy 2
jsObject.selectedItinerary.loop = itineraries; // Auto-reference

var fun1 = function() {
	return jsObject;
};
1 Like

Related issue: https://github.com/enonic/xp/issues/7515

This is fixed in 7.3.