1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/tests/js1_5/extensions/regress-225831.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,162 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +/* 1.10 + * 1.11 + * Date: 15 Nov 2003 1.12 + * SUMMARY: Stressing the byte code generator 1.13 + * 1.14 + * See http://bugzilla.mozilla.org/show_bug.cgi?id=225831 1.15 + * 1.16 + */ 1.17 +//----------------------------------------------------------------------------- 1.18 +var UBound = 0; 1.19 +var BUGNUMBER = 225831; 1.20 +var summary = 'Stressing the byte code generator'; 1.21 +var status = ''; 1.22 +var statusitems = []; 1.23 +var actual = ''; 1.24 +var actualvalues = []; 1.25 +var expect= ''; 1.26 +var expectedvalues = []; 1.27 + 1.28 + 1.29 +function f() { return {x: 0}; } 1.30 + 1.31 +var N = 300; 1.32 +var a = new Array(N + 1); 1.33 +a[N] = 10; 1.34 +a[0] = 100; 1.35 + 1.36 + 1.37 +status = inSection(1); 1.38 + 1.39 +// build string of the form ++(a[++f().x + ++f().x + ... + ++f().x]) which 1.40 +// gives ++a[N] 1.41 +var str = "".concat("++(a[", repeat_str("++f().x + ", (N - 1)), "++f().x])"); 1.42 + 1.43 +// Use Script constructor instead of simple eval to test Rhino optimizer mode 1.44 +// because in Rhino, eval always uses interpreted mode. 1.45 +if (typeof Script == 'undefined') 1.46 +{ 1.47 + print('Test skipped. Script not defined.'); 1.48 +} 1.49 +else 1.50 +{ 1.51 + var script = new Script(str); 1.52 + script(); 1.53 + 1.54 + actual = a[N]; 1.55 + expect = 11; 1.56 +} 1.57 +addThis(); 1.58 + 1.59 +status = inSection(2); 1.60 + 1.61 + 1.62 +// build string of the form (a[f().x-- + f().x-- + ... + f().x--])-- 1.63 +// which should give (a[0])-- 1.64 +if (typeof Script == 'undefined') 1.65 +{ 1.66 + print('Test skipped. Script not defined.'); 1.67 +} 1.68 +else 1.69 +{ 1.70 + str = "".concat("(a[", repeat_str("f().x-- + ", (N - 1)), "f().x--])--"); 1.71 + script = new Script(str); 1.72 + script(); 1.73 + 1.74 + actual = a[0]; 1.75 + expect = 99; 1.76 +} 1.77 +addThis(); 1.78 + 1.79 + 1.80 +status = inSection(3); 1.81 + 1.82 +// build string of the form [[1], [1], ..., [1]] 1.83 +if (typeof Script == 'undefined') 1.84 +{ 1.85 + print('Test skipped. Script not defined.'); 1.86 +} 1.87 +else 1.88 +{ 1.89 + str = "".concat("[", repeat_str("[1], ", (N - 1)), "[1]]"); 1.90 + script = new Script(str); 1.91 + script(); 1.92 + 1.93 + actual = uneval(script()); 1.94 + expect = str; 1.95 +} 1.96 +addThis(); 1.97 + 1.98 + 1.99 +status = inSection(4); 1.100 + 1.101 +// build string of the form ({1:{a:1}, 2:{a:1}, ... N:{a:1}}) 1.102 +if (typeof Script == 'undefined') 1.103 +{ 1.104 + print('Test skipped. Script not defined.'); 1.105 +} 1.106 +else 1.107 +{ 1.108 + str = function() { 1.109 + var arr = new Array(N+1); 1.110 + arr[0] = "({"; 1.111 + for (var i = 1; i < N; ++i) { 1.112 + arr[i] = i+":{a:1}, "; 1.113 + } 1.114 + arr[N] = N+":{a:1}})"; 1.115 + return "".concat.apply("", arr); 1.116 + }(); 1.117 + 1.118 + script = new Script(str); 1.119 + script(); 1.120 + 1.121 + actual = uneval(script()); 1.122 + expect = str; 1.123 +} 1.124 +addThis(); 1.125 + 1.126 + 1.127 + 1.128 + 1.129 +//----------------------------------------------------------------------------- 1.130 +test(); 1.131 +//----------------------------------------------------------------------------- 1.132 + 1.133 + 1.134 + 1.135 +function repeat_str(str, repeat_count) 1.136 +{ 1.137 + var arr = new Array(--repeat_count); 1.138 + while (repeat_count != 0) 1.139 + arr[--repeat_count] = str; 1.140 + return str.concat.apply(str, arr); 1.141 +} 1.142 + 1.143 + 1.144 +function addThis() 1.145 +{ 1.146 + statusitems[UBound] = status; 1.147 + actualvalues[UBound] = actual; 1.148 + expectedvalues[UBound] = expect; 1.149 + UBound++; 1.150 +} 1.151 + 1.152 + 1.153 +function test() 1.154 +{ 1.155 + enterFunc('test'); 1.156 + printBugNumber(BUGNUMBER); 1.157 + printStatus(summary); 1.158 + 1.159 + for (var i=0; i<UBound; i++) 1.160 + { 1.161 + reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]); 1.162 + } 1.163 + 1.164 + exitFunc ('test'); 1.165 +}