v8_foozzie_harness_adjust.js 3 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
// Copyright 2018 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Extensions to mjsunit and other test harnesses added between harness and
// fuzzing code.

try {
  // Scope for utility functions.
  (function() {
    // Same as in mjsunit.js.
    function classOf(object) {
      // Argument must not be null or undefined.
      var string = Object.prototype.toString.call(object);
      // String has format [object <ClassName>].
      return string.substring(8, string.length - 1);
    }

    // Override prettyPrinted with a version that also recusively prints object
    // properties (with a depth of 3).
21 22
    let origPrettyPrinted = prettyPrinted;
    prettyPrinted = function prettyPrinted(value, depth=3) {
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
      if (depth == 0) {
        return "...";
      }
      switch (typeof value) {
        case "object":
          if (value === null) return "null";
          var objectClass = classOf(value);
          switch (objectClass) {
            case "Object":
              var name = value.constructor.name;
              if (!name)
                name = "Object";
              return name + "{" + Object.keys(value).map(function(key, index) {
                return (
                    prettyPrinted(key, depth - 1) +
                    ": " +
                    prettyPrinted(value[key], depth - 1)
                );
              }).join(",")  + "}";
          }
      }
      // Fall through to original version for all other types.
      return origPrettyPrinted(value);
    }
47 48

    // We're not interested in stack traces.
49
    MjsUnitAssertionError = function MjsUnitAssertionError(message) {}
50 51 52
    MjsUnitAssertionError.prototype.toString = function () { return ""; };

    // Do more printing in assertions for more correctness coverage.
53
    failWithMessage = function failWithMessage(message) {
54 55 56
      print(prettyPrinted(message))
    }

57
    assertSame = function assertSame(expected, found, name_opt) {
58 59
      print(prettyPrinted(found));
    }
60

61
    assertNotSame = function assertNotSame(expected, found, name_opt) {
62 63 64
      print(prettyPrinted(found));
    }

65
    assertEquals = function assertEquals(expected, found, name_opt) {
66 67 68
      print(prettyPrinted(found));
    }

69
    assertNotEquals = function assertNotEquals(expected, found, name_opt) {
70 71 72
      print(prettyPrinted(found));
    }

73
    assertNull = function assertNull(value, name_opt) {
74 75 76
      print(prettyPrinted(value));
    }

77
    assertNotNull = function assertNotNull(value, name_opt) {
78 79
      print(prettyPrinted(value));
    }
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
    isOptimized = function isOptimized() {}
93

94
    isTurboFanned = function isTurboFanned() {}
95 96
  })();
} catch(e) { }