From c91e2f2dbb12d12b7f7c9f46acbdc3c83a7a5f85 Mon Sep 17 00:00:00 2001 From: Danny Yoo Date: Mon, 21 Nov 2011 18:34:50 -0500 Subject: [PATCH] adding some more error trapping on the tree navigation primitives --- web-world/js-impl.js | 55 ++++++++++++++++++++++++++++++++----- web-world/js-tree-cursor.js | 4 +++ 2 files changed, 52 insertions(+), 7 deletions(-) diff --git a/web-world/js-impl.js b/web-world/js-impl.js index d4798a3..b1c91e2 100644 --- a/web-world/js-impl.js +++ b/web-world/js-impl.js @@ -1562,6 +1562,11 @@ var checkMockView = plt.baselib.check.makeCheckArgumentType( isMockView, 'view'); + var checkMockViewOnElement = plt.baselib.check.makeCheckArgumentType( + function(x) { + return isMockView(x) && (!(x.cursor.isOnAtomicElement())); + }, + 'element-focused view'); var checkSelector = plt.baselib.check.makeCheckArgumentType( @@ -1719,7 +1724,13 @@ 1, function(MACHINE) { var view = checkMockView(MACHINE, 'view-left', 0); - return view.left(); + try { + return view.left(); + } catch (e) { + plt.baselib.exceptions.raise( + MACHINE, + new Error("unable to focus left")); + } }); EXPORTS['view-right'] = makePrimitiveProcedure( @@ -1727,7 +1738,13 @@ 1, function(MACHINE) { var view = checkMockView(MACHINE, 'view-right', 0); - return view.right(); + try { + return view.right(); + } catch (e) { + plt.baselib.exceptions.raise( + MACHINE, + new Error("unable to focus right")); + } }); EXPORTS['view-up'] = makePrimitiveProcedure( @@ -1735,7 +1752,13 @@ 1, function(MACHINE) { var view = checkMockView(MACHINE, 'view-up', 0); - return view.up(); + try { + return view.up(); + } catch (e) { + plt.baselib.exceptions.raise( + MACHINE, + new Error("unable to focus up")); + } }); EXPORTS['view-down'] = makePrimitiveProcedure( @@ -1743,7 +1766,13 @@ 1, function(MACHINE) { var view = checkMockView(MACHINE, 'view-down', 0); - return view.down(); + try { + return view.down(); + } catch(e) { + plt.baselib.exceptions.raise( + MACHINE, + new Error("unable to focus down")); + } }); EXPORTS['view-forward'] = makePrimitiveProcedure( @@ -1751,7 +1780,13 @@ 1, function(MACHINE) { var view = checkMockView(MACHINE, 'view-forward', 0); - return view.forward(); + try { + return view.forward(); + } catch(e) { + plt.baselib.exceptions.raise( + MACHINE, + new Error("unable to focus forward")); + } }); EXPORTS['view-backward'] = makePrimitiveProcedure( @@ -1759,7 +1794,13 @@ 1, function(MACHINE) { var view = checkMockView(MACHINE, 'view-backward', 0); - return view.backward(); + try { + return view.backward(); + } catch(e) { + plt.baselib.exceptions.raise( + MACHINE, + new Error("unable to focus backward")); + } }); @@ -1946,7 +1987,7 @@ 'view-append-child', 2, function(MACHINE) { - var view = checkMockView(MACHINE, 'view-append-child', 0); + var view = checkMockViewOnElement(MACHINE, 'view-append-child', 0); var x = MACHINE.e[MACHINE.e.length - 2]; PAUSE(function(restart) { coerseToDomNode(x, diff --git a/web-world/js-tree-cursor.js b/web-world/js-tree-cursor.js index a9b59db..b1b400f 100644 --- a/web-world/js-tree-cursor.js +++ b/web-world/js-tree-cursor.js @@ -28,6 +28,10 @@ var TreeCursor = (function() { this.atomicF = atomicF; }; + TreeCursor.prototype.isOnAtomicElement = function() { + return this.atomicF(this.node); + }; + TreeCursor.prototype.canDown = function() { return (!(this.atomicF(this.node)) && this.openF(this.node).length !== 0);