summaryrefslogtreecommitdiff
path: root/chromium/third_party/catapult/tracing/tracing/mre/mre_result.html
blob: e4f37cb53edf2bfa3c1871d14b26685701f280ac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<!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="/tracing/mre/failure.html">

<script>
'use strict';

tr.exportTo('tr.mre', function() {
  class MreResult {
    constructor(failures, pairs) {
      if (failures === undefined)
        failures = [];
      if (pairs === undefined)
        pairs = {};
      this.failures = failures;
      this.pairs = pairs;
    }

    addFailure(failure) {
      this.failures.push(failure);
    }

    addPair(key, value) {
      if (key in this.pairs)
        throw new Error('Key ' + key + ' already exists in result.');
      this.pairs[key] = value;
    }

    asDict() {
      var d = {
        pairs: this.pairs
      };

      if (this.failures)
        d.failures = this.failures.map(function(f) {return f.asDict();});

      return d;
    }

    hadFailures() {
      return this.failures.length > 0;
    }

    static fromDict(resultDict) {
      if (resultDict.failures !== undefined)
        var failures = resultDict.failures.map(tr.mre.Failure.fromDict);
      var pairs = resultDict.pairs;
      return new MreResult(failures, pairs);
    }
  };

  return {
    MreResult: MreResult
  };
});

</script>