From 9807668e3e7dea2002a98683c9572f23b865a7b3 Mon Sep 17 00:00:00 2001 From: pyoor Date: Wed, 28 Mar 2018 13:26:28 -0400 Subject: [PATCH] Add support for wrapping arrays elements in try/catch --- lib/utils/script.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/utils/script.js b/lib/utils/script.js index f245d5d..4070d3d 100644 --- a/lib/utils/script.js +++ b/lib/utils/script.js @@ -58,8 +58,12 @@ utils.script = { } return JSON.stringify(o) }, - safely: function (s) { - return 'try { ' + s + ' } catch(e) { }' + safely: function (obj) { + if (Array.isArray(obj)) { + return obj.map(s => utils.script.safely(s)).join(' ') + } else { + return `try { ${obj} } catch(e) { }` + } }, makeLoop: function (s, max) { return 'for (let i = 0; i < ' + (max || make.number.range()) + '; i++) {' + s + '}'