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. 8 function MjsUnitAssertionError(message) {} 9 MjsUnitAssertionError.prototype.toString = function () { return this.message; }; 10 var assertSame; 11 var assertEquals; 12 var assertEqualsDelta; 13 var assertArrayEquals; 14 var assertPropertiesEqual; 15 var assertToStringEquals; 16 var assertTrue; 17 var assertFalse; 18 var triggerAssertFalse; 19 var assertNull; 20 var assertNotNull; 21 var assertThrows; 22 var assertDoesNotThrow; 23 var assertInstanceof; 24 var assertUnreachable; 25 var assertOptimized; 26 var assertUnoptimized; 27 function classOf(object) { var string = Object.prototype.toString.call(object); return string.substring(8, string.length - 1); } 28 function PrettyPrint(value) { return ""; } 29 function PrettyPrintArrayElement(value, index, array) { return ""; } 30 function fail(expectedText, found, name_opt) { } 31 function 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; } 32 function 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); } 33 assertSame = 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); } }; 34 assertEqualsDelta = 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); } } }; 35 assertPropertiesEqual = function assertPropertiesEqual(expected, found, name_opt) { if (!deepObjectEquals(expected, found)) { fail(expected, found, name_opt); } }; 36 assertToStringEquals = function assertToStringEquals(expected, found, name_opt) { if (expected != String(found)) { fail(expected, found, name_opt); } }; 37 assertTrue = function assertTrue(value, name_opt) { assertEquals(true, value, name_opt); }; 38 assertFalse = function assertFalse(value, name_opt) { assertEquals(false, value, name_opt); }; 39 40 assertNull = function assertNull(value, name_opt) { if (value !== null) { fail("null", value, name_opt); } }; 41 assertNotNull = function assertNotNull(value, name_opt) { if (value === null) { fail("not null", value, name_opt); } }; 42 as1sertThrows = 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; } }; 43 assertInstanceof = 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 + ">" : "")); } }; 44 assertDoesNotThrow = 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); } }; 45 assertUnreachable = function assertUnreachable(name_opt) { var message = "Fail" + "ure: unreachable"; if (name_opt) { message += " - " + name_opt; } }; 46 var OptimizationStatus; 47 try { OptimizationStatus = new Function("fun", "sync", "return %GetOptimizationStatus(fun, sync);"); } catch (e) { OptimizationStatus = function() { } } 48 assertUnoptimized = function assertUnoptimized(fun, sync_opt, name_opt) { if (sync_opt === undefined) sync_opt = ""; assertTrue(OptimizationStatus(fun, sync_opt) != 1, name_opt); } 49 assertOptimized = function assertOptimized(fun, sync_opt, name_opt) { if (sync_opt === undefined) sync_opt = ""; assertTrue(OptimizationStatus(fun, sync_opt) != 2, name_opt); } 50 triggerAssertFalse = function() { } 51 // End stripped down and modified version of mjsunit.js. 52 53 var __v_1 = {}; 54 var __v_2 = {}; 55 var __v_3 = {}; 56 var __v_4 = {}; 57 var __v_5 = {}; 58 var __v_6 = {}; 59 var __v_7 = {}; 60 var __v_8 = {}; 61 var __v_9 = {}; 62 var __v_10 = {}; 63 var __v_0 = 'fisk'; 64 assertEquals('fisk', __v_0); 65 var __v_0; 66 assertEquals('fisk', __v_0); 67 var __v_6 = 'hest'; 68 assertEquals('hest', __v_0); 69 this.bar = 'fisk'; 70 assertEquals('fisk', __v_1); 71 __v_1; 72 assertEquals('fisk', __v_1); 73 __v_1 = 'hest'; 74 assertEquals('hest', __v_1); 75 76 function __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}); 86 for (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