• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright 2018 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5// Extensions to mjsunit and other test harnesses added between harness and
6// fuzzing code.
7
8try {
9  // Scope for utility functions.
10  (function() {
11    // Same as in mjsunit.js.
12    function classOf(object) {
13      // Argument must not be null or undefined.
14      var string = Object.prototype.toString.call(object);
15      // String has format [object <ClassName>].
16      return string.substring(8, string.length - 1);
17    }
18
19    // Override prettyPrinted with a version that also recusively prints object
20    // properties (with a depth of 3).
21    let origPrettyPrinted = prettyPrinted;
22    prettyPrinted = function prettyPrinted(value, depth=3) {
23      if (depth == 0) {
24        return "...";
25      }
26      switch (typeof value) {
27        case "object":
28          if (value === null) return "null";
29          var objectClass = classOf(value);
30          switch (objectClass) {
31            case "Object":
32              var name = value.constructor.name;
33              if (!name)
34                name = "Object";
35              return name + "{" + Object.keys(value).map(function(key, index) {
36                return (
37                    prettyPrinted(key, depth - 1) +
38                    ": " +
39                    prettyPrinted(value[key], depth - 1)
40                );
41              }).join(",")  + "}";
42          }
43      }
44      // Fall through to original version for all other types.
45      return origPrettyPrinted(value);
46    }
47
48    // We're not interested in stack traces.
49    MjsUnitAssertionError = function MjsUnitAssertionError(message) {}
50    MjsUnitAssertionError.prototype.toString = function () { return ""; };
51
52    // Do more printing in assertions for more correctness coverage.
53    failWithMessage = function failWithMessage(message) {
54      print(prettyPrinted(message))
55    }
56
57    assertSame = function assertSame(expected, found, name_opt) {
58      print(prettyPrinted(found));
59    }
60
61    assertNotSame = function assertNotSame(expected, found, name_opt) {
62      print(prettyPrinted(found));
63    }
64
65    assertEquals = function assertEquals(expected, found, name_opt) {
66      print(prettyPrinted(found));
67    }
68
69    assertNotEquals = function assertNotEquals(expected, found, name_opt) {
70      print(prettyPrinted(found));
71    }
72
73    assertNull = function assertNull(value, name_opt) {
74      print(prettyPrinted(value));
75    }
76
77    assertNotNull = function assertNotNull(value, name_opt) {
78      print(prettyPrinted(value));
79    }
80
81    // Suppress optimization status as it leads to false positives.
82    assertUnoptimized = function assertUnoptimized() {}
83
84    assertOptimized = function assertOptimized() {}
85
86    isNeverOptimize = function isNeverOptimize() {}
87
88    isAlwaysOptimize = function isAlwaysOptimize() {}
89
90    isInterpreted = function isInterpreted() {}
91
92    isBaseline = function isBaseline() {}
93
94    isUnoptimized = function isUnoptimized() {}
95
96    isOptimized = function isOptimized() {}
97
98    isTurboFanned = function isTurboFanned() {}
99  })();
100} catch(e) { }
101