Skip to content

Commit

Permalink
fix init problems
Browse files Browse the repository at this point in the history
  • Loading branch information
pmario committed Apr 16, 2024
1 parent 838c463 commit 04f9477
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
6 changes: 3 additions & 3 deletions core/modules/widgets/button.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ Button widget
/*global $tw: false */
"use strict";

/* String: Maximum -relative- permitted depth of the widget tree for recursion detection */
var MAX_WIDGET_TREE_DEPTH_RELATIVE = "50";
/* Maximum -relative- permitted depth of the widget tree for recursion detection */
var MAX_WIDGET_TREE_DEPTH_RELATIVE = 50;

var Widget = require("$:/core/modules/widgets/widget.js").widget;

Expand All @@ -26,7 +26,7 @@ var ButtonWidget = function(parseTreeNode,options) {
if(!this.hasVariable("tv-button","true")) {
this.setVariable("tv-button", "true");
// set "local" max depth to a relative value, so nesting in higher levels is possible
this.setVariable("tv-UNSAFE-max-widget-tree-depth", this.getAncestorCount() + MAX_WIDGET_TREE_DEPTH_RELATIVE);
this.setVariable("tv-UNSAFE-max-widget-tree-depth", this.getAncestorCount() + MAX_WIDGET_TREE_DEPTH_RELATIVE + "");
// allow users to debug the info
this.setVariable("tv-ancestors", this.getAncestorCount() + "");
}
Expand Down
11 changes: 5 additions & 6 deletions core/modules/widgets/widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ Widget base class
/*global $tw: false */
"use strict";

/* String: Maximum permitted depth of the widget tree for recursion detection */
var MAX_WIDGET_TREE_DEPTH = "1000";
/* 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
Expand Down Expand Up @@ -481,7 +481,7 @@ Widget.prototype.getAncestorCount = function() {
this.ancestorCount = this.parentWidget.getAncestorCount() + 1;
} else {
this.ancestorCount = 0;
this.setVariable("tv-UNSAFE-max-widget-tree-depth", MAX_WIDGET_TREE_DEPTH);
this.setVariable("tv-UNSAFE-max-widget-tree-depth", MAX_WIDGET_TREE_DEPTH + "");
}
}
return this.ancestorCount;
Expand All @@ -493,10 +493,9 @@ Make child widgets correspondng to specified parseTreeNodes
Widget.prototype.makeChildWidgets = function(parseTreeNodes,options) {
options = options || {};
this.children = [];
var self = this,
maxWidgetTreeDepth = $tw.utils.getInt(this.variables["tv-UNSAFE-max-widget-tree-depth"].value, MAX_WIDGET_TREE_DEPTH);
var self = this;
// Check for too much recursion
if(this.getAncestorCount() > maxWidgetTreeDepth) {
if(this.getAncestorCount() > $tw.utils.getInt(this.variables["tv-UNSAFE-max-widget-tree-depth"].value, MAX_WIDGET_TREE_DEPTH + "")) {
this.children.push(this.makeChildWidget({type: "error", attributes: {
"$message": {type: "string", value: this.getAncestorCount() + " - " + $tw.language.getString("Error/RecursiveTransclusion")}
}}));
Expand Down

0 comments on commit 04f9477

Please sign in to comment.