blob: 97e46bd5df8045965eab98639b451a34e0a5838a [file] [log] [blame]
<!DOCTYPE html>
<!--
Copyright 2015 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->
<link rel="import" href="/perf_insights/mre/failure.html">
<script>
'use strict';
tr.exportTo('pi.mre', function() {
function MreResult(failures, pairs) {
if (failures === undefined)
failures = [];
if (pairs === undefined)
pairs = {};
this.failures = failures;
this.pairs = pairs;
}
MreResult.prototype = {
addFailure: function(failure) {
this.failures.push(failure);
},
addPair: function(key, value) {
if (key in this.pairs)
throw new Error('Key ' + key + ' already exists in result.');
this.pairs[key] = value;
},
asDict: function() {
var d = {
pairs: this.pairs
};
if (this.failures)
d.failures = this.failures.map(function(f) {return f.asDict();});
return d;
},
hadFailures: function() {
return this.failures.length > 0;
}
};
MreResult.fromDict = function(resultDict) {
if (resultDict.failures !== undefined)
var failures = resultDict.failures.map(pi.mre.Failure.fromDict);
var pairs = resultDict.pairs;
return new MreResult(failures, pairs);
};
return {
MreResult: MreResult
};
});
</script>