From e91895d7b1d663da3f7627a832a346926fa67194 Mon Sep 17 00:00:00 2001 From: DallonF Date: Fri, 10 Aug 2012 12:17:50 -0700 Subject: [PATCH] Fixed errors on script compiling --- lib/script.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/script.js b/lib/script.js index 88f236b..f52aba9 100644 --- a/lib/script.js +++ b/lib/script.js @@ -9,14 +9,21 @@ var vm = require('vm') */ function Script(src, path) { - this.compiled = vm.createScript('(function() {' + src + '\n}).call(_this)', path); + try { + this.compiled = vm.createScript('(function() {' + src + '\n}).call(_this)', path); + } catch(ex) { + this.error = ex; + } + } /** * Run the current script in the given sandbox. An optional domain may be provided to extend the sandbox exposed to the script. */ -Script.prototype.run = function (ctx, domain, fn) { +Script.prototype.run = function (ctx, domain, fn) { + + if (this.error) { fn(this.error); } if(typeof domain === 'function') { fn = domain;