1 // Copyright 2014 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// Flags: --allow-natives-syntax --debug-code --gc-interval=201 --verify-heap --max-inlined-source-size=999999 --max-inlined-nodes=999999 --max-inlined-nodes-cumulative=999999
6
7// Begin stripped down and modified version of mjsunit.js for easy minimization in CF.
8function MjsUnitAssertionError(message) {}
9MjsUnitAssertionError.prototype.toString = function () { return this.message; };
10var assertSame;
11var assertEquals;
12var assertEqualsDelta;
13var assertArrayEquals;
14var assertPropertiesEqual;
15var assertToStringEquals;
16var assertTrue;
17var assertFalse;
18var triggerAssertFalse;
19var assertNull;
20var assertNotNull;
21var assertThrows;
22var assertDoesNotThrow;
23var assertInstanceof;
24var assertUnreachable;
25var assertOptimized;
26var assertUnoptimized;
27function classOf(object) { var string = Object.prototype.toString.call(object); return string.substring(8, string.length - 1); }
28function PrettyPrint(value) { return ""; }
29function PrettyPrintArrayElement(value, index, array) { return ""; }
30function fail(expectedText, found, name_opt) { }
31function deepObjectEquals(a, b) { var aProps = Object.keys(a); aProps.sort(); var bProps = Object.keys(b); bProps.sort(); if (!deepEquals(aProps, bProps)) { return false; } for (var i = 0; i < aProps.length; i++) { if (!deepEquals(a[aProps[i]], b[aProps[i]])) { return false; } } return true; }
32function deepEquals(a, b) { if (a === b) { if (a === 0) return (1 / a) === (1 / b); return true; } if (typeof a != typeof b) return false; if (typeof a == "number") return isNaN(a) && isNaN(b); if (typeof a !== "object" && typeof a !== "function") return false; var objectClass = classOf(a); if (objectClass !== classOf(b)) return false; if (objectClass === "RegExp") { return (a.toString() === b.toString()); } if (objectClass === "Function") return false; if (objectClass === "Array") { var elementCount = 0; if (a.length != b.length) { return false; } for (var i = 0; i < a.length; i++) { if (!deepEquals(a[i], b[i])) return false; } return true; } if (objectClass == "String" || objectClass == "Number" || objectClass == "Boolean" || objectClass == "Date") { if (a.valueOf() !== b.valueOf()) return false; } return deepObjectEquals(a, b); }
33assertSame = function assertSame(expected, found, name_opt) { if (found === expected) { if (expected !== 0 || (1 / expected) == (1 / found)) return; } else if ((expected !== expected) && (found !== found)) { return; } fail(PrettyPrint(expected), found, name_opt); }; assertEquals = function assertEquals(expected, found, name_opt) { if (!deepEquals(found, expected)) { fail(PrettyPrint(expected), found, name_opt); } };
34assertEqualsDelta = function assertEqualsDelta(expected, found, delta, name_opt) { assertTrue(Math.abs(expected - found) <= delta, name_opt); }; assertArrayEquals = function assertArrayEquals(expected, found, name_opt) { var start = ""; if (name_opt) { start = name_opt + " - "; } assertEquals(expected.length, found.length, start + "array length"); if (expected.length == found.length) { for (var i = 0; i < expected.length; ++i) { assertEquals(expected[i], found[i], start + "array element at index " + i); } } };
35assertPropertiesEqual = function assertPropertiesEqual(expected, found, name_opt) { if (!deepObjectEquals(expected, found)) { fail(expected, found, name_opt); } };
36assertToStringEquals = function assertToStringEquals(expected, found, name_opt) { if (expected != String(found)) { fail(expected, found, name_opt); } };
37assertTrue = function assertTrue(value, name_opt) { assertEquals(true, value, name_opt); };
38assertFalse = function assertFalse(value, name_opt) { assertEquals(false, value, name_opt); };
39
40assertNull = function assertNull(value, name_opt) { if (value !== null) { fail("null", value, name_opt); } };
41assertNotNull = function assertNotNull(value, name_opt) { if (value === null) { fail("not null", value, name_opt); } };
42as1sertThrows = function assertThrows(code, type_opt, cause_opt) { var threwException = true; try { if (typeof code == 'function') { code(); } else { eval(code); } threwException = false; } catch (e) { if (typeof type_opt == 'function') { assertInstanceof(e, type_opt); } if (arguments.length >= 3) { assertEquals(e.type, cause_opt); } return; } };
43assertInstanceof = function assertInstanceof(obj, type) { if (!(obj instanceof type)) { var actualTypeName = null; var actualConstructor = Object.getPrototypeOf(obj).constructor; if (typeof actualConstructor == "function") { actualTypeName = actualConstructor.name || String(actualConstructor); } fail("Object <" + PrettyPrint(obj) + "> is not an instance of <" + (type.name || type) + ">" + (actualTypeName ? " but of < " + actualTypeName + ">" : "")); } };
44assertDoesNotThrow = function assertDoesNotThrow(code, name_opt) { try { if (typeof code == 'function') { code(); } else { eval(code); } } catch (e) { fail("threw an exception: ", e.message || e, name_opt); } };
45assertUnreachable = function assertUnreachable(name_opt) { var message = "Fail" + "ure: unreachable"; if (name_opt) { message += " - " + name_opt; } };
46var OptimizationStatus;
47try { OptimizationStatus = new Function("fun", "sync", "return %GetOptimizationStatus(fun, sync);"); } catch (e) { OptimizationStatus = function() { } }
48assertUnoptimized = function assertUnoptimized(fun, sync_opt, name_opt) { if (sync_opt === undefined) sync_opt = ""; assertTrue(OptimizationStatus(fun, sync_opt) != 1, name_opt); }
49assertOptimized = function assertOptimized(fun, sync_opt, name_opt) { if (sync_opt === undefined) sync_opt = "";  assertTrue(OptimizationStatus(fun, sync_opt) != 2, name_opt); }
50triggerAssertFalse = function() { }
51// End stripped down and modified version of mjsunit.js.
52
53var __v_1 = {};
54var __v_2 = {};
55var __v_3 = {};
56var __v_4 = {};
57var __v_5 = {};
58var __v_6 = {};
59var __v_7 = {};
60var __v_8 = {};
61var __v_9 = {};
62var __v_10 = {};
63var __v_0 = 'fisk';
64assertEquals('fisk', __v_0);
65var __v_0;
66assertEquals('fisk', __v_0);
67var __v_6 = 'hest';
68assertEquals('hest', __v_0);
69this.bar = 'fisk';
70assertEquals('fisk', __v_1);
71__v_1;
72assertEquals('fisk', __v_1);
73__v_1 = 'hest';
74assertEquals('hest', __v_1);
75
76function __f_0(o) {
77  o.g();
78  if (!o.g()) {
79    assertTrue(false);
80  }
81}
82__v_4 = {};
83__v_4.size = function() { return 42; }
84__v_4.g = function() { return this.size(); };
85__f_0({g: __v_4.g, size:__v_4.size});
86for (var __v_0 = 0; __v_0 < 5; __v_0++) __f_0(__v_4);
87%OptimizeFunctionOnNextCall(__f_0);
88__f_0(__v_4);
89__f_0({g: __v_4.g, size:__v_4.size});
90