fixes #129 - Can't put // comments in evaluate() function
Showing
2 changed files
with
12 additions
and
1 deletions
... | @@ -67,7 +67,9 @@ var FunctionArgsInjector = function FunctionArgsInjector(fn) { | ... | @@ -67,7 +67,9 @@ var FunctionArgsInjector = function FunctionArgsInjector(fn) { |
67 | throw new CasperError("Unable to process function " + this.fn.toString()); | 67 | throw new CasperError("Unable to process function " + this.fn.toString()); |
68 | } | 68 | } |
69 | var inject = this.getArgsInjectionString(fnObj.args, values); | 69 | var inject = this.getArgsInjectionString(fnObj.args, values); |
70 | return 'function ' + (fnObj.name || '') + '(){' + inject + fnObj.body + '}'; | 70 | var newFn = new Function([inject, fnObj.body].join('\n')); |
71 | newFn.name = fnObj.name || ''; | ||
72 | return newFn; | ||
71 | }; | 73 | }; |
72 | 74 | ||
73 | this.getArgsInjectionString = function getArgsInjectionString(args, values) { | 75 | this.getArgsInjectionString = function getArgsInjectionString(args, values) { | ... | ... |
... | @@ -19,6 +19,11 @@ function Plip() { return 'plop'; } | ... | @@ -19,6 +19,11 @@ function Plip() { return 'plop'; } |
19 | function foo_bar(boz) {} | 19 | function foo_bar(boz) {} |
20 | var gni = function ($bubu_bibi, __popo__) {}; | 20 | var gni = function ($bubu_bibi, __popo__) {}; |
21 | var gno = function ( arg1, /*plop*/ arg2 ) { }; | 21 | var gno = function ( arg1, /*plop*/ arg2 ) { }; |
22 | function issue129(term) { | ||
23 | // see issue #129 | ||
24 | return term; | ||
25 | // see issue #129 | ||
26 | } | ||
22 | t.assertEquals(injector.extract(Plop), { | 27 | t.assertEquals(injector.extract(Plop), { |
23 | name: 'Plop', | 28 | name: 'Plop', |
24 | args: ['foo', 'bar'], | 29 | args: ['foo', 'bar'], |
... | @@ -52,4 +57,8 @@ eval('processed = ' + injector.process({ a: 1, b: 2 })); | ... | @@ -52,4 +57,8 @@ eval('processed = ' + injector.process({ a: 1, b: 2 })); |
52 | t.assertType(processed, "function", 'FunctionArgsInjector.process() processed a function'); | 57 | t.assertType(processed, "function", 'FunctionArgsInjector.process() processed a function'); |
53 | t.assertEquals(processed(), 3, 'FunctionArgsInjector.process() processed the function correctly'); | 58 | t.assertEquals(processed(), 3, 'FunctionArgsInjector.process() processed the function correctly'); |
54 | 59 | ||
60 | // Issue #129 | ||
61 | var fnIssue129 = createInjector(issue129).process({term: 'fixed'}); | ||
62 | t.assertEquals(fnIssue129('fixed'), 'fixed', 'FunctionArgsInjector.process() has issue #129 fixed'); | ||
63 | |||
55 | t.done(); | 64 | t.done(); | ... | ... |
-
Please register or sign in to post a comment