From 74d3dceab2dd66e8d3c6bdebaec041132b7c2626 Mon Sep 17 00:00:00 2001 From: Andreas Lind Petersen Date: Mon, 7 Apr 2014 22:49:01 +0200 Subject: [PATCH] sanitize: Moved stack.push/pop to the outer level. --- lib/unexpected-core.js | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/lib/unexpected-core.js b/lib/unexpected-core.js index 854761925..17ba01df6 100644 --- a/lib/unexpected-core.js +++ b/lib/unexpected-core.js @@ -147,32 +147,27 @@ } } + stack.push(obj); + var sanitized, matchingCustomType = utils.findFirst(this.types || [], function (type) { return type.identify(obj); }); if (matchingCustomType) { - stack.push(obj); sanitized = this.sanitize(matchingCustomType.toJSON(obj), stack); - stack.pop(); - return sanitized; - } - if (isArray(obj)) { - stack.push(obj); + } else if (isArray(obj)) { sanitized = map(obj, function (item) { return this.sanitize(item, stack); }, this); - stack.pop(); } else if (typeof obj === 'object' && obj) { - stack.push(obj); sanitized = {}; forEach(getKeys(obj).sort(), function (key) { sanitized[key] = this.sanitize(obj[key], stack); }, this); - stack.pop(); } else { sanitized = obj; } + stack.pop(); return sanitized; };