Debian Codegraph @

rhino/testsrc/tests/js1_6/extensions/regress-456826.js

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