Fixed errors on script compiling

This commit is contained in:
DallonF
2012-08-10 12:17:50 -07:00
parent f3757e5dfb
commit e91895d7b1

View File

@@ -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;