From 2fbd8f063e46c0eabb8efebfddf072a3eeecfb33 Mon Sep 17 00:00:00 2001 From: "Owen W. Taylor" Date: Mon, 19 May 2014 22:11:48 -0400 Subject: [PATCH] Scripting: catch errors from shell-perf-helper When calling remote D-Bus methods, handle exceptions, log them and exit, rather than just proceeding as if nothing happened. https://bugzilla.gnome.org/show_bug.cgi?id=732349 --- js/ui/scripting.js | 63 +++++++++++++++++++++++----------------------- 1 file changed, 31 insertions(+), 32 deletions(-) diff --git a/js/ui/scripting.js b/js/ui/scripting.js index 4e7453a0d..4cea3a15f 100644 --- a/js/ui/scripting.js +++ b/js/ui/scripting.js @@ -98,6 +98,28 @@ function _getPerfHelper() { return _perfHelper; } +function _callRemote(obj, method, ...args) { + let cb; + let errcb; + + args.push(function(result, excp) { + if (excp) { + if (errcb) + errcb(excp); + } else { + if (cb) + cb(); + } + }); + + method.apply(obj, args); + + return function(callback, error_callback) { + cb = callback; + errcb = error_callback; + }; +} + /** * createTestWindow: * @params: options for window creation. @@ -119,19 +141,10 @@ function createTestWindow(width, height, params) { alpha: false, maximized: false }); - let cb; let perfHelper = _getPerfHelper(); - - perfHelper.CreateWindowRemote(params.width, params.height, - params.alpha, params.maximized, - function(result, excp) { - if (cb) - cb(); - }); - - return function(callback) { - cb = callback; - }; + return _callRemote(perfHelper, perfHelper.CreateWindowRemote, + params.width, params.height, + params.alpha, params.maximized); } /** @@ -141,17 +154,8 @@ function createTestWindow(width, height, params) { * created with createTestWindow have been mapped and exposed. */ function waitTestWindows() { - let cb; let perfHelper = _getPerfHelper(); - - perfHelper.WaitWindowsRemote(function(result, excp) { - if (cb) - cb(); - }); - - return function(callback) { - cb = callback; - }; + return _callRemote(perfHelper, perfHelper.WaitWindowsRemote); } /** @@ -164,17 +168,8 @@ function waitTestWindows() { * process because of normal X asynchronicity. */ function destroyTestWindows() { - let cb; let perfHelper = _getPerfHelper(); - - perfHelper.DestroyWindowsRemote(function(result, excp) { - if (cb) - cb(); - }); - - return function(callback) { - cb = callback; - }; + return _callRemote(perfHelper, perfHelper.DestroyWindowsRemote); } /** @@ -217,6 +212,10 @@ function _step(g, finish, onError) { let waitFunction = g.next(); waitFunction(function() { _step(g, finish, onError); + }, + function(err) { + if (onError) + onError(err); }); } catch (err if err instanceof StopIteration) { if (finish)