1 <!DOCTYPE html> 2 <!-- 3 Copyright 2015 The Chromium Authors. All rights reserved. 4 Use of this source code is governed by a BSD-style license that can be 5 found in the LICENSE file. 6 --> 7 <link rel="import" href="/tracing/mre/failure.html"> 8 9 <script> 10 'use strict'; 11 12 tr.exportTo('tr.mre', function() { 13 class MreResult { 14 constructor(failures, pairs) { 15 if (failures === undefined) 16 failures = []; 17 if (pairs === undefined) 18 pairs = {}; 19 this.failures = failures; 20 this.pairs = pairs; 21 } 22 23 addFailure(failure) { 24 this.failures.push(failure); 25 } 26 27 addPair(key, value) { 28 if (key in this.pairs) 29 throw new Error('Key ' + key + ' already exists in result.'); 30 this.pairs[key] = value; 31 } 32 33 asDict() { 34 var d = { 35 pairs: this.pairs 36 }; 37 38 if (this.failures) 39 d.failures = this.failures.map(function(f) {return f.asDict();}); 40 41 return d; 42 } 43 44 hadFailures() { 45 return this.failures.length > 0; 46 } 47 48 static fromDict(resultDict) { 49 if (resultDict.failures !== undefined) 50 var failures = resultDict.failures.map(tr.mre.Failure.fromDict); 51 var pairs = resultDict.pairs; 52 return new MreResult(failures, pairs); 53 } 54 }; 55 56 return { 57 MreResult: MreResult 58 }; 59 }); 60 61 </script> 62