Made ExpectationFilterChain immutable
This commit is contained in:
@@ -1,42 +1,52 @@
|
||||
getJasmineRequireObj().ExpectationFilterChain = function() {
|
||||
function ExpectationFilterChain() {
|
||||
this.filters_ = [];
|
||||
function ExpectationFilterChain(maybeFilter, prev) {
|
||||
this.filter_ = maybeFilter;
|
||||
this.prev_ = prev;
|
||||
}
|
||||
|
||||
ExpectationFilterChain.prototype.addFilter = function(filter) {
|
||||
this.filters_.push(filter);
|
||||
return new ExpectationFilterChain(filter, this);
|
||||
};
|
||||
|
||||
ExpectationFilterChain.prototype.selectComparisonFunc = function(matcher) {
|
||||
return this.callFirst_('selectComparisonFunc', arguments);
|
||||
return this.callFirst_('selectComparisonFunc', arguments).result;
|
||||
};
|
||||
|
||||
ExpectationFilterChain.prototype.buildFailureMessage = function(result, matcherName, args, util) {
|
||||
return this.callFirst_('buildFailureMessage', arguments);
|
||||
return this.callFirst_('buildFailureMessage', arguments).result;
|
||||
};
|
||||
|
||||
ExpectationFilterChain.prototype.modifyFailureMessage = function(msg) {
|
||||
var i;
|
||||
if (this.prev_) {
|
||||
msg = this.prev_.modifyFailureMessage(msg);
|
||||
}
|
||||
|
||||
for (i = this.filters_.length - 1; i >= 0; i--) {
|
||||
if (this.filters_[i].modifyFailureMessage) {
|
||||
msg = this.filters_[i].modifyFailureMessage(msg);
|
||||
}
|
||||
if (this.filter_ && this.filter_.modifyFailureMessage) {
|
||||
msg = this.filter_.modifyFailureMessage(msg);
|
||||
}
|
||||
|
||||
return msg;
|
||||
};
|
||||
|
||||
ExpectationFilterChain.prototype.callFirst_ = function(fname, args) {
|
||||
var i, filter;
|
||||
var prevResult;
|
||||
|
||||
for (i = 0; i < this.filters_.length; i++) {
|
||||
filter = this.filters_[i];
|
||||
if (this.prev_) {
|
||||
prevResult = this.prev_.callFirst_(fname, args);
|
||||
|
||||
if (filter[fname]) {
|
||||
return filter[fname].apply(filter, args);
|
||||
if (prevResult.found) {
|
||||
return prevResult;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.filter_ && this.filter_[fname]) {
|
||||
return {
|
||||
found: true,
|
||||
result: this.filter_[fname].apply(this.filter_, args)
|
||||
};
|
||||
}
|
||||
|
||||
return {found: false};
|
||||
};
|
||||
|
||||
return ExpectationFilterChain;
|
||||
|
||||
Reference in New Issue
Block a user