Put try/catch directly around `this.editor.options.onNodeName(...)` (see #617)

This commit is contained in:
jos 2019-01-05 15:00:13 +01:00
parent 1e29d2a94a
commit 8c74bc7ef9
1 changed files with 12 additions and 12 deletions

View File

@ -4468,25 +4468,25 @@ Node.prototype._escapeJSON = function (text) {
* @private
*/
Node.prototype.updateNodeName = function () {
try {
var count = this.childs ? this.childs.length : 0;
var nodeName;
if (this.type === 'object' || this.type === 'array') {
if (this.editor.options.onNodeName) {
var count = this.childs ? this.childs.length : 0;
var nodeName;
if (this.type === 'object' || this.type === 'array') {
if (this.editor.options.onNodeName) {
try {
nodeName = this.editor.options.onNodeName({
path: this.getPath(),
size: count,
type: this.type
});
}
this.dom.value.innerHTML = (this.type === 'object')
? '{' + (nodeName || count) + '}'
: '[' + (nodeName || count) + ']';
catch (err) {
console.error('Error in onNodeName callback: ', err);
}
}
}
catch (err) {
console.error('Error in onNodeName callback: ', err);
this.dom.value.innerHTML = (this.type === 'object')
? ('{' + (nodeName || count) + '}')
: ('[' + (nodeName || count) + ']');
}
}