|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function exclude () { |
|
var excludes = [].slice.call(arguments); |
|
|
|
function excludeProps (res, obj) { |
|
Object.keys(obj).forEach(function (key) { |
|
if (!~excludes.indexOf(key)) res[key] = obj[key]; |
|
}); |
|
} |
|
|
|
return function extendExclude () { |
|
var args = [].slice.call(arguments) |
|
, i = 0 |
|
, res = {}; |
|
|
|
for (; i < args.length; i++) { |
|
excludeProps(res, args[i]); |
|
} |
|
|
|
return res; |
|
}; |
|
}; |
|
|
|
|
|
|
|
|
|
|
|
module.exports = AssertionError; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function AssertionError (message, _props, ssf) { |
|
var extend = exclude('name', 'message', 'stack', 'constructor', 'toJSON') |
|
, props = extend(_props || {}); |
|
|
|
|
|
this.message = message || 'Unspecified AssertionError'; |
|
this.showDiff = false; |
|
|
|
|
|
for (var key in props) { |
|
this[key] = props[key]; |
|
} |
|
|
|
|
|
ssf = ssf || AssertionError; |
|
if (Error.captureStackTrace) { |
|
Error.captureStackTrace(this, ssf); |
|
} else { |
|
try { |
|
throw new Error(); |
|
} catch(e) { |
|
this.stack = e.stack; |
|
} |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
|
|
AssertionError.prototype = Object.create(Error.prototype); |
|
|
|
|
|
|
|
|
|
|
|
AssertionError.prototype.name = 'AssertionError'; |
|
|
|
|
|
|
|
|
|
|
|
AssertionError.prototype.constructor = AssertionError; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
AssertionError.prototype.toJSON = function (stack) { |
|
var extend = exclude('constructor', 'toJSON', 'stack') |
|
, props = extend({ name: this.name }, this); |
|
|
|
|
|
if (false !== stack && this.stack) { |
|
props.stack = this.stack; |
|
} |
|
|
|
return props; |
|
}; |
|
|