From e337ffe2465aae894395b42a8abe8d7ee7fccf91 Mon Sep 17 00:00:00 2001 From: Nico Rehwaldt Date: Fri, 1 Aug 2014 07:47:36 +0200 Subject: [PATCH] chore(Viewer): remove failSafeUtil --- lib/Util.js | 24 ------------------------ lib/Viewer.js | 31 ++++++++++++++++++------------- 2 files changed, 18 insertions(+), 37 deletions(-) delete mode 100644 lib/Util.js diff --git a/lib/Util.js b/lib/Util.js deleted file mode 100644 index 8d1bb423..00000000 --- a/lib/Util.js +++ /dev/null @@ -1,24 +0,0 @@ -var _ = require('lodash'); - -function failSafeAsync(fn) { - - return function() { - - var args = Array.prototype.slice.call(arguments); - - var done = args[args.length - 1]; - if (!done || !_.isFunction(done)) { - done = function(e) { - throw e; - }; - } - - try { - fn.apply(this, args); - } catch (e) { - done(e); - } - }; -} - -module.exports.failSafeAsync = failSafeAsync; \ No newline at end of file diff --git a/lib/Viewer.js b/lib/Viewer.js index f2c2502c..c910fd49 100644 --- a/lib/Viewer.js +++ b/lib/Viewer.js @@ -5,8 +5,7 @@ var Diagram = require('diagram-js'), $ = require('jquery'), _ = require('lodash'); -var Importer = require('./import/Importer'), - util = require('./Util'); +var Importer = require('./import/Importer'); function getSvgContents(diagram) { @@ -176,21 +175,27 @@ Viewer.prototype.invoke = function(fn) { return this.diagram.invoke(fn); }; -Viewer.prototype.importDefinitions = util.failSafeAsync(function(definitions, done) { +Viewer.prototype.importDefinitions = function(definitions, done) { var diagram = this.diagram; - if (diagram) { - this.clear(); + // use try/catch to not swallow synchronous exceptions + // that may be raised during model parsing + try { + if (diagram) { + this.clear(); + } + + this.diagram = diagram = this._createDiagram(this.options.modules); + this.definitions = definitions; + + this._init(diagram); + + Importer.importBpmnDiagram(diagram, definitions, done); + } catch (e) { + done(e); } - - this.diagram = diagram = this._createDiagram(this.options.modules); - this.definitions = definitions; - - this._init(diagram); - - Importer.importBpmnDiagram(diagram, definitions, done); -}); +}; Viewer.prototype._init = function(diagram) { initListeners(diagram, this.__listeners || []);