Commit 4e0b7878 4e0b7878dfc62261c1f01255919467f17e82c45d by Nicolas Perriault

fixes #129 - Can't put // comments in evaluate() function

1 parent ef3540a0
......@@ -67,7 +67,9 @@ var FunctionArgsInjector = function FunctionArgsInjector(fn) {
throw new CasperError("Unable to process function " + this.fn.toString());
}
var inject = this.getArgsInjectionString(fnObj.args, values);
return 'function ' + (fnObj.name || '') + '(){' + inject + fnObj.body + '}';
var newFn = new Function([inject, fnObj.body].join('\n'));
newFn.name = fnObj.name || '';
return newFn;
};
this.getArgsInjectionString = function getArgsInjectionString(args, values) {
......
......@@ -19,6 +19,11 @@ function Plip() { return 'plop'; }
function foo_bar(boz) {}
var gni = function ($bubu_bibi, __popo__) {};
var gno = function ( arg1, /*plop*/ arg2 ) { };
function issue129(term) {
// see issue #129
return term;
// see issue #129
}
t.assertEquals(injector.extract(Plop), {
name: 'Plop',
args: ['foo', 'bar'],
......@@ -52,4 +57,8 @@ eval('processed = ' + injector.process({ a: 1, b: 2 }));
t.assertType(processed, "function", 'FunctionArgsInjector.process() processed a function');
t.assertEquals(processed(), 3, 'FunctionArgsInjector.process() processed the function correctly');
// Issue #129
var fnIssue129 = createInjector(issue129).process({term: 'fixed'});
t.assertEquals(fnIssue129('fixed'), 'fixed', 'FunctionArgsInjector.process() has issue #129 fixed');
t.done();
......