Skip to content

Commit ce73ecd

Browse files
author
cloudhead
committed
Cleaned up the inner loop a little
1 parent 9fa313c commit ce73ecd

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

lib/vows.js

+8-5
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ function addVows(tests) {
246246
}
247247

248248
this.addListener("end", function (honored, broken, errored) {
249-
var topic, vow, env;
249+
var topic;
250250

251251
vows.remaining += remaining;
252252

@@ -309,15 +309,18 @@ function addVows(tests) {
309309
Object.keys(ctx.tests).filter(function (k) {
310310
return ctx.tests[k] && k !== 'topic';
311311
}).forEach(function (item) {
312+
// Create a new evaluation context,
313+
// inheriting from the parent one.
314+
var env = Object.create(ctx.env);
315+
312316
// Holds the current test or context
313-
vow = Object.create({
317+
var vow = Object.create({
314318
callback: ctx.tests[item],
315319
context: ctx.name,
316320
description: item,
317321
binding: ctx.env,
318322
promise: promise
319323
});
320-
env = Object.create(ctx.env);
321324

322325
// If we encounter a function, add it to the callbacks
323326
// of the `topic` function, so it'll get called once the
@@ -331,11 +334,11 @@ function addVows(tests) {
331334
// before calling the inner context. Else, just run the inner context
332335
// synchronously.
333336
if (topic) {
334-
topic.addListener("success", function (vow, ctx, env) {
337+
topic.addListener("success", function (ctx) {
335338
return function (val) {
336339
return run(new(Context)(vow, ctx, env), lastTopic);
337340
};
338-
}(vow, ctx, env));
341+
}(ctx));
339342
} else {
340343
run(new(Context)(vow, ctx, env), lastTopic);
341344
}

0 commit comments

Comments
 (0)