diff --git a/lib/ejs.js b/lib/ejs.js index ca304a13..47a028bb 100644 --- a/lib/ejs.js +++ b/lib/ejs.js @@ -227,6 +227,7 @@ var compile = exports.compile = function(str, options){ var input = JSON.stringify(str) , compileDebug = options.compileDebug !== false , client = options.client + , helpers = options.helpers || {} , filename = options.filename ? JSON.stringify(options.filename) : 'undefined'; @@ -250,7 +251,7 @@ var compile = exports.compile = function(str, options){ if (client) str = 'escape = escape || ' + escape.toString() + ';\n' + str; try { - var fn = new Function('locals, filters, escape, rethrow', str); + var fn = new Function('locals, filters, escape, rethrow, helpers', 'with(helpers){'+ str+'}'); } catch (err) { if ('SyntaxError' == err.name) { err.message += options.filename @@ -263,7 +264,7 @@ var compile = exports.compile = function(str, options){ if (client) return fn; return function(locals){ - return fn.call(this, locals, filters, escape, rethrow); + return fn.call(this, locals, filters, escape, rethrow, helpers); } };