Permalink
Browse files

Using new Function instead of eval

  • Loading branch information...
Alex Young
Alex Young committed Oct 22, 2009
1 parent ecc0bfc commit ab4a8d147fe2ec33eb4633d8845eb4f04aee2711
Showing with 12 additions and 13 deletions.
  1. +12 −13 riot.js
View
25 riot.js
@@ -47,19 +47,18 @@ var Riot = {
},
withDSL: function(fn, context) {
- var body = this.functionBody(fn);
- body = "(function(context, given, asserts, should, setup, teardown) { " + body + " })";
- return function() {
- var args = [
- Riot.context,
- Riot.given,
- function() { return context.asserts.apply(context, arguments); },
- function() { return context.should.apply(context, arguments); },
- function() { return context.setup.apply(context, arguments); },
- function() { return context.teardown.apply(context, arguments); }
- ];
- eval(body).apply(Riot, args);
- };
+ var body = this.functionBody(fn),
+ f = new Function('context', 'given', 'asserts', 'should', 'setup', 'teardown', body),
+ args = [
+ Riot.context,
+ Riot.given,
+ function() { return context.asserts.apply(context, arguments); },
+ function() { return context.should.apply(context, arguments); },
+ function() { return context.setup.apply(context, arguments); },
+ function() { return context.teardown.apply(context, arguments); }
+ ];
+
+ return function() { f.apply(Riot, args); };
},
context: function(title, callback) {

0 comments on commit ab4a8d1

Please sign in to comment.