Debian Codegraph @

js/src/tests/non262/extensions/regress-456826.js

raw
1 // |reftest| skip-if(!xulRuntime.shell||Android) slow -- bug 504632
2 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7 //-----------------------------------------------------------------------------
8 var BUGNUMBER = 456826;
9 var summary = 'Do not assert with JIT during OOM';
10 var actual = 'No Crash';
11 var expect = 'No Crash';
12
13
14 //-----------------------------------------------------------------------------
15 test();
16 //-----------------------------------------------------------------------------
17
18 function test()
19 {
20 printBugNumber(BUGNUMBER);
21 printStatus (summary);
22
23
24 if (typeof gcparam != 'undefined')
25 {
26 gc();
27 gc();
28 gcparam("maxBytes", gcparam("gcBytes") + 4*1024);
29 expectExitCode(5);
30 expectExitCode(3);
31 }
32
33 const numRows = 600;
34 const numCols = 600;
35 var scratch = {};
36 var scratchZ = {};
37
38 function complexMult(a, b) {
39 var newr = a.r * b.r - a.i * b.i;
40 var newi = a.r * b.i + a.i * b.r;
41 scratch.r = newr;
42 scratch.i = newi;
43 return scratch;
44 }
45
46 function complexAdd(a, b) {
47 scratch.r = a.r + b.r;
48 scratch.i = a.i + b.i;
49 return scratch;
50 }
51
52 function abs(a) {
53 return Math.sqrt(a.r * a.r + a.i * a.i);
54 }
55
56 function computeEscapeSpeed(c) {
57 scratchZ.r = scratchZ.i = 0;
58 const scaler = 5;
59 const threshold = (colors.length - 1) * scaler + 1;
60 for (var i = 1; i < threshold; ++i) {
61 scratchZ = complexAdd(c, complexMult(scratchZ, scratchZ));
62 if (scratchZ.r * scratchZ.r + scratchZ.i * scratchZ.i > 4) {
63 return Math.floor((i - 1) / scaler) + 1;
64 }
65 }
66 return 0;
67 }
68
69 const colorStrings = [
70 "black",
71 "green",
72 "blue",
73 "red",
74 "purple",
75 "orange",
76 "cyan",
77 "yellow",
78 "magenta",
79 "brown",
80 "pink",
81 "chartreuse",
82 "darkorange",
83 "crimson",
84 "gray",
85 "deeppink",
86 "firebrick",
87 "lavender",
88 "lawngreen",
89 "lightsalmon",
90 "lime",
91 "goldenrod"
92 ];
93
94 var colors = [];
95
96 function createMandelSet(realRange, imagRange) {
97 var start = new Date();
98
99 // Set up our colors
100 for (var color of colorStrings) {
101 var [r, g, b] = [0, 0, 0];
102 colors.push([r, g, b, 0xff]);
103 }
104
105 var realStep = (realRange.max - realRange.min)/numCols;
106 var imagStep = (imagRange.min - imagRange.max)/numRows;
107 for (var i = 0, curReal = realRange.min;
108 i < numCols;
109 ++i, curReal += realStep) {
110 for (var j = 0, curImag = imagRange.max;
111 j < numRows;
112 ++j, curImag += imagStep) {
113 var c = { r: curReal, i: curImag }
114 var n = computeEscapeSpeed(c);
115 }
116 }
117 print(Date.now() - start);
118 }
119
120 var realRange = { min: -2.1, max: 2 };
121 var imagRange = { min: -2, max: 2 };
122 createMandelSet(realRange, imagRange);
123
124
125 reportCompare(expect, actual, summary);
126 }