smartxml: throw exception on transformation returning invalid change root
authorAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Sun, 8 Dec 2013 12:40:58 +0000 (13:40 +0100)
committerAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Sun, 15 Dec 2013 21:32:49 +0000 (22:32 +0100)
src/smartxml/transformations.js

index 25c0ec1..3f4b65f 100644 (file)
@@ -90,7 +90,17 @@ toret.createGenericTransformation = function(desc, name) {
         run: function(options) {
             var changeRoot;
             if(!desc.undo && options.beUndoable) {
-                changeRoot = desc.getChangeRoot ? desc.getChangeRoot.call(this) : this.document.root;
+                if(desc.getChangeRoot) {
+                    changeRoot = desc.getChangeRoot.call(this);
+                    if(!changeRoot) {
+                        throw new Error(
+                            'Transformation {name} returned invalid change root value'
+                            .replace('{name}', name)
+                        );
+                    }
+                } else {
+                    changeRoot = this.document.root;
+                }
                 this.snapshot = changeRoot.clone();
                 this.changeRootPath = changeRoot.getPath();
             }