blob: 98367bdf20af79e8b74336fed58e4317561d889d [file] [log] [blame]
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001// 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 --expose-gc
6
7var assertDoesNotThrow;
8var assertInstanceof;
9var assertUnreachable;
10var assertOptimized;
11var assertUnoptimized;
12function classOf(object) { var string = Object.prototype.toString.call(object); return string.substring(8, string.length - 1); }
13function PrettyPrint(value) { return ""; }
14function PrettyPrintArrayElement(value, index, array) { return ""; }
15function fail(expectedText, found, name_opt) { }
16function 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; }
17function 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); }
18assertSame = 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); } };
19assertEqualsDelta = function assertEqualsDelta(expected, found, delta, name_opt) { assertTrue(Math.abs(expected - found) <= delta, name_opt); };
20assertArrayEquals = 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); } } };
21assertPropertiesEqual = function assertPropertiesEqual(expected, found, name_opt) { if (!deepObjectEquals(expected, found)) { fail(expected, found, name_opt); } };
22assertToStringEquals = function assertToStringEquals(expected, found, name_opt) { if (expected != String(found)) { fail(expected, found, name_opt); } };
23assertTrue = function assertTrue(value, name_opt) { assertEquals(true, value, name_opt); };
24assertFalse = function assertFalse(value, name_opt) { assertEquals(false, value, name_opt); };
25assertNull = function assertNull(value, name_opt) { if (value !== null) { fail("null", value, name_opt); } };
26assertNotNull = function assertNotNull(value, name_opt) { if (value === null) { fail("not null", value, name_opt); } };
27var __v_39 = {};
28var __v_40 = {};
29var __v_41 = {};
30var __v_42 = {};
31var __v_43 = {};
32var __v_44 = {};
33try {
34__v_0 = [1.5,,1.7];
35__v_1 = {__v_0:1.8};
36} catch(e) { print("Caught: " + e); }
37function __f_0(__v_1,__v_0,i) {
38 __v_1.a = __v_0[i];
39 gc();
40}
41try {
42__f_0(__v_1,__v_0,0);
43__f_0(__v_1,__v_0,0);
44%OptimizeFunctionOnNextCall(__f_0);
45__f_0(__v_1,__v_0,1);
46assertEquals(undefined, __v_1.a);
47__v_0 = [1,,3];
48__v_1 = {ab:5};
49} catch(e) { print("Caught: " + e); }
50function __f_1(__v_1,__v_0,i) {
51 __v_1.ab = __v_0[i];
52}
53try {
54__f_1(__v_1,__v_0,1);
55} catch(e) { print("Caught: " + e); }
56function __f_5(x) {
57 return ~x;
58}
59try {
60__f_5(42);
61assertEquals(~12, __f_5(12.45));
62assertEquals(~46, __f_5(42.87));
63__v_2 = 1, __v_4 = 2, __v_3 = 4, __v_6 = 8;
64} catch(e) { print("Caught: " + e); }
65function __f_4() {
66 return __v_2 | (__v_4 | (__v_3 | __v_6));
67}
68try {
69__f_4();
70__v_3 = "16";
71assertEquals(17 | -13 | 0 | -5, __f_4());
72} catch(e) { print("Caught: " + e); }
73function __f_6() {
74 return __f_4();
75}
76try {
77assertEquals(1 | 2 | 16 | 8, __f_6());
78__f_4 = function() { return 42; };
79assertEquals(42, __f_6());
80__v_5 = {};
81__v_5.__f_4 = __f_4;
82} catch(e) { print("Caught: " + e); }
83function __f_7(o) {
84 return o.__f_4();
85}
86try {
87for (var __v_7 = 0; __v_7 < 5; __v_7++) __f_7(__v_5);
88%OptimizeFunctionOnNextCall(__f_7);
89__f_7(__v_5);
90assertEquals(42, __f_7(__v_5));
91assertEquals(87, __f_7({__f_4: function() { return 87; }}));
92} catch(e) { print("Caught: " + e); }
93function __f_8(x,y) {
94 x = 42;
95 y = 1;
96 y = y << "0";
97 return x | y;
98}
99try {
100assertEquals(43, __f_8(0,0));
101} catch(e) { print("Caught: " + e); }
102function __f_2(x) {
103 return 'lit[' + (x + ']');
104}
105try {
106assertEquals('lit[-87]', __f_2(-87));
107assertEquals('lit[0]', __f_2(0));
108assertEquals('lit[42]', __f_2(42));
109__v_9 = "abc";
110gc();
111var __v_8;
112} catch(e) { print("Caught: " + e); }
113function __f_9(n) { return __v_9.charAt(n); }
114try {
115for (var __v_7 = 0; __v_7 < 5; __v_7++) {
116 __v_8 = __f_9(0);
117}
118%OptimizeFunctionOnNextCall(__f_9);
119__v_8 = __f_9(0);
120} catch(e) { print("Caught: " + e); }
121function __f_3(__v_2,__v_4,__v_3,__v_6) {
122 return __v_2+__v_4+__v_3+__v_6;
123}
124try {
125assertEquals(0x40000003, __f_3(1,1,2,0x3fffffff));
126} catch(e) { print("Caught: " + e); }
127try {
128__v_19 = {
129 fast_smi_only : 'fast smi only elements',
130 fast : 'fast elements',
131 fast_double : 'fast double elements',
132 dictionary : 'dictionary elements',
133 external_int32 : 'external int8 elements',
134 external_uint8 : 'external uint8 elements',
135 external_int16 : 'external int16 elements',
136 external_uint16 : 'external uint16 elements',
137 external_int32 : 'external int32 elements',
138 external_uint32 : 'external uint32 elements',
139 external_float32 : 'external float32 elements',
140 external_float64 : 'external float64 elements',
141 external_uint8_clamped : 'external uint8_clamped elements',
142 fixed_int32 : 'fixed int8 elements',
143 fixed_uint8 : 'fixed uint8 elements',
144 fixed_int16 : 'fixed int16 elements',
145 fixed_uint16 : 'fixed uint16 elements',
146 fixed_int32 : 'fixed int32 elements',
147 fixed_uint32 : 'fixed uint32 elements',
148 fixed_float32 : 'fixed float32 elements',
149 fixed_float64 : 'fixed float64 elements',
150 fixed_uint8_clamped : 'fixed uint8_clamped elements'
151}
152} catch(e) { print("Caught: " + e); }
153function __f_12() {
154}
155__v_10 = {};
156__v_10.dance = 0xD15C0;
157__v_10.drink = 0xC0C0A;
158__f_12(__v_19.fast, __v_10);
159__v_24 = [1,2,3];
160__f_12(__v_19.fast_smi_only, __v_24);
161__v_24.dance = 0xD15C0;
162__v_24.drink = 0xC0C0A;
163__f_12(__v_19.fast_smi_only, __v_24);
164function __f_18() {
165 var __v_27 = new Array();
166 __f_12(__v_19.fast_smi_only, __v_27);
167 for (var __v_18 = 0; __v_18 < 1337; __v_18++) {
168 var __v_16 = __v_18;
169 if (__v_18 == 1336) {
170 __f_12(__v_19.fast_smi_only, __v_27);
171 __v_16 = new Object();
172 }
173 __v_27[__v_18] = __v_16;
174 }
175 __f_12(__v_19.fast, __v_27);
176 var __v_15 = [];
177 __v_15[912570] = 7;
178 __f_12(__v_19.dictionary, __v_15);
179 var __v_26 = new Array(912561);
180 %SetAllocationTimeout(100000000, 10000000);
181 for (var __v_18 = 0; __v_18 < 0x20000; __v_18++) {
182 __v_26[0] = __v_18 / 2;
183 }
184 __f_12(__v_19.fixed_int8, new Int8Array(007));
185 __f_12(__v_19.fixed_uint8, new Uint8Array(007));
186 __f_12(__v_19.fixed_int16, new Int16Array(666));
187 __f_12(__v_19.fixed_uint16, new Uint16Array(42));
188 __f_12(__v_19.fixed_int32, new Int32Array(0xF));
189 __f_12(__v_19.fixed_uint32, new Uint32Array(23));
190 __f_12(__v_19.fixed_float32, new Float32Array(7));
191 __f_12(__v_19.fixed_float64, new Float64Array(0));
192 __f_12(__v_19.fixed_uint8_clamped, new Uint8ClampedArray(512));
193 var __v_13 = new ArrayBuffer(128);
194 __f_12(__v_19.external_int8, new Int8Array(__v_13));
195 __f_12(__v_37.external_uint8, new Uint8Array(__v_13));
196 __f_12(__v_19.external_int16, new Int16Array(__v_13));
197 __f_12(__v_19.external_uint16, new Uint16Array(__v_13));
198 __f_12(__v_19.external_int32, new Int32Array(__v_13));
199 __f_12(__v_19.external_uint32, new Uint32Array(__v_13));
200 __f_12(__v_19.external_float32, new Float32Array(__v_13));
201 __f_12(__v_19.external_float64, new Float64Array(__v_13));
202 __f_12(__v_19.external_uint8_clamped, new Uint8ClampedArray(__v_13));
203}
204try {
205__f_18();
206} catch(e) { }