Reduce eval scope in test env

This commit is contained in:
kpdecker
2013-10-14 22:49:23 -05:00
parent 84049bf0c5
commit 6f94fc0a3b
3 changed files with 18 additions and 3 deletions
+6 -1
View File
@@ -1,3 +1,4 @@
/*global handlebarsEnv */
require('./common');
var _ = require('underscore'),
@@ -10,9 +11,13 @@ vm.runInThisContext(fs.readFileSync(__dirname + '/../../dist/handlebars.js'), 'd
global.CompilerContext = {
compile: function(template, options) {
var templateSpec = handlebarsEnv.precompile(template, options);
return handlebarsEnv.template(eval('(' + templateSpec + ')'));
return handlebarsEnv.template(safeEval(templateSpec));
},
compileWithPartial: function(template, options) {
return handlebarsEnv.compile(template, options);
}
};
function safeEval(templateSpec) {
return eval('(' + templateSpec + ')');
}
+6 -1
View File
@@ -1,3 +1,4 @@
/*global handlebarsEnv */
require('./common');
global.Handlebars = require('../../lib');
@@ -5,9 +6,13 @@ global.Handlebars = require('../../lib');
global.CompilerContext = {
compile: function(template, options) {
var templateSpec = handlebarsEnv.precompile(template, options);
return handlebarsEnv.template(eval('(' + templateSpec + ')'));
return handlebarsEnv.template(safeEval(templateSpec));
},
compileWithPartial: function(template, options) {
return handlebarsEnv.compile(template, options);
}
};
function safeEval(templateSpec) {
return eval('(' + templateSpec + ')');
}
+6 -1
View File
@@ -1,3 +1,4 @@
/*global handlebarsEnv */
require('./common');
var _ = require('underscore'),
@@ -12,7 +13,7 @@ var compiler = require('../../dist/cjs/handlebars/compiler/compiler');
global.CompilerContext = {
compile: function(template, options) {
var templateSpec = compiler.precompile(template, options);
return handlebarsEnv.template(eval('(' + templateSpec + ')'));
return handlebarsEnv.template(safeEval(templateSpec));
},
compileWithPartial: function(template, options) {
// Hack the compiler on to the environment for these specific tests
@@ -22,3 +23,7 @@ global.CompilerContext = {
return handlebarsEnv.compile(template, options);
}
};
function safeEval(templateSpec) {
return eval('(' + templateSpec + ')');
}