diff --git a/core/modules/utils/errors.js b/core/modules/utils/errors.js index 73f60ae84..fac4b3fa7 100644 --- a/core/modules/utils/errors.js +++ b/core/modules/utils/errors.js @@ -8,11 +8,16 @@ Custom errors for TiddlyWiki. \*/ (function(){ -function TranscludeRecursionError(depth) { - this.depth = depth; +function TranscludeRecursionError() { + Error.apply(this,arguments); this.signatures = Object.create(null); }; +/* Maximum permitted depth of the widget tree for recursion detection */ +TranscludeRecursionError.MAX_WIDGET_TREE_DEPTH = 1000; + +TranscludeRecursionError.prototype = Object.create(Error); + exports.TranscludeRecursionError = TranscludeRecursionError; })(); diff --git a/core/modules/widgets/transclude.js b/core/modules/widgets/transclude.js index ce51e2102..35b4941bd 100755 --- a/core/modules/widgets/transclude.js +++ b/core/modules/widgets/transclude.js @@ -39,7 +39,7 @@ TranscludeWidget.prototype.render = function(parent,nextSibling) { // Hopefully that will land us just outside where the loop began. That's where we want to issue an error. // Rendering widgets beneath this point may result in a freezing browser if they explode exponentially. var transcludeSignature = this.getVariable("transclusion"); - if(this.getAncestorCount() > error.depth - 50) { + if(this.getAncestorCount() > $tw.utils.TranscludeRecursionError.MAX_WIDGET_TREE_DEPTH - 50) { // For the first fifty transcludes we climb up, we simply collect signatures. // We're assuming that those first 50 will likely include all transcludes involved in the loop. error.signatures[transcludeSignature] = true; diff --git a/core/modules/widgets/widget.js b/core/modules/widgets/widget.js index 1fe951787..601ff68f9 100755 --- a/core/modules/widgets/widget.js +++ b/core/modules/widgets/widget.js @@ -12,9 +12,6 @@ Widget base class /*global $tw: false */ "use strict"; -/* Maximum permitted depth of the widget tree for recursion detection */ -var MAX_WIDGET_TREE_DEPTH = 1000; - /* Create a widget object for a parse tree node parseTreeNode: reference to the parse tree node to be rendered @@ -494,8 +491,8 @@ Widget.prototype.makeChildWidgets = function(parseTreeNodes,options) { this.children = []; var self = this; // Check for too much recursion - if(this.getAncestorCount() > MAX_WIDGET_TREE_DEPTH) { - throw new $tw.utils.TranscludeRecursionError(MAX_WIDGET_TREE_DEPTH); + if(this.getAncestorCount() > $tw.utils.TranscludeRecursionError.MAX_WIDGET_TREE_DEPTH) { + throw new $tw.utils.TranscludeRecursionError(); } else { // Create set variable widgets for each variable $tw.utils.each(options.variables,function(value,name) { diff --git a/editions/test/tiddlers/tests/test-widget.js b/editions/test/tiddlers/tests/test-widget.js index 9724c72b4..1c7665a53 100755 --- a/editions/test/tiddlers/tests/test-widget.js +++ b/editions/test/tiddlers/tests/test-widget.js @@ -180,7 +180,7 @@ describe("Widget module", function() { expect(wrapper.innerHTML).toBe("Recursive transclusion error in transclude widget Recursive transclusion error in transclude widget"); }); - fit("should handle many-tiddler recursion with branching nodes", function() { + it("should handle many-tiddler recursion with branching nodes", function() { var wiki = new $tw.Wiki(); // Add a tiddler wiki.addTiddlers([